Search in sources :

Example 76 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.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;
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource)

Example 77 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.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;
}
Also used : IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Example 78 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.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);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) Bundle(org.hl7.fhir.r4.model.Bundle) Patient(org.hl7.fhir.r4.model.Patient) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) StringEntity(org.apache.http.entity.StringEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) PlanDefinition(org.hl7.fhir.r4.model.PlanDefinition) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 79 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.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;
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) Reference(org.hl7.fhir.r4.model.Reference) Date(java.util.Date) Communication(org.hl7.fhir.r4.model.Communication)

Example 80 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.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;
}
Also used : MessageHeader(org.hl7.fhir.r4.model.MessageHeader)

Aggregations

JsonElement (com.google.gson.JsonElement)33 HashSet (java.util.HashSet)26 Bundle (org.hl7.fhir.r4.model.Bundle)24 ResourceType (org.hl7.fhir.r4.model.Enumerations.ResourceType)21 Test (org.junit.Test)20 Nonnull (javax.annotation.Nonnull)18 ArrayList (java.util.ArrayList)15 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)10 FhirContext (ca.uhn.fhir.context.FhirContext)9 File (java.io.File)9 Row (org.apache.spark.sql.Row)9 IdType (org.hl7.fhir.dstu3.model.IdType)9 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)9 JsonObject (com.google.gson.JsonObject)8 Test (org.junit.jupiter.api.Test)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 IOException (java.io.IOException)7 List (java.util.List)7 Bundle (org.hl7.fhir.dstu3.model.Bundle)7 Resource (org.hl7.fhir.r4.model.Resource)7