-
Notifications
You must be signed in to change notification settings - Fork 2
/
condition.go
90 lines (80 loc) · 3.4 KB
/
condition.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
package hdsfhir
import fhir "github.com/intervention-engine/fhir/models"
type Condition struct {
Entry
// NOTE: HDS has inconsistent representations of severity, but the only working importer (cat1)
// models it like a CodeMap -- so that's what we assume. Note the difference from Allergy.
Severity CodeMap `json:"severity"`
}
func (c *Condition) FHIRModels() []interface{} {
fhirCondition := &fhir.Condition{}
fhirCondition.Id = c.GetTempID()
fhirCondition.Patient = c.Patient.FHIRReference()
fhirCondition.Code = c.Codes.FHIRCodeableConcept(c.Description)
// TODO: consider setting category to "diagnosis"
fhirCondition.ClinicalStatus = c.convertClinicalStatus()
if c.NegationInd {
fhirCondition.VerificationStatus = "refuted"
} else {
fhirCondition.VerificationStatus = "confirmed"
}
fhirCondition.Severity = c.convertSeverity()
if c.StartTime != nil {
fhirCondition.OnsetDateTime = c.StartTime.FHIRDateTime()
}
if c.EndTime != nil {
fhirCondition.AbatementDateTime = c.EndTime.FHIRDateTime()
}
return []interface{}{fhirCondition}
}
// convertClinicalStatus maps the clinical status to a code in the "preferred" FHIR value set:
// http://hl7.org/fhir/DSTU2/valueset-condition-clinical.html
// If the status cannot be reliably mapped, an empty code will be returned.
func (c *Condition) convertClinicalStatus() string {
var status string
statusConcept := c.StatusCode.FHIRCodeableConcept("")
switch {
case statusConcept.MatchesCode("http://snomed.info/sct", "55561003"):
status = "active"
case statusConcept.MatchesCode("http://snomed.info/sct", "73425007"):
status = "remission"
case statusConcept.MatchesCode("http://snomed.info/sct", "413322009"):
status = "resolved"
case statusConcept.MatchesCode("http://hl7.org/fhir/ValueSet/v3-ActStatus", "active"):
status = "active"
}
// In order to remain consistent, fix the status if there is an end date (abatement)
// and it doesn't match the start date (in which case we can't be sure it's really an end)
if status == "" && c.EndTime != nil && c.StartTime != nil && *c.EndTime != *c.StartTime {
status = "resolved"
}
return status
}
// convertSeverity maps the severity to a CodeableConcept. If possible, it will add a display name.
// FHIR has a "preferred" value set for severity:
// http://hl7.org/fhir/DSTU2/valueset-condition-severity.html
// Note that this is a subset of the value set that is often used:
// https://phinvads.cdc.gov/vads/ViewValueSet.action?id=72FDBFB5-A277-DE11-9B52-0015173D1785
// Rather than make a subjective mapping decision, we keep the codes as-is, which is likely
// more in line with the larger value set (containing "mild to moderate" and "moderate to severe")
func (c *Condition) convertSeverity() *fhir.CodeableConcept {
if len(c.Severity) == 0 {
return nil
}
severity := c.Severity.FHIRCodeableConcept("")
switch {
case severity.MatchesCode("http://snomed.info/sct", "399166001"):
severity.Text = "Fatal"
case severity.MatchesCode("http://snomed.info/sct", "255604002"):
severity.Text = "Mild"
case severity.MatchesCode("http://snomed.info/sct", "371923003"):
severity.Text = "Mild to moderate"
case severity.MatchesCode("http://snomed.info/sct", "6736007"):
severity.Text = "Moderate"
case severity.MatchesCode("http://snomed.info/sct", "371924009"):
severity.Text = "Moderate to severe"
case severity.MatchesCode("http://snomed.info/sct", "24484000"):
severity.Text = "Severe"
}
return severity
}