use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method genInclude.
private boolean genInclude(ResourceContext rcontext, XhtmlNode ul, ConceptSetComponent inc, String type, List<String> langs) throws FHIRException {
boolean hasExtensions = false;
XhtmlNode li;
li = ul.li();
CodeSystem e = context.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);
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);
hasDefinition = hasDefinition || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_DEFINITION);
}
if (hasComments || hasDefinition)
hasExtensions = true;
addTableHeaderRowStandard(t, false, true, hasDefinition, hasComments, false);
for (ConceptReferenceComponent c : inc.getConcept()) {
XhtmlNode tr = t.tr();
XhtmlNode td = tr.td();
ConceptDefinitionComponent cc = getConceptForCode(e, c.getCode(), inc);
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());
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 (ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_VS_COMMENT)) {
smartAddText(tr.td(), "Note: " + ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_VS_COMMENT));
}
for (ConceptReferenceDesignationComponent cd : c.getDesignation()) {
if (cd.hasLanguage() && !langs.contains(cd.getLanguage()))
langs.add(cd.getLanguage());
}
}
}
boolean first = true;
for (ConceptSetFilterComponent f : inc.getFilter()) {
if (first) {
li.addText(type + " codes from ");
first = false;
} else
li.tx(" and ");
addCsRef(inc, li, e);
li.tx(" where " + f.getProperty() + " " + describe(f.getOp()) + " ");
if (e != null && codeExistsInValueSet(e, f.getValue())) {
String href = prefix + 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 = context.validateCode(inc.getSystem(), 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(rcontext, vs.asStringValue(), li);
}
}
} else {
li = ul.li();
li.tx("Import all the codes that are contained in ");
boolean first = true;
for (UriType vs : inc.getValueSet()) {
if (first)
first = false;
else
li.tx(", ");
AddVsRef(rcontext, vs.asStringValue(), li);
}
}
return hasExtensions;
}
use of org.hl7.v3.CD 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>();
if (options.getValueSetMode() != ValueSetMode.CHECK_MEMERSHIP_ONLY) {
for (Coding c : code.getCoding()) {
if (!c.hasSystem()) {
warnings.add(context.formatMessage(I18nConstants.CODING_HAS_NO_SYSTEM__CANNOT_VALIDATE));
}
CodeSystem cs = resolveCodeSystem(c.getSystem());
ValidationResult res = null;
if (cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE) {
res = context.validateCode(options.noClient(), c, null);
} else {
res = validateCode(c, cs);
}
if (!res.isOk()) {
errors.add(res.getMessage());
} else if (res.getMessage() != null) {
warnings.add(res.getMessage());
}
}
}
Coding foundCoding = null;
if (valueset != null && options.getValueSetMode() != ValueSetMode.NO_MEMBERSHIP_CHECK) {
Boolean result = false;
for (Coding c : code.getCoding()) {
Boolean ok = codeInValueSet(c.getSystem(), c.getCode(), warnings);
if (ok == null && result == false) {
result = null;
} else if (ok) {
result = true;
foundCoding = c;
}
}
if (result == null) {
warnings.add(0, context.formatMessage(I18nConstants.UNABLE_TO_CHECK_IF_THE_PROVIDED_CODES_ARE_IN_THE_VALUE_SET_, valueset.getUrl()));
} else if (!result) {
errors.add(0, context.formatMessage(I18nConstants.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 {
ConceptDefinitionComponent cd = new ConceptDefinitionComponent(foundCoding.getCode());
cd.setDisplay(foundCoding.getDisplay());
return new ValidationResult(foundCoding.getSystem(), cd);
}
}
use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method addLanguageRow.
private void addLanguageRow(ConceptReferenceComponent c, XhtmlNode t, List<String> langs) {
XhtmlNode tr = t.tr();
tr.td().addText(c.getCode());
for (String lang : langs) {
String d = null;
for (ConceptReferenceDesignationComponent cd : c.getDesignation()) {
String l = cd.getLanguage();
if (lang.equals(l))
d = cd.getValue();
}
tr.td().addText(d == null ? "" : d);
}
}
use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.
the class CapabilityStatementComparer method intersectCodeableConcepts.
private void intersectCodeableConcepts(List<CodeableConcept> tgt, List<CodeableConcept> src) {
List<CodeableConcept> toRemove = new ArrayList<CodeableConcept>();
for (CodeableConcept cd : src) {
boolean remove = false;
for (CodeableConcept t : tgt) {
if (t.matches(cd)) {
remove = true;
}
}
if (remove) {
toRemove.add(cd);
}
}
tgt.removeAll(toRemove);
}
use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.
the class CodeSystemComparer method getProp.
public ConceptPropertyComponent getProp(ConceptDefinitionComponent cd, PropertyComponent p, boolean right, CodeSystemComparison comp) {
String c = p.getCode();
if (right) {
c = comp.getPropMap().get(c);
}
ConceptPropertyComponent cp = null;
if (cd != null) {
for (ConceptPropertyComponent t : cd.getProperty()) {
if (t.getCode().equals(c)) {
cp = t;
}
}
}
return cp;
}
Aggregations