health-data-standards 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/lib/health-data-standards.rb +20 -1
  2. data/lib/health-data-standards/export/ccr.rb +30 -5
  3. data/lib/health-data-standards/export/green_c32/entry.rb +15 -0
  4. data/lib/health-data-standards/export/green_c32/export_generator.rb +23 -0
  5. data/lib/health-data-standards/export/template_helper.rb +0 -1
  6. data/lib/health-data-standards/import/c32/condition_importer.rb +66 -0
  7. data/lib/health-data-standards/import/c32/provider_importer.rb +66 -0
  8. data/lib/health-data-standards/import/c32/section_importer.rb +2 -0
  9. data/lib/health-data-standards/import/ccr/patient_importer.rb +208 -0
  10. data/lib/health-data-standards/import/ccr/product_importer.rb +60 -0
  11. data/lib/health-data-standards/import/ccr/provider_importer.rb +62 -0
  12. data/lib/health-data-standards/import/ccr/result_importer.rb +49 -0
  13. data/lib/health-data-standards/import/ccr/section_importer.rb +124 -0
  14. data/lib/health-data-standards/import/ccr/simple_importer.rb +30 -0
  15. data/lib/health-data-standards/import/green_c32/condition_importer.rb +45 -0
  16. data/lib/health-data-standards/import/green_c32/patient_importer.rb +14 -0
  17. data/lib/health-data-standards/import/green_c32/result_importer.rb +30 -0
  18. data/lib/health-data-standards/import/green_c32/section_importer.rb +93 -0
  19. data/lib/health-data-standards/models/comment.rb +2 -0
  20. data/lib/health-data-standards/models/condition.rb +10 -0
  21. data/lib/health-data-standards/models/entry.rb +5 -0
  22. data/lib/health-data-standards/models/fulfillment_history.rb +2 -0
  23. data/lib/health-data-standards/models/lab_result.rb +1 -0
  24. data/lib/health-data-standards/models/provider.rb +51 -0
  25. data/lib/health-data-standards/models/provider_performance.rb +10 -0
  26. data/lib/health-data-standards/models/record.rb +21 -4
  27. data/lib/health-data-standards/models/treating_provider.rb +3 -0
  28. data/lib/health-data-standards/util/hl7_helper.rb +1 -0
  29. data/templates/_condition.gc32.erb +11 -0
  30. data/templates/_result.gc32.erb +20 -0
  31. data/templates/show.c32.erb +16 -5
  32. metadata +33 -12
@@ -0,0 +1,2 @@
1
+ class Comment < Entry
2
+ end
@@ -0,0 +1,10 @@
1
+ class Condition < Entry
2
+ field :type, type: String
3
+ field :causeOfDeath, type: Boolean
4
+ field :name, type: String
5
+
6
+ # embeds_many :treating_provider, class_name: "Provider"
7
+
8
+ alias :cause_of_death :causeOfDeath
9
+ alias :cause_of_death= :causeOfDeath=
10
+ end
@@ -11,6 +11,11 @@ class Entry
11
11
  field :status, type: String
12
12
  field :codes, type: Hash, default: {}
13
13
  field :value, type: Hash, default: {}
14
+
15
+ attr_protected :version
16
+ attr_protected :_id
17
+ attr_protected :created_at
18
+ attr_protected :updated_at
14
19
 
15
20
  def single_code_value?
16
21
  codes.size == 1 && codes.first[1].size == 1
@@ -9,6 +9,8 @@ class FulfillmentHistory
9
9
  field :fillNumber, type: Integer
10
10
  field :fillStatus, type: Hash
11
11
 
12
+ alias :prescription_number :prescriptionNumber
13
+ alias :prescription_number= :prescriptionNumber=
12
14
  alias :dispensing_pharmacy_location :dispensingPharmacyLocation
13
15
  alias :dispensing_pharmacy_location= :dispensingPharmacyLocation=
14
16
  alias :dispense_date :dispenseDate
@@ -4,4 +4,5 @@ class LabResult < Entry
4
4
 
5
5
  alias :reference_range :referenceRange
6
6
  alias :reference_range= :referenceRange=
7
+
7
8
  end
@@ -0,0 +1,51 @@
1
+ class Provider
2
+ include Mongoid::Document
3
+
4
+ field :title , type: String
5
+ field :given_name , type: String
6
+ field :family_name , type: String
7
+ field :npi , type: String
8
+ field :tin , type: String
9
+ field :specialty , type: String
10
+ field :phone , type: String
11
+ field :organization, type: String
12
+
13
+ validates_uniqueness_of :npi, allow_blank: true
14
+
15
+
16
+ def records(effective_date=nil)
17
+ Record.by_provider(self, effective_date)
18
+ end
19
+
20
+ # validate the NPI, should be 10 or 15 digits total with the final digit being a
21
+ # checksum using the Luhn algorithm with additional special handling as described in
22
+ # https://www.cms.gov/NationalProvIdentStand/Downloads/NPIcheckdigit.pdf
23
+ def self.valid_npi?(npi)
24
+ return false if npi.length != 10 and npi.length != 15
25
+ return false if npi.gsub(/\d/, '').length > 0 # npi must be all digits
26
+ return false if npi.length == 15 and (npi =~ /^80840/)==nil # 15 digit npi must start with 80840
27
+
28
+ # checksum is always calculated as if 80840 prefix is present
29
+ if npi.length==10
30
+ npi = '80840'+npi
31
+ end
32
+
33
+ return luhn_checksum(npi[0,14])==npi[14]
34
+ end
35
+
36
+ def self.luhn_checksum(num)
37
+ double = {'0' => 0, '1' => 2, '2' => 4, '3' => 6, '4' => 8, '5' => 1, '6' => 3, '7' => 5, '8' => 7, '9' => 9}
38
+ sum = 0
39
+ num.reverse!
40
+ num.split("").each_with_index do |char, i|
41
+ if (i%2)==0
42
+ sum+=double[char]
43
+ else
44
+ sum+=char.to_i
45
+ end
46
+ end
47
+ sum = (9*sum)%10
48
+
49
+ return sum.to_s
50
+ end
51
+ end
@@ -0,0 +1,10 @@
1
+ class ProviderPerformance
2
+ include Mongoid::Document
3
+
4
+ field :start_date, type: Integer
5
+ field :end_date, type: Integer
6
+
7
+ belongs_to :provider
8
+ embedded_in :record
9
+
10
+ end
@@ -1,11 +1,11 @@
1
1
  class Record
2
-
3
2
  include Mongoid::Document
4
3
 
5
4
  field :first, type: String
6
5
  field :last, type: String
7
6
  field :gender, type: String
8
7
  field :birthdate, type: Integer
8
+ field :deathdate, type: Integer
9
9
  field :effective_time, type: Integer
10
10
  field :race, type: Hash
11
11
  field :ethnicity, type: Hash
@@ -13,14 +13,31 @@ class Record
13
13
  field :test_id, type: BSON::ObjectId
14
14
  field :medical_record_number, type: String
15
15
 
16
+ embeds_many :allergies
17
+ embeds_many :care_goals, class_name: "Entry"
18
+ embeds_many :conditions, class_name: "Entry"
19
+ embeds_many :encounters
20
+ embeds_many :immunizations
21
+ embeds_many :medical_equipment, class_name: "Entry"
22
+ embeds_many :medications
23
+ embeds_many :procedures
24
+ embeds_many :results, class_name: "LabResult"
25
+ embeds_many :social_history, class_name: "Entry"
26
+ embeds_many :vital_signs, class_name: "Entry"
27
+
16
28
  Sections = [:allergies, :care_goals, :conditions, :encounters, :immunizations, :medical_equipment,
17
29
  :medications, :procedures, :results, :social_history, :vital_signs]
18
30
 
19
- Sections.each do |section|
20
- embeds_many section, as: :entry_list, class_name: "Entry"
31
+ embeds_many :provider_performances
32
+
33
+ scope :by_provider, ->(prov, effective_date) { (effective_date) ? where(provider_queries(prov.id, effective_date)) : where('provider_performances.provider_id'=>prov.id) }
34
+ scope :by_patient_id, ->(id) { where(:medical_record_number => id) }
35
+
36
+ def providers
37
+ provider_performances.map {|pp| pp.provider }
21
38
  end
22
39
 
23
40
  def over_18?
24
41
  Time.at(birthdate) < Time.now.years_ago(18)
25
42
  end
26
- end
43
+ end
@@ -0,0 +1,3 @@
1
+ class TreatingProvider < Entry
2
+ field :treatingProviderID, type: Integer
3
+ end
@@ -20,6 +20,7 @@ module HealthDataStandards
20
20
  nil
21
21
  end
22
22
  end
23
+
23
24
  end
24
25
  end
25
26
  end
@@ -0,0 +1,11 @@
1
+ <condition <% if condition.cause_of_death %> causeOfDeath="true" <% end %> xmlns="urn:hl7-org:greencda:c32">
2
+ <id><%= condition.id%></id>
3
+ <%== code_display result, "tag_name" => "code", 'preferred_code_sets' => ['SNOMED-CT'] %>
4
+ <% if condition.name %>
5
+ <name><%= condition.name%></name>
6
+ <% end %>
7
+ <effectiveTime>
8
+ <start><%= Time.at(condition.start_time)%></start>
9
+ <end><%= Time.at(condition.end_time)%></end>
10
+ </effectiveTime>
11
+ </condition>
@@ -0,0 +1,20 @@
1
+ <result xmlns="urn:hl7-org:greencda:c32">
2
+ <id><%= result.id %></id>
3
+
4
+ <%== code_display result, "tag_name" => "code", 'preferred_code_sets' => ['SNOMED-CT'] %>
5
+ <% if result.status %>
6
+ <status code="completed"/>
7
+ <% end %>
8
+
9
+ <effectiveTime><%= Time.at(result.time) %></effectiveTime>
10
+
11
+
12
+ <value amount="<%= result.value['scalar']%>" unit="<%= result.value['units'] %>" />
13
+ <% if result.interpretation%>
14
+ <% code = result.interpretation.first%>
15
+ <interpretation code="<%= code.last %>" codeSystem="<%= CodeSystemHelper.oid_for_code_system(code.first) %>">
16
+ <% end %>
17
+ <% if result.reference_range %>
18
+ <referenceRange><%= result.reference_range %></referenceRange>
19
+ <% end %>
20
+ </result>
@@ -29,11 +29,22 @@
29
29
  </name>
30
30
  <administrativeGenderCode code="<%= patient.gender %>" codeSystem="2.16.840.1.113883.5.1" codeSystemName="HL7 AdministrativeGender"/>
31
31
  <birthTime value="<%= Time.at(patient.birthdate).utc.to_formatted_s(:number) %>"/>
32
- <languageCommunication>
33
- <templateId root="2.16.840.1.113883.3.88.11.83.2" assigningAuthorityName="HITSP/C83"/>
34
- <templateId root="1.3.6.1.4.1.19376.1.5.3.1.2.1" assigningAuthorityName="IHE/PCC"/>
35
- <languageCode code="en-US"/>
36
- </languageCommunication>
32
+ <% if (patient.race) %>
33
+ <raceCode code="<%= patient.race['code'] %>" <% if patient.race['name']%>displayName="<%= patient.race['name'] %>"<% end %> codeSystemName="CDC Race and Ethnicity" codeSystem="2.16.840.1.113883.6.238"/>
34
+ <% end %>
35
+ <% if (patient.race) %>
36
+ <ethnicGroupCode code="<%= patient.ethnicity['code'] %>" <% if patient.ethnicity['name']%>displayName="<%= patient.ethnicity['name'] %>"<% end %> codeSystemName="CDC Race and Ethnicity" codeSystem="2.16.840.1.113883.6.238"/>
37
+ <% end %>
38
+ <%
39
+ languages = patient.languages
40
+ languages = ["en-US"] if languages.nil? or languages.empty?
41
+ languages.each do |language|%>
42
+ <languageCommunication>
43
+ <templateId root="2.16.840.1.113883.3.88.11.83.2" assigningAuthorityName="HITSP/C83"/>
44
+ <templateId root="1.3.6.1.4.1.19376.1.5.3.1.2.1" assigningAuthorityName="IHE/PCC"/>
45
+ <languageCode code="<%= language %>"/>
46
+ </languageCommunication>
47
+ <% end %>
37
48
  </patient>
38
49
  </patientRole>
39
50
  </recordTarget>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: health-data-standards
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-31 00:00:00.000000000 -05:00
12
+ date: 2012-02-17 00:00:00.000000000 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: erubis
17
- requirement: &2152718120 !ruby/object:Gem::Requirement
17
+ requirement: &2153337220 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '2.6'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2152718120
25
+ version_requirements: *2153337220
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: mongoid
28
- requirement: &2152717640 !ruby/object:Gem::Requirement
28
+ requirement: &2153336700 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 2.4.2
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2152717640
36
+ version_requirements: *2153336700
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: uuid
39
- requirement: &2152717180 !ruby/object:Gem::Requirement
39
+ requirement: &2153336240 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 2.3.4
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *2152717180
47
+ version_requirements: *2153336240
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: builder
50
- requirement: &2152716720 !ruby/object:Gem::Requirement
50
+ requirement: &2153335760 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 3.0.0
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *2152716720
58
+ version_requirements: *2153335760
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: nokogiri
61
- requirement: &2152716260 !ruby/object:Gem::Requirement
61
+ requirement: &2153335280 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,7 +66,7 @@ dependencies:
66
66
  version: 1.4.7
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *2152716260
69
+ version_requirements: *2153335280
70
70
  description: A library for generating and consuming various healthcare related formats.
71
71
  This includes HITSP C32, ASTM CCR and PQRI.
72
72
  email: talk@projectpophealth.org
@@ -77,21 +77,37 @@ files:
77
77
  - lib/health-data-standards/export/c32.rb
78
78
  - lib/health-data-standards/export/ccr.rb
79
79
  - lib/health-data-standards/export/csv.rb
80
+ - lib/health-data-standards/export/green_c32/entry.rb
81
+ - lib/health-data-standards/export/green_c32/export_generator.rb
80
82
  - lib/health-data-standards/export/rendering_context.rb
81
83
  - lib/health-data-standards/export/template_helper.rb
82
84
  - lib/health-data-standards/export/view_helper.rb
83
85
  - lib/health-data-standards/ext/string.rb
84
86
  - lib/health-data-standards/ext/symbol.rb
85
87
  - lib/health-data-standards/import/c32/allergy_importer.rb
88
+ - lib/health-data-standards/import/c32/condition_importer.rb
86
89
  - lib/health-data-standards/import/c32/encounter_importer.rb
87
90
  - lib/health-data-standards/import/c32/immunization_importer.rb
88
91
  - lib/health-data-standards/import/c32/medication_importer.rb
89
92
  - lib/health-data-standards/import/c32/patient_importer.rb
90
93
  - lib/health-data-standards/import/c32/procedure_importer.rb
94
+ - lib/health-data-standards/import/c32/provider_importer.rb
91
95
  - lib/health-data-standards/import/c32/result_importer.rb
92
96
  - lib/health-data-standards/import/c32/section_importer.rb
93
97
  - lib/health-data-standards/import/c32/vital_sign_importer.rb
98
+ - lib/health-data-standards/import/ccr/patient_importer.rb
99
+ - lib/health-data-standards/import/ccr/product_importer.rb
100
+ - lib/health-data-standards/import/ccr/provider_importer.rb
101
+ - lib/health-data-standards/import/ccr/result_importer.rb
102
+ - lib/health-data-standards/import/ccr/section_importer.rb
103
+ - lib/health-data-standards/import/ccr/simple_importer.rb
104
+ - lib/health-data-standards/import/green_c32/condition_importer.rb
105
+ - lib/health-data-standards/import/green_c32/patient_importer.rb
106
+ - lib/health-data-standards/import/green_c32/result_importer.rb
107
+ - lib/health-data-standards/import/green_c32/section_importer.rb
94
108
  - lib/health-data-standards/models/allergy.rb
109
+ - lib/health-data-standards/models/comment.rb
110
+ - lib/health-data-standards/models/condition.rb
95
111
  - lib/health-data-standards/models/encounter.rb
96
112
  - lib/health-data-standards/models/entry.rb
97
113
  - lib/health-data-standards/models/fulfillment_history.rb
@@ -100,7 +116,10 @@ files:
100
116
  - lib/health-data-standards/models/medication.rb
101
117
  - lib/health-data-standards/models/order_information.rb
102
118
  - lib/health-data-standards/models/procedure.rb
119
+ - lib/health-data-standards/models/provider.rb
120
+ - lib/health-data-standards/models/provider_performance.rb
103
121
  - lib/health-data-standards/models/record.rb
122
+ - lib/health-data-standards/models/treating_provider.rb
104
123
  - lib/health-data-standards/util/code_system_helper.rb
105
124
  - lib/health-data-standards/util/hl7_helper.rb
106
125
  - lib/health-data-standards.rb
@@ -108,6 +127,7 @@ files:
108
127
  - templates/_allergies_no_current.c32.erb
109
128
  - templates/_care_goals.c32.erb
110
129
  - templates/_code_with_reference.c32.erb
130
+ - templates/_condition.gc32.erb
111
131
  - templates/_conditions.c32.erb
112
132
  - templates/_conditions_no_current.c32.erb
113
133
  - templates/_encounters.c32.erb
@@ -117,6 +137,7 @@ files:
117
137
  - templates/_medications_no_current.c32.erb
118
138
  - templates/_narrative_block.c32.erb
119
139
  - templates/_procedures.c32.erb
140
+ - templates/_result.gc32.erb
120
141
  - templates/_results.c32.erb
121
142
  - templates/_social_history.c32.erb
122
143
  - templates/_vital_signs.c32.erb