Skip to content

Commit

Permalink
adding test for parsing converted CCDA document.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Jun 27, 2024
1 parent dabca50 commit ed6f3fd
Show file tree
Hide file tree
Showing 4 changed files with 3,823 additions and 1 deletion.
5 changes: 4 additions & 1 deletion clients/internal/manual/client_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
fhir430utils "github.com/fastenhealth/gofhir-models/fhir430/utils"
"github.com/samber/lo"
"io"
"log"
"os"
)

Expand All @@ -25,6 +26,7 @@ func extractPatientIdBundle(bundleFile *os.File) (string, pkg.FhirVersion, error

//fallback to 430 bundle
if err != nil || patientIds == nil || len(patientIds) == 0 {
log.Printf("failed to parse bundle or extract patientIds as 401, trying as 430: %v", err)
bundleType = pkg.FhirVersion430

patientIds, err = parse430Bundle(bundleFile)
Expand All @@ -49,6 +51,7 @@ func parse401Bundle(bundleFile *os.File) ([]string, error) {
patientIds := lo.FilterMap[fhir401.BundleEntry, string](bundle401Data.Entry, func(bundleEntry fhir401.BundleEntry, _ int) (string, bool) {
parsedResource, err := fhir401utils.MapToResource(bundleEntry.Resource, false)
if err != nil {
log.Printf("failed to parse resource: %v", err)
return "", false
}
typedResource := parsedResource.(models.ResourceInterface)
Expand All @@ -57,7 +60,7 @@ func parse401Bundle(bundleFile *os.File) ([]string, error) {
if resourceId == nil || len(*resourceId) == 0 {
return "", false
}
return *resourceId, resourceType == fhir430.ResourceTypePatient.String()
return *resourceId, resourceType == fhir401.ResourceTypePatient.String()
})

return patientIds, nil
Expand Down
24 changes: 24 additions & 0 deletions clients/internal/manual/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ func TestGetSourceClientManual_ExtractPatientId_Bundle(t *testing.T) {
require.Equal(t, "57959813-8cd2-4e3c-8970-e4364b74980a", resp)
}

func TestGetSourceClientManual_ExtractPatientId_CCDAToFHIRConvertedBundle(t *testing.T) {
t.Parallel()
//setup
testLogger := logrus.WithFields(logrus.Fields{
"type": "test",
})
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
fakeSourceCredential := mock_models.NewMockSourceCredential(mockCtrl)
fakeSourceCredential.EXPECT().GetPlatformType().AnyTimes().Return(pkg.PlatformTypeManual)
client, err := GetSourceClientManual(pkg.FastenLighthouseEnvSandbox, context.Background(), testLogger, fakeSourceCredential)

bundleFile, err := os.Open("testdata/fixtures/401-R4/bundle/ccda_to_fhir_converted_C-CDA_R2-1_CCD.xml.json")
require.NoError(t, err)

//test
resp, ver, err := client.ExtractPatientId(bundleFile)

//assert
require.NoError(t, err)
require.Equal(t, pkg.FhirVersion401, ver)
require.Equal(t, "12345", resp)
}

func TestGetSourceClientManual_ExtractPatientId_BundleIPS(t *testing.T) {
t.Parallel()
//setup
Expand Down
Loading

0 comments on commit ed6f3fd

Please sign in to comment.