use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.DIAGNOSTICREPORT in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7IdentifierFHIRConversionTest method diagnosticReportIdentifierTestFillerPlacerFromOBR.
@Test
void diagnosticReportIdentifierTestFillerPlacerFromOBR() {
// Filler and placer from OBR
String diagnosticReport = "MSH|^~\\&|PROSLOV|MYHOSPITAL|WHIA|IBM|20170825010500||ORU^R01|MSGID22102712|T|2.6\n" + "PID|||1234||DOE^JANE^|||F||||||||||||||||||||||\n" + "ORC|NW|||PGN001|SC|D|1||20170825010500|MS|MS||||20170825010500|\n" + "OBR|1|CC_000000^OE PHIMS Stage|CD_000000|2244^General Order|||20170825010500||||||Relevant Clinical Information|||||||002|||||F\n" + "OBX|1|TX|||Impression: 1. Markedly intense metabolic activity corresponding with the area of nodular enhancement in the left oral cavity.||||||F|||20170825010500\n";
DiagnosticReport report = ResourceUtils.getDiagnosticReport(ftv, diagnosticReport);
// Expect 3 identifiers
assertThat(report.hasIdentifier()).isTrue();
assertThat(report.getIdentifier()).hasSize(3);
List<Identifier> identifiers = report.getIdentifier();
// Match the three id's to position; we can't depend on an order.
int posExtId = getIdentifierPositionByValue("20170825010500", identifiers);
assertThat(posExtId).isNotSameAs(-1);
int posFILLER = getIdentifierPositionByValue("CD_000000", identifiers);
assertThat(posFILLER).isNotSameAs(-1);
int posPLACER = getIdentifierPositionByValue("CC_000000", identifiers);
assertThat(posPLACER).isNotSameAs(-1);
// Identifier 1: extID with MSH-7
Identifier identifier = report.getIdentifier().get(posExtId);
String value = identifier.getValue();
String system = identifier.getSystem();
// MSH-7
assertThat(value).isEqualTo("20170825010500");
assertThat(system).isEqualTo("urn:id:extID");
// Identifier 2: Filler
identifier = report.getIdentifier().get(posFILLER);
value = identifier.getValue();
system = identifier.getSystem();
// OBR-3.1
assertThat(value).isEqualTo("CD_000000");
// OBR-3.2 is empty
assertThat(system).isNull();
CodeableConcept type = identifier.getType();
DatatypeUtils.checkCommonCodeableConceptAssertions(type, "FILL", "Filler Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// Identifier 3: Placer
identifier = report.getIdentifier().get(posPLACER);
value = identifier.getValue();
system = identifier.getSystem();
// OBR-2
assertThat(value).isEqualTo("CC_000000");
// OBR-2.2
assertThat(system).isEqualTo("urn:id:OE_PHIMS_Stage");
type = identifier.getType();
DatatypeUtils.checkCommonCodeableConceptAssertions(type, "PLAC", "Placer Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.DIAGNOSTICREPORT in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7IdentifierFHIRConversionTest method serviceRequestIdentifierTest5.
// 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 serviceRequestIdentifierTest5() {
// Test 3:
// - MSH.7 as the visit number
// - filler from ORC
// - placer from ORC
String serviceRequest = "MSH|^~\\&|||||20180924152907|34001|ORU^R01^ORU_R01|213|T|2.6|||||||||||\n" + // PID.18 is empty so MSH.7 with be used as backup identifier visit number
"PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + // PV1.19 is empty so MSH.7 with be used as backup identifier visit number
"PV1|1|E|||||||||||||||||||||||||||||||||||||||||||\n" + // 1. ORC.3 is used as Filler because it has priority over OBR.3
"ORC|RE|222298|222299|ML18267-C00001^Beaker||||||||||||||||||||||||||||\n" + // 11. OBR.3 ignored as Filler
"OBR|1|||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);
// 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("20180924152907", identifiers);
assertThat(posVN).isNotSameAs(-1);
int posFILLER = getIdentifierPositionByValue("222299", identifiers);
assertThat(posFILLER).isNotSameAs(-1);
int posPLACER = getIdentifierPositionByValue("222298", identifiers);
assertThat(posPLACER).isNotSameAs(-1);
// Identifier 1: visit number should be set by MSH.7
Identifier identifier = serviceReq.getIdentifier().get(posVN);
String value = identifier.getValue();
String system = identifier.getSystem();
// MSH.7
assertThat(value).isEqualTo("20180924152907");
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();
// ORC.3
assertThat(value).isEqualTo("222299");
assertThat(system).isNull();
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();
// ORC.2
assertThat(value).isEqualTo("222298");
assertThat(system).isNull();
type = identifier.getType();
DatatypeUtils.checkCommonCodeableConceptAssertions(type, "PLAC", "Placer Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.DIAGNOSTICREPORT in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7OrderRequestFHIRConversionTest method testAdditionalOBRFieldsNoORCSegment.
@Test
void testAdditionalOBRFieldsNoORCSegment() {
String hl7message = "MSH|^~\\&|Epic|ATRIUS|||20180924152907|34001|ORU^R01^ORU_R01|213|T|2.6|||||||||PHLabReport-Ack^^2.16.840.1.114222.4.10.3^ISO||\n" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + "PV1|1|E|||||||||||||||||||||||||||||||||||||||||||\n" + // ORC.15 is missing, so use OBR.7 as ServiceRequest.occurrenceDateTime
"OBR|1|248648498^|248648498^|83036E^HEMOGLOBIN A1C^PACSEAP^^^^^^HEMOGLOBIN A1C|||20170707120707|20180808120808|||||||||||||||||F|||||||||||||||||||||||||\n";
String json = ftv.convert(hl7message, PatientUtils.OPTIONS);
assertThat(json).isNotBlank();
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle bundle = (Bundle) bundleResource;
List<BundleEntryComponent> e = bundle.getEntry();
List<Resource> diagnosticReportList = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
DiagnosticReport diagnosticReport = ResourceUtils.getResourceDiagnosticReport(diagnosticReportList.get(0), context);
// OBR.7 and OBR.8 together map to DiagnosticReport.effectivePeriod
assertThat(diagnosticReport.hasEffectivePeriod()).isTrue();
assertThat(diagnosticReport.getEffectivePeriod().getStartElement().toString()).containsPattern("2017-07-07T12:07:07");
assertThat(diagnosticReport.getEffectivePeriod().getEndElement().toString()).containsPattern("2018-08-08T12:08:08");
List<Resource> serviceRequestList = e.stream().filter(v -> ResourceType.ServiceRequest == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
// 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), context);
assertThat(serviceRequest.hasStatus()).isTrue();
// OBR.7 should create an ServiceRequest.occurrenceDateTime date
assertThat(serviceRequest.hasOccurrenceDateTimeType()).isTrue();
assertThat(serviceRequest.getOccurrenceDateTimeType().toString()).containsPattern("2017-07-07T12:07:07");
// ORC.5 is missing, so serviceRequest.status() should be unknown
assertThat(serviceRequest.hasStatus()).isTrue();
assertThat(serviceRequest.getStatusElement().getCode()).isEqualTo("unknown");
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.DIAGNOSTICREPORT in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7NoteFHIRConverterTest method testNoteCreationServiceRequestMutipleOBX.
// 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")
@ParameterizedTest
@MethodSource("provideParmsForNoteCreationServiceRequestMutipleOBX")
void testNoteCreationServiceRequestMutipleOBX(String message, int numExpectedDiagnosticReports) {
String hl7ORU = "MSH|^~\\&|||||20180924152907||" + message + "|213|T|2.3.1|||||||||||\n" + "PID|||Pract1ID^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + // "NTE|1|O|TEST NOTE DD line 1|\n" + "NTE|2|O|TEST NOTE DD line 2 |\n" + "NTE|3|O|TEST NOTE D line 3|\n"
"PV1|1|I||||||||||||||||||||||||||||||||||||||||||20180924152707|\n" + "ORC|RE|248648498^|248648498^|ML18267-C00001^Beaker|||||||||||||||||||||||||||\n" + "OBR|1|248648498^|248648498^|83036E^HEMOGLOBIN A1C^PACSEAP^^^^^^HEMOGLOBIN A1C||||||||||||||||||||||||||||||||||||\n" + // ServiceRequest NTE has a practitioner reference in NTE.5
"NTE|1|O|TEST ORC/OBR NOTE AA line 1||Pract1ID^Pract1Last^Pract1First|\n" + "NTE|2|O|TEST NOTE AA line 2|\n" + "NTE|3|O|TEST NOTE AA line 3|\n" + "OBX|1|NM|17985^GLYCOHEMOGLOBIN HGB A1C^LRR^^^^^^GLYCOHEMOGLOBIN HGB A1C||5.6|%|<6.0||||F||||||||||||||\n" + // GLYCOHEMOGLOBIN Observation NTE has a practitioner reference in NTE.5. Note in second NTE. The first valied NTE.5 is used.
"NTE|1|L|TEST OBXa NOTE BB line 1|\n" + "NTE|2|L|TEST NOTE BB line 2||Pract2ID^Pract2Last^Pract2First|\n" + "NTE|3|L|TEST NOTE BB line 3|\n" + "OBX|2|NM|17853^MEAN BLOOD GLUCOSE^LRR^^^^^^MEAN BLOOD GLUCOSE||114.02|mg/dL|||||F||||||||||||||\n" + // Glucose Observation NTE has no practitioner reference in NTE.5
"NTE|1|L|TEST OBXb NOTE CC line 1|\n" + "NTE|2|L|TEST NOTE CC line 2|\n" + // Test that blank lines are preserved.
"NTE|3|L| |\n" + "NTE|4|L|TEST NOTE CC line 4|\n";
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7ORU);
List<Resource> diagnosticReports = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
// DiagnosticReport expected for ORU, but not for ORM
// From the OBR in the ORU test case
assertThat(diagnosticReports).hasSize(numExpectedDiagnosticReports);
// One ServiceRequest contains NTE for ORC/OBR
List<Resource> serviceRequests = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
assertThat(serviceRequests).hasSize(1);
ServiceRequest serviceRequest = ResourceUtils.getResourceServiceRequest(serviceRequests.get(0), ResourceUtils.context);
assertThat(serviceRequest.hasNote()).isTrue();
assertThat(serviceRequest.getNote()).hasSize(1);
// Processing adds " \n" two spaces and a line feed between each line.
// NOTE: the note contains an Annotation, which contains a MarkdownType that has the string.
// Must use getTextElement().getValueAsString() to see untrimmed contents.
assertThat(serviceRequest.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST ORC/OBR NOTE AA line 1 \nTEST NOTE AA line 2 \nTEST NOTE AA line 3");
assertThat(serviceRequest.getNote().get(0).hasAuthorReference()).isTrue();
String practitionerServReqRefId = serviceRequest.getNote().get(0).getAuthorReference().getReference();
// Two observations. One has GLYCOHEMOGLOBIN and notes BB, One has GLUCOSE and notes CC
List<Resource> observations = ResourceUtils.getResourceList(e, ResourceType.Observation);
// Should be 2 for ORU and ORM
assertThat(observations).hasSize(2);
Observation obsGlucose = ResourceUtils.getResourceObservation(observations.get(0), ResourceUtils.context);
Observation obsHemoglobin = ResourceUtils.getResourceObservation(observations.get(1), ResourceUtils.context);
// Figure out which is first and reassign if needed for testing
if (obsGlucose.getCode().getText() != "MEAN BLOOD GLUCOSE") {
Observation temp = obsGlucose;
obsGlucose = obsHemoglobin;
obsHemoglobin = temp;
}
// Validate the note contents and references
assertThat(obsHemoglobin.hasNote()).isTrue();
assertThat(obsHemoglobin.getNote()).hasSize(1);
assertThat(obsHemoglobin.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST OBXa NOTE BB line 1 \nTEST NOTE BB line 2 \nTEST NOTE BB line 3");
assertThat(obsHemoglobin.getNote().get(0).hasAuthorReference()).isTrue();
String practitionerObsHemoglobinRefId = obsHemoglobin.getNote().get(0).getAuthorReference().getReference();
assertThat(obsGlucose.hasNote()).isTrue();
assertThat(obsGlucose.getNote()).hasSize(1);
assertThat(obsGlucose.getNote().get(0).getTextElement().getValueAsString()).isEqualTo(// Test that blank lines are preserved.
"TEST OBXb NOTE CC line 1 \nTEST NOTE CC line 2 \n \nTEST NOTE CC line 4");
assertThat(obsGlucose.getNote().get(0).hasAuthorReference()).isFalse();
// Two Practitioners, one for the serviceRequest, one for the GLYCOHEMOGLOBIN Observation
List<Resource> practitioners = ResourceUtils.getResourceList(e, ResourceType.Practitioner);
assertThat(practitioners).hasSize(2);
Practitioner practitionerServReq = ResourceUtils.getResourcePractitioner(practitioners.get(0), ResourceUtils.context);
Practitioner practitionerObsHemoglobin = ResourceUtils.getResourcePractitioner(practitioners.get(1), ResourceUtils.context);
// Adjust to correct practitioner if needed
if (!practitionerServReq.getIdentifierFirstRep().getValue().contentEquals("Pract1ID")) {
Practitioner temp = practitionerObsHemoglobin;
practitionerObsHemoglobin = practitionerServReq;
practitionerServReq = temp;
}
// Check the values for the Practitioners and validate match to references.
assertThat(practitionerServReq.getIdentifier()).hasSize(1);
assertThat(practitionerServReq.getIdentifierFirstRep().getValue()).isEqualTo("Pract1ID");
assertThat(practitionerServReq.getName()).hasSize(1);
assertThat(practitionerServReq.getNameFirstRep().getText()).isEqualTo("Pract1First Pract1Last");
// Check the cross-reference
assertThat(practitionerServReq.getId()).isEqualTo(practitionerServReqRefId);
// Sanity check to confirm data corruption in meta content has not returned.
CodeableConcept ccSourceEventTrigger = (CodeableConcept) practitionerServReq.getMeta().getExtensionByUrl("http://ibm.com/fhir/cdm/StructureDefinition/source-event-trigger").getValue();
assertThat(ccSourceEventTrigger.hasText()).isFalse();
assertThat(practitionerObsHemoglobin.getIdentifier()).hasSize(1);
assertThat(practitionerObsHemoglobin.getIdentifierFirstRep().getValue()).isEqualTo("Pract2ID");
assertThat(practitionerObsHemoglobin.getName()).hasSize(1);
assertThat(practitionerObsHemoglobin.getNameFirstRep().getText()).isEqualTo("Pract2First Pract2Last");
// Check the cross-reference
assertThat(practitionerObsHemoglobin.getId()).isEqualTo(practitionerObsHemoglobinRefId);
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.DIAGNOSTICREPORT in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveDiagnosticReport.
private DiagnosticReport resolveDiagnosticReport(ActivityDefinition activityDefinition, String patientId) {
DiagnosticReport diagnosticReport = new DiagnosticReport();
diagnosticReport.setStatus(DiagnosticReport.DiagnosticReportStatus.UNKNOWN);
diagnosticReport.setSubject(new Reference(patientId));
if (activityDefinition.hasCode()) {
diagnosticReport.setCode(activityDefinition.getCode());
} else {
throw new ActivityDefinitionApplyException("Missing required ActivityDefinition.code property for DiagnosticReport");
}
if (activityDefinition.hasRelatedArtifact()) {
List<Attachment> presentedFormAttachments = new ArrayList<>();
for (RelatedArtifact artifact : activityDefinition.getRelatedArtifact()) {
Attachment attachment = new Attachment();
if (artifact.hasUrl()) {
attachment.setUrl(artifact.getUrl());
}
if (artifact.hasDisplay()) {
attachment.setTitle(artifact.getDisplay());
}
presentedFormAttachments.add(attachment);
}
diagnosticReport.setPresentedForm(presentedFormAttachments);
}
return diagnosticReport;
}
Aggregations