Search in sources :

Example 1 with OrderSignRequest

use of org.hl7.davinci.r4.crdhook.ordersign.OrderSignRequest in project CRD by HL7-DaVinci.

the class OrderSignRequestTest method testReadingJson.

@Test
public void testReadingJson() throws IOException, FHIRException {
    InputStream requestStream = this.getClass().getResourceAsStream("requestWithHydratedPrefetchBundle.json");
    ObjectMapper mapper = new ObjectMapper();
    OrderSignRequest request = mapper.readValue(requestStream, OrderSignRequest.class);
    assertNotNull(request);
    assertEquals("1288992", request.getContext().getPatientId());
    Bundle deviceRequestBundle = request.getPrefetch().getDeviceRequestBundle();
    List<DeviceRequest> deviceRequestList = Utilities.getResourcesOfTypeFromBundle(DeviceRequest.class, deviceRequestBundle);
    DeviceRequest deviceRequest = deviceRequestList.get(0);
    Patient patient = (Patient) deviceRequest.getSubject().getResource();
    assertNotNull(deviceRequest);
    assertEquals("E0424", deviceRequest.getCodeCodeableConcept().getCoding().get(0).getCode());
    assertEquals("male", (patient.getGender().toCode()));
}
Also used : InputStream(java.io.InputStream) Bundle(org.hl7.fhir.r4.model.Bundle) Patient(org.hl7.fhir.r4.model.Patient) DeviceRequest(org.hl7.fhir.r4.model.DeviceRequest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 2 with OrderSignRequest

use of org.hl7.davinci.r4.crdhook.ordersign.OrderSignRequest in project CRD by HL7-DaVinci.

the class CrdRequestCreator method createOrderSignRequest.

/**
 * Generate a order sign request that contains a ServiceRequest.
 *
 * @param patientGender Desired gender of the patient in the request
 * @param patientBirthdate Desired birth date of the patient in the request
 * @return Fully populated CdsRequest
 */
public static OrderSignRequest createOrderSignRequest(Enumerations.AdministrativeGender patientGender, Date patientBirthdate, String patientAddressState, String providerAddressState) {
    OrderSignRequest request = new OrderSignRequest();
    request.setHook(Hook.ORDER_SIGN);
    request.setHookInstance(UUID.randomUUID().toString());
    OrderSignContext context = new OrderSignContext();
    request.setContext(context);
    context.setUserId("Practitioner/1234");
    Patient patient = createPatient(patientGender, patientBirthdate, patientAddressState);
    context.setPatientId(patient.getId());
    ServiceRequest sr = new ServiceRequest();
    sr.setStatus(ServiceRequest.ServiceRequestStatus.DRAFT);
    sr.setId("DeviceRequest/123");
    sr.setIntent(ServiceRequest.ServiceRequestIntent.ORDER);
    PrefetchCallback callback = (p, c) -> {
        sr.addPerformer(new Reference(p));
        sr.addInsurance(new Reference(c));
    };
    sr.setSubject(new Reference(patient));
    Practitioner provider = createPractitioner();
    Bundle prefetchBundle = createPrefetchBundle(patient, provider, callback, providerAddressState);
    Coding oxygen = new Coding().setCode("A0426").setSystem("https://bluebutton.cms.gov/resources/codesystem/hcpcs").setDisplay("Ambulance service, advanced life support, non-emergency transport, level 1 (als 1)");
    sr.setCode(new CodeableConcept().addCoding(oxygen).setText("Ambulance service Non-Emergency Transport"));
    Bundle orderBundle = new Bundle();
    Bundle.BundleEntryComponent bec = new Bundle.BundleEntryComponent();
    bec.setResource(sr);
    orderBundle.addEntry(bec);
    Bundle.BundleEntryComponent pfDrBec = new Bundle.BundleEntryComponent();
    pfDrBec.setResource(sr);
    prefetchBundle.addEntry(pfDrBec);
    context.setDraftOrders(orderBundle);
    Device device = new Device();
    device.setType(new CodeableConcept().addCoding(oxygen));
    bec = new Bundle.BundleEntryComponent();
    bec.setResource(device);
    prefetchBundle.addEntry(bec);
    CrdPrefetch prefetch = new CrdPrefetch();
    prefetch.setServiceRequestBundle(prefetchBundle);
    request.setPrefetch(prefetch);
    return request;
}
Also used : CrdPrefetch(org.hl7.davinci.r4.crdhook.CrdPrefetch) Logger(org.slf4j.Logger) OrderSignContext(org.hl7.davinci.r4.crdhook.ordersign.OrderSignContext) Date(java.util.Date) org.hl7.fhir.r4.model(org.hl7.fhir.r4.model) LoggerFactory(org.slf4j.LoggerFactory) UUID(java.util.UUID) OrderSignRequest(org.hl7.davinci.r4.crdhook.ordersign.OrderSignRequest) OrderSelectContext(org.hl7.davinci.r4.crdhook.orderselect.OrderSelectContext) AddressUse(org.hl7.fhir.r4.model.Address.AddressUse) ArrayList(java.util.ArrayList) List(java.util.List) OrderSelectRequest(org.hl7.davinci.r4.crdhook.orderselect.OrderSelectRequest) Hook(org.cdshooks.Hook) AddressType(org.hl7.fhir.r4.model.Address.AddressType) OrderSignContext(org.hl7.davinci.r4.crdhook.ordersign.OrderSignContext) CrdPrefetch(org.hl7.davinci.r4.crdhook.CrdPrefetch) OrderSignRequest(org.hl7.davinci.r4.crdhook.ordersign.OrderSignRequest)

Example 3 with OrderSignRequest

use of org.hl7.davinci.r4.crdhook.ordersign.OrderSignRequest in project CRD by HL7-DaVinci.

the class OrderSignServiceTest method testHandleRequest.

@Test
public void testHandleRequest() {
    URL applicationBase;
    try {
        applicationBase = new URL("http", "localhost", "/");
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
    Calendar cal = Calendar.getInstance();
    cal.set(1970, Calendar.JULY, 4);
    OrderSignRequest request = CrdRequestCreator.createOrderSignRequest(Enumerations.AdministrativeGender.MALE, cal.getTime(), "MA", "MA");
    CdsResponse response = service.handleRequest(request, applicationBase);
    assertNotNull(response);
    assertEquals(1, response.getCards().size());
    String summary = response.getCards().get(0).getSummary();
    assertTrue(summary.endsWith("Prior Authorization required."));
}
Also used : MalformedURLException(java.net.MalformedURLException) Calendar(java.util.Calendar) CdsResponse(org.cdshooks.CdsResponse) OrderSignRequest(org.hl7.davinci.r4.crdhook.ordersign.OrderSignRequest) URL(java.net.URL) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with OrderSignRequest

use of org.hl7.davinci.r4.crdhook.ordersign.OrderSignRequest in project CRD by HL7-DaVinci.

the class OrderSignService method createCqlExecutionContexts.

@Override
public List<CoverageRequirementRuleResult> createCqlExecutionContexts(OrderSignRequest orderSignRequest, FileStore fileStore, String baseUrl) {
    FhirBundleProcessor fhirBundleProcessor = new FhirBundleProcessor(fileStore, baseUrl);
    CrdPrefetch prefetch = orderSignRequest.getPrefetch();
    fhirBundleProcessor.processDeviceRequests(prefetch.getDeviceRequestBundle());
    fhirBundleProcessor.processMedicationRequests(prefetch.getMedicationRequestBundle());
    fhirBundleProcessor.processServiceRequests(prefetch.getServiceRequestBundle());
    fhirBundleProcessor.processMedicationDispenses(prefetch.getMedicationDispenseBundle());
    List<CoverageRequirementRuleResult> results = fhirBundleProcessor.getResults();
    if (results.isEmpty()) {
        throw RequestIncompleteException.NoSupportedBundlesFound();
    }
    return results;
}
Also used : CrdPrefetch(org.hl7.davinci.r4.crdhook.CrdPrefetch) CoverageRequirementRuleResult(org.hl7.davinci.endpoint.rules.CoverageRequirementRuleResult)

Aggregations

CrdPrefetch (org.hl7.davinci.r4.crdhook.CrdPrefetch)2 OrderSignRequest (org.hl7.davinci.r4.crdhook.ordersign.OrderSignRequest)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 List (java.util.List)1 UUID (java.util.UUID)1 CdsResponse (org.cdshooks.CdsResponse)1 Hook (org.cdshooks.Hook)1 CoverageRequirementRuleResult (org.hl7.davinci.endpoint.rules.CoverageRequirementRuleResult)1 OrderSelectContext (org.hl7.davinci.r4.crdhook.orderselect.OrderSelectContext)1 OrderSelectRequest (org.hl7.davinci.r4.crdhook.orderselect.OrderSelectRequest)1 OrderSignContext (org.hl7.davinci.r4.crdhook.ordersign.OrderSignContext)1 org.hl7.fhir.r4.model (org.hl7.fhir.r4.model)1 AddressType (org.hl7.fhir.r4.model.Address.AddressType)1 AddressUse (org.hl7.fhir.r4.model.Address.AddressUse)1