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
data/History.txt CHANGED
@@ -1,3 +1,6 @@
1
+ === 0.9.5 2011-12-02
2
+ Bug fix around ADL parser, data types, constranit
3
+
1
4
  === 0.9.4 2011-11-22
2
5
  Bug fix around ADL parser, ArchetypeOntology
3
6
 
data/README.rdoc CHANGED
@@ -5,12 +5,12 @@ Ruby openEHR implementation project.
5
5
 
6
6
  = Version
7
7
 
8
- Release-0.9.4
8
+ Release-0.9.5
9
9
 
10
10
  = Requirements
11
11
 
12
- * Ruby 1.9.2 reccomended
13
- * Tested with Ruby 1.9.2 on Linux and FreeBSD.
12
+ * Ruby 1.9.x reccomended
13
+ * Tested with Ruby 1.9.3 on Linux and FreeBSD.
14
14
  * It would work with some adjustment on Ruby 1.8 or earlier,
15
15
  but not confirmed.
16
16
  * It should work on other platforms with Ruby
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.4
1
+ 0.9.5
@@ -34,6 +34,7 @@ module OpenEHR
34
34
  binary_consistency(args[:true_valid], args[:false_valid])
35
35
  @true_valid = args[:true_valid]
36
36
  @false_valid = args[:false_valid]
37
+ args[:type] = 'Boolean'
37
38
  super(args)
38
39
  end
39
40
 
@@ -78,6 +79,7 @@ module OpenEHR
78
79
  attr_reader :pattern, :list
79
80
 
80
81
  def initialize(args = { })
82
+ args[:type] = 'String'
81
83
  super
82
84
  consistency(args[:pattern], args[:list])
83
85
  @pattern = args[:pattern]
@@ -106,6 +108,7 @@ module OpenEHR
106
108
  attr_reader :list, :range
107
109
 
108
110
  def initialize(args = { })
111
+ args[:type] ||= 'Integer'
109
112
  super
110
113
  consistency(args[:list], args[:range])
111
114
  @list = args[:list]
@@ -132,13 +135,14 @@ module OpenEHR
132
135
 
133
136
  class CReal < CInteger
134
137
  def initialize(args = { })
138
+ args[:type] = 'Real'
135
139
  super
136
140
  end
137
141
  end
138
142
 
139
143
  module CDateModule
140
- attr_accessor :range, :timezone_validity
141
- attr_reader :month_validity, :day_validity
144
+ attr_accessor :timezone_validity, :day_validity, :range, :list
145
+ attr_reader :month_validity, :day_validity, :range, :pattern
142
146
 
143
147
  def month_validity=(month_validity)
144
148
  if (month_validity == ValidityKind::OPTIONAL &&
@@ -151,14 +155,23 @@ module OpenEHR
151
155
  @month_validity = month_validity
152
156
  end
153
157
 
154
- def day_validity=(day_validity)
155
- @day_validity = day_validity
158
+ def pattern=(pattern)
159
+ @pattern = pattern if valid_pattern?(pattern)
156
160
  end
157
161
 
158
162
  def validity_is_range?
159
163
  return !@range.nil?
160
164
  end
161
165
 
166
+ protected
167
+ def valid_pattern?(pattern)
168
+ if /^([Yy?X]{4})(-([Mm?X]{2})(-([Dd?X]{2}))?)?$/ =~ pattern
169
+ true
170
+ else
171
+ false
172
+ end
173
+ end
174
+
162
175
  private
163
176
  def consistency_validity(month_validity, day_validity)
164
177
  end
@@ -168,8 +181,13 @@ module OpenEHR
168
181
  include CDateModule
169
182
 
170
183
  def initialize(args = { })
171
- super(args)
172
- self.range = args[:range]
184
+ args[:type] = 'ISO8601_DATE'
185
+ super
186
+ @range = args[:range]
187
+ if args[:pattern]
188
+ self.pattern = args[:pattern]
189
+ end
190
+ self.list = args[:list]
173
191
  self.timezone_validity = args[:timezone_validity]
174
192
  self.day_validity = args[:day_validity]
175
193
  self.month_validity = args[:month_validity]
@@ -177,9 +195,12 @@ module OpenEHR
177
195
  end
178
196
 
179
197
  module CTimeModule
180
- attr_accessor :range
198
+ attr_accessor :range, :list
181
199
  attr_reader :minute_validity, :second_validity,
182
- :millisecond_validity
200
+ :millisecond_validity, :pattern
201
+ def pattern=(pattern)
202
+ @pattern = pattern if valid_pattern? pattern
203
+ end
183
204
 
184
205
  def minute_validity=(minute_validity)
185
206
  if (minute_validity == ValidityKind::OPTIONAL &&
@@ -205,17 +226,29 @@ module OpenEHR
205
226
  @millisecond_validity = millisecond_validity
206
227
  end
207
228
 
229
+ protected
208
230
  def validity_is_range?
209
231
  return !@range.nil?
210
232
  end
233
+
234
+ def valid_pattern?(pattern)
235
+ if /^([Hh?X]{2})(:([Mm?X]{2})(:([Ss?X]{2}))?)?$/ =~ pattern
236
+ true
237
+ else
238
+ false
239
+ end
240
+ end
211
241
  end
212
242
 
213
243
  class CTime < CPrimitive
214
244
  include CTimeModule
215
245
 
216
246
  def initialize(args = { })
247
+ args[:type] = 'ISO8601_TIME'
217
248
  super
249
+ self.pattern = args[:pattern]
218
250
  self.range = args[:range]
251
+ self.list = args[:list]
219
252
  self.millisecond_validity = args[:millisecond_validity]
220
253
  self.second_validity = args[:second_validity]
221
254
  self.minute_validity = args[:minute_validity]
@@ -227,7 +260,11 @@ module OpenEHR
227
260
  attr_reader :hour_validity
228
261
 
229
262
  def initialize(args = { })
263
+ args[:type] = 'ISO8601_DATE_TIME'
230
264
  super
265
+ self.pattern = args[:pattern]
266
+ self.list = args[:list]
267
+ self.range = args[:range]
231
268
  self.timezone_validity = args[:timezone_validity]
232
269
  self.millisecond_validity = args[:millisecond_validity]
233
270
  self.second_validity = args[:second_validity]
@@ -258,40 +295,30 @@ module OpenEHR
258
295
  end
259
296
  @day_validity = day_validity
260
297
  end
298
+
299
+ protected
300
+ def valid_pattern?(pattern)
301
+ if /^([Yy?X]{4})(-([Mm?X]{2})(-([Dd?X]{2}))?)?[T ]?([Hh?X]{2})(:([Mm?X]{2})(:([Ss?X]{2}))?)?$/ =~ pattern
302
+ true
303
+ else
304
+ false
305
+ end
306
+ end
261
307
  end
262
308
 
263
309
  class CDuration < CPrimitive
264
- attr_reader :range
265
- attr_accessor :years_allowed, :months_allowed, :weeks_allowed,
266
- :days_allowed, :hours_allowed, :minutes_allowed,
267
- :seconds_allowed, :fractional_seconds_allowed
310
+ attr_accessor :years_allowed, :months_allowed, :weeks_allowed
311
+ attr_accessor :days_allowed, :hours_allowed, :minutes_allowed
312
+ attr_accessor :seconds_allowed, :fractional_seconds_allowed
313
+ attr_accessor :pattern, :list, :range
268
314
 
269
315
  def initialize(args = { })
316
+ args[:type] = 'ISO8601_DURATION'
270
317
  super
271
- self.fractional_seconds_allowed = args[:fractional_seconds_allowed]
272
- self.seconds_allowed = args[:seconds_allowed]
273
- self.minutes_allowed = args[:minutes_allowed]
274
- self.hours_allowed = args[:hours_allowed]
275
- self.days_allowed = args[:days_allowed]
276
- self.months_allowed = args[:months_allowed]
277
- self.weeks_allowed = args[:weeks_allowed]
278
- self.years_allowed = args[:years_allowed]
318
+ self.pattern = args[:pattern]
319
+ self.list = args[:list]
279
320
  self.range = args[:range]
280
321
  end
281
-
282
- def range=(range)
283
- if range.nil? && !(@years_allowed ||
284
- @months_allowed ||
285
- @weeks_allowed ||
286
- @days_allowed ||
287
- @hours_allowed ||
288
- @minutes_allowed ||
289
- @seconds_allowed ||
290
- @fractional_seconds_allowed)
291
- raise ArgumentError, 'invalid range'
292
- end
293
- @range = range
294
- end
295
322
  end
296
323
  end # of Primitive
297
324
  end # of CostraintModel
@@ -0,0 +1,27 @@
1
+ module OpenEHR
2
+ module AM
3
+ module OpenEHRProfile
4
+ module DataTypes
5
+ module Basic
6
+ class CDvState
7
+ end
8
+
9
+ class StateMachine
10
+ end
11
+
12
+ class State
13
+ end
14
+
15
+ class TerminalState < State
16
+ end
17
+
18
+ class NonTerminalState < State
19
+ end
20
+
21
+ class Transition
22
+ end
23
+ end
24
+ end # of DataTypes
25
+ end # of OpenEHR Profile
26
+ end # of AM
27
+ end # of OpenEHR
@@ -0,0 +1,18 @@
1
+ module OpenEHR
2
+ module AM
3
+ module OpenEHRProfile
4
+ module DataTypes
5
+ module Quantity
6
+ class CDvQuantity < OpenEHR::AM::Archetype::ConstraintModel::CDomainType
7
+ end
8
+
9
+ class CDvOrdinal < OpenEHR::AM::Archetype::ConstraintModel::CDomainType
10
+ end
11
+
12
+ class CQuantityItem
13
+ end
14
+ end
15
+ end # of DataTypes
16
+ end # of OpenEHRProfile
17
+ end # of AM
18
+ end # of OpenEHR
@@ -0,0 +1,22 @@
1
+ include OpenEHR::AM::Archetype::ConstraintModel
2
+
3
+ module OpenEHR
4
+ module AM
5
+ module OpenEHRProfile
6
+ module DataTypes
7
+ module Text
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,12 @@
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
+
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ module OpenEHR
4
+ module AM
5
+ module OpenEHRProfile
6
+ autoload :DataTypes, 'openehr_profile/data_types'
7
+
8
+ end
9
+ end
10
+ end
data/lib/open_ehr/am.rb CHANGED
@@ -4,5 +4,7 @@ $:.unshift(File.dirname(__FILE__)) unless
4
4
  module OpenEHR
5
5
  module AM
6
6
  autoload :Archetype, 'am/archetype'
7
+ autoload :OpenEHRProfile, 'am/openehr_profile'
8
+
7
9
  end
8
10
  end
@@ -80,7 +80,7 @@ module OpenEHR
80
80
  end
81
81
  end # end of Interval
82
82
 
83
- class TimeDefinitions < Any
83
+ module TimeDefinitions #< Any
84
84
  DAYS_IN_LEAP_YEAR = 366
85
85
  DAYS_IN_WEEK = 7
86
86
  DAYS_IN_YEAR = 365
@@ -131,26 +131,33 @@ module OpenEHR
131
131
  def self.valid_month?(mo)
132
132
  mo >= 1 and mo <= MONTH_IN_YEAR
133
133
  end
134
+
135
+ protected
136
+ def nilthenzero(value)
137
+ return value ? value : 0
138
+ end
139
+
134
140
  end # end of TimeDefinitions
135
141
 
136
142
  module ISO8601DateModule
143
+ include TimeDefinitions
137
144
  attr_reader :year, :month, :day
138
145
 
139
146
  def year=(year)
140
- unless ISO8601Date.valid_year?(year)
147
+ unless TimeDefinitions.valid_year?(year)
141
148
  raise ArgumentError, "Year is not valid"
142
149
  end
143
150
  @year = year
144
151
  end
145
152
 
146
153
  def month=(month)
147
- raise ArgumentError, "Month is not valid" unless month.nil? or ISO8601Date.valid_month?(month)
154
+ raise ArgumentError, "Month is not valid" unless month.nil? or TimeDefinitions.valid_month?(month)
148
155
  @month = month
149
156
  end
150
157
 
151
158
  def day=(day)
152
159
 
153
- raise ArgumentError, "Day is not valid" unless day.nil? or ISO8601Date.valid_day?(@year, @month, day)
160
+ raise ArgumentError, "Day is not valid" unless day.nil? or TimeDefinitions.valid_day?(@year, @month, day)
154
161
  @day = day
155
162
  end
156
163
 
@@ -197,11 +204,7 @@ module OpenEHR
197
204
  end
198
205
  end
199
206
 
200
- def nilthenzero(value)
201
- return value ? value : 0
202
- end
203
-
204
- class ISO8601Date < TimeDefinitions
207
+ class ISO8601Date
205
208
  include ISO8601DateModule, Comparable
206
209
  def initialize(string)
207
210
  /(\d{4})(?:-(\d{2})(?:-(\d{2})?)?)?/ =~ string
@@ -237,10 +240,11 @@ module OpenEHR
237
240
  end # end of ISO8601_DATE
238
241
 
239
242
  module ISO8601TimeModule
243
+ include TimeDefinitions
240
244
  attr_reader :hour, :minute, :second, :fractional_second, :timezone
241
245
 
242
246
  def hour=(hour)
243
- unless ISO8601Time.valid_hour?(hour, @minute, @second)
247
+ unless TimeDefinitions.valid_hour?(hour, @minute, @second)
244
248
  raise ArgumentError, "hour is not valid"
245
249
  end
246
250
  @hour = hour
@@ -251,7 +255,7 @@ module OpenEHR
251
255
  end
252
256
 
253
257
  def minute=(minute)
254
- raise ArgumentError, "minute is not valid" if !minute.nil? and !ISO8601Time.valid_minute?(minute)
258
+ raise ArgumentError, "minute is not valid" if !minute.nil? and !TimeDefinitions.valid_minute?(minute)
255
259
  @minute = minute
256
260
  end
257
261
 
@@ -261,7 +265,7 @@ module OpenEHR
261
265
 
262
266
  def second=(second)
263
267
  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)
268
+ raise ArgumentError, "second is not valid" if !second.nil? and !TimeDefinitions.valid_second?(second)
265
269
  @second = second
266
270
  end
267
271
 
@@ -280,8 +284,8 @@ module OpenEHR
280
284
  end
281
285
 
282
286
  def timezone=(timezone)
283
- unless timezone.nil? or timezone == 'Z'
284
- if /[+-](\d{2}):?(\d{2})/ =~ timezone
287
+ unless timezone.nil?
288
+ if /([+-](\d{2}):?(\d{2})|Z)/ =~ timezone
285
289
  @timezone = timezone
286
290
  else
287
291
  raise ArgumentError, "timezone invalid"
@@ -328,10 +332,10 @@ module OpenEHR
328
332
  end
329
333
  end
330
334
 
331
- class ISO8601Time < TimeDefinitions
335
+ class ISO8601Time
332
336
  include ISO8601TimeModule, Comparable
333
337
  def initialize(string)
334
- /(\d{2}):?(\d{2})?(:?)(\d{2})?((\.|,)(\d+))?(Z|([+-](\d{2}):?(\d{2})))?/ =~ string
338
+ /^(\d{2}):?(\d{2})?(:?)(\d{2})?((\.|,)(\d+))?(Z|([+-](\d{2}):?(\d{2})))?$/ =~ string
335
339
  if $2.nil?
336
340
  self.minute = nil
337
341
  else
@@ -376,12 +380,12 @@ module OpenEHR
376
380
  return false
377
381
  end
378
382
  if !mm.nil?
379
- if !self.valid_minute?(mm.to_i)
383
+ if !TimeDefinitions.valid_minute?(mm.to_i)
380
384
  return false
381
385
  end
382
386
  end
383
387
  if !ss.nil?
384
- if !self.valid_second?(ss.to_i)
388
+ if !TimeDefinitions.valid_second?(ss.to_i)
385
389
  return false
386
390
  end
387
391
  end
@@ -435,7 +439,7 @@ module OpenEHR
435
439
  class ISO8601DateTime < ISO8601Date
436
440
  include ISO8601DateTimeModule
437
441
  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
442
+ unless /(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?T(\d{2})(?::(\d{2})(?::(\d{2})(?:(\.|,)(\d+))?)?(Z|([+-]\d{2}):?(\d{2}))?)?/ =~ string
439
443
  raise ArgumentError, 'format invalid'
440
444
  else
441
445
  self.year = $1.to_i
@@ -465,15 +469,15 @@ module OpenEHR
465
469
  else
466
470
  self.hour = $4.to_i
467
471
  end
468
- if $7.nil? or $7.empty?
472
+ if $8.nil? or $8.empty?
469
473
  self.fractional_second = nil
470
474
  else
471
- self.fractional_second = ("0."+$7).to_f
475
+ self.fractional_second = ("0."+$8).to_f
472
476
  end
473
- if $8.nil?
477
+ if $9.nil?
474
478
  self.timezone = nil
475
479
  else
476
- self.timezone = $9+$10
480
+ self.timezone = $9
477
481
  end
478
482
  end
479
483
 
@@ -517,6 +521,7 @@ module OpenEHR
517
521
  end # end of ISO8601Timezone
518
522
 
519
523
  module ISO8601DurationModule
524
+ include TimeDefinitions
520
525
  attr_reader :years, :months, :weeks, :days
521
526
  attr_reader :hours, :minutes, :seconds, :fractional_second
522
527
 
@@ -607,10 +612,10 @@ module OpenEHR
607
612
  end
608
613
  end
609
614
 
610
- class ISO8601Duration < TimeDefinitions
615
+ class ISO8601Duration
611
616
  include ISO8601DurationModule
612
617
  def initialize(str)
613
- /^P((\d+)Y)?((\d+)M)?((\d+)W)?((\d)D)?(T((\d+)H)?((\d+)M)?((\d+)(\.\d+)?S)?)?$/ =~ str
618
+ /^P((\d+)[Yy])?((\d+)[Mm])?((\d+)[Ww])?((\d)[dD])?(T((\d+)[Hh])?((\d+)[Mm])?((\d+)(\.\d+)?[Ss])?)?$/ =~ str
614
619
  self.years = $2.to_i
615
620
  self.months = $4.to_i
616
621
  self.weeks = $6.to_i