Skip to content

Commit

Permalink
#175: adapt MHD
Browse files Browse the repository at this point in the history
  • Loading branch information
oliveregger committed Aug 30, 2024
1 parent 539492b commit a4c599f
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 232 deletions.
12 changes: 10 additions & 2 deletions src/main/java/ch/bfh/ti/i4mi/mag/mhd/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,16 @@ public static Processor keptBodyToHeader() {
exchange.getMessage().setHeader(KEPT_BODY, exchange.getProperty(KEPT_BODY));
};
}



/**
* move previously stored message body to name property
* @return
*/
public static Processor storeBodyToHeader(String name) {
return exchange -> {
exchange.getMessage().setHeader(name, exchange.getIn().getBody());
};
}

public static Processor storePreferHeader() {
return exchange -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,13 @@ public org.openehealth.ipf.commons.ihe.xds.core.metadata.Address transform(Addre
* @param system
* @return
*/
public String noPrefix(String system) {
static public String noPrefix(String system) {
if (system == null) return null;
if (system.startsWith("urn:oid:")) {
system = system.substring(8);
}
if (system.startsWith("urn:uuid:")) {
system = system.substring(9);
}
return system;
}
Expand Down Expand Up @@ -443,19 +446,23 @@ public Identifiable transform(Identifier identifier) {
public Identifiable transformReferenceToIdentifiable(Reference reference, DomainResource container) {
if (reference.hasReference()) {
String targetRef = reference.getReference();
List<Resource> resources = container.getContained();
for (Resource resource : resources) {
if (targetRef.equals(resource.getId())) {
if (resource instanceof Patient) {
return transform(((Patient) resource).getIdentifierFirstRep());
} else if (resource instanceof Encounter) {
return transform(((Encounter) resource).getIdentifierFirstRep());
if (targetRef.startsWith("#")) {
// targetRef = targetRef.substring(1); note: resource.getId() return the id wit the # prefix for the contained resources
List<Resource> resources = container.getContained();
for (Resource resource : resources) {
if (targetRef.equals(resource.getId())) {
if (resource instanceof Patient) {
return transform(((Patient) resource).getIdentifierFirstRep());
} else if (resource instanceof Encounter) {
return transform(((Encounter) resource).getIdentifierFirstRep());
}
}
}
}

Identifiable result = patientRefCreator.resolvePatientReference(reference.getReference());
if (result != null) return result;
if (result != null)
return result;

MultiValueMap<String, String> vals = UriComponentsBuilder.fromUriString(targetRef).build().getQueryParams();
if (vals.containsKey("identifier")) {
Expand All @@ -472,6 +479,7 @@ public Identifiable transformReferenceToIdentifiable(Reference reference, Domai
String fhirBase = ref.substring(0, ref.indexOf("/Patient/"));

if (!fhirBase.equals(config.getUriExternalPatientEndpoint())) {
log.error("Patient url must be in the form "+config.getUriExternalPatientEndpoint()+"/Patient/... but was "+ref);
throw FhirUtils.invalidRequest(
OperationOutcome.IssueSeverity.ERROR,
OperationOutcome.IssueType.INVALID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@
import org.hl7.fhir.r4.model.OperationOutcome.OperationOutcomeIssueComponent;
import org.hl7.fhir.r4.model.StringType;
import org.openehealth.ipf.commons.ihe.fhir.translation.ToFhirTranslator;
import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.ProvideAndRegisterDocumentSetRequestType;
import org.openehealth.ipf.commons.ihe.xds.core.requests.ProvideAndRegisterDocumentSet;
import org.openehealth.ipf.commons.ihe.xds.core.responses.ErrorCode;
import org.openehealth.ipf.commons.ihe.xds.core.responses.ErrorInfo;
import org.openehealth.ipf.commons.ihe.xds.core.responses.Response;
import org.openehealth.ipf.commons.ihe.xds.core.responses.Severity;
import org.openehealth.ipf.commons.ihe.xds.core.responses.Status;
import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rim.ExtrinsicObjectType;

import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ch.bfh.ti.i4mi.mag.Config;
Expand All @@ -61,14 +64,13 @@ public Iti65ResponseConverter(final Config config) {
*/
@Override
public Object translateToFhir(Response input, Map<String, Object> parameters) {


String entryUuid = null;
if (input.getStatus().equals(Status.SUCCESS)) {

Bundle responseBundle = new Bundle();
Bundle requestBundle = (Bundle) parameters.get(Utils.KEPT_BODY);

responseBundle.getMeta().addProfile("https://profiles.ihe.net/ITI/MHD/StructureDefinition/IHE.MHD.ProvideDocumentBundleResponse");

ProvideAndRegisterDocumentSet prb = (ProvideAndRegisterDocumentSet) parameters.get("ProvideAndRegisterDocumentSet");
entryUuid = Iti65RequestConverter.noPrefix(prb.getDocuments().get(0).getDocumentEntry().getEntryUuid());
Bundle requestBundle = (Bundle) parameters.get("BundleRequest");
for (Bundle.BundleEntryComponent requestEntry : requestBundle.getEntry()) {
Bundle.BundleEntryResponseComponent response = new Bundle.BundleEntryResponseComponent()
.setStatus("201 Created")
Expand All @@ -78,19 +80,15 @@ public Object translateToFhir(Response input, Map<String, Object> parameters) {
response.setLocation(config.getUriMagXdsRetrieve() + "?uniqueId=" + uniqueId
+ "&repositoryUniqueId=" + config.getRepositoryUniqueId());
} else if (requestEntry.getResource() instanceof ListResource) {
String id = config.getSchemeMapper().getScheme(((ListResource) requestEntry.getResource()).getId());
response.setLocation(config.getBaseurl()+"/fhir/List/"+id);
response.setLocation(config.getBaseurl()+"/fhir/List/"+Iti65RequestConverter.noPrefix(prb.getSubmissionSet().getEntryUuid()));
} else if (requestEntry.getResource() instanceof DocumentReference) {
String id = config.getSchemeMapper().getScheme(((DocumentReference) requestEntry.getResource()).getId());
response.setLocation(config.getBaseurl()+"/fhir/DocumentReference/"+id);
response.setLocation(config.getBaseurl()+"/fhir/DocumentReference/"+entryUuid);
}
responseBundle.addEntry()
.setResponse(response);

}

return responseBundle;

return responseBundle;
} else {
processError(input);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ public void configure() throws Exception {
.process(AuthTokenConverter.addWsHeader())
// translate, forward, translate back
.process(Utils.keepBody())
.process(Utils.storeBodyToHeader("BundleRequest"))
.bean(Iti65RequestConverter.class)
.process(Utils.storeBodyToHeader("ProvideAndRegisterDocumentSet"))
.convertBodyTo(ProvideAndRegisterDocumentSetRequestType.class)
//.process(iti41RequestValidator())
.to(xds41Endpoint)
.convertBodyTo(Response.class)
.process(Utils.keptBodyToHeader())
.process(translateToFhir(new Iti65ResponseConverter(config) , Response.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public Identifiable resolvePatientReference(String reference) {
}

public Identifiable resolvePatientId(String fullId) {
if (fullId==null)
return null;
int splitIdx = fullId.indexOf("-");
if (splitIdx>0) {
if (fullId.substring(0,splitIdx).contains(".")) {
Expand All @@ -82,8 +84,10 @@ public Identifiable resolvePatientId(String fullId) {
log.error("expected oid as a system for resolving Patient in: "+fullId);
}
} else {
if (config.isChEprspidAsPatientId()) {
return new Identifiable(fullId, new AssigningAuthority(schemeMapper.getScheme(config.getOID_EPRSPID())));
if (config.isChEprspidAsPatientId() && fullId.startsWith("76133761")) {
if (fullId.matches("^[0-9]{18}$") ) {
return new Identifiable(fullId, new AssigningAuthority(schemeMapper.getScheme(config.getOID_EPRSPID())));
}
}
}
return null;
Expand Down
394 changes: 189 additions & 205 deletions src/test/resources/mhdch.json

Large diffs are not rendered by default.

0 comments on commit a4c599f

Please sign in to comment.