use of org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetRenderer method renderExpandGroup.
private void renderExpandGroup(HierarchicalTableGenerator gen, TableModel model, Extension ext, ConceptSetComponent inc, Map<String, ConceptDefinitionComponent> definitions) {
Row row = gen.new Row();
model.getRows().add(row);
row.setIcon("icon_entry_blue.png", "entry");
String code = ext.getExtensionString("code");
if (code != null) {
row.getCells().add(gen.new Cell(null, null, code, null, null));
row.getCells().add(gen.new Cell(null, null, getDisplayForCode(inc, code, definitions), null, null));
} else if (ext.hasId()) {
row.getCells().add(gen.new Cell(null, null, "(#" + ext.getId() + ")", null, null));
row.getCells().add(gen.new Cell(null, null, ext.getExtensionString("display"), null, null));
} else {
row.getCells().add(gen.new Cell(null, null, null, null, null));
row.getCells().add(gen.new Cell(null, null, ext.getExtensionString("display"), null, null));
}
for (Extension member : ext.getExtensionsByUrl("member")) {
Row subRow = gen.new Row();
row.getSubRows().add(subRow);
subRow.setIcon("icon_entry_blue.png", "entry");
String mc = member.getValue().primitiveValue();
// mc might be a reference to another expansion group - we check that first, or to a code in the compose
if (mc.startsWith("#")) {
// it's a reference by id
subRow.getCells().add(gen.new Cell(null, null, "(" + mc + ")", null, null));
subRow.getCells().add(gen.new Cell(null, null, "group reference by id", null, null));
} else {
Extension tgt = findTargetByCode(inc, mc);
if (tgt != null) {
subRow.getCells().add(gen.new Cell(null, null, mc, null, null));
subRow.getCells().add(gen.new Cell(null, null, "group reference by code", null, null));
} else {
subRow.getCells().add(gen.new Cell(null, null, mc, null, null));
subRow.getCells().add(gen.new Cell(null, null, getDisplayForCode(inc, mc, definitions), null, null));
}
}
}
}
use of org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent 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 doDesignations, List<UsedConceptMap> maps, Map<String, String> designations, int index) throws FHIRException, IOException {
boolean hasExtensions = false;
XhtmlNode li;
li = ul.li();
CodeSystem e = getContext().getWorker().fetchCodeSystem(inc.getSystem());
Map<String, ConceptDefinitionComponent> definitions = new HashMap<>();
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
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, designations, doDesignations), 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 (doDesignations) {
addDesignationsToRow(c, designations, tr);
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);
}
}
if (inc.hasExtension(ToolingExtensions.EXT_EXPAND_RULES) || inc.hasExtension(ToolingExtensions.EXT_EXPAND_GROUP)) {
hasExtensions = true;
renderExpansionRules(li, inc, index, definitions);
}
} 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.model.CodeSystem.ConceptDefinitionComponent in project redmatch by aehrc.
the class RedmatchGrammarCodeSystemGenerator method createBaseCodeSystem.
private CodeSystem createBaseCodeSystem(VersionedFhirPackage fhirPackage) {
CodeSystem cs = new CodeSystem();
cs.setId("redmatch-" + fhirPackage.getName());
cs.setUrl("http://redmatch." + fhirPackage.getName());
cs.setVersion(fhirPackage.getVersion());
cs.setName("Redmatch Validation Code System for " + fhirPackage.getName());
cs.setStatus(PublicationStatus.ACTIVE);
cs.setDescription("A code system with all the valid paths used to refer to attributes of resources in " + fhirPackage.getName());
cs.setValueSet("http://redmatch." + fhirPackage.getName() + "?vs");
cs.setHierarchyMeaning(CodeSystemHierarchyMeaning.ISA);
cs.setContent(CodeSystemContentMode.COMPLETE);
cs.setExperimental(false);
cs.setCompositional(false);
cs.setVersionNeeded(false);
cs.addProperty().setCode("parent").setDescription("Parent codes.").setType(PropertyType.CODE);
cs.addProperty().setCode("root").setDescription("Indicates if this concept is a root concept.").setType(PropertyType.BOOLEAN);
cs.addProperty().setCode("deprecated").setDescription("Indicates if this concept is deprecated.").setType(PropertyType.BOOLEAN);
cs.addProperty().setCode("parentResourceOrProfile").setDescription("If this concept represents an attribute then this property represents the resource or profile" + "that contains the attribute. If this concepts is a profile or resource then the parent resource is Object.").setType(PropertyType.CODE);
cs.addProperty().setCode("min").setDescription("Minimum cardinality").setType(PropertyType.INTEGER);
cs.addProperty().setCode("max").setDescription("Maximum cardinality").setType(PropertyType.STRING);
cs.addProperty().setCode("type").setDescription("Data type for this element.").setType(PropertyType.STRING);
cs.addProperty().setCode("targetProfile").setDescription("If this code represents a Reference attribute, contains an allowed target profile.").setType(PropertyType.STRING);
cs.addProperty().setCode("profile").setDescription("Indicates if this code represents a profile.").setType(PropertyType.BOOLEAN);
cs.addProperty().setCode("baseResource").setDescription("For profiles, indicates the resource the profile constrains.").setType(PropertyType.CODE);
cs.addProperty().setCode("extensionUrl").setDescription("If this code represents an extension, then this is its url.").setType(PropertyType.STRING);
cs.addProperty().setCode("profileUrl").setDescription("If this code represents a profile, then this is its url.").setType(PropertyType.STRING);
cs.addFilter().setCode("root").setValue("True or false.").addOperator(FilterOperator.EQUAL);
cs.addFilter().setCode("deprecated").setValue("True or false.").addOperator(FilterOperator.EQUAL);
cs.addFilter().setCode("parentResourceOrProfile").setValue("The parent resource or profile code.").addOperator(FilterOperator.EQUAL);
cs.addFilter().setCode("profile").setValue("True or false.").addOperator(FilterOperator.EQUAL);
// Create root concept
ConceptDefinitionComponent objectRoot = cs.addConcept().setCode("Object").setDisplay("Object");
objectRoot.addProperty().setCode("root").setValue(new BooleanType(true));
objectRoot.addProperty().setCode("deprecated").setValue(new BooleanType(false));
ConceptDefinitionComponent complexTypeRoot = cs.addConcept().setCode("ComplexType").setDisplay("ComplexType");
complexTypeRoot.addProperty().setCode("root").setValue(new BooleanType(false));
complexTypeRoot.addProperty().setCode("deprecated").setValue(new BooleanType(false));
complexTypeRoot.addProperty().setCode("parent").setValue(new CodeType("Object"));
ConceptDefinitionComponent resourceRoot = cs.addConcept().setCode("Resource").setDisplay("Resource");
resourceRoot.addProperty().setCode("root").setValue(new BooleanType(false));
resourceRoot.addProperty().setCode("deprecated").setValue(new BooleanType(false));
resourceRoot.addProperty().setCode("parent").setValue(new CodeType("Object"));
ConceptDefinitionComponent profileRoot = cs.addConcept().setCode("Profile").setDisplay("Profile");
profileRoot.addProperty().setCode("root").setValue(new BooleanType(false));
profileRoot.addProperty().setCode("deprecated").setValue(new BooleanType(false));
profileRoot.addProperty().setCode("parent").setValue(new CodeType("Object"));
return cs;
}
use of org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent in project synthea by synthetichealth.
the class ValidationSupportR4 method lookupCode.
@Override
public LookupCodeResult lookupCode(ValidationSupportContext theValidationSupportContext, String theSystem, String theCode, String theDisplayLanguage) {
LookupCodeResult result = new LookupCodeResult();
result.setSearchedForCode(theCode);
result.setSearchedForSystem(theSystem);
result.setFound(false);
CodeSystem cs = (CodeSystem) this.fetchCodeSystem(theSystem);
if (cs != null) {
for (ConceptDefinitionComponent cdc : cs.getConcept()) {
if (conceptContainsCode(cdc, theCode)) {
result.setFound(true);
}
}
}
return result;
}
use of org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent in project elexis-server by elexis.
the class CodeSystemTest method getCodeSystemProperties.
@Test
public void getCodeSystemProperties() {
// tessinercode
CodeSystem readCodeSystem = client.read().resource(CodeSystem.class).withId("tessinercode").execute();
assertNotNull(readCodeSystem);
assertEquals(CodingSystem.ELEXIS_DIAGNOSE_TESSINERCODE.getSystem(), readCodeSystem.getUrl());
Optional<ConceptDefinitionComponent> concept = getConceptFromSytem("A1", readCodeSystem);
assertTrue(concept.isPresent());
// coveragetype
readCodeSystem = client.read().resource(CodeSystem.class).withId("coveragetype").execute();
assertNotNull(readCodeSystem);
assertEquals(CodingSystem.ELEXIS_COVERAGE_TYPE.getSystem(), readCodeSystem.getUrl());
concept = getConceptFromSytem("KVG", readCodeSystem);
assertTrue(concept.isPresent());
}
Aggregations