open_ehr 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/History.txt +3 -0
  2. data/README.rdoc +3 -3
  3. data/VERSION +1 -1
  4. data/lib/open_ehr/am/archetype/constraint_model/primitive.rb +61 -34
  5. data/lib/open_ehr/am/openehr_profile/data_types/basic.rb +27 -0
  6. data/lib/open_ehr/am/openehr_profile/data_types/quantity.rb +18 -0
  7. data/lib/open_ehr/am/openehr_profile/data_types/text.rb +22 -0
  8. data/lib/open_ehr/am/openehr_profile/data_types.rb +12 -0
  9. data/lib/open_ehr/am/openehr_profile.rb +10 -0
  10. data/lib/open_ehr/am.rb +2 -0
  11. data/lib/open_ehr/assumed_library_types.rb +30 -25
  12. data/lib/open_ehr/parser/cadl_grammar.tt +479 -163
  13. data/lib/open_ehr/parser/shared_token_grammar.tt +63 -43
  14. data/lib/open_ehr/rm/data_types/quantity/date_time.rb +27 -14
  15. data/lib/open_ehr.rb +1 -1
  16. data/open_ehr.gemspec +17 -6
  17. data/spec/lib/open_ehr/am/archetype/assertion/operator_kind_spec.rb +4 -0
  18. data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_date_spec.rb +20 -48
  19. data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_date_time_spec.rb +33 -8
  20. data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_duration_spec.rb +19 -52
  21. data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_string_spec.rb +2 -3
  22. data/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_time_spec.rb +27 -7
  23. data/spec/lib/open_ehr/am/archetype/ontology/archetype_ontology_spec.rb +0 -1
  24. data/spec/lib/open_ehr/am/openehr_profile/data_types/text/c_code_phrase_spec.rb +35 -0
  25. data/spec/lib/open_ehr/parser/adl14/adl-test-SOME_TYPE.generic_type_basic.draft.adl +1 -1
  26. data/spec/lib/open_ehr/parser/adl14/adl-test-entry.archetype_slot.test.adl +1 -1
  27. data/spec/lib/open_ehr/parser/adl14/adl-test-entry.archetype_slot.test2.adl +1 -1
  28. data/spec/lib/open_ehr/parser/adl14/adl-test-entry.basic_types.test.adl +3 -3
  29. data/spec/lib/open_ehr/parser/adl14/adl-test-entry.c_code_phrase.test.adl +1 -1
  30. data/spec/lib/open_ehr/parser/adl14/adl-test-entry.datetime.test.adl +1 -1
  31. data/spec/lib/open_ehr/parser/adl14/adl-test-entry.durations.test.adl +2 -4
  32. data/spec/lib/open_ehr/parser/adl_archetype_internal_ref_with_generics_spec.rb +6 -6
  33. data/spec/lib/open_ehr/parser/adl_archetype_slot_cluster_spec.rb +101 -0
  34. data/spec/lib/open_ehr/parser/adl_archetype_slot_spec.rb +193 -0
  35. data/spec/lib/open_ehr/parser/adl_archetype_uncommon_term_keys_spec.rb +25 -0
  36. data/spec/lib/open_ehr/parser/adl_parser_spec.rb +6 -6
  37. data/spec/lib/open_ehr/parser/basic_generic_type_spec.rb +18 -0
  38. data/spec/lib/open_ehr/parser/basic_type_spec.rb +2922 -0
  39. data/spec/lib/open_ehr/parser/code_phrase_spec.rb +91 -0
  40. data/spec/lib/open_ehr/parser/date_time_spec.rb +1953 -0
  41. data/spec/lib/open_ehr/parser/duration_spec.rb +475 -0
  42. data/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_duration_spec.rb +44 -0
  43. data/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_time_spec.rb +6 -2
  44. data/spec/spec_helper.rb +3 -2
  45. metadata +52 -41
  46. data/lib/open_ehr/am/archetype/archetype_description/archetype_description.rb +0 -21
  47. data/lib/open_ehr/am/open_ehr_profile/data_types/basic.rb +0 -29
  48. data/lib/open_ehr/am/open_ehr_profile/data_types/quantity.rb +0 -19
  49. data/lib/open_ehr/am/open_ehr_profile/data_types/text.rb +0 -15
@@ -1,6 +1,7 @@
1
1
  require 'shared_token_grammar'
2
2
  require 'open_ehr/assumed_library_types'
3
3
  require 'open_ehr/am/archetype/constraint_model'
4
+ require 'open_ehr/am/openehr_profile/data_types/text'
4
5
  require 'cadl_node'
5
6
 
6
7
  module OpenEHR
@@ -22,7 +23,7 @@ module OpenEHR
22
23
  end
23
24
 
24
25
  rule c_complex_object
25
- head:c_complex_object_head SYM_MATCHES SYM_START_CBLOCK body:c_complex_object_body SYM_END_CBLOCK {
26
+ head:c_complex_object_head SYM_MATCHES SYM_START_CBLOCK body:c_complex_object_body SYM_END_CBLOCK space {
26
27
  def value(node = ArchetypeNode.new)
27
28
  args = head.value
28
29
  args[:occurrences] ||= OpenEHR::AssumedLibraryTypes::Interval.new(
@@ -101,6 +102,11 @@ module OpenEHR
101
102
  c_complex_object.value(node)
102
103
  end
103
104
  }
105
+ / vtc:V_TERM_CODE_CONSTRAINT '' {
106
+ def value(node)
107
+ vtc.value(node)
108
+ end
109
+ }
104
110
  / constraint_ref '' {
105
111
  def value(node = nil)
106
112
  constraint_ref.value
@@ -147,28 +153,25 @@ module OpenEHR
147
153
  end
148
154
 
149
155
  rule archetype_slot
150
- c_archetype_slot_head SYM_MATCHES SYM_START_CBLOCK c_includes c_excludes SYM_END_CBLOCK {
151
- def value(node = nil)
152
- args = c_archetype_slot_head.value
156
+ c_archetype_slot_head SYM_MATCHES SYM_START_CBLOCK c_includes c_excludes SYM_END_CBLOCK space {
157
+ def value(node)
158
+ args = c_archetype_slot_head.value(node)
153
159
  args[:includes] = c_includes.value
154
160
  args[:excludes] = c_excludes.value
155
- args[:path] = node.path
156
161
  OpenEHR::AM::Archetype::ConstraintModel::ArchetypeSlot.new(args)
157
162
  end
158
163
  }
159
- / c_archetype_slot_head SYM_MATCHES SYM_START_CBLOCK c_includes SYM_END_CBLOCK {
160
- def value(node = nil)
161
- args = c_archetype_slot_head.value
164
+ / c_archetype_slot_head SYM_MATCHES SYM_START_CBLOCK c_includes SYM_END_CBLOCK space {
165
+ def value(node)
166
+ args = c_archetype_slot_head.value(node)
162
167
  args[:includes] = c_includes.value
163
- args[:path] = node.path
164
168
  OpenEHR::AM::Archetype::ConstraintModel::ArchetypeSlot.new(args)
165
169
  end
166
170
  }
167
- / c_archetype_slot_head SYM_MATCHES SYM_START_CBLOCK c_excludes SYM_END_CBLOCK {
168
- def value(node = nil)
169
- args = c_archetype_slot_head.value
171
+ / c_archetype_slot_head SYM_MATCHES SYM_START_CBLOCK c_excludes SYM_END_CBLOCK space {
172
+ def value(node)
173
+ args = c_archetype_slot_head.value(node)
170
174
  args[:excludes] = c_excludes.value
171
- args[:path] = node.path
172
175
  OpenEHR::AM::Archetype::ConstraintModel::ArchetypeSlot.new(args)
173
176
  end
174
177
  }
@@ -176,29 +179,31 @@ module OpenEHR
176
179
 
177
180
  rule c_archetype_slot_head
178
181
  c_archetype_slot_id white_space c_occurrences {
179
- def value
180
- args = c_archetype_slot_id.value
182
+ def value(node)
183
+ args = c_archetype_slot_id.value(node)
181
184
  args[:occurrences] = c_occurrences.value
182
185
  args
183
186
  end
184
187
  }
185
188
  / c_archetype_slot_id white_space {
186
- def value
189
+ def value(node)
187
190
  c_archetype_slot_id.value
188
191
  end
189
192
  }
190
193
  end
191
194
 
192
195
  rule c_archetype_slot_id
193
- SYM_ALLOW_ARCHETYPE type_identifier V_LOCAL_TERM_CODE_REF {
194
- def value
196
+ SYM_ALLOW_ARCHETYPE type_identifier lt:V_LOCAL_TERM_CODE_REF {
197
+ def value(node)
195
198
  {:rm_type_name => type_identifier.value,
196
- :node_id => V_LOCAL_TERM_CODE_REF.value}
199
+ :node_id => lt.value,
200
+ :path => node.path + "[#{lt.value}]"}
197
201
  end
198
202
  }
199
203
  / SYM_ALLOW_ARCHETYPE type_identifier {
200
- def value
201
- {:rm_type_name => type_identifier.value}
204
+ def value(node)
205
+ {:rm_type_name => type_identifier.value,
206
+ :path => node.path}
202
207
  end
203
208
  }
204
209
  end
@@ -212,19 +217,14 @@ module OpenEHR
212
217
  end
213
218
 
214
219
  rule c_primitive
215
- c_integer '' {
216
- def value
217
- c_integer.value
218
- end
219
- }
220
- / c_real '' {
220
+ c_duration '' {
221
221
  def value
222
- c_real.value
222
+ c_duration.value
223
223
  end
224
224
  }
225
- / c_date '' {
225
+ / c_date_time '' {
226
226
  def value
227
- c_date.value
227
+ c_date_time.value
228
228
  end
229
229
  }
230
230
  / c_time '' {
@@ -232,26 +232,31 @@ module OpenEHR
232
232
  c_time.value
233
233
  end
234
234
  }
235
- / c_date_time '' {
235
+ / c_date '' {
236
236
  def value
237
- c_date_time.value
237
+ c_date.value
238
238
  end
239
239
  }
240
- / c_duration '' {
240
+ / c_real '' {
241
241
  def value
242
- c_duration.value
242
+ c_real.value
243
243
  end
244
244
  }
245
- / c_string '' {
245
+ / c_integer '' {
246
246
  def value
247
- c_string.value
247
+ c_integer.value
248
248
  end
249
- }
249
+ }
250
250
  / c_boolean '' {
251
251
  def value
252
252
  c_boolean.value
253
253
  end
254
254
  }
255
+ / c_string '' {
256
+ def value
257
+ c_string.value
258
+ end
259
+ }
255
260
  end
256
261
 
257
262
  rule c_any
@@ -352,7 +357,7 @@ module OpenEHR
352
357
  end
353
358
 
354
359
  rule c_attr_body
355
- SYM_MATCHES SYM_START_CBLOCK c_attr_values SYM_END_CBLOCK {
360
+ SYM_MATCHES SYM_START_CBLOCK c_attr_values SYM_END_CBLOCK space {
356
361
  def value(node)
357
362
  c_attr_values.value(node)
358
363
  end
@@ -393,7 +398,7 @@ module OpenEHR
393
398
  end
394
399
 
395
400
  rule c_existence
396
- SYM_EXISTENCE SYM_MATCHES SYM_START_CBLOCK existence_spec SYM_END_CBLOCK {
401
+ SYM_EXISTENCE SYM_MATCHES SYM_START_CBLOCK existence_spec SYM_END_CBLOCK space {
397
402
  def value
398
403
  existence_spec.value
399
404
  end
@@ -414,7 +419,7 @@ module OpenEHR
414
419
  end
415
420
 
416
421
  rule c_cardinality
417
- SYM_CARDINALITY SYM_MATCHES SYM_START_CBLOCK cardinality_spec SYM_END_CBLOCK {
422
+ SYM_CARDINALITY SYM_MATCHES SYM_START_CBLOCK cardinality_spec SYM_END_CBLOCK space {
418
423
  def value
419
424
  cardinality_spec.value
420
425
  end
@@ -475,10 +480,16 @@ module OpenEHR
475
480
  :is_unique => true)
476
481
  end
477
482
  }
483
+ / occurrence_spec space {
484
+ def value
485
+ OpenEHR::AM::Archetype::ConstraintModel::Cardinality.new(
486
+ :interval => occurrence_spec.value)
487
+ end
488
+ }
478
489
  end
479
490
 
480
491
  rule c_occurrences
481
- SYM_OCCURRENCES SYM_MATCHES SYM_START_CBLOCK occurrence_spec SYM_END_CBLOCK {
492
+ SYM_OCCURRENCES SYM_MATCHES SYM_START_CBLOCK occurrence_spec SYM_END_CBLOCK space {
482
493
  def value
483
494
  occurrence_spec.value
484
495
  end
@@ -486,7 +497,7 @@ module OpenEHR
486
497
  end
487
498
 
488
499
  rule occurrence_spec
489
- st:(V_INTEGER) SYM_ELLIPSIS ed:cardinality_limit_value {
500
+ st:integer_value SYM_ELLIPSIS ed:cardinality_limit_value {
490
501
  def value
491
502
  if ed.value == '*'
492
503
  interval = OpenEHR::AssumedLibraryTypes::Interval.new(
@@ -509,7 +520,7 @@ module OpenEHR
509
520
  end
510
521
 
511
522
  rule cardinality_limit_value
512
- integer_value {
523
+ integer_value '' {
513
524
  def value
514
525
  text_value.to_i
515
526
  end
@@ -521,274 +532,312 @@ module OpenEHR
521
532
  }
522
533
  end
523
534
 
524
- rule c_integer_spec
525
- cardinality_limit_value '' {
535
+ rule c_integer
536
+ c_integer_spec ';' white_space integer_value {
526
537
  def value
527
- cardinality_limit_value.value
538
+ args = c_integer_spec.value
539
+ args[:assumed_value] = integer_value.value
540
+ OpenEHR::AM::Archetype::ConstraintModel::Primitive::CInteger.new(args)
528
541
  end
529
542
  }
530
- / integer_list_value '' {
543
+ / c_integer_spec '' {
531
544
  def value
532
- integer_list_value.value
545
+ OpenEHR::AM::Archetype::ConstraintModel::Primitive::CInteger.new(
546
+ c_integer_spec.value)
533
547
  end
534
548
  }
535
- / integer_interval_value '' {
549
+ end
550
+
551
+ rule c_integer_spec
552
+ integer_list_value '' {
536
553
  def value
537
- integer_interval_value.value
554
+ {:list => integer_list_value.value}
538
555
  end
539
556
  }
540
- / occurrence_spec '' {
557
+ / integer_interval_value '' {
541
558
  def value
542
- occurrence_spec.value
559
+ {:range => integer_interval_value.value}
543
560
  end
544
561
  }
545
- end
546
-
547
- rule c_integer
548
- c_integer_spec '' {
562
+ / integer_value !'..' '' {
549
563
  def value
550
- c_integer_spec.value
564
+ {:list => [integer_value.value]}
551
565
  end
552
566
  }
553
- / c_integer_spec ';' integer_value {
567
+ / occurrence_spec '' {
554
568
  def value
555
- c_integer_spec.value
569
+ {:range => occurrence_spec.value}
556
570
  end
557
571
  }
558
572
  end
559
573
 
560
574
  rule c_real_spec
561
- real_value '' {
575
+ real_list_value '' {
562
576
  def value
563
- real_value.value
577
+ {:list => real_list_value.value}
564
578
  end
565
579
  }
566
- / real_list_value '' {
580
+ / real_interval_value '' {
567
581
  def value
568
- real_list_value.value
582
+ {:range => real_interval_value.value}
569
583
  end
570
584
  }
571
- / real_interval_value '' {
585
+ / real_value '' {
572
586
  def value
573
- real_interval_value.value
587
+ {:list => [real_value.value]}
574
588
  end
575
589
  }
576
590
  end
577
591
 
578
592
  rule c_real
579
- c_real_spec '' {
593
+ c_real_spec ';' white_space real_value {
580
594
  def value
581
- c_real_spec.value
595
+ args = c_real_spec.value
596
+ args[:assumed_value] = real_value.value
597
+ OpenEHR::AM::Archetype::ConstraintModel::Primitive::CReal.new(args)
582
598
  end
583
599
  }
584
- / c_real_spec ';' real_value {
600
+ / c_real_spec '' {
585
601
  def value
586
- c_real_spec.assumed_value = real_value.value
602
+ OpenEHR::AM::Archetype::ConstraintModel::Primitive::CReal.new(
603
+ c_real_spec.value)
587
604
  end
588
605
  }
589
606
  end
590
607
 
591
608
  rule c_date_constraint
592
- V_ISO8601_DATE_CONSTRAINT_PATTERN '' {
609
+ date_interval_value '' {
610
+ def value
611
+ {:range => date_interval_value.value}
612
+ end
613
+ }
614
+ / date_list_value '' {
593
615
  def value
594
- V_ISO8601_DATE_CONSTRAINT_PATTERN.value
616
+ {:list => date_list_value.value}
595
617
  end
596
618
  }
597
619
  / date_value '' {
598
620
  def value
599
- date_value.value
621
+ {:list => [date_value.value]}
600
622
  end
601
623
  }
602
- / date_interval_value '' {
624
+ / con:V_ISO8601_DATE_CONSTRAINT_PATTERN '' {
603
625
  def value
604
- date_interval_value.value
626
+ {:pattern => con.text_value}
605
627
  end
606
628
  }
607
629
  end
608
630
 
609
631
  rule c_date
610
- c_date_constraint '' {
632
+ c_date_constraint ';' white_space date_value {
611
633
  def value
612
- c_date_constraint.value
634
+ args = c_date_constraint.value
635
+ args[:assumed_value] = date_value.value
636
+ OpenEHR::AM::Archetype::ConstraintModel::Primitive::CDate.new(
637
+ args)
613
638
  end
614
639
  }
615
- / c_date_constraint ';' date_value {
640
+ / c_date_constraint '' {
616
641
  def value
617
- c_date_constraint.value
642
+ OpenEHR::AM::Archetype::ConstraintModel::Primitive::CDate.new(
643
+ c_date_constraint.value)
618
644
  end
619
645
  }
620
646
  end
621
647
 
622
648
  rule c_time_constraint
623
- V_ISO8601_TIME_CONSTRAINT_PATTERN '' {
649
+ time_interval_value '' {
624
650
  def value
625
- V_ISO8601_TIME_CONSTRAINT_PATTERN.value
651
+ {:range => time_interval_value.value}
652
+ end
653
+ }
654
+ / time_list_value '' {
655
+ def value
656
+ {:list => time_list_value.value}
626
657
  end
627
658
  }
628
659
  / time_value '' {
629
660
  def value
630
- time_value.value
661
+ {:list => [time_value.value]}
631
662
  end
632
663
  }
633
- / time_interval_value {
664
+ / tc:V_ISO8601_TIME_CONSTRAINT_PATTERN '' {
634
665
  def value
635
- time_interval_value.value
666
+ {:pattern => tc.text_value}
636
667
  end
637
668
  }
638
669
  end
639
670
 
640
671
  rule c_time
641
- c_time_constraint '' {
672
+ c_time_constraint ';' white_space time_value {
642
673
  def value
643
- c_time_constraint.value
674
+ args = c_time_constraint.value
675
+ args[:assumed_value] = time_value.value
676
+ OpenEHR::AM::Archetype::ConstraintModel::Primitive::CTime.new(
677
+ args)
644
678
  end
645
- }
646
- / c_time_constraint ';' time_value {
679
+ }
680
+ / c_time_constraint '' {
647
681
  def value
648
- c_time_constraint.value
682
+ OpenEHR::AM::Archetype::ConstraintModel::Primitive::CTime.new(
683
+ c_time_constraint.value)
649
684
  end
650
- }
685
+ }
651
686
  end
652
687
 
653
688
  rule c_date_time_constraint
654
- V_ISO8601_DATE_TIME_CONSTRAINT_PATTERN '' {
689
+ date_time_interval_value '' {
655
690
  def value
656
- V_ISO8601_DATE_TIME_CONSTRAINT_PATTERN.value
691
+ {:range => date_time_interval_value.value}
657
692
  end
658
693
  }
659
694
  / date_time_value '' {
660
695
  def value
661
- date_time_value.value
696
+ {:list => [date_time_value.value]}
662
697
  end
663
698
  }
664
- / date_time_interval_value '' {
699
+ / dtc:V_ISO8601_DATE_TIME_CONSTRAINT_PATTERN '' {
665
700
  def value
666
- date_time_interval_value.value
701
+ {:pattern => dtc.text_value}
667
702
  end
668
703
  }
669
704
  end
670
705
 
671
706
  rule c_date_time
672
- c_date_time_constraint '' {
707
+ c_date_time_constraint ';' white_space date_time_value {
673
708
  def value
674
- c_date_time_constraint.value
709
+ args = c_date_time_constraint.value
710
+ args[:assumed_value] = date_time_value.value
711
+ OpenEHR::AM::Archetype::ConstraintModel::Primitive::CDateTime.new(
712
+ args)
675
713
  end
676
714
  }
677
- / c_date_time_constraint ';' date_time_value {
715
+ / c_date_time_constraint '' {
678
716
  def value
679
- c_date_time_constraint.value
717
+ OpenEHR::AM::Archetype::ConstraintModel::Primitive::CDateTime.new(
718
+ c_date_time_constraint.value)
680
719
  end
681
720
  }
682
721
  end
683
722
 
684
723
  rule c_duration_constraint
685
- duration_pattern '' {
724
+ duration_pattern '/' duration_interval_value '' {
686
725
  def value
687
- duration_pattern.value
726
+ {:pattern => duration_pattern.value}
688
727
  end
689
728
  }
690
- / duration_pattern '/' duration_interval_pattern {
729
+ / duration_pattern '' {
691
730
  def value
692
- duration_interval_patternl.value
731
+ {:pattern => duration_pattern.value}
693
732
  end
694
733
  }
695
- / duration_value {
734
+ / duration_interval_value '' {
696
735
  def value
697
- duration_value.value
736
+ {:range => duration_interval_value.value}
698
737
  end
699
738
  }
700
- / duration_interval_value {
739
+ / duration_value '' {
701
740
  def value
702
- duration_interval_value.value
741
+ {:list => [duration_value.value]}
703
742
  end
704
743
  }
705
744
  end
706
745
 
707
746
  rule duration_pattern
708
- V_ISO8601_TIME_CONSTRAINT_PATTERN '' {
747
+ dp:V_ISO8601_DURATION_CONSTRAINT_PATTERN '' {
709
748
  def value
710
- V_ISO8601_TIME_CONSTRAINT_PATTERN.value
749
+ dp.text_value
711
750
  end
712
751
  }
713
752
  end
714
753
 
715
754
  rule c_duration
716
- c_duration_constraint '' {
755
+ c_duration_constraint ';' white_space duration_value '' {
717
756
  def value
718
- c_duration_constraint.value
757
+ args = c_duration_constraint.value
758
+ args[:assumed_value] = duration_value.value
759
+ OpenEHR::AM::Archetype::ConstraintModel::Primitive::CDuration.new(
760
+ args)
719
761
  end
720
762
  }
721
- / c_duration_constraint ';' duration_value {
763
+ / c_duration_constraint !';' '' {
722
764
  def value
723
- c_duration_constraint.value
765
+ OpenEHR::AM::Archetype::ConstraintModel::Primitive::CDuration.new(
766
+ c_duration_constraint.value)
724
767
  end
725
768
  }
726
769
  end
727
770
 
728
771
  rule c_string_spec
729
- string_list_value ',' SYM_LIST_CONTINUE {
772
+ string_list_value ',' white_space SYM_LIST_CONTINUE {
730
773
  def value
731
- OpenEHR::AM::Archetype::ConstraintModel::Primitive::CString.new(
732
- :list => string_list_value.value)
774
+ {:list => string_list_value.value}
733
775
  end
734
776
  }
735
777
  / string_list_value '' {
736
778
  def value
737
- OpenEHR::AM::Archetype::ConstraintModel::Primitive::CString.new(
738
- :list => string_list_value.value, :type => 'Boolean')
779
+ {:list => string_list_value.value}
739
780
  end
740
781
  }
741
782
  / pat:V_REGEXP '' {
742
783
  def value
743
- OpenEHR::AM::Archetype::ConstraintModel::Primitive::CString.new(
744
- :pattern => pat.value, :type => 'Boolean')
784
+ {:pattern => pat.value}
745
785
  end
746
786
  }
747
787
  / str:V_STRING '' {
748
788
  def value
749
- OpenEHR::AM::Archetype::ConstraintModel::Primitive::CString.new(
750
- :list => [str.value])
789
+ {:list => [str.value]}
751
790
  end
752
791
  }
753
792
  end
754
793
 
755
794
  rule c_string
756
- c_string_spec (';' string_value)? {
795
+ c_string_spec white_space ';' white_space string_value {
796
+ def value
797
+ args = c_string_spec.value
798
+ args[:assumed_value] = string_value.value
799
+ OpenEHR::AM::Archetype::ConstraintModel::Primitive::CString.new(
800
+ args)
801
+ end
802
+ }
803
+ / c_string_spec '' {
757
804
  def value
758
- c_string_spec.value
805
+ OpenEHR::AM::Archetype::ConstraintModel::Primitive::CString.new(
806
+ c_string_spec.value)
759
807
  end
760
808
  }
761
809
  end
762
810
 
763
811
  rule c_boolean_spec
764
- SYM_TRUE '' {
812
+ SYM_TRUE ',' white_space SYM_FALSE {
765
813
  def value
766
- {:true_valid => true, :false_valid => false}
814
+ {:true_valid => true, :false_valid => true}
767
815
  end
768
816
  }
769
- / SYM_TRUE ',' SYM_FALSE {
817
+ / SYM_TRUE white_space '' {
770
818
  def value
771
- {:true_valid => true, :false_valid => true}
819
+ {:true_valid => true, :false_valid => false}
772
820
  end
773
821
  }
774
- / SYM_FALSE '' {
822
+ / SYM_FALSE white_space ',' white_space SYM_TRUE {
775
823
  def value
776
- {:true_valid => false, :false_valid => true}
824
+ {:true_valid => true, :false_valid => true}
777
825
  end
778
826
  }
779
- / SYM_FALSE ',' SYM_TRUE {
827
+ / SYM_FALSE white_space '' {
780
828
  def value
781
- {:true_valid => true, :false_valid => true}
829
+ {:false_valid => true, :true_valid => false}
782
830
  end
783
831
  }
784
832
  end
785
833
 
786
834
  rule c_boolean
787
- c_boolean_spec ';' boolean_value {
835
+ c_boolean_spec ';' white_space boolean_value {
788
836
  def value
789
- c_boolean_spec.value[:assumed_value] = boolean_value.value
837
+ args = c_boolean_spec.value
838
+ args[:assumed_value] = boolean_value.value
790
839
  OpenEHR::AM::Archetype::ConstraintModel::Primitive::CBoolean.new(
791
- c_boolean_spec.value)
840
+ args)
792
841
  end
793
842
  }
794
843
  / c_boolean_spec '' {
@@ -815,6 +864,72 @@ module OpenEHR
815
864
  }
816
865
  end
817
866
 
867
+ rule code_string
868
+ NAMECHAR+ '' {
869
+ def value
870
+ text_value
871
+ end
872
+ }
873
+ end
874
+
875
+ rule code_string_list
876
+ first:code_string more:(',' space code_string)+ space {
877
+ def value
878
+ codes.map {|c| c.value}
879
+ end
880
+
881
+ def codes
882
+ [first] + more.elements.map {|e| e.code_string}
883
+ end
884
+ }
885
+ end
886
+
887
+ rule code_string_spec
888
+ code_string_list '' {
889
+ def value
890
+ code_string_list.value
891
+ end
892
+ }
893
+ / code_string '' {
894
+ def value
895
+ [code_string.value]
896
+ end
897
+ }
898
+ end
899
+
900
+ rule V_TERM_CODE_CONSTRAINT
901
+ ti:V_TERM_CODE code_string_spec ';' space code_string ']' space {
902
+ def value(node)
903
+ ::OpenEHR::AM::OpenEHRProfile::DataTypes::Text::CCodePhrase.new(
904
+ :rm_type_name => 'CodePhrase',
905
+ :occurrences => OpenEHR::AssumedLibraryTypes::Interval.new(
906
+ :upper => 1, :lower => 1),
907
+ :terminology_id => ti.value, :code_list => code_string_spec.value,
908
+ :assumed_value => code_string.value,
909
+ :path => node.path)
910
+ end
911
+ }
912
+ / ti:V_TERM_CODE code_string_spec ']' space {
913
+ def value(node)
914
+ ::OpenEHR::AM::OpenEHRProfile::DataTypes::Text::CCodePhrase.new(
915
+ :rm_type_name => 'CodePhrase',
916
+ :occurrences => OpenEHR::AssumedLibraryTypes::Interval.new(
917
+ :upper => 1, :lower => 1),
918
+ :terminology_id => ti.value, :code_list => code_string_spec.value,
919
+ :path => node.path)
920
+ end
921
+ }
922
+ / ti:V_TERM_CODE ']' space {
923
+ def value(node)
924
+ ::OpenEHR::AM::OpenEHRProfile::DataTypes::Text::CCodePhrase.new(
925
+ :rm_type_name => 'CodePhrase',
926
+ :occurrences => OpenEHR::AssumedLibraryTypes::Interval.new(
927
+ :upper => 1, :lower => 1),
928
+ :terminology_id => ti.value, :code_list => [], :path => node.path)
929
+ end
930
+ }
931
+ end
932
+
818
933
  rule V_C_DOMAIN_TYPE
819
934
  '('? [A-Z] IDCHAR* ')'? [ \n]* '<' [^>]* '>'
820
935
  end
@@ -846,10 +961,12 @@ module OpenEHR
846
961
  def value
847
962
  if (id && !id.empty?)
848
963
  OpenEHR::AM::Archetype::Assertion::Assertion.new(
849
- :tag => id.value, :expression => boolean_expression.value)
964
+ :tag => id.value, :expression => boolean_expression.value,
965
+ :string_expression => id.text_value + boolean_expression.text_value)
850
966
  else
851
967
  OpenEHR::AM::Archetype::Assertion::Assertion.new(
852
- :expression => boolean_expression.value)
968
+ :expression => boolean_expression.value,
969
+ :string_expression => boolean_expression.text_value)
853
970
  end
854
971
  end
855
972
  }
@@ -861,36 +978,153 @@ module OpenEHR
861
978
  boolean_node.value
862
979
  end
863
980
  }
981
+ / boolean_leaf '' {
982
+ def value
983
+ boolean_leaf.value
984
+ end
985
+ }
864
986
  end
865
987
 
866
988
  rule boolean_node
867
989
  SYM_EXISTS absolute_path {
868
990
  def value
869
- {:operator => OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_EXISTS,
870
- :path => absolute_path.value }
991
+ item = OpenEHR::AM::Archetype::Assertion::ExprLeaf.new(
992
+ :type => 'String',
993
+ :item => absolute_path.value,
994
+ :reference_type => 'CONSTANT')
995
+ OpenEHR::AM::Archetype::Assertion::ExprUnaryOperator.new(
996
+ :type => 'Boolean',
997
+ :operator => OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_EXISTS,
998
+ :operand => item,
999
+ :precedence_overridden => false)
871
1000
  end
872
1001
  }
873
1002
  / relative_path white_space SYM_MATCHES SYM_START_CBLOCK c_primitive SYM_END_CBLOCK {
874
1003
  def value
875
- OpenEHR::AM::Archetype::Assertion::ExprLeaf.new(
876
- :item => c_primitive.value,
877
- :type => c_primitive.value.type,
878
- :path => relative_path.value,
879
- :reference_type => 'constraint')
1004
+ left_op = OpenEHR::AM::Archetype::Assertion::ExprLeaf.new(
1005
+ :type => 'String',
1006
+ :item => relative_path.value,
1007
+ :reference_type => 'Constant')
1008
+ right_op = OpenEHR::AM::Archetype::Assertion::ExprLeaf.new(
1009
+ :item => c_primitive.value,
1010
+ :type => c_primitive.value.type,
1011
+ :reference_type => 'Constant')
1012
+ op = OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_MATCHES
1013
+ OpenEHR::AM::Archetype::Assertion::ExprBinaryOperator.new(
1014
+ :type => 'Boolean',
1015
+ :operator => op,
1016
+ :right_operand => right_op,
1017
+ :left_operand => left_op,
1018
+ :reference_type => 'Constraint')
880
1019
  end
881
1020
  }
882
1021
  / SYM_NOT boolean_leaf {
883
1022
  def value
884
- boolean_leaf.value
1023
+ OpenEHR::AM::Archetype::Assertion::ExprUnaryOperator.new(
1024
+ :type => 'Boolean',
1025
+ :operator => OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_NOT,
1026
+ :operand => boolean_leaf.value,
1027
+ :precedence_overridden => false)
1028
+ end
1029
+ }
1030
+ / arithmetic_leaf SYM_EQ arithmetic_expression {
1031
+ def value
1032
+ OpenEHR::AM::Archetype::Assertion::ExprBinaryOperator.new(
1033
+ :type => 'Boolean',
1034
+ :operator => OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_EQ,
1035
+ :left_operand => arithmetic_leaf.value,
1036
+ :right_operand => arithmetic_expression.value,
1037
+ :reference_type => 'Constraint')
1038
+ end
1039
+ }
1040
+ / arithmetic_leaf SYM_NE arithmetic_expression {
1041
+ def value
1042
+ OpenEHR::AM::Archetype::Assertion::ExprBinaryOperator.new(
1043
+ :type => 'Boolean',
1044
+ :operator => OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_NE,
1045
+ :left_operand => arithmetic_leaf.value,
1046
+ :right_operand => arithmetic_expression.value,
1047
+ :reference_type => 'Constraint')
1048
+ end
1049
+ }
1050
+ / arithmetic_leaf SYM_LT arithmetic_expression {
1051
+ def value
1052
+ OpenEHR::AM::Archetype::Assertion::ExprBinaryOperator.new(
1053
+ :type => 'Boolean',
1054
+ :operator => OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_LT,
1055
+ :left_operand => arithmetic_leaf.value,
1056
+ :right_operand => arithmetic_expression.value,
1057
+ :reference_type => 'Constraint')
885
1058
  end
886
1059
  }
887
- / arithmetic_expression (SYM_EQ / SYM_NE / SYM_LT / SYM_GT / SYM_LE / SYM_GE) arithmetic_expression { def value
888
- p elements
1060
+ / arithmetic_leaf SYM_GT arithmetic_expression {
1061
+ def value
1062
+ OpenEHR::AM::Archetype::Assertion::ExprBinaryOperator.new(
1063
+ :type => 'Boolean',
1064
+ :operator => OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_GT,
1065
+ :left_operand => arithmetic_leaf.value,
1066
+ :right_operand => arithmetic_expression.value,
1067
+ :reference_type => 'Constraint')
1068
+ end
1069
+ }
1070
+ / arithmetic_leaf SYM_LE arithmetic_expression {
1071
+ def value
1072
+ OpenEHR::AM::Archetype::Assertion::ExprBinaryOperator.new(
1073
+ :type => 'Boolean',
1074
+ :operator => OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_LE,
1075
+ :left_operand => arithmetic_leaf.value,
1076
+ :right_operand => arithmetic_expression.value,
1077
+ :reference_type => 'Constraint')
1078
+ end
1079
+ }
1080
+ / arithmetic_leaf SYM_GE arithmetic_expression {
1081
+ def value
1082
+ OpenEHR::AM::Archetype::Assertion::ExprBinaryOperator.new(
1083
+ :type => 'Boolean',
1084
+ :operator => OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_GE,
1085
+ :left_operand => arithmetic_leaf.value,
1086
+ :right_operand => arithmetic_expression.value,
1087
+ :reference_type => 'Constraint')
1088
+ end
1089
+ }
1090
+ / boolean_leaf SYM_AND boolean_expression {
1091
+ def value
1092
+ OpenEHR::AM::Archetype::Assertion::ExprBinaryOperator.new(
1093
+ :type => 'Boolean',
1094
+ :operator => OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_AND,
1095
+ :left_operand => boolean_leaf.value,
1096
+ :right_operand => boolean_expression.value,
1097
+ :reference_type => 'Constraint')
1098
+ end
1099
+ }
1100
+ / boolean_leaf SYM_OR boolean_expression {
1101
+ def value
1102
+ OpenEHR::AM::Archetype::Assertion::ExprBinaryOperator.new(
1103
+ :type => 'Boolean',
1104
+ :operator => OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_OR,
1105
+ :left_operand => boolean_leaf.value,
1106
+ :right_operand => boolean_expression.value,
1107
+ :reference_type => 'Constraint')
1108
+ end
1109
+ }
1110
+ / boolean_leaf SYM_XOR boolean_expression {
1111
+ def value
1112
+ OpenEHR::AM::Archetype::Assertion::ExprBinaryOperator.new(
1113
+ :type => 'Boolean',
1114
+ :operator => OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_XOR,
1115
+ :left_operand => boolean_leaf.value,
1116
+ :right_operand => boolean_expression.value,
1117
+ :reference_type => 'Constraint')
889
1118
  end
890
1119
  }
891
- / boolean_leaf ((SYM_AND / SYM_OR / SYM_XOR / SYM_IMPLIES) boolean_leaf)? {
1120
+ / boolean_leaf SYM_IMPLIES boolean_expression {
892
1121
  def value
893
- p elements
1122
+ OpenEHR::AM::Archetype::Assertion::ExprBinaryOperator.new(
1123
+ :type => 'Boolean',
1124
+ :operator => OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_IMPLIES,
1125
+ :left_operand => boolean_leaf.value,
1126
+ :right_operand => boolean_expression.value,
1127
+ :reference_type => 'Constraint')
894
1128
  end
895
1129
  }
896
1130
  end
@@ -903,12 +1137,18 @@ module OpenEHR
903
1137
  }
904
1138
  / SYM_TRUE {
905
1139
  def value
906
- true
1140
+ OpenEHR::AM::Archetype::Assertion::ExprLeaf.new(
1141
+ :type => 'Boolean',
1142
+ :item => true,
1143
+ :reference_type => 'CONSTANT')
907
1144
  end
908
1145
  }
909
1146
  / SYM_FALSE {
910
1147
  def value
911
- false
1148
+ OpenEHR::AM::Archetype::Assertion::ExprLeaf.new(
1149
+ :type => 'Boolean',
1150
+ :item => false,
1151
+ :reference_type => 'CONSTANT')
912
1152
  end
913
1153
  }
914
1154
  end
@@ -919,44 +1159,120 @@ module OpenEHR
919
1159
  arithmetic_node.value
920
1160
  end
921
1161
  }
1162
+ / arithmetic_leaf '' {
1163
+ def value
1164
+ arithmetic_leaf.value
1165
+ end
1166
+ }
922
1167
  end
923
1168
 
924
1169
  rule arithmetic_node
925
- arithmetic_leaf (('+' / '-' / '*' / '/' / '^') arithmetic_leaf)*
1170
+ arithmetic_leaf '+' arithmetic_expression {
1171
+ def value
1172
+ OpenEHR::AM::Archetype::Assertion::ExprBinaryOperator.new(
1173
+ :type => 'Boolean',
1174
+ :operator => OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_PLUS,
1175
+ :left_operand => arithmetic_leaf.value,
1176
+ :right_operand => arithmetic_expression.value,
1177
+ :reference_type => 'Constraint')
1178
+ end
1179
+ }
1180
+ / arithmetic_leaf '-' arithmetic_expression {
1181
+ def value
1182
+ OpenEHR::AM::Archetype::Assertion::ExprBinaryOperator.new(
1183
+ :type => 'Boolean',
1184
+ :operator => OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_MINUS,
1185
+ :left_operand => arithmetic_leaf.value,
1186
+ :right_operand => arithmetic_expression.value,
1187
+ :reference_type => 'Constraint')
1188
+ end
1189
+ }
1190
+ / arithmetic_leaf '*' arithmetic_expression {
1191
+ def value
1192
+ OpenEHR::AM::Archetype::Assertion::ExprBinaryOperator.new(
1193
+ :type => 'Boolean',
1194
+ :operator => OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_MULTIPLY,
1195
+ :left_operand => arithmetic_leaf.value,
1196
+ :right_operand => arithmetic_expression.value,
1197
+ :reference_type => 'Constraint')
1198
+ end
1199
+ }
1200
+ / arithmetic_leaf '/' arithmetic_expression {
1201
+ def value
1202
+ OpenEHR::AM::Archetype::Assertion::ExprBinaryOperator.new(
1203
+ :type => 'Boolean',
1204
+ :operator => OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_DIVIDE,
1205
+ :left_operand => arithmetic_leaf.value,
1206
+ :right_operand => arithmetic_expression.value,
1207
+ :reference_type => 'Constraint')
1208
+ end
1209
+ }
1210
+ / arithmetic_leaf '^' arithmetic_expression {
1211
+ def value
1212
+ OpenEHR::AM::Archetype::Assertion::ExprBinaryOperator.new(
1213
+ :type => 'Boolean',
1214
+ :operator => OpenEHR::AM::Archetype::Assertion::OperatorKind::OP_EXP,
1215
+ :left_operand => arithmetic_leaf.value,
1216
+ :right_operand => arithmetic_expression.value,
1217
+ :reference_type => 'Constraint')
1218
+ end
1219
+ }
926
1220
  end
927
1221
 
928
1222
  rule arithmetic_leaf
929
- '(' arithmetic_expression ')' {
1223
+ '(' arithmetic_expression ')' space {
930
1224
  def value
931
1225
  arithmetic_expression.value
932
1226
  end
933
1227
  }
934
1228
  / integer_value '' {
935
1229
  def value
936
- integer_value.value
1230
+ OpenEHR::AM::Archetype::ConstraintModel::ExprLeaf.new(
1231
+ :type => 'Integer',
1232
+ :item => integer_value.value,
1233
+ :reference_type => 'CONSTANT')
937
1234
  end
938
1235
  }
939
1236
  / real_value '' {
940
1237
  def value
941
- real_value.value
1238
+ OpenEHR::AM::Archetype::ConstraintModel::ExprLeaf.new(
1239
+ :type => 'Real',
1240
+ :item => real_value.value,
1241
+ :reference_type => 'CONSTANT')
942
1242
  end
943
1243
  }
944
- / absolute_path '' {
1244
+ / absolute_path space {
945
1245
  def value
946
- absolute_path.value
1246
+ OpenEHR::AM::Archetype::ConstraintModel::ExprLeaf.new(
1247
+ :type => 'String',
1248
+ :item => absolute_path.value,
1249
+ :reference_type => 'CONSTANT')
1250
+
947
1251
  end
948
1252
  }
949
1253
  end
950
1254
 
951
1255
  # path block
952
1256
  rule object_path
953
- movable_path
954
- / absolute_path
955
- / relative_path
1257
+ movable_path '' {
1258
+ def value
1259
+ movable_path.value
1260
+ end
1261
+ }
1262
+ / absolute_path '' {
1263
+ def value
1264
+ absolute_path.value
1265
+ end
1266
+ }
1267
+ / relative_path '' {
1268
+ def value
1269
+ relative_path.value
1270
+ end
1271
+ }
956
1272
  end
957
1273
 
958
1274
  rule movable_path
959
- SYM_MOVABLE_LEADER relative_path {
1275
+ SYM_MOVABLE_LEADER relative_path '' {
960
1276
  def value
961
1277
  text_value
962
1278
  end
@@ -964,7 +1280,7 @@ module OpenEHR
964
1280
  end
965
1281
 
966
1282
  rule absolute_path
967
- '/' relative_path? {
1283
+ '/' relative_path? '' {
968
1284
  def value
969
1285
  text_value
970
1286
  end
@@ -972,7 +1288,7 @@ module OpenEHR
972
1288
  end
973
1289
 
974
1290
  rule relative_path
975
- path_segment ('/' path_segment)* {
1291
+ path_segment ('/' path_segment)* '' {
976
1292
  def value
977
1293
  text_value
978
1294
  end
@@ -980,7 +1296,7 @@ module OpenEHR
980
1296
  end
981
1297
 
982
1298
  rule path_segment
983
- V_ATTRIBUTE_IDENTIFIER V_LOCAL_TERM_CODE_REF? {
1299
+ V_ATTRIBUTE_IDENTIFIER V_LOCAL_TERM_CODE_REF? '' {
984
1300
  def value
985
1301
  text_value
986
1302
  end