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()));
}
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;
}
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."));
}
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;
}
Aggregations