-
Notifications
You must be signed in to change notification settings - Fork 2
/
medication.go
140 lines (126 loc) · 5.21 KB
/
medication.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package hdsfhir
import fhir "github.com/intervention-engine/fhir/models"
type Medication struct {
Entry
}
func (m *Medication) FHIRModels() []interface{} {
// Sometimes immunizations come across as medications, so we need to support that
_, isImmunization := m.Codes["CVX"]
if isImmunization {
return m.convertImmunization()
}
return m.convertMedication()
}
func (m *Medication) convertMedication() []interface{} {
// TODO: Use more specific medication resources (MedicationOrder, MedicationAdministration, etc.)
fhirMedicationStatement := &fhir.MedicationStatement{}
fhirMedicationStatement.Id = m.GetTempID()
fhirMedicationStatement.Patient = m.Patient.FHIRReference()
fhirMedicationStatement.Status = m.convertMedicationStatus()
if m.NegationInd {
t := true
fhirMedicationStatement.WasNotTaken = &t
}
if m.NegationReason != nil {
cc := m.NegationReason.FHIRCodeableConcept("")
fhirMedicationStatement.ReasonNotTaken = []fhir.CodeableConcept{*cc}
}
fhirMedicationStatement.EffectivePeriod = m.GetFHIRPeriod()
fhirMedicationStatement.MedicationCodeableConcept = m.Codes.FHIRCodeableConcept(m.Description)
// Ignoring dosage, route, etc.
return []interface{}{fhirMedicationStatement}
}
// convertMedicationStatus maps the status to a code in the required FHIR value set:
// http://hl7.org/fhir/DSTU2/valueset-medication-statement-status.html
func (m *Medication) convertMedicationStatus() string {
var status string
statusConcept := m.StatusCode.FHIRCodeableConcept("")
switch {
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "active"):
status = "active"
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "cancelled"):
status = "entered-in-error"
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "held"):
status = "intended"
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "new"):
status = "intended"
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "suspended"):
status = "completed"
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "nullified"):
status = "entered-in-error"
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "obsolete"):
status = "cancelled"
// NOTE: this is not a real ActStatus, but HDS seems to use it
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "ordered"):
status = "intended"
// NOTE: this is not a real ActStatus, but HDS seems to use it
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "discharge"):
status = "intended"
// NOTE: this is not a real ActStatus, but HDS seems to use it
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "dispensed"):
status = "intended"
case m.MoodCode == "RQO":
status = "intended"
case len(m.StatusCode) == 0 && m.EndTime == nil:
status = "active"
default:
status = "completed"
}
return status
}
func (m *Medication) convertImmunization() []interface{} {
fhirImmunization := &fhir.Immunization{}
fhirImmunization.Id = m.GetTempID()
fhirImmunization.Status = m.convertImmunizationStatus()
if m.StartTime != nil {
fhirImmunization.Date = m.StartTime.FHIRDateTime()
}
fhirImmunization.VaccineCode = m.Codes.FHIRCodeableConcept(m.Description)
fhirImmunization.Patient = m.Patient.FHIRReference()
if m.NegationInd {
t := true
fhirImmunization.WasNotGiven = &t
}
if m.NegationReason != nil {
cc := m.NegationReason.FHIRCodeableConcept("")
fhirImmunization.Explanation = &fhir.ImmunizationExplanationComponent{
ReasonNotGiven: []fhir.CodeableConcept{*cc},
}
}
// Ignoring dosage, route, etc.
return []interface{}{fhirImmunization}
}
// convertImmunizationStatus maps the status to a code in the required FHIR value set:
// http://hl7.org/fhir/DSTU2/valueset-medication-admin-status.html
func (m *Medication) convertImmunizationStatus() string {
var status string
statusConcept := m.StatusCode.FHIRCodeableConcept("")
switch {
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "aborted"):
status = "stopped"
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "active"):
status = "in-progress"
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "cancelled"):
status = "entered-in-error"
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "held"):
status = "on-hold"
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "new"):
status = "intended"
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "suspended"):
status = "on-hold"
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "nullified"):
status = "entered-in-error"
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "obsolete"):
status = "entered-in-error"
// NOTE: this is not a real ActStatus, but HDS seems to use it
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "ordered"):
status = "intended"
case m.MoodCode == "RQO":
status = "intended"
case len(m.StatusCode) == 0 && m.EndTime == nil:
status = "in-progress"
default:
status = "completed"
}
return status
}