-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmedications.go
60 lines (53 loc) · 1.45 KB
/
medications.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
package ptgen
import (
"bytes"
"encoding/json"
"github.com/intervention-engine/fhir/models"
)
type MedicationMetadata struct {
ID int `json:"medication_id"`
RxNormCode string `json:"rxNormCode"`
BrandName string `json:"brandName"`
TradeName string `json:"tradeName"`
}
func GenerateMedication(medicationID int, onset *models.FHIRDateTime, abatement *models.FHIRDateTime, mmd []MedicationMetadata) *models.MedicationStatement {
if medicationID == 0 {
return nil
} else {
ms := &models.MedicationStatement{}
mmd := medicationByID(medicationID, mmd)
ms.EffectivePeriod = &models.Period{Start: onset}
if abatement != nil {
ms.EffectivePeriod.End = abatement
ms.Status = "completed"
} else {
ms.Status = "active"
}
var medName string
if mmd.TradeName == "N/A" {
medName = mmd.BrandName
} else {
medName = mmd.TradeName
}
ms.MedicationCodeableConcept = &models.CodeableConcept{Coding: []models.Coding{{Code: mmd.RxNormCode, System: "http://www.nlm.nih.gov/research/umls/rxnorm"}}, Text: medName}
return ms
}
}
func LoadMedications() []MedicationMetadata {
j, err := Asset("data/medications.json")
if err != nil {
panic("Can't get the medications data")
}
decoder := json.NewDecoder(bytes.NewReader(j))
md := []MedicationMetadata{}
decoder.Decode(&md)
return md
}
func medicationByID(id int, md []MedicationMetadata) *MedicationMetadata {
for _, m := range md {
if m.ID == id {
return &m
}
}
return nil
}