use of org.hl7.fhir.r4b.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) {
ConceptDefinitionComponent cc = findCodeInConcept(cs.getConcept(), code);
if (cc == null)
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.ERROR, "Display Name for " + code + " must be one of '" + b.toString() + "'");
}
use of org.hl7.fhir.r4b.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method verifyCodeExternal.
private ValidationResult verifyCodeExternal(ValueSet vs, Coding coding, boolean tryCache) {
ValidationResult res = vs == null ? null : handleByCache(vs, coding, tryCache);
if (res != null)
return res;
Parameters pin = new Parameters();
pin.addParameter().setName("coding").setValue(coding);
if (vs != null)
pin.addParameter().setName("valueSet").setResource(vs);
res = serverValidateCode(pin);
if (vs != null) {
Map<String, ValidationResult> cache = validationCache.get(vs.getUrl());
cache.put(cacheId(coding), res);
}
return res;
}
use of org.hl7.fhir.r4b.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method opMemberOf.
private List<Base> opMemberOf(ExecutionContext context, List<Base> left, List<Base> right, ExpressionNode expr) throws FHIRException {
boolean ans = false;
String url = right.get(0).primitiveValue();
ValueSet vs = hostServices != null ? hostServices.resolveValueSet(context.appInfo, url) : worker.fetchResource(ValueSet.class, url);
if (vs != null) {
for (Base l : left) {
if (Utilities.existsInList(l.fhirType(), "code", "string", "uri")) {
if (worker.validateCode(terminologyServiceOptions, TypeConvertor.castToCoding(l), vs).isOk()) {
ans = true;
}
} else if (l.fhirType().equals("Coding")) {
if (worker.validateCode(terminologyServiceOptions, TypeConvertor.castToCoding(l), vs).isOk()) {
ans = true;
}
} else if (l.fhirType().equals("CodeableConcept")) {
CodeableConcept cc = TypeConvertor.castToCodeableConcept(l);
ValidationResult vr = worker.validateCode(terminologyServiceOptions, cc, vs);
// System.out.println("~~~ "+DataRenderer.display(worker, cc)+ " memberOf "+url+": "+vr.toString());
if (vr.isOk()) {
ans = true;
}
} else {
// System.out.println("unknown type in opMemberOf: "+l.fhirType());
}
}
}
return makeBoolean(ans);
}
use of org.hl7.fhir.r4b.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.
the class ValueSetRenderer method genInclude.
private boolean genInclude(XhtmlNode ul, ConceptSetComponent inc, String type, List<String> langs, boolean doLangs, List<UsedConceptMap> maps) throws FHIRException, IOException {
boolean hasExtensions = false;
XhtmlNode li;
li = ul.li();
CodeSystem e = getContext().getWorker().fetchCodeSystem(inc.getSystem());
if (inc.hasSystem()) {
if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
li.addText(type + " all codes defined in ");
addCsRef(inc, li, e);
} else {
if (inc.getConcept().size() > 0) {
li.addText(type + " these codes as defined in ");
addCsRef(inc, li, e);
if (inc.hasVersion()) {
li.addText(" version ");
li.code(inc.getVersion());
}
// for performance reasons, we do all the fetching in one batch
Map<String, ConceptDefinitionComponent> definitions = getConceptsForCodes(e, inc);
XhtmlNode t = li.table("none");
boolean hasComments = false;
boolean hasDefinition = false;
for (ConceptReferenceComponent c : inc.getConcept()) {
hasComments = hasComments || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_VS_COMMENT);
ConceptDefinitionComponent cc = definitions.get(c.getCode());
hasDefinition = hasDefinition || ((cc != null && cc.hasDefinition()) || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_DEFINITION));
}
if (hasComments || hasDefinition)
hasExtensions = true;
addMapHeaders(addTableHeaderRowStandard(t, false, true, hasDefinition, hasComments, false, false, null, langs, doLangs), maps);
for (ConceptReferenceComponent c : inc.getConcept()) {
XhtmlNode tr = t.tr();
XhtmlNode td = tr.td();
ConceptDefinitionComponent cc = definitions.get(c.getCode());
addCodeToTable(false, inc.getSystem(), c.getCode(), c.hasDisplay() ? c.getDisplay() : cc != null ? cc.getDisplay() : "", td);
td = tr.td();
if (!Utilities.noString(c.getDisplay()))
td.addText(c.getDisplay());
else if (cc != null && !Utilities.noString(cc.getDisplay()))
td.addText(cc.getDisplay());
if (hasDefinition) {
td = tr.td();
if (ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_DEFINITION)) {
smartAddText(td, ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_DEFINITION));
} else if (cc != null && !Utilities.noString(cc.getDefinition())) {
smartAddText(td, cc.getDefinition());
}
}
if (hasComments) {
td = tr.td();
if (ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_VS_COMMENT)) {
smartAddText(td, "Note: " + ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_VS_COMMENT));
}
}
if (doLangs) {
addLangaugesToRow(c, langs, tr);
}
}
}
if (inc.getFilter().size() > 0) {
li.addText(type + " codes from ");
addCsRef(inc, li, e);
li.tx(" where ");
for (int i = 0; i < inc.getFilter().size(); i++) {
ConceptSetFilterComponent f = inc.getFilter().get(i);
if (i > 0) {
if (i == inc.getFilter().size() - 1) {
li.tx(" and ");
} else {
li.tx(", ");
}
}
if (f.getOp() == FilterOperator.EXISTS) {
if (f.getValue().equals("true")) {
li.tx(f.getProperty() + " exists");
} else {
li.tx(f.getProperty() + " doesn't exist");
}
} else {
li.tx(f.getProperty() + " " + describe(f.getOp()) + " ");
if (e != null && codeExistsInValueSet(e, f.getValue())) {
String href = getContext().fixReference(getCsRef(e));
if (href.contains("#"))
href = href + "-" + Utilities.nmtokenize(f.getValue());
else
href = href + "#" + e.getId() + "-" + Utilities.nmtokenize(f.getValue());
li.ah(href).addText(f.getValue());
} else if ("concept".equals(f.getProperty()) && inc.hasSystem()) {
li.addText(f.getValue());
ValidationResult vr = getContext().getWorker().validateCode(getContext().getTerminologyServiceOptions(), inc.getSystem(), inc.getVersion(), f.getValue(), null);
if (vr.isOk()) {
li.tx(" (" + vr.getDisplay() + ")");
}
} else
li.addText(f.getValue());
String disp = ToolingExtensions.getDisplayHint(f);
if (disp != null)
li.tx(" (" + disp + ")");
}
}
}
}
if (inc.hasValueSet()) {
li.tx(", where the codes are contained in ");
boolean first = true;
for (UriType vs : inc.getValueSet()) {
if (first)
first = false;
else
li.tx(", ");
AddVsRef(vs.asStringValue(), li);
}
}
} else {
li.tx("Import all the codes that are contained in ");
if (inc.getValueSet().size() < 4) {
boolean first = true;
for (UriType vs : inc.getValueSet()) {
if (first)
first = false;
else
li.tx(", ");
AddVsRef(vs.asStringValue(), li);
}
} else {
XhtmlNode xul = li.ul();
for (UriType vs : inc.getValueSet()) {
AddVsRef(vs.asStringValue(), xul.li());
}
}
}
return hasExtensions;
}
use of org.hl7.fhir.r4b.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.
the class ValueSetCheckerSimple method inComponent.
private Boolean inComponent(ConceptSetComponent vsi, int vsiIndex, String system, String code, boolean only, List<String> warnings) throws FHIRException {
for (UriType uri : vsi.getValueSet()) {
if (inImport(uri.getValue(), system, code)) {
return true;
}
}
if (!vsi.hasSystem()) {
return false;
}
if (only && system == null) {
// whether we know the system or not, we'll accept the stated codes at face value
for (ConceptReferenceComponent cc : vsi.getConcept()) {
if (cc.getCode().equals(code)) {
return true;
}
}
}
if (!system.equals(vsi.getSystem()))
return false;
// ok, we need the code system
CodeSystem cs = resolveCodeSystem(system);
if (cs == null || (cs.getContent() != CodeSystemContentMode.COMPLETE && cs.getContent() != CodeSystemContentMode.FRAGMENT)) {
// make up a transient value set with
ValueSet vs = new ValueSet();
vs.setStatus(PublicationStatus.ACTIVE);
vs.setUrl(valueset.getUrl() + "--" + vsiIndex);
vs.setVersion(valueset.getVersion());
vs.getCompose().addInclude(vsi);
ValidationResult res = context.validateCode(options.noClient(), new Coding(system, code, null), vs);
if (res.getErrorClass() == TerminologyServiceErrorClass.UNKNOWN || res.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED || res.getErrorClass() == TerminologyServiceErrorClass.VALUESET_UNSUPPORTED) {
if (warnings != null && res.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED) {
warnings.add(context.formatMessage(I18nConstants.TERMINOLOGY_TX_SYSTEM_NOTKNOWN, system));
}
return null;
}
if (res.getErrorClass() == TerminologyServiceErrorClass.NOSERVICE) {
throw new NoTerminologyServiceException();
}
return res.isOk();
} else {
if (vsi.hasFilter()) {
boolean ok = true;
for (ConceptSetFilterComponent f : vsi.getFilter()) {
if (!codeInFilter(cs, system, f, code)) {
ok = false;
break;
}
}
return ok;
}
List<ConceptDefinitionComponent> list = cs.getConcept();
boolean ok = validateCodeInConceptList(code, cs, list);
if (ok && vsi.hasConcept()) {
for (ConceptReferenceComponent cc : vsi.getConcept()) {
if (cc.getCode().equals(code)) {
return true;
}
}
return false;
} else {
return ok;
}
}
}
Aggregations