-
Notifications
You must be signed in to change notification settings - Fork 2
/
encounter.go
67 lines (61 loc) · 2.57 KB
/
encounter.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
package hdsfhir
import fhir "github.com/intervention-engine/fhir/models"
type Encounter struct {
Entry
Reason *Entry `json:"reason"`
DischargeDisposition *CodeObject `json:"dischargeDisposition"`
}
func (e *Encounter) FHIRModels() []interface{} {
fhirEncounter := &fhir.Encounter{}
fhirEncounter.Id = e.GetTempID()
fhirEncounter.Status = e.convertStatus()
typeConcept := e.Codes.FHIRCodeableConcept(e.Description)
fhirEncounter.Type = []fhir.CodeableConcept{*typeConcept}
fhirEncounter.Patient = e.Patient.FHIRReference()
fhirEncounter.Period = e.GetFHIRPeriod()
if e.Reason != nil && len(e.Reason.Codes) > 0 {
reasonConcept := e.Reason.Codes.FHIRCodeableConcept("")
fhirEncounter.Reason = []fhir.CodeableConcept{*reasonConcept}
}
if e.DischargeDisposition != nil {
fhirEncounter.Hospitalization = &fhir.EncounterHospitalizationComponent{
DischargeDisposition: e.DischargeDisposition.FHIRCodeableConcept(""),
}
}
return []interface{}{fhirEncounter}
}
// convertStatus maps the status to a code in the required FHIR value set:
// http://hl7.org/fhir/DSTU2/valueset-encounter-state.html
// If the status cannot be reliably mapped, "finished" will be assumed. Note that this code is
// built to handle even some statuses that HDS does not currently return (active, cancelled, etc.)
func (e *Encounter) convertStatus() string {
var status string
statusConcept := e.StatusCode.FHIRCodeableConcept("")
switch {
// Negated encounters are rare, but if we run into one, call it cancelled
case e.NegationInd:
status = "cancelled"
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 = "cancelled"
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "held"):
status = "planned"
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "new"):
status = "planned"
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "suspended"):
status = "onleave"
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "nullified"):
status = "cancelled"
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 = "planned"
case e.MoodCode == "RQO":
status = "planned"
default:
status = "finished"
}
return status
}