use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project org.hl7.fhir.core by hapifhir.
the class ProfileComparer method unionBindings.
private ElementDefinitionBindingComponent unionBindings(ProfileComparison comp, StructuralMatch<ElementDefinitionNode> res, String path, ElementDefinitionBindingComponent left, ElementDefinitionBindingComponent right) throws FHIRFormatError, DefinitionException, IOException {
ElementDefinitionBindingComponent union = new ElementDefinitionBindingComponent();
if (left.getStrength().compareTo(right.getStrength()) < 0)
union.setStrength(left.getStrength());
else
union.setStrength(right.getStrength());
union.setDescription(mergeText(comp, res, path, "binding.description", left.getDescription(), right.getDescription(), false));
if (Base.compareDeep(left.getValueSet(), right.getValueSet(), false))
union.setValueSet(left.getValueSet());
else {
ValueSet lvs = resolveVS(comp.getLeft(), left.getValueSet(), session.getContextLeft());
ValueSet rvs = resolveVS(comp.getRight(), right.getValueSet(), session.getContextRight());
if (lvs != null && rvs != null) {
ValueSetComparison compP = (ValueSetComparison) session.compare(lvs, rvs);
if (compP != null) {
union.setValueSet(compP.getUnion().getUrl());
}
} else if (lvs != null) {
union.setValueSet(lvs.getUrl());
} else if (rvs != null) {
union.setValueSet(rvs.getUrl());
}
}
return union;
}
use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project org.hl7.fhir.core by hapifhir.
the class InstanceValidator method checkTerminologyCoding.
private void checkTerminologyCoding(List<ValidationMessage> errors, String path, Element element, StructureDefinition profile, ElementDefinition theElementCntext, boolean inCodeableConcept, boolean checkDisplay, NodeStack stack, StructureDefinition logical) {
Coding c = convertToCoding(element, logical);
String code = c.getCode();
String system = c.getSystem();
String display = c.getDisplay();
String version = c.getVersion();
rule(errors, IssueType.CODEINVALID, element.line(), element.col(), path, system == null || isCodeSystemReferenceValid(system), I18nConstants.TERMINOLOGY_TX_SYSTEM_RELATIVE);
if (system != null && code != null && !noTerminologyChecks) {
rule(errors, IssueType.CODEINVALID, element.line(), element.col(), path, !isValueSet(system), I18nConstants.TERMINOLOGY_TX_SYSTEM_VALUESET2, system);
try {
if (checkCode(errors, element, path, code, system, version, display, checkDisplay, stack))
if (theElementCntext != null && theElementCntext.hasBinding()) {
ElementDefinitionBindingComponent binding = theElementCntext.getBinding();
if (warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, binding != null, I18nConstants.TERMINOLOGY_TX_BINDING_MISSING2, path)) {
if (binding.hasValueSet()) {
ValueSet valueset = resolveBindingReference(profile, binding.getValueSet(), profile.getUrl());
if (valueset == null) {
CodeSystem cs = context.fetchCodeSystem(binding.getValueSet());
if (rule(errors, IssueType.CODEINVALID, element.line(), element.col(), path, cs == null, I18nConstants.TERMINOLOGY_TX_VALUESET_NOTFOUND_CS, describeReference(binding.getValueSet()))) {
warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, valueset != null, I18nConstants.TERMINOLOGY_TX_VALUESET_NOTFOUND, describeReference(binding.getValueSet()));
}
} else {
try {
long t = System.nanoTime();
ValidationResult vr = null;
if (binding.getStrength() != BindingStrength.EXAMPLE) {
vr = checkCodeOnServer(stack, valueset, c, true);
}
if (binding.getStrength() == BindingStrength.REQUIRED) {
removeTrackedMessagesForLocation(errors, element, path);
}
timeTracker.tx(t, "vc " + system + "#" + code + " '" + display + "'");
if (vr != null && !vr.isOk()) {
if (vr.IsNoService())
txHint(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_BINDING_NOSERVER);
else if (vr.getErrorClass() != null && vr.getErrorClass().isInfrastructure()) {
if (binding.getStrength() == BindingStrength.REQUIRED)
txWarning(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_CONFIRM_4a, describeReference(binding.getValueSet(), valueset), vr.getMessage(), system + "#" + code);
else if (binding.getStrength() == BindingStrength.EXTENSIBLE) {
if (binding.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"))
checkMaxValueSet(errors, path, element, profile, ToolingExtensions.readStringExtension(binding, "http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"), c, stack);
else if (!noExtensibleWarnings)
txWarningForLaterRemoval(element, errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_CONFIRM_5, describeReference(binding.getValueSet(), valueset));
} else if (binding.getStrength() == BindingStrength.PREFERRED) {
if (baseOnly) {
txHint(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_CONFIRM_6, describeReference(binding.getValueSet(), valueset));
}
}
} else if (binding.getStrength() == BindingStrength.REQUIRED)
txRule(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_NOVALID_4, describeReference(binding.getValueSet(), valueset), (vr.getMessage() != null ? " (error message = " + vr.getMessage() + ")" : ""), system + "#" + code);
else if (binding.getStrength() == BindingStrength.EXTENSIBLE) {
if (binding.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"))
checkMaxValueSet(errors, path, element, profile, ToolingExtensions.readStringExtension(binding, "http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"), c, stack);
else
txWarning(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_NOVALID_5, describeReference(binding.getValueSet(), valueset), (vr.getMessage() != null ? " (error message = " + vr.getMessage() + ")" : ""), system + "#" + code);
} else if (binding.getStrength() == BindingStrength.PREFERRED) {
if (baseOnly) {
txHint(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_NOVALID_6, describeReference(binding.getValueSet(), valueset), (vr.getMessage() != null ? " (error message = " + vr.getMessage() + ")" : ""), system + "#" + code);
}
}
}
} catch (Exception e) {
if (STACK_TRACE)
e.printStackTrace();
warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_ERROR_CODING1, e.getMessage());
}
}
} else if (binding.hasValueSet()) {
hint(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_BINDING_CANTCHECK);
} else if (!inCodeableConcept && !noBindingMsgSuppressed) {
hint(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_BINDING_NOSOURCE, path);
}
}
}
} catch (Exception e) {
if (STACK_TRACE)
e.printStackTrace();
rule(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_ERROR_CODING2, e.getMessage(), e.toString());
}
}
}
use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method generateGridDescription.
private Cell generateGridDescription(HierarchicalTableGenerator gen, Row row, ElementDefinition definition, ElementDefinition fallback, boolean used, String baseURL, String url, StructureDefinition profile, String corePath, String imagePath, boolean root, ElementDefinition valueDefn) throws IOException, FHIRException {
Cell c = gen.new Cell();
row.getCells().add(c);
if (used) {
if (definition.hasContentReference()) {
ElementDefinition ed = getElementByName(profile.getSnapshot().getElement(), definition.getContentReference());
if (ed == null)
c.getPieces().add(gen.new Piece(null, "Unknown reference to " + definition.getContentReference(), null));
else
c.getPieces().add(gen.new Piece("#" + ed.getPath(), "See " + ed.getPath(), null));
}
if (definition.getPath().endsWith("url") && definition.hasFixed()) {
c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "\"" + buildJson(definition.getFixed()) + "\"", null).addStyle("color: darkgreen")));
} else {
if (url != null) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
String fullUrl = url.startsWith("#") ? baseURL + url : url;
StructureDefinition ed = context.fetchResource(StructureDefinition.class, url);
String ref = null;
if (ed != null) {
String p = ed.getUserString("path");
if (p != null) {
ref = p.startsWith("http:") || igmode ? p : Utilities.pathURL(corePath, p);
}
}
c.getPieces().add(gen.new Piece(null, "URL: ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(ref, fullUrl, null));
}
if (definition.hasSlicing()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(gen.new Piece(null, "Slice: ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(null, describeSlice(definition.getSlicing()), null));
}
if (definition != null) {
ElementDefinitionBindingComponent binding = null;
if (valueDefn != null && valueDefn.hasBinding() && !valueDefn.getBinding().isEmpty())
binding = valueDefn.getBinding();
else if (definition.hasBinding())
binding = definition.getBinding();
if (binding != null && !binding.isEmpty()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
BindingResolution br = pkp.resolveBinding(profile, binding, definition.getPath());
c.getPieces().add(checkForNoChange(binding, gen.new Piece(null, "Binding: ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(binding, gen.new Piece(br.url == null ? null : Utilities.isAbsoluteUrl(br.url) || !pkp.prependLinks() ? br.url : corePath + br.url, br.display, null)));
if (binding.hasStrength()) {
c.getPieces().add(checkForNoChange(binding, gen.new Piece(null, " (", null)));
c.getPieces().add(checkForNoChange(binding, gen.new Piece(corePath + "terminologies.html#" + binding.getStrength().toCode(), binding.getStrength().toCode(), binding.getStrength().getDefinition())));
c.getPieces().add(gen.new Piece(null, ")", null));
}
}
for (ElementDefinitionConstraintComponent inv : definition.getConstraint()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, inv.getKey() + ": ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, inv.getHuman(), null)));
}
if (definition.hasFixed()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "Fixed Value: ", null).addStyle("font-weight:bold")));
String s = buildJson(definition.getFixed());
String link = null;
if (Utilities.isAbsoluteUrl(s))
link = pkp.getLinkForUrl(corePath, s);
c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(link, s, null).addStyle("color: darkgreen")));
} else if (definition.hasPattern()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, "Required Pattern: ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, buildJson(definition.getPattern()), null).addStyle("color: darkgreen")));
} else if (definition.hasExample()) {
for (ElementDefinitionExampleComponent ex : definition.getExample()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(ex, gen.new Piece(null, "Example'" + ("".equals("General") ? "" : " " + ex.getLabel() + "'") + ": ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(ex, gen.new Piece(null, buildJson(ex.getValue()), null).addStyle("color: darkgreen")));
}
}
if (definition.hasMaxLength() && definition.getMaxLength() != 0) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(definition.getMaxLengthElement(), gen.new Piece(null, "Max Length: ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(definition.getMaxLengthElement(), gen.new Piece(null, Integer.toString(definition.getMaxLength()), null).addStyle("color: darkgreen")));
}
if (profile != null) {
for (StructureDefinitionMappingComponent md : profile.getMapping()) {
if (md.hasExtension(ToolingExtensions.EXT_TABLE_NAME)) {
ElementDefinitionMappingComponent map = null;
for (ElementDefinitionMappingComponent m : definition.getMapping()) if (m.getIdentity().equals(md.getIdentity()))
map = m;
if (map != null) {
for (int i = 0; i < definition.getMapping().size(); i++) {
c.addPiece(gen.new Piece("br"));
c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(md, ToolingExtensions.EXT_TABLE_NAME) + ": " + map.getMap(), null));
}
}
}
}
}
if (definition.hasDefinition()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(gen.new Piece(null, "Definition: ", null).addStyle("font-weight:bold"));
c.addPiece(gen.new Piece("br"));
c.addMarkdown(definition.getDefinition());
// c.getPieces().add(checkForNoChange(definition.getCommentElement(), gen.new Piece(null, definition.getComment(), null)));
}
if (definition.getComment() != null) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(gen.new Piece(null, "Comments: ", null).addStyle("font-weight:bold"));
c.addPiece(gen.new Piece("br"));
c.addMarkdown(definition.getComment());
// c.getPieces().add(checkForNoChange(definition.getCommentElement(), gen.new Piece(null, definition.getComment(), null)));
}
}
}
}
return c;
}
use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project org.hl7.fhir.core by hapifhir.
the class ProfileComparer method unionBindings.
private ElementDefinitionBindingComponent unionBindings(ElementDefinition ed, ProfileComparison outcome, String path, ElementDefinitionBindingComponent left, ElementDefinitionBindingComponent right) throws FHIRFormatError {
ElementDefinitionBindingComponent union = new ElementDefinitionBindingComponent();
if (left.getStrength().compareTo(right.getStrength()) < 0)
union.setStrength(left.getStrength());
else
union.setStrength(right.getStrength());
union.setDescription(mergeText(ed, outcome, path, "binding.description", left.getDescription(), right.getDescription()));
if (Base.compareDeep(left.getValueSet(), right.getValueSet(), false))
union.setValueSet(left.getValueSet());
else {
ValueSet lvs = resolveVS(outcome.left, left.getValueSet());
ValueSet rvs = resolveVS(outcome.left, right.getValueSet());
if (lvs != null && rvs != null)
union.setValueSet("#" + addValueSet(unite(ed, outcome, path, lvs, rvs)));
else if (lvs != null)
union.setValueSet("#" + addValueSet(lvs));
else if (rvs != null)
union.setValueSet("#" + addValueSet(rvs));
}
return union;
}
use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project kindling by HL7.
the class CDAGenerator method processProperty.
private void processProperty(List<ElementDefinition> list, String dtn, Element prop, String param) throws FHIRFormatError {
ElementDefinition ed = new ElementDefinition();
String n = prop.getAttribute("name");
PropStatus p = getPropStatus(dtn, n);
if (p == PropStatus.IGNORE)
return;
if (prop.hasAttribute("fixedValue") && prop.getAttribute("fixedValue").startsWith("NullFlavor."))
return;
ed.setPath(dtn + "." + n);
seePath(ed);
ed.setDefinition(getDefinition(prop));
ed.setComment(getDesignComments(prop));
ed.setLabel(XMLUtil.getNamedChildAttribute(prop, "mif:businessName", "name"));
ed.setMin(Integer.parseInt(prop.getAttribute("minimumMultiplicity")));
ed.setMax(prop.getAttribute("maximumMultiplicity"));
String t = getType(prop);
if (primitiveTypes.containsKey(t) && p == PropStatus.ATTRIBUTE)
ed.addType().setCode(primitiveTypes.get(t));
else if (Utilities.existsInList(t, "UID"))
ed.addType().setCode("string");
else if (t.equals("T") && param != null)
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/" + param);
else if (t.equals("N") && param != null)
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/" + param);
else if (t.equals("D") && param != null)
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/" + param);
else if (t.equals("QTY") && param != null)
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/PQ");
else if (t.equals("IVL_T"))
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/IVL_TS");
else if ("GTS".equals(t)) {
ed.setMax("*");
ed.addRepresentation(PropertyRepresentation.TYPEATTR);
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/IVL_TS");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/EIVL_TS");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/PIVL_TS");
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/SXPR_TS");
ed.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-defaulttype").setValue(new StringType("SXPR_TS"));
} else
ed.addType().setCode("http://hl7.org/fhir/cda/StructureDefinition/" + t);
if (p == PropStatus.ATTRIBUTE)
ed.addRepresentation(PropertyRepresentation.XMLATTR);
// special stuff
String vs = getValueSet(dtn, n);
if (vs != null) {
ed.setBinding(new ElementDefinitionBindingComponent().setStrength(BindingStrength.REQUIRED).setValueSet("http://terminology.hl7.org/ValueSet/v3-" + vs));
v3vs.add(vs);
}
list.add(ed);
}
Aggregations