use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method validateCode.
@Override
public ValidationResult validateCode(String system, String code, String display, ConceptSetComponent vsi) {
try {
ValueSet vs = new ValueSet();
vs.setUrl(Utilities.makeUuidUrn());
vs.getCompose().addInclude(vsi);
return verifyCodeExternal(vs, new Coding().setSystem(system).setCode(code).setDisplay(display), true);
} catch (Exception e) {
return new ValidationResult(IssueSeverity.FATAL, "Error validating code \"" + code + "\" in system \"" + system + "\": " + e.getMessage());
}
}
use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method verifyCodeInCodeSystem.
private ValidationResult verifyCodeInCodeSystem(CodeSystem cs, String system, String code, String display) throws Exception {
ConceptDefinitionComponent cc = findCodeInConcept(cs.getConcept(), code);
if (cc == null) {
if (cs.getContent().equals(CodeSystem.CodeSystemContentMode.COMPLETE)) {
return new ValidationResult(IssueSeverity.ERROR, "Unknown Code " + code + " in " + cs.getUrl());
} else if (!cs.getContent().equals(CodeSystem.CodeSystemContentMode.NOTPRESENT)) {
return new ValidationResult(IssueSeverity.WARNING, "Unknown Code " + code + " in partial code list of " + cs.getUrl());
} else {
return verifyCodeExternal(null, new Coding().setSystem(system).setCode(code).setDisplay(display), false);
}
}
// return new ValidationResult(IssueSeverity.ERROR, "Unknown Code "+code+" in "+cs.getUrl());
if (display == null) {
return new ValidationResult(cc);
}
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
if (cc.hasDisplay()) {
b.append(cc.getDisplay());
if (display.equalsIgnoreCase(cc.getDisplay())) {
return new ValidationResult(cc);
}
}
for (ConceptDefinitionDesignationComponent ds : cc.getDesignation()) {
b.append(ds.getValue());
if (display.equalsIgnoreCase(ds.getValue())) {
return new ValidationResult(cc);
}
}
return new ValidationResult(IssueSeverity.WARNING, "Display Name for " + code + " must be one of '" + b.toString() + "'", cc);
}
use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.
the class ValueSetCheckerSimple method validateCode.
private ValidationResult validateCode(Coding code, CodeSystem cs) {
ConceptDefinitionComponent cc = findCodeInConcept(cs.getConcept(), code.getCode());
if (cc == null)
return new ValidationResult(IssueSeverity.ERROR, "Unknown Code " + gen(code) + " in " + cs.getUrl());
if (code.getDisplay() == null)
return new ValidationResult(cc);
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
if (cc.hasDisplay()) {
b.append(cc.getDisplay());
if (code.getDisplay().equalsIgnoreCase(cc.getDisplay()))
return new ValidationResult(cc);
}
for (ConceptDefinitionDesignationComponent ds : cc.getDesignation()) {
b.append(ds.getValue());
if (code.getDisplay().equalsIgnoreCase(ds.getValue()))
return new ValidationResult(cc);
}
// also check to see if the value set has another display
ConceptReferenceComponent vs = findValueSetRef(code.getSystem(), code.getCode());
if (vs != null && (vs.hasDisplay() || vs.hasDesignation())) {
if (vs.hasDisplay()) {
b.append(vs.getDisplay());
if (code.getDisplay().equalsIgnoreCase(vs.getDisplay()))
return new ValidationResult(cc);
}
for (ConceptReferenceDesignationComponent ds : vs.getDesignation()) {
b.append(ds.getValue());
if (code.getDisplay().equalsIgnoreCase(ds.getValue()))
return new ValidationResult(cc);
}
}
return new ValidationResult(IssueSeverity.WARNING, "Display Name for " + code.getSystem() + "#" + code.getCode() + " should be one of '" + b.toString() + "' instead of " + code.getDisplay(), cc);
}
use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.
the class ValueSetCheckerSimple method validateCode.
public ValidationResult validateCode(Coding code) throws FHIRException {
String warningMessage = null;
// first, we validate the concept itself
String system = code.hasSystem() ? code.getSystem() : getValueSetSystem();
if (system == null && !code.hasDisplay()) {
// dealing with just a plain code (enum)
system = systemForCodeInValueSet(code.getCode());
}
if (!code.hasSystem())
code.setSystem(system);
boolean inExpansion = checkExpansion(code);
CodeSystem cs = context.fetchCodeSystem(system);
if (cs == null) {
warningMessage = "Unable to resolve system " + system + " - system is not specified or implicit";
if (!inExpansion)
throw new FHIRException(warningMessage);
}
if (cs != null && cs.getContent() != CodeSystemContentMode.COMPLETE) {
warningMessage = "Unable to resolve system " + system + " - system is not complete";
if (!inExpansion)
throw new FHIRException(warningMessage);
}
ValidationResult res = null;
if (cs != null)
res = validateCode(code, cs);
// then, if we have a value set, we check it's in the value set
if ((res == null || res.isOk()) && valueset != null && !codeInValueSet(system, code.getCode())) {
if (!inExpansion)
res.setMessage("Not in value set " + valueset.getUrl()).setSeverity(IssueSeverity.ERROR);
else if (warningMessage != null)
res = new ValidationResult(IssueSeverity.WARNING, "Code found in expansion, however: " + warningMessage);
else
res.setMessage("Code found in expansion, however: " + res.getMessage());
}
return res;
}
use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.
the class ValueSetCheckerSimple method validateCode.
public ValidationResult validateCode(CodeableConcept code) throws FHIRException {
// first, we validate the codings themselves
List<String> errors = new ArrayList<String>();
List<String> warnings = new ArrayList<String>();
for (Coding c : code.getCoding()) {
if (!c.hasSystem())
warnings.add("Coding has no system");
CodeSystem cs = context.fetchCodeSystem(c.getSystem());
if (cs == null)
warnings.add("Unsupported system " + c.getSystem() + " - system is not specified or implicit");
else if (cs.getContent() != CodeSystemContentMode.COMPLETE)
warnings.add("Unable to resolve system " + c.getSystem() + " - system is not complete");
else {
ValidationResult res = validateCode(c, cs);
if (!res.isOk())
errors.add(res.getMessage());
else if (res.getMessage() != null)
warnings.add(res.getMessage());
}
}
if (valueset != null) {
boolean ok = false;
for (Coding c : code.getCoding()) {
ok = ok || codeInValueSet(c.getSystem(), c.getCode());
}
if (!ok)
errors.add(0, "None of the provided codes are in the value set " + valueset.getUrl());
}
if (errors.size() > 0)
return new ValidationResult(IssueSeverity.ERROR, errors.toString());
else if (warnings.size() > 0)
return new ValidationResult(IssueSeverity.WARNING, warnings.toString());
else
return new ValidationResult(IssueSeverity.INFORMATION, null);
}
Aggregations