Search in sources :

Example 16 with Endpoint

use of org.hl7.fhir.r4.model.Endpoint in project cqf-ruler by DBCG.

the class CacheValueSetsProviderIT method testCacheValueSetsEndpointNull.

@Test
public void testCacheValueSetsEndpointNull() throws Exception {
    StringAndListParam stringAndListParam = getStringAndListParamFromValueSet("valueset/AcuteInpatient.json");
    RequestDetails details = Mockito.mock(RequestDetails.class);
    Resource outcomeResource = cacheValueSetsProvider.cacheValuesets(details, new Endpoint().getIdElement(), stringAndListParam, null, null);
    validateOutcome(outcomeResource, "Could not find Endpoint/null");
}
Also used : Endpoint(org.hl7.fhir.r4.model.Endpoint) StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) Resource(org.hl7.fhir.r4.model.Resource) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 17 with Endpoint

use of org.hl7.fhir.r4.model.Endpoint in project cqf-ruler by DBCG.

the class CacheValueSetsProviderIT method testCacheValueSetsAlreadyExpanded.

// Get help with this....
// @Test
// public void testCacheValueSetsExpandAndAddConcepts() throws Exception {
// Endpoint endpoint = uploadLocalServerEndpoint();
// RequestDetails details = Mockito.mock(RequestDetails.class);
// ValueSet vs = uploadValueSet("valueset/valueset-buprenorphine-and-methadone-medications.json");
// vs.getCompose().getInclude().forEach(include -> {
// assertTrue(!include.hasConcept());
// });
// StringAndListParam stringAndListParam = getStringAndListParamFromValueSet(vs);
// IGenericClient localClient = createClient(ourCtx, endpoint);
// // localClient.operation().onServer().named("updateCodeSystems").withNoParameters(Parameters.class).execute();
// Resource outcomeResource = cacheValueSetsProvider.cacheValuesets(details, endpoint.getIdElement(), stringAndListParam, null, null);
// assertTrue(outcomeResource instanceof Bundle);
// Bundle resultBundle = (Bundle) outcomeResource;
// assertTrue(resultBundle.getEntry().size() == 1);
// BundleEntryComponent entry = resultBundle.getEntry().get(0);
// assertTrue(entry.getResponse().getLocation().startsWith("ValueSet/" + vs.getIdElement().getIdPart()));
// assertTrue(entry.getResponse().getStatus().equals("200 OK"));
// ValueSet resultingValueSet = localClient.read().resource(ValueSet.class).withId(vs.getIdElement()).execute();
// resultingValueSet.getCompose().getInclude().forEach(include -> {
// assertTrue(include.hasConcept());
// });
// }
@Test
public void testCacheValueSetsAlreadyExpanded() throws Exception {
    Endpoint endpoint = uploadLocalServerEndpoint();
    RequestDetails details = Mockito.mock(RequestDetails.class);
    ValueSet vs = uploadValueSet("valueset/valueset-benzodiazepine-medications.json");
    StringAndListParam stringAndListParam = getStringAndListParamFromValueSet(vs);
    Resource outcomeResource = cacheValueSetsProvider.cacheValuesets(details, endpoint.getIdElement(), stringAndListParam, null, null);
    assertTrue(outcomeResource instanceof Bundle);
    Bundle resultBundle = (Bundle) outcomeResource;
    assertEquals(1, resultBundle.getEntry().size());
    BundleEntryComponent entry = resultBundle.getEntry().get(0);
    assertTrue(entry.getResponse().getLocation().startsWith("ValueSet/" + vs.getIdElement().getIdPart()));
    assertEquals("200 OK", entry.getResponse().getStatus());
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Endpoint(org.hl7.fhir.r4.model.Endpoint) StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) ValueSet(org.hl7.fhir.r4.model.ValueSet) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 18 with Endpoint

use of org.hl7.fhir.r4.model.Endpoint in project himss_2021_sepsis_detection by redhat-na-ssa.

the class GetObservationsSignalEventCommand method getTimeBoxedObservation.

private List<Observation> getTimeBoxedObservation(Patient patient) {
    List<Observation> obsList = new ArrayList<>();
    Calendar instance = Calendar.getInstance();
    instance.add(Calendar.DATE, -1);
    Date timeBoxDate = instance.getTime();
    String patientID = patient.getId();
    String url = fhirURL + "/fhir/Observation?patient=" + patientID + "&_pretty=true";
    log.info("getTimeBoxedObservation() fhirUrl endpoint = " + url);
    String bundleStr = template.getForEntity(url, String.class).getBody();
    Bundle newBundle = fhirCtx.newJsonParser().parseResource(Bundle.class, bundleStr);
    for (BundleEntryComponent component : newBundle.getEntry()) {
        if (component.getResource() instanceof Observation) {
            Observation obs = (Observation) component.getResource();
            if (// Adding Observation only if its 24 hrs
            obs.getMeta().getLastUpdatedElement().after(timeBoxDate))
                obsList.add(obs);
        }
    }
    log.info("getTimedBoxedObservation() Patient Id : " + patientID + " # of Observations = " + obsList.size());
    return obsList;
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) Calendar(java.util.Calendar) Observation(org.hl7.fhir.r4.model.Observation) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 19 with Endpoint

use of org.hl7.fhir.r4.model.Endpoint in project Gravity-SDOH-Exchange-RI by FHIR.

the class TaskPollingService method updateTasks.

public void updateTasks() {
    log.info("Updating tasks from CP Organizations...");
    Bundle tasksBundle = openEhrClient.search().forResource(Task.class).include(Task.INCLUDE_FOCUS).include(Task.INCLUDE_OWNER).include(Organization.INCLUDE_ENDPOINT.setRecurse(true)).where(new TokenClientParam("owner:Organization.type").exactly().systemAndCode(OrganizationTypeCode.CP.getSystem(), OrganizationTypeCode.CP.toCode())).where(new TokenClientParam(Task.SP_STATUS + ":" + SearchModifierCode.NOT.toCode()).exactly().code(Task.TaskStatus.FAILED.toCode())).where(new TokenClientParam(Task.SP_STATUS + ":" + SearchModifierCode.NOT.toCode()).exactly().code(Task.TaskStatus.REJECTED.toCode())).where(new TokenClientParam(Task.SP_STATUS + ":" + SearchModifierCode.NOT.toCode()).exactly().code(Task.TaskStatus.COMPLETED.toCode())).where(new TokenClientParam(Task.SP_STATUS + ":" + SearchModifierCode.NOT.toCode()).exactly().code(Task.TaskStatus.CANCELLED.toCode())).where(Task.AUTHORED_ON.before().millis(Date.from(LocalDateTime.now().minusSeconds(10).atZone(ZoneId.systemDefault()).toInstant()))).returnBundle(Bundle.class).execute();
    TasksPollingInfo tasksPollingInfo = new TasksPollingBundleExtractor().extract(tasksBundle);
    // Collect all entries from every Task bundle for performance considerations.
    Bundle updateBundle = new Bundle();
    updateBundle.setType(Bundle.BundleType.TRANSACTION);
    for (Task task : tasksPollingInfo.getTasks()) {
        ServiceRequest serviceRequest = tasksPollingInfo.getServiceRequest(task);
        Organization organization = tasksPollingInfo.getOrganization(task);
        try {
            Endpoint endpoint = tasksPollingInfo.getEndpoint(organization);
            combineResult(updateBundle, getUpdateBundle(task, serviceRequest, endpoint));
        } catch (TaskPollingUpdateException | CpClientException exc) {
            combineResult(updateBundle, failTask(task, serviceRequest, exc.getMessage()));
        }
    }
    // If there is at least one bundle entry - execute a transaction request.
    if (updateBundle.getEntry().size() != 0) {
        log.info("One or more tasks were changed. Storing updates to EHR...");
        openEhrClient.transaction().withBundle(updateBundle).execute();
    }
    log.info("Task update process finished.");
}
Also used : Task(org.hl7.fhir.r4.model.Task) TasksPollingInfo(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor.TasksPollingInfo) TasksPollingBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor) CpClientException(org.hl7.gravity.refimpl.sdohexchange.service.CpService.CpClientException) Organization(org.hl7.fhir.r4.model.Organization) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) Endpoint(org.hl7.fhir.r4.model.Endpoint) Bundle(org.hl7.fhir.r4.model.Bundle) TaskPollingUpdateException(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor.TaskPollingUpdateException) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest)

Example 20 with Endpoint

use of org.hl7.fhir.r4.model.Endpoint in project Gravity-SDOH-Exchange-RI by FHIR.

the class TaskPollingService method copyTaskFields.

protected void copyTaskFields(Task ehrTask, Task cpTask, Endpoint endpoint) {
    ehrTask.setStatus(cpTask.getStatus());
    ehrTask.setStatusReason(cpTask.getStatusReason());
    ehrTask.setLastModified(cpTask.getLastModified());
    int ehrNotesSize = ehrTask.getNote().size();
    int cpNotesSize = cpTask.getNote().size();
    if (ehrNotesSize < cpNotesSize) {
        cpTask.getNote().subList(ehrNotesSize, cpNotesSize).stream().filter(cpComment -> cpComment.getAuthor() instanceof Reference).forEach(cpComment -> {
            cpService.externalizeReference(cpComment.getAuthorReference(), endpoint.getAddress());
            ehrTask.addNote(cpComment);
        });
    }
}
Also used : Date(java.util.Date) TaskOutputComponent(org.hl7.fhir.r4.model.Task.TaskOutputComponent) Constants(ca.uhn.fhir.rest.api.Constants) RequiredArgsConstructor(lombok.RequiredArgsConstructor) LocalDateTime(java.time.LocalDateTime) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Autowired(org.springframework.beans.factory.annotation.Autowired) Endpoint(org.hl7.fhir.r4.model.Endpoint) Scheduled(org.springframework.scheduling.annotation.Scheduled) Reference(org.hl7.fhir.r4.model.Reference) TaskStatus(org.hl7.fhir.r4.model.Task.TaskStatus) Function(java.util.function.Function) ArrayList(java.util.ArrayList) JSONParser(net.minidev.json.parser.JSONParser) TasksPollingInfo(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor.TasksPollingInfo) Procedure(org.hl7.fhir.r4.model.Procedure) Task(org.hl7.fhir.r4.model.Task) FhirContext(ca.uhn.fhir.context.FhirContext) TaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) StringClientParam(ca.uhn.fhir.rest.gclient.StringClientParam) SearchModifierCode(org.hl7.fhir.r4.model.codesystems.SearchModifierCode) Observation(org.hl7.fhir.r4.model.Observation) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) SDOHProfiles(org.hl7.gravity.refimpl.sdohexchange.fhir.SDOHProfiles) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) Set(java.util.Set) TaskFailBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskFailBundleFactory) CpClientException(org.hl7.gravity.refimpl.sdohexchange.service.CpService.CpClientException) Collectors(java.util.stream.Collectors) IdType(org.hl7.fhir.r4.model.IdType) ZoneId(java.time.ZoneId) Organization(org.hl7.fhir.r4.model.Organization) Slf4j(lombok.extern.slf4j.Slf4j) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) TaskPollingUpdateException(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor.TaskPollingUpdateException) List(java.util.List) TasksPollingBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor) JSONObject(net.minidev.json.JSONObject) Bundle(org.hl7.fhir.r4.model.Bundle) OrganizationTypeCode(org.hl7.gravity.refimpl.sdohexchange.codes.OrganizationTypeCode) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) Reference(org.hl7.fhir.r4.model.Reference) Endpoint(org.hl7.fhir.r4.model.Endpoint)

Aggregations

Test (org.junit.jupiter.api.Test)26 RequestDetails (ca.uhn.fhir.rest.api.server.RequestDetails)18 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)16 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)16 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 Endpoint (org.hl7.fhir.r4.model.Endpoint)15 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)14 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)14 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)12 Bundle (org.hl7.fhir.r4.model.Bundle)12 Endpoint (org.hl7.fhir.dstu3.model.Endpoint)11 Resource (org.hl7.fhir.r4.model.Resource)10 Resource (org.hl7.fhir.dstu3.model.Resource)9 Operation (ca.uhn.fhir.rest.annotation.Operation)7 Description (ca.uhn.fhir.model.api.annotation.Description)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 HashMap (java.util.HashMap)5 Task (org.hl7.fhir.r4.model.Task)5 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)4