rendering improvements for deprecated codes

This commit is contained in:
Grahame Grieve 2022-12-09 23:28:58 +11:00
parent 7c2c44b333
commit dd7ca2182a
4 changed files with 54 additions and 3 deletions

View File

@ -316,6 +316,11 @@ public class CodeSystemRenderer extends TerminologyRenderer {
private boolean addDefineRowToTable(XhtmlNode t, ConceptDefinitionComponent c, int level, boolean hasHierarchy, boolean hasDisplay, boolean hasDefinitions, boolean comment, boolean version, boolean deprecated, List<UsedConceptMap> maps, String system, CodeSystem cs, List<PropertyComponent> properties, CodeSystemNavigator csNav, List<String> langs, boolean isSupplement) throws FHIRFormatError, DefinitionException, IOException {
boolean hasExtensions = false;
XhtmlNode tr = t.tr();
boolean notCurrent = CodeSystemUtilities.isNotCurrent(cs, c);
if (notCurrent) {
tr.setAttribute("style", "background-color: #ffeeee");
}
XhtmlNode td = tr.td();
if (hasHierarchy) {
td.addText(Integer.toString(level+1));
@ -392,6 +397,14 @@ public class CodeSystemRenderer extends TerminologyRenderer {
td.tx(": "+cc.getDisplay()+")");
} else
td.addText(cc.getCode()+" '"+cc.getDisplay()+"' in "+cc.getSystem()+")");
} else {
Extension ext = c.getExtensionByUrl(ToolingExtensions.EXT_STANDARDS_STATUS);
if (ext != null) {
ext = ext.getValue().getExtensionByUrl(ToolingExtensions.EXT_STANDARDS_STATUS_REASON);
if (ext != null) {
addMarkdown(td, ext.getValue().primitiveValue());
}
}
}
}
}

View File

@ -44,6 +44,7 @@ import org.hl7.fhir.r5.renderers.utils.RenderingContext.GenerationRules;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities;
import org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome;
import org.hl7.fhir.r5.terminologies.ValueSetUtilities;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.LoincLinker;
import org.hl7.fhir.utilities.Utilities;
@ -249,7 +250,7 @@ public class ValueSetRenderer extends TerminologyRenderer {
addMapHeaders(tr, maps);
for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
addExpansionRowToTable(t, c, 1, doLevel, true, doDefinition, maps, allCS, langs, designations, doDesignations, properties);
addExpansionRowToTable(t, vs, c, 1, doLevel, true, doDefinition, maps, allCS, langs, designations, doDesignations, properties);
}
// now, build observed languages
@ -742,8 +743,12 @@ public class ValueSetRenderer extends TerminologyRenderer {
}
}
private void addExpansionRowToTable(XhtmlNode t, ValueSetExpansionContainsComponent c, int i, boolean doLevel, boolean doSystem, boolean doDefinition, List<UsedConceptMap> maps, CodeSystem allCS, List<String> langs, Map<String, String> designations, boolean doDesignations, Map<String, String> properties) throws FHIRFormatError, DefinitionException, IOException {
private void addExpansionRowToTable(XhtmlNode t, ValueSet vs, ValueSetExpansionContainsComponent c, int i, boolean doLevel, boolean doSystem, boolean doDefinition, List<UsedConceptMap> maps, CodeSystem allCS, List<String> langs, Map<String, String> designations, boolean doDesignations, Map<String, String> properties) throws FHIRFormatError, DefinitionException, IOException {
XhtmlNode tr = t.tr();
if (ValueSetUtilities.isDeprecated(vs, c)) {
tr.setAttribute("style", "background-color: #ffeeee");
}
XhtmlNode td = tr.td();
String tgt = makeAnchor(c.getSystem(), c.getCode());
@ -801,7 +806,7 @@ public class ValueSetRenderer extends TerminologyRenderer {
addLangaugesToRow(c, langs, tr);
}
for (ValueSetExpansionContainsComponent cc : c.getContains()) {
addExpansionRowToTable(t, cc, i+1, doLevel, doSystem, doDefinition, maps, allCS, langs, designations, doDesignations, properties);
addExpansionRowToTable(t, vs, cc, i+1, doLevel, doSystem, doDefinition, maps, allCS, langs, designations, doDesignations, properties);
}
}

View File

@ -320,6 +320,10 @@ public class CodeSystemUtilities {
if ("deprecated".equals(p.getCode()) && p.hasValue() && p.getValue() instanceof BooleanType)
return ((BooleanType) p.getValue()).getValue();
}
StandardsStatus ss = ToolingExtensions.getStandardsStatus(def);
if (ss == StandardsStatus.DEPRECATED) {
return true;
}
return false;
} catch (FHIRException e) {
return false;
@ -670,5 +674,9 @@ public class CodeSystemUtilities {
}
return null;
}
public static boolean isNotCurrent(CodeSystem cs, ConceptDefinitionComponent c) {
return isInactive(cs, c) || isDeprecated(cs, c, false);
}
}

View File

@ -1,5 +1,6 @@
package org.hl7.fhir.r5.terminologies;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@ -48,6 +49,7 @@ import org.hl7.fhir.r5.model.Meta;
import org.hl7.fhir.r5.model.UriType;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent;
import org.hl7.fhir.r5.model.CodeSystem.ConceptPropertyComponent;
import org.hl7.fhir.r5.model.CodeType;
import org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent;
import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent;
@ -286,5 +288,28 @@ public class ValueSetUtilities {
return null;
}
public static boolean isDeprecated(ValueSet vs, ValueSetExpansionContainsComponent c) {
try {
for (org.hl7.fhir.r5.model.ValueSet.ConceptPropertyComponent p : c.getProperty()) {
if ("status".equals(p.getCode()) && p.hasValue() && p.hasValueCodeType() && "deprecated".equals(p.getValueCodeType().getCode())) {
return true;
}
// this, though status should also be set
if ("deprecationDate".equals(p.getCode()) && p.hasValue() && p.getValue() instanceof DateTimeType)
return ((DateTimeType) p.getValue()).before(new DateTimeType(Calendar.getInstance()));
// legacy
if ("deprecated".equals(p.getCode()) && p.hasValue() && p.getValue() instanceof BooleanType)
return ((BooleanType) p.getValue()).getValue();
}
StandardsStatus ss = ToolingExtensions.getStandardsStatus(c);
if (ss == StandardsStatus.DEPRECATED) {
return true;
}
return false;
} catch (FHIRException e) {
return false;
}
}
}