openehr 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (384) hide show
  1. data/.document +5 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +3 -0
  4. data/Gemfile +23 -0
  5. data/Guardfile +12 -0
  6. data/History.txt +36 -0
  7. data/PostInstall.txt +9 -0
  8. data/README.rdoc +82 -0
  9. data/Rakefile +44 -0
  10. data/VERSION +1 -0
  11. data/doc/openehr_terminology.xml +2700 -0
  12. data/lib/openehr.rb +11 -0
  13. data/lib/openehr/am.rb +8 -0
  14. data/lib/openehr/am/archetype.rb +133 -0
  15. data/lib/openehr/am/archetype/assertion.rb +190 -0
  16. data/lib/openehr/am/archetype/constraint_model.rb +328 -0
  17. data/lib/openehr/am/archetype/constraint_model/primitive.rb +327 -0
  18. data/lib/openehr/am/archetype/ontology.rb +126 -0
  19. data/lib/openehr/am/openehr_profile.rb +9 -0
  20. data/lib/openehr/am/openehr_profile/data_types.rb +13 -0
  21. data/lib/openehr/am/openehr_profile/data_types/basic.rb +114 -0
  22. data/lib/openehr/am/openehr_profile/data_types/quantity.rb +67 -0
  23. data/lib/openehr/am/openehr_profile/data_types/text.rb +22 -0
  24. data/lib/openehr/assumed_library_types.rb +691 -0
  25. data/lib/openehr/parser.rb +23 -0
  26. data/lib/openehr/parser/adl.rb +57 -0
  27. data/lib/openehr/parser/adl_grammar.tt +245 -0
  28. data/lib/openehr/parser/adl_parser.rb +52 -0
  29. data/lib/openehr/parser/cadl_grammar.tt +1527 -0
  30. data/lib/openehr/parser/cadl_node.rb +44 -0
  31. data/lib/openehr/parser/dadl.rb +13 -0
  32. data/lib/openehr/parser/dadl_grammar.tt +358 -0
  33. data/lib/openehr/parser/exception.rb +68 -0
  34. data/lib/openehr/parser/shared_token_grammar.tt +1229 -0
  35. data/lib/openehr/parser/validator.rb +19 -0
  36. data/lib/openehr/parser/xml_perser.rb +13 -0
  37. data/lib/openehr/rm.rb +15 -0
  38. data/lib/openehr/rm/common.rb +14 -0
  39. data/lib/openehr/rm/common/archetyped.rb +182 -0
  40. data/lib/openehr/rm/common/change_control.rb +332 -0
  41. data/lib/openehr/rm/common/directory.rb +29 -0
  42. data/lib/openehr/rm/common/generic.rb +216 -0
  43. data/lib/openehr/rm/common/resource.rb +154 -0
  44. data/lib/openehr/rm/composition.rb +103 -0
  45. data/lib/openehr/rm/composition/content.rb +22 -0
  46. data/lib/openehr/rm/composition/content/entry.rb +253 -0
  47. data/lib/openehr/rm/composition/content/navigation.rb +31 -0
  48. data/lib/openehr/rm/data_structures.rb +25 -0
  49. data/lib/openehr/rm/data_structures/history.rb +117 -0
  50. data/lib/openehr/rm/data_structures/item_structure.rb +218 -0
  51. data/lib/openehr/rm/data_structures/item_structure/representation.rb +63 -0
  52. data/lib/openehr/rm/data_types.rb +14 -0
  53. data/lib/openehr/rm/data_types/basic.rb +108 -0
  54. data/lib/openehr/rm/data_types/charset.lst +818 -0
  55. data/lib/openehr/rm/data_types/charset_extract.rb +24 -0
  56. data/lib/openehr/rm/data_types/encapsulated.rb +98 -0
  57. data/lib/openehr/rm/data_types/quantity.rb +402 -0
  58. data/lib/openehr/rm/data_types/quantity/date_time.rb +256 -0
  59. data/lib/openehr/rm/data_types/text.rb +169 -0
  60. data/lib/openehr/rm/data_types/time_specification.rb +75 -0
  61. data/lib/openehr/rm/data_types/uri.rb +83 -0
  62. data/lib/openehr/rm/demographic.rb +269 -0
  63. data/lib/openehr/rm/ehr.rb +162 -0
  64. data/lib/openehr/rm/integration.rb +27 -0
  65. data/lib/openehr/rm/security.rb +12 -0
  66. data/lib/openehr/rm/support.rb +14 -0
  67. data/lib/openehr/rm/support/definition.rb +15 -0
  68. data/lib/openehr/rm/support/identification.rb +412 -0
  69. data/lib/openehr/rm/support/measurement.rb +17 -0
  70. data/lib/openehr/rm/support/terminology.rb +135 -0
  71. data/lib/openehr/serializer.rb +272 -0
  72. data/lib/openehr/terminology.rb +7 -0
  73. data/lib/openehr/terminology/open_ehr_terminology.rb +41 -0
  74. data/lib/openehr/writer.rb +12 -0
  75. data/openehr.gemspec +472 -0
  76. data/spec/lib/openehr/am/archetype/archetype_spec.rb +103 -0
  77. data/spec/lib/openehr/am/archetype/assertion/assertion_spec.rb +60 -0
  78. data/spec/lib/openehr/am/archetype/assertion/assertion_variable_spec.rb +30 -0
  79. data/spec/lib/openehr/am/archetype/assertion/expr_binary_operator.rb +40 -0
  80. data/spec/lib/openehr/am/archetype/assertion/expr_item_spec.rb +28 -0
  81. data/spec/lib/openehr/am/archetype/assertion/expr_leaf_spec.rb +34 -0
  82. data/spec/lib/openehr/am/archetype/assertion/expr_operator_spec.rb +25 -0
  83. data/spec/lib/openehr/am/archetype/assertion/expr_unary_operator_spec.rb +26 -0
  84. data/spec/lib/openehr/am/archetype/assertion/operator_kind_spec.rb +114 -0
  85. data/spec/lib/openehr/am/archetype/constraint_model/archetype_constraint_spec.rb +56 -0
  86. data/spec/lib/openehr/am/archetype/constraint_model/archetype_internal_ref_spec.rb +36 -0
  87. data/spec/lib/openehr/am/archetype/constraint_model/archetype_slot_spec.rb +61 -0
  88. data/spec/lib/openehr/am/archetype/constraint_model/c_attribute_spec.rb +59 -0
  89. data/spec/lib/openehr/am/archetype/constraint_model/c_complex_object_spec.rb +39 -0
  90. data/spec/lib/openehr/am/archetype/constraint_model/c_defined_object_spec.rb +53 -0
  91. data/spec/lib/openehr/am/archetype/constraint_model/c_domain_type_spec.rb +25 -0
  92. data/spec/lib/openehr/am/archetype/constraint_model/c_multiple_attribute_spec.rb +23 -0
  93. data/spec/lib/openehr/am/archetype/constraint_model/c_object_spec.rb +61 -0
  94. data/spec/lib/openehr/am/archetype/constraint_model/c_primitive_object_spec.rb +33 -0
  95. data/spec/lib/openehr/am/archetype/constraint_model/c_reference_object_spec.rb +17 -0
  96. data/spec/lib/openehr/am/archetype/constraint_model/c_single_attribute_spec.rb +22 -0
  97. data/spec/lib/openehr/am/archetype/constraint_model/cardinality_spec.rb +68 -0
  98. data/spec/lib/openehr/am/archetype/constraint_model/constraint_ref_spec.rb +29 -0
  99. data/spec/lib/openehr/am/archetype/constraint_model/primitive/c_boolean_spec.rb +57 -0
  100. data/spec/lib/openehr/am/archetype/constraint_model/primitive/c_date_spec.rb +52 -0
  101. data/spec/lib/openehr/am/archetype/constraint_model/primitive/c_date_time_spec.rb +136 -0
  102. data/spec/lib/openehr/am/archetype/constraint_model/primitive/c_duration_spec.rb +41 -0
  103. data/spec/lib/openehr/am/archetype/constraint_model/primitive/c_integer_spec.rb +67 -0
  104. data/spec/lib/openehr/am/archetype/constraint_model/primitive/c_primitive_spec.rb +41 -0
  105. data/spec/lib/openehr/am/archetype/constraint_model/primitive/c_real_spec.rb +19 -0
  106. data/spec/lib/openehr/am/archetype/constraint_model/primitive/c_string_spec.rb +73 -0
  107. data/spec/lib/openehr/am/archetype/constraint_model/primitive/c_time_spec.rb +104 -0
  108. data/spec/lib/openehr/am/archetype/ontology/archetype_ontology_spec.rb +97 -0
  109. data/spec/lib/openehr/am/archetype/ontology/archetype_term_spec.rb +43 -0
  110. data/spec/lib/openehr/am/archetype/validity_kind_spec.rb +42 -0
  111. data/spec/lib/openehr/am/openehr_profile/data_types/basic/c_dv_state_spec.rb +34 -0
  112. data/spec/lib/openehr/am/openehr_profile/data_types/basic/non_terminal_state_spec.rb +36 -0
  113. data/spec/lib/openehr/am/openehr_profile/data_types/basic/state_machine_spec.rb +34 -0
  114. data/spec/lib/openehr/am/openehr_profile/data_types/basic/state_spec.rb +26 -0
  115. data/spec/lib/openehr/am/openehr_profile/data_types/basic/terminal_state_spec.rb +18 -0
  116. data/spec/lib/openehr/am/openehr_profile/data_types/basic/transition_spec.rb +62 -0
  117. data/spec/lib/openehr/am/openehr_profile/data_types/quantity/c_dv_ordinal_spec.rb +41 -0
  118. data/spec/lib/openehr/am/openehr_profile/data_types/quantity/c_dv_quantity_spec.rb +50 -0
  119. data/spec/lib/openehr/am/openehr_profile/data_types/quantity/c_quantity_item_spec.rb +46 -0
  120. data/spec/lib/openehr/am/openehr_profile/data_types/text/c_code_phrase_spec.rb +34 -0
  121. data/spec/lib/openehr/assumed_library_types/interval_spec.rb +145 -0
  122. data/spec/lib/openehr/assumed_library_types/iso8601_date_spec.rb +236 -0
  123. data/spec/lib/openehr/assumed_library_types/iso8601_date_time_spec.rb +47 -0
  124. data/spec/lib/openehr/assumed_library_types/iso8601_duration_spec.rb +150 -0
  125. data/spec/lib/openehr/assumed_library_types/iso8601_time_spec.rb +234 -0
  126. data/spec/lib/openehr/assumed_library_types/iso8601_timezone_spec.rb +57 -0
  127. data/spec/lib/openehr/assumed_library_types/time_definitions_spec.rb +136 -0
  128. data/spec/lib/openehr/assumed_library_types/timezone_spec.rb +42 -0
  129. data/spec/lib/openehr/parser/adl14/adl-test-ENTRY.assumed_types.v1.adl +88 -0
  130. data/spec/lib/openehr/parser/adl14/adl-test-ENTRY.basic_types.v1.adl +143 -0
  131. data/spec/lib/openehr/parser/adl14/adl-test-ENTRY.basic_types_fail.v1.adl +50 -0
  132. data/spec/lib/openehr/parser/adl14/adl-test-ENTRY.most_minimal.v1.adl +27 -0
  133. data/spec/lib/openehr/parser/adl14/adl-test-ENTRY.structure_test1.v1.adl +46 -0
  134. data/spec/lib/openehr/parser/adl14/adl-test-SOME_TYPE.generic_type_basic.draft.adl +56 -0
  135. data/spec/lib/openehr/parser/adl14/adl-test-SOME_TYPE.generic_type_use_node.draft.adl +63 -0
  136. data/spec/lib/openehr/parser/adl14/adl-test-car.paths.test.adl +80 -0
  137. data/spec/lib/openehr/parser/adl14/adl-test-car.use_node.test.adl +87 -0
  138. data/spec/lib/openehr/parser/adl14/adl-test-composition.dv_coded_text.test.adl +29 -0
  139. data/spec/lib/openehr/parser/adl14/adl-test-entry.archetype_bindings.test.adl +47 -0
  140. data/spec/lib/openehr/parser/adl14/adl-test-entry.archetype_desc_missing_purpose.test.adl +45 -0
  141. data/spec/lib/openehr/parser/adl14/adl-test-entry.archetype_description.test.adl +61 -0
  142. data/spec/lib/openehr/parser/adl14/adl-test-entry.archetype_description2.test.adl +45 -0
  143. data/spec/lib/openehr/parser/adl14/adl-test-entry.archetype_identification.test.adl +26 -0
  144. data/spec/lib/openehr/parser/adl14/adl-test-entry.archetype_internal_ref.test.adl +36 -0
  145. data/spec/lib/openehr/parser/adl14/adl-test-entry.archetype_internal_ref2.test.adl +36 -0
  146. data/spec/lib/openehr/parser/adl14/adl-test-entry.archetype_language.test.adl +47 -0
  147. data/spec/lib/openehr/parser/adl14/adl-test-entry.archetype_language_no_accreditation.test.adl +38 -0
  148. data/spec/lib/openehr/parser/adl14/adl-test-entry.archetype_language_order_of_translation_details.test.adl +40 -0
  149. data/spec/lib/openehr/parser/adl14/adl-test-entry.archetype_ontology.test.adl +25 -0
  150. data/spec/lib/openehr/parser/adl14/adl-test-entry.archetype_slot.test.adl +40 -0
  151. data/spec/lib/openehr/parser/adl14/adl-test-entry.archetype_slot.test2.adl +37 -0
  152. data/spec/lib/openehr/parser/adl14/adl-test-entry.archetype_uncommonkeys.test.adl +29 -0
  153. data/spec/lib/openehr/parser/adl14/adl-test-entry.basic_types.test.adl +272 -0
  154. data/spec/lib/openehr/parser/adl14/adl-test-entry.c_code_phrase.test.adl +77 -0
  155. data/spec/lib/openehr/parser/adl14/adl-test-entry.c_dv_ordinal.test.adl +66 -0
  156. data/spec/lib/openehr/parser/adl14/adl-test-entry.c_dv_quantity_empty.test.adl +46 -0
  157. data/spec/lib/openehr/parser/adl14/adl-test-entry.c_dv_quantity_full.test.adl +64 -0
  158. data/spec/lib/openehr/parser/adl14/adl-test-entry.c_dv_quantity_full2.test.adl +64 -0
  159. data/spec/lib/openehr/parser/adl14/adl-test-entry.c_dv_quantity_full3.test.adl +64 -0
  160. data/spec/lib/openehr/parser/adl14/adl-test-entry.c_dv_quantity_item_units_only.test.adl +55 -0
  161. data/spec/lib/openehr/parser/adl14/adl-test-entry.c_dv_quantity_list.test.adl +58 -0
  162. data/spec/lib/openehr/parser/adl14/adl-test-entry.c_dv_quantity_property.test.adl +47 -0
  163. data/spec/lib/openehr/parser/adl14/adl-test-entry.c_dv_quantity_reversed.test.adl +59 -0
  164. data/spec/lib/openehr/parser/adl14/adl-test-entry.constraint_binding.test.adl +37 -0
  165. data/spec/lib/openehr/parser/adl14/adl-test-entry.constraint_ref.test.adl +43 -0
  166. data/spec/lib/openehr/parser/adl14/adl-test-entry.datetime.test.adl +183 -0
  167. data/spec/lib/openehr/parser/adl14/adl-test-entry.domain_types.test.adl +97 -0
  168. data/spec/lib/openehr/parser/adl14/adl-test-entry.durations.test.adl +109 -0
  169. data/spec/lib/openehr/parser/adl14/adl-test-entry.empty_other_contributors.test.adl +42 -0
  170. data/spec/lib/openehr/parser/adl14/adl-test-entry.missing_language.test.adl +23 -0
  171. data/spec/lib/openehr/parser/adl14/adl-test-entry.mixed_node_types.draft.adl +61 -0
  172. data/spec/lib/openehr/parser/adl14/adl-test-entry.most_minimal.test.adl +23 -0
  173. data/spec/lib/openehr/parser/adl14/adl-test-entry.multi_language.test.adl +52 -0
  174. data/spec/lib/openehr/parser/adl14/adl-test-entry.special_string.test.adl +88 -0
  175. data/spec/lib/openehr/parser/adl14/adl-test-entry.structure_test1.test.adl +45 -0
  176. data/spec/lib/openehr/parser/adl14/adl-test-entry.structure_test2.test.adl +45 -0
  177. data/spec/lib/openehr/parser/adl14/adl-test-entry.term_binding.test.adl +37 -0
  178. data/spec/lib/openehr/parser/adl14/adl-test-entry.term_binding2.test.adl +32 -0
  179. data/spec/lib/openehr/parser/adl14/adl-test-entry.testtranslations.test.adl +83 -0
  180. data/spec/lib/openehr/parser/adl14/adl-test-entry.translations_author_language.test.adl +34 -0
  181. data/spec/lib/openehr/parser/adl14/adl-test-entry.translations_language_author.test.adl +34 -0
  182. data/spec/lib/openehr/parser/adl14/adl-test-entry.unicode_BOM_support.test.adl +41 -0
  183. data/spec/lib/openehr/parser/adl14/adl-test-entry.unicode_support.test.adl +41 -0
  184. data/spec/lib/openehr/parser/adl14/openEHR-EHR-ACTION.imaging.v1.adl +275 -0
  185. data/spec/lib/openehr/parser/adl14/openEHR-EHR-ACTION.referral.v1.adl +351 -0
  186. data/spec/lib/openehr/parser/adl14/openEHR-EHR-CLUSTER.auscultation-chest.v1.adl +765 -0
  187. data/spec/lib/openehr/parser/adl14/openEHR-EHR-CLUSTER.auscultation.v1.adl +48 -0
  188. data/spec/lib/openehr/parser/adl14/openEHR-EHR-CLUSTER.dimensions-circumference.v1.adl +134 -0
  189. data/spec/lib/openehr/parser/adl14/openEHR-EHR-CLUSTER.dimensions.v1.adl +241 -0
  190. data/spec/lib/openehr/parser/adl14/openEHR-EHR-CLUSTER.exam-abdomen.v1.adl +321 -0
  191. data/spec/lib/openehr/parser/adl14/openEHR-EHR-CLUSTER.exam-chest.v1.adl +379 -0
  192. data/spec/lib/openehr/parser/adl14/openEHR-EHR-CLUSTER.exam-fetus.v1.adl +577 -0
  193. data/spec/lib/openehr/parser/adl14/openEHR-EHR-CLUSTER.exam-generic-joint.v1.adl +146 -0
  194. data/spec/lib/openehr/parser/adl14/openEHR-EHR-CLUSTER.exam-generic-lymphnode.v1.adl +176 -0
  195. data/spec/lib/openehr/parser/adl14/openEHR-EHR-CLUSTER.exam-generic-mass.v1.adl +221 -0
  196. data/spec/lib/openehr/parser/adl14/openEHR-EHR-CLUSTER.exam-generic.v1.adl +139 -0
  197. data/spec/lib/openehr/parser/adl14/openEHR-EHR-CLUSTER.exam-nervous_system.v1.adl +116 -0
  198. data/spec/lib/openehr/parser/adl14/openEHR-EHR-CLUSTER.exam-uterine_cervix.v1.adl +420 -0
  199. data/spec/lib/openehr/parser/adl14/openEHR-EHR-CLUSTER.exam-uterus.v1.adl +293 -0
  200. data/spec/lib/openehr/parser/adl14/openEHR-EHR-COMPOSITION.discharge.v1draft.adl +53 -0
  201. data/spec/lib/openehr/parser/adl14/openEHR-EHR-COMPOSITION.encounter.v1draft.adl +45 -0
  202. data/spec/lib/openehr/parser/adl14/openEHR-EHR-EVALUATION.adverse.v1.adl +411 -0
  203. data/spec/lib/openehr/parser/adl14/openEHR-EHR-EVALUATION.columna_vertebral.v1.adl +85 -0
  204. data/spec/lib/openehr/parser/adl14/openEHR-EHR-INSTRUCTION.medication.v1.adl +88 -0
  205. data/spec/lib/openehr/parser/adl14/openEHR-EHR-INSTRUCTION.referral.v1.adl +84 -0
  206. data/spec/lib/openehr/parser/adl14/openEHR-EHR-ITEM_TREE.Laboratory_request.v1.adl +492 -0
  207. data/spec/lib/openehr/parser/adl14/openEHR-EHR-ITEM_TREE.follow_up.v1draft.adl +94 -0
  208. data/spec/lib/openehr/parser/adl14/openEHR-EHR-ITEM_TREE.imaging.v1.adl +127 -0
  209. data/spec/lib/openehr/parser/adl14/openEHR-EHR-ITEM_TREE.medication-formulation.v1.adl +457 -0
  210. data/spec/lib/openehr/parser/adl14/openEHR-EHR-ITEM_TREE.medication.v1.adl +869 -0
  211. data/spec/lib/openehr/parser/adl14/openEHR-EHR-ITEM_TREE.referral.v1.adl +494 -0
  212. data/spec/lib/openehr/parser/adl14/openEHR-EHR-OBSERVATION.apgar.v1.adl +545 -0
  213. data/spec/lib/openehr/parser/adl14/openEHR-EHR-OBSERVATION.blood_pressure.v1.adl +673 -0
  214. data/spec/lib/openehr/parser/adl14/openEHR-EHR-OBSERVATION.body_mass_index.v1.adl +166 -0
  215. data/spec/lib/openehr/parser/adl14/openEHR-EHR-OBSERVATION.lab_test.v1.adl +376 -0
  216. data/spec/lib/openehr/parser/adl14/openEHR-EHR-OBSERVATION.testassumedvalue.v1.adl +99 -0
  217. data/spec/lib/openehr/parser/adl14/openEHR-EHR-SECTION.findings.v1.adl +47 -0
  218. data/spec/lib/openehr/parser/adl14/openEHR-EHR-SECTION.reason_for_encounter.v1.adl +51 -0
  219. data/spec/lib/openehr/parser/adl14/openEHR-EHR-SECTION.summary.v1.adl +52 -0
  220. data/spec/lib/openehr/parser/adl14/openEHR-EHR-SECTION.vital_signs.v1.adl +54 -0
  221. data/spec/lib/openehr/parser/adl_archetype_internal_ref2_spec.rb +42 -0
  222. data/spec/lib/openehr/parser/adl_archetype_internal_ref_spec.rb +125 -0
  223. data/spec/lib/openehr/parser/adl_archetype_internal_ref_with_generics_spec.rb +258 -0
  224. data/spec/lib/openehr/parser/adl_archetype_ontology_binding_spec.rb +98 -0
  225. data/spec/lib/openehr/parser/adl_archetype_ontology_spec.rb +42 -0
  226. data/spec/lib/openehr/parser/adl_archetype_slot_cluster_spec.rb +101 -0
  227. data/spec/lib/openehr/parser/adl_archetype_slot_spec.rb +193 -0
  228. data/spec/lib/openehr/parser/adl_archetype_uncommon_term_keys_spec.rb +25 -0
  229. data/spec/lib/openehr/parser/adl_description_spec.rb +164 -0
  230. data/spec/lib/openehr/parser/adl_identification_spec.rb +18 -0
  231. data/spec/lib/openehr/parser/adl_language_no_accreditation_spec.rb +66 -0
  232. data/spec/lib/openehr/parser/adl_language_order_spec.rb +68 -0
  233. data/spec/lib/openehr/parser/adl_language_spec.rb +119 -0
  234. data/spec/lib/openehr/parser/adl_language_translation_author_language_spec.rb +50 -0
  235. data/spec/lib/openehr/parser/adl_language_translation_language_author_spec.rb +46 -0
  236. data/spec/lib/openehr/parser/adl_parser_spec.rb +347 -0
  237. data/spec/lib/openehr/parser/adl_path_spec.rb +176 -0
  238. data/spec/lib/openehr/parser/base_spec.rb +19 -0
  239. data/spec/lib/openehr/parser/basic_generic_type_spec.rb +18 -0
  240. data/spec/lib/openehr/parser/basic_type_spec.rb +2922 -0
  241. data/spec/lib/openehr/parser/c_dv_quantity_any_allowed_spec.rb +34 -0
  242. data/spec/lib/openehr/parser/c_dv_quantity_shared_example_for_lacked_items_spec.rb +36 -0
  243. data/spec/lib/openehr/parser/c_dv_quantity_shared_example_spec.rb +146 -0
  244. data/spec/lib/openehr/parser/cdv_ordinal_parse_spec.rb +231 -0
  245. data/spec/lib/openehr/parser/code_phrase_spec.rb +96 -0
  246. data/spec/lib/openehr/parser/constraint_binding_spec.rb +26 -0
  247. data/spec/lib/openehr/parser/constraint_ref_spec.rb +32 -0
  248. data/spec/lib/openehr/parser/date_time_spec.rb +1953 -0
  249. data/spec/lib/openehr/parser/duration_spec.rb +475 -0
  250. data/spec/lib/openehr/parser/dv_coded_text_parse_spec.rb +27 -0
  251. data/spec/lib/openehr/parser/empty_other_contributors_spec.rb +19 -0
  252. data/spec/lib/openehr/parser/lab_test_parser_spec.rb +14 -0
  253. data/spec/lib/openehr/parser/missing_language_spec.rb +20 -0
  254. data/spec/lib/openehr/parser/missing_purpose_spec.rb +23 -0
  255. data/spec/lib/openehr/parser/mixed_node_types_spec.rb +16 -0
  256. data/spec/lib/openehr/parser/most_minimal_adl_spec.rb +19 -0
  257. data/spec/lib/openehr/parser/multi_language_spec.rb +58 -0
  258. data/spec/lib/openehr/parser/parser_spec_helper.rb +7 -0
  259. data/spec/lib/openehr/parser/path_based_terminology_binding_spec.rb +30 -0
  260. data/spec/lib/openehr/parser/special_string_spec.rb +20 -0
  261. data/spec/lib/openehr/parser/structure_comment_spec.rb +21 -0
  262. data/spec/lib/openehr/parser/structure_nested_comments_spec.rb +22 -0
  263. data/spec/lib/openehr/parser/structure_spec.rb +202 -0
  264. data/spec/lib/openehr/parser/term_binding_spec.rb +54 -0
  265. data/spec/lib/openehr/parser/unicode_bom_spec.rb +17 -0
  266. data/spec/lib/openehr/parser/unicode_support_spec.rb +46 -0
  267. data/spec/lib/openehr/rm/common/archetyped/archetyped_spec.rb +50 -0
  268. data/spec/lib/openehr/rm/common/archetyped/feeder_audit_details_spec.rb +60 -0
  269. data/spec/lib/openehr/rm/common/archetyped/feeder_audit_spec.rb +51 -0
  270. data/spec/lib/openehr/rm/common/archetyped/link_spec.rb +42 -0
  271. data/spec/lib/openehr/rm/common/archetyped/locatable_spec.rb +89 -0
  272. data/spec/lib/openehr/rm/common/archetyped/pathable_spec.rb +42 -0
  273. data/spec/lib/openehr/rm/common/change_control/contribution_spec.rb +56 -0
  274. data/spec/lib/openehr/rm/common/change_control/imported_version_spec.rb +62 -0
  275. data/spec/lib/openehr/rm/common/change_control/original_version_spec.rb +71 -0
  276. data/spec/lib/openehr/rm/common/change_control/version_spec.rb +91 -0
  277. data/spec/lib/openehr/rm/common/change_control/versioned_object_spec.rb +284 -0
  278. data/spec/lib/openehr/rm/common/directory/folder_spec.rb +26 -0
  279. data/spec/lib/openehr/rm/common/generic/attestation_spec.rb +62 -0
  280. data/spec/lib/openehr/rm/common/generic/audit_details_spec.rb +51 -0
  281. data/spec/lib/openehr/rm/common/generic/participation_spec.rb +36 -0
  282. data/spec/lib/openehr/rm/common/generic/party_identified_spec.rb +64 -0
  283. data/spec/lib/openehr/rm/common/generic/party_proxy_spec.rb +18 -0
  284. data/spec/lib/openehr/rm/common/generic/party_related_spec.rb +24 -0
  285. data/spec/lib/openehr/rm/common/generic/revision_history_item_spec.rb +43 -0
  286. data/spec/lib/openehr/rm/common/generic/revision_history_spec.rb +45 -0
  287. data/spec/lib/openehr/rm/common/resource/authored_resource_spec.rb +68 -0
  288. data/spec/lib/openehr/rm/common/resource/resource_description_item_spec.rb +105 -0
  289. data/spec/lib/openehr/rm/common/resource/resource_description_spec.rb +74 -0
  290. data/spec/lib/openehr/rm/common/resource/translation_details_spec.rb +35 -0
  291. data/spec/lib/openehr/rm/composition/composition_spec.rb +92 -0
  292. data/spec/lib/openehr/rm/composition/content/content_item_spec.rb +14 -0
  293. data/spec/lib/openehr/rm/composition/content/entry/action_spec.rb +69 -0
  294. data/spec/lib/openehr/rm/composition/content/entry/activity_spec.rb +61 -0
  295. data/spec/lib/openehr/rm/composition/content/entry/admin_entry_spec.rb +38 -0
  296. data/spec/lib/openehr/rm/composition/content/entry/care_entry_spec.rb +37 -0
  297. data/spec/lib/openehr/rm/composition/content/entry/entry_spec.rb +98 -0
  298. data/spec/lib/openehr/rm/composition/content/entry/evaluation_spec.rb +37 -0
  299. data/spec/lib/openehr/rm/composition/content/entry/instruction_details_spec.rb +51 -0
  300. data/spec/lib/openehr/rm/composition/content/entry/instruction_spec.rb +62 -0
  301. data/spec/lib/openehr/rm/composition/content/entry/ism_transition_spec.rb +46 -0
  302. data/spec/lib/openehr/rm/composition/content/entry/observation_spec.rb +45 -0
  303. data/spec/lib/openehr/rm/composition/content/navigation/section_spec.rb +32 -0
  304. data/spec/lib/openehr/rm/composition/event_context_spec.rb +88 -0
  305. data/spec/lib/openehr/rm/data_structures/data_structure_spec.rb +21 -0
  306. data/spec/lib/openehr/rm/data_structures/history/event_spec.rb +44 -0
  307. data/spec/lib/openehr/rm/data_structures/history/history_spec.rb +67 -0
  308. data/spec/lib/openehr/rm/data_structures/history/interval_event_spec.rb +43 -0
  309. data/spec/lib/openehr/rm/data_structures/item_structure/item_list_spec.rb +53 -0
  310. data/spec/lib/openehr/rm/data_structures/item_structure/item_single_spec.rb +29 -0
  311. data/spec/lib/openehr/rm/data_structures/item_structure/item_table_spec.rb +147 -0
  312. data/spec/lib/openehr/rm/data_structures/item_structure/item_tree_spec.rb +48 -0
  313. data/spec/lib/openehr/rm/data_structures/item_structure/representation/cluster_spec.rb +26 -0
  314. data/spec/lib/openehr/rm/data_structures/item_structure/representation/element_spec.rb +22 -0
  315. data/spec/lib/openehr/rm/data_types/basic/data_value_spec.rb +17 -0
  316. data/spec/lib/openehr/rm/data_types/basic/dv_boolean_spec.rb +29 -0
  317. data/spec/lib/openehr/rm/data_types/basic/dv_identifier_spec.rb +108 -0
  318. data/spec/lib/openehr/rm/data_types/basic/dv_state_spec.rb +44 -0
  319. data/spec/lib/openehr/rm/data_types/encapsulated/dv_encapsulated_spec.rb +42 -0
  320. data/spec/lib/openehr/rm/data_types/encapsulated/dv_multimedia_spec.rb +79 -0
  321. data/spec/lib/openehr/rm/data_types/encapsulated/dv_parsable_spec.rb +34 -0
  322. data/spec/lib/openehr/rm/data_types/quantity/date_time/dv_date_spec.rb +64 -0
  323. data/spec/lib/openehr/rm/data_types/quantity/date_time/dv_date_time_spec.rb +26 -0
  324. data/spec/lib/openehr/rm/data_types/quantity/date_time/dv_duration_spec.rb +44 -0
  325. data/spec/lib/openehr/rm/data_types/quantity/date_time/dv_temporal_spec.rb +25 -0
  326. data/spec/lib/openehr/rm/data_types/quantity/date_time/dv_time_spec.rb +41 -0
  327. data/spec/lib/openehr/rm/data_types/quantity/dv_absolute_quantity_spec.rb +35 -0
  328. data/spec/lib/openehr/rm/data_types/quantity/dv_amount_spec.rb +105 -0
  329. data/spec/lib/openehr/rm/data_types/quantity/dv_count_spec.rb +12 -0
  330. data/spec/lib/openehr/rm/data_types/quantity/dv_interval_spec.rb +17 -0
  331. data/spec/lib/openehr/rm/data_types/quantity/dv_ordered_spec.rb +60 -0
  332. data/spec/lib/openehr/rm/data_types/quantity/dv_ordinal_spec.rb +74 -0
  333. data/spec/lib/openehr/rm/data_types/quantity/dv_proportion_spec.rb +162 -0
  334. data/spec/lib/openehr/rm/data_types/quantity/dv_quantified_spec.rb +36 -0
  335. data/spec/lib/openehr/rm/data_types/quantity/dv_quantity_spec.rb +78 -0
  336. data/spec/lib/openehr/rm/data_types/quantity/proportion_kind_spec.rb +24 -0
  337. data/spec/lib/openehr/rm/data_types/quantity/reference_range_spec.rb +43 -0
  338. data/spec/lib/openehr/rm/data_types/text/code_phrase_spec.rb +23 -0
  339. data/spec/lib/openehr/rm/data_types/text/dv_paragraph_spec.rb +13 -0
  340. data/spec/lib/openehr/rm/data_types/text/dv_text_spec.rb +79 -0
  341. data/spec/lib/openehr/rm/data_types/text/term_mapping_spec.rb +59 -0
  342. data/spec/lib/openehr/rm/data_types/uri/dv_ehr_uri_spec.rb +21 -0
  343. data/spec/lib/openehr/rm/data_types/uri/dv_uri_spec.rb +36 -0
  344. data/spec/lib/openehr/rm/demographic/actor_spec.rb +79 -0
  345. data/spec/lib/openehr/rm/demographic/address_spec.rb +33 -0
  346. data/spec/lib/openehr/rm/demographic/capability_spec.rb +37 -0
  347. data/spec/lib/openehr/rm/demographic/contact_spec.rb +45 -0
  348. data/spec/lib/openehr/rm/demographic/party_identity_spec.rb +32 -0
  349. data/spec/lib/openehr/rm/demographic/party_relationship_spec.rb +84 -0
  350. data/spec/lib/openehr/rm/demographic/party_spec.rb +131 -0
  351. data/spec/lib/openehr/rm/demographic/role_spec.rb +58 -0
  352. data/spec/lib/openehr/rm/ehr/ehr_access_spec.rb +33 -0
  353. data/spec/lib/openehr/rm/ehr/ehr_spec.rb +139 -0
  354. data/spec/lib/openehr/rm/ehr/ehr_status_spec.rb +52 -0
  355. data/spec/lib/openehr/rm/ehr/versioned_composition_spec.rb +33 -0
  356. data/spec/lib/openehr/rm/integration/generic_entry_spec.rb +31 -0
  357. data/spec/lib/openehr/rm/support/identification/access_group_ref_spec.rb +19 -0
  358. data/spec/lib/openehr/rm/support/identification/archetype_id_spec.rb +152 -0
  359. data/spec/lib/openehr/rm/support/identification/generic_id_spec.rb +33 -0
  360. data/spec/lib/openehr/rm/support/identification/hier_object_id_spec.rb +12 -0
  361. data/spec/lib/openehr/rm/support/identification/internet_id_spec.rb +12 -0
  362. data/spec/lib/openehr/rm/support/identification/iso_oid_spec.rb +12 -0
  363. data/spec/lib/openehr/rm/support/identification/locatable_ref_spec.rb +34 -0
  364. data/spec/lib/openehr/rm/support/identification/object_id_spec.rb +24 -0
  365. data/spec/lib/openehr/rm/support/identification/object_ref_spec.rb +33 -0
  366. data/spec/lib/openehr/rm/support/identification/object_version_id_spec.rb +59 -0
  367. data/spec/lib/openehr/rm/support/identification/party_ref_spec.rb +29 -0
  368. data/spec/lib/openehr/rm/support/identification/template_id_spec.rb +12 -0
  369. data/spec/lib/openehr/rm/support/identification/terminology_id_spec.rb +33 -0
  370. data/spec/lib/openehr/rm/support/identification/uid_based_id_spec.rb +50 -0
  371. data/spec/lib/openehr/rm/support/identification/uid_spec.rb +29 -0
  372. data/spec/lib/openehr/rm/support/identification/version_tree_id_spec.rb +104 -0
  373. data/spec/lib/openehr/rm/support/measurement_service_spec.rb +7 -0
  374. data/spec/lib/openehr/rm/support/terminology_service_spec.rb +24 -0
  375. data/spec/lib/openehr/serializer/adl-test-entry.most_minimal.test.adl +20 -0
  376. data/spec/lib/openehr/serializer/adl_serializer_spec.rb +47 -0
  377. data/spec/lib/openehr/serializer/openEHR-EHR-SECTION.test.v1.adl +38 -0
  378. data/spec/lib/openehr/serializer/openEHR-EHR-SECTION.test.v1.xml +58 -0
  379. data/spec/lib/openehr/serializer/sample_archetype_spec.rb +44 -0
  380. data/spec/lib/openehr/serializer/xml_serializer_spec.rb +49 -0
  381. data/spec/lib/openehr/terminology/open_ehr_terminology_spec.rb +40 -0
  382. data/spec/spec.opts +6 -0
  383. data/spec/spec_helper.rb +58 -0
  384. metadata +631 -0
@@ -0,0 +1,9 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ module OpenEHR
4
+ module AM
5
+ module OpenEHRProfile
6
+ autoload :DataTypes, 'openehr_profile/data_types'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ module OpenEHR
4
+ module AM
5
+ module OpenEHRProfile
6
+ module DataTypes
7
+ autoload :Text, 'data_types/text'
8
+ autoload :Quantity, 'data_types/quantity'
9
+ autoload :Basic, 'data_types/basic'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,114 @@
1
+ module OpenEHR
2
+ module AM
3
+ module OpenEHRProfile
4
+ module DataTypes
5
+ module Basic
6
+ include OpenEHR::AM::Archetype::ConstraintModel
7
+
8
+ class CDvState < CDomainType
9
+ attr_reader :value
10
+
11
+ def initialize(args = { })
12
+ args[:rm_type_name] = 'DvState'
13
+ super
14
+ self.value = args[:value]
15
+ end
16
+
17
+ def value=(value)
18
+ raise ArgumentError, 'value is mandatory' if value.nil?
19
+ @value = value
20
+ end
21
+ end
22
+
23
+ class StateMachine
24
+ attr_reader :states
25
+
26
+ def initialize(args = { })
27
+ self.states = args[:states]
28
+ end
29
+
30
+ def states=(states)
31
+ if states.nil? or states.empty?
32
+ raise ArgumentError, 'states are mandatory'
33
+ end
34
+ @states = states
35
+ end
36
+ end
37
+
38
+ class State
39
+ attr_reader :name
40
+
41
+ def initialize(args = { })
42
+ self.name = args[:name]
43
+ end
44
+
45
+ def name=(name)
46
+ if name.nil? or name.empty?
47
+ raise ArgumentError, 'Invalid name'
48
+ end
49
+ @name = name
50
+ end
51
+ end
52
+
53
+ class TerminalState < State
54
+
55
+ end
56
+
57
+ class NonTerminalState < State
58
+ attr_reader :transitions
59
+ def initialize(args = { })
60
+ super
61
+ self.transitions = args[:transitions]
62
+ end
63
+
64
+ def transitions=(transitions)
65
+ if transitions.nil? or transitions.empty?
66
+ raise ArgumentError, 'transition should not be empty'
67
+ end
68
+ @transitions = transitions
69
+ end
70
+ end
71
+
72
+ class Transition
73
+ attr_reader :event, :action, :guard, :next_state
74
+
75
+ def initialize(args = { })
76
+ self.event = args[:event]
77
+ self.guard = args[:guard]
78
+ self.action = args[:action]
79
+ self.next_state = args[:next_state]
80
+ end
81
+
82
+ def event=(event)
83
+ if event.nil? or event.empty?
84
+ raise ArgumentError, 'event is mandatory'
85
+ end
86
+ @event = event
87
+ end
88
+
89
+ def guard=(guard)
90
+ if !guard.nil? && guard.empty?
91
+ raise ArgumentError, 'guard should not be empty'
92
+ end
93
+ @guard = guard
94
+ end
95
+
96
+ def action=(action)
97
+ if !action.nil? && action.empty?
98
+ raise ArgumentError, 'action should not be empty'
99
+ end
100
+ @action = action
101
+ end
102
+
103
+ def next_state=(next_state)
104
+ if next_state.nil?
105
+ raise ArgumentError, 'next state is mandatory'
106
+ end
107
+ @next_state = next_state
108
+ end
109
+ end
110
+ end
111
+ end # of DataTypes
112
+ end # of OpenEHR Profile
113
+ end # of AM
114
+ end # of OpenEHR
@@ -0,0 +1,67 @@
1
+ module OpenEHR
2
+ module AM
3
+ module OpenEHRProfile
4
+ module DataTypes
5
+ module Quantity
6
+ include OpenEHR::AM::Archetype::ConstraintModel
7
+
8
+ class CDvQuantity < CDomainType
9
+ attr_accessor :property, :list
10
+
11
+ def initialize(args = { })
12
+ super
13
+ self.property = args[:property]
14
+ self.list = args[:list]
15
+ end
16
+
17
+ def any_allowed?
18
+ if @property.nil? && @list.nil?
19
+ return true
20
+ else
21
+ return false
22
+ end
23
+ end
24
+ end
25
+
26
+ class CDvOrdinal < CDomainType
27
+ attr_accessor :list
28
+ def initialize(args = { })
29
+ super
30
+ self.list = args[:list]
31
+ end
32
+
33
+ def any_allowed?
34
+ @list.nil?
35
+ end
36
+ end
37
+
38
+ class CQuantityItem
39
+ attr_accessor :magnitude, :precision
40
+ attr_reader :units
41
+
42
+ def initialize(args = { })
43
+ self.magnitude = args[:magnitude]
44
+ self.precision = args[:precision]
45
+ self.units = args[:units]
46
+ end
47
+
48
+ def units=(units)
49
+ if units.nil? or units.empty?
50
+ raise ArgumentError, 'units are mandatory'
51
+ end
52
+ @units = units
53
+ end
54
+
55
+ def precision_unconstrained?
56
+ if @precision.upper == -1 && @precision.lower == -1
57
+ return true
58
+ else
59
+ return false
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end # of DataTypes
65
+ end # of OpenEHRProfile
66
+ end # of AM
67
+ end # of OpenEHR
@@ -0,0 +1,22 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+ module OpenEHR
3
+ module AM
4
+ module OpenEHRProfile
5
+ module DataTypes
6
+ module Text
7
+ include OpenEHR::AM::Archetype::ConstraintModel
8
+ class CCodePhrase < CDomainType
9
+ attr_accessor :terminology_id, :code_list
10
+
11
+ def initialize(args = { })
12
+ super
13
+ self.terminology_id = args[:terminology_id]
14
+ self.code_list = args[:code_list]
15
+ self.assumed_value = args[:assumed_value]
16
+ end
17
+ end
18
+ end # of Text
19
+ end # of Data_Types
20
+ end # of OpenEHR Profile
21
+ end # of AM
22
+ end # of OpenEHR
@@ -0,0 +1,691 @@
1
+ # This module is related to the ticket #36
2
+ require 'date'
3
+ require 'time'
4
+
5
+ module OpenEHR
6
+ module AssumedLibraryTypes
7
+ class Any < Object
8
+
9
+ end # of Any
10
+
11
+ class Interval < Any
12
+ attr_reader :lower, :upper
13
+
14
+ def initialize(args = {})
15
+ check_lower_upper(args[:lower], args[:upper])
16
+ self.lower_included = args[:lower_included]
17
+ self.upper_included = args[:upper_included]
18
+ end
19
+
20
+ def lower=(lower)
21
+ check_lower_upper(lower, @upper)
22
+ end
23
+
24
+ def upper=(upper)
25
+ check_lower_upper(@lower, upper)
26
+ end
27
+
28
+ def lower_included?
29
+ return @lower_included
30
+ end
31
+
32
+ def lower_included=(lower_included)
33
+ if (lower == nil) && (lower_included != nil)
34
+ raise ArgumentError, "lower is not set"
35
+ end
36
+ @lower_included = lower_included
37
+ end
38
+
39
+ def lower_unbounded?
40
+ return @lower.nil?
41
+ end
42
+
43
+ def upper_included?
44
+ return @upper_included
45
+ end
46
+
47
+ def upper_included=(upper_included)
48
+ if (@upper.nil?) && (upper_included != nil)
49
+ raise ArgumentError, "upper is not set"
50
+ end
51
+ @upper_included = upper_included
52
+ end
53
+
54
+ def upper_unbounded?
55
+ return @upper.nil?
56
+ end
57
+
58
+ def has?(value)
59
+ if ((@lower.nil?||@lower < value||((@lower_included == true) && (@lower == value)))&&
60
+ (@upper.nil?||value < @upper||((@upper_included == true) && (@upper == value))))
61
+ true
62
+ else
63
+ false
64
+ end
65
+ end
66
+
67
+ def ==(value)
68
+ return (@lower == value.lower) && (@upper == value.upper) &&
69
+ (@lower_included == value.lower_included?) &&
70
+ (@upper_included == value.upper_included?)
71
+ end
72
+ private
73
+
74
+ def check_lower_upper(lower, upper)
75
+ if lower.nil? && upper.nil?
76
+ raise ArgumentError, "Either lower or upper must be assigned"
77
+ end
78
+ unless (lower.nil? || upper.nil?)
79
+ if lower > upper
80
+ raise ArgumentError, "Upper must be larger than lower."
81
+ end
82
+ end
83
+ @lower = lower
84
+ @upper = upper
85
+ end
86
+ end # end of Interval
87
+
88
+ class Timezone
89
+ attr_reader :hour, :minute, :value
90
+
91
+ def initialize(value)
92
+ self.value = value
93
+ end
94
+
95
+ def value=(value)
96
+ unless value.nil?
97
+ if /((([+-](\d{2})):?(\d{2}))|Z)/ =~ value
98
+ @value = value
99
+ if $1 == 'Z'
100
+ @hour, @minute = 0,0
101
+ else
102
+ @hour = $3.to_i
103
+ @minute = $5.to_i
104
+ end
105
+ else
106
+ raise ArgumentError, "timezone invalid"
107
+ end
108
+ else
109
+ @value = nil
110
+ end
111
+ end
112
+
113
+ def sign
114
+ unless @hour
115
+ return nil
116
+ end
117
+ if @hour < 0
118
+ return -1
119
+ else
120
+ return +1
121
+ end
122
+ end
123
+
124
+ def to_s
125
+ return value
126
+ end
127
+
128
+ alias_method :as_string, :to_s
129
+ alias_method :hours, :hour
130
+ alias_method :minutes, :minute
131
+ end
132
+
133
+ module TimeDefinitions #< Any
134
+ DAYS_IN_LEAP_YEAR = 366
135
+ DAYS_IN_WEEK = 7
136
+ DAYS_IN_YEAR = 365
137
+ HOURS_IN_DAY = 24
138
+ MAX_DAYS_IN_MONTH = 31
139
+ MAX_DAYS_IN_YEAR = 366
140
+ MINUTES_IN_HOUR = 60
141
+ MONTH_IN_YEAR = 12
142
+ NOMINAL_DAYS_IN_MONTH = 30.42
143
+ NOMINAL_DAYS_IN_YEAR = 365.24
144
+ SECONDS_IN_MINUTE = 60
145
+
146
+ def self.valid_year?(year)
147
+ return !year.nil? && year >= 0
148
+ end
149
+
150
+ def self.valid_day?(y, m, d)
151
+ unless y.nil? || m.nil? || d.nil?
152
+ return Date.valid_date?(y,m,d)
153
+ end
154
+ if (y.nil?) || (m.nil? && !d.nil?)
155
+ return false
156
+ end
157
+ return self.valid_year?(y) && self.valid_month?(m)
158
+ end
159
+
160
+ def self.valid_hour?(h,m = nil, s = nil)
161
+ if h.nil?
162
+ return false
163
+ end
164
+ if !m.nil? and !valid_minute?(m)
165
+ return false
166
+ end
167
+ if !s.nil? and (!m.nil? and !valid_second?(s))
168
+ return false
169
+ end
170
+ (h >= 0 and h < HOURS_IN_DAY) or (h == HOURS_IN_DAY and m == 0 and s == 0)
171
+ end
172
+
173
+ def self.valid_minute?(mi)
174
+ mi >= 0 and mi < MINUTES_IN_HOUR
175
+ end
176
+
177
+ def self.valid_second?(s)
178
+ s >= 0 and s < SECONDS_IN_MINUTE
179
+ end
180
+
181
+ def self.valid_month?(mo)
182
+ mo >= 1 and mo <= MONTH_IN_YEAR
183
+ end
184
+
185
+ protected
186
+ def nilthenzero(value)
187
+ return value ? value : 0
188
+ end
189
+
190
+ end # end of TimeDefinitions
191
+
192
+ module ISO8601DateModule
193
+ include TimeDefinitions
194
+ attr_reader :year, :month, :day
195
+
196
+ def year=(year)
197
+ unless TimeDefinitions.valid_year?(year)
198
+ raise ArgumentError, "Year is not valid"
199
+ end
200
+ @year = year
201
+ end
202
+
203
+ def month=(month)
204
+ raise ArgumentError, "Month is not valid" unless month.nil? or TimeDefinitions.valid_month?(month)
205
+ @month = month
206
+ end
207
+
208
+ def day=(day)
209
+
210
+ raise ArgumentError, "Day is not valid" unless day.nil? or TimeDefinitions.valid_day?(@year, @month, day)
211
+ @day = day
212
+ end
213
+
214
+ def as_string
215
+ if (!@year.nil? and !@month.nil? and !@day.nil?)
216
+ Date.new(@year, @month, @day).to_s
217
+ elsif (!@year.nil? and !@month.nil? and @day.nil?)
218
+ Date.new(@year, @month).to_s[0,7]
219
+ elsif (!@year.nil? and @month.nil? and @day.nil?)
220
+ Date.new(@year).to_s[0,4]
221
+ end
222
+ end
223
+
224
+ def to_days
225
+ days = nilthenzero(@year)*TimeDefinitions::NOMINAL_DAYS_IN_YEAR +
226
+ nilthenzero(@month)*TimeDefinitions::NOMINAL_DAYS_IN_MONTH +
227
+ nilthenzero(@day)
228
+ return days
229
+ end
230
+
231
+ def month_unknown?
232
+ @month.nil?
233
+ end
234
+
235
+ def day_unknown?
236
+ @day.nil?
237
+ end
238
+
239
+ def is_extended?
240
+ true
241
+ end
242
+
243
+ def is_partial?
244
+ month_unknown? or day_unknown?
245
+ end
246
+
247
+ protected
248
+ def leapyear?(year)
249
+ case
250
+ when (year % 400) == 0 then true
251
+ when (year % 100) == 0 then false
252
+ else year % 4 == 0
253
+ end
254
+ end
255
+ end
256
+
257
+ class ISO8601Date
258
+ include ISO8601DateModule, Comparable
259
+ def initialize(string)
260
+ /(\d{4})(?:-(\d{2})(?:-(\d{2})?)?)?/ =~ string
261
+ if $1.nil?
262
+ raise ArgumentError, 'data invalid'
263
+ else
264
+ self.year = $1.to_i
265
+ end
266
+ if $2.nil?
267
+ self.month = nil
268
+ else
269
+ self.month = $2.to_i
270
+ end
271
+ if $3.nil?
272
+ self.day = nil
273
+ else
274
+ self.day = $3.to_i
275
+ end
276
+ end
277
+
278
+ def <=>(other)
279
+ self.to_days <=> other.to_days
280
+ end
281
+
282
+ def self.valid_iso8601_date?(string)
283
+ begin
284
+ Date.parse(string)
285
+ rescue
286
+ return false
287
+ end
288
+ true
289
+ end
290
+ end # end of ISO8601_DATE
291
+
292
+ module ISO8601TimeModule
293
+ include TimeDefinitions
294
+ attr_reader :hour, :minute, :second, :fractional_second
295
+
296
+ def hour=(hour)
297
+ unless TimeDefinitions.valid_hour?(hour, @minute, @second)
298
+ raise ArgumentError, "hour is not valid"
299
+ end
300
+ @hour = hour
301
+ end
302
+
303
+ def minute_unknown?
304
+ @minute.nil?
305
+ end
306
+
307
+ def minute=(minute)
308
+ raise ArgumentError, "minute is not valid" if !minute.nil? and !TimeDefinitions.valid_minute?(minute)
309
+ @minute = minute
310
+ end
311
+
312
+ def second_unknown?
313
+ @second.nil?
314
+ end
315
+
316
+ def second=(second)
317
+ raise ArgumentError, "minute not defined" if @minute.nil? and !second.nil?
318
+ raise ArgumentError, "second is not valid" if !second.nil? and !TimeDefinitions.valid_second?(second)
319
+ @second = second
320
+ end
321
+
322
+ def fractional_second=(fractional_second)
323
+ raise ArgumentError, "minute not defined" if minute_unknown? and !fractional_second.nil?
324
+ raise ArgumentError, "second not defined" if second_unknown? and !fractional_second.nil?
325
+ if !fractional_second.nil? &&
326
+ (fractional_second < 0.0 || fractional_second >= 1.0)
327
+ raise ArgumentError, 'fractional second should be between 0.0 - 1.0'
328
+ end
329
+ @fractional_second = fractional_second
330
+ end
331
+
332
+ def has_fractional_second?
333
+ return !@fractional_second.nil?
334
+ end
335
+
336
+ def timezone=(timezone)
337
+ unless timezone.nil? or timezone.empty?
338
+ @timezone = Timezone.new(timezone)
339
+ else
340
+ @timezone = nil
341
+ end
342
+ end
343
+
344
+ def timezone
345
+ @timezone.to_s
346
+ end
347
+
348
+ def is_decimal_sign_comma?
349
+ false
350
+ end
351
+
352
+ def is_extended?
353
+ true
354
+ end
355
+
356
+ def is_partial?
357
+ second_unknown? or minute_unknown?
358
+ end
359
+
360
+ def as_string
361
+ s = sprintf("%02d", @hour)
362
+ if !@minute.nil?
363
+ s += ":" + sprintf("%02d",@minute)
364
+ if !@second.nil?
365
+ s += ":" + sprintf("%02d", @second)
366
+ if !@fractional_second.nil?
367
+ s += "." + @fractional_second.to_s[2..-1]
368
+ if !@timezone.nil?
369
+ s += @timezone.to_s
370
+ end
371
+ end
372
+ end
373
+ end
374
+ return s
375
+ end
376
+
377
+ def to_second
378
+ second = (nilthenzero(@hour)*60 + nilthenzero(@minute))*60 +
379
+ nilthenzero(@second) +
380
+ nilthenzero(@fractional_second)
381
+ return second
382
+ end
383
+ end
384
+
385
+ class ISO8601Time
386
+ include ISO8601TimeModule, Comparable
387
+ def initialize(string)
388
+ /^(\d{2}):?(\d{2})?(:?)(\d{2})?((\.|,)(\d+))?(Z|([+-](\d{2}):?(\d{2})))?$/ =~ string
389
+ if $2.nil?
390
+ self.minute = nil
391
+ else
392
+ self.minute = $2.to_i
393
+ end
394
+ if $4.nil?
395
+ self.second = nil
396
+ else
397
+ self.second = $4.to_i
398
+ end
399
+ if $1.nil?
400
+ raise ArgumentError, 'data invalid'
401
+ else
402
+ self.hour = $1.to_i
403
+ end
404
+ if $7.nil?
405
+ self.fractional_second = nil
406
+ else
407
+ self.fractional_second = ("0." + $7).to_f
408
+ end
409
+ if $8.nil?
410
+ self.timezone = nil
411
+ else
412
+ self.timezone = $8
413
+ end
414
+ end
415
+
416
+ def <=>(other)
417
+ self.to_second <=> other.to_second
418
+ end
419
+
420
+ def self.valid_iso8601_time?(s)
421
+ if /^(\d{2}):?(\d{2})?(:?)(\d{2})?((\.|,)(\d+))?(Z|([+-](\d{2}):?(\d{2})))?$/ =~ s
422
+ # ISO 8601 regular expression by H. Yuki
423
+ # http://digit.que.ne.jp/work/wiki.cgi?Perl%E3%83%A1%E3%83%A2%2FW3C%E5%BD%A2%E5%BC%8F%E3%81%AE%E6%97%A5%E6%99%82%E3%81%AE%E8%A7%A3%E6%9E%90
424
+ # (\d{4})(?:-(\d{2})(?:-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d))?)?(Z|([+-]\d{2}):(\d{2}))?)?)?)?
425
+ hh = $1; mm = $2; ss = $4; msec = $7; tz = $8
426
+ if hh.to_i == HOURS_IN_DAY and (mm.nil? or mm.to_i == 0) and (ss.nil? or ss.to_i == 0) and (msec.nil? or msec.to_i==0)
427
+ return true
428
+ end
429
+ if hh.nil? or (hh.to_i < 0 or hh.to_i >= HOURS_IN_DAY)
430
+ return false
431
+ end
432
+ if !mm.nil?
433
+ if !TimeDefinitions.valid_minute?(mm.to_i)
434
+ return false
435
+ end
436
+ end
437
+ if !ss.nil?
438
+ if !TimeDefinitions.valid_second?(ss.to_i)
439
+ return false
440
+ end
441
+ end
442
+ unless tz.nil?
443
+ timezone = Timezone.new(tz)
444
+ if timezone.hour < 0 or timezone.hour >= HOURS_IN_DAY
445
+ return false
446
+ end
447
+ if timezone.minute < 0 or timezone.minute >= MINUTES_IN_HOUR
448
+ return false
449
+ end
450
+ return true
451
+ else
452
+ return false
453
+ end
454
+ end
455
+ end
456
+ end # end of ISO8601_TIME
457
+
458
+ module ISO8601DateTimeModule
459
+ include ISO8601DateModule, ISO8601TimeModule
460
+
461
+ def as_string
462
+ if (!@year.nil? and !@month.nil? and !@day.nil?)
463
+ s = Date.new(@year, @month, @day).to_s
464
+ elsif (!@year.nil? and !@month.nil? and @day.nil?)
465
+ return Date.new(@year, @month).to_s[0,7]
466
+ elsif (!@year.nil? and @month.nil? and @day.nil?)
467
+ return Date.new(@year).to_s[0,4]
468
+ end
469
+ unless hour.nil?
470
+ s += sprintf("T%02d", @hour)
471
+ unless @minute.nil?
472
+ s += ":" + sprintf("%02d",@minute)
473
+ unless @second.nil?
474
+ s += ":" + sprintf("%02d", @second)
475
+ unless @fractional_second.nil?
476
+ s += "." + @fractional_second.to_s[2..-1]
477
+ end
478
+ end
479
+ end
480
+ unless @timezone.nil?
481
+ s += @timezone.to_s
482
+ end
483
+ end
484
+ return s
485
+ end
486
+ end
487
+
488
+ class ISO8601DateTime
489
+ include ISO8601DateTimeModule
490
+ def initialize(string)
491
+ unless /(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?T(\d{2})(?::(\d{2})(?::(\d{2})(?:(\.|,)(\d+))?)?(Z|([+-]\d{2}):?(\d{2}))?)?/ =~ string
492
+ raise ArgumentError, 'format invalid'
493
+ else
494
+ self.year = $1.to_i
495
+ end
496
+ if $2.nil?
497
+ self.month = nil
498
+ else
499
+ self.month = $2.to_i
500
+ end
501
+ if $3.nil?
502
+ self.day = nil
503
+ else
504
+ self.day = $3.to_i
505
+ end
506
+ if $5.nil?
507
+ self.minute = nil
508
+ else
509
+ self.minute = $5.to_i
510
+ end
511
+ if $6.nil?
512
+ self.second = nil
513
+ else
514
+ self.second = $6.to_i
515
+ end
516
+ if $4.nil?
517
+ self.hour = nil
518
+ else
519
+ self.hour = $4.to_i
520
+ end
521
+ if $8.nil? or $8.empty?
522
+ self.fractional_second = nil
523
+ else
524
+ self.fractional_second = ("0."+$8).to_f
525
+ end
526
+ if $9.nil?
527
+ self.timezone = nil
528
+ else
529
+ self.timezone = $9
530
+ end
531
+ end
532
+
533
+ def <=>(other)
534
+ self.magnitude <=> other.magnitude
535
+ end
536
+
537
+ protected
538
+ def magnitude
539
+ return self.to_days*HOURS_IN_DAY*MINUTES_IN_HOUR*SECONDS_IN_MINUTE +
540
+ self.to_second
541
+ end
542
+ end
543
+
544
+ class ISO8601Timezone
545
+ def initialize(string)
546
+ @timezone = Timezone.new(string)
547
+ end
548
+
549
+ def hour
550
+ return @timezone.hour
551
+ end
552
+
553
+ def minute
554
+ return @timezone.minute
555
+ end
556
+
557
+ def sign
558
+ if @timezone.hour < 0
559
+ return -1
560
+ else
561
+ return +1
562
+ end
563
+ end
564
+
565
+ def is_gmt?
566
+ return (@timezone.hour == 0 and @timezone.minute == 0)
567
+ end
568
+
569
+ def as_string
570
+ if @timezone.hour < 0
571
+ s = ''
572
+ else
573
+ s = '+'
574
+ end
575
+ sprintf("%s%02d%02d", s, @timezone.hour, @timezone.minute)
576
+ end
577
+
578
+ alias to_s as_string
579
+ alias gmt? is_gmt?
580
+ end # end of ISO8601Timezone
581
+
582
+ module ISO8601DurationModule
583
+ include TimeDefinitions
584
+ attr_reader :years, :months, :weeks, :days
585
+ attr_reader :hours, :minutes, :seconds, :fractional_second
586
+
587
+ def years=(years)
588
+ unless years.nil? || years >= 0
589
+ raise ArgumentError, 'years must be above zero'
590
+ end
591
+ @years = years
592
+ end
593
+
594
+ def months=(months)
595
+ unless months.nil? || months >= 0
596
+ raise ArgumentError, 'months must be above zero'
597
+ end
598
+ @months = months
599
+ end
600
+
601
+ def weeks=(weeks)
602
+ unless weeks.nil? || weeks >= 0
603
+ raise ArgumentError, 'weeks must be above zero'
604
+ end
605
+ @weeks = weeks
606
+ end
607
+
608
+ def days=(days)
609
+ unless days.nil? || days >= 0
610
+ raise ArgumentError, 'days must be above zero'
611
+ end
612
+ @days = days
613
+ end
614
+
615
+ def hours=(hours)
616
+ unless hours.nil? || hours >= 0
617
+ raise ArgumentError, 'hours must be above zero'
618
+ end
619
+ @hours = hours
620
+ end
621
+
622
+ def minutes=(minutes)
623
+ unless minutes.nil? || minutes >= 0
624
+ raise ArgumentError, 'minutes must be above zero'
625
+ end
626
+ @minutes = minutes
627
+ end
628
+
629
+ def seconds=(seconds)
630
+ unless seconds.nil? || seconds >= 0
631
+ raise ArgumentError, 'seconds must be above zero'
632
+ end
633
+ @seconds = seconds
634
+ end
635
+
636
+ def fractional_second=(fractional_second)
637
+ unless fractional_second.nil? || (fractional_second >= 0 && fractional_second < 1.0)
638
+ raise ArgumentError, 'fractional_second must be between 0.0 and 1.0'
639
+ end
640
+ @fractional_second = fractional_second
641
+ end
642
+
643
+ def as_string
644
+ str = 'P'
645
+ unless @years.nil?
646
+ str += @years.to_s + 'Y'
647
+ end
648
+ unless @months.nil?
649
+ str += @months.to_s + 'M'
650
+ end
651
+ unless @weeks.nil?
652
+ str += @weeks.to_s + 'W'
653
+ end
654
+ unless @days.nil?
655
+ str += @days.to_s + 'D'
656
+ end
657
+ unless @hours.nil?
658
+ str += 'T' + @hours.to_s + 'H'
659
+ unless @minutes.nil?
660
+ str += @minutes.to_s + 'M'
661
+ unless @seconds.nil?
662
+ str += @seconds.to_s
663
+ unless @fractional_second.nil?
664
+ str += @fractional_second.to_s[1 .. -1]
665
+ end
666
+ str += 'S'
667
+ end
668
+ end
669
+ end
670
+ return str
671
+ end
672
+ end
673
+
674
+ class ISO8601Duration
675
+ include ISO8601DurationModule
676
+ def initialize(str)
677
+ /^P((\d+)[Yy])?((\d+)[Mm])?((\d+)[Ww])?((\d)[dD])?(T((\d+)[Hh])?((\d+)[Mm])?((\d+)(\.\d+)?[Ss])?)?$/ =~ str
678
+ self.years = $2.to_i
679
+ self.months = $4.to_i
680
+ self.weeks = $6.to_i
681
+ self.days = $8.to_i
682
+ self.hours = $11.to_i
683
+ self.minutes = $13.to_i
684
+ self.seconds = $15.to_i
685
+ unless $16.nil?
686
+ self.fractional_second = $16.to_f
687
+ end
688
+ end
689
+ end # end of ISO8601Duration
690
+ end # end of Assumed_Types
691
+ end # end of OpenEHR