Skip to content

Commit

Permalink
✅ test: Add a test for JSON Patch mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukan10 committed Oct 9, 2024
1 parent eeb15b5 commit 7ea7cf3
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,19 @@ object MappingTaskExecutor {
))
} else {
mappedResources.flatMap {
//If this is a JSON Patch, the resources are patches so return it as single result
// JSON Patch is a document that represents a series of operations to be applied to a target resource,
// formatted as an array of objects. Each object describes a single operation, such as testing, adding,
// removing, or replacing values at specific paths in the resource. Example format:
//
// [
// { "op": "test", "path": "/component/0/code/coding/0/code", "value": "80-6" },
// { "op": "remove", "path": "/component/0/code/coding/2" },
// { "op": "add", "path": "/component/0/code/coding/1", "value": { "system": "test", "code": "test" } },
// { "op": "replace", "path": "/component/0/code/coding/2/code", "value": "test3" }
// ]
//
// If the input is recognized as a JSON Patch, return the patch document as a single result so it can be
// passed directly to the body of a FHIR Patch interaction request.
case (mappingExpr, resources, fhirInteraction) if fhirInteraction.exists(_.`type` == "patch") && resources.length > 1 =>
Seq(FhirMappingResult(
jobId = fhirMappingService.jobId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"id": "patient-mapping-with-json-patch",
"url": "https://aiccelerate.eu/fhir/mappings/patient-mapping-with-json-patch",
"name": "patient-mapping-with-json-patch",
"title": "Mapping of some patient data to a JSON patch for FHIR Patient resource",
"source": [
{
"alias": "source",
"url": "https://aiccelerate.eu/fhir/StructureDefinition/Ext-patient-extra"
}
],
"mapping": [
{
"expression": {
"name": "result",
"language": "application/fhir-template+json",
"value": [
{
"op": "replace",
"path": "gender",
"value": "female"
},
{
"op": "replace",
"path": "birthDate",
"value": "2021-03-05"
}
]
},
"fhirInteraction": {
"type": "patch",
"rid": "Patient/{{mpp:getHashedId('Patient',pid)}}"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,25 @@ class FhirMappingJobManagerTest extends AsyncFlatSpec with BeforeAndAfterAll wit
)
}

it should "execute the mapping with JSON patch" in {
val jsonPatchMapping: FhirMappingTask = FhirMappingTask(
name = "patient-mapping-with-json-patch",
mappingRef = "https://aiccelerate.eu/fhir/mappings/patient-mapping-with-json-patch",
sourceBinding = Map("source" -> FileSystemSource(path = "patients-extra.csv", contentType = SourceContentTypes.CSV))
)
val fhirMappingJobManager = new FhirMappingJobManager(mappingRepository, contextLoader, schemaRepository, Map.empty, sparkSession)

fhirMappingJobManager.executeMappingJob(mappingJobExecution = FhirMappingJobExecution(mappingTasks = Seq(patientMappingTask), job = fhirMappingJob), sourceSettings = fhirMappingJob.sourceSettings, sinkSettings = fhirMappingJob.sinkSettings).flatMap(_ =>
fhirMappingJobManager.executeMappingJob(mappingJobExecution = FhirMappingJobExecution(mappingTasks = Seq(jsonPatchMapping), job = fhirMappingJob), sourceSettings = fhirMappingJob.sourceSettings, sinkSettings = fhirMappingJob.sinkSettings) flatMap { response =>
response shouldBe()
onFhirClient.read("Patient", FhirMappingUtility.getHashedId("Patient", "p1")).executeAndReturnResource() flatMap { p1Resource =>
(p1Resource \ "gender").extract[String] shouldBe "female"
(p1Resource \ "birthDate").extract[String] shouldBe "2021-03-05"
}
}
)
}

it should "execute the patient mapping task with given tsv file and return the results" in {
val patientTsvFileMappingTask: FhirMappingTask = FhirMappingTask(
name = "patient-mapping",
Expand Down

0 comments on commit 7ea7cf3

Please sign in to comment.