use of org.hl7.fhir.utilities.validation.ValidationOptions in project org.hl7.fhir.core by hapifhir.
the class TerminologyCache method generateValidationToken.
public CacheToken generateValidationToken(ValidationOptions options, CodeableConcept code, ValueSet vs) {
CacheToken ct = new CacheToken();
for (Coding c : code.getCoding()) {
if (c.hasSystem()) {
ct.setName(getNameForSystem(c.getSystem()));
ct.hasVersion = c.hasVersion();
}
}
nameCacheToken(vs, ct);
JsonParser json = new JsonParser();
json.setOutputStyle(OutputStyle.PRETTY);
if (vs != null && vs.hasUrl() && vs.hasVersion()) {
try {
ct.request = "{\"code\" : " + json.composeString(code, "codeableConcept") + ", \"url\": \"" + Utilities.escapeJson(vs.getUrl()) + "\", \"version\": \"" + Utilities.escapeJson(vs.getVersion()) + "\"" + (options == null ? "" : ", " + options.toJson()) + "+}\r\n";
} catch (IOException e) {
throw new Error(e);
}
} else {
ValueSet vsc = getVSEssense(vs);
try {
ct.request = "{\"code\" : " + json.composeString(code, "codeableConcept") + ", \"valueSet\" :" + extracted(json, vsc) + (options == null ? "" : ", " + options.toJson()) + "}";
} catch (IOException e) {
throw new Error(e);
}
}
ct.key = String.valueOf(hashJson(ct.request));
return ct;
}
use of org.hl7.fhir.utilities.validation.ValidationOptions in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireValidator method validateAnswerCode.
private void validateAnswerCode(List<ValidationMessage> errors, Element value, NodeStack stack, QuestionnaireWithContext qSrc, String ref, boolean theOpenChoice) {
ValueSet vs = null;
if (ref.startsWith("#") && qSrc.container != null) {
vs = (ValueSet) loadContainedResource(errors, qSrc.containerPath, qSrc.container, ref.substring(1), ValueSet.class);
} else {
vs = resolveBindingReference(qSrc.q(), ref, qSrc.q().getUrl());
}
if (warning(errors, IssueType.CODEINVALID, value.line(), value.col(), stack.getLiteralPath(), vs != null, I18nConstants.TERMINOLOGY_TX_VALUESET_NOTFOUND, describeReference(ref))) {
try {
Coding c = ObjectConverter.readAsCoding(value);
if (isBlank(c.getCode()) && isBlank(c.getSystem()) && isNotBlank(c.getDisplay())) {
if (theOpenChoice) {
return;
}
}
long t = System.nanoTime();
ValidationContextCarrier vc = makeValidationContext(errors, qSrc);
ValidationResult res = context.validateCode(new ValidationOptions(stack.getWorkingLang()), c, vs, vc);
timeTracker.tx(t, "vc " + c.getSystem() + "#" + c.getCode() + " '" + c.getDisplay() + "'");
if (!res.isOk()) {
txRule(errors, res.getTxLink(), IssueType.CODEINVALID, value.line(), value.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_BADOPTION, c.getSystem(), c.getCode());
} else if (res.getSeverity() != null) {
super.addValidationMessage(errors, IssueType.CODEINVALID, value.line(), value.col(), stack.getLiteralPath(), res.getMessage(), res.getSeverity(), Source.TerminologyEngine, null);
}
} catch (Exception e) {
warning(errors, IssueType.CODEINVALID, value.line(), value.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_CODING, e.getMessage());
}
}
}
use of org.hl7.fhir.utilities.validation.ValidationOptions in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method doValidateCode.
public ValidationResult doValidateCode(ValidationOptions options, Coding code, ValueSet vs, boolean implySystem) {
CacheToken cacheToken = txCache != null ? txCache.generateValidationToken(options, code, vs) : null;
ValidationResult res = null;
if (txCache != null)
res = txCache.getValidation(cacheToken);
if (res != null)
return res;
// ok, first we try to validate locally
try {
ValueSetCheckerSimple vsc = new ValueSetCheckerSimple(options, vs, this);
res = vsc.validateCode(code);
if (txCache != null)
txCache.cacheValidation(cacheToken, res, TerminologyCache.TRANSIENT);
return res;
} catch (Exception e) {
}
// if that failed, we try to validate on the server
if (noTerminologyServer)
return new ValidationResult(IssueSeverity.ERROR, "Error validating code: running without terminology services", TerminologyServiceErrorClass.NOSERVICE);
String csumm = txCache != null ? txCache.summary(code) : null;
if (txCache != null)
tlog("$validate " + csumm + " for " + txCache.summary(vs));
else
tlog("$validate " + csumm + " before cache exists");
try {
Parameters pIn = new Parameters();
pIn.addParameter().setName("coding").setValue(code);
if (implySystem)
pIn.addParameter().setName("implySystem").setValue(new BooleanType(true));
if (options != null)
setTerminologyOptions(options, pIn);
res = validateOnServer(vs, pIn);
} catch (Exception e) {
res = new ValidationResult(IssueSeverity.ERROR, e.getMessage() == null ? e.getClass().getName() : e.getMessage()).setTxLink(txLog == null ? null : txLog.getLastId());
}
if (txCache != null)
txCache.cacheValidation(cacheToken, res, TerminologyCache.PERMANENT);
return res;
}
use of org.hl7.fhir.utilities.validation.ValidationOptions in project org.hl7.fhir.core by hapifhir.
the class TerminologyCache method generateValidationToken.
public CacheToken generateValidationToken(ValidationOptions options, CodeableConcept code, ValueSet vs) {
CacheToken ct = new CacheToken();
for (Coding c : code.getCoding()) {
if (c.hasSystem())
ct.setName(getNameForSystem(c.getSystem()));
}
JsonParser json = new JsonParser();
json.setOutputStyle(OutputStyle.PRETTY);
ValueSet vsc = getVSEssense(vs);
try {
ct.request = "{\"code\" : " + json.composeString(code, "codeableConcept") + ", \"valueSet\" :" + json.composeString(vsc) + (options == null ? "" : ", " + options.toJson()) + "}";
} catch (IOException e) {
throw new Error(e);
}
ct.key = String.valueOf(hashNWS(ct.request));
return ct;
}
use of org.hl7.fhir.utilities.validation.ValidationOptions in project org.hl7.fhir.core by hapifhir.
the class TerminologyCache method generateValidationToken.
public CacheToken generateValidationToken(ValidationOptions options, Coding code, ValueSet vs) {
CacheToken ct = new CacheToken();
if (code.hasSystem())
ct.name = getNameForSystem(code.getSystem());
else
ct.name = NAME_FOR_NO_SYSTEM;
JsonParser json = new JsonParser();
json.setOutputStyle(OutputStyle.PRETTY);
ValueSet vsc = getVSEssense(vs);
try {
ct.request = "{\"code\" : " + json.composeString(code, "code") + ", \"valueSet\" :" + (vsc == null ? "null" : json.composeString(vsc)) + (options == null ? "" : ", " + options.toJson()) + "}";
} catch (IOException e) {
throw new Error(e);
}
ct.key = String.valueOf(hashNWS(ct.request));
return ct;
}
Aggregations