Skip to content

Commit

Permalink
fixing unmarshalling/parsing of FHIR code sets & enums.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Nov 1, 2024
1 parent 3319331 commit e1baa08
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 3 deletions.
94 changes: 94 additions & 0 deletions clients/internal/base/fhir401_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,100 @@ func TestFhir401Client_ProcessResource(t *testing.T) {
//require.Equal(t, "A00000000000005", profile.SourceResourceID)
}

func TestFhir401Client_ProcessEncounterResource_WhichContainsCapitalizedStatusEnum_ShouldParseCorrectly(t *testing.T) {
t.Parallel()
//setup
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
sc := mock_models.NewMockSourceCredential(mockCtrl)
db := mock_models.NewMockDatabaseRepository(mockCtrl)
testLogger := logrus.WithFields(logrus.Fields{
"type": "test",
})

cernerSandboxDefinition, err := definitions.GetSourceDefinition(definitions.GetSourceConfigOptions{
EndpointId: "3290e5d7-978e-42ad-b661-1cf8a01a989c",
})
require.NoError(t, err)

client, err := GetSourceClientFHIR401(pkg.FastenLighthouseEnvSandbox, context.Background(), testLogger, sc, cernerSandboxDefinition, models.WithTestHttpClient(&http.Client{}))
require.NoError(t, err)
db.EXPECT().UpsertRawResource(gomock.Any(), gomock.Any(), gomock.Any()).Return(true, nil).AnyTimes()

jsonBytes, err := ReadTestFixture("testdata/fixtures/401-R4/document_reference/encounter_resource_broken_parse.json")
require.NoError(t, err)
referencedResourcesLookup := map[string]bool{}
internalFragmentReferenceLookup := map[string]string{}
summary := models.UpsertSummary{}

rawResource := models.RawResourceFhir{
SourceResourceID: "e7vTGSIu3VmPxDxo8hbtSKQ3",
SourceResourceType: "Encounter",
ResourceRaw: jsonBytes,
}

// test
err = client.ProcessResource(db, rawResource, referencedResourcesLookup, internalFragmentReferenceLookup, &summary)

//assert
require.NoError(t, err)
require.Equal(t, 4, len(referencedResourcesLookup))
require.Equal(t, map[string]bool{
"Encounter/e7vTGSIu3VmPxDxo8hbtSKQ3": true,
"Location/eq0Zb8k23Hg.GX9aMfavyZg3": false,
"Patient/etMDDQeIicnivVsdRrZcEQGPqfFlXIbJH5wMZqQ7ZNldGo3": false,
"Practitioner/e7y0GLCXTb0rdKZlNSuQhww3": false,
}, referencedResourcesLookup)
//require.Equal(t, "A00000000000005", profile.SourceResourceID)
}

func TestFhir401Client_ProcessObservationResource_WhichContainsUnicodeCharacters_ShouldParseCorrectly(t *testing.T) {
t.Skip("Cannot handle escaped unicode characters")
//setup
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
sc := mock_models.NewMockSourceCredential(mockCtrl)
db := mock_models.NewMockDatabaseRepository(mockCtrl)
testLogger := logrus.WithFields(logrus.Fields{
"type": "test",
})

cernerSandboxDefinition, err := definitions.GetSourceDefinition(definitions.GetSourceConfigOptions{
EndpointId: "3290e5d7-978e-42ad-b661-1cf8a01a989c",
})
require.NoError(t, err)

client, err := GetSourceClientFHIR401(pkg.FastenLighthouseEnvSandbox, context.Background(), testLogger, sc, cernerSandboxDefinition, models.WithTestHttpClient(&http.Client{}))
require.NoError(t, err)
db.EXPECT().UpsertRawResource(gomock.Any(), gomock.Any(), gomock.Any()).Return(true, nil).AnyTimes()

jsonBytes, err := ReadTestFixture("testdata/fixtures/401-R4/document_reference/observation_broken_parse.json")
require.NoError(t, err)
referencedResourcesLookup := map[string]bool{}
internalFragmentReferenceLookup := map[string]string{}
summary := models.UpsertSummary{}

rawResource := models.RawResourceFhir{
SourceResourceID: "e7vTGSIu3VmPxDxo8hbtSKQ3",
SourceResourceType: "Encounter",
ResourceRaw: jsonBytes,
}

// test
err = client.ProcessResource(db, rawResource, referencedResourcesLookup, internalFragmentReferenceLookup, &summary)

//assert
require.NoError(t, err)
require.Equal(t, 4, len(referencedResourcesLookup))
require.Equal(t, map[string]bool{
"Encounter/e7vTGSIu3VmPxDxo8hbtSKQ3": true,
"Location/eq0Zb8k23Hg.GX9aMfavyZg3": false,
"Patient/etMDDQeIicnivVsdRrZcEQGPqfFlXIbJH5wMZqQ7ZNldGo3": false,
"Practitioner/e7y0GLCXTb0rdKZlNSuQhww3": false,
}, referencedResourcesLookup)
//require.Equal(t, "A00000000000005", profile.SourceResourceID)
}

func TestFhir401Client_ProcessResourceWithContainedResources(t *testing.T) {
t.Parallel()
//setup
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"class": {
"code": "5",
"display": "Appointment",
"system": "urn:oid:1.2.840.114350.1.72.1.7.7.10.696784.13260"
},
"id": "e7vTGSIu3VmPxDxo8hbtSKQ3",
"identifier": [
{
"system": "urn:oid:1.2.840.114350.1.13.44.2.7.3.698084.8",
"use": "usual",
"value": "247735644"
}
],
"location": [
{
"location": {
"display": "Adult Orthopedics",
"reference": "Location/eq0Zb8k23Hg.GX9aMfavyZg3"
}
}
],
"participant": [
{
"individual": {
"display": "KIRK J. JAMES, MD",
"reference": "Practitioner/e7y0GLCXTb0rdKZlNSuQhww3"
},
"period": {
"end": "2019-11-21T18:00:00Z",
"start": "2018-11-21T17:40:00Z"
}
}
],
"period": {
"end": "2019-11-21T18:00:00Z",
"start": "2018-11-21T17:40:00Z"
},
"reasonCode": [
{
"coding": [
{
"code": "494",
"display": "Limb Pain",
"system": "urn:oid:1.2.840.114350.1.13.44.2.7.2.728286"
}
],
"text": "Limb Pain"
}
],
"resourceType": "Encounter",
"status": "Finished",
"subject": {
"display": "Doe, John",
"reference": "Patient/etMDDQeIicnivVsdRrZcEQGPqfFlXIbJH5wMZqQ7ZNldGo3"
},
"type": [
{
"coding": [
{
"code": "101",
"display": "Office Visit",
"system": "urn:oid:1.2.840.114350.1.13.44.2.7.10.698084.30"
}
],
"text": "Office Visit"
},
{
"coding": [
{
"code": "36",
"display": "Initial Specialty Visit",
"system": "urn:oid:1.2.840.114350.1.13.44.2.7.2.808267"
}
],
"text": "Initial Specialty Visit"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"basedOn": [
{
"display": "HEPATITIS B SURFACE ANTIBODY IMMUNITY QUANTITATIVE",
"reference": "ServiceRequest/klsdk3-PBKXHFeY0Q7KMDFz92TYK2nbYKsI3"
}
],
"category": [
{
"coding": [
{
"code": "laboratory",
"display": "Laboratory",
"system": "http://terminology.hl7.org/CodeSystem/observation-category"
}
],
"text": "Laboratory"
},
{
"coding": [
{
"code": "LAB",
"display": "LAB",
"system": "urn:oid:1.2.840.114350.1.13.44.2.7.10.798268.30"
}
],
"text": "LAB"
}
],
"code": {
"coding": [
{
"code": "5193-8",
"display": "Hepatitis B virus surface Ab [Units/volume] in Serum or Plasma by Immunoassay",
"system": "http://loinc.org"
},
{
"code": "18063",
"system": "urn:oid:1.2.840.114350.1.13.44.2.7.5.737384.80113"
},
{
"code": "18063",
"display": "HEPATITIS B SURFACE ANTIBODY QUANT",
"system": "urn:oid:1.2.840.114350.1.13.44.2.7.2.768282"
}
],
"text": "HEPATITIS B SURFACE ANTIBODY QUANT"
},
"effectiveDateTime": "2021-06-07T01:00:00Z",
"encounter": {
"display": "Lab Visit",
"identifier": {
"system": "urn:oid:1.2.840.114350.1.13.44.2.7.3.698084.8",
"use": "usual",
"value": "315534385"
},
"reference": "Encounter/exxx3In3deguCac1YMmg3"
},
"id": "eDLs6fOQWxxxxxyRm6L53E5CxAMgXynSZ6fIlFdJM8SeT.qhxNM3",
"interpretation": [
{
"coding": [
{
"code": "L",
"display": "Low",
"system": "http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation"
}
],
"text": "Low"
}
],
"issued": "2021-06-07T20:00:00Z",
"note": [
{
"text": "Patient is considered to be Not Immune to infection with HBV."
}
],
"referenceRange": [
{
"text": "\u003e=10.00"
}
],
"resourceType": "Observation",
"specimen": {
"display": "Specimen XD#DDD-D00420",
"reference": "Specimen/xxxxwer-YwClO-82tNgDDI43tkGp2UsGcRs3"
},
"status": "final",
"subject": {
"display": "Doe, John",
"reference": "Patient/1234"
},
"valueQuantity": {
"comparator": "\u003c",
"unit": "mIU/mL",
"value": 3.1
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/fastenhealth/fasten-sources
go 1.18

require (
github.com/fastenhealth/gofhir-models v0.0.6
github.com/fastenhealth/gofhir-models v0.0.7
github.com/gabriel-vasile/mimetype v1.4.3
github.com/go-playground/validator/v10 v10.16.0
github.com/golang/mock v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fastenhealth/gofhir-models v0.0.6 h1:yJYYaV1eJtHiGEfA1rXLsyOm/9hIi6s2cGoZzGfW1tM=
github.com/fastenhealth/gofhir-models v0.0.6/go.mod h1:xB8ikGxu3bUq2b1JYV+CZpHqBaLXpOizFR0eFBCunis=
github.com/fastenhealth/gofhir-models v0.0.7 h1:t7Oyvc6eh3z9oaX5e5Krs7LiBT2n32z8yJrn5D0+cJg=
github.com/fastenhealth/gofhir-models v0.0.7/go.mod h1:xB8ikGxu3bUq2b1JYV+CZpHqBaLXpOizFR0eFBCunis=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
Expand Down

0 comments on commit e1baa08

Please sign in to comment.