Search in sources :

Example 21 with FINAL

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

the class CpService method create.

public void create(final Task ehrTask, final Endpoint endpoint) throws CpClientException {
    Task cpTask = externalizeResource(ehrTask.copy(), identifierSystem);
    // TODO: Remove this after Logica bug response
    cpTask.setMeta(null);
    cpTask.addIdentifier().setSystem(identifierSystem).setValue(ehrTask.getIdElement().getIdPart());
    try {
        cpClient(endpoint).create().resource(cpTask).execute();
    } catch (BaseServerResponseException exc) {
        throw new CpClientException(String.format("Could not create a Task with identifier '%s' in CP at '%s'. Reason: %s.", identifierSystem + "|" + ehrTask.getIdElement().getIdPart(), endpoint.getAddress(), exc.getMessage()), exc);
    }
}
Also used : Task(org.hl7.fhir.r4.model.Task) BaseServerResponseException(ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException)

Example 22 with FINAL

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

the class CpService method read.

public TaskInfoHolder read(final String id, final Endpoint endpoint) throws CpClientException {
    try {
        Bundle taskBundle = cpClient(endpoint).search().forResource(Task.class).where(Task.IDENTIFIER.exactly().systemAndValues(identifierSystem, id)).include(Task.INCLUDE_FOCUS).returnBundle(Bundle.class).execute();
        // Additional validation
        int tasksSize = FhirUtil.getFromBundle(taskBundle, Task.class).size();
        if (tasksSize == 0) {
            throw new CpClientException(String.format("No Task is present at '%s' for identifier '%s'.", endpoint.getAddress(), identifierSystem + "|" + id));
        } else if (tasksSize > 1) {
            throw new CpClientException(String.format("More than one Task is present at '%s' for identifier '%s'.", endpoint.getAddress(), identifierSystem + "|" + id));
        }
        return new TaskInfoBundleExtractor().extract(taskBundle).stream().findFirst().get();
    } catch (BaseServerResponseException exc) {
        throw new CpClientException(String.format("Task retrieval failed for identifier '%s' at CP location '%s'. Reason: %s.", identifierSystem + "|" + id, endpoint.getAddress(), exc.getMessage()), exc);
    }
}
Also used : Task(org.hl7.fhir.r4.model.Task) Bundle(org.hl7.fhir.r4.model.Bundle) TaskInfoBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor) BaseServerResponseException(ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException) Endpoint(org.hl7.fhir.r4.model.Endpoint)

Example 23 with FINAL

use of org.hl7.fhir.r4.model.Observation.ObservationStatus.FINAL in project drug-formulary-ri by HL7-DaVinci.

the class ExampleServerDstu3IT method testWebsocketSubscription.

@Test
public void testWebsocketSubscription() throws Exception {
    /*
		 * Create subscription
		 */
    Subscription subscription = new Subscription();
    subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
    subscription.setStatus(Subscription.SubscriptionStatus.REQUESTED);
    subscription.setCriteria("Observation?status=final");
    Subscription.SubscriptionChannelComponent channel = new Subscription.SubscriptionChannelComponent();
    channel.setType(Subscription.SubscriptionChannelType.WEBSOCKET);
    channel.setPayload("application/json");
    subscription.setChannel(channel);
    MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
    IIdType mySubscriptionId = methodOutcome.getId();
    // Wait for the subscription to be activated
    waitForSize(1, () -> ourClient.search().forResource(Subscription.class).where(Subscription.STATUS.exactly().code("active")).cacheControl(new CacheControlDirective().setNoCache(true)).returnBundle(Bundle.class).execute().getEntry().size());
    /*
		 * Attach websocket
		 */
    WebSocketClient myWebSocketClient = new WebSocketClient();
    SocketImplementation mySocketImplementation = new SocketImplementation(mySubscriptionId.getIdPart(), EncodingEnum.JSON);
    myWebSocketClient.start();
    URI echoUri = new URI("ws://localhost:" + ourPort + "/hapi-fhir-jpaserver/websocket");
    ClientUpgradeRequest request = new ClientUpgradeRequest();
    ourLog.info("Connecting to : {}", echoUri);
    Future<Session> connection = myWebSocketClient.connect(mySocketImplementation, echoUri, request);
    Session session = connection.get(2, TimeUnit.SECONDS);
    ourLog.info("Connected to WS: {}", session.isOpen());
    /*
		 * Create a matching resource
		 */
    Observation obs = new Observation();
    obs.setStatus(Observation.ObservationStatus.FINAL);
    ourClient.create().resource(obs).execute();
    // Give some time for the subscription to deliver
    Thread.sleep(2000);
    /*
		 * Ensure that we receive a ping on the websocket
		 */
    waitForSize(1, () -> mySocketImplementation.myPingCount);
    /*
		 * Clean up
		 */
    ourClient.delete().resourceById(mySubscriptionId).execute();
}
Also used : CacheControlDirective(ca.uhn.fhir.rest.api.CacheControlDirective) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) URI(java.net.URI) Observation(org.hl7.fhir.dstu3.model.Observation) ClientUpgradeRequest(org.eclipse.jetty.websocket.client.ClientUpgradeRequest) Subscription(org.hl7.fhir.dstu3.model.Subscription) IIdType(org.hl7.fhir.instance.model.api.IIdType) Session(org.eclipse.jetty.websocket.api.Session) Test(org.junit.Test)

Example 24 with FINAL

use of org.hl7.fhir.r4.model.Observation.ObservationStatus.FINAL in project ab2d by CMSgov.

the class JobProcessorIntegrationTest method when_beneHasNoEobs_notCounted.

@Test
@DisplayName("When bene has no eobs then do not count bene toward statistic")
void when_beneHasNoEobs_notCounted() {
    reset(mockBfdClient);
    OngoingStubbing<IBaseBundle> stubbing = when(mockBfdClient.requestEOBFromServer(eq(STU3), anyLong(), any()));
    stubbing = andThenAnswerEobs(stubbing, 0, 95);
    stubbing.thenReturn(BundleUtils.createBundle()).thenReturn(BundleUtils.createBundle()).thenReturn(BundleUtils.createBundle()).thenReturn(BundleUtils.createBundle()).thenReturn(BundleUtils.createBundle());
    var processedJob = cut.process(job.getJobUuid());
    assertEquals(JobStatus.SUCCESSFUL, processedJob.getStatus());
    assertEquals(COMPLETED_PERCENT, processedJob.getStatusMessage());
    assertNotNull(processedJob.getExpiresAt());
    assertNotNull(processedJob.getCompletedAt());
    List<LoggableEvent> beneSearchEvents = loggerEventRepository.load(ContractSearchEvent.class);
    assertEquals(1, beneSearchEvents.size());
    ContractSearchEvent event = (ContractSearchEvent) beneSearchEvents.get(0);
    assertEquals(JOB_UUID, event.getJobId());
    assertEquals(100, event.getBenesExpected());
    assertEquals(100, event.getBenesSearched());
    assertEquals(CONTRACT_NAME, event.getContractNumber());
    assertEquals(95, event.getBenesWithEobs());
    final List<JobOutput> jobOutputs = processedJob.getJobOutputs();
    assertFalse(jobOutputs.isEmpty());
}
Also used : LoggableEvent(gov.cms.ab2d.eventlogger.LoggableEvent) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) JobOutput(gov.cms.ab2d.common.model.JobOutput) ContractSearchEvent(gov.cms.ab2d.eventlogger.events.ContractSearchEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringIntegrationTest(org.springframework.integration.test.context.SpringIntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 25 with FINAL

use of org.hl7.fhir.r4.model.Observation.ObservationStatus.FINAL in project ab2d by CMSgov.

the class PatientClaimsProcessorUnitTest method process_whenPatientHasDataWithBadLastUpdated.

@Test
void process_whenPatientHasDataWithBadLastUpdated() throws ExecutionException, InterruptedException {
    ExplanationOfBenefit firstEob = eob.copy();
    eob.getMeta().setLastUpdated(null);
    org.hl7.fhir.dstu3.model.Bundle bundle1 = EobTestDataUtil.createBundle(eob.copy());
    ExplanationOfBenefit eob2 = eob.copy();
    // now set the last updated date to a time before the since date (which is attribution date here)
    eob2.getMeta().setLastUpdated(new Date(LATER_ATT_DATE.toInstant().toEpochMilli() - 1000));
    final org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent bundleEntryComponent = new org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent();
    bundleEntryComponent.setResource(eob2);
    bundle1.addEntry(bundleEntryComponent);
    ExplanationOfBenefit eob3 = eob.copy();
    eob2.getMeta().setLastUpdated(new Date());
    final org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent bundleEntryComponent3 = new org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent();
    bundleEntryComponent3.setResource(eob3);
    bundle1.addEntry(bundleEntryComponent3);
    assertEquals(3, bundle1.getEntry().size());
    PatientClaimsRequest request2 = new PatientClaimsRequest(List.of(coverageSummary), LATER_ATT_DATE, LATER_ATT_DATE, "client", "job", "contractNum", Contract.ContractType.NORMAL, noOpToken, STU3, tmpEfsMountDir.getAbsolutePath());
    when(mockBfdClient.requestEOBFromServer(STU3, patientId, request2.getAttTime())).thenReturn(bundle1);
    cut.process(request2).get();
}
Also used : ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)229 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)85 HashMap (java.util.HashMap)83 CamelSpringBootTest (org.apache.camel.test.spring.junit5.CamelSpringBootTest)59 List (java.util.List)53 Bundle (org.hl7.fhir.dstu3.model.Bundle)50 Nonnull (javax.annotation.Nonnull)48 Patient (org.hl7.fhir.dstu3.model.Patient)46 Organization (org.hl7.fhir.dstu3.model.Organization)45 ArrayList (java.util.ArrayList)44 Bundle (org.hl7.fhir.r4.model.Bundle)41 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)39 UUID (java.util.UUID)38 Collectors (java.util.stream.Collectors)38 Coding (org.hl7.fhir.r4.model.Coding)34 FhirContext (ca.uhn.fhir.context.FhirContext)33 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)32 IParser (ca.uhn.fhir.parser.IParser)31 IOException (java.io.IOException)29 IdType (org.hl7.fhir.dstu3.model.IdType)28