use of org.hl7.fhir.r4.model.RiskAssessment in project himss_2021_sepsis_detection by redhat-na-ssa.
the class DebeziumStreamListener method processMessage.
@KafkaListener(topics = "${listener.destination.debezium-stream}", containerFactory = "debeziumListenerContainerFactory")
public void processMessage(@Payload String cloudEvent, @Header(KafkaHeaders.RECEIVED_TOPIC) String topic, @Header(KafkaHeaders.RECEIVED_PARTITION_ID) int partition, Acknowledgment ack) throws IOException {
GZIPInputStream is = null;
try {
JsonNode rootNode = objectMapper.readTree(cloudEvent);
JsonNode after = rootNode.get("data").get("payload").get("after");
JsonNode resType = after.get("res_type");
log.debug("processMessage() topic = " + topic + " : resType = " + resType.asText());
if (FHIRUtil.PATIENT.equals(resType.asText())) {
JsonNode resId = after.get("res_id");
JsonNode resText = after.get("res_text");
byte[] bytes = resText.binaryValue();
is = new GZIPInputStream(new ByteArrayInputStream(bytes));
String fhirJson = IOUtils.toString(is, "UTF-8");
Patient patientObj = fhirCtx.newJsonParser().parseResource(Patient.class, fhirJson);
patientObj.setId(resId.asText());
log.info("processMessage() bytes length = " + bytes.length + " : fhir json = \n" + fhirJson + "\n fhir resourceType: " + patientObj.getResourceType().name() + " : patientId = " + resId);
if (patientObj.getId() != null) {
// Start Business Process
fhirProcessMgmt.startProcess(patientObj);
} else {
log.error("processMessage() no res_id for patient: " + fhirJson);
}
} else if (FHIRUtil.RISK_ASSESSMENT.equals(resType.asText())) {
JsonNode resId = after.get("res_id");
JsonNode resText = after.get("res_text");
byte[] bytes = resText.binaryValue();
is = new GZIPInputStream(new ByteArrayInputStream(bytes));
String fhirJson = IOUtils.toString(is, "UTF-8");
RiskAssessment raObj = fhirCtx.newJsonParser().parseResource(RiskAssessment.class, fhirJson);
fhirProcessMgmt.signalProcess(raObj);
} else {
log.warn("Will not process message with FHIR type: " + resType.asText());
}
} catch (Exception x) {
log.error("Unable to process the following debezium stream event: \n" + cloudEvent);
x.printStackTrace();
} finally {
ack.acknowledge();
if (is != null)
is.close();
}
}
use of org.hl7.fhir.r4.model.RiskAssessment 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());
}
use of org.hl7.fhir.r4.model.RiskAssessment in project himss_2021_sepsis_detection by redhat-na-ssa.
the class RiskAssessmentService method publishRiskAssessment.
public void publishRiskAssessment(Patient patient, String sepsisResponse, String observationId, String correlationKey) throws JsonProcessingException {
log.info("createRiskAssessment() patient = " + patient.getId() + " : sepsisResponse = " + sepsisResponse + " : obsId = " + observationId);
String uid = UUID.randomUUID().toString();
RiskAssessment assessment = createRiskAssessment(patient, sepsisResponse, observationId, correlationKey);
String cEventString = generateCloudEventJson(uid, assessment, RiskAssessmentUtils.MESSAGE_TYPE_EVENT);
Message<String> record = KafkaRecord.of(uid, cEventString);
eventChannel.send(record);
eventBus.send(RiskAssessmentUtils.POST_TO_FHIR_SERVER, assessment);
// postRiskAssessmentToFhirServer(assessment);
}
use of org.hl7.fhir.r4.model.RiskAssessment in project himss_2021_sepsis_detection by redhat-na-ssa.
the class CloudEventTest method kafkaCloudEventTest.
// TO-DO: Need to switch to Binary encoding
@Disabled
@Test
public void kafkaCloudEventTest() throws JsonProcessingException {
// Send Patient as CloudEvent
Patient patient = createPatient();
String uid = UUID.randomUUID().toString();
String cEventString = generateCloudEventJson(uid, patient, RiskAssessmentUtils.MESSAGE_TYPE_COMMAND);
InMemorySource<Message<String>> generateRACommandSource = connector.source(RiskAssessmentUtils.COMMAND_CHANNEL);
/* By default, this test class will send message with the following metadata type:
* io.smallrye.reactive.messaging.kafka.OutgoingKafkaRecordMetadata
*
* To be consistent with metadata types in production, need to switch to use of:
* io.smallrye.reactive.messaging.kafka.impl.ce.DefaultIncomingKafkaCloudEventMetadata
*
* TO-DO: The following is being coded because during testing it doesn't appear that "cloud-event=true" on the channels has any affect.
*/
IncomingCloudEventMetadata<String> cloudEventMetadata = new DefaultIncomingCloudEventMetadata<>(builder.withId("id").withSource(URI.create("test://cloud.event")).withType(RiskAssessmentUtils.MESSAGE_TYPE_COMMAND).withTimestamp(OffsetDateTime.now().toZonedDateTime()).build());
DefaultIncomingKafkaCloudEventMetadata kafkaCloudEventMetadata = new DefaultIncomingKafkaCloudEventMetadata<>(cloudEventMetadata);
Message<String> record = KafkaRecord.of(uid, cEventString).addMetadata(kafkaCloudEventMetadata);
generateRACommandSource.send(record);
// Consume CloudEvent with RiskAssessment
InMemorySink consumeRASink = connector.sink(RiskAssessmentUtils.EVENT_CHANNEL);
await().atMost(Duration.ofSeconds(15)).<List<? extends Message<String>>>until(consumeRASink::received, t -> t.size() == 1);
}
use of org.hl7.fhir.r4.model.RiskAssessment in project himss_2021_sepsis_detection by redhat-na-ssa.
the class FhirServerTest method riskAssessmentPredictionTest.
@Test
public void riskAssessmentPredictionTest() throws IOException {
String filePath = "/fhir/RiskAssessment.json";
InputStream fStream = null;
String oJson = null;
try {
fStream = this.getClass().getResourceAsStream(filePath);
if (fStream != null) {
oJson = IOUtils.toString(fStream, "UTF-8");
RiskAssessment rAssessment = (RiskAssessment) fhirCtx.newJsonParser().parseResource(oJson);
RiskAssessmentPredictionComponent raPredictionComponent = rAssessment.getPredictionFirstRep();
Property cProp = raPredictionComponent.getOutcome().getChildByName("coding");
Coding coding = (Coding) cProp.getValues().get(0);
String code = coding.getCode();
log.info("riskAssessmentPredictionTest() code = " + code);
} else {
log.error("riskAssessmentTest() resource not found: " + filePath);
return;
}
} finally {
if (fStream != null)
fStream.close();
}
}
Aggregations