Skip to content

Commit 510a977

Browse files
committed
Added more test scenarios
1 parent 6a552ce commit 510a977

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed

service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/DiagnosticReportMapperTest.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,65 @@ void When_DiagnosticReport_Has_MultipleSpecimensAndOneObservation_Expect_ADummyO
339339

340340
}
341341

342+
/**
343+
* A Diagnostic Report may have an Observation (Test Result) and Specimen. If the observation and specimen are not
344+
* linked then we need to create a dummy observation linked to the specimen.
345+
*/
346+
@Test
347+
void When_DiagnosticReport_Has_ThreeSpecimensAndOneObservation_Expect_DummyObservationsLinkedToSpecimen() {
348+
final String diagnosticReportFileName = "diagnostic-report-with-three-specimens-and-one-observation.json";
349+
final DiagnosticReport diagnosticReport = getDiagnosticReportResourceFromJson(diagnosticReportFileName);
350+
final Bundle bundle = getBundleResourceFromJson(INPUT_JSON_BUNDLE);
351+
final InputBundle inputBundle = new InputBundle(bundle);
352+
353+
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
354+
355+
final String actualXml = mapper.mapDiagnosticReportToCompoundStatement(diagnosticReport);
356+
357+
// This checks that the unlinked test result is given a dummy specimen.
358+
assertThat(actualXml).containsIgnoringWhitespaces(
359+
"<!-- Mapped Specimen with id: Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-0 "
360+
+ "with linked Observations: Observation/B7F05EA7-A1A4-48C0-9C4C-CDB5768796B2-->");
361+
362+
assertThat(actualXml).containsIgnoringWhitespaces(
363+
"<!-- Mapped Specimen with id: Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-1 "
364+
+ "with linked Observations: DUMMY-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->");
365+
366+
assertThat(actualXml).containsIgnoringWhitespaces(
367+
"<!-- Mapped Specimen with id: Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-2 "
368+
+ "with linked Observations: DUMMY-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->");
369+
}
370+
371+
/**
372+
* A Diagnostic Report may have an Observation (Test Result) and Specimen. If the observation and specimen are not
373+
* linked then we need to create a dummy observation linked to the specimen.
374+
*/
375+
@Test
376+
void When_DiagnosticReport_Has_TwoLinkedSpecimensOneUnlinkedSpecimenAndOneObservation_Expect_DummyObservationsLinkedToSpecimen() {
377+
final String diagnosticReportFileName =
378+
"diagnostic-report-with-three-specimens-one-unlinked-specimen-and-one-observation.json";
379+
final DiagnosticReport diagnosticReport = getDiagnosticReportResourceFromJson(diagnosticReportFileName);
380+
final Bundle bundle = getBundleResourceFromJson(INPUT_JSON_BUNDLE);
381+
final InputBundle inputBundle = new InputBundle(bundle);
382+
383+
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
384+
385+
final String actualXml = mapper.mapDiagnosticReportToCompoundStatement(diagnosticReport);
386+
387+
// This checks that the unlinked test result is given a dummy specimen.
388+
assertThat(actualXml).containsIgnoringWhitespaces(
389+
"<!-- Mapped Specimen with id: Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-0 "
390+
+ "with linked Observations: Observation/B7F05EA7-A1A4-48C0-9C4C-CDB5768796B2-->");
391+
392+
assertThat(actualXml).containsIgnoringWhitespaces(
393+
"<!-- Mapped Specimen with id: Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-1 "
394+
+ "with linked Observations: Observation/6E30A9E3-FF9A-4868-8FCD-7DAC26A16E78-->");
395+
396+
assertThat(actualXml).containsIgnoringWhitespaces(
397+
"<!-- Mapped Specimen with id: Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-2 "
398+
+ "with linked Observations: DUMMY-OBSERVATION-5E496953-065B-41F2-9577-BE8F2FBD0757-->");
399+
}
400+
342401
@Test
343402
void When_DiagnosticReport_Has_SpecimenALinkedTestResultAndAnUnlinkedTestResult_Expect_ASpecimenOnAllTestResults() {
344403
final String diagnosticReportFileName =
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"resourceType": "DiagnosticReport",
3+
"id": "96B93E28-293D-46E7-B4C2-D477EEBF7098",
4+
"meta": {
5+
"profile": [
6+
"https://fhir.nhs.uk/STU3/StructureDefinition/CareConnect-GPC-DiagnosticReport-1"
7+
]
8+
},
9+
"identifier": [
10+
{
11+
"system": "https://EMISWeb/A82038",
12+
"value": "96B93E28-293D-46E7-B4C2-D477EEBF7098"
13+
}
14+
],
15+
"status": "unknown",
16+
"category": {
17+
"coding": [
18+
{
19+
"system": "http://hl7.org/fhir/v2/0074",
20+
"code": "PAT",
21+
"display": "Pathology (gross & histopath, not surgical)"
22+
}
23+
]
24+
},
25+
"code": {
26+
"coding": [
27+
{
28+
"system": "http://snomed.info/sct",
29+
"code": "721981007",
30+
"display": "Diagnostic studies report"
31+
}
32+
]
33+
},
34+
"subject": {
35+
"reference": "Patient/DAED5527-1985-45D9-993E-C5FF51F36828"
36+
},
37+
"issued": "2010-02-25T15:41:00+00:00",
38+
"specimen": [
39+
{"reference": "Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-0"},
40+
{"reference": "Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-1"},
41+
{"reference": "Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-2"}
42+
],
43+
"result": [
44+
{ "reference": "Observation/B7F05EA7-A1A4-48C0-9C4C-CDB5768796B2" }
45+
]
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"resourceType": "DiagnosticReport",
3+
"id": "96B93E28-293D-46E7-B4C2-D477EEBF7098",
4+
"meta": {
5+
"profile": [
6+
"https://fhir.nhs.uk/STU3/StructureDefinition/CareConnect-GPC-DiagnosticReport-1"
7+
]
8+
},
9+
"identifier": [
10+
{
11+
"system": "https://EMISWeb/A82038",
12+
"value": "96B93E28-293D-46E7-B4C2-D477EEBF7098"
13+
}
14+
],
15+
"status": "unknown",
16+
"category": {
17+
"coding": [
18+
{
19+
"system": "http://hl7.org/fhir/v2/0074",
20+
"code": "PAT",
21+
"display": "Pathology (gross & histopath, not surgical)"
22+
}
23+
]
24+
},
25+
"code": {
26+
"coding": [
27+
{
28+
"system": "http://snomed.info/sct",
29+
"code": "721981007",
30+
"display": "Diagnostic studies report"
31+
}
32+
]
33+
},
34+
"subject": {
35+
"reference": "Patient/DAED5527-1985-45D9-993E-C5FF51F36828"
36+
},
37+
"issued": "2010-02-25T15:41:00+00:00",
38+
"specimen": [
39+
{"reference": "Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-0"},
40+
{"reference": "Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-1"},
41+
{"reference": "Specimen/96B93E28-293D-46E7-B4C2-D477EEBF7098-SPEC-2"}
42+
],
43+
"result": [
44+
{ "reference": "Observation/B7F05EA7-A1A4-48C0-9C4C-CDB5768796B2" },
45+
{ "reference": "Observation/6E30A9E3-FF9A-4868-8FCD-7DAC26A16E78" }
46+
]
47+
}

0 commit comments

Comments
 (0)