open_ehr 0.6.1
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.
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +43 -0
- data/Guardfile +9 -0
- data/History.txt +4 -0
- data/Manifest.txt +16 -0
- data/PostInstall.txt +9 -0
- data/README.rdoc +66 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/doc/README_rdoc.html +148 -0
- data/doc/created.rid +2 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +54 -0
- data/doc/js/darkfish.js +116 -0
- data/doc/js/jquery.js +32 -0
- data/doc/js/quicksearch.js +114 -0
- data/doc/js/thickbox-compressed.js +10 -0
- data/doc/openehr_terminology.xml +2700 -0
- data/doc/rdoc.css +706 -0
- data/lib/#open_ehr.rb# +11 -0
- data/lib/open_ehr/am/archetype/archetype_description/archetype_description.rb +21 -0
- data/lib/open_ehr/am/archetype/assertion.rb +190 -0
- data/lib/open_ehr/am/archetype/constraint_model/primitive.rb +296 -0
- data/lib/open_ehr/am/archetype/constraint_model.rb +340 -0
- data/lib/open_ehr/am/archetype/ontology.rb +97 -0
- data/lib/open_ehr/am/archetype.rb +134 -0
- data/lib/open_ehr/am/open_ehr_profile/data_types/basic.rb +29 -0
- data/lib/open_ehr/am/open_ehr_profile/data_types/quantity.rb +19 -0
- data/lib/open_ehr/am/open_ehr_profile/data_types/text.rb +12 -0
- data/lib/open_ehr/am.rb +8 -0
- data/lib/open_ehr/assumed_library_types.rb +627 -0
- data/lib/open_ehr/parser/xml_perser.rb +13 -0
- data/lib/open_ehr/parser.rb +19 -0
- data/lib/open_ehr/rm/common/archetyped.rb +182 -0
- data/lib/open_ehr/rm/common/change_control.rb +332 -0
- data/lib/open_ehr/rm/common/directory.rb +29 -0
- data/lib/open_ehr/rm/common/generic.rb +216 -0
- data/lib/open_ehr/rm/common/resource.rb +154 -0
- data/lib/open_ehr/rm/common.rb +14 -0
- data/lib/open_ehr/rm/composition/content/entry.rb +246 -0
- data/lib/open_ehr/rm/composition/content/navigation.rb +31 -0
- data/lib/open_ehr/rm/composition/content.rb +22 -0
- data/lib/open_ehr/rm/composition.rb +103 -0
- data/lib/open_ehr/rm/data_structures/history.rb +117 -0
- data/lib/open_ehr/rm/data_structures/item_structure/representation.rb +63 -0
- data/lib/open_ehr/rm/data_structures/item_structure.rb +216 -0
- data/lib/open_ehr/rm/data_structures.rb +25 -0
- data/lib/open_ehr/rm/data_types/basic.rb +108 -0
- data/lib/open_ehr/rm/data_types/charset.lst +818 -0
- data/lib/open_ehr/rm/data_types/charset_extract.rb +24 -0
- data/lib/open_ehr/rm/data_types/encapsulated.rb +98 -0
- data/lib/open_ehr/rm/data_types/quantity/date_time.rb +229 -0
- data/lib/open_ehr/rm/data_types/quantity.rb +403 -0
- data/lib/open_ehr/rm/data_types/text.rb +168 -0
- data/lib/open_ehr/rm/data_types/time_specification.rb +75 -0
- data/lib/open_ehr/rm/data_types/uri.rb +82 -0
- data/lib/open_ehr/rm/data_types.rb +14 -0
- data/lib/open_ehr/rm/demographic.rb +269 -0
- data/lib/open_ehr/rm/ehr.rb +162 -0
- data/lib/open_ehr/rm/integration.rb +27 -0
- data/lib/open_ehr/rm/security.rb +12 -0
- data/lib/open_ehr/rm/support/assumed_types.rb +81 -0
- data/lib/open_ehr/rm/support/definition.rb +15 -0
- data/lib/open_ehr/rm/support/identification.rb +408 -0
- data/lib/open_ehr/rm/support/measurement.rb +17 -0
- data/lib/open_ehr/rm/support/terminology.rb +135 -0
- data/lib/open_ehr/rm/support.rb +14 -0
- data/lib/open_ehr/rm.rb +16 -0
- data/lib/open_ehr/serializer.rb +272 -0
- data/lib/open_ehr/terminology/open_ehr_terminology.rb +41 -0
- data/lib/open_ehr/terminology.rb +7 -0
- data/lib/open_ehr/writer.rb +12 -0
- data/lib/open_ehr.rb +11 -0
- data/spec/lib/open_ehr/am/archetype/archetype_spec.rb +98 -0
- data/spec/lib/open_ehr/am/archetype/assertion/assertion_spec.rb +60 -0
- data/spec/lib/open_ehr/am/archetype/assertion/assertion_variable_spec.rb +30 -0
- data/spec/lib/open_ehr/am/archetype/assertion/expr_binary_operator.rb +40 -0
- data/spec/lib/open_ehr/am/archetype/assertion/expr_item_spec.rb +28 -0
- data/spec/lib/open_ehr/am/archetype/assertion/expr_leaf_spec.rb +34 -0
- data/spec/lib/open_ehr/am/archetype/assertion/expr_operator_spec.rb +25 -0
- data/spec/lib/open_ehr/am/archetype/assertion/expr_unary_operator_spec.rb +26 -0
- data/spec/lib/open_ehr/am/archetype/assertion/operator_kind_spec.rb +110 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/archetype_constraint_spec.rb +56 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/archetype_internal_ref_spec.rb +36 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/archetype_slot_spec.rb +61 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/c_attribute_spec.rb +59 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/c_complex_object_spec.rb +39 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/c_defined_object_spec.rb +53 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/c_domain_type_spec.rb +25 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/c_multiple_attribute_spec.rb +29 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/c_object_spec.rb +61 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/c_primitive_object_spec.rb +33 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/c_reference_object_spec.rb +17 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/c_single_attribute_spec.rb +28 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/cardinality_spec.rb +68 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/constraint_ref_spec.rb +29 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_boolean_spec.rb +52 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_date_spec.rb +80 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_date_time_spec.rb +106 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_duration_spec.rb +69 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_integer_spec.rb +62 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_primitive_spec.rb +39 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_real_spec.rb +14 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_string_spec.rb +69 -0
- data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_time_spec.rb +79 -0
- data/spec/lib/open_ehr/am/archetype/ontology/archetype_ontology_spec.rb +59 -0
- data/spec/lib/open_ehr/am/archetype/ontology/archetype_term_spec.rb +43 -0
- data/spec/lib/open_ehr/am/archetype/validity_kind_spec.rb +42 -0
- data/spec/lib/open_ehr/assumed_library_types/interval_spec.rb +140 -0
- data/spec/lib/open_ehr/assumed_library_types/iso8601_date_spec.rb +236 -0
- data/spec/lib/open_ehr/assumed_library_types/iso8601_date_time_spec.rb +47 -0
- data/spec/lib/open_ehr/assumed_library_types/iso8601_duration_spec.rb +150 -0
- data/spec/lib/open_ehr/assumed_library_types/iso8601_time_spec.rb +234 -0
- data/spec/lib/open_ehr/assumed_library_types/iso8601_timezone_spec.rb +57 -0
- data/spec/lib/open_ehr/assumed_library_types/time_definitions_spec.rb +136 -0
- data/spec/lib/open_ehr/rm/common/archetyped/archetyped_spec.rb +50 -0
- data/spec/lib/open_ehr/rm/common/archetyped/feeder_audit_details_spec.rb +60 -0
- data/spec/lib/open_ehr/rm/common/archetyped/feeder_audit_spec.rb +51 -0
- data/spec/lib/open_ehr/rm/common/archetyped/link_spec.rb +42 -0
- data/spec/lib/open_ehr/rm/common/archetyped/locatable_spec.rb +89 -0
- data/spec/lib/open_ehr/rm/common/archetyped/pathable_spec.rb +42 -0
- data/spec/lib/open_ehr/rm/common/change_control/contribution_spec.rb +56 -0
- data/spec/lib/open_ehr/rm/common/change_control/imported_version_spec.rb +63 -0
- data/spec/lib/open_ehr/rm/common/change_control/original_version_spec.rb +71 -0
- data/spec/lib/open_ehr/rm/common/change_control/version_spec.rb +92 -0
- data/spec/lib/open_ehr/rm/common/change_control/versioned_object_spec.rb +285 -0
- data/spec/lib/open_ehr/rm/common/directory/folder_spec.rb +26 -0
- data/spec/lib/open_ehr/rm/common/generic/attestation_spec.rb +62 -0
- data/spec/lib/open_ehr/rm/common/generic/audit_details_spec.rb +51 -0
- data/spec/lib/open_ehr/rm/common/generic/participation_spec.rb +36 -0
- data/spec/lib/open_ehr/rm/common/generic/party_identified_spec.rb +64 -0
- data/spec/lib/open_ehr/rm/common/generic/party_proxy_spec.rb +18 -0
- data/spec/lib/open_ehr/rm/common/generic/party_related_spec.rb +24 -0
- data/spec/lib/open_ehr/rm/common/generic/revision_history_item_spec.rb +43 -0
- data/spec/lib/open_ehr/rm/common/generic/revision_history_spec.rb +45 -0
- data/spec/lib/open_ehr/rm/common/resource/authored_resource_spec.rb +68 -0
- data/spec/lib/open_ehr/rm/common/resource/resource_description_item_spec.rb +105 -0
- data/spec/lib/open_ehr/rm/common/resource/resource_description_spec.rb +74 -0
- data/spec/lib/open_ehr/rm/common/resource/translation_details_spec.rb +35 -0
- data/spec/lib/open_ehr/rm/composition/composition_spec.rb +92 -0
- data/spec/lib/open_ehr/rm/composition/content/content_item_spec.rb +14 -0
- data/spec/lib/open_ehr/rm/composition/content/entry/action_spec.rb +69 -0
- data/spec/lib/open_ehr/rm/composition/content/entry/activity_spec.rb +61 -0
- data/spec/lib/open_ehr/rm/composition/content/entry/admin_entry_spec.rb +38 -0
- data/spec/lib/open_ehr/rm/composition/content/entry/care_entry_spec.rb +37 -0
- data/spec/lib/open_ehr/rm/composition/content/entry/entry_spec.rb +88 -0
- data/spec/lib/open_ehr/rm/composition/content/entry/evaluation_spec.rb +37 -0
- data/spec/lib/open_ehr/rm/composition/content/entry/instruction_details_spec.rb +51 -0
- data/spec/lib/open_ehr/rm/composition/content/entry/instruction_spec.rb +62 -0
- data/spec/lib/open_ehr/rm/composition/content/entry/ism_transition_spec.rb +46 -0
- data/spec/lib/open_ehr/rm/composition/content/entry/observation_spec.rb +45 -0
- data/spec/lib/open_ehr/rm/composition/content/navigation/section_spec.rb +32 -0
- data/spec/lib/open_ehr/rm/composition/event_context_spec.rb +88 -0
- data/spec/lib/open_ehr/rm/data_structures/data_structure_spec.rb +21 -0
- data/spec/lib/open_ehr/rm/data_structures/history/event_spec.rb +44 -0
- data/spec/lib/open_ehr/rm/data_structures/history/history_spec.rb +67 -0
- data/spec/lib/open_ehr/rm/data_structures/history/interval_event_spec.rb +43 -0
- data/spec/lib/open_ehr/rm/data_structures/item_structure/item_list_spec.rb +53 -0
- data/spec/lib/open_ehr/rm/data_structures/item_structure/item_single_spec.rb +29 -0
- data/spec/lib/open_ehr/rm/data_structures/item_structure/item_table_spec.rb +147 -0
- data/spec/lib/open_ehr/rm/data_structures/item_structure/item_tree_spec.rb +48 -0
- data/spec/lib/open_ehr/rm/data_structures/item_structure/representation/cluster_spec.rb +26 -0
- data/spec/lib/open_ehr/rm/data_structures/item_structure/representation/element_spec.rb +22 -0
- data/spec/lib/open_ehr/rm/data_types/basic/data_value_spec.rb +17 -0
- data/spec/lib/open_ehr/rm/data_types/basic/dv_boolean_spec.rb +29 -0
- data/spec/lib/open_ehr/rm/data_types/basic/dv_identifier_spec.rb +108 -0
- data/spec/lib/open_ehr/rm/data_types/basic/dv_state_spec.rb +44 -0
- data/spec/lib/open_ehr/rm/data_types/encapsulated/dv_encapsulated_spec.rb +42 -0
- data/spec/lib/open_ehr/rm/data_types/encapsulated/dv_multimedia_spec.rb +79 -0
- data/spec/lib/open_ehr/rm/data_types/encapsulated/dv_parsable_spec.rb +34 -0
- data/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_date_spec.rb +64 -0
- data/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_date_time_spec.rb +25 -0
- data/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_tempral_spec.rb +24 -0
- data/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_time_spec.rb +37 -0
- data/spec/lib/open_ehr/rm/data_types/quantity/dv_absolute_quantity_spec.rb +35 -0
- data/spec/lib/open_ehr/rm/data_types/quantity/dv_amount_spec.rb +105 -0
- data/spec/lib/open_ehr/rm/data_types/quantity/dv_count_spec.rb +12 -0
- data/spec/lib/open_ehr/rm/data_types/quantity/dv_interval_spec.rb +17 -0
- data/spec/lib/open_ehr/rm/data_types/quantity/dv_ordered_spec.rb +60 -0
- data/spec/lib/open_ehr/rm/data_types/quantity/dv_ordinal_spec.rb +74 -0
- data/spec/lib/open_ehr/rm/data_types/quantity/dv_proportion_spec.rb +162 -0
- data/spec/lib/open_ehr/rm/data_types/quantity/dv_quantified_spec.rb +36 -0
- data/spec/lib/open_ehr/rm/data_types/quantity/dv_quantity_spec.rb +78 -0
- data/spec/lib/open_ehr/rm/data_types/quantity/proportion_kind_spec.rb +24 -0
- data/spec/lib/open_ehr/rm/data_types/quantity/reference_range_spec.rb +43 -0
- data/spec/lib/open_ehr/rm/data_types/text/code_phrase_spec.rb +23 -0
- data/spec/lib/open_ehr/rm/data_types/text/dv_paragraph_spec.rb +13 -0
- data/spec/lib/open_ehr/rm/data_types/text/dv_text_spec.rb +57 -0
- data/spec/lib/open_ehr/rm/data_types/text/term_mapping_spec.rb +59 -0
- data/spec/lib/open_ehr/rm/data_types/uri/dv_ehr_uri_spec.rb +21 -0
- data/spec/lib/open_ehr/rm/data_types/uri/dv_uri_spec.rb +36 -0
- data/spec/lib/open_ehr/rm/demographic/actor_spec.rb +79 -0
- data/spec/lib/open_ehr/rm/demographic/address_spec.rb +33 -0
- data/spec/lib/open_ehr/rm/demographic/capability_spec.rb +37 -0
- data/spec/lib/open_ehr/rm/demographic/contact_spec.rb +45 -0
- data/spec/lib/open_ehr/rm/demographic/party_identity_spec.rb +32 -0
- data/spec/lib/open_ehr/rm/demographic/party_relationship_spec.rb +84 -0
- data/spec/lib/open_ehr/rm/demographic/party_spec.rb +133 -0
- data/spec/lib/open_ehr/rm/demographic/role_spec.rb +58 -0
- data/spec/lib/open_ehr/rm/ehr/ehr_access_spec.rb +33 -0
- data/spec/lib/open_ehr/rm/ehr/ehr_spec.rb +139 -0
- data/spec/lib/open_ehr/rm/ehr/ehr_status_spec.rb +52 -0
- data/spec/lib/open_ehr/rm/ehr/versioned_composition_spec.rb +33 -0
- data/spec/lib/open_ehr/rm/integration/generic_entry_spec.rb +31 -0
- data/spec/lib/open_ehr/rm/support/identification/access_group_ref_spec.rb +19 -0
- data/spec/lib/open_ehr/rm/support/identification/archetype_id_spec.rb +152 -0
- data/spec/lib/open_ehr/rm/support/identification/generic_id_spec.rb +33 -0
- data/spec/lib/open_ehr/rm/support/identification/hier_object_id_spec.rb +12 -0
- data/spec/lib/open_ehr/rm/support/identification/internet_id_spec.rb +12 -0
- data/spec/lib/open_ehr/rm/support/identification/iso_oid_spec.rb +12 -0
- data/spec/lib/open_ehr/rm/support/identification/locatable_ref_spec.rb +34 -0
- data/spec/lib/open_ehr/rm/support/identification/object_id_spec.rb +24 -0
- data/spec/lib/open_ehr/rm/support/identification/object_ref_spec.rb +33 -0
- data/spec/lib/open_ehr/rm/support/identification/object_version_id_spec.rb +60 -0
- data/spec/lib/open_ehr/rm/support/identification/party_ref_spec.rb +29 -0
- data/spec/lib/open_ehr/rm/support/identification/template_id_spec.rb +12 -0
- data/spec/lib/open_ehr/rm/support/identification/terminology_id_spec.rb +33 -0
- data/spec/lib/open_ehr/rm/support/identification/uid_based_id_spec.rb +50 -0
- data/spec/lib/open_ehr/rm/support/identification/uid_spec.rb +29 -0
- data/spec/lib/open_ehr/rm/support/identification/version_tree_id_spec.rb +104 -0
- data/spec/lib/open_ehr/rm/support/measurement_service_spec.rb +7 -0
- data/spec/lib/open_ehr/rm/support/terminology_service_spec.rb +24 -0
- data/spec/lib/open_ehr/serializer/adl-test-entry.most_minimal.test.adl +20 -0
- data/spec/lib/open_ehr/serializer/adl_serializer_spec.rb +47 -0
- data/spec/lib/open_ehr/serializer/openEHR-EHR-SECTION.test.v1.adl +38 -0
- data/spec/lib/open_ehr/serializer/openEHR-EHR-SECTION.test.v1.xml +58 -0
- data/spec/lib/open_ehr/serializer/sample_archetype_spec.rb +44 -0
- data/spec/lib/open_ehr/serializer/xml_serializer_spec.rb +49 -0
- data/spec/lib/open_ehr/terminology/open_ehr_terminology_spec.rb +40 -0
- data/spec/rcov.opts +1 -0
- data/spec/spec.opts +5 -0
- data/spec/spec_helper.rb +54 -0
- metadata +401 -0
@@ -0,0 +1,627 @@
|
|
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
|
+
private
|
68
|
+
|
69
|
+
def check_lower_upper(lower, upper)
|
70
|
+
if lower.nil? && upper.nil?
|
71
|
+
raise ArgumentError, "Either lower or upper must be assigned"
|
72
|
+
end
|
73
|
+
unless (lower.nil? || upper.nil?)
|
74
|
+
if lower > upper
|
75
|
+
raise ArgumentError, "Upper must be larger than lower."
|
76
|
+
end
|
77
|
+
end
|
78
|
+
@lower = lower
|
79
|
+
@upper = upper
|
80
|
+
end
|
81
|
+
end # end of Interval
|
82
|
+
|
83
|
+
class TimeDefinitions < Any
|
84
|
+
DAYS_IN_LEAP_YEAR = 366
|
85
|
+
DAYS_IN_WEEK = 7
|
86
|
+
DAYS_IN_YEAR = 365
|
87
|
+
HOURS_IN_DAY = 24
|
88
|
+
MAX_DAYS_IN_MONTH = 31
|
89
|
+
MAX_DAYS_IN_YEAR = 366
|
90
|
+
MINUTES_IN_HOUR = 60
|
91
|
+
MONTH_IN_YEAR = 12
|
92
|
+
NOMINAL_DAYS_IN_MONTH = 30.42
|
93
|
+
NOMINAL_DAYS_IN_YEAR = 365.24
|
94
|
+
SECONDS_IN_MINUTE = 60
|
95
|
+
|
96
|
+
def self.valid_year?(year)
|
97
|
+
return !year.nil? && year >= 0
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.valid_day?(y, m, d)
|
101
|
+
unless y.nil? || m.nil? || d.nil?
|
102
|
+
return Date.valid_date?(y,m,d)
|
103
|
+
end
|
104
|
+
if (y.nil?) || (m.nil? && !d.nil?)
|
105
|
+
return false
|
106
|
+
end
|
107
|
+
return self.valid_year?(y) && self.valid_month?(m)
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.valid_hour?(h,m = nil, s = nil)
|
111
|
+
if h.nil?
|
112
|
+
return false
|
113
|
+
end
|
114
|
+
if !m.nil? and !valid_minute?(m)
|
115
|
+
return false
|
116
|
+
end
|
117
|
+
if !s.nil? and (!m.nil? and !valid_second?(s))
|
118
|
+
return false
|
119
|
+
end
|
120
|
+
(h >= 0 and h < HOURS_IN_DAY) or (h == HOURS_IN_DAY and m == 0 and s == 0)
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.valid_minute?(mi)
|
124
|
+
mi >= 0 and mi < MINUTES_IN_HOUR
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.valid_second?(s)
|
128
|
+
s >= 0 and s < SECONDS_IN_MINUTE
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.valid_month?(mo)
|
132
|
+
mo >= 1 and mo <= MONTH_IN_YEAR
|
133
|
+
end
|
134
|
+
end # end of TimeDefinitions
|
135
|
+
|
136
|
+
module ISO8601DateModule
|
137
|
+
attr_reader :year, :month, :day
|
138
|
+
|
139
|
+
def year=(year)
|
140
|
+
unless ISO8601Date.valid_year?(year)
|
141
|
+
raise ArgumentError, "Year is not valid"
|
142
|
+
end
|
143
|
+
@year = year
|
144
|
+
end
|
145
|
+
|
146
|
+
def month=(month)
|
147
|
+
raise ArgumentError, "Month is not valid" unless month.nil? or ISO8601Date.valid_month?(month)
|
148
|
+
@month = month
|
149
|
+
end
|
150
|
+
|
151
|
+
def day=(day)
|
152
|
+
|
153
|
+
raise ArgumentError, "Day is not valid" unless day.nil? or ISO8601Date.valid_day?(@year, @month, day)
|
154
|
+
@day = day
|
155
|
+
end
|
156
|
+
|
157
|
+
def as_string
|
158
|
+
if (!@year.nil? and !@month.nil? and !@day.nil?)
|
159
|
+
Date.new(@year, @month, @day).to_s
|
160
|
+
elsif (!@year.nil? and !@month.nil? and @day.nil?)
|
161
|
+
Date.new(@year, @month).to_s[0,7]
|
162
|
+
elsif (!@year.nil? and @month.nil? and @day.nil?)
|
163
|
+
Date.new(@year).to_s[0,4]
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def to_days
|
168
|
+
days = nilthenzero(@year)*TimeDefinitions::NOMINAL_DAYS_IN_YEAR +
|
169
|
+
nilthenzero(@month)*TimeDefinitions::NOMINAL_DAYS_IN_MONTH +
|
170
|
+
nilthenzero(@day)
|
171
|
+
return days
|
172
|
+
end
|
173
|
+
|
174
|
+
def month_unknown?
|
175
|
+
@month.nil?
|
176
|
+
end
|
177
|
+
|
178
|
+
def day_unknown?
|
179
|
+
@day.nil?
|
180
|
+
end
|
181
|
+
|
182
|
+
def is_extended?
|
183
|
+
true
|
184
|
+
end
|
185
|
+
|
186
|
+
def is_partial?
|
187
|
+
month_unknown? or day_unknown?
|
188
|
+
end
|
189
|
+
|
190
|
+
protected
|
191
|
+
def leapyear?(year)
|
192
|
+
case
|
193
|
+
when (year % 400) == 0 then true
|
194
|
+
when (year % 100) == 0 then false
|
195
|
+
else year % 4 == 0
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def nilthenzero(value)
|
201
|
+
return value ? value : 0
|
202
|
+
end
|
203
|
+
|
204
|
+
class ISO8601Date < TimeDefinitions
|
205
|
+
include ISO8601DateModule, Comparable
|
206
|
+
def initialize(string)
|
207
|
+
/(\d{4})(?:-(\d{2})(?:-(\d{2})?)?)?/ =~ string
|
208
|
+
if $1.nil?
|
209
|
+
raise ArgumentError, 'data invalid'
|
210
|
+
else
|
211
|
+
self.year = $1.to_i
|
212
|
+
end
|
213
|
+
if $2.nil?
|
214
|
+
self.month = nil
|
215
|
+
else
|
216
|
+
self.month = $2.to_i
|
217
|
+
end
|
218
|
+
if $3.nil?
|
219
|
+
self.day = nil
|
220
|
+
else
|
221
|
+
self.day = $3.to_i
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def <=>(other)
|
226
|
+
self.to_days <=> other.to_days
|
227
|
+
end
|
228
|
+
|
229
|
+
def self.valid_iso8601_date?(string)
|
230
|
+
begin
|
231
|
+
Date.parse(string)
|
232
|
+
rescue
|
233
|
+
return false
|
234
|
+
end
|
235
|
+
true
|
236
|
+
end
|
237
|
+
end # end of ISO8601_DATE
|
238
|
+
|
239
|
+
module ISO8601TimeModule
|
240
|
+
attr_reader :hour, :minute, :second, :fractional_second, :timezone
|
241
|
+
|
242
|
+
def hour=(hour)
|
243
|
+
unless ISO8601Time.valid_hour?(hour, @minute, @second)
|
244
|
+
raise ArgumentError, "hour is not valid"
|
245
|
+
end
|
246
|
+
@hour = hour
|
247
|
+
end
|
248
|
+
|
249
|
+
def minute_unknown?
|
250
|
+
@minute.nil?
|
251
|
+
end
|
252
|
+
|
253
|
+
def minute=(minute)
|
254
|
+
raise ArgumentError, "minute is not valid" if !minute.nil? and !ISO8601Time.valid_minute?(minute)
|
255
|
+
@minute = minute
|
256
|
+
end
|
257
|
+
|
258
|
+
def second_unknown?
|
259
|
+
@second.nil?
|
260
|
+
end
|
261
|
+
|
262
|
+
def second=(second)
|
263
|
+
raise ArgumentError, "minute not defined" if @minute.nil? and !second.nil?
|
264
|
+
raise ArgumentError, "second is not valid" if !second.nil? and !ISO8601Time.valid_second?(second)
|
265
|
+
@second = second
|
266
|
+
end
|
267
|
+
|
268
|
+
def fractional_second=(fractional_second)
|
269
|
+
raise ArgumentError, "minute not defined" if minute_unknown? and !fractional_second.nil?
|
270
|
+
raise ArgumentError, "second not defined" if second_unknown? and !fractional_second.nil?
|
271
|
+
if !fractional_second.nil? &&
|
272
|
+
(fractional_second < 0.0 || fractional_second >= 1.0)
|
273
|
+
raise ArgumentError, 'fractional second should be between 0.0 - 1.0'
|
274
|
+
end
|
275
|
+
@fractional_second = fractional_second
|
276
|
+
end
|
277
|
+
|
278
|
+
def has_fractional_second?
|
279
|
+
return !@fractional_second.nil?
|
280
|
+
end
|
281
|
+
|
282
|
+
def timezone=(timezone)
|
283
|
+
unless timezone.nil? or timezone == 'Z'
|
284
|
+
if /[+-](\d{2}):?(\d{2})/ =~ timezone
|
285
|
+
@timezone = timezone
|
286
|
+
else
|
287
|
+
raise ArgumentError, "timezone invalid"
|
288
|
+
end
|
289
|
+
else
|
290
|
+
@timezone = nil
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
def is_decimal_sign_comma?
|
295
|
+
false
|
296
|
+
end
|
297
|
+
|
298
|
+
def is_extended?
|
299
|
+
true
|
300
|
+
end
|
301
|
+
|
302
|
+
def is_partial?
|
303
|
+
second_unknown? or minute_unknown?
|
304
|
+
end
|
305
|
+
|
306
|
+
def as_string
|
307
|
+
s = sprintf("%02d", @hour)
|
308
|
+
if !@minute.nil?
|
309
|
+
s += ":" + sprintf("%02d",@minute)
|
310
|
+
if !@second.nil?
|
311
|
+
s += ":" + sprintf("%02d", @second)
|
312
|
+
if !@fractional_second.nil?
|
313
|
+
s += "." + @fractional_second.to_s[2..-1]
|
314
|
+
if !@timezone.nil?
|
315
|
+
s += @timezone
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
return s
|
321
|
+
end
|
322
|
+
|
323
|
+
def to_second
|
324
|
+
second = (nilthenzero(@hour)*60 + nilthenzero(@minute))*60 +
|
325
|
+
nilthenzero(@second) +
|
326
|
+
nilthenzero(@fractional_second)
|
327
|
+
return second
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
class ISO8601Time < TimeDefinitions
|
332
|
+
include ISO8601TimeModule, Comparable
|
333
|
+
def initialize(string)
|
334
|
+
/(\d{2}):?(\d{2})?(:?)(\d{2})?((\.|,)(\d+))?(Z|([+-](\d{2}):?(\d{2})))?/ =~ string
|
335
|
+
if $2.nil?
|
336
|
+
self.minute = nil
|
337
|
+
else
|
338
|
+
self.minute = $2.to_i
|
339
|
+
end
|
340
|
+
if $4.nil?
|
341
|
+
self.second = nil
|
342
|
+
else
|
343
|
+
self.second = $4.to_i
|
344
|
+
end
|
345
|
+
if $1.nil?
|
346
|
+
raise ArgumentError, 'data invalid'
|
347
|
+
else
|
348
|
+
self.hour = $1.to_i
|
349
|
+
end
|
350
|
+
if $7.nil?
|
351
|
+
self.fractional_second = nil
|
352
|
+
else
|
353
|
+
self.fractional_second = ("0." + $7).to_f
|
354
|
+
end
|
355
|
+
if $8.nil?
|
356
|
+
self.timezone = nil
|
357
|
+
else
|
358
|
+
self.timezone = $8
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
def <=>(other)
|
363
|
+
self.to_second <=> other.to_second
|
364
|
+
end
|
365
|
+
|
366
|
+
def self.valid_iso8601_time?(s)
|
367
|
+
if /^(\d{2}):?(\d{2})?(:?)(\d{2})?((\.|,)(\d+))?(Z|([+-](\d{2}):?(\d{2})))?$/ =~ s
|
368
|
+
# ISO 8601 regular expression by H. Yuki
|
369
|
+
# 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
|
370
|
+
# (\d{4})(?:-(\d{2})(?:-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d))?)?(Z|([+-]\d{2}):(\d{2}))?)?)?)?
|
371
|
+
hh = $1; mm = $2; ss = $4; msec = $7; tz = $8
|
372
|
+
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)
|
373
|
+
return true
|
374
|
+
end
|
375
|
+
if hh.nil? or (hh.to_i < 0 or hh.to_i >= HOURS_IN_DAY)
|
376
|
+
return false
|
377
|
+
end
|
378
|
+
if !mm.nil?
|
379
|
+
if !self.valid_minute?(mm.to_i)
|
380
|
+
return false
|
381
|
+
end
|
382
|
+
end
|
383
|
+
if !ss.nil?
|
384
|
+
if !self.valid_second?(ss.to_i)
|
385
|
+
return false
|
386
|
+
end
|
387
|
+
end
|
388
|
+
if !tz.nil? and tz != "Z"
|
389
|
+
if /[+-](\d{2}):?(\d{2})/ =~ tz
|
390
|
+
h = $1; m = $2
|
391
|
+
if h.to_i < 0 or h.to_i >= HOURS_IN_DAY
|
392
|
+
return false
|
393
|
+
end
|
394
|
+
if m.to_i < 0 or m.to_i >= MINUTES_IN_HOUR
|
395
|
+
return false
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
return true
|
400
|
+
else
|
401
|
+
return false
|
402
|
+
end
|
403
|
+
end
|
404
|
+
end # end of ISO8601_TIME
|
405
|
+
|
406
|
+
module ISO8601DateTimeModule
|
407
|
+
include ISO8601DateModule, ISO8601TimeModule
|
408
|
+
def as_string
|
409
|
+
if (!@year.nil? and !@month.nil? and !@day.nil?)
|
410
|
+
s = Date.new(@year, @month, @day).to_s
|
411
|
+
elsif (!@year.nil? and !@month.nil? and @day.nil?)
|
412
|
+
return Date.new(@year, @month).to_s[0,7]
|
413
|
+
elsif (!@year.nil? and @month.nil? and @day.nil?)
|
414
|
+
return Date.new(@year).to_s[0,4]
|
415
|
+
end
|
416
|
+
unless hour.nil?
|
417
|
+
s += sprintf("T%02d", @hour)
|
418
|
+
unless @minute.nil?
|
419
|
+
s += ":" + sprintf("%02d",@minute)
|
420
|
+
unless @second.nil?
|
421
|
+
s += ":" + sprintf("%02d", @second)
|
422
|
+
unless @fractional_second.nil?
|
423
|
+
s += "." + @fractional_second.to_s[2..-1]
|
424
|
+
unless @timezone.nil?
|
425
|
+
s += @timezone
|
426
|
+
end
|
427
|
+
end
|
428
|
+
end
|
429
|
+
end
|
430
|
+
end
|
431
|
+
return s
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
435
|
+
class ISO8601DateTime < ISO8601Date
|
436
|
+
include ISO8601DateTimeModule
|
437
|
+
def initialize(string)
|
438
|
+
unless /(\d{4})(?:-(\d{2})(?:-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(Z|([+-]\d{2}):?(\d{2}))?)?)?)?/ =~ string
|
439
|
+
raise ArgumentError, 'format invalid'
|
440
|
+
else
|
441
|
+
self.year = $1.to_i
|
442
|
+
end
|
443
|
+
if $2.nil?
|
444
|
+
self.month = nil
|
445
|
+
else
|
446
|
+
self.month = $2.to_i
|
447
|
+
end
|
448
|
+
if $3.nil?
|
449
|
+
self.day = nil
|
450
|
+
else
|
451
|
+
self.day = $3.to_i
|
452
|
+
end
|
453
|
+
if $5.nil?
|
454
|
+
self.minute = nil
|
455
|
+
else
|
456
|
+
self.minute = $5.to_i
|
457
|
+
end
|
458
|
+
if $6.nil?
|
459
|
+
self.second = nil
|
460
|
+
else
|
461
|
+
self.second = $6.to_i
|
462
|
+
end
|
463
|
+
if $4.nil?
|
464
|
+
self.hour = nil
|
465
|
+
else
|
466
|
+
self.hour = $4.to_i
|
467
|
+
end
|
468
|
+
if $7.nil? or $7.empty?
|
469
|
+
self.fractional_second = nil
|
470
|
+
else
|
471
|
+
self.fractional_second = ("0."+$7).to_f
|
472
|
+
end
|
473
|
+
if $8.nil?
|
474
|
+
self.timezone = nil
|
475
|
+
else
|
476
|
+
self.timezone = $9+$10
|
477
|
+
end
|
478
|
+
end
|
479
|
+
|
480
|
+
def <=>(other)
|
481
|
+
self.magnitude <=> other.magnitude
|
482
|
+
end
|
483
|
+
|
484
|
+
protected
|
485
|
+
def magnitude
|
486
|
+
return self.to_days*HOURS_IN_DAY*MINUTES_IN_HOUR*SECONDS_IN_MINUTE +
|
487
|
+
self.to_second
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
class ISO8601Timezone
|
492
|
+
attr_accessor :sign, :hour, :minute
|
493
|
+
|
494
|
+
def initialize(string)
|
495
|
+
unless /(Z|(([+-])(\d{2}):?(\d{2})))/ =~ string
|
496
|
+
raise ArgumentError, 'invaild format'
|
497
|
+
end
|
498
|
+
if $1 == 'Z'
|
499
|
+
@sign, @hour, @minute = +1, 0, 0
|
500
|
+
else
|
501
|
+
@sign, @hour, @minute = ($3+'1').to_i, $4.to_i , $5.to_i
|
502
|
+
end
|
503
|
+
end
|
504
|
+
|
505
|
+
def is_gmt?
|
506
|
+
@sign == +1 and @hour == 0 and @minute == 0
|
507
|
+
end
|
508
|
+
|
509
|
+
def as_string
|
510
|
+
if @sign == +1
|
511
|
+
s = "+"
|
512
|
+
elsif @sign == -1
|
513
|
+
s = "-"
|
514
|
+
end
|
515
|
+
sprintf("%s%02d%02d", s, @hour, @minute)
|
516
|
+
end
|
517
|
+
end # end of ISO8601Timezone
|
518
|
+
|
519
|
+
module ISO8601DurationModule
|
520
|
+
attr_reader :years, :months, :weeks, :days
|
521
|
+
attr_reader :hours, :minutes, :seconds, :fractional_second
|
522
|
+
|
523
|
+
def years=(years)
|
524
|
+
unless years.nil? || years >= 0
|
525
|
+
raise ArgumentError, 'years must be above zero'
|
526
|
+
end
|
527
|
+
@years = years
|
528
|
+
end
|
529
|
+
|
530
|
+
def months=(months)
|
531
|
+
unless months.nil? || months >= 0
|
532
|
+
raise ArgumentError, 'months must be above zero'
|
533
|
+
end
|
534
|
+
@months = months
|
535
|
+
end
|
536
|
+
|
537
|
+
def weeks=(weeks)
|
538
|
+
unless weeks.nil? || weeks >= 0
|
539
|
+
raise ArgumentError, 'weeks must be above zero'
|
540
|
+
end
|
541
|
+
@weeks = weeks
|
542
|
+
end
|
543
|
+
|
544
|
+
def days=(days)
|
545
|
+
unless days.nil? || days >= 0
|
546
|
+
raise ArgumentError, 'days must be above zero'
|
547
|
+
end
|
548
|
+
@days = days
|
549
|
+
end
|
550
|
+
|
551
|
+
def hours=(hours)
|
552
|
+
unless hours.nil? || hours >= 0
|
553
|
+
raise ArgumentError, 'hours must be above zero'
|
554
|
+
end
|
555
|
+
@hours = hours
|
556
|
+
end
|
557
|
+
|
558
|
+
def minutes=(minutes)
|
559
|
+
unless minutes.nil? || minutes >= 0
|
560
|
+
raise ArgumentError, 'minutes must be above zero'
|
561
|
+
end
|
562
|
+
@minutes = minutes
|
563
|
+
end
|
564
|
+
|
565
|
+
def seconds=(seconds)
|
566
|
+
unless seconds.nil? || seconds >= 0
|
567
|
+
raise ArgumentError, 'seconds must be above zero'
|
568
|
+
end
|
569
|
+
@seconds = seconds
|
570
|
+
end
|
571
|
+
|
572
|
+
def fractional_second=(fractional_second)
|
573
|
+
unless fractional_second.nil? || (fractional_second >= 0 && fractional_second < 1.0)
|
574
|
+
raise ArgumentError, 'fractional_second must be between 0.0 and 1.0'
|
575
|
+
end
|
576
|
+
@fractional_second = fractional_second
|
577
|
+
end
|
578
|
+
|
579
|
+
def as_string
|
580
|
+
str = 'P'
|
581
|
+
unless @years.nil?
|
582
|
+
str += @years.to_s + 'Y'
|
583
|
+
end
|
584
|
+
unless @months.nil?
|
585
|
+
str += @months.to_s + 'M'
|
586
|
+
end
|
587
|
+
unless @weeks.nil?
|
588
|
+
str += @weeks.to_s + 'W'
|
589
|
+
end
|
590
|
+
unless @days.nil?
|
591
|
+
str += @days.to_s + 'D'
|
592
|
+
end
|
593
|
+
unless @hours.nil?
|
594
|
+
str += 'T' + @hours.to_s + 'H'
|
595
|
+
unless @minutes.nil?
|
596
|
+
str += @minutes.to_s + 'M'
|
597
|
+
unless @seconds.nil?
|
598
|
+
str += @seconds.to_s
|
599
|
+
unless @fractional_second.nil?
|
600
|
+
str += @fractional_second.to_s[1 .. -1]
|
601
|
+
end
|
602
|
+
str += 'S'
|
603
|
+
end
|
604
|
+
end
|
605
|
+
end
|
606
|
+
return str
|
607
|
+
end
|
608
|
+
end
|
609
|
+
|
610
|
+
class ISO8601Duration < TimeDefinitions
|
611
|
+
include ISO8601DurationModule
|
612
|
+
def initialize(str)
|
613
|
+
/^P((\d+)Y)?((\d+)M)?((\d+)W)?((\d)D)?(T((\d+)H)?((\d+)M)?((\d+)(\.\d+)?S)?)?$/ =~ str
|
614
|
+
self.years = $2.to_i
|
615
|
+
self.months = $4.to_i
|
616
|
+
self.weeks = $6.to_i
|
617
|
+
self.days = $8.to_i
|
618
|
+
self.hours = $11.to_i
|
619
|
+
self.minutes = $13.to_i
|
620
|
+
self.seconds = $15.to_i
|
621
|
+
unless $16.nil?
|
622
|
+
self.fractional_second = $16.to_f
|
623
|
+
end
|
624
|
+
end
|
625
|
+
end # end of ISO8601Duration
|
626
|
+
end # end of Assumed_Types
|
627
|
+
end # end of OpenEHR
|