use of org.hl7.fhir.r4b.model.DateTimeType in project cqf-ruler by DBCG.
the class ExtractProvider method createObservationFromItemAnswer.
private Bundle.BundleEntryComponent createObservationFromItemAnswer(QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent answer, String linkId, Date authored, QuestionnaireResponse questionnaireResponse, Map<String, Coding> questionnaireCodeMap) {
Observation obs = new Observation();
obs.setEffective(new DateTimeType(authored));
obs.setStatus(Observation.ObservationStatus.FINAL);
obs.setSubject(questionnaireResponse.getSubject());
Coding qrCategoryCoding = new Coding();
qrCategoryCoding.setCode("survey");
qrCategoryCoding.setSystem("http://hl7.org/fhir/observation-category");
obs.setCategory(Collections.singletonList(new CodeableConcept().addCoding(qrCategoryCoding)));
obs.setCode(new CodeableConcept().addCoding(questionnaireCodeMap.get(linkId)));
obs.setId("qr" + questionnaireResponse.getIdElement().getIdPart() + "." + linkId);
switch(answer.getValue().fhirType()) {
case "string":
obs.setValue(new StringType(answer.getValueStringType().getValue()));
break;
case "Coding":
obs.setValue(new CodeableConcept().addCoding(answer.getValueCoding()));
break;
case "boolean":
obs.setValue(new BooleanType(answer.getValueBooleanType().booleanValue()));
break;
}
Reference questionnaireResponseReference = new Reference();
questionnaireResponseReference.setReference("QuestionnaireResponse" + "/" + questionnaireResponse.getIdElement().getIdPart());
Observation.ObservationRelatedComponent related = new Observation.ObservationRelatedComponent().setType(Observation.ObservationRelationshipType.DERIVEDFROM).setTarget(questionnaireResponseReference);
obs.setRelated(Collections.singletonList(related));
Extension linkIdExtension = new Extension();
linkIdExtension.setUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/derivedFromLinkId");
Extension innerLinkIdExtension = new Extension();
innerLinkIdExtension.setUrl("text");
innerLinkIdExtension.setValue(new StringType(linkId));
linkIdExtension.setExtension(Collections.singletonList(innerLinkIdExtension));
obs.addExtension(linkIdExtension);
Bundle.BundleEntryRequestComponent berc = new Bundle.BundleEntryRequestComponent();
berc.setMethod(Bundle.HTTPVerb.PUT);
berc.setUrl("Observation/" + obs.getId());
Bundle.BundleEntryComponent bec = new Bundle.BundleEntryComponent();
bec.setResource(obs);
bec.setRequest(berc);
return bec;
}
use of org.hl7.fhir.r4b.model.DateTimeType in project cqf-ruler by DBCG.
the class ExtractProvider method createObservationFromItemAnswer.
private Bundle.BundleEntryComponent createObservationFromItemAnswer(QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent answer, String linkId, Date authored, QuestionnaireResponse questionnaireResponse, Map<String, Coding> questionnaireCodeMap) {
Observation obs = new Observation();
obs.setEffective(new DateTimeType(authored));
obs.setStatus(Observation.ObservationStatus.FINAL);
obs.setSubject(questionnaireResponse.getSubject());
Coding qrCategoryCoding = new Coding();
qrCategoryCoding.setCode("survey");
qrCategoryCoding.setSystem("http://hl7.org/fhir/observation-category");
obs.setCategory(Collections.singletonList(new CodeableConcept().addCoding(qrCategoryCoding)));
obs.setCode(new CodeableConcept().addCoding(questionnaireCodeMap.get(linkId)));
obs.setId("qr" + questionnaireResponse.getIdElement().getIdPart() + "." + linkId);
switch(answer.getValue().fhirType()) {
case "string":
obs.setValue(new StringType(answer.getValueStringType().getValue()));
break;
case "Coding":
obs.setValue(new CodeableConcept().addCoding(answer.getValueCoding()));
break;
case "boolean":
obs.setValue(new BooleanType(answer.getValueBooleanType().booleanValue()));
break;
}
Reference questionnaireResponseReference = new Reference();
questionnaireResponseReference.setReference("QuestionnaireResponse" + "/" + questionnaireResponse.getIdElement().getIdPart());
obs.setDerivedFrom(Collections.singletonList(questionnaireResponseReference));
Extension linkIdExtension = new Extension();
linkIdExtension.setUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/derivedFromLinkId");
Extension innerLinkIdExtension = new Extension();
innerLinkIdExtension.setUrl("text");
innerLinkIdExtension.setValue(new StringType(linkId));
linkIdExtension.setExtension(Collections.singletonList(innerLinkIdExtension));
obs.addExtension(linkIdExtension);
Bundle.BundleEntryRequestComponent berc = new Bundle.BundleEntryRequestComponent();
berc.setMethod(Bundle.HTTPVerb.PUT);
berc.setUrl("Observation/" + obs.getId());
Bundle.BundleEntryComponent bec = new Bundle.BundleEntryComponent();
bec.setResource(obs);
bec.setRequest(berc);
return bec;
}
use of org.hl7.fhir.r4b.model.DateTimeType in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7OrderRequestFHIRConversionTest method testBroadORCPlusOBRFields.
// This test is a companion to testBroadORCFields. ORC and OBR records often have repeated data; one taking priority over the other.
// Read comments carefully. This sometimes tests the secondary value and may be the opposite to the tests in testBroadORCFields.
@Test
// 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")
void testBroadORCPlusOBRFields() {
String hl7message = "MSH|^~\\&|||||20180924152907|34001|ORU^R01^ORU_R01|213|T|2.6|||||||||||\n" + // PID.18 is used as backup identifier visit number because PV1.19 is empty
"PID|||1234^^^^MR||DOE^JANE^|||F||||||||||665544||||||||||||\n" + // PV1.19 is empty and not used as visit number identifier
"PV1|1|E|||||||||||||||||||||||||||||||||||||||||||\n" + // 7. ORC.16 is set to a reason code (but it is ignored because it is secondary to OBR.31, which is present in this case and therefore overrides ORC.16)
"ORC|RE|248648498^|248648498^|||||||||||||042^Human immunodeficiency virus [HIV] disease [42]^I9CDX^^^^29|||||||||||||||\n" + // 14. OBR.6 creates ServiceRequest.authoredOn
"OBR|1|248648498^|248648498^|83036E^HEMOGLOBIN A1C^PACSEAP^^^^^^HEMOGLOBIN A1C||20120606120606|20170707150707||||L|||||54321678^SCHMIDT^FRIEDA^^MD^^^^NPI^D^^^NPI||||||20180924152900|||F||||||HIV^HIV/Aids^L^^^^V1|323232&Mahoney&Paul&J||||||||||||||||||\n";
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), context);
assertThat(serviceRequest.hasStatus()).isTrue();
assertThat(serviceRequest.hasIdentifier()).isTrue();
assertThat(serviceRequest.getIdentifier()).hasSize(3);
// Identifier 1: visit number should be set by in this test by secondary PID.18
// ORU_RO1 records do not create the ServiceRequest directly. They create a DiagnosticReport and it creates the ServiceRequest.
// This makes sure the specification for ORU_RO1.DiagnosticReport is specifying PID correctly in AdditionalSegments.
// Extensive testing of identifiers is done in Hl7IdentifierFHIRConversionTest.java
Identifier identifier = serviceRequest.getIdentifier().get(0);
String value = identifier.getValue();
String system = identifier.getSystem();
// PID.18
assertThat(value).isEqualTo("665544");
assertThat(system).isNull();
CodeableConcept type = identifier.getType();
DatatypeUtils.checkCommonCodeableConceptAssertions(type, "VN", "Visit number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
// No requisition in the serviceRequest.
assertThat(serviceRequest.hasRequisition()).isFalse();
// OBR.6 should create authoredOn because ORC.9 is not filled in
assertThat(serviceRequest.hasAuthoredOn()).isTrue();
assertThat(serviceRequest.getAuthoredOnElement().toString()).containsPattern("2012-06-06T12:06:06");
// OBR.7 is used to create an ServiceRequest.occurrenceDateTime date because ORC.15 is empty
assertThat(serviceRequest.hasOccurrenceDateTimeType()).isTrue();
assertThat(serviceRequest.getOccurrenceDateTimeType().toString()).containsPattern("2017-07-07T15:07:07");
// OBR.31 should create the ServiceRequest.reasonCode CWE
assertThat(serviceRequest.hasReasonCode()).isTrue();
assertThat(serviceRequest.getReasonCode()).hasSize(1);
DatatypeUtils.checkCommonCodeableConceptVersionedAssertions(serviceRequest.getReasonCodeFirstRep(), "HIV", "HIV/Aids", "urn:id:L", "HIV/Aids", "V1");
// OBR.16 should create an ServiceRequest.requester reference & display
assertThat(serviceRequest.hasRequester()).isTrue();
assertThat(serviceRequest.getRequester().hasDisplay()).isTrue();
assertThat(serviceRequest.getRequester().getDisplay()).isEqualTo("FRIEDA SCHMIDT MD");
assertThat(serviceRequest.getRequester().hasReference()).isTrue();
String requesterRef = serviceRequest.getRequester().getReference();
Practitioner pract = ResourceUtils.getSpecificPractitionerFromBundleEntriesList(e, requesterRef);
// Confirm that the matching practitioner by ID has the correct content (simple validation)
// Should be OBR.16 because ORC.12 is empty.
// Check the practitioner content in detail, validating subfields.
assertThat(pract.getIdentifier()).hasSize(1);
// OBR.16.1
assertThat(pract.getIdentifierFirstRep().getValue()).isEqualTo("54321678");
// OBR.16.9, tests known system logic
assertThat(pract.getIdentifierFirstRep().getSystem()).isEqualTo("http://hl7.org/fhir/sid/us-npi");
DatatypeUtils.checkCommonCodeableConceptAssertions(pract.getIdentifierFirstRep().getType(), "NPI", "National provider identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", // OBR.16.13
null);
assertThat(pract.getName()).hasSize(1);
// Combined OBR.16.2 - OBR.16.7
assertThat(pract.getNameFirstRep().getTextElement().toString()).hasToString("FRIEDA SCHMIDT MD");
// OBR.16.10
assertThat(pract.getNameFirstRep().getUseElement().getCode()).isEqualTo("usual");
// OBR.4 maps to ServiceRequest.code. Verify resulting CodeableConcept.
assertThat(serviceRequest.hasCode()).isTrue();
DatatypeUtils.checkCommonCodeableConceptAssertions(serviceRequest.getCode(), "83036E", "HEMOGLOBIN A1C", "urn:id:PACSEAP", "HEMOGLOBIN A1C");
List<Resource> diagnosticReportList = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
assertThat(diagnosticReportList).hasSize(1);
DiagnosticReport diagnosticReport = ResourceUtils.getResourceDiagnosticReport(diagnosticReportList.get(0), context);
// OBR.4 ALSO maps to DiagnosticReport.code. Verify resulting CodeableConcept.
assertThat(diagnosticReport.hasCode()).isTrue();
DatatypeUtils.checkCommonCodeableConceptAssertions(diagnosticReport.getCode(), "83036E", "HEMOGLOBIN A1C", "urn:id:PACSEAP", "HEMOGLOBIN A1C");
assertThat(diagnosticReport.hasBasedOn()).isTrue();
assertThat(diagnosticReport.getBasedOn()).hasSize(1);
// OBR.7 maps to create an DiagnosticReport.effectiveDateTime
assertThat(diagnosticReport.hasEffectiveDateTimeType()).isTrue();
assertThat(diagnosticReport.getEffectiveDateTimeType().toString()).containsPattern("2017-07-07T15:07:07");
// Check for DiagnosticReport.issued instant of OBR.22
assertThat(diagnosticReport.hasIssued()).isTrue();
// NOTE: The data is kept as an InstantType, and is extracted with .toInstant
// thus results in a different format than other time stamps that are based on DateTimeType
assertThat(diagnosticReport.getIssued().toInstant().toString()).contains("2018-09-24T07:29:00Z");
// Get the diagnosticReport.resultsInterpreter, which should match the Practitioner data from OBR.32
assertThat(diagnosticReport.hasResultsInterpreter()).isTrue();
assertThat(diagnosticReport.getResultsInterpreter()).hasSize(1);
String resultsInterpreterRef = diagnosticReport.getResultsInterpreter().get(0).getReference();
pract = ResourceUtils.getSpecificPractitionerFromBundleEntriesList(e, resultsInterpreterRef);
// Confirm that the matching practitioner by ID has the correct content (simple validation)
// Should be the value OBR.32
assertThat(pract.getIdentifierFirstRep().getValue()).isEqualTo("323232");
assertThat(pract.getName()).hasSize(1);
assertThat(pract.getName().get(0).getTextElement()).hasToString("Paul J Mahoney");
// Check for OBR.25 mapped to DiagnosticReport.status
assertThat(diagnosticReport.hasStatus()).isTrue();
assertThat(diagnosticReport.getStatusElement().getCode()).isEqualTo("final");
}
use of org.hl7.fhir.r4b.model.DateTimeType in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7PatientFHIRConversionTest method validate_lineage_json.
private void validate_lineage_json(List<Extension> extensions, String messageType, boolean millis) {
assertThat(extensions.size()).isEqualTo(6);
for (Extension extension : extensions) {
// Get the URL
String url = extension.getUrl();
LOGGER.debug("URL:" + url);
// Get the value
String value = extension.getValue().toString();
// If the value is a codeable concept and not a simple value - parse the value out of the codeable concept.
if (value.indexOf("CodeableConcept") >= 0) {
String codeableConceptValue = extension.getValue().getChildByName("coding").getValues().get(0).getNamedProperty("code").getValues().get(0).toString();
LOGGER.debug("CodeableConceptValue:" + codeableConceptValue.toString());
value = codeableConceptValue.toString();
}
// Get the Name from the URL
String name = url.substring(url.lastIndexOf("/") + 1, url.length());
LOGGER.debug("Name:" + name);
LOGGER.debug("Value:" + value);
LOGGER.debug("Message Type:" + messageType);
String[] messageParts = messageType.split("\\^");
// test value based off the name.
switch(name) {
case "source-event-timestamp":
if (millis)
assertThat(value).isEqualTo("DateTimeType[2006-09-15T21:00:00.567+08:00]");
else
assertThat(value).isEqualTo("DateTimeType[2006-09-15T21:00:00+08:00]");
break;
case "source-record-id":
assertThat(value).isEqualTo("1473973200100600");
break;
case "source-data-model-version":
assertThat(value).isEqualTo("2.3");
break;
case "process-client-id":
assertThat(value).isEqualTo("SendingApplication");
break;
case "source-event-trigger":
assertThat(value).isEqualTo(messageParts[1]);
break;
case "source-record-type":
assertThat(value).isEqualTo(messageParts[0]);
break;
default:
// this shouldn't happen
LOGGER.debug("Not found");
Assertions.fail();
break;
}
}
}
use of org.hl7.fhir.r4b.model.DateTimeType in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7AllergyFHIRConversionTest method test_allergy_onset.
@Test
/**
* Verifies AL1-6 is put into AllergyIntolerance.onsetDateTime; AllergyIntolerance.reaction.onset is not set.
*/
void test_allergy_onset() {
String hl7message = "MSH|^~\\&|SE050|050|PACS|050|20120912011230||ADT^A01|102|T|2.6|||AL|NE\r" + "PID|0010||PID1234||DOE^JANE|||F\r" + "AL1|1|DA|00000741^OXYCODONE||HYPOTENSION|20210101\r";
AllergyIntolerance allergy = ResourceUtils.getAllergyResource(ftv, hl7message);
assertThat(allergy.getCategory().get(0).getCode()).isEqualTo("medication");
assertThat(allergy.getReaction().get(0).getManifestation()).extracting(m -> m.getText()).containsExactly("HYPOTENSION");
Date onsetReaction = allergy.getReaction().get(0).getOnset();
Assertions.assertNull(onsetReaction);
DateTimeType onsetAllergy = allergy.getOnsetDateTimeType();
assertThat(onsetAllergy.getValueAsString()).isEqualTo("2021-01-01");
}
Aggregations