diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR2.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR2.java index c2c91f996..f005cdb35 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR2.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR2.java @@ -254,4 +254,9 @@ public class TerminologyClientR2 implements ITerminologyClient { return result == null ? null : (Bundle) VersionConvertorFactory_10_50.convertResource(result); } + @Override + public Parameters translate(Parameters params) throws FHIRException { + return (Parameters) VersionConvertorFactory_10_50.convertResource(client.translate((org.hl7.fhir.dstu2.model.Parameters) VersionConvertorFactory_10_50.convertResource(params))); + } + } \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR3.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR3.java index 78d861b28..792cb04ef 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR3.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR3.java @@ -257,4 +257,9 @@ public class TerminologyClientR3 implements ITerminologyClient { return (Parameters) VersionConvertorFactory_30_50.convertResource(p2); } + @Override + public Parameters translate(Parameters params) throws FHIRException { + return (Parameters) VersionConvertorFactory_30_50.convertResource(client.transform((org.hl7.fhir.dstu3.model.Parameters) VersionConvertorFactory_30_50.convertResource(params))); + } + } \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR4.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR4.java index a44bc9f9b..a5c6ef476 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR4.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR4.java @@ -274,5 +274,10 @@ public class TerminologyClientR4 implements ITerminologyClient { org.hl7.fhir.r4.model.Bundle result = client.search(type, criteria); return result == null ? null : (Bundle) VersionConvertorFactory_40_50.convertResource(result); } + + @Override + public Parameters translate(Parameters params) throws FHIRException { + return (Parameters) VersionConvertorFactory_40_50.convertResource(client.translate((org.hl7.fhir.r4.model.Parameters) VersionConvertorFactory_40_50.convertResource(params))); + } } \ No newline at end of file diff --git a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/client/FHIRToolingClient.java b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/client/FHIRToolingClient.java index 8bdb5725d..ff5900da4 100644 --- a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/client/FHIRToolingClient.java +++ b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/client/FHIRToolingClient.java @@ -762,6 +762,26 @@ public class FHIRToolingClient extends FHIRBaseToolingClient { return (Parameters) result.getPayload(); } + public Parameters translate(Parameters p) { + recordUse(); + ResourceRequest result = utils.issuePostRequest( + resourceAddress.resolveOperationUri(ConceptMap.class, "translate"), + utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), + withVer(getPreferredResourceFormat(), "1.0"), + timeoutNormal); + result.addErrorStatus(410);// gone + result.addErrorStatus(404);// unknown + result.addErrorStatus(405); + result.addErrorStatus(422);// Unprocessable Entity + result.addSuccessStatus(200); + result.addSuccessStatus(201); + if (result.isUnsuccessfulRequest()) { + throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), + (OperationOutcome) result.getPayload()); + } + return (Parameters) result.getPayload(); + } + public ValueSet expandValueset(ValueSet source, Parameters expParams) { recordUse(); List
headers = null; diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/client/FHIRToolingClient.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/client/FHIRToolingClient.java index 8089aa8cc..a1d365dad 100644 --- a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/client/FHIRToolingClient.java +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/client/FHIRToolingClient.java @@ -451,6 +451,25 @@ public class FHIRToolingClient extends FHIRBaseToolingClient { return (Parameters) result.getPayload(); } + public Parameters transform(Parameters p) { + recordUse(); + org.hl7.fhir.dstu3.utils.client.network.ResourceRequest result = null; + try { + result = client.issuePostRequest(resourceAddress.resolveOperationUri(ConceptMap.class, "transform"), + ByteUtils.resourceToByteArray(p, false, isJson(getPreferredResourceFormat())), + withVer(getPreferredResourceFormat(), "3.0"), + generateHeaders(), + "ConceptMap/$transform", + timeoutNormal); + } catch (IOException e) { + e.printStackTrace(); + } + if (result.isUnsuccessfulRequest()) { + throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload()); + } + return (Parameters) result.getPayload(); + } + public ValueSet expandValueset(ValueSet source, Parameters expParams) { recordUse(); Parameters p = expParams == null ? new Parameters() : expParams.copy(); diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/FHIRToolingClient.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/FHIRToolingClient.java index cddd33412..71d17810e 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/FHIRToolingClient.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/FHIRToolingClient.java @@ -418,7 +418,7 @@ public class FHIRToolingClient extends FHIRBaseToolingClient { } return (Parameters) result.getPayload(); } - + public Parameters lookupCode(Parameters p) { recordUse(); org.hl7.fhir.r4.utils.client.network.ResourceRequest result = null; @@ -435,6 +435,23 @@ public class FHIRToolingClient extends FHIRBaseToolingClient { } return (Parameters) result.getPayload(); } + + public Parameters translate(Parameters p) { + recordUse(); + org.hl7.fhir.r4.utils.client.network.ResourceRequest result = null; + try { + result = client.issuePostRequest(resourceAddress.resolveOperationUri(ConceptMap.class, "translate"), + ByteUtils.resourceToByteArray(p, false, isJson(getPreferredResourceFormat())), + withVer(getPreferredResourceFormat(), "4.0"), generateHeaders(), "ConceptMap/$translate", timeoutNormal); + } catch (IOException e) { + throw new FHIRException(e); + } + if (result.isUnsuccessfulRequest()) { + throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), + (OperationOutcome) result.getPayload()); + } + return (Parameters) result.getPayload(); + } public ValueSet expandValueset(ValueSet source, Parameters expParams) { recordUse(); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/client/ITerminologyClient.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/client/ITerminologyClient.java index 5ec15f1ba..2be9473c0 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/client/ITerminologyClient.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/client/ITerminologyClient.java @@ -63,6 +63,7 @@ public interface ITerminologyClient { CapabilityStatement getCapabilitiesStatementQuick() throws FHIRException; Parameters lookupCode(Map params) throws FHIRException; Parameters lookupCode(Parameters params) throws FHIRException; + Parameters translate(Parameters params) throws FHIRException; Bundle validateBatch(Bundle batch); CanonicalResource read(String type, String id); ClientHeaders getClientHeaders(); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/client/TerminologyClientR5.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/client/TerminologyClientR5.java index 54f8957bb..063708bb8 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/client/TerminologyClientR5.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/client/TerminologyClientR5.java @@ -268,5 +268,10 @@ public class TerminologyClientR5 implements ITerminologyClient { return client.search(type, criteria); } + @Override + public Parameters translate(Parameters params) throws FHIRException { + return client.translate(params); + } + } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java index 138691752..6159ae180 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java @@ -506,6 +506,25 @@ public class FHIRToolingClient extends FHIRBaseToolingClient { } return (Parameters) result.getPayload(); } + + public Parameters translate(Parameters p) { + recordUse(); + org.hl7.fhir.r5.utils.client.network.ResourceRequest result = null; + try { + result = client.issuePostRequest(resourceAddress.resolveOperationUri(ConceptMap.class, "translate"), + ByteUtils.resourceToByteArray(p, false, isJson(getPreferredResourceFormat())), + withVer(getPreferredResourceFormat(), "4.0"), + generateHeaders(), + "ConceptMap/$translate", + timeoutNormal); + } catch (IOException e) { + e.printStackTrace(); + } + if (result.isUnsuccessfulRequest()) { + throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload()); + } + return (Parameters) result.getPayload(); + } public String getAddress() { return base; diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTester.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTester.java index 649c4d1bf..951931b05 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTester.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTester.java @@ -205,6 +205,8 @@ public class TxTester { msg = validateCS(test.str("name"),tx, setup, req, resp, fp, lang, profile, ext); } else if (test.asString("operation").equals("lookup")) { msg = lookup(test.str("name"),tx, setup, req, resp, fp, lang, profile, ext); + } else if (test.asString("operation").equals("translate")) { + msg = translate(test.str("name"),tx, setup, req, resp, fp, lang, profile, ext); } else { throw new Exception("Unknown Operation "+test.asString("operation")); } @@ -277,6 +279,32 @@ public class TxTester { } return diff; } + + private String translate(String id, ITerminologyClient tx, List setup, Parameters p, String resp, String fp, String lang, Parameters profile, JsonObject ext) throws IOException { + for (Resource r : setup) { + p.addParameter().setName("tx-resource").setResource(r); + } + tx.setContentLanguage(lang); + p.getParameter().addAll(profile.getParameter()); + String pj; + try { + Parameters po = tx.translate(p); + TxTesterScrubbers.scrubParams(po); + TxTesterSorters.sortParameters(po); + pj = new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(po); + } catch (EFhirClientException e) { + OperationOutcome oo = e.getServerError(); + TxTesterScrubbers.scrubOO(oo, tight); + pj = new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(oo); + } + String diff = CompareUtilities.checkJsonSrcIsSame(id, resp, pj, false, ext); + if (diff != null) { + Utilities.createDirectory(Utilities.getDirectoryForFile(fp)); + TextFile.stringToFile(pj, fp); + } + return diff; + } + private String expand(String id, ITerminologyClient tx, List setup, Parameters p, String resp, String fp, String lang, Parameters profile, JsonObject ext) throws IOException { for (Resource r : setup) { p.addParameter().setName("tx-resource").setResource(r); @@ -438,7 +466,7 @@ public class TxTester { Resource res = new org.hl7.fhir.r5.formats.JsonParser().parse(ManagedFileAccess.inStream(Utilities.path(folder, filename))); org.hl7.fhir.r4.model.Resource r4 = VersionConvertorFactory_40_50.convertResource(res); String p = Utilities.path(folder, "r4", filename); - Utilities.createDirectory(p); + Utilities.createDirectory(Utilities.getDirectoryForFile(p)); new org.hl7.fhir.r4.formats.JsonParser().compose(ManagedFileAccess.outStream(p), r4); return res; }