Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Configure iti41 #556

Merged
merged 7 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import org.apache.camel.Processor;
import org.ehrbase.fhirbridge.camel.CamelConstants;
import org.ehrbase.fhirbridge.fhir.support.Bundles;
import org.ehrbase.fhirbridge.ihe.xds.ITITrace;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.Binary;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.DocumentManifest;
import org.hl7.fhir.r4.model.DocumentReference;
import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r4.model.ResourceType;
import org.springframework.stereotype.Component;
Expand All @@ -27,6 +30,7 @@ public class ITI65Processor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
Bundle bundle = (Bundle) exchange.getIn().getBody(Resource.class);
setSaveInput(exchange, bundle);
for(Bundle.BundleEntryComponent entry: bundle.getEntry()){
if(entry.getResource().getResourceType().equals(ResourceType.Binary)){
Binary binary = (Binary) entry.getResource();
Expand All @@ -44,4 +48,18 @@ public void process(Exchange exchange) throws Exception {
}
}
}

private void setSaveInput(Exchange exchange, Bundle bundle) {
DocumentManifest documentManifest = null; // cant be null since fhir profile requires it
DocumentReference documentReference = null; // cant be null since fhir profile requires it
for(Bundle.BundleEntryComponent entry: bundle.getEntry()){
if(entry.getResource().getResourceType().equals(ResourceType.DocumentManifest)){
documentManifest = (DocumentManifest) entry.getResource();
}else if(entry.getResource().getResourceType().equals(ResourceType.DocumentReference)){
documentReference = (DocumentReference) entry.getResource();
}
}
ITITrace itiTrace = new ITITrace(documentManifest, documentReference);
exchange.getIn().setHeader("iti65-trace", itiTrace);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.ehrbase.fhirbridge.fhir.bundle.validator.AntiBodyPanelBundleValidator;
import org.ehrbase.fhirbridge.fhir.bundle.validator.BloodGasPanelBundleValidator;
import org.ehrbase.fhirbridge.fhir.bundle.validator.DiagnosticReportLabBundleValidator;
import org.ehrbase.fhirbridge.fhir.bundle.validator.Iti65BundleValidator;
import org.ehrbase.fhirbridge.fhir.bundle.validator.UCCAppProDatenValidator;
import org.ehrbase.fhirbridge.fhir.bundle.validator.UCCSensorDatenValidator;
import org.ehrbase.fhirbridge.fhir.bundle.validator.VirologischerBefundBundleValidator;
Expand All @@ -53,15 +54,24 @@ public class TransactionRouteBuilder extends AbstractRouteBuilder {
public void configure() throws Exception {
// @formatter:off
from("bundle-provide:consumer?fhirContext=#fhirContext")
.setHeader(CamelConstants.PROFILE, method(Bundles.class, "getTransactionProfile"))
.choice()
.when(header(CamelConstants.PROFILE).isEqualTo(Profile.ITI65))
.bean(ITI65Processor.class)
.choice()
.when(header(CamelConstants.PROFILE).isEqualTo(Optional.empty()))
.to("direct:provideResource")
.process(BundleResponseProcessor.BEAN_ID)
.setHeader(CamelConstants.PROFILE, method(Bundles.class, "getTransactionProfile"))
.choice()
.when(header(CamelConstants.PROFILE).isEqualTo(Profile.ITI65))
.to("direct:processITI65")
.otherwise()
.to("direct:process-bundle");

from("direct:processITI65")
.bean(ITI65Processor.class)
.bean(Iti65BundleValidator.class)
.choice()
.when(header(CamelConstants.PROFILE).isEqualTo(Optional.empty())) // If no Bundle is contained within MHD
.to("direct:provideResource")
.process(BundleResponseProcessor.BEAN_ID)
.otherwise()
.to("direct:process-bundle");

from("direct:process-bundle")
.choice()
.when(header(CamelConstants.PROFILE).isEqualTo(Profile.ANTI_BODY_PANEL))
.bean(AntiBodyPanelBundleValidator.class)
Expand All @@ -71,33 +81,33 @@ public void configure() throws Exception {
.bean(BloodGasPanelConverter.class, "convert")
.when(header(CamelConstants.PROFILE).isEqualTo(Profile.DIAGNOSTIC_REPORT_LAB))
.bean(DiagnosticReportLabBundleValidator.class)
.bean(DiagnosticReportLabConverter.class,"convert")
.bean(DiagnosticReportLabConverter.class, "convert")
.when(header(CamelConstants.PROFILE).isEqualTo(Profile.VIROLOGISCHER_BEFUND))
.bean(VirologischerBefundBundleValidator.class)
.bean(VirologischerBefundConverter.class,"convert")
.bean(VirologischerBefundConverter.class, "convert")
.when(header(CamelConstants.PROFILE).isEqualTo(Profile.UCC_SENSORDATEN_STEPS))
.bean(UCCSensorDatenValidator.class)
.bean(UCCSensordatenActivityBundleConverter.class,"convert")
.bean(UCCSensordatenActivityBundleConverter.class, "convert")
.when(header(CamelConstants.PROFILE).isEqualTo(Profile.UCC_SENSORDATEN_VITALSIGNS))
.bean(UCCSensorDatenValidator.class)
.bean(UCCSensordatenVitalSignsBundleConverter.class,"convert")
.bean(UCCSensordatenVitalSignsBundleConverter.class, "convert")
.when(header(CamelConstants.PROFILE).isEqualTo(Profile.UCC_APP_PRO_DATEN))
.bean(UCCAppProDatenValidator.class)
.bean(UCCAppProDatenBundleConverter.class,"convert")
.bean(UCCAppProDatenBundleConverter.class, "convert")
.otherwise()
.throwException(new UnprocessableEntityException("Unsupported transaction: provided Bundle should have a resource that " +
"uses on of the following profiles: " +
Profile.BLOOD_GAS_PANEL.getUri() +
", " + Profile.DIAGNOSTIC_REPORT_LAB.getUri() +
", " + Profile.ANTI_BODY_PANEL.getUri() +
", " +Profile.VIROLOGISCHER_BEFUND.getUri() +
", " + Profile.UCC_SENSORDATEN_STEPS.getUri()+
", " + Profile.VIROLOGISCHER_BEFUND.getUri() +
", " + Profile.UCC_SENSORDATEN_STEPS.getUri() +
", " + Profile.UCC_SENSORDATEN_VITALSIGNS.getUri() +
", " + Profile.UCC_APP_PRO_DATEN.getUri()
))
.end()
.to("direct:provideResource")
.process(BundleResponseProcessor.BEAN_ID);
.end()
.to("direct:provideResource")
.process(BundleResponseProcessor.BEAN_ID);
// @formatter:on
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.ehrbase.fhirbridge.config.ihe.xds;

import org.ehrbase.fhirbridge.ihe.xds.Iti41Converter;
import org.ehrbase.fhirbridge.ihe.xds.converter.Iti41Converter;
import org.ehrbase.fhirbridge.ihe.xds.XdsRouteBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.ehrbase.fhirbridge.fhir.bundle.validator;

import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.ResourceType;
import org.openehealth.ipf.commons.ihe.fhir.FhirTransactionValidator;

import java.util.Map;

public class Iti65BundleValidator implements FhirTransactionValidator {

@Override
public void validateRequest(Object payload, Map<String, Object> parameters) {
Bundle bundle = (Bundle) payload;
validateDocumentReference(bundle);
}

private void validateDocumentReference(Bundle bundle) {
int count = 0;
for(Bundle.BundleEntryComponent entry :bundle.getEntry()){
if(entry.getResource().getResourceType().equals(ResourceType.DocumentReference)){
count ++;
}
}
if(count>1){
throw new UnprocessableEntityException("Only one DocumentReference per MHD Bundle is supported!");
}
}

@Override
public void validateResponse(Object o, Map<String, Object> map) {
throw new UnsupportedOperationException("Response validation is not supported");
}
}
17 changes: 17 additions & 0 deletions src/main/java/org/ehrbase/fhirbridge/ihe/xds/ITI41Processor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.ehrbase.fhirbridge.ihe.xds;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.ehrbase.client.classgenerator.interfaces.CompositionEntity;

public class ITI41Processor implements Processor {

public static final String BEAN_ID = "iti41Processor";

@Override
public void process(Exchange exchange) throws Exception {
ITITrace iti41Trace = (ITITrace) exchange.getIn().getHeader("iti65-trace");
iti41Trace.setCompositionEntity((CompositionEntity) exchange.getIn().getBody());
exchange.getIn().setBody(iti41Trace);
}
}
34 changes: 34 additions & 0 deletions src/main/java/org/ehrbase/fhirbridge/ihe/xds/ITITrace.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.ehrbase.fhirbridge.ihe.xds;

import org.ehrbase.client.classgenerator.interfaces.CompositionEntity;
import org.hl7.fhir.r4.model.DocumentManifest;
import org.hl7.fhir.r4.model.DocumentReference;

public class ITITrace {
private final DocumentManifest documentManifest;
private final DocumentReference documentReference;
private CompositionEntity compositionEntity;

public ITITrace(DocumentManifest documentManifest, DocumentReference documentReference) {
this.documentManifest = documentManifest;
this.documentReference = documentReference;
}

public CompositionEntity getCompositionEntity() {
return compositionEntity;
}

public void setCompositionEntity(CompositionEntity compositionEntity) {
this.compositionEntity = compositionEntity;
}

public DocumentManifest getDocumentManifest() {
return documentManifest;
}

public DocumentReference getDocumentReference() {
return documentReference;
}
}


15 changes: 15 additions & 0 deletions src/main/java/org/ehrbase/fhirbridge/ihe/xds/XDSValidator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.ehrbase.fhirbridge.ihe.xds;

import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;

public class XDSValidator implements Processor {

@Override
public void process(Exchange exchange) throws Exception {
if(exchange.getIn().getHeader("iti65-trace")==null){
throw new UnprocessableEntityException("ITI 41 is only supported, if the rsource instance was sent via ITI65.");
}
}
}
28 changes: 23 additions & 5 deletions src/main/java/org/ehrbase/fhirbridge/ihe/xds/XdsRouteBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@

package org.ehrbase.fhirbridge.ihe.xds;

import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.util.ObjectHelper;
import org.ehrbase.client.classgenerator.interfaces.CompositionEntity;
import org.ehrbase.client.openehrclient.VersionUid;
import org.ehrbase.fhirbridge.camel.CamelConstants;
import org.ehrbase.fhirbridge.ehr.converter.ConversionException;
import org.openehealth.ipf.commons.ihe.xds.core.requests.ProvideAndRegisterDocumentSet;

/**
Expand All @@ -31,11 +37,23 @@ public void configure() throws Exception {
errorHandler(defaultErrorHandler().logExhaustedMessageHistory(false));

from("direct:send-to-cdr")
.routeId("sendToXdsCdr")
.setProperty("fhir_resource").body()
.convertBodyTo(ProvideAndRegisterDocumentSet.class)
.to("xds-iti41://{{fhir-bridge.xds.hostname}}:{{fhir-bridge.xds.port}}{{fhir-bridge.xds.context-path}}")
.setBody().exchangeProperty("fhir_resource");
.routeId("sendToXdsCdr")
.bean(XDSValidator.class)
.doTry()
.to("bean:fhirResourceConversionService?method=convert(${headers.CamelFhirBridgeProfile}, ${body})")
.doCatch(ConversionException.class)
.throwException(UnprocessableEntityException.class, "${exception.message}")
.end()
.process(exchange -> {
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(CamelConstants.COMPOSITION_ID))) {
String compositionId = exchange.getIn().getHeader(CamelConstants.COMPOSITION_ID, String.class);
exchange.getIn().getBody(CompositionEntity.class).setVersionUid(new VersionUid(compositionId));
}
})
.bean(ITI41Processor.class)
.convertBodyTo(ProvideAndRegisterDocumentSet.class)
.to("xds-iti41://{{fhir-bridge.xds.hostname}}:{{fhir-bridge.xds.port}}{{fhir-bridge.xds.context-path}}")
.setBody().exchangeProperty("fhir_resource");
// @formatter:on
}
}
Loading