Search in sources :

Example 56 with Range

use of org.hl7.fhir.r5.model.Range in project beneficiary-fhir-data by CMSgov.

the class R4ExplanationOfBenefitResourceProviderIT method searchEobWithLastUpdatedAndPaginationAndType.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.r4.providers.ExplanationOfBenefitResourceProvider#findByPatient} works
 * as with a lastUpdated parameter after yesterday.
 *
 * @throws FHIRException (indicates test failure)
 */
@Test
public void searchEobWithLastUpdatedAndPaginationAndType() throws FHIRException {
    Beneficiary beneficiary = loadSampleA();
    IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
    // Search with lastUpdated range between yesterday and now
    int expectedCount = 3;
    Date yesterday = Date.from(Instant.now().minus(1, ChronoUnit.DAYS));
    Date now = new Date();
    DateRangeParam afterYesterday = new DateRangeParam(yesterday, now);
    Bundle searchResultsAfter = fhirClient.search().forResource(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtilsV2.buildPatientId(beneficiary))).lastUpdated(afterYesterday).count(expectedCount).returnBundle(Bundle.class).execute();
    assertEquals(expectedCount, searchResultsAfter.getEntry().size(), "Expected number resources return to be equal to count");
    // Check self url
    String selfLink = searchResultsAfter.getLink(IBaseBundle.LINK_SELF).getUrl();
    assertTrue(selfLink.contains("lastUpdated"));
    // Check next bundle
    String nextLink = searchResultsAfter.getLink(IBaseBundle.LINK_NEXT).getUrl();
    assertTrue(nextLink.contains("lastUpdated"));
    Bundle nextResults = fhirClient.search().byUrl(nextLink).returnBundle(Bundle.class).execute();
    assertEquals(expectedCount, nextResults.getEntry().size(), "Expected number resources return to be equal to count");
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Bundle(org.hl7.fhir.r4.model.Bundle) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) Date(java.util.Date) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Stu3EobSamhsaMatcherTest(gov.cms.bfd.server.war.stu3.providers.Stu3EobSamhsaMatcherTest) Test(org.junit.jupiter.api.Test)

Example 57 with Range

use of org.hl7.fhir.r5.model.Range in project beneficiary-fhir-data by CMSgov.

the class R4ExplanationOfBenefitResourceProviderIT method searchEobWithLastUpdatedAndPagination.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.r4.providers.ExplanationOfBenefitResourceProvider#findByPatient} works
 * as with a lastUpdated parameter after yesterday.
 *
 * @throws FHIRException (indicates test failure)
 */
@Test
public void searchEobWithLastUpdatedAndPagination() throws FHIRException {
    Beneficiary beneficiary = loadSampleA();
    IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
    // Search with lastUpdated range between yesterday and now
    int expectedCount = 3;
    Date yesterday = Date.from(Instant.now().minus(1, ChronoUnit.DAYS));
    Date now = new Date();
    DateRangeParam afterYesterday = new DateRangeParam(yesterday, now);
    Bundle searchResultsAfter = fhirClient.search().forResource(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtilsV2.buildPatientId(beneficiary))).lastUpdated(afterYesterday).count(expectedCount).returnBundle(Bundle.class).execute();
    assertEquals(expectedCount, searchResultsAfter.getEntry().size(), "Expected number resources return to be equal to count");
    // Check self url
    String selfLink = searchResultsAfter.getLink(IBaseBundle.LINK_SELF).getUrl();
    assertTrue(selfLink.contains("lastUpdated"));
    // Check next bundle
    String nextLink = searchResultsAfter.getLink(IBaseBundle.LINK_NEXT).getUrl();
    assertTrue(nextLink.contains("lastUpdated"));
    Bundle nextResults = fhirClient.search().byUrl(nextLink).returnBundle(Bundle.class).execute();
    assertEquals(expectedCount, nextResults.getEntry().size(), "Expected number resources return to be equal to count");
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Bundle(org.hl7.fhir.r4.model.Bundle) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) Date(java.util.Date) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Stu3EobSamhsaMatcherTest(gov.cms.bfd.server.war.stu3.providers.Stu3EobSamhsaMatcherTest) Test(org.junit.jupiter.api.Test)

Example 58 with Range

use of org.hl7.fhir.r5.model.Range in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7MedicationRequestFHIRConversionTest method dosageInstructionTestDoseRangeRXE.

@Test
void dosageInstructionTestDoseRangeRXE() {
    // Test dosageInstruction.DoseRange using RXE segment WITH a range
    String hl7message = "MSH|^~\\&||||||S1|RDE^O11||T|2.6|||||||||\n" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + "ORC|NW|||||E|||||||||||||||||||||||I\n" + // RXE.6 through RXE.44 not used.
    "RXE||DUONEB3INH^3 ML PLAS CONT : IPRATROPIUM-ALBUTEROL 0.5-2.5 (3) MG/3ML IN SOLN^ADS|3|6|mL||||||||||||||||||||||||||||||||||\n";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    List<Resource> medicationRequestList = ResourceUtils.getResourceList(e, ResourceType.MedicationRequest);
    // Confirm that one medicationRequest was created.
    assertThat(medicationRequestList).hasSize(1);
    MedicationRequest medicationRequest = ResourceUtils.getResourceMedicationRequest(medicationRequestList.get(0), ResourceUtils.context);
    Range doseRange = medicationRequest.getDosageInstructionFirstRep().getDoseAndRateFirstRep().getDoseRange();
    // doseRange.low(RXE.3)
    // RXE.3
    assertThat(doseRange.getLow().getValue()).hasToString("3.0");
    // RXE.5
    assertThat(doseRange.getLow().getUnit()).isEqualTo("mL");
    // Defaulted
    assertThat(doseRange.getLow().getSystem()).isEqualTo("http://unitsofmeasure.org");
    // doseRange.high(RXE.4)
    assertThat(doseRange.getHigh().getValue()).hasToString("6.0");
    // RXE.5
    assertThat(doseRange.getHigh().getUnit()).isEqualTo("mL");
    assertThat(doseRange.getHigh().getSystem()).isEqualTo("http://unitsofmeasure.org");
    // Verify no extraneous resources
    // Expect MedicationRequest, Patient
    assertThat(e).hasSize(2);
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Range(org.hl7.fhir.r4.model.Range) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 59 with Range

use of org.hl7.fhir.r5.model.Range in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7ObservationFHIRConversionTest method testObservationNmResult.

@Test
void testObservationNmResult() throws IOException {
    String hl7message = baseMessage + "OBX|1|NM|0135-4^TotalProtein||7.3|gm/dl|5.9-8.4|||R|F";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
    assertThat(obsResource).hasSize(1);
    Observation obs = (Observation) obsResource.get(0);
    assertThat(obs.getValueQuantity()).isNotNull();
    Quantity q = obs.getValueQuantity();
    assertThat(q.getUnit()).isEqualTo("gm/dl");
    assertThat(q.getValue().floatValue()).isEqualTo(7.3f);
    assertThat(obs.hasReferenceRange()).isTrue();
    assertThat(obs.getReferenceRange()).hasSize(1);
    ObservationReferenceRangeComponent range = obs.getReferenceRangeFirstRep();
    assertThat(range).isNotNull();
    assertThat(range.hasHigh()).isTrue();
    assertThat(range.hasLow()).isTrue();
    Quantity high = range.getHigh();
    assertThat(high.getUnit()).isEqualTo("gm/dl");
    assertThat(high.getValue().floatValue()).isEqualTo(8.4f);
    Quantity low = range.getLow();
    assertThat(low.getValue().floatValue()).isEqualTo(5.9f);
    assertThat(low.getUnit()).isEqualTo("gm/dl");
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) ObservationReferenceRangeComponent(org.hl7.fhir.r4.model.Observation.ObservationReferenceRangeComponent) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) Observation(org.hl7.fhir.r4.model.Observation) Quantity(org.hl7.fhir.r4.model.Quantity) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 60 with Range

use of org.hl7.fhir.r5.model.Range in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7ObservationFHIRConversionTest method extendedObservationTestMostMessages.

// Tests most fields of OBX
@ParameterizedTest
@ValueSource(strings = { "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|ADT^A01|||2.6||||||||2.6\r", "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|ADT^A03|||2.6||||||||2.6\r", "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|ADT^A04|||2.6||||||||2.6\r", "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|ADT^A08|||2.6||||||||2.6\r", "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|ADT^A28|||2.6||||||||2.6\r", "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|ADT^A31|||2.6||||||||2.6\r", "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|OMP^O09|||2.6||||||||2.6\r", "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|ORM^O01|||2.6||||||||2.6\r", "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|ORU^R01|||2.6||||||||2.6\r", "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|PPR^PC1|||2.6||||||||2.6\r", // "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|PPR^PC3|||2.6||||||||2.6\r",
"MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|VXU^V04|||2.6||||||||2.6\r" })
// 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 extendedObservationTestMostMessages(String msh) throws IOException {
    String hl7message = msh + "OBX|1|CWE|DQW^Some text 1^SNM3|100|DQW^Other text 2^SNM3|mm^Text 3^SNM3|56-98|IND|25|ST|F|20210322153839|LKJ|20210320153850|N56|1111^ClinicianLastName^ClinicianFirstName^^^^Title|Manual^Text the 4th^SNM3|Device_1234567^mySystem|20210322153925|Observation Site^Text 5^SNM3|INST^Instance Identifier System||Radiology^Radiological Services|467 Albany Hospital^^Albany^NY|Cardiology^ContactLastName^Jane^Q^^Dr.^MD\r";
    // use special created engine
    String json = message.convert(hl7message, customEngine);
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    List<BundleEntryComponent> e = b.getEntry();
    List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
    assertThat(obsResource).hasSize(1);
    Observation obs = (Observation) obsResource.get(0);
    assertThat(obs.hasValueCodeableConcept()).isTrue();
    // Check the coding  (OBX.3)
    assertThat(obs.hasCode()).isTrue();
    DatatypeUtils.checkCommonCodeableConceptAssertions(obs.getCode(), "DQW", "Some text 1", "http://terminology.hl7.org/CodeSystem/SNM3", "Some text 1");
    // Check the value  (OBX.5)
    assertThat(obs.hasValueCodeableConcept()).isTrue();
    DatatypeUtils.checkCommonCodeableConceptAssertions(obs.getValueCodeableConcept(), "DQW", "Other text 2", "http://terminology.hl7.org/CodeSystem/SNM3", "Other text 2");
    // OBX.6 is ignored because the record can only have one valueX and this one is valueCodeableConcept. See test test_observation_NM_result.
    assertThat(obs.hasReferenceRange()).isTrue();
    assertThat(obs.getReferenceRange()).hasSize(1);
    ObservationReferenceRangeComponent range = obs.getReferenceRangeFirstRep();
    assertThat(range).isNotNull();
    assertThat(range.hasHigh()).isTrue();
    assertThat(range.hasLow()).isTrue();
    Quantity high = range.getHigh();
    assertThat(high.getUnit()).isEqualTo("mm");
    assertThat(high.getValue().floatValue()).isEqualTo(98.0f);
    Quantity low = range.getLow();
    assertThat(low.getValue().floatValue()).isEqualTo(56.0f);
    assertThat(low.getUnit()).isEqualTo("mm");
    // Check interpretation (OBX.8)
    assertThat(obs.hasInterpretation()).isTrue();
    assertThat(obs.getInterpretation()).hasSize(1);
    DatatypeUtils.checkCommonCodeableConceptAssertions(obs.getInterpretationFirstRep(), "IND", "Indeterminate", "http://terminology.hl7.org/CodeSystem/v2-0078", null);
    // Check the effective Date Time  (OBX.14)
    assertThat(obs.hasEffective()).isTrue();
    assertThat(obs.hasEffectiveDateTimeType()).isTrue();
    assertThat(obs.getEffectiveDateTimeType().asStringValue()).isEqualTo("2021-03-20T15:38:50+08:00");
    // Check performer  (OBX.16 Practictioner + OBX.23/OBX.24/OBX.25 Organization)
    assertThat(obs.hasPerformer()).isTrue();
    // Practioner and Organization
    assertThat(obs.getPerformer()).hasSize(2);
    // Get Practitioner and see that it is populated with OBX.16 information
    assertThat(obs.getPerformer().get(0).hasReference()).isTrue();
    List<Resource> practitionerResource = e.stream().filter(v -> ResourceType.Practitioner == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    assertThat(practitionerResource).hasSize(1);
    Practitioner doctor = ResourceUtils.getResourcePractitioner(practitionerResource.get(0), ResourceUtils.context);
    assertThat(doctor.getName().get(0).getFamily()).isEqualTo("ClinicianLastName");
    // Get Organization and see that it is populated with OBX.23/OBX.24/OBX.25 information
    assertThat(obs.getPerformer().get(1).hasReference()).isTrue();
    List<Resource> organizationResource = e.stream().filter(v -> ResourceType.Organization == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    assertThat(organizationResource).hasSize(1);
    Organization org = ResourceUtils.getResourceOrganization(organizationResource.get(0), ResourceUtils.context);
    // from OBX.23
    assertThat(org.getName()).isEqualTo("Radiology");
    assertThat(org.getAddress().get(0).getLine().get(0).getValueAsString()).isEqualTo(// from OBX.24
    "467 Albany Hospital");
    // from OBX.24
    assertThat(org.getAddress().get(0).getCity()).isEqualTo("Albany");
    // from OBX.24
    assertThat(org.getAddress().get(0).getState()).isEqualTo("NY");
    // from OBX.25
    assertThat(org.getContact().get(0).getName().getFamily()).isEqualTo("ContactLastName");
    // from OBX.25
    assertThat(org.getContact().get(0).getName().getGiven().get(0).getValueAsString()).isEqualTo("Jane");
    // from OBX.25
    assertThat(org.getContact().get(0).getName().getText()).isEqualTo("Dr. Jane Q ContactLastName");
    // purpose added because of OBX.25
    assertThat(org.getContact().get(0).hasPurpose()).isTrue();
    DatatypeUtils.checkCommonCodeableConceptAssertions(org.getContact().get(0).getPurpose(), "ADMIN", "Administrative", "http://terminology.hl7.org/CodeSystem/contactentity-type", "Organization Medical Director");
    // Check method  (OBX.17)
    assertThat(obs.hasMethod()).isTrue();
    DatatypeUtils.checkCommonCodeableConceptAssertions(obs.getMethod(), "Manual", "Text the 4th", "http://terminology.hl7.org/CodeSystem/SNM3", "Text the 4th");
    // Check device  (OBX.18)
    assertThat(obs.hasDevice()).isTrue();
    assertThat(obs.getDevice().hasReference()).isTrue();
    List<Resource> deviceResource = e.stream().filter(v -> ResourceType.Device == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    assertThat(deviceResource).hasSize(1);
    Device device = ResourceUtils.getResourceDevice(deviceResource.get(0), ResourceUtils.context);
    assertThat(device.getIdentifier().get(0).getValue()).isEqualTo("Device_1234567");
    assertThat(device.getIdentifier().get(0).getSystem()).isEqualTo("urn:id:mySystem");
    // Check bodySite  (OBX.20)
    assertThat(obs.hasBodySite()).isTrue();
    DatatypeUtils.checkCommonCodeableConceptAssertions(obs.getBodySite(), "Observation Site", "Text 5", "http://terminology.hl7.org/CodeSystem/SNM3", "Text 5");
    // Check identifier  (OBX.21)
    assertThat(obs.hasIdentifier()).isTrue();
    assertThat(obs.getIdentifier()).hasSize(2);
    assertThat(obs.getIdentifier().get(1).getValue()).isEqualTo("INST");
    assertThat(obs.getIdentifier().get(1).getSystem()).isEqualTo("urn:id:Instance_Identifier_System");
    // OBX.23/OBX.24/OBX.25 went into Performer: Organization.  Checked above.
    // Check for ABSENCE of category (because no SPM)  Presence of category tested in extendedObservationUnusualRangesAndOtherTest
    assertThat(obs.hasCategory()).isFalse();
}
Also used : Organization(org.hl7.fhir.r4.model.Organization) Bundle(org.hl7.fhir.r4.model.Bundle) Device(org.hl7.fhir.r4.model.Device) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) Quantity(org.hl7.fhir.r4.model.Quantity) Practitioner(org.hl7.fhir.r4.model.Practitioner) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) ObservationReferenceRangeComponent(org.hl7.fhir.r4.model.Observation.ObservationReferenceRangeComponent) Observation(org.hl7.fhir.r4.model.Observation) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Test (org.junit.jupiter.api.Test)18 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)15 Quantity (org.hl7.fhir.r4.model.Quantity)14 Resource (org.hl7.fhir.r4.model.Resource)13 NotImplementedException (org.apache.commons.lang3.NotImplementedException)12 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Search (ca.uhn.fhir.rest.annotation.Search)11 Trace (com.newrelic.api.agent.Trace)10 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)10 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)9 ArrayList (java.util.ArrayList)9 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)8 Operation (gov.cms.bfd.server.war.Operation)8 OffsetLinkBuilder (gov.cms.bfd.server.war.commons.OffsetLinkBuilder)8 Date (java.util.Date)8 Range (org.hl7.fhir.r4.model.Range)8 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)7 List (java.util.List)7 Bundle (org.hl7.fhir.r4.model.Bundle)7