Add support for $translate to terminology client
This commit is contained in:
parent
63852b4082
commit
1f7f57bade
|
@ -254,4 +254,9 @@ public class TerminologyClientR2 implements ITerminologyClient {
|
||||||
return result == null ? null : (Bundle) VersionConvertorFactory_10_50.convertResource(result);
|
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)));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -257,4 +257,9 @@ public class TerminologyClientR3 implements ITerminologyClient {
|
||||||
return (Parameters) VersionConvertorFactory_30_50.convertResource(p2);
|
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)));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -275,4 +275,9 @@ public class TerminologyClientR4 implements ITerminologyClient {
|
||||||
return result == null ? null : (Bundle) VersionConvertorFactory_40_50.convertResource(result);
|
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)));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -762,6 +762,26 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
|
||||||
return (Parameters) result.getPayload();
|
return (Parameters) result.getPayload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Parameters translate(Parameters p) {
|
||||||
|
recordUse();
|
||||||
|
ResourceRequest<Resource> 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) {
|
public ValueSet expandValueset(ValueSet source, Parameters expParams) {
|
||||||
recordUse();
|
recordUse();
|
||||||
List<Header> headers = null;
|
List<Header> headers = null;
|
||||||
|
|
|
@ -451,6 +451,25 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
|
||||||
return (Parameters) result.getPayload();
|
return (Parameters) result.getPayload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Parameters transform(Parameters p) {
|
||||||
|
recordUse();
|
||||||
|
org.hl7.fhir.dstu3.utils.client.network.ResourceRequest<Resource> 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) {
|
public ValueSet expandValueset(ValueSet source, Parameters expParams) {
|
||||||
recordUse();
|
recordUse();
|
||||||
Parameters p = expParams == null ? new Parameters() : expParams.copy();
|
Parameters p = expParams == null ? new Parameters() : expParams.copy();
|
||||||
|
|
|
@ -436,6 +436,23 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
|
||||||
return (Parameters) result.getPayload();
|
return (Parameters) result.getPayload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Parameters translate(Parameters p) {
|
||||||
|
recordUse();
|
||||||
|
org.hl7.fhir.r4.utils.client.network.ResourceRequest<Resource> 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) {
|
public ValueSet expandValueset(ValueSet source, Parameters expParams) {
|
||||||
recordUse();
|
recordUse();
|
||||||
Parameters p = expParams == null ? new Parameters() : expParams.copy();
|
Parameters p = expParams == null ? new Parameters() : expParams.copy();
|
||||||
|
|
|
@ -63,6 +63,7 @@ public interface ITerminologyClient {
|
||||||
CapabilityStatement getCapabilitiesStatementQuick() throws FHIRException;
|
CapabilityStatement getCapabilitiesStatementQuick() throws FHIRException;
|
||||||
Parameters lookupCode(Map<String, String> params) throws FHIRException;
|
Parameters lookupCode(Map<String, String> params) throws FHIRException;
|
||||||
Parameters lookupCode(Parameters params) throws FHIRException;
|
Parameters lookupCode(Parameters params) throws FHIRException;
|
||||||
|
Parameters translate(Parameters params) throws FHIRException;
|
||||||
Bundle validateBatch(Bundle batch);
|
Bundle validateBatch(Bundle batch);
|
||||||
CanonicalResource read(String type, String id);
|
CanonicalResource read(String type, String id);
|
||||||
ClientHeaders getClientHeaders();
|
ClientHeaders getClientHeaders();
|
||||||
|
|
|
@ -268,5 +268,10 @@ public class TerminologyClientR5 implements ITerminologyClient {
|
||||||
return client.search(type, criteria);
|
return client.search(type, criteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Parameters translate(Parameters params) throws FHIRException {
|
||||||
|
return client.translate(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -507,6 +507,25 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
|
||||||
return (Parameters) result.getPayload();
|
return (Parameters) result.getPayload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Parameters translate(Parameters p) {
|
||||||
|
recordUse();
|
||||||
|
org.hl7.fhir.r5.utils.client.network.ResourceRequest<Resource> 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() {
|
public String getAddress() {
|
||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,6 +205,8 @@ public class TxTester {
|
||||||
msg = validateCS(test.str("name"),tx, setup, req, resp, fp, lang, profile, ext);
|
msg = validateCS(test.str("name"),tx, setup, req, resp, fp, lang, profile, ext);
|
||||||
} else if (test.asString("operation").equals("lookup")) {
|
} else if (test.asString("operation").equals("lookup")) {
|
||||||
msg = lookup(test.str("name"),tx, setup, req, resp, fp, lang, profile, ext);
|
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 {
|
} else {
|
||||||
throw new Exception("Unknown Operation "+test.asString("operation"));
|
throw new Exception("Unknown Operation "+test.asString("operation"));
|
||||||
}
|
}
|
||||||
|
@ -277,6 +279,32 @@ public class TxTester {
|
||||||
}
|
}
|
||||||
return diff;
|
return diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String translate(String id, ITerminologyClient tx, List<Resource> 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<Resource> setup, Parameters p, String resp, String fp, String lang, Parameters profile, JsonObject ext) throws IOException {
|
private String expand(String id, ITerminologyClient tx, List<Resource> setup, Parameters p, String resp, String fp, String lang, Parameters profile, JsonObject ext) throws IOException {
|
||||||
for (Resource r : setup) {
|
for (Resource r : setup) {
|
||||||
p.addParameter().setName("tx-resource").setResource(r);
|
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)));
|
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);
|
org.hl7.fhir.r4.model.Resource r4 = VersionConvertorFactory_40_50.convertResource(res);
|
||||||
String p = Utilities.path(folder, "r4", filename);
|
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);
|
new org.hl7.fhir.r4.formats.JsonParser().compose(ManagedFileAccess.outStream(p), r4);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue