fix rendering of type for previous versions

This commit is contained in:
Grahame Grieve 2023-12-14 07:20:21 -05:00
parent ceaa131d81
commit 75a3c325ef
1 changed files with 17 additions and 4 deletions

View File

@ -6,6 +6,7 @@ import java.io.UnsupportedEncodingException;
import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.model.CodeType; import org.hl7.fhir.r5.model.CodeType;
import org.hl7.fhir.r5.model.Enumeration; import org.hl7.fhir.r5.model.Enumeration;
import org.hl7.fhir.r5.model.Enumerations.FHIRTypes;
import org.hl7.fhir.r5.model.Enumerations.VersionIndependentResourceTypesAll; import org.hl7.fhir.r5.model.Enumerations.VersionIndependentResourceTypesAll;
import org.hl7.fhir.r5.model.Extension; import org.hl7.fhir.r5.model.Extension;
import org.hl7.fhir.r5.model.OperationDefinition; import org.hl7.fhir.r5.model.OperationDefinition;
@ -21,6 +22,7 @@ import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.StandardsStatus; import org.hl7.fhir.utilities.StandardsStatus;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.xhtml.XhtmlNode; import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class OperationDefinitionRenderer extends TerminologyRenderer { public class OperationDefinitionRenderer extends TerminologyRenderer {
@ -122,9 +124,10 @@ public class OperationDefinitionRenderer extends TerminologyRenderer {
} }
tr.td().addText(Integer.toString(p.getMin())+".."+p.getMax()); tr.td().addText(Integer.toString(p.getMin())+".."+p.getMax());
td = tr.td(); td = tr.td();
StructureDefinition sd = p.getType() != null ? context.getWorker().fetchTypeDefinition(p.getType().toCode()) : null; String actualType = translateTypeToVersion(p.getTypeElement());
StructureDefinition sd = actualType != null ? context.getWorker().fetchTypeDefinition(actualType) : null;
if (sd == null) if (sd == null)
td.tx(p.hasType() ? p.getType().toCode() : ""); td.tx(p.hasType() ? actualType : "");
else if (sd.getAbstract() && p.hasExtension(ToolingExtensions.EXT_ALLOWED_TYPE)) { else if (sd.getAbstract() && p.hasExtension(ToolingExtensions.EXT_ALLOWED_TYPE)) {
boolean first = true; boolean first = true;
for (Extension ex : p.getExtensionsByUrl(ToolingExtensions.EXT_ALLOWED_TYPE)) { for (Extension ex : p.getExtensionsByUrl(ToolingExtensions.EXT_ALLOWED_TYPE)) {
@ -132,12 +135,12 @@ public class OperationDefinitionRenderer extends TerminologyRenderer {
String s = ex.getValue().primitiveValue(); String s = ex.getValue().primitiveValue();
StructureDefinition sdt = context.getWorker().fetchTypeDefinition(s); StructureDefinition sdt = context.getWorker().fetchTypeDefinition(s);
if (sdt == null) if (sdt == null)
td.tx(p.hasType() ? p.getType().toCode() : ""); td.tx(p.hasType() ? actualType : "");
else else
td.ah(sdt.getWebPath()).tx(s); td.ah(sdt.getWebPath()).tx(s);
} }
} else } else
td.ah(sd.getWebPath()).tx(p.hasType() ? p.getType().toCode() : ""); td.ah(sd.getWebPath()).tx(actualType);
if (p.hasSearchType()) { if (p.hasSearchType()) {
td.br(); td.br();
td.tx("("); td.tx("(");
@ -156,6 +159,16 @@ public class OperationDefinitionRenderer extends TerminologyRenderer {
} }
} }
} }
public static final String EXT_OPDEF_ORIGINAL_TYPE = "http://hl7.org/fhir/4.0/StructureDefinition/extension-OperationDefinition.parameter.type";
private String translateTypeToVersion(Enumeration<FHIRTypes> src) {
if (src.hasExtension(EXT_OPDEF_ORIGINAL_TYPE)) {
return src.getExtensionString(EXT_OPDEF_ORIGINAL_TYPE);
} else {
return src.asStringValue();
}
}
} }