use of org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method serverValidateCode.
private ValidationResult serverValidateCode(Parameters pin, boolean doCache) throws Exception {
if (noTerminologyServer) {
return new ValidationResult(null, null, TerminologyServiceErrorClass.NOSERVICE);
}
String cacheName = doCache ? generateCacheName(pin) : null;
ValidationResult res = loadFromCache(cacheName);
if (res != null) {
return res;
}
tlog("Terminology Server: $validate-code " + describeValidationParameters(pin));
for (ParametersParameterComponent pp : pin.getParameter()) {
if (pp.getName().equals("profile")) {
throw new Error("Can only specify profile in the context");
}
}
if (expProfile == null) {
throw new Exception("No ExpansionProfile provided");
}
pin.addParameter().setName("profile").setResource(expProfile);
Parameters pout = txServer.operateType(ValueSet.class, "validate-code", pin);
boolean ok = false;
String message = "No Message returned";
String display = null;
TerminologyServiceErrorClass err = TerminologyServiceErrorClass.UNKNOWN;
for (ParametersParameterComponent p : pout.getParameter()) {
if (p.getName().equals("result")) {
ok = ((BooleanType) p.getValue()).getValue().booleanValue();
} else if (p.getName().equals("message")) {
message = ((StringType) p.getValue()).getValue();
} else if (p.getName().equals("display")) {
display = ((StringType) p.getValue()).getValue();
} else if (p.getName().equals("cause")) {
try {
IssueType it = IssueType.fromCode(((StringType) p.getValue()).getValue());
if (it == IssueType.UNKNOWN) {
err = TerminologyServiceErrorClass.UNKNOWN;
} else if (it == IssueType.NOTSUPPORTED) {
err = TerminologyServiceErrorClass.VALUESET_UNSUPPORTED;
}
} catch (FHIRException e) {
}
}
}
if (!ok) {
res = new ValidationResult(IssueSeverity.ERROR, message, err);
} else if (display != null) {
res = new ValidationResult(new ConceptDefinitionComponent().setDisplay(display));
} else {
res = new ValidationResult(new ConceptDefinitionComponent());
}
saveToCache(res, cacheName);
return res;
}
use of org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method doExpand.
public ValueSetExpansionOutcome doExpand(ValueSet source, Parameters expParams) throws FHIRException, ETooCostly, FileNotFoundException, IOException {
if (expParams == null)
expParams = makeDefaultExpansion();
source.checkNoModifiers("ValueSet", "expanding");
focus = source.copy();
focus.setExpansion(new ValueSet.ValueSetExpansionComponent());
focus.getExpansion().setTimestampElement(DateTimeType.now());
focus.getExpansion().setIdentifier(Factory.createUUID());
for (ParametersParameterComponent p : expParams.getParameter()) {
if (Utilities.existsInList(p.getName(), "includeDesignations", "excludeNested"))
focus.getExpansion().addParameter().setName(p.getName()).setValue(p.getValue());
}
if (source.hasCompose())
handleCompose(source.getCompose(), focus.getExpansion().getParameter(), expParams, source.getUrl());
if (canBeHeirarchy) {
for (ValueSetExpansionContainsComponent c : roots) {
focus.getExpansion().getContains().add(c);
}
} else {
for (ValueSetExpansionContainsComponent c : codes) {
if (map.containsKey(key(c)) && !c.getAbstract()) {
// we may have added abstract codes earlier while we still thought it might be heirarchical, but later we gave up, so now ignore them
focus.getExpansion().getContains().add(c);
// make sure any heirarchy is wiped
c.getContains().clear();
}
}
}
if (total > 0) {
focus.getExpansion().setTotal(total);
}
return new ValueSetExpansionOutcome(focus);
}
use of org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method serverValidateCode.
private ValidationResult serverValidateCode(Parameters pin) {
Parameters pout = txServer.operateType(ValueSet.class, "validate-code", pin);
boolean ok = false;
String message = "No Message returned";
String display = null;
for (ParametersParameterComponent p : pout.getParameter()) {
if (p.getName().equals("result"))
ok = ((BooleanType) p.getValue()).getValue().booleanValue();
else if (p.getName().equals("message"))
message = ((StringType) p.getValue()).getValue();
else if (p.getName().equals("display"))
display = ((StringType) p.getValue()).getValue();
}
if (!ok)
return new ValidationResult(IssueSeverity.ERROR, message);
else if (display != null)
return new ValidationResult(new ConceptDefinitionComponent().setDisplay(display));
else
return new ValidationResult(null);
}
use of org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent in project org.hl7.fhir.core by hapifhir.
the class FHIRToolingClient method operateType.
public <T extends Resource> Parameters operateType(Class<T> resourceClass, String name, Parameters params) {
boolean complex = false;
for (ParametersParameterComponent p : params.getParameter()) complex = complex || !(p.getValue() instanceof PrimitiveType);
String ps = "";
try {
if (!complex)
for (ParametersParameterComponent p : params.getParameter()) if (p.getValue() instanceof PrimitiveType)
ps += p.getName() + "=" + Utilities.encodeUri(((PrimitiveType) p.getValue()).asStringValue()) + "&";
ResourceRequest<T> result;
URI url = resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps);
if (complex) {
byte[] body = ByteUtils.resourceToByteArray(params, false, isJson(getPreferredResourceFormat()));
if (client.getLogger() != null) {
client.getLogger().logRequest("POST", url.toString(), null, body);
}
result = client.issuePostRequest(url, body, getPreferredResourceFormat(), generateHeaders(), "POST " + resourceClass.getName() + "/$" + name, TIMEOUT_OPERATION_LONG);
} else {
if (client.getLogger() != null) {
client.getLogger().logRequest("GET", url.toString(), null, null);
}
result = client.issueGetResourceRequest(url, getPreferredResourceFormat(), generateHeaders(), "GET " + resourceClass.getName() + "/$" + name, TIMEOUT_OPERATION_LONG);
}
if (result.isUnsuccessfulRequest()) {
throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload());
}
if (result.getPayload() instanceof Parameters) {
return (Parameters) result.getPayload();
} else {
Parameters p_out = new Parameters();
p_out.addParameter().setName("return").setResource(result.getPayload());
return p_out;
}
} catch (Exception e) {
handleException("Error performing tx3 operation '" + name + ": " + e.getMessage() + "' (parameters = \"" + ps + "\")", e);
}
return null;
}
use of org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method doExpand.
public ValueSetExpansionOutcome doExpand(ValueSet source, Parameters expParams) throws FHIRException, ETooCostly, FileNotFoundException, IOException {
if (expParams == null)
expParams = makeDefaultExpansion();
source.checkNoModifiers("ValueSet", "expanding");
focus = source.copy();
focus.setExpansion(new ValueSet.ValueSetExpansionComponent());
focus.getExpansion().setTimestampElement(DateTimeType.now());
focus.getExpansion().setIdentifier(Factory.createUUID());
for (ParametersParameterComponent p : expParams.getParameter()) {
if (Utilities.existsInList(p.getName(), "includeDesignations", "excludeNested"))
focus.getExpansion().addParameter().setName(p.getName()).setValue(p.getValue());
}
if (source.hasCompose())
handleCompose(source.getCompose(), focus.getExpansion(), expParams, source.getUrl(), focus.getExpansion().getExtension());
if (canBeHeirarchy) {
for (ValueSetExpansionContainsComponent c : roots) {
focus.getExpansion().getContains().add(c);
}
} else {
for (ValueSetExpansionContainsComponent c : codes) {
if (map.containsKey(key(c)) && (includeAbstract || !c.getAbstract())) {
// we may have added abstract codes earlier while we still thought it might be heirarchical, but later we gave up, so now ignore them
focus.getExpansion().getContains().add(c);
// make sure any heirarchy is wiped
c.getContains().clear();
}
}
}
if (total > 0) {
focus.getExpansion().setTotal(total);
}
return new ValueSetExpansionOutcome(focus);
}
Aggregations