/
bluebutton.go
69 lines (61 loc) · 2.26 KB
/
bluebutton.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
package worker
import (
"encoding/json"
"strings"
"github.com/CMSgov/bcda-app/bcda/client"
models "github.com/CMSgov/bcda-app/bcda/models"
"github.com/pkg/errors"
)
// This method will ensure that a valid BlueButton ID is returned.
// If you use cclfBeneficiary.BlueButtonID you will not be guaranteed a valid value
func getBlueButtonID(bb client.APIClient, mbi string, jobData models.JobEnqueueArgs) (blueButtonID string, err error) {
hashedIdentifier, err := client.HashIdentifier(mbi)
if err != nil {
return "", err
}
jsonData, err := bb.GetPatientByIdentifierHash(jobData, hashedIdentifier)
if err != nil {
return "", err
}
var patient models.Patient
err = json.Unmarshal([]byte(jsonData), &patient)
if err != nil {
return "", err
}
if len(patient.Entry) == 0 {
err = errors.New("patient identifier not found at Blue Button for CCLF")
return "", err
}
var foundIdentifier = false
var foundBlueButtonID = false
blueButtonID = patient.Entry[0].Resource.ID
for _, identifier := range patient.Entry[0].Resource.Identifier {
if strings.Contains(identifier.System, "us-mbi") {
if identifier.Value == mbi {
foundIdentifier = true
}
} else if strings.Contains(identifier.System, "bene_id") && identifier.Value == blueButtonID {
foundBlueButtonID = true
} else if strings.EqualFold(identifier.System, "http://terminology.hl7.org/CodeSystem/v2-0203") {
// This hot-fix logic to handle the changes made in this PR:
// https://github.com/CMSgov/beneficiary-fhir-data/pull/474
// Specifically:
// https://github.com/CMSgov/beneficiary-fhir-data/pull/474/files#diff-97195cabdd2698fa9148e9ad32fb8fef8dd462a55dabb9eaf4a4b4300f691fddL112
// https://github.com/CMSgov/beneficiary-fhir-data/pull/474/files#diff-97195cabdd2698fa9148e9ad32fb8fef8dd462a55dabb9eaf4a4b4300f691fddR132
// https://github.com/CMSgov/beneficiary-fhir-data/pull/474/files#diff-97195cabdd2698fa9148e9ad32fb8fef8dd462a55dabb9eaf4a4b4300f691fddL191
if identifier.Value == mbi {
foundIdentifier = true
foundBlueButtonID = true
}
}
}
if !foundIdentifier {
err = errors.New("Identifier not found")
return "", err
}
if !foundBlueButtonID {
err = errors.New("Blue Button identifier not found in the identifiers")
return "", err
}
return blueButtonID, nil
}