Search in sources :

Example 16 with Manager

use of org.hl7.fhir.r5.elementmodel.Manager in project himss_2021_sepsis_detection by redhat-na-ssa.

the class FHIRServerWIH method executeWorkItem.

@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
    String taskName = (String) workItem.getParameter(FHIRUtil.WORK_ITEM_NAME);
    Observation obs = (Observation) workItem.getParameter(FHIRUtil.OBSERVATION);
    Encounter eObj = (Encounter) workItem.getParameter(FHIRUtil.ENCOUNTER);
    log.warn(taskName + " : " + obs + " : " + eObj);
    Map<String, Object> results = workItem.getResults();
    manager.completeWorkItem(workItem.getId(), results);
}
Also used : Observation(org.hl7.fhir.r4.model.Observation) Encounter(org.hl7.fhir.r4.model.Encounter)

Example 17 with Manager

use of org.hl7.fhir.r5.elementmodel.Manager in project himss_2021_sepsis_detection by redhat-na-ssa.

the class RiskAssessmentWIH method executeWorkItem.

@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
    Map<String, Object> parameters = workItem.getParameters();
    Patient patient = (Patient) parameters.get(FHIRUtil.PATIENT);
    if (patient == null) {
        throw new RuntimeException("executeWorkItem() must pass value for " + FHIRUtil.PATIENT);
    }
    PatientVitals vitals = (PatientVitals) parameters.get(FHIRUtil.PATIENT_VITALS);
    if (vitals == null)
        throw new RuntimeException("executeWorkItem() must pass value for " + FHIRUtil.PATIENT_VITALS);
    String sepsisResponse = (String) parameters.get(FHIRUtil.SEPSIS_RESPONSE);
    if (sepsisResponse == null)
        throw new RuntimeException("executeWorkItem() must pass value for " + FHIRUtil.SEPSIS_RESPONSE);
    String correlationKey = runtimeService.getProcessInstanceById(workItem.getProcessInstanceId()).getCorrelationKey();
    log.info("executeWorkItem() will send generate RiskAssessment command regarding patientId = " + patient.getId() + " : correlationKey = " + correlationKey + " : sepsisResponse = " + sepsisResponse + " : obsId = " + vitals.getObservationId());
    try {
        String patientPayload = fhirCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(patient);
        ObjectNode rootNode = objectMapper.createObjectNode();
        rootNode.put(FHIRUtil.PATIENT, patientPayload);
        rootNode.put(FHIRUtil.SEPSIS_RESPONSE, sepsisResponse);
        rootNode.put(FHIRUtil.OBSERVATION_ID, vitals.getObservationId());
        rootNode.put(FHIRUtil.CORRELATION_KEY, correlationKey);
        String cloudEventPayload = objectMapper.writeValueAsString(rootNode);
        CloudEvent cloudEvent = CloudEventBuilder.v1().withId(correlationKey).withSource(URI.create("")).withType(FHIRUtil.GENERATE_RISK_ASSESSMENT).withTime(OffsetDateTime.now()).withData(cloudEventPayload.getBytes()).build();
        producer.send(this.generateRiskAssessmentCommandDestination, cloudEvent);
    } catch (Exception x) {
        x.printStackTrace();
        throw new RuntimeException(x);
    }
    manager.completeWorkItem(workItem.getId(), workItem.getParameters());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PatientVitals(com.redhat.naps.process.model.PatientVitals) Patient(org.hl7.fhir.r4.model.Patient) CloudEvent(io.cloudevents.CloudEvent)

Example 18 with Manager

use of org.hl7.fhir.r5.elementmodel.Manager in project org.hl7.fhir.core by hapifhir.

the class IgLoader method loadIgSource.

/**
 * @param src can be one of the following:
 *      <br> - a canonical url for an ig - this will be converted to a package id and loaded into the cache
 *      <br> - a package id for an ig - this will be loaded into the cache
 *      <br> - a direct reference to a package ("package.tgz") - this will be extracted by the cache manager, but not put in the cache
 *      <br> - a folder containing resources - these will be loaded directly
 * @param recursive if true and src resolves to a folder, recursively find and load IgSources from that directory
 * @param explore should be true if we're trying to load an -ig parameter, and false if we're loading source
 *
 * @return
 * @throws FHIRException
 * @throws IOException
 */
public Map<String, byte[]> loadIgSource(String src, boolean recursive, boolean explore) throws FHIRException, IOException {
    // 
    if (Common.isNetworkPath(src)) {
        String v = null;
        if (src.contains("|")) {
            v = src.substring(src.indexOf("|") + 1);
            src = src.substring(0, src.indexOf("|"));
        }
        String pid = explore ? getPackageCacheManager().getPackageId(src) : null;
        if (!Utilities.noString(pid))
            return fetchByPackage(pid + (v == null ? "" : "#" + v));
        else
            return fetchFromUrl(src + (v == null ? "" : "|" + v), explore);
    }
    File f = new File(Utilities.path(src));
    if (f.exists()) {
        if (f.isDirectory() && new File(Utilities.path(src, "package.tgz")).exists())
            return loadPackage(new FileInputStream(Utilities.path(src, "package.tgz")), Utilities.path(src, "package.tgz"));
        if (f.isDirectory() && new File(Utilities.path(src, "igpack.zip")).exists())
            return readZip(new FileInputStream(Utilities.path(src, "igpack.zip")));
        if (f.isDirectory() && new File(Utilities.path(src, "validator.pack")).exists())
            return readZip(new FileInputStream(Utilities.path(src, "validator.pack")));
        if (f.isDirectory())
            return scanDirectory(f, recursive);
        if (src.endsWith(".tgz"))
            return loadPackage(new FileInputStream(src), src);
        if (src.endsWith(".pack"))
            return readZip(new FileInputStream(src));
        if (src.endsWith("igpack.zip"))
            return readZip(new FileInputStream(src));
        Manager.FhirFormat fmt = ResourceChecker.checkIsResource(getContext(), isDebug(), TextFile.fileToBytes(f), src, true);
        if (fmt != null) {
            Map<String, byte[]> res = new HashMap<String, byte[]>();
            res.put(Utilities.changeFileExt(src, "." + fmt.getExtension()), TextFile.fileToBytesNCS(src));
            return res;
        }
    } else if ((src.matches(FilesystemPackageCacheManager.PACKAGE_REGEX) || src.matches(FilesystemPackageCacheManager.PACKAGE_VERSION_REGEX)) && !src.endsWith(".zip") && !src.endsWith(".tgz")) {
        return fetchByPackage(src);
    }
    throw new FHIRException("Unable to find/resolve/read " + (explore ? "-ig " : "") + src);
}
Also used : HashMap(java.util.HashMap) FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) Manager(org.hl7.fhir.r5.elementmodel.Manager) IniFile(org.hl7.fhir.utilities.IniFile) TextFile(org.hl7.fhir.utilities.TextFile) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)15 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)14 IdDt (ca.uhn.fhir.model.primitive.IdDt)14 Constants (ca.uhn.fhir.rest.api.Constants)14 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)14 StringClientParam (ca.uhn.fhir.rest.gclient.StringClientParam)14 TokenClientParam (ca.uhn.fhir.rest.gclient.TokenClientParam)14 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)14 InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)14 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)14 ImmutableList (com.google.common.collect.ImmutableList)14 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)14 BeneficiaryHistory (gov.cms.bfd.model.rif.BeneficiaryHistory)14 CarrierClaim (gov.cms.bfd.model.rif.CarrierClaim)14 DMEClaim (gov.cms.bfd.model.rif.DMEClaim)14 HHAClaim (gov.cms.bfd.model.rif.HHAClaim)14 HospiceClaim (gov.cms.bfd.model.rif.HospiceClaim)14 InpatientClaim (gov.cms.bfd.model.rif.InpatientClaim)14 MedicareBeneficiaryIdHistory (gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory)14 OutpatientClaim (gov.cms.bfd.model.rif.OutpatientClaim)14