health_seven 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,6 @@
1
- # Version numbering: http://wiki.github.com/sandal/prawn/development-roadmap
2
- HEALTH_SEVEN_VERSION = "0.0.2"
3
-
4
1
  Gem::Specification.new do |spec|
5
2
  spec.name = "health_seven"
6
- spec.version = HEALTH_SEVEN_VERSION
3
+ spec.version = "0.0.3"
7
4
  spec.platform = Gem::Platform::RUBY
8
5
  spec.summary = "Ruby library for hl7 2.x"
9
6
  spec.files = Dir.glob("{lib,spec}/**/**/*") +
@@ -48,7 +48,7 @@ module HealthSeven
48
48
  gramar.push <<-RULE
49
49
 
50
50
  rule #{self.rule_name}
51
- #{seg_name} payload delim #{_children_enum.join(" ")} <HealthSeven::SegmentLiteral>
51
+ #{seg_name} payload delim #{_children_enum.join(" ")} <HealthSeven::SegmentLiteral>
52
52
  end
53
53
  RULE
54
54
 
@@ -75,24 +75,52 @@ module HealthSeven
75
75
  end
76
76
  end
77
77
  end
78
+
78
79
  class MessageDef < SegmentDef
80
+ def _children_enum
81
+ @segments.map do |s|
82
+ s.dsl_off!
83
+ s.rule_name
84
+ end
85
+ end
86
+
87
+ def optional
88
+ @optional ||= @segments.map do |s|
89
+ s.rule_name if s.optional?
90
+ end.compact
91
+ end
92
+
93
+ def required
94
+ @reqired ||= @segments.map do |s|
95
+ s.rule_name unless s.optional?
96
+ end.compact
97
+ end
98
+
79
99
  def to_gramar(gramar)
80
100
  gramar.push <<-RULE
81
101
 
82
102
  rule message
83
- #{_children_enum.join(" ")} "\\n" <HealthSeven::SegmentLiteral>
103
+ msh segment* "\\n" <HealthSeven::SegmentLiteral>
104
+ end
105
+
106
+ rule segment
107
+ #{_children_enum.join(" / ")}
84
108
  end
85
109
 
86
110
  rule delim
87
- "#{13.chr}"
111
+ "#{13.chr}"
88
112
  end
89
113
 
90
114
  rule not_delim
91
- [^#{13.chr}]
115
+ [^#{13.chr}]
92
116
  end
93
117
 
94
118
  rule payload
95
- not_delim+ <HealthSeven::FieldsLiteral>
119
+ not_delim+ <HealthSeven::FieldsLiteral>
120
+ end
121
+
122
+ rule msh
123
+ 'MSH' payload delim <HealthSeven::SegmentLiteral>
96
124
  end
97
125
  RULE
98
126
 
@@ -181,7 +209,9 @@ module HealthSeven
181
209
  raise HealthSeven::BadGrammarException, message
182
210
  end
183
211
  msg = Message.new
212
+ @required_segments = Object.const_get("#{self.name}").message_def.required
184
213
  self.clean_tree(ast_tree, msg)
214
+ raise "No required segment(s) found: #{@required_segments.join(', ')}" unless @required_segments.empty?
185
215
 
186
216
  msg
187
217
  end
@@ -193,6 +223,7 @@ module HealthSeven
193
223
 
194
224
  segment.name = node.name
195
225
  segment.fields = node.fields
226
+ @required_segments.delete(node.name.downcase)
196
227
 
197
228
  return true unless node.elements
198
229
  node.elements.each do |e|
@@ -3,7 +3,6 @@ require 'spec_helper'
3
3
  describe HealthSeven::Message do
4
4
  class AdmitMessage < HealthSeven::Message
5
5
  define_message do
6
- msh
7
6
  evn
8
7
  pid
9
8
  nk1
@@ -38,4 +37,11 @@ describe HealthSeven::Message do
38
37
  error.message.should =~ 'IN2'
39
38
  end
40
39
  end
40
+
41
+ it 'should not raise an exception in case of incorrect order of top level segments' do
42
+ -> {
43
+ msg = AdmitMessage.parse(load_message('disordered_admit'))
44
+ }.should_not raise_error
45
+
46
+ end
41
47
  end
@@ -3,7 +3,6 @@ require 'spec_helper'
3
3
  describe HealthSeven::Message do
4
4
  class DiagnosesMessage < HealthSeven::Message
5
5
  define_message do
6
- msh
7
6
  evn
8
7
  pid
9
8
  pv1?
@@ -0,0 +1,12 @@
1
+ MSH|^~\&|MS4ADT|001|UST|001|20090123204848||ADT^A04|00000000008186657|P|2.3
2
+ PID|1|111111122^^^MS4^PN^|11-22-33^^^MS4^MR^001|11-22-33^^^MS4^MR^001|SMITH^LIDA^^^||19670101|F||P|9166 NEW-YORK CANYON^(OAKVIEW CONV)^NEW-YORK^CA^91042^^^||(111)111-2222|| 31|W|OTH|00016604787^^^MS4001^AN^001|000-00-0000
3
+ EVN|A04|20090123204846|||NURSE
4
+ NK1|1|IVANOV^JOHN^^^|J|7903 HELLSTREET^^NEW-YORK^CA^91040^^|(222)222-3333||S||||||UNKNOWN|S|F||||||||||NON||||||||202244189^^^MS4^PN^||C|| 1
5
+ PV1||I|ICU5^T589^ A^001^OCCPD|1|||20131^PARTAMIAN^LEON^N^^^MD^^^^^^^|||MED||||7||||I||0401|3||||||||||||||||||001|OCCPD||||200901192300||46141.20|46141.20
6
+ AL1|1|FA|NONE^NONE^^^^|||
7
+ GT1|1|111111122^^^MS4^PN^|SMITH^LIDA^^^|IVANOV^JOHN^^^|9166 NEW-YORK CANYON^(OAKVIEW CONV)^NEW-YORK^CA^91042^^|(111)111-2222||19670101|F||A|000-00-0000||||RETIRED|^^^^00000||||||||||||07496|W||||||||Y|||OTH||||||||RETIRED||||||P
8
+ IN1|1||0401|MEDICARE I/P|^^^^ |||||||19990201|||MCR|SMITH^LIDA^^^|A|19670101|9166 NEW-YORK CANYON^(OAKVIEW CONV)^NEW-YORK^CA^91042^^^^|||1||||||||||||||000000008M|||||||F|^^^^00000|Y||||111111122
9
+ IN2||000000008|07496^RETIRED|||000000008M||||||||||||||||||||||||||||||Y|||OTH||||W|||RETIRED|||||||||||||||||(111)111-2222||||||||P
10
+ IN1|2||0304|MEDI-CAL SECONDARY|P.O. BOX 15600^^NEW-YORK^CA^95891-1600|||||||19940501|||MCD|SMITH^LIDA^^^|A|19670101|9166 NEW-YORK CANYON^(OAKVIEW CONV)^NEW-YORK^CA^91042^^^^|||2||||||||||||||00000000000000|||||||F|^^^^00000|N||||111111122
11
+ IN2||000000000|07496^RETIRED|||||00000000000000||||||||||||||||||||||||||||Y|||OTH||||W|||RETIRED|||||||||||||||||(111)111-2222||||||||P
12
+ ZBC|16000087|TELPC01 |TELLABEL
@@ -3,7 +3,6 @@ require 'spec_helper'
3
3
  describe HealthSeven::Message do
4
4
  class OruMessage < HealthSeven::Message
5
5
  define_message do
6
- msh
7
6
  pid
8
7
  pv1?
9
8
  orc {
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: health_seven
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nikolay Ryzhikov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-11 00:00:00.000000000 Z
13
+ date: 2013-01-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  type: :runtime
@@ -40,6 +40,7 @@ files:
40
40
  - lib/health_seven.rb
41
41
  - spec/messages/corrupt_admit.hl7
42
42
  - spec/messages/admit.hl7
43
+ - spec/messages/disordered_admit.hl7
43
44
  - spec/messages/diagnoses.hl7
44
45
  - spec/messages/oru_r01.hl7
45
46
  - spec/diagnoses_message_spec.rb