Fix up StructureMap R4/R5 conversion

This commit is contained in:
Grahame Grieve 2023-05-01 18:08:35 +10:00
parent 03a1271508
commit 89c1c8608c
6 changed files with 44 additions and 83 deletions

View File

@ -801,25 +801,17 @@ public class StructureMap40_50 {
return tgt;
}
public static org.hl7.fhir.r5.model.DataType convertVariableStringToParameterDataType(org.hl7.fhir.r4.model.StringType it) {
org.hl7.fhir.r4.model.Extension originalElementType = it.getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE);
return originalElementType != null ? convertVariableStringToParameterDataType(it, originalElementType) : convertVariableStringToGuessedParameterDataType(it);
}
public static org.hl7.fhir.r5.model.DataType convertVariableStringToParameterDataType(org.hl7.fhir.r4.model.StringType it, org.hl7.fhir.r4.model.Extension originalElementType) {
if (!(originalElementType.getValue() instanceof org.hl7.fhir.r4.model.UrlType)) {
throw new FHIRException("");
}
org.hl7.fhir.r4.model.UrlType url = (org.hl7.fhir.r4.model.UrlType)originalElementType.getValue();
switch (url.getValueAsString()) {
case "id" : return it.hasValue() ? new org.hl7.fhir.r5.model.IdType(it.getValueAsString()) : new org.hl7.fhir.r5.model.IdType();
case "string" : return it.hasValue() ? new org.hl7.fhir.r5.model.StringType(it.getValueAsString()) : new org.hl7.fhir.r5.model.StringType();
case "integer" : return it.hasValue() ? new org.hl7.fhir.r5.model.IntegerType(it.getValueAsString()) : new org.hl7.fhir.r5.model.IntegerType();
case "decimal" : return it.hasValue() ? new org.hl7.fhir.r5.model.DecimalType(it.getValueAsString()) : new org.hl7.fhir.r5.model.DecimalType();
case "boolean" : return it.hasValue() ? new org.hl7.fhir.r5.model.BooleanType(it.getValueAsString()) : new org.hl7.fhir.r5.model.BooleanType();
}
return null;
public static org.hl7.fhir.r5.model.DataType convertVariableStringToParameterDataType(org.hl7.fhir.r4.model.StringType src) {
if (src.hasExtension(ToolingExtensions.EXT_ORIGINAL_VARIABLE_TYPE)) {
return ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_VARIABLE_TYPE).getValue());
} else {
org.hl7.fhir.r5.model.IdType tgt = new org.hl7.fhir.r5.model.IdType();
ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
if (src.hasValue()) {
tgt.setValueAsString(src.getValueAsString());
}
return tgt;
}
}
public static org.hl7.fhir.r5.model.DataType convertVariableStringToGuessedParameterDataType(org.hl7.fhir.r4.model.StringType it) {
@ -860,24 +852,12 @@ public class StructureMap40_50 {
public static org.hl7.fhir.r4.model.StringType convertStructureMapGroupRuleTargetParameterComponentToString(StructureMapGroupRuleTargetParameterComponent src) {
org.hl7.fhir.r4.model.StringType tgt = new org.hl7.fhir.r4.model.StringType();
org.hl7.fhir.instance.model.api.IPrimitiveType primitiveType;
if (src.hasValueIdType()) {
primitiveType = src.getValueIdType();
} else if (src.hasValueStringType()) {
primitiveType = src.getValueStringType();
} else if (src.hasValueIntegerType()) {
primitiveType = src.getValueIntegerType();
} else if (src.hasValueDecimalType()) {
primitiveType = src.getValueDecimalType();
} else if (src.hasValueBooleanType()) {
primitiveType = src.getValueBooleanType();
} else {
throw new FHIRException("Unrecognized primitive type");
}
tgt.setValueAsString(primitiveType.getValueAsString());
ToolingExtensions.addUrlExtension(tgt, ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE, primitiveType.fhirType());
ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
if (src.hasValueIdType()) {
tgt.setValueAsString(src.getValueIdType().getValueAsString());
} else if (src.hasValue()) {
tgt.addExtension(ToolingExtensions.EXT_ORIGINAL_VARIABLE_TYPE,ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getValue()));
}
return tgt;
}
}

View File

@ -2,6 +2,7 @@ package org.hl7.fhir.convertors.conv43_50.resources43_50;
import java.util.stream.Collectors;
import org.hl7.fhir.convertors.context.ConversionContext40_50;
import org.hl7.fhir.convertors.context.ConversionContext43_50;
import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.CodeableConcept43_50;
import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.Identifier43_50;
@ -801,25 +802,17 @@ public class StructureMap43_50 {
return tgt;
}
public static org.hl7.fhir.r5.model.DataType convertVariableStringToParameterDataType(org.hl7.fhir.r4b.model.StringType it) {
org.hl7.fhir.r4b.model.Extension originalElementType = it.getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE);
return originalElementType != null ? convertVariableStringToParameterDataType(it, originalElementType) : convertVariableStringToGuessedParameterDataType(it);
}
public static org.hl7.fhir.r5.model.DataType convertVariableStringToParameterDataType(org.hl7.fhir.r4b.model.StringType it, org.hl7.fhir.r4b.model.Extension originalElementType) {
if (!(originalElementType.getValue() instanceof org.hl7.fhir.r4b.model.UrlType)) {
throw new FHIRException("");
}
org.hl7.fhir.r4b.model.UrlType url = (org.hl7.fhir.r4b.model.UrlType)originalElementType.getValue();
switch (url.getValueAsString()) {
case "id" : return it.hasValue() ? new org.hl7.fhir.r5.model.IdType(it.getValueAsString()) : new org.hl7.fhir.r5.model.IdType();
case "string" : return it.hasValue() ? new org.hl7.fhir.r5.model.StringType(it.getValueAsString()) : new org.hl7.fhir.r5.model.StringType();
case "integer" : return it.hasValue() ? new org.hl7.fhir.r5.model.IntegerType(it.getValueAsString()) : new org.hl7.fhir.r5.model.IntegerType();
case "decimal" : return it.hasValue() ? new org.hl7.fhir.r5.model.DecimalType(it.getValueAsString()) : new org.hl7.fhir.r5.model.DecimalType();
case "boolean" : return it.hasValue() ? new org.hl7.fhir.r5.model.BooleanType(it.getValueAsString()) : new org.hl7.fhir.r5.model.BooleanType();
}
return null;
public static org.hl7.fhir.r5.model.DataType convertVariableStringToParameterDataType(org.hl7.fhir.r4b.model.StringType src) {
if (src.hasExtension(ToolingExtensions.EXT_ORIGINAL_VARIABLE_TYPE)) {
return ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().convertType(src.getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_VARIABLE_TYPE).getValue());
} else {
org.hl7.fhir.r5.model.IdType tgt = new org.hl7.fhir.r5.model.IdType();
ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt);
if (src.hasValue()) {
tgt.setValueAsString(src.getValueAsString());
}
return tgt;
}
}
public static org.hl7.fhir.r5.model.DataType convertVariableStringToGuessedParameterDataType(org.hl7.fhir.r4b.model.StringType it) {
@ -860,24 +853,12 @@ public class StructureMap43_50 {
public static org.hl7.fhir.r4b.model.StringType convertStructureMapGroupRuleTargetParameterComponentToString(StructureMapGroupRuleTargetParameterComponent src) {
org.hl7.fhir.r4b.model.StringType tgt = new org.hl7.fhir.r4b.model.StringType();
org.hl7.fhir.instance.model.api.IPrimitiveType primitiveType;
if (src.hasValueIdType()) {
primitiveType = src.getValueIdType();
} else if (src.hasValueStringType()) {
primitiveType = src.getValueStringType();
} else if (src.hasValueIntegerType()) {
primitiveType = src.getValueIntegerType();
} else if (src.hasValueDecimalType()) {
primitiveType = src.getValueDecimalType();
} else if (src.hasValueBooleanType()) {
primitiveType = src.getValueBooleanType();
} else {
throw new FHIRException("Unrecognized primitive type");
}
tgt.setValueAsString(primitiveType.getValueAsString());
ToolingExtensions.addUrlExtension(tgt, ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE, primitiveType.fhirType());
ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt);
if (src.hasValueIdType()) {
tgt.setValueAsString(src.getValueIdType().getValueAsString());
} else if (src.hasValue()) {
tgt.addExtension(ToolingExtensions.EXT_ORIGINAL_VARIABLE_TYPE,ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().convertType(src.getValue()));
}
return tgt;
}
}

View File

@ -79,11 +79,11 @@ class Convertor_Factory_40_50Test {
assertEquals("item", mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(0).getValueAsString());
assertEquals("patient", mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(1).getValueAsString());
assertEquals("url", mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(0).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE).getValue().fhirType());
assertEquals("url", mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(1).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE).getValue().fhirType());
assertNull(mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(0).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_VARIABLE_TYPE));
assertNull(mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(1).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_VARIABLE_TYPE));
assertEquals("id", ((org.hl7.fhir.r4.model.UrlType)mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(0).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE).getValue()).getValueAsString());
assertEquals("id", ((org.hl7.fhir.r4.model.UrlType)mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(1).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE).getValue()).getValueAsString());
assertEquals("item", mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(0).getValueAsString());
assertEquals("patient", mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(1).getValueAsString());
@ -111,7 +111,7 @@ class Convertor_Factory_40_50Test {
assertEquals("item", mapR5.getGroup().get(0).getRule().get(0).getDependent().get(0).getParameter().get(0).getValueIdType().getValueAsString());
assertEquals("patient", mapR5.getGroup().get(0).getRule().get(0).getDependent().get(0).getParameter().get(1).getValueIdType().getValueAsString());
assertNull(mapR5.getGroup().get(0).getRule().get(0).getDependent().get(0).getParameter().get(0).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE));
assertNull(mapR5.getGroup().get(0).getRule().get(0).getDependent().get(0).getParameter().get(1).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE));
assertNull(mapR5.getGroup().get(0).getRule().get(0).getDependent().get(0).getParameter().get(0).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_VARIABLE_TYPE));
assertNull(mapR5.getGroup().get(0).getRule().get(0).getDependent().get(0).getParameter().get(1).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_VARIABLE_TYPE));
}
}

View File

@ -157,8 +157,8 @@ public class ToolingExtensions {
public static final String EXT_XML_TYPE = "http://hl7.org/fhir/StructureDefinition/structuredefinition-xml-type";
public static final String EXT_JSON_TYPE = "http://hl7.org/fhir/StructureDefinition/structuredefinition-json-type";
public static final String EXT_ORIGINAL_ITEM_TYPE = "http://hl7.org/fhir/tools/StructureDefinition/original-item-type";
public static final String EXT_ORIGINAL_ELEMENT_TYPE = "http://hl7.org/fhir/tools/StructureDefinition/original-item-type";
public static final String EXT_ORIGINAL_ITEM_TYPE = "http://hl7.org/fhir/4.0/StructureDefinition/extension-Questionnaire.item.type";
public static final String EXT_ORIGINAL_VARIABLE_TYPE = "http://hl7.org/fhir/5.0/StructureDefinition/extension-StructureMap.group.rule.dependent.parameter";
// specific extension helpers

View File

@ -40,7 +40,7 @@ import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import javax.annotation.Nonnull;
public class QuestionnaireRenderer extends TerminologyRenderer {
public static final String EXT_QUESTIONNAIRE_ITEM_TYPE_ORIGINAL = "http://hl7.org/fhir/tools/StructureDefinition/original-item-type";
public static final String EXT_QUESTIONNAIRE_ITEM_TYPE_ORIGINAL = "http://hl7.org/fhir/4.0/StructureDefinition/extension-Questionnaire.item.type";
public QuestionnaireRenderer(RenderingContext context) {
super(context);

View File

@ -202,8 +202,8 @@ public class ToolingExtensions {
public static final String EXT_EXPAND_GROUP = "http://hl7.org/fhir/StructureDefinition/valueset-expand-group";
public static final String EXT_BINDING_ADDITIONAL = "http://hl7.org/fhir/tools/StructureDefinition/additional-binding";
public static final String EXT_ORIGINAL_ITEM_TYPE = "http://hl7.org/fhir/tools/StructureDefinition/original-item-type";
public static final String EXT_ORIGINAL_ELEMENT_TYPE = "http://hl7.org/fhir/tools/StructureDefinition/original-item-type";
public static final String EXT_ORIGINAL_ITEM_TYPE = "http://hl7.org/fhir/4.0/StructureDefinition/extension-Questionnaire.item.type";
public static final String EXT_ORIGINAL_VARIABLE_TYPE = "http://hl7.org/fhir/5.0/StructureDefinition/extension-StructureMap.group.rule.dependent.parameter";
// specific extension helpers