use of org.hl7.fhir.r4b.model.PlanDefinition in project cqf-ruler by DBCG.
the class CdsHooksServletIT method testCdsServicesRequest.
@Test
public // TODO: Add Opioid Tests once $apply-cql is implemented.
void testCdsServicesRequest() throws IOException {
// Server Load
loadTransaction("HelloWorldPatientView-bundle.json");
loadResource("hello-world-patient-view-patient.json");
Patient ourPatient = getClient().read().resource(Patient.class).withId("patient-hello-world-patient-view").execute();
assertNotNull(ourPatient);
assertEquals("patient-hello-world-patient-view", ourPatient.getIdElement().getIdPart());
PlanDefinition ourPlanDefinition = getClient().read().resource(PlanDefinition.class).withId("hello-world-patient-view").execute();
assertNotNull(ourPlanDefinition);
Bundle getPlanDefinitions = null;
int tries = 0;
do {
// Can take up to 10 seconds for HAPI to reindex searches
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
tries++;
getPlanDefinitions = getClient().search().forResource(PlanDefinition.class).returnBundle(Bundle.class).execute();
} while (getPlanDefinitions.getEntry().size() == 0 && tries < 15);
assertTrue(getPlanDefinitions.hasEntry());
// Update fhirServer Base
String jsonHooksRequest = stringFromResource("request-HelloWorld.json");
Gson gsonRequest = new Gson();
JsonObject jsonRequestObject = gsonRequest.fromJson(jsonHooksRequest, JsonObject.class);
jsonRequestObject.addProperty("fhirServer", getServerBase());
// Setup Client
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost request = new HttpPost(ourCdsBase + "/hello-world-patient-view");
request.setEntity(new StringEntity(jsonRequestObject.toString()));
request.addHeader("Content-Type", "application/json");
CloseableHttpResponse response = httpClient.execute(request);
String result = EntityUtils.toString(response.getEntity());
Gson gsonResponse = new Gson();
JsonObject jsonResponseObject = gsonResponse.fromJson(result, JsonObject.class);
// Ensure Cards
assertNotNull(jsonResponseObject.get("cards"));
JsonArray cards = jsonResponseObject.get("cards").getAsJsonArray();
// Ensure Patient Detail
assertNotNull(cards.get(0).getAsJsonObject().get("detail"));
String patientName = cards.get(0).getAsJsonObject().get("detail").getAsString();
assertEquals("The CDS Service is alive and communicating successfully!", patientName);
// Ensure Summary
assertNotNull(cards.get(0));
assertNotNull(cards.get(0).getAsJsonObject().get("summary"));
String summary = cards.get(0).getAsJsonObject().get("summary").getAsString();
assertEquals("Hello World!", summary);
// Ensure Activity Definition / Suggestions
assertNotNull(cards.get(0).getAsJsonObject().get("suggestions"));
JsonArray suggestions = cards.get(0).getAsJsonObject().get("suggestions").getAsJsonArray();
assertNotNull(suggestions.get(0));
assertNotNull(suggestions.get(0).getAsJsonObject().get("actions"));
JsonArray actions = suggestions.get(0).getAsJsonObject().get("actions").getAsJsonArray();
assertNotNull(actions.get(0));
assertNotNull(actions.get(0).getAsJsonObject().get("description"));
String suggestionsDescription = actions.get(0).getAsJsonObject().get("description").getAsString();
assertEquals("The CDS Service is alive and communicating successfully!", suggestionsDescription);
}
use of org.hl7.fhir.r4b.model.PlanDefinition in project cqf-ruler by DBCG.
the class CdsHooksServletIT method testCdsServicesRequest.
@Test
public // TODO: Debug delay in Client.search().
void testCdsServicesRequest() throws IOException {
// Server Load
loadTransaction("Screening-bundle-r4.json");
Patient ourPatient = getClient().read().resource(Patient.class).withId("HighRiskIDUPatient").execute();
assertNotNull(ourPatient);
assertEquals("HighRiskIDUPatient", ourPatient.getIdElement().getIdPart());
PlanDefinition ourPlanDefinition = getClient().read().resource(PlanDefinition.class).withId("plandefinition-Screening").execute();
assertNotNull(ourPlanDefinition);
Bundle getPlanDefinitions = null;
int tries = 0;
do {
// Can take up to 10 seconds for HAPI to reindex searches
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
tries++;
getPlanDefinitions = getClient().search().forResource(PlanDefinition.class).returnBundle(Bundle.class).execute();
} while (getPlanDefinitions.getEntry().size() == 0 && tries < 15);
assertTrue(getPlanDefinitions.hasEntry());
// Update fhirServer Base
String jsonHooksRequest = stringFromResource("request-HighRiskIDUPatient.json");
Gson gsonRequest = new Gson();
JsonObject jsonRequestObject = gsonRequest.fromJson(jsonHooksRequest, JsonObject.class);
jsonRequestObject.addProperty("fhirServer", getServerBase());
// Setup Client
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost request = new HttpPost(ourCdsBase + "/plandefinition-Screening");
request.setEntity(new StringEntity(jsonRequestObject.toString()));
request.addHeader("Content-Type", "application/json");
CloseableHttpResponse response = httpClient.execute(request);
String result = EntityUtils.toString(response.getEntity());
Gson gsonResponse = new Gson();
JsonObject jsonResponseObject = gsonResponse.fromJson(result, JsonObject.class);
// Ensure Cards
assertNotNull(jsonResponseObject.get("cards"));
JsonArray cards = jsonResponseObject.get("cards").getAsJsonArray();
// Ensure Patient Detail
assertNotNull(cards.get(0).getAsJsonObject().get("detail"));
String patientName = cards.get(0).getAsJsonObject().get("detail").getAsString();
assertEquals("Ashley Madelyn", patientName);
// Ensure Summary
assertNotNull(cards.get(1));
assertNotNull(cards.get(1).getAsJsonObject().get("summary"));
String recommendation = cards.get(1).getAsJsonObject().get("summary").getAsString();
assertEquals("HIV Screening Recommended due to patient being at High Risk for HIV and over three months have passed since previous screening.", recommendation);
// Ensure Activity Definition / Suggestions
assertNotNull(cards.get(1).getAsJsonObject().get("suggestions"));
JsonArray suggestions = cards.get(1).getAsJsonObject().get("suggestions").getAsJsonArray();
assertNotNull(suggestions.get(0));
assertNotNull(suggestions.get(0).getAsJsonObject().get("actions"));
JsonArray actions = suggestions.get(0).getAsJsonObject().get("actions").getAsJsonArray();
assertNotNull(actions.get(0));
assertNotNull(actions.get(0).getAsJsonObject().get("resource"));
JsonObject suggestionsActivityResource = actions.get(0).getAsJsonObject().get("resource").getAsJsonObject();
assertNotNull(suggestionsActivityResource.get("resourceType"));
assertEquals("ServiceRequest", suggestionsActivityResource.get("resourceType").getAsString());
assertNotNull(suggestionsActivityResource.get("subject"));
String expectedPatientID = ourPatient.getIdElement().getIdPart();
String actualPatientID = suggestionsActivityResource.get("subject").getAsJsonObject().get("reference").getAsString();
assertEquals("Patient/" + expectedPatientID, actualPatientID);
}
use of org.hl7.fhir.r4b.model.PlanDefinition in project cqf-ruler by DBCG.
the class DiscoveryResolutionR4 method getPrefetchUrlList.
public PrefetchUrlList getPrefetchUrlList(PlanDefinition planDefinition) {
PrefetchUrlList prefetchList = new PrefetchUrlList();
if (planDefinition == null)
return null;
if (!isEca(planDefinition))
return null;
Library library = resolvePrimaryLibrary(planDefinition);
// TODO: resolve data requirements
if (library == null || !library.hasDataRequirement())
return null;
for (DataRequirement dataRequirement : library.getDataRequirement()) {
List<String> requestUrls = createRequestUrl(dataRequirement);
if (requestUrls != null) {
prefetchList.addAll(requestUrls);
}
}
return prefetchList;
}
use of org.hl7.fhir.r4b.model.PlanDefinition in project cqf-ruler by DBCG.
the class DiscoveryResolutionR4 method resolve.
public DiscoveryResponse resolve() {
List<PlanDefinition> planDefinitions = search(PlanDefinition.class, Searches.all()).getAllResourcesTyped();
DiscoveryResponse response = new DiscoveryResponse();
for (PlanDefinition resource : planDefinitions) {
response.addElement(new DiscoveryElementR4(resource, getPrefetchUrlList(resource)));
}
return response;
}
use of org.hl7.fhir.r4b.model.PlanDefinition in project cqf-ruler by DBCG.
the class DiscoveryElementR4 method getAsJson.
public JsonObject getAsJson() {
JsonObject service = new JsonObject();
if (planDefinition != null) {
if (planDefinition.hasAction()) {
// TODO - this needs some work - too naive
if (planDefinition.getActionFirstRep().hasTrigger()) {
if (planDefinition.getActionFirstRep().getTriggerFirstRep().hasName()) {
service.addProperty("hook", planDefinition.getActionFirstRep().getTriggerFirstRep().getName());
}
}
}
if (planDefinition.hasName()) {
service.addProperty("name", planDefinition.getName());
}
if (planDefinition.hasTitle()) {
service.addProperty("title", planDefinition.getTitle());
}
if (planDefinition.hasDescription()) {
service.addProperty("description", planDefinition.getDescription());
}
service.addProperty("id", planDefinition.getIdElement().getIdPart());
if (prefetchUrlList == null) {
prefetchUrlList = new PrefetchUrlList();
}
JsonObject prefetchContent = new JsonObject();
int itemNo = 0;
if (!prefetchUrlList.stream().anyMatch(p -> p.equals("Patient/{{context.patientId}}") || p.equals("Patient?_id={{context.patientId}}") || p.equals("Patient?_id=Patient/{{context.patientId}}"))) {
prefetchContent.addProperty("item1", "Patient?_id={{context.patientId}}");
++itemNo;
}
for (String item : prefetchUrlList) {
prefetchContent.addProperty("item" + Integer.toString(++itemNo), item);
}
service.add("prefetch", prefetchContent);
return service;
}
return null;
}
Aggregations