@@ -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 =
0 commit comments