Search in sources :

Example 36 with COMPLETED

use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7ImmunizationFHIRConversionTest method testImmunizationTestORC5BackupForRXA20.

@Test
void testImmunizationTestORC5BackupForRXA20() throws IOException {
    // ORC.5 backs up RXA.20 and RXA.18
    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|||197027||PA|||||^Clerk^Myron|||||||RI2050\r" + "RXA|0|1|20130531||48^HIB PRP-T^CVX|999|ML^^UCUM||||||||||||||A\r";
    Immunization immunization = ResourceUtils.getImmunization(ftv, hl7VUXmessageRep);
    // doseQuantity with 999 as the value which should return null;
    assertThat(immunization.hasDoseQuantity()).isFalse();
    // ORC.5 backs up RXA.20 and RXA.18
    assertThat(immunization.getStatus().getDisplay()).isEqualTo("completed");
    assertThat(immunization.hasStatusReason()).isFalse();
    assertThat(immunization.hasReaction()).isFalse();
    assertThat(immunization.hasProgramEligibility()).isFalse();
    assertThat(immunization.hasFundingSource()).isFalse();
}
Also used : Immunization(org.hl7.fhir.r4.model.Immunization) Test(org.junit.jupiter.api.Test)

Example 37 with COMPLETED

use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project openmrs-module-fhir2 by openmrs.

the class BaseServiceRequestTranslator method determineServiceRequestStatus.

protected ServiceRequest.ServiceRequestStatus determineServiceRequestStatus(String orderUuid) {
    IBundleProvider results = taskService.searchForTasks(new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam("ServiceRequest", null, orderUuid))), null, null, null, null, null, null);
    Collection<Task> serviceRequestTasks = results.getResources(START_INDEX, END_INDEX).stream().map(p -> (Task) p).collect(Collectors.toList());
    ServiceRequest.ServiceRequestStatus serviceRequestStatus = ServiceRequest.ServiceRequestStatus.UNKNOWN;
    if (serviceRequestTasks.size() != 1) {
        return serviceRequestStatus;
    }
    Task serviceRequestTask = serviceRequestTasks.iterator().next();
    if (serviceRequestTask.hasStatus()) {
        switch(serviceRequestTask.getStatus()) {
            case ACCEPTED:
            case REQUESTED:
                serviceRequestStatus = ServiceRequest.ServiceRequestStatus.ACTIVE;
                break;
            case REJECTED:
                serviceRequestStatus = ServiceRequest.ServiceRequestStatus.REVOKED;
                break;
            case COMPLETED:
                serviceRequestStatus = ServiceRequest.ServiceRequestStatus.COMPLETED;
                break;
        }
    }
    return serviceRequestStatus;
}
Also used : ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) Setter(lombok.Setter) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) Reference(org.hl7.fhir.r4.model.Reference) Collectors(java.util.stream.Collectors) Task(org.hl7.fhir.r4.model.Task) AccessLevel(lombok.AccessLevel) FhirTaskService(org.openmrs.module.fhir2.api.FhirTaskService) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) Task(org.hl7.fhir.r4.model.Task) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest)

Example 38 with COMPLETED

use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project openmrs-module-fhir2 by openmrs.

the class FhirImmunizationServiceImplTest method saveImmunization_shouldCreateEncounterAndObsGroupWhenNewImmunization.

@Test
public void saveImmunization_shouldCreateEncounterAndObsGroupWhenNewImmunization() {
    // setup
    FhirContext ctx = FhirContext.forR4();
    IParser parser = ctx.newJsonParser();
    Immunization newImmunization = parser.parseResource(Immunization.class, "{\n" + "  \"resourceType\": \"Immunization\",\n" + "  \"status\": \"completed\",\n" + "  \"vaccineCode\": {\n" + "    \"coding\": [\n" + "      {\n" + "        \"code\": \"15f83cd6-64e9-4e06-a5f9-364d3b14a43d\",\n" + "        \"display\": \"Aspirin as a vaccine\"\n" + "      }\n" + "    ]\n" + "  },\n" + "  \"patient\": {\n" + "    \"reference\": \"Patient/a7e04421-525f-442f-8138-05b619d16def\",\n" + "    \"type\": \"Patient\"\n" + "  },\n" + "  \"encounter\": {\n" + "    \"reference\": \"Encounter/7d8c1980-6b78-11e0-93c3-18a905e044dc\",\n" + "    \"type\": \"Encounter\"\n" + "  },\n" + "  \"occurrenceDateTime\": \"2020-07-08T18:30:00.000Z\",\n" + "  \"manufacturer\": {\n" + "    \"display\": \"Acme\"\n" + "  },\n" + "  \"lotNumber\": \"FOO1234\",\n" + "  \"expirationDate\": \"2022-07-31T18:30:00.000Z\",\n" + "  \"performer\": [\n" + "    {\n" + "      \"actor\": {\n" + "        \"reference\": \"Practitioner/f9badd80-ab76-11e2-9e96-0800200c9a66\",\n" + "        \"type\": \"Practitioner\"\n" + "      }\n" + "    }\n" + "  ],\n" + "  \"protocolApplied\": [\n" + "    {\n" + "      \"doseNumberPositiveInt\": 2,\n" + "      \"series\": \"Dose 2\"\n" + "    }\n" + "  ]\n" + "}");
    // replay
    Immunization savedImmunization = service.create(newImmunization);
    Obs obs = obsService.getObsByUuid(savedImmunization.getId());
    // verify
    helper.validateImmunizationObsGroup(obs);
    assertObsCommons(obs, "a7e04421-525f-442f-8138-05b619d16def", "7d8c1980-6b78-11e0-93c3-18a905e044dc", "f9badd80-ab76-11e2-9e96-0800200c9a66");
    obs.getGroupMembers().forEach(o -> assertObsCommons(o, "a7e04421-525f-442f-8138-05b619d16def", "7d8c1980-6b78-11e0-93c3-18a905e044dc", "f9badd80-ab76-11e2-9e96-0800200c9a66"));
    Map<String, Obs> members = helper.getObsMembersMap(obs);
    assertThat(members.get(CIEL_984).getValueCoded().getUuid(), is("15f83cd6-64e9-4e06-a5f9-364d3b14a43d"));
    assertThat(members.get(CIEL_1410).getValueDatetime(), equalTo(new DateTimeType("2020-07-08T18:30:00.000Z").getValue()));
    assertThat(members.get(CIEL_1418).getValueNumeric(), equalTo(2.0));
    assertThat(members.get(CIEL_1419).getValueText(), is("Acme"));
    assertThat(members.get(CIEL_1420).getValueText(), is("FOO1234"));
    assertThat(members.get(CIEL_165907).getValueDatetime(), equalTo(new DateTimeType("2022-07-31T18:30:00.000Z").getValue()));
}
Also used : Obs(org.openmrs.Obs) FhirContext(ca.uhn.fhir.context.FhirContext) Immunization(org.hl7.fhir.r4.model.Immunization) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) IParser(ca.uhn.fhir.parser.IParser) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 39 with COMPLETED

use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project openmrs-module-fhir2 by openmrs.

the class ImmunizationFhirResourceProviderIntegrationTest method shouldCreateNewImmunizationWithoutSomeOptionalMembersAsJSON.

@Test
public void shouldCreateNewImmunizationWithoutSomeOptionalMembersAsJSON() throws Exception {
    // read JSON record
    String jsonImmunization;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_PARTIAL_IMMUNIZATION_DOCUMENT)) {
        Objects.requireNonNull(is);
        jsonImmunization = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    // create IMMUNIZATION
    MockHttpServletResponse response = post("/Immunization").accept(FhirMediaTypes.JSON).jsonContent(jsonImmunization).go();
    // verify created correctly
    assertThat(response, isCreated());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Immunization immunization = readResponse(response);
    assertThat(immunization, notNullValue());
    assertThat(immunization.getResourceType().toString(), equalTo("Immunization"));
    assertThat(immunization.getStatus().toCode(), equalTo("completed"));
    assertThat(immunization.getVaccineCode().getCodingFirstRep().getCode(), equalTo("15f83cd6-64e9-4e06-a5f9-364d3b14a43d"));
    assertThat(immunization.getPatient().getReferenceElement().getIdPart(), equalTo("8d703ff2-c3e2-4070-9737-73e713d5a50d"));
    assertThat(immunization.getOccurrenceDateTimeType().getValueAsCalendar().getTime(), sameInstant(Date.from(ZonedDateTime.parse("2020-07-08T18:30:00.000Z").toInstant())));
    assertThat(immunization.hasManufacturer(), is(true));
    assertThat(immunization.getManufacturer().getDisplay(), equalTo("Pfizer"));
    assertThat(immunization.getLotNumber(), equalTo("22"));
    assertThat(immunization.getExpirationDate(), sameDay(LocalDate.parse("2021-07-28")));
    assertThat(immunization.getPerformer().get(0).getActor().getReferenceElement().getIdPart(), equalTo("6f763a67-2bd1-451c-93b9-95caeb36cc24"));
    assertThat(immunization, validResource());
    // try to get new immunization
    response = get("/Immunization/" + immunization.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    Immunization newImmunization = readResponse(response);
    assertThat(newImmunization.getId(), equalTo(immunization.getId()));
}
Also used : Immunization(org.hl7.fhir.r4.model.Immunization) InputStream(java.io.InputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 40 with COMPLETED

use of org.hl7.fhir.r4.model.Procedure.ProcedureStatus.COMPLETED in project ab2d by CMSgov.

the class CoverageMappingCallable method call.

/**
 * Execute queries against BFD and collect enrollment result into a single object.
 *
 * In the past there have been significant issues related to the values of the enrollment returned by BFD.
 * These issues have led to adding a bunch of logs in here for most steps in the enrollment process.
 *
 * These logs include:
 *      - log each bundle received with the page number
 *      - listing all links to additional pages returned by BFD
 *      - log last page received
 *      - record statistics regarding potentially missing things like MBIs, beneficiary ids, distribution of reference
 *          years on the patient, and past reference years which are not expected.
 *
 * Steps
 *      - Set a unique id for the job as a header to BFD for monitoring purposes
 *      - Get the first page of enrollment results and process those results
 *      - Loop over the remaining pages of results and query until none are left
 *      - Add the results to the CoverageMapping object
 *      - Mark the search as completed
 *      - Log statistics concerning enrollment pulled
 *      - Remove the unique id header used for BFD
 *
 * @throws Exception on any failure, before the exception is thrown it will be logged
 */
@Trace(metricName = "EnrollmentRequest", dispatcher = true)
@Override
public CoverageMapping call() {
    int month = coverageMapping.getPeriod().getMonth();
    String contractNumber = coverageMapping.getContractNumber();
    final Set<Identifiers> patientIds = new HashSet<>();
    int bundleNo = 1;
    try {
        log.info("retrieving contract membership for ContractWorkerDto {}-{}-{} bundle #{}", contractNumber, this.year, month, bundleNo);
        BFDClient.BFD_BULK_JOB_ID.set(coverageMapping.getJobId());
        IBaseBundle bundle = getBundle(contractNumber, month, this.year);
        patientIds.addAll(extractAndFilter(bundle));
        String availableLinks = BundleUtils.getAvailableLinks(bundle);
        log.info("retrieving contract membership for ContractWorkerDto {}-{}-{} bundle #{}, available links {}", contractNumber, this.year, month, bundleNo, availableLinks);
        if (BundleUtils.getNextLink(bundle) == null) {
            log.info("retrieving contract membership for ContractWorkerDto {}-{}-{} bundle #{}, does not have a next link", contractNumber, this.year, month, bundleNo);
        }
        while (BundleUtils.getNextLink(bundle) != null) {
            bundleNo += 1;
            log.info("retrieving contract membership for ContractWorkerDto {}-{}-{} bundle #{}", contractNumber, this.year, month, bundleNo);
            bundle = bfdClient.requestNextBundleFromServer(version, bundle);
            availableLinks = BundleUtils.getAvailableLinksPretty(bundle);
            log.info("retrieving contract membership for ContractWorkerDto {}-{}-{} bundle #{}, available links {}", contractNumber, this.year, month, bundleNo, availableLinks);
            if (BundleUtils.getNextLink(bundle) == null) {
                log.info("retrieving contract membership for ContractWorkerDto {}-{}-{} bundle #{}, does not have a next link", contractNumber, this.year, month, bundleNo);
            }
            patientIds.addAll(extractAndFilter(bundle));
        }
        log.info("retrieving contract membership for ContractWorkerDto {}-{}-{}, #{} bundles received.", contractNumber, this.year, month, bundleNo);
        coverageMapping.addBeneficiaries(patientIds);
        log.debug("finished reading [{}] Set<Identifiers>resources", patientIds.size());
        coverageMapping.completed();
        return coverageMapping;
    } catch (Exception e) {
        log.error("Unable to get patient information for " + contractNumber + " for month " + month + " and year " + this.year, e);
        coverageMapping.failed();
        throw e;
    } finally {
        int total = patientIds.size() + missingReferenceYear + missingBeneId + pastReferenceYear;
        log.info("Search {}-{}-{} found {} distribution of reference years over a total of {} benes", contractNumber, this.year, month, referenceYears, total);
        log.info("Search {}-{}-{} discarded {} entries missing a reference year out of {}", contractNumber, this.year, month, missingReferenceYear, total);
        log.info("Search {}-{}-{} discarded {} entries with a reference year in the past out of {}", contractNumber, this.year, month, pastReferenceYear, total);
        log.info("Search {}-{}-{} discarded {} entries missing a beneficiary identifier out of {}", contractNumber, this.year, month, missingBeneId, total);
        log.info("Search {}-{}-{} found {} entries missing a current mbi out of {}", contractNumber, this.year, month, missingCurrentMbi, total);
        log.info("Search {}-{}-{} found {} entries with a historical mbi out of {}", contractNumber, this.year, month, hasHistoricalMbi, total);
        completed.set(true);
        BFDClient.BFD_BULK_JOB_ID.remove();
    }
}
Also used : IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Identifiers(gov.cms.ab2d.coverage.model.Identifiers) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Trace(com.newrelic.api.agent.Trace)

Aggregations

Immunization (org.hl7.fhir.r4.model.Immunization)13 Date (java.util.Date)9 ArrayList (java.util.ArrayList)8 InputStream (java.io.InputStream)7 Reference (org.hl7.fhir.dstu3.model.Reference)7 Test (org.junit.jupiter.api.Test)7 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)6 Collectors (java.util.stream.Collectors)5 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)5 Reference (org.hl7.fhir.r4.model.Reference)5 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)5 FhirContext (ca.uhn.fhir.context.FhirContext)4 Search (ca.uhn.fhir.rest.annotation.Search)4 Trace (com.newrelic.api.agent.Trace)4 File (java.io.File)4 List (java.util.List)4 BundleEntryComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)4 Coding (org.hl7.fhir.dstu3.model.Coding)4 Bundle (org.hl7.fhir.r4.model.Bundle)4 CodeType (org.hl7.fhir.r4.model.CodeType)4