use of org.hl7.fhir.r4.model.ServiceRequest in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7IdentifierFHIRConversionTest method serviceRequestIdentifierTest1.
@Test
void serviceRequestIdentifierTest1() {
// Test 1 removed: OMP_O09 messages do not create a service request
// Test 2:
// - Visit number with PID-18
// - filler and placer from OBR
String serviceRequest = "MSH|^~\\&|SendTest1|Sendfac1|Receiveapp1|Receivefac1|200603081747|security|PPR^PC1^PPR_PC1|1|P^I|2.6||||||ASCII||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|78654||||N\n" + "PRB|AD|200603150625|aortic stenosis|53692||2||200603150625\n" + // ORC.4 is not used as an identifier
"ORC||||PG1234567^MYPG||E|^Q6H^D10^^^R\n" + "OBR|1|CD150920001336^OE|CD150920001337^IE|||20150930000000|20150930164100|||||||||25055^MARCUSON^PATRICIA^L|||||||||F|||5755^DUNN^CHAD^B~25055^MARCUSON^PATRICIA^L|||WEAKNESS|DAS, SURJYA P||SHIELDS, SHARON A|||||||||";
ServiceRequest serviceReq = ResourceUtils.getServiceRequest(ftv, serviceRequest);
// Expect 3 identifiers
assertThat(serviceReq.hasIdentifier()).isTrue();
assertThat(serviceReq.getIdentifier()).hasSize(3);
List<Identifier> identifiers = serviceReq.getIdentifier();
// Match the three id's to position; we can't depend on an order.
int posVN = getIdentifierPositionByValue("78654", identifiers);
assertThat(posVN).isNotSameAs(-1);
int posFILLER = getIdentifierPositionByValue("CD150920001337", identifiers);
assertThat(posFILLER).isNotSameAs(-1);
int posPLACER = getIdentifierPositionByValue("CD150920001336", identifiers);
assertThat(posPLACER).isNotSameAs(-1);
// Identifier 1: visit number
Identifier identifier = serviceReq.getIdentifier().get(posVN);
String value = identifier.getValue();
String system = identifier.getSystem();
// PID.18
assertThat(value).isEqualTo("78654");
assertThat(system).isNull();
CodeableConcept type = identifier.getType();
DatatypeUtils.checkCommonCodeableConceptAssertions(type, "VN", "Visit number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// Identifier 2: filler
identifier = serviceReq.getIdentifier().get(posFILLER);
value = identifier.getValue();
system = identifier.getSystem();
// OBR.3.1
assertThat(value).isEqualTo("CD150920001337");
// OBR.3.2
assertThat(system).isEqualTo("urn:id:IE");
type = identifier.getType();
DatatypeUtils.checkCommonCodeableConceptAssertions(type, "FILL", "Filler Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// Identifier 3: placer
identifier = serviceReq.getIdentifier().get(posPLACER);
value = identifier.getValue();
system = identifier.getSystem();
// OBR.2.1
assertThat(value).isEqualTo("CD150920001336");
// OBR.2.2
assertThat(system).isEqualTo("urn:id:OE");
type = identifier.getType();
DatatypeUtils.checkCommonCodeableConceptAssertions(type, "PLAC", "Placer Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
}
use of org.hl7.fhir.r4.model.ServiceRequest in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7IdentifierFHIRConversionTest method serviceRequestIdentifierTest3.
// NOTE: ORU_RO1 records do not create the ServiceRequest directly. They create a DiagnosticReport and it creates the ServiceRequest.
// This test makes sure the specification for ORU_RO1.DiagnosticReport is specifying PID and PV1 correctly in AdditionalSegments.
@Test
void serviceRequestIdentifierTest3() {
// Test 1:
// - Visit number with PV1.19
// - filler and placer from OBR
String serviceRequest = "MSH|^~\\&|||||20180924152907|34001|ORU^R01^ORU_R01|213|T|2.6|||||||||||\n" + // PID.18 is ignored as visit number identifier because PV1.19 is present
"PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + // PV1.19 is used as the identifier visit number
"PV1|1|E|||||||||||||||||78654||||||||||||||||||||||||||\n" + // 2. ORC.3 empty so OBR.3 is used
"ORC|RE|||ML18267-C00001^Beaker||||||||||||||||||||||||||||||||||\n" + // 11. OBR.2 used for Placer
"OBR|1|CD150920001336^OE|CD150920001337^IE|83036E^HEMOGLOBIN A1C^PACSEAP^^^^^^HEMOGLOBIN A1C|||||||||||||||||||||||||||||||||||||||||||\n";
ServiceRequest serviceReq = ResourceUtils.getServiceRequest(ftv, serviceRequest);
// Expect 3 identifiers
assertThat(serviceReq.hasIdentifier()).isTrue();
assertThat(serviceReq.getIdentifier()).hasSize(3);
List<Identifier> identifiers = serviceReq.getIdentifier();
// Match the three id's to position; we can't depend on an order.
int posVN = getIdentifierPositionByValue("78654", identifiers);
assertThat(posVN).isNotSameAs(-1);
int posFILLER = getIdentifierPositionByValue("CD150920001337", identifiers);
assertThat(posFILLER).isNotSameAs(-1);
int posPLACER = getIdentifierPositionByValue("CD150920001336", identifiers);
assertThat(posPLACER).isNotSameAs(-1);
// Identifier 1: visit number should be set by PV1.19
Identifier identifier = serviceReq.getIdentifier().get(posVN);
String value = identifier.getValue();
String system = identifier.getSystem();
// PV1.19
assertThat(value).isEqualTo("78654");
assertThat(system).isNull();
CodeableConcept type = identifier.getType();
DatatypeUtils.checkCommonCodeableConceptAssertions(type, "VN", "Visit number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// Identifier 2: filler
identifier = serviceReq.getIdentifier().get(posFILLER);
value = identifier.getValue();
system = identifier.getSystem();
// OBR.3.1
assertThat(value).isEqualTo("CD150920001337");
// OBR.3.2
assertThat(system).isEqualTo("urn:id:IE");
type = identifier.getType();
DatatypeUtils.checkCommonCodeableConceptAssertions(type, "FILL", "Filler Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// Identifier 3: placer
identifier = serviceReq.getIdentifier().get(posPLACER);
value = identifier.getValue();
system = identifier.getSystem();
// OBR.2.1
assertThat(value).isEqualTo("CD150920001336");
// OBR.2.2
assertThat(system).isEqualTo("urn:id:OE");
type = identifier.getType();
DatatypeUtils.checkCommonCodeableConceptAssertions(type, "PLAC", "Placer Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
}
use of org.hl7.fhir.r4.model.ServiceRequest in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7ImmunizationFHIRConversionTest method testImmunizationRXA20Priority.
// Suppress warnings about too many assertions in a test. Justification: creating a FHIR message is very costly; we need to check many asserts per creation for efficiency.
@java.lang.SuppressWarnings("squid:S5961")
@Test
void testImmunizationRXA20Priority() throws IOException {
// RXA.20 is "completed" this takes precedence over rxa.18 having a value and orc.5
// ORC.5 is here to prove RXA.20 is taking precedence
// ORC.9 is here to prove RXA.22 is taking precedence
String hl7VUXmessageRep = "MSH|^~\\&|EHR|12345^SiteName|MIIS|99990|20140701041038||VXU^V04^VXU_V04|MSG.Valid_01|P|2.6|||\n" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\r" + "ORC|RE||197027||ER||||20130905041038|||MD67895^Pediatric^MARY^^^^MD^^RIA|||||\r" + // RXA.11 to Performer Organization
"RXA|||20130531||48^HIB PRP-T^CVX|0.5|ML^^ISO+||00^new immunization record^NIP001|^Sticker^Nurse|^^^RI2050||||33k2a|20131210|PMC^sanofi^MVX|00^Patient refusal^NIP002||PA|A|20120901041038\r" + "OBX|1|CWE|31044-1^Reaction^LN|1|VXC9^Persistent, inconsolable crying lasting > 3 hours within 48 hours of dose^CDCPHINVS||||||F|||20130531|||VXC40^per imm^CDCPHINVS\r";
List<Bundle.BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7VUXmessageRep);
List<Resource> immu = ResourceUtils.getResourceList(e, ResourceType.Immunization);
assertThat(immu).hasSize(1);
Immunization resource = ResourceUtils.getResourceImmunization(immu.get(0), ResourceUtils.context);
assertThat(resource).isNotNull();
// RXA.20 is "completed" this takes precedence over rxa.18 having a value and orc.5
assertThat(resource.getStatus().getDisplay()).isEqualTo("completed");
assertThat(resource.hasStatusReason()).isTrue();
// RXA.18
assertThat(resource.getStatusReason().getCodingFirstRep().getCode()).isEqualTo("00");
// RXA.18
assertThat(resource.getStatusReason().getCodingFirstRep().getSystem()).isEqualTo("urn:id:NIP002");
// RXA.18
assertThat(resource.getStatusReason().getCodingFirstRep().getDisplay()).isEqualTo("Patient refusal");
assertThat(resource.getStatusReason().getText()).isEqualTo("Patient refusal");
assertThat(resource.getIsSubpotent()).isTrue();
// RXA.5.1 + 5.3
assertThat(resource.getIdentifier().get(0).getValue()).isEqualTo("48-CVX");
assertThat(resource.getIdentifier().get(0).getSystem()).isEqualTo("urn:id:extID");
assertThat(resource.getVaccineCode().getCoding().get(0).getSystem()).isEqualTo(// RXA.5.3
"http://hl7.org/fhir/sid/cvx");
// RXA.5.1
assertThat(resource.getVaccineCode().getCoding().get(0).getCode()).isEqualTo("48");
// RXA.5.2
assertThat(resource.getVaccineCode().getText()).isEqualTo("HIB PRP-T");
// RXA.3
assertThat(resource.getOccurrence()).hasToString("DateTimeType[2013-05-31]");
// RXA.9.3
assertThat(resource.getReportOrigin().getCoding().get(0).getSystem()).isEqualTo("urn:id:NIP001");
// RXA.9.
assertThat(resource.getReportOrigin().getCoding().get(0).getCode()).isEqualTo("00");
// RXA.9.2
assertThat(resource.getReportOrigin().getCoding().get(0).getDisplay()).isEqualTo("new immunization record");
// RXA.9.2
assertThat(resource.getReportOrigin().getText()).isEqualTo("new immunization record");
// RXA.17
assertThat(resource.getManufacturer().isEmpty()).isFalse();
// RXA.22
assertThat(resource.hasRecorded()).isTrue();
// RXA.22
assertThat(resource.getRecordedElement().toString()).contains("2012-09-01");
String manufacturerRef = resource.getManufacturer().getReference();
// RXA.15
assertThat(resource.getLotNumber()).isEqualTo("33k2a");
// RXA.16
assertThat(resource.getExpirationDate()).isEqualTo("2013-12-10");
// dose Quantity with an unknown system
assertThat(resource.hasDoseQuantity()).isTrue();
assertThat(resource.getDoseQuantity().getValue()).hasToString("0.5");
assertThat(resource.getDoseQuantity().getUnit()).isEqualTo("ML");
assertThat(resource.getDoseQuantity().getCode()).isEqualTo("ML");
assertThat(resource.getDoseQuantity().getSystem()).isEqualTo("urn:id:ISO+");
String requesterRef1 = resource.getPerformer().get(0).getActor().getReference();
Practitioner practBundle1 = ResourceUtils.getSpecificPractitionerFromBundleEntriesList(e, requesterRef1);
assertThat(resource.getPerformer()).hasSize(3);
DatatypeUtils.checkCommonCodingAssertions(resource.getPerformer().get(0).getFunction().getCoding().get(0), "OP", "Ordering Provider", "http://terminology.hl7.org/CodeSystem/v2-0443", // ORC.12
null);
assertThat(resource.getPerformer().get(0).getFunction().hasText()).isFalse();
// ORC.12
assertThat(resource.getPerformer().get(0).getActor().getReference()).isNotEmpty();
assertThat(practBundle1.getNameFirstRep().getText()).isEqualTo("MARY Pediatric");
assertThat(practBundle1.getNameFirstRep().getFamily()).isEqualTo("Pediatric");
assertThat(practBundle1.getNameFirstRep().getGiven().get(0)).hasToString("MARY");
assertThat(practBundle1.getIdentifierFirstRep().getValue()).isEqualTo("MD67895");
String requesterRef2 = resource.getPerformer().get(1).getActor().getReference();
Practitioner practBundle2 = ResourceUtils.getSpecificPractitionerFromBundleEntriesList(e, requesterRef2);
DatatypeUtils.checkCommonCodingAssertions(resource.getPerformer().get(1).getFunction().getCoding().get(0), "AP", "Administering Provider", "http://terminology.hl7.org/CodeSystem/v2-0443", // RXA.10
null);
assertThat(resource.getPerformer().get(1).getFunction().hasText()).isFalse();
// RXA.10
assertThat(resource.getPerformer().get(1).getActor().isEmpty()).isFalse();
assertThat(practBundle2.getNameFirstRep().getText()).isEqualTo("Nurse Sticker");
assertThat(practBundle2.getNameFirstRep().getFamily()).isEqualTo("Sticker");
assertThat(practBundle2.getNameFirstRep().getGiven().get(0)).hasToString("Nurse");
String requesterRef3 = resource.getPerformer().get(2).getActor().getReference();
DatatypeUtils.checkCommonCodingAssertions(resource.getPerformer().get(2).getFunction().getCoding().get(0), "AP", "Administering Provider", "http://terminology.hl7.org/CodeSystem/v2-0443", // RXA.11
null);
assertThat(resource.getPerformer().get(1).getFunction().hasText()).isFalse();
// Immunization.Reaction Date (OBX.14) and Detail (OBX.5 if OBX 3 is 31044-1)
// OBX.14
assertThat(resource.getReactionFirstRep().getDateElement().toString()).contains("2013-05-31");
// OBX.5
assertThat(resource.getReactionFirstRep().getDetail().hasReference()).isTrue();
// Looking for one Observation that matches the Reaction.Detail reference
String reactionDetail = resource.getReactionFirstRep().getDetail().getReference();
List<Resource> observations = ResourceUtils.getResourceList(e, ResourceType.Observation);
assertThat(observations).hasSize(1);
Observation obs = ResourceUtils.getResourceObservation(observations.get(0), ResourceUtils.context);
assertThat(obs.getId()).isEqualTo(reactionDetail);
assertThat(obs.getCode().getCodingFirstRep().getDisplay()).isEqualTo("Persistent, inconsolable crying lasting > 3 hours within 48 hours of dose");
assertThat(obs.getCode().getCodingFirstRep().getCode()).isEqualTo("VXC9");
assertThat(obs.getCode().getCodingFirstRep().getSystem()).isEqualTo("urn:id:CDCPHINVS");
assertThat(obs.getCode().getText()).isEqualTo("Persistent, inconsolable crying lasting > 3 hours within 48 hours of dose");
assertThat(obs.getIdentifierFirstRep().getValue()).isEqualTo("197027-VXC9-CDCPHINVS");
assertThat(obs.getIdentifierFirstRep().getSystem()).isEqualTo("urn:id:extID");
// Looking for two Organizations: one for the manufacturer reference and one for the Immunization.performer
List<Resource> organizations = ResourceUtils.getResourceList(e, ResourceType.Organization);
assertThat(organizations).hasSize(2);
Organization org = ResourceUtils.getResourceOrganization(organizations.get(0), ResourceUtils.context);
assertThat(org.getName()).isEqualTo("RI2050");
assertThat(org.getId()).isEqualTo(requesterRef3);
assertThat(org.hasContact()).isFalse();
org = ResourceUtils.getResourceOrganization(organizations.get(1), ResourceUtils.context);
assertThat(org.getName()).isEqualTo("sanofi");
assertThat(org.getId()).isEqualTo(manufacturerRef);
assertThat(org.hasContact()).isFalse();
// Test that a ServiceRequest is not created for VXU_V04
List<Resource> serviceRequestList = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
// Confirm that a serviceRequest was not created.
assertThat(serviceRequestList).isEmpty();
// Check for expected resources: Organizations (2), Immunization, Patient, Observation, Practitioner (2)
assertThat(e).hasSize(7);
}
use of org.hl7.fhir.r4.model.ServiceRequest in project hl7v2-fhir-converter by LinuxForHealth.
the class CodeableConceptTest method testMultipleCWEsWIthSecondaryCodes.
@Test
void testMultipleCWEsWIthSecondaryCodes() {
// This test documents behaviors of how multiple CWEs with primary and secondary codings are GROUPED
// in the resulting CodeableConcept.
// The question is, when there is more than one CodeableConcept in the FHIR resources, should it
// be one codeable concept with an array of two code/systems and one text, like this:
// "sampleCodeableConcept": [ {
// "coding": [ {
// "system": "http://system.org/AAAA-system",
// "code": "AAAA",
// "display": "Apples Add Additional Age"
// }, {
// "system": "http://system.org/BBBB-system",
// "code": "BBBB",
// "display": "Berries Become Beneficial"
// } ],
// "text": "Eat Fruits for Health"
// } ]
// OR should it be an array two codings each with one code/system and a text, like this:
// "sampleCodeableConcept": [ {
// "coding": [ {
// "system": "http://system.org/AAAA-system",
// "code": "AAAA",
// "display": "Apples Add Additional Age"
// } ],
// "text": "Apples are Healthy"
// }, {
// "coding": [ {
// "system": "http://system.org/BBBB-system",
// "code": "BBBB",
// "display": "Berries Become Beneficial"
// } ],
// "text": "Berries are Healthy"
// } ]
// Both of these are valid in FHIR.
//
// ANSWER: it currently depends on whether the multiple codings come in the HL7 in
// a repeating field, or in the secondary information of a CWE
//
// Detailed discussion in https://github.com/LinuxForHealth/hl7v2-fhir-converter/issues/363
//
// This test uses a repeating field with two CWE's each with secondary sub-fields
// to illustrate the way things currently work.
String hl7message = "MSH|^~\\&|||||20180924152907|34001|ORU^R01^ORU_R01|213|T|2.6|||||||||||\n" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + // ORC.16 key for this test. It sets a reason code: two codes with two codings each. See other comments.
"ORC|RE|248648498^|248648498^|ML18267-C00001^Beaker|SC||||||||||20170917151717|042^Human immunodeficiency virus [HIV] disease [42]^I9CDX^HIV^HIV/Aids^L~012^Other respiratory tuberculosis^I9CDX^017^Tuberculosis of other organs^I9CDX|||||||||||||||\n" + // NOTE: OBR record required so a ServiceRequest is created
"OBR|1|248648498^|248648498^|83036E^HEMOGLOBIN A1C^PACSEAP^^^^^^HEMOGLOBIN A1C|||||||L|||||||||||||||||||||||||||||||||||||||\n";
;
// Expected output for reasonCode:
// "reasonCode": [ {
// "coding": [ {
// "system": "http://terminology.hl7.org/CodeSystem/ICD-9CM-diagnosiscodes", << FROM FIRST CWE, PRIMARY CODE
// "code": "042",
// "display": "Human immunodeficiency virus [HIV] disease [42]"
// }, {
// "system": "urn:id:L", << FROM FIRST CWE, SECONDARY CODE
// "code": "HIV",
// "display": "HIV/Aids"
// } ],
// "text": "Human immunodeficiency virus [HIV] disease [42]"
// }, {
// "coding": [ {
// "system": "http://terminology.hl7.org/CodeSystem/ICD-9CM-diagnosiscodes", << FROM SECOND CWE, PRIMARY CODE
// "code": "012",
// "display": "Other respiratory tuberculosis"
// }, {
// "system": "http://terminology.hl7.org/CodeSystem/ICD-9CM-diagnosiscodes", << FROM SECOND CWE, SECONDARY CODE
// "code": "017",
// "display": "Tuberculosis of other organs"
// } ],
// "text": "Other respiratory tuberculosis"
// } ]
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
List<Resource> serviceRequestList = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
// Important that we have exactly one service request (no duplication). OBR creates it as a reference.
assertThat(serviceRequestList).hasSize(1);
ServiceRequest serviceRequest = ResourceUtils.getResourceServiceRequest(serviceRequestList.get(0), ResourceUtils.context);
// ORC.16 should create a ServiceRequest.reasonCode CWE
assertThat(serviceRequest.hasReasonCode()).isTrue();
// There are two reason codes (an array of 2)
assertThat(serviceRequest.getReasonCode()).hasSize(2);
// The first reason code has an array of 2 codings
assertThat(serviceRequest.getReasonCode().get(0).getCoding()).hasSize(2);
// The second reason code has an array of 2 codings
assertThat(serviceRequest.getReasonCode().get(1).getCoding()).hasSize(2);
assertThat(serviceRequest.getReasonCode().get(0).getText()).isEqualTo("Human immunodeficiency virus [HIV] disease [42]");
assertThat(serviceRequest.getReasonCode().get(1).getText()).isEqualTo("Other respiratory tuberculosis");
// Check the content of the coding sets to see they are as expected
DatatypeUtils.checkCommonCodingAssertions(serviceRequest.getReasonCode().get(0).getCoding().get(0), "042", "Human immunodeficiency virus [HIV] disease [42]", "http://terminology.hl7.org/CodeSystem/ICD-9CM-diagnosiscodes", null);
DatatypeUtils.checkCommonCodingAssertions(serviceRequest.getReasonCode().get(0).getCoding().get(1), "HIV", "HIV/Aids", "urn:id:L", null);
DatatypeUtils.checkCommonCodingAssertions(serviceRequest.getReasonCode().get(1).getCoding().get(0), "012", "Other respiratory tuberculosis", "http://terminology.hl7.org/CodeSystem/ICD-9CM-diagnosiscodes", null);
DatatypeUtils.checkCommonCodingAssertions(serviceRequest.getReasonCode().get(1).getCoding().get(1), "017", "Tuberculosis of other organs", "http://terminology.hl7.org/CodeSystem/ICD-9CM-diagnosiscodes", null);
// There should be one DiagnosticReport
List<Resource> diagnosticReportList = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
assertThat(diagnosticReportList).hasSize(1);
// There should be one Patient
List<Resource> patients = ResourceUtils.getResourceList(e, ResourceType.Patient);
assertThat(patients).hasSize(1);
// Ensure there are no extra resources created
assertThat(e).hasSize(3);
}
use of org.hl7.fhir.r4.model.ServiceRequest in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7ORUMessageTest method test_oru_multipleOBXofDifferentTypes.
/**
* ORU messages with an OBR and multiple OBX segments create records only for non TX type OBX
* The OBX type TX are added to the presentedForm as an attachment for the diagnostic
* @throws IOException
*/
// Suppress warnings about too many assertions in a test. Justification: creating a FHIR message is very costly; we need to check many asserts per creation for efficiency.
@java.lang.SuppressWarnings("squid:S5961")
@Test
void test_oru_multipleOBXofDifferentTypes() throws IOException {
String json = ftv.convert(new File("src/test/resources/ORU-multiline-short.hl7"), OPTIONS_PRETTYPRINT);
assertThat(json).isNotBlank();
LOGGER.debug("FHIR json result:\n" + json);
// Verify conversion
FHIRContext context = new FHIRContext();
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
Assertions.assertSame(BundleType.COLLECTION, b.getType(), "Bundle type not expected");
List<BundleEntryComponent> e = b.getEntry();
// Verify that the right resources have been created
List<Resource> patientResource = ResourceUtils.getResourceList(e, ResourceType.Patient);
assertThat(patientResource).hasSize(1);
List<Resource> encounterResource = ResourceUtils.getResourceList(e, ResourceType.Encounter);
assertThat(encounterResource).hasSize(1);
List<Resource> organizationResource = ResourceUtils.getResourceList(e, ResourceType.Organization);
// We expect an organization created from an Encounter.serviceProvider reference
assertThat(organizationResource).hasSize(1);
List<Resource> practitionerResource = ResourceUtils.getResourceList(e, ResourceType.Practitioner);
assertThat(practitionerResource).hasSize(4);
List<Resource> messageHeader = ResourceUtils.getResourceList(e, ResourceType.MessageHeader);
assertThat(messageHeader).hasSize(1);
// Verify Diagnostic Report is created as expected
List<Resource> reportResource = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
assertThat(reportResource).hasSize(1);
List<Resource> servReqResource = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
assertThat(servReqResource).hasSize(1);
// Verify there are no extra resources created
assertThat(e).hasSize(10);
// Verify no observations are created
List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
// TODO: When NTE is implemented, then update this to one.
assertThat(obsResource).isEmpty();
// /////////////////////////////////////////
// Now confirm content of the diagnosticReport because we don't have separate tests for DiagnosticReport
// /////////////////////////////////////////
DiagnosticReport diag = ResourceUtils.getResourceDiagnosticReport(reportResource.get(0), context);
// Verify status from OBR.25
assertThat(diag.getStatus().toCode()).isEqualTo("final");
// Verify category from OBR.24
assertThat(diag.getCategory()).hasSize(1);
DatatypeUtils.checkCommonCodeableConceptAssertions(diag.getCategoryFirstRep(), "CT", "CAT Scan", "http://terminology.hl7.org/CodeSystem/v2-0074", "CT");
// Verify code from OBR.4; This tests scenario of the code not being in the default loinc system.
assertThat(diag.hasCode()).isTrue();
List<Coding> codings = diag.getCode().getCoding();
assertThat(codings).hasSize(1);
Coding coding = codings.get(0);
assertThat(coding.hasDisplay()).isTrue();
assertThat(coding.getDisplay()).hasToString("ECHO CARDIOGRAM COMPLETE");
assertThat(coding.hasCode()).isTrue();
assertThat(coding.getCode()).hasToString("1487");
assertThat(coding.hasSystem()).isFalse();
// Verify encounter reference
assertThat(diag.getEncounter().isEmpty()).isFalse();
// Verify subject reference
assertThat(diag.getSubject().isEmpty()).isFalse();
// Verify effectiveDateTime from OBR.7 and OBR.8
// This also verifies the type, confirming effectiveDateTime was set rather than effectivePeriod
assertThat(diag.getEffectiveDateTimeType().asStringValue()).isEqualTo("2020-08-02T12:44:55+08:00");
// Verify issued from OBR.22
assertThat(diag.getIssued()).isNull();
// Verify resultsInterpreter from OBR.32
assertThat(diag.getResultsInterpreter()).isEmpty();
// Verify basedOn is ref to the ServiceRequest created for ORC or OBR
assertThat(diag.getBasedOn()).hasSize(1);
assertThat(diag.getBasedOn().get(0).getReference().substring(0, 15)).isEqualTo("ServiceRequest/");
// Verify specimen reference
List<Reference> spmRef = diag.getSpecimen();
assertThat(spmRef).isEmpty();
// Verify result reference
List<Reference> obsRef = diag.getResult();
assertThat(obsRef).isEmpty();
// Verify attachment to diagnostic report
List<Attachment> attachments = diag.getPresentedForm();
Assertions.assertEquals(1, attachments.size(), "Unexpected number of attachments");
Attachment a = attachments.get(0);
Assertions.assertTrue(a.getContentType().equalsIgnoreCase("text/plain"), "Incorrect content type");
Assertions.assertTrue(a.getLanguage().equalsIgnoreCase("en"), "Incorrect language");
// Verify data attachment after decoding
String decoded = new String(Base64.getDecoder().decode(a.getDataElement().getValueAsString()));
System.out.println("Decoded: '" + decoded + "'");
Assertions.assertEquals("\n[PII] Emergency Department\nED Encounter Arrival Date: [ADDRESS] [PERSONALNAME]:", decoded, "Incorrect data");
Assertions.assertTrue(a.getTitle().equalsIgnoreCase("ECHO CARDIOGRAM COMPLETE"), "Incorrect title");
// Verify creation data is persisted correctly - 2020-08-02T12:44:55+08:00
Calendar c = Calendar.getInstance();
// needed to completely clear out calendar object
c.clear();
c.set(2020, 7, 2, 12, 44, 55);
c.setTimeZone(TimeZone.getTimeZone(ZoneId.of("+08:00")));
Date d = c.getTime();
Assertions.assertEquals(d, a.getCreation(), "Incorrect creation date");
// //////////////////////////////////
for (Resource res : obsResource) {
// Verify encounter reference exists
Observation obs = (Observation) res;
assertThat(obs.getEncounter().isEmpty()).isFalse();
assertThat(obs.getEncounter().getReference().substring(0, 10)).isEqualTo("Encounter/");
// Verify subject reference to Patient exists
assertThat(obs.getSubject().isEmpty()).isFalse();
assertThat(obs.getSubject().getReference().substring(0, 8)).isEqualTo("Patient/");
}
}
Aggregations