use of org.hl7.fhir.r4.model.ResourceType in project cqf-ruler by DBCG.
the class FhirMeasureBundler method bundle.
public Bundle bundle(Iterable<Resource> resources, String fhirServerBase) {
Bundle bundle = new Bundle();
bundle.setType(Bundle.BundleType.COLLECTION);
for (Resource resource : resources) {
Bundle.BundleEntryComponent entry = new Bundle.BundleEntryComponent();
entry.setResource(resource);
// The null check for resourceType handles Lists, which don't have a resource
// type.
entry.setFullUrl(fhirServerBase + (resource.getIdElement().getResourceType() != null ? (resource.getIdElement().getResourceType() + "/") : "") + resource.getIdElement().getIdPart());
bundle.getEntry().add(entry);
}
return bundle;
}
use of org.hl7.fhir.r4.model.ResourceType in project cqf-ruler by DBCG.
the class ResourceCreator method newResource.
@SuppressWarnings("unchecked")
default <T extends IBaseResource, I extends IIdType> T newResource(I theId) {
checkNotNull(theId, "theId is required");
checkArgument(theId.getResourceType() != null, "theId must have a resourceType");
IBaseResource newResource = this.getFhirContext().getResourceDefinition(theId.getResourceType()).newInstance();
newResource.setId(theId);
return (T) newResource;
}
use of org.hl7.fhir.r4.model.ResourceType 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.r4.model.ResourceType in project cqf-ruler by DBCG.
the class ProcessMessageProvider method constructAndSaveCommunication.
private String constructAndSaveCommunication(String patientId) {
String communication = "{\"resourceType\" : \"Communication\",\"meta\" : {\"versionId\" : \"1\",\"profile\" : [\"http://hl7.org/fhir/us/medmorph/StructureDefinition/us-ph-communication\"]},\"extension\" : [{\"url\" : \"http://hl7.org/fhir/us/medmorph/StructureDefinition/ext-responseMessageStatus\",\"valueCodeableConcept\" : {\"coding\" : [{\"system\" :\"http://hl7.org/fhir/us/medmorph/CodeSystem/us-ph-response-message-processing-status\",\"code\" : \"RRVS1\"}]}}],\"identifier\" : [{\"system\" : \"http://example.pha.org/\",\"value\" : \"12345\"}],\"status\" : \"completed\",\"category\" : [{\"coding\" : [{\"system\" : \"http://hl7.org/fhir/us/medmorph/CodeSystem/us-ph-messageheader-message-types\",\"code\" : \"cancer-response-message\"}]}],\"reasonCode\" : [{\"coding\" : [{\"system\" : \"http://hl7.org/fhir/us/medmorph/CodeSystem/us-ph-messageheader-message-types\",\"code\" : \"cancer-report-message\"}]}]}";
Communication comm = (Communication) this.getFhirContext().newJsonParser().parseResource(communication);
String commId = getUUID();
comm.setId(commId);
Meta meta = comm.getMeta();
meta.setLastUpdated(new Date());
comm.setMeta(meta);
comm.setSubject(new Reference(patientId));
comm.setReceived(new Date());
this.getDaoRegistry().getResourceDao(Communication.class).create(comm);
return commId;
}
use of org.hl7.fhir.r4.model.ResourceType in project cqf-ruler by DBCG.
the class ProcessMessageProvider method constructMessageHeaderResource.
private MessageHeader constructMessageHeaderResource() {
String message = "{\"resourceType\": \"MessageHeader\",\"id\": \"messageheader-example-reportheader\",\"meta\": {\"versionId\": \"1\",\"lastUpdated\": \"2020-11-29T02:03:28.045+00:00\",\"profile\": [\"http://hl7.org/fhir/us/medmorph/StructureDefinition/us-ph-messageheader\"]},\"extension\": [{\"url\": \"http://hl7.org/fhir/us/medmorph/StructureDefinition/ext-dataEncrypted\",\"valueBoolean\": false},{\"url\":\"http://hl7.org/fhir/us/medmorph/StructureDefinition/ext-messageProcessingCategory\",\"valueCode\": \"consequence\"}],\"eventCoding\": {\"system\": \"http://hl7.org/fhir/us/medmorph/CodeSystem/us-ph-messageheader-message-types\",\"code\": \"cancer-report-message\"},\"destination\": [{\"name\": \"PHA endpoint\",\"endpoint\": \"http://example.pha.org/fhir\"}],\"source\": {\"name\": \"Healthcare Organization\",\"software\": \"Backend Service App\",\"version\": \"3.1.45.AABB\",\"contact\": {\"system\": \"phone\",\"value\": \"+1 (917) 123 4567\"},\"endpoint\": \"http://example.healthcare.org/fhir\"},\"reason\": {\"coding\": [{\"system\": \"http://hl7.org/fhir/us/medmorph/CodeSystem/us-ph-triggerdefinition-namedevents\",\"code\": \"encounter-close\"}]}}";
MessageHeader messageHeader = (MessageHeader) this.getFhirContext().newJsonParser().parseResource(message);
messageHeader.setId(getUUID());
return messageHeader;
}
Aggregations