open_ehr 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (253) hide show
  1. data/.document +5 -0
  2. data/Gemfile +14 -0
  3. data/Gemfile.lock +43 -0
  4. data/Guardfile +9 -0
  5. data/History.txt +4 -0
  6. data/Manifest.txt +16 -0
  7. data/PostInstall.txt +9 -0
  8. data/README.rdoc +66 -0
  9. data/Rakefile +49 -0
  10. data/VERSION +1 -0
  11. data/doc/README_rdoc.html +148 -0
  12. data/doc/created.rid +2 -0
  13. data/doc/images/brick.png +0 -0
  14. data/doc/images/brick_link.png +0 -0
  15. data/doc/images/bug.png +0 -0
  16. data/doc/images/bullet_black.png +0 -0
  17. data/doc/images/bullet_toggle_minus.png +0 -0
  18. data/doc/images/bullet_toggle_plus.png +0 -0
  19. data/doc/images/date.png +0 -0
  20. data/doc/images/find.png +0 -0
  21. data/doc/images/loadingAnimation.gif +0 -0
  22. data/doc/images/macFFBgHack.png +0 -0
  23. data/doc/images/package.png +0 -0
  24. data/doc/images/page_green.png +0 -0
  25. data/doc/images/page_white_text.png +0 -0
  26. data/doc/images/page_white_width.png +0 -0
  27. data/doc/images/plugin.png +0 -0
  28. data/doc/images/ruby.png +0 -0
  29. data/doc/images/tag_green.png +0 -0
  30. data/doc/images/wrench.png +0 -0
  31. data/doc/images/wrench_orange.png +0 -0
  32. data/doc/images/zoom.png +0 -0
  33. data/doc/index.html +54 -0
  34. data/doc/js/darkfish.js +116 -0
  35. data/doc/js/jquery.js +32 -0
  36. data/doc/js/quicksearch.js +114 -0
  37. data/doc/js/thickbox-compressed.js +10 -0
  38. data/doc/openehr_terminology.xml +2700 -0
  39. data/doc/rdoc.css +706 -0
  40. data/lib/#open_ehr.rb# +11 -0
  41. data/lib/open_ehr/am/archetype/archetype_description/archetype_description.rb +21 -0
  42. data/lib/open_ehr/am/archetype/assertion.rb +190 -0
  43. data/lib/open_ehr/am/archetype/constraint_model/primitive.rb +296 -0
  44. data/lib/open_ehr/am/archetype/constraint_model.rb +340 -0
  45. data/lib/open_ehr/am/archetype/ontology.rb +97 -0
  46. data/lib/open_ehr/am/archetype.rb +134 -0
  47. data/lib/open_ehr/am/open_ehr_profile/data_types/basic.rb +29 -0
  48. data/lib/open_ehr/am/open_ehr_profile/data_types/quantity.rb +19 -0
  49. data/lib/open_ehr/am/open_ehr_profile/data_types/text.rb +12 -0
  50. data/lib/open_ehr/am.rb +8 -0
  51. data/lib/open_ehr/assumed_library_types.rb +627 -0
  52. data/lib/open_ehr/parser/xml_perser.rb +13 -0
  53. data/lib/open_ehr/parser.rb +19 -0
  54. data/lib/open_ehr/rm/common/archetyped.rb +182 -0
  55. data/lib/open_ehr/rm/common/change_control.rb +332 -0
  56. data/lib/open_ehr/rm/common/directory.rb +29 -0
  57. data/lib/open_ehr/rm/common/generic.rb +216 -0
  58. data/lib/open_ehr/rm/common/resource.rb +154 -0
  59. data/lib/open_ehr/rm/common.rb +14 -0
  60. data/lib/open_ehr/rm/composition/content/entry.rb +246 -0
  61. data/lib/open_ehr/rm/composition/content/navigation.rb +31 -0
  62. data/lib/open_ehr/rm/composition/content.rb +22 -0
  63. data/lib/open_ehr/rm/composition.rb +103 -0
  64. data/lib/open_ehr/rm/data_structures/history.rb +117 -0
  65. data/lib/open_ehr/rm/data_structures/item_structure/representation.rb +63 -0
  66. data/lib/open_ehr/rm/data_structures/item_structure.rb +216 -0
  67. data/lib/open_ehr/rm/data_structures.rb +25 -0
  68. data/lib/open_ehr/rm/data_types/basic.rb +108 -0
  69. data/lib/open_ehr/rm/data_types/charset.lst +818 -0
  70. data/lib/open_ehr/rm/data_types/charset_extract.rb +24 -0
  71. data/lib/open_ehr/rm/data_types/encapsulated.rb +98 -0
  72. data/lib/open_ehr/rm/data_types/quantity/date_time.rb +229 -0
  73. data/lib/open_ehr/rm/data_types/quantity.rb +403 -0
  74. data/lib/open_ehr/rm/data_types/text.rb +168 -0
  75. data/lib/open_ehr/rm/data_types/time_specification.rb +75 -0
  76. data/lib/open_ehr/rm/data_types/uri.rb +82 -0
  77. data/lib/open_ehr/rm/data_types.rb +14 -0
  78. data/lib/open_ehr/rm/demographic.rb +269 -0
  79. data/lib/open_ehr/rm/ehr.rb +162 -0
  80. data/lib/open_ehr/rm/integration.rb +27 -0
  81. data/lib/open_ehr/rm/security.rb +12 -0
  82. data/lib/open_ehr/rm/support/assumed_types.rb +81 -0
  83. data/lib/open_ehr/rm/support/definition.rb +15 -0
  84. data/lib/open_ehr/rm/support/identification.rb +408 -0
  85. data/lib/open_ehr/rm/support/measurement.rb +17 -0
  86. data/lib/open_ehr/rm/support/terminology.rb +135 -0
  87. data/lib/open_ehr/rm/support.rb +14 -0
  88. data/lib/open_ehr/rm.rb +16 -0
  89. data/lib/open_ehr/serializer.rb +272 -0
  90. data/lib/open_ehr/terminology/open_ehr_terminology.rb +41 -0
  91. data/lib/open_ehr/terminology.rb +7 -0
  92. data/lib/open_ehr/writer.rb +12 -0
  93. data/lib/open_ehr.rb +11 -0
  94. data/spec/lib/open_ehr/am/archetype/archetype_spec.rb +98 -0
  95. data/spec/lib/open_ehr/am/archetype/assertion/assertion_spec.rb +60 -0
  96. data/spec/lib/open_ehr/am/archetype/assertion/assertion_variable_spec.rb +30 -0
  97. data/spec/lib/open_ehr/am/archetype/assertion/expr_binary_operator.rb +40 -0
  98. data/spec/lib/open_ehr/am/archetype/assertion/expr_item_spec.rb +28 -0
  99. data/spec/lib/open_ehr/am/archetype/assertion/expr_leaf_spec.rb +34 -0
  100. data/spec/lib/open_ehr/am/archetype/assertion/expr_operator_spec.rb +25 -0
  101. data/spec/lib/open_ehr/am/archetype/assertion/expr_unary_operator_spec.rb +26 -0
  102. data/spec/lib/open_ehr/am/archetype/assertion/operator_kind_spec.rb +110 -0
  103. data/spec/lib/open_ehr/am/archetype/constraint_model/archetype_constraint_spec.rb +56 -0
  104. data/spec/lib/open_ehr/am/archetype/constraint_model/archetype_internal_ref_spec.rb +36 -0
  105. data/spec/lib/open_ehr/am/archetype/constraint_model/archetype_slot_spec.rb +61 -0
  106. data/spec/lib/open_ehr/am/archetype/constraint_model/c_attribute_spec.rb +59 -0
  107. data/spec/lib/open_ehr/am/archetype/constraint_model/c_complex_object_spec.rb +39 -0
  108. data/spec/lib/open_ehr/am/archetype/constraint_model/c_defined_object_spec.rb +53 -0
  109. data/spec/lib/open_ehr/am/archetype/constraint_model/c_domain_type_spec.rb +25 -0
  110. data/spec/lib/open_ehr/am/archetype/constraint_model/c_multiple_attribute_spec.rb +29 -0
  111. data/spec/lib/open_ehr/am/archetype/constraint_model/c_object_spec.rb +61 -0
  112. data/spec/lib/open_ehr/am/archetype/constraint_model/c_primitive_object_spec.rb +33 -0
  113. data/spec/lib/open_ehr/am/archetype/constraint_model/c_reference_object_spec.rb +17 -0
  114. data/spec/lib/open_ehr/am/archetype/constraint_model/c_single_attribute_spec.rb +28 -0
  115. data/spec/lib/open_ehr/am/archetype/constraint_model/cardinality_spec.rb +68 -0
  116. data/spec/lib/open_ehr/am/archetype/constraint_model/constraint_ref_spec.rb +29 -0
  117. data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_boolean_spec.rb +52 -0
  118. data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_date_spec.rb +80 -0
  119. data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_date_time_spec.rb +106 -0
  120. data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_duration_spec.rb +69 -0
  121. data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_integer_spec.rb +62 -0
  122. data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_primitive_spec.rb +39 -0
  123. data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_real_spec.rb +14 -0
  124. data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_string_spec.rb +69 -0
  125. data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_time_spec.rb +79 -0
  126. data/spec/lib/open_ehr/am/archetype/ontology/archetype_ontology_spec.rb +59 -0
  127. data/spec/lib/open_ehr/am/archetype/ontology/archetype_term_spec.rb +43 -0
  128. data/spec/lib/open_ehr/am/archetype/validity_kind_spec.rb +42 -0
  129. data/spec/lib/open_ehr/assumed_library_types/interval_spec.rb +140 -0
  130. data/spec/lib/open_ehr/assumed_library_types/iso8601_date_spec.rb +236 -0
  131. data/spec/lib/open_ehr/assumed_library_types/iso8601_date_time_spec.rb +47 -0
  132. data/spec/lib/open_ehr/assumed_library_types/iso8601_duration_spec.rb +150 -0
  133. data/spec/lib/open_ehr/assumed_library_types/iso8601_time_spec.rb +234 -0
  134. data/spec/lib/open_ehr/assumed_library_types/iso8601_timezone_spec.rb +57 -0
  135. data/spec/lib/open_ehr/assumed_library_types/time_definitions_spec.rb +136 -0
  136. data/spec/lib/open_ehr/rm/common/archetyped/archetyped_spec.rb +50 -0
  137. data/spec/lib/open_ehr/rm/common/archetyped/feeder_audit_details_spec.rb +60 -0
  138. data/spec/lib/open_ehr/rm/common/archetyped/feeder_audit_spec.rb +51 -0
  139. data/spec/lib/open_ehr/rm/common/archetyped/link_spec.rb +42 -0
  140. data/spec/lib/open_ehr/rm/common/archetyped/locatable_spec.rb +89 -0
  141. data/spec/lib/open_ehr/rm/common/archetyped/pathable_spec.rb +42 -0
  142. data/spec/lib/open_ehr/rm/common/change_control/contribution_spec.rb +56 -0
  143. data/spec/lib/open_ehr/rm/common/change_control/imported_version_spec.rb +63 -0
  144. data/spec/lib/open_ehr/rm/common/change_control/original_version_spec.rb +71 -0
  145. data/spec/lib/open_ehr/rm/common/change_control/version_spec.rb +92 -0
  146. data/spec/lib/open_ehr/rm/common/change_control/versioned_object_spec.rb +285 -0
  147. data/spec/lib/open_ehr/rm/common/directory/folder_spec.rb +26 -0
  148. data/spec/lib/open_ehr/rm/common/generic/attestation_spec.rb +62 -0
  149. data/spec/lib/open_ehr/rm/common/generic/audit_details_spec.rb +51 -0
  150. data/spec/lib/open_ehr/rm/common/generic/participation_spec.rb +36 -0
  151. data/spec/lib/open_ehr/rm/common/generic/party_identified_spec.rb +64 -0
  152. data/spec/lib/open_ehr/rm/common/generic/party_proxy_spec.rb +18 -0
  153. data/spec/lib/open_ehr/rm/common/generic/party_related_spec.rb +24 -0
  154. data/spec/lib/open_ehr/rm/common/generic/revision_history_item_spec.rb +43 -0
  155. data/spec/lib/open_ehr/rm/common/generic/revision_history_spec.rb +45 -0
  156. data/spec/lib/open_ehr/rm/common/resource/authored_resource_spec.rb +68 -0
  157. data/spec/lib/open_ehr/rm/common/resource/resource_description_item_spec.rb +105 -0
  158. data/spec/lib/open_ehr/rm/common/resource/resource_description_spec.rb +74 -0
  159. data/spec/lib/open_ehr/rm/common/resource/translation_details_spec.rb +35 -0
  160. data/spec/lib/open_ehr/rm/composition/composition_spec.rb +92 -0
  161. data/spec/lib/open_ehr/rm/composition/content/content_item_spec.rb +14 -0
  162. data/spec/lib/open_ehr/rm/composition/content/entry/action_spec.rb +69 -0
  163. data/spec/lib/open_ehr/rm/composition/content/entry/activity_spec.rb +61 -0
  164. data/spec/lib/open_ehr/rm/composition/content/entry/admin_entry_spec.rb +38 -0
  165. data/spec/lib/open_ehr/rm/composition/content/entry/care_entry_spec.rb +37 -0
  166. data/spec/lib/open_ehr/rm/composition/content/entry/entry_spec.rb +88 -0
  167. data/spec/lib/open_ehr/rm/composition/content/entry/evaluation_spec.rb +37 -0
  168. data/spec/lib/open_ehr/rm/composition/content/entry/instruction_details_spec.rb +51 -0
  169. data/spec/lib/open_ehr/rm/composition/content/entry/instruction_spec.rb +62 -0
  170. data/spec/lib/open_ehr/rm/composition/content/entry/ism_transition_spec.rb +46 -0
  171. data/spec/lib/open_ehr/rm/composition/content/entry/observation_spec.rb +45 -0
  172. data/spec/lib/open_ehr/rm/composition/content/navigation/section_spec.rb +32 -0
  173. data/spec/lib/open_ehr/rm/composition/event_context_spec.rb +88 -0
  174. data/spec/lib/open_ehr/rm/data_structures/data_structure_spec.rb +21 -0
  175. data/spec/lib/open_ehr/rm/data_structures/history/event_spec.rb +44 -0
  176. data/spec/lib/open_ehr/rm/data_structures/history/history_spec.rb +67 -0
  177. data/spec/lib/open_ehr/rm/data_structures/history/interval_event_spec.rb +43 -0
  178. data/spec/lib/open_ehr/rm/data_structures/item_structure/item_list_spec.rb +53 -0
  179. data/spec/lib/open_ehr/rm/data_structures/item_structure/item_single_spec.rb +29 -0
  180. data/spec/lib/open_ehr/rm/data_structures/item_structure/item_table_spec.rb +147 -0
  181. data/spec/lib/open_ehr/rm/data_structures/item_structure/item_tree_spec.rb +48 -0
  182. data/spec/lib/open_ehr/rm/data_structures/item_structure/representation/cluster_spec.rb +26 -0
  183. data/spec/lib/open_ehr/rm/data_structures/item_structure/representation/element_spec.rb +22 -0
  184. data/spec/lib/open_ehr/rm/data_types/basic/data_value_spec.rb +17 -0
  185. data/spec/lib/open_ehr/rm/data_types/basic/dv_boolean_spec.rb +29 -0
  186. data/spec/lib/open_ehr/rm/data_types/basic/dv_identifier_spec.rb +108 -0
  187. data/spec/lib/open_ehr/rm/data_types/basic/dv_state_spec.rb +44 -0
  188. data/spec/lib/open_ehr/rm/data_types/encapsulated/dv_encapsulated_spec.rb +42 -0
  189. data/spec/lib/open_ehr/rm/data_types/encapsulated/dv_multimedia_spec.rb +79 -0
  190. data/spec/lib/open_ehr/rm/data_types/encapsulated/dv_parsable_spec.rb +34 -0
  191. data/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_date_spec.rb +64 -0
  192. data/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_date_time_spec.rb +25 -0
  193. data/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_tempral_spec.rb +24 -0
  194. data/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_time_spec.rb +37 -0
  195. data/spec/lib/open_ehr/rm/data_types/quantity/dv_absolute_quantity_spec.rb +35 -0
  196. data/spec/lib/open_ehr/rm/data_types/quantity/dv_amount_spec.rb +105 -0
  197. data/spec/lib/open_ehr/rm/data_types/quantity/dv_count_spec.rb +12 -0
  198. data/spec/lib/open_ehr/rm/data_types/quantity/dv_interval_spec.rb +17 -0
  199. data/spec/lib/open_ehr/rm/data_types/quantity/dv_ordered_spec.rb +60 -0
  200. data/spec/lib/open_ehr/rm/data_types/quantity/dv_ordinal_spec.rb +74 -0
  201. data/spec/lib/open_ehr/rm/data_types/quantity/dv_proportion_spec.rb +162 -0
  202. data/spec/lib/open_ehr/rm/data_types/quantity/dv_quantified_spec.rb +36 -0
  203. data/spec/lib/open_ehr/rm/data_types/quantity/dv_quantity_spec.rb +78 -0
  204. data/spec/lib/open_ehr/rm/data_types/quantity/proportion_kind_spec.rb +24 -0
  205. data/spec/lib/open_ehr/rm/data_types/quantity/reference_range_spec.rb +43 -0
  206. data/spec/lib/open_ehr/rm/data_types/text/code_phrase_spec.rb +23 -0
  207. data/spec/lib/open_ehr/rm/data_types/text/dv_paragraph_spec.rb +13 -0
  208. data/spec/lib/open_ehr/rm/data_types/text/dv_text_spec.rb +57 -0
  209. data/spec/lib/open_ehr/rm/data_types/text/term_mapping_spec.rb +59 -0
  210. data/spec/lib/open_ehr/rm/data_types/uri/dv_ehr_uri_spec.rb +21 -0
  211. data/spec/lib/open_ehr/rm/data_types/uri/dv_uri_spec.rb +36 -0
  212. data/spec/lib/open_ehr/rm/demographic/actor_spec.rb +79 -0
  213. data/spec/lib/open_ehr/rm/demographic/address_spec.rb +33 -0
  214. data/spec/lib/open_ehr/rm/demographic/capability_spec.rb +37 -0
  215. data/spec/lib/open_ehr/rm/demographic/contact_spec.rb +45 -0
  216. data/spec/lib/open_ehr/rm/demographic/party_identity_spec.rb +32 -0
  217. data/spec/lib/open_ehr/rm/demographic/party_relationship_spec.rb +84 -0
  218. data/spec/lib/open_ehr/rm/demographic/party_spec.rb +133 -0
  219. data/spec/lib/open_ehr/rm/demographic/role_spec.rb +58 -0
  220. data/spec/lib/open_ehr/rm/ehr/ehr_access_spec.rb +33 -0
  221. data/spec/lib/open_ehr/rm/ehr/ehr_spec.rb +139 -0
  222. data/spec/lib/open_ehr/rm/ehr/ehr_status_spec.rb +52 -0
  223. data/spec/lib/open_ehr/rm/ehr/versioned_composition_spec.rb +33 -0
  224. data/spec/lib/open_ehr/rm/integration/generic_entry_spec.rb +31 -0
  225. data/spec/lib/open_ehr/rm/support/identification/access_group_ref_spec.rb +19 -0
  226. data/spec/lib/open_ehr/rm/support/identification/archetype_id_spec.rb +152 -0
  227. data/spec/lib/open_ehr/rm/support/identification/generic_id_spec.rb +33 -0
  228. data/spec/lib/open_ehr/rm/support/identification/hier_object_id_spec.rb +12 -0
  229. data/spec/lib/open_ehr/rm/support/identification/internet_id_spec.rb +12 -0
  230. data/spec/lib/open_ehr/rm/support/identification/iso_oid_spec.rb +12 -0
  231. data/spec/lib/open_ehr/rm/support/identification/locatable_ref_spec.rb +34 -0
  232. data/spec/lib/open_ehr/rm/support/identification/object_id_spec.rb +24 -0
  233. data/spec/lib/open_ehr/rm/support/identification/object_ref_spec.rb +33 -0
  234. data/spec/lib/open_ehr/rm/support/identification/object_version_id_spec.rb +60 -0
  235. data/spec/lib/open_ehr/rm/support/identification/party_ref_spec.rb +29 -0
  236. data/spec/lib/open_ehr/rm/support/identification/template_id_spec.rb +12 -0
  237. data/spec/lib/open_ehr/rm/support/identification/terminology_id_spec.rb +33 -0
  238. data/spec/lib/open_ehr/rm/support/identification/uid_based_id_spec.rb +50 -0
  239. data/spec/lib/open_ehr/rm/support/identification/uid_spec.rb +29 -0
  240. data/spec/lib/open_ehr/rm/support/identification/version_tree_id_spec.rb +104 -0
  241. data/spec/lib/open_ehr/rm/support/measurement_service_spec.rb +7 -0
  242. data/spec/lib/open_ehr/rm/support/terminology_service_spec.rb +24 -0
  243. data/spec/lib/open_ehr/serializer/adl-test-entry.most_minimal.test.adl +20 -0
  244. data/spec/lib/open_ehr/serializer/adl_serializer_spec.rb +47 -0
  245. data/spec/lib/open_ehr/serializer/openEHR-EHR-SECTION.test.v1.adl +38 -0
  246. data/spec/lib/open_ehr/serializer/openEHR-EHR-SECTION.test.v1.xml +58 -0
  247. data/spec/lib/open_ehr/serializer/sample_archetype_spec.rb +44 -0
  248. data/spec/lib/open_ehr/serializer/xml_serializer_spec.rb +49 -0
  249. data/spec/lib/open_ehr/terminology/open_ehr_terminology_spec.rb +40 -0
  250. data/spec/rcov.opts +1 -0
  251. data/spec/spec.opts +5 -0
  252. data/spec/spec_helper.rb +54 -0
  253. metadata +401 -0
@@ -0,0 +1,24 @@
1
+ #! /usr/bin/env ruby
2
+ # charactor sets extraction from download file from
3
+ # http://www.iana.org/assignments/character-sets
4
+ # as character-sets
5
+
6
+ class CharacterSets
7
+ def self.get_list
8
+ list = Array.new
9
+ open('character-sets') do |file|
10
+ while line = file.gets
11
+ if /^((Name:)|(Alias:)) (\S+)/ =~ line
12
+ list << $4 unless $4 == "None"
13
+ end
14
+ end
15
+ end
16
+ return list
17
+ end
18
+ end
19
+
20
+ open('charset.lst','w') do |f|
21
+ CharacterSets.get_list.each do |line|
22
+ f.puts(line)
23
+ end
24
+ end
@@ -0,0 +1,98 @@
1
+ # OpenEHR::RM::Data_Types::Encapsulated
2
+ # http://www.openehr.org/svn/specification/TAGS/Release-1.0.2/publishing/architecture/computable/UML/uml_start_view.html
3
+ # refs #51
4
+ require 'rubygems'
5
+ require 'locale/info'
6
+
7
+ module OpenEHR
8
+ module RM
9
+ module DataTypes
10
+ module Encapsulated
11
+ class DvEncapsulated < OpenEHR::RM::DataTypes::Basic::DataValue
12
+ attr_reader :language, :charset
13
+
14
+ def initialize(args = {})
15
+ super(args)
16
+ self.charset = args[:charset]
17
+ self.language = args[:language]
18
+ end
19
+
20
+ def size
21
+ @value.size
22
+ end
23
+
24
+ def language=(language)
25
+ if !language.nil? &&
26
+ !Locale::Info.language_code?(language.code_string)
27
+ raise ArgumentError, 'invalid language code'
28
+ end
29
+ @language = language
30
+ end
31
+
32
+ def charset=(charset)
33
+ if !charset.nil? && !charset_valid?(charset.code_string)
34
+ raise ArgumentError, 'invalid charset'
35
+ end
36
+ @charset = charset
37
+ end
38
+
39
+ private
40
+
41
+ def charset_valid?(charset)
42
+ result = false
43
+ open('lib/open_ehr/rm/data_types/charset.lst') do |file|
44
+ while line = file.gets
45
+ if charset == line.chomp
46
+ result = true
47
+ break
48
+ end
49
+ end
50
+ end
51
+ return result
52
+ end
53
+ end
54
+
55
+ # media type http://www.iana.org/assignments/media-types/text/
56
+ class DvMultimedia < DvEncapsulated
57
+ attr_reader :media_type
58
+ attr_accessor :uri, :data, :compression_algorithm,
59
+ :integrity_check, :integrity_check_algorithm, :alternate_text
60
+
61
+ def initialize(args = {})
62
+ super(args)
63
+ self.media_type = args[:media_type]
64
+ self.uri = args[:uri]
65
+ self.data = args[:data]
66
+ self.compression_algorithm = args[:compression_algorithm]
67
+ self.integrity_check = args[:integrity_check]
68
+ self.integrity_check_algorithm = args[:integrity_check_algorithm]
69
+ self.alternate_text = args[:alternate_text]
70
+ end
71
+
72
+ def media_type=(media_type)
73
+ if media_type.code_string.nil?
74
+ raise ArgumentError, 'media_type should not be nil'
75
+ end
76
+ @media_type = media_type
77
+ end
78
+ end
79
+
80
+ class DvParsable < DvEncapsulated
81
+ attr_reader :formalism
82
+
83
+ def initialize(args = {})
84
+ super(args)
85
+ self.formalism = args[:formalism]
86
+ end
87
+
88
+ def formalism=(formalism)
89
+ if formalism.nil? || formalism.empty?
90
+ raise ArgumentError, 'formalism is mandatory'
91
+ end
92
+ @formalism = formalism
93
+ end
94
+ end
95
+ end # of Encapsulated
96
+ end # of DataTypes
97
+ end # of RM
98
+ end # of OpenEHR
@@ -0,0 +1,229 @@
1
+ # This module is implementation of the UML:
2
+ # http://www.openehr.org/uml/release-1.0.1/Browsable/_9_0_76d0249_1109696321450_28117_5362Report.html
3
+ # Ticket refs #49
4
+ #require 'assumed_library_types'
5
+ require 'date'
6
+ include OpenEHR::RM::DataTypes::Quantity
7
+ include OpenEHR::AssumedLibraryTypes
8
+
9
+ module OpenEHR
10
+ module RM
11
+ module DataTypes
12
+ module Quantity
13
+ module DateTime
14
+ class DvTemporal < DvAbsoluteQuantity
15
+ def initialize(args = {})
16
+ self.value = args[:value]
17
+ self.magnitude_status = args[:magnitude_status]
18
+ self.accuracy = args[:accuracy]
19
+ self.normal_range = args[:normal_range]
20
+ self.normal_status = args[:normal_status]
21
+ self.other_reference_ranges = args[:other_reference_ranges]
22
+ end
23
+
24
+ def value=(value)
25
+ if value.nil? or value.empty?
26
+ raise ArgumentError, 'invalid value'
27
+ end
28
+ @value = value
29
+ end
30
+
31
+ undef magnitude=
32
+ end
33
+
34
+ class DvDate < DvTemporal
35
+ include ISO8601DateModule
36
+
37
+ DAYS_IN_MONTH = [0,31,28,31,30,31,30,31,31,30,31,30,31]
38
+
39
+ def value=(value)
40
+ super(value)
41
+ iso8601_date = ISO8601Date.new(value)
42
+ @year = iso8601_date.year
43
+ @month = iso8601_date.month
44
+ @day = iso8601_date.day
45
+ end
46
+
47
+ def magnitude
48
+ return Date.new(@year, @month, @day)-Date.new(0000,1,1)
49
+ end
50
+
51
+ def diff(other)
52
+ if self.magnitude > other.magnitude
53
+ past, future = other, self
54
+ else
55
+ past, future = self, other
56
+ end
57
+ year, month, day = 0, 0, 0
58
+ if (future.day >= past.day)
59
+ day = future.day - past.day
60
+ else
61
+ month = -1
62
+ previous_month = future.month - 1
63
+ if previous_month == 0
64
+ previous_month = 12
65
+ end
66
+ day = DAYS_IN_MONTH[previous_month] + future.day - past.day
67
+ if leapyear?(future.year) && (previous_month == 2)
68
+ day += 1
69
+ end
70
+ end
71
+ week = day / 7
72
+ if (future.month >= past.month)
73
+ month += future.month - past.month
74
+ else
75
+ year -= 1
76
+ month += future.month + 12 - past.month
77
+ end
78
+ if month < 0
79
+ year -= 1
80
+ month += 12
81
+ end
82
+ year += future.year - past.year
83
+ return DvDuration.new(:value =>
84
+ 'P' + year.to_s + 'Y' + month.to_s + 'M' +
85
+ week.to_s + 'W' + day.to_s + 'D')
86
+ end
87
+ end
88
+
89
+ class DvTime < DvTemporal
90
+ include ISO8601TimeModule
91
+
92
+ def value=(value)
93
+ super(value)
94
+ iso8601_time = ISO8601Time.new(value)
95
+ @hour = iso8601_time.hour
96
+ @minute = iso8601_time.minute
97
+ @second = iso8601_time.second
98
+ @fractional_second = iso8601_time.fractional_second
99
+ end
100
+
101
+ def magnitude
102
+ if @fractional_second.nil?
103
+ return @hour * 60 * 60 + @minute * 60 + @second
104
+ else
105
+ return @hour * 60 * 60 + @minute * 60 + @second + @fractional_second
106
+ end
107
+ end
108
+
109
+ def diff(other)
110
+ diff = (other.magnitude - self.magnitude).abs
111
+ hour = (diff / 60 / 60).to_i
112
+ minute = ((diff - hour*60*60)/60).to_i
113
+ second = (diff - hour * 60 *60 - minute * 60).to_i
114
+ fractional_second = ((diff - diff.to_i)*1000000.0).to_i/1000000.0
115
+ str = 'P0Y0M0W0DT' + hour.to_s + 'H' +
116
+ minute.to_s + 'M' + second.to_s
117
+ if @fractional_second.nil?
118
+ str += 'S'
119
+ else
120
+ str += fractional_second.to_s[1..-1] + 'S'
121
+ end
122
+ return DvDuration.new(:value => str)
123
+ end
124
+ end
125
+
126
+ class DvDateTime < DvTemporal
127
+ include OpenEHR::AssumedLibraryTypes::ISO8601DateTimeModule
128
+
129
+ def value=(value)
130
+ super(value)
131
+ iso8601date_time = AssumedLibraryTypes::ISO8601DateTime.new(value)
132
+ self.year = iso8601date_time.year
133
+ self.month = iso8601date_time.month
134
+ self.day = iso8601date_time.day
135
+ self.minute = iso8601date_time.minute
136
+ self.second = iso8601date_time.second
137
+ self.hour = iso8601date_time.hour
138
+ self.fractional_second = iso8601date_time.fractional_second
139
+ self.timezone = iso8601date_time.timezone
140
+ end
141
+
142
+ def magnitude
143
+ seconds = (((@year * 365.24 +
144
+ @month * 30.42 +
145
+ @day) * 24 + @hour) * 60 +
146
+ @minute) * 60 + @second
147
+ if @fractional_second.nil?
148
+ return seconds
149
+ else
150
+ return seconds + @fractional_second
151
+ end
152
+ end
153
+
154
+ def diff(other)
155
+ if self.magnitude >= other.magnitude
156
+ past, future = other, self
157
+ else
158
+ past, future = self, other
159
+ end
160
+ past_date, past_time = split_date_time(past)
161
+ future_date, future_time = split_date_time(future)
162
+ time_diff = future_time.magnitude - past_time.magnitude
163
+ if future_time.magnitude < past_time.magnitude
164
+ future_date.day = future_date.day - 1
165
+ time_diff += 24 * 60 * 60
166
+ end
167
+ date_duration = past_date.diff(future_date)
168
+ hour = (time_diff / 60 / 60).to_i
169
+ minute = ((time_diff - hour*60*60)/60).to_i
170
+ second = (time_diff - hour * 60 *60 - minute * 60).to_i
171
+ str = date_duration.value + 'T' + hour.to_s + 'H' +
172
+ minute.to_s + 'M' + second.to_s
173
+ if @fractional_second.nil?
174
+ return DvDuration.new(:value => str +'S')
175
+ else
176
+ fractional_second =
177
+ ((time_diff - time_diff.to_i)*1000000.0).to_i/1000000.0
178
+ return DvDuration.new(:value => str +
179
+ fractional_second.to_s[1..-1] + 'S')
180
+ end
181
+ end
182
+
183
+ private
184
+ def split_date_time(date_time)
185
+ /^(.*)T(.*)$/ =~ date_time.as_string
186
+ return DvDate.new(:value => $1), DvTime.new(:value => $2)
187
+ end
188
+ end
189
+
190
+ class DvDuration < DvAmount
191
+ include AssumedLibraryTypes::ISO8601DurationModule
192
+ attr_reader :value
193
+
194
+ def initialize(args = { })
195
+ self.value = args[:value]
196
+ self.magnitude_status = args[:magnitude_status]
197
+ self.normal_range = args[:normal_range]
198
+ self.normal_status = args[:normal_status]
199
+ self.other_reference_ranges = args[:other_reference_ranges]
200
+ end
201
+
202
+ def value=(value)
203
+ raise ArgumentError, 'value must be not nil' if value.nil?
204
+ @value = value
205
+ iso8601_duration = AssumedLibraryTypes::ISO8601Duration.new(value)
206
+ self.years = iso8601_duration.years
207
+ self.months = iso8601_duration.months
208
+ self.weeks = iso8601_duration.weeks
209
+ self.days = iso8601_duration.days
210
+ self.hours = iso8601_duration.hours
211
+ self.minutes = iso8601_duration.minutes
212
+ self.seconds = iso8601_duration.seconds
213
+ self.fractional_second = iso8601_duration.fractional_second
214
+ end
215
+
216
+ def magnitude
217
+ return ((((@year + @month/MONTH_IN_YEAR)*NOMINAL_DAYS_IN_MONTH) +
218
+ @week * DAYS_IN_WEEK + @days) * HOURS_IN_DAY * MINUTES_IN_HOUR*
219
+ SECONDS_IN_MINUTE) + @second + @fractional_second
220
+ end
221
+
222
+ undef magnitude=
223
+
224
+ end
225
+ end # of DateTime
226
+ end # of Quantity
227
+ end # of Data_Types
228
+ end # of RM
229
+ end # of OpenEHR