Merge pull request #1177 from hapifhir/gg-202303-mapping

Gg 202303 mapping
This commit is contained in:
Grahame Grieve 2023-03-19 12:30:48 +11:00 committed by GitHub
commit 12d114016d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 240 additions and 110 deletions

View File

@ -130,6 +130,13 @@ import org.hl7.fhir.utilities.xml.SchematronWriter.Section;
*/ */
public class ProfileUtilities extends TranslatingUtilities { public class ProfileUtilities extends TranslatingUtilities {
public enum MappingMergeModeOption {
DUPLICATE, // if there's more than one mapping for the same URI, just keep them all
IGNORE, // if there's more than one, keep the first
OVERWRITE, // if there's opre than, keep the last
APPEND, // if there's more than one, append them with ';'
}
public enum AllowUnknownProfile { public enum AllowUnknownProfile {
NONE, // exception if there's any unknown profiles (the default) NONE, // exception if there's any unknown profiles (the default)
NON_EXTNEIONS, // don't raise an exception except on Extension (because more is going on there NON_EXTNEIONS, // don't raise an exception except on Extension (because more is going on there
@ -280,6 +287,7 @@ public class ProfileUtilities extends TranslatingUtilities {
private Set<String> masterSourceFileNames; private Set<String> masterSourceFileNames;
private Map<ElementDefinition, SourcedChildDefinitions> childMapCache = new HashMap<>(); private Map<ElementDefinition, SourcedChildDefinitions> childMapCache = new HashMap<>();
private AllowUnknownProfile allowUnknownProfile = AllowUnknownProfile.ALL_TYPES; private AllowUnknownProfile allowUnknownProfile = AllowUnknownProfile.ALL_TYPES;
private MappingMergeModeOption mappingMergeMode = MappingMergeModeOption.APPEND;
public ProfileUtilities(IWorkerContext context, List<ValidationMessage> messages, ProfileKnowledgeProvider pkp, FHIRPathEngine fpe) { public ProfileUtilities(IWorkerContext context, List<ValidationMessage> messages, ProfileKnowledgeProvider pkp, FHIRPathEngine fpe) {
super(); super();
@ -2263,25 +2271,11 @@ public class ProfileUtilities extends TranslatingUtilities {
} }
if (derived.hasMapping()) { if (derived.hasMapping()) {
// todo: mappings are not cumulative - one replaces another List<ElementDefinitionMappingComponent> list = new ArrayList<>();
if (!Base.compareDeep(derived.getMapping(), base.getMapping(), false)) { list.addAll(base.getMapping());
for (ElementDefinitionMappingComponent s : derived.getMapping()) { base.getMapping().clear();
boolean found = false; addMappings(base.getMapping(), list);
for (ElementDefinitionMappingComponent d : base.getMapping()) { addMappings(base.getMapping(), derived.getMapping());
found = found || (d.getIdentity().equals(s.getIdentity()) && d.getMap().equals(s.getMap()));
}
if (!found) {
base.getMapping().add(s);
}
}
}
else if (trimDifferential) {
derived.getMapping().clear();
} else {
for (ElementDefinitionMappingComponent t : derived.getMapping()) {
t.setUserData(UD_DERIVATION_EQUALS, true);
}
}
} }
for (ElementDefinitionMappingComponent m : base.getMapping()) { for (ElementDefinitionMappingComponent m : base.getMapping()) {
if (m.hasMap()) { if (m.hasMap()) {
@ -2332,6 +2326,52 @@ public class ProfileUtilities extends TranslatingUtilities {
} }
} }
private void addMappings(List<ElementDefinitionMappingComponent> destination, List<ElementDefinitionMappingComponent> source) {
for (ElementDefinitionMappingComponent s : source) {
boolean found = false;
for (ElementDefinitionMappingComponent d : destination) {
if (compareMaps(s, d)) {
found = true;
d.setUserData(UD_DERIVATION_EQUALS, true);
break;
}
}
if (!found) {
destination.add(s);
}
}
}
private boolean compareMaps(ElementDefinitionMappingComponent s, ElementDefinitionMappingComponent d) {
if (d.getIdentity().equals(s.getIdentity()) && d.getMap().equals(s.getMap())) {
return true;
}
if (VersionUtilities.isR5Plus(context.getVersion())) {
if (d.getIdentity().equals(s.getIdentity())) {
switch (mappingMergeMode) {
case APPEND:
if (!Utilities.splitStrings(d.getMap(), "\\,").contains(s.getMap())) {
d.setMap(d.getMap()+","+s.getMap());
}
return true;
case DUPLICATE:
return false;
case IGNORE:
d.setMap(s.getMap());
return true;
case OVERWRITE:
return true;
default:
return false;
}
} else {
return false;
}
} else {
return false;
}
}
private void checkTypeDerivation(String purl, StructureDefinition srcSD, ElementDefinition base, ElementDefinition derived, TypeRefComponent ts) { private void checkTypeDerivation(String purl, StructureDefinition srcSD, ElementDefinition base, ElementDefinition derived, TypeRefComponent ts) {
boolean ok = false; boolean ok = false;
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder(); CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();

View File

@ -23,7 +23,7 @@ public class TypeConvertor {
else if (b.isMetadataBased()) else if (b.isMetadataBased())
return ((org.hl7.fhir.r5.elementmodel.Element) b).asType(); return ((org.hl7.fhir.r5.elementmodel.Element) b).asType();
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Reference"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Reference");
} }
@ -34,7 +34,7 @@ public class TypeConvertor {
if (b instanceof BooleanType) if (b instanceof BooleanType)
return (BooleanType) b; return (BooleanType) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Boolean"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Boolean");
} }
public static IntegerType castToInteger(Base b) throws FHIRException { public static IntegerType castToInteger(Base b) throws FHIRException {
@ -44,7 +44,7 @@ public class TypeConvertor {
if (b instanceof IntegerType) if (b instanceof IntegerType)
return (IntegerType) b; return (IntegerType) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Integer"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Integer");
} }
public static Integer64Type castToInteger64(Base b) throws FHIRException { public static Integer64Type castToInteger64(Base b) throws FHIRException {
@ -54,7 +54,7 @@ public class TypeConvertor {
if (b instanceof Integer64Type) if (b instanceof Integer64Type)
return (Integer64Type) b; return (Integer64Type) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Integer"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Integer");
} }
public static DecimalType castToDecimal(Base b) throws FHIRException { public static DecimalType castToDecimal(Base b) throws FHIRException {
@ -66,7 +66,7 @@ public class TypeConvertor {
else if (b.hasPrimitiveValue()) else if (b.hasPrimitiveValue())
return new DecimalType(b.primitiveValue()); return new DecimalType(b.primitiveValue());
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Decimal"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Decimal");
} }
public static Base64BinaryType castToBase64Binary(Base b) throws FHIRException { public static Base64BinaryType castToBase64Binary(Base b) throws FHIRException {
@ -76,7 +76,7 @@ public class TypeConvertor {
if (b instanceof Base64BinaryType) if (b instanceof Base64BinaryType)
return (Base64BinaryType) b; return (Base64BinaryType) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Base64Binary"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Base64Binary");
} }
public static InstantType castToInstant(Base b) throws FHIRException { public static InstantType castToInstant(Base b) throws FHIRException {
@ -86,7 +86,7 @@ public class TypeConvertor {
if (b instanceof InstantType) if (b instanceof InstantType)
return (InstantType) b; return (InstantType) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Instant"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Instant");
} }
public static StringType castToString(Base b) throws FHIRException { public static StringType castToString(Base b) throws FHIRException {
@ -99,7 +99,7 @@ public class TypeConvertor {
else if (b.hasPrimitiveValue()) else if (b.hasPrimitiveValue())
return new StringType(b.primitiveValue()); return new StringType(b.primitiveValue());
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a String"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a String");
} }
public static UriType castToUri(Base b) throws FHIRException { public static UriType castToUri(Base b) throws FHIRException {
@ -112,7 +112,7 @@ public class TypeConvertor {
else if (b.hasPrimitiveValue()) else if (b.hasPrimitiveValue())
return new UriType(b.primitiveValue()); return new UriType(b.primitiveValue());
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Uri"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Uri");
} }
public static UrlType castToUrl(Base b) throws FHIRException { public static UrlType castToUrl(Base b) throws FHIRException {
@ -125,7 +125,7 @@ public class TypeConvertor {
else if (b.hasPrimitiveValue()) else if (b.hasPrimitiveValue())
return new UrlType(b.primitiveValue()); return new UrlType(b.primitiveValue());
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Uri"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Uri");
} }
public static CanonicalType castToCanonical(Base b) throws FHIRException { public static CanonicalType castToCanonical(Base b) throws FHIRException {
@ -138,7 +138,7 @@ public class TypeConvertor {
else if (b.hasPrimitiveValue()) else if (b.hasPrimitiveValue())
return new CanonicalType(b.primitiveValue()); return new CanonicalType(b.primitiveValue());
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Uri"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Uri");
} }
public static DateType castToDate(Base b) throws FHIRException { public static DateType castToDate(Base b) throws FHIRException {
@ -151,7 +151,7 @@ public class TypeConvertor {
else if (b.hasPrimitiveValue()) else if (b.hasPrimitiveValue())
return new DateType(b.primitiveValue()); return new DateType(b.primitiveValue());
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Date"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Date");
} }
public static DateTimeType castToDateTime(Base b) throws FHIRException { public static DateTimeType castToDateTime(Base b) throws FHIRException {
@ -164,7 +164,7 @@ public class TypeConvertor {
else if (b.fhirType().equals("dateTime")) else if (b.fhirType().equals("dateTime"))
return new DateTimeType(b.primitiveValue()); return new DateTimeType(b.primitiveValue());
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a DateTime"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a DateTime");
} }
public static TimeType castToTime(Base b) throws FHIRException { public static TimeType castToTime(Base b) throws FHIRException {
@ -175,7 +175,7 @@ public class TypeConvertor {
if (b instanceof TimeType) if (b instanceof TimeType)
return (TimeType) b; return (TimeType) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Time"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Time");
} }
public static CodeType castToCode(Base b) throws FHIRException { public static CodeType castToCode(Base b) throws FHIRException {
@ -190,7 +190,7 @@ public class TypeConvertor {
} else if (b.isPrimitive()) } else if (b.isPrimitive())
return new CodeType(b.primitiveValue()); return new CodeType(b.primitiveValue());
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Code"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Code");
} }
public static OidType castToOid(Base b) throws FHIRException { public static OidType castToOid(Base b) throws FHIRException {
@ -201,7 +201,7 @@ public class TypeConvertor {
if (b instanceof OidType) if (b instanceof OidType)
return (OidType) b; return (OidType) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Oid"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Oid");
} }
public static IdType castToId(Base b) throws FHIRException { public static IdType castToId(Base b) throws FHIRException {
@ -212,7 +212,7 @@ public class TypeConvertor {
if (b instanceof IdType) if (b instanceof IdType)
return (IdType) b; return (IdType) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Id"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Id");
} }
public static UnsignedIntType castToUnsignedInt(Base b) throws FHIRException { public static UnsignedIntType castToUnsignedInt(Base b) throws FHIRException {
@ -223,7 +223,7 @@ public class TypeConvertor {
if (b instanceof UnsignedIntType) if (b instanceof UnsignedIntType)
return (UnsignedIntType) b; return (UnsignedIntType) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a UnsignedInt"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a UnsignedInt");
} }
public static PositiveIntType castToPositiveInt(Base b) throws FHIRException { public static PositiveIntType castToPositiveInt(Base b) throws FHIRException {
@ -234,7 +234,7 @@ public class TypeConvertor {
if (b instanceof PositiveIntType) if (b instanceof PositiveIntType)
return (PositiveIntType) b; return (PositiveIntType) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a PositiveInt"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a PositiveInt");
} }
public static MarkdownType castToMarkdown(Base b) throws FHIRException { public static MarkdownType castToMarkdown(Base b) throws FHIRException {
@ -247,7 +247,7 @@ public class TypeConvertor {
else if (b.hasPrimitiveValue()) else if (b.hasPrimitiveValue())
return new MarkdownType(b.primitiveValue()); return new MarkdownType(b.primitiveValue());
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Markdown"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Markdown");
} }
public static Annotation castToAnnotation(Base b) throws FHIRException { public static Annotation castToAnnotation(Base b) throws FHIRException {
@ -258,7 +258,7 @@ public class TypeConvertor {
if (b instanceof Annotation) if (b instanceof Annotation)
return (Annotation) b; return (Annotation) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to an Annotation"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to an Annotation");
} }
public static Dosage castToDosage(Base b) throws FHIRException { public static Dosage castToDosage(Base b) throws FHIRException {
@ -269,7 +269,7 @@ public class TypeConvertor {
if (b instanceof Dosage) if (b instanceof Dosage)
return (Dosage) b; return (Dosage) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to an DosageInstruction"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to an DosageInstruction");
} }
@ -281,7 +281,7 @@ public class TypeConvertor {
if (b instanceof Attachment) if (b instanceof Attachment)
return (Attachment) b; return (Attachment) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to an Attachment"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to an Attachment");
} }
public static Identifier castToIdentifier(Base b) throws FHIRException { public static Identifier castToIdentifier(Base b) throws FHIRException {
@ -292,7 +292,7 @@ public class TypeConvertor {
if (b instanceof Identifier) if (b instanceof Identifier)
return (Identifier) b; return (Identifier) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to an Identifier"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to an Identifier");
} }
public static CodeableConcept castToCodeableConcept(Base b) throws FHIRException { public static CodeableConcept castToCodeableConcept(Base b) throws FHIRException {
@ -313,7 +313,7 @@ public class TypeConvertor {
cc.addCoding().setCode(((StringType) b).asStringValue()); cc.addCoding().setCode(((StringType) b).asStringValue());
return cc; return cc;
} else } else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a CodeableConcept"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a CodeableConcept");
} }
public static CodeableReference castToCodeableReference(Base b) throws FHIRException { public static CodeableReference castToCodeableReference(Base b) throws FHIRException {
@ -336,7 +336,7 @@ public class TypeConvertor {
cc.getConcept().addCoding().setCode(((StringType) b).asStringValue()); cc.getConcept().addCoding().setCode(((StringType) b).asStringValue());
return cc; return cc;
} else } else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a CodeableConcept"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a CodeableConcept");
} }
public static Population castToPopulation(Base b) throws FHIRException { public static Population castToPopulation(Base b) throws FHIRException {
@ -347,7 +347,7 @@ public class TypeConvertor {
if (b instanceof Population) if (b instanceof Population)
return (Population) b; return (Population) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Population"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Population");
} }
@ -370,7 +370,7 @@ public class TypeConvertor {
} else if (b.isPrimitive()) { } else if (b.isPrimitive()) {
return new Coding().setCode(b.primitiveValue()); return new Coding().setCode(b.primitiveValue());
} else { } else {
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Coding"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Coding");
} }
} else if (b instanceof ICoding) { } else if (b instanceof ICoding) {
ICoding c = (ICoding) b; ICoding c = (ICoding) b;
@ -383,7 +383,7 @@ public class TypeConvertor {
} else if (b.isPrimitive()) { } else if (b.isPrimitive()) {
return new Coding().setCode(b.primitiveValue()); return new Coding().setCode(b.primitiveValue());
} else { } else {
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Coding"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Coding");
} }
} }
@ -395,7 +395,7 @@ public class TypeConvertor {
if (b instanceof Quantity) if (b instanceof Quantity)
return (Quantity) b; return (Quantity) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to an Quantity"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to an Quantity");
} }
public static Count castToCount(Base b) throws FHIRException { public static Count castToCount(Base b) throws FHIRException {
@ -406,7 +406,7 @@ public class TypeConvertor {
if (b instanceof Count) if (b instanceof Count)
return (Count) b; return (Count) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to an Count"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to an Count");
} }
public static Money castToMoney(Base b) throws FHIRException { public static Money castToMoney(Base b) throws FHIRException {
@ -416,8 +416,11 @@ public class TypeConvertor {
if (b instanceof Money) if (b instanceof Money)
return (Money) b; return (Money) b;
else else if (b instanceof org.hl7.fhir.r5.elementmodel.Element && Utilities.tail(b.fhirType()).equals("Money")) {
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to an Money"); org.hl7.fhir.r5.elementmodel.Element e = (org.hl7.fhir.r5.elementmodel.Element) b;
return new Money().setCurrency(e.getChildValue("currency")).setValue(Long.parseLong(e.getChildValue("value")));
} else
throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to an Money");
} }
public static Duration castToDuration(Base b) throws FHIRException { public static Duration castToDuration(Base b) throws FHIRException {
@ -428,7 +431,7 @@ public class TypeConvertor {
if (b instanceof Duration) if (b instanceof Duration)
return (Duration) b; return (Duration) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to an Duration"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to an Duration");
} }
public static SimpleQuantity castToSimpleQuantity(Base b) throws FHIRException { public static SimpleQuantity castToSimpleQuantity(Base b) throws FHIRException {
@ -448,7 +451,7 @@ public class TypeConvertor {
sq.setCodeElement(q.getCodeElement()); sq.setCodeElement(q.getCodeElement());
return sq; return sq;
} else } else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to an SimpleQuantity"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to an SimpleQuantity");
} }
public static Range castToRange(Base b) throws FHIRException { public static Range castToRange(Base b) throws FHIRException {
@ -459,7 +462,7 @@ public class TypeConvertor {
if (b instanceof Range) if (b instanceof Range)
return (Range) b; return (Range) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Range"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Range");
} }
public static Period castToPeriod(Base b) throws FHIRException { public static Period castToPeriod(Base b) throws FHIRException {
@ -470,7 +473,7 @@ public class TypeConvertor {
if (b instanceof Period) if (b instanceof Period)
return (Period) b; return (Period) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Period"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Period");
} }
public static Ratio castToRatio(Base b) throws FHIRException { public static Ratio castToRatio(Base b) throws FHIRException {
@ -481,7 +484,7 @@ public class TypeConvertor {
if (b instanceof Ratio) if (b instanceof Ratio)
return (Ratio) b; return (Ratio) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Ratio"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Ratio");
} }
public static SampledData castToSampledData(Base b) throws FHIRException { public static SampledData castToSampledData(Base b) throws FHIRException {
@ -492,7 +495,7 @@ public class TypeConvertor {
if (b instanceof SampledData) if (b instanceof SampledData)
return (SampledData) b; return (SampledData) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a SampledData"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a SampledData");
} }
public static Signature castToSignature(Base b) throws FHIRException { public static Signature castToSignature(Base b) throws FHIRException {
@ -503,7 +506,7 @@ public class TypeConvertor {
if (b instanceof Signature) if (b instanceof Signature)
return (Signature) b; return (Signature) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Signature"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Signature");
} }
public static HumanName castToHumanName(Base b) throws FHIRException { public static HumanName castToHumanName(Base b) throws FHIRException {
@ -514,7 +517,7 @@ public class TypeConvertor {
if (b instanceof HumanName) if (b instanceof HumanName)
return (HumanName) b; return (HumanName) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a HumanName"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a HumanName");
} }
public static Address castToAddress(Base b) throws FHIRException { public static Address castToAddress(Base b) throws FHIRException {
@ -525,7 +528,7 @@ public class TypeConvertor {
if (b instanceof Address) if (b instanceof Address)
return (Address) b; return (Address) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Address"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Address");
} }
public static ContactDetail castToContactDetail(Base b) throws FHIRException { public static ContactDetail castToContactDetail(Base b) throws FHIRException {
@ -536,7 +539,7 @@ public class TypeConvertor {
if (b instanceof ContactDetail) if (b instanceof ContactDetail)
return (ContactDetail) b; return (ContactDetail) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a ContactDetail"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a ContactDetail");
} }
public static Contributor castToContributor(Base b) throws FHIRException { public static Contributor castToContributor(Base b) throws FHIRException {
@ -547,7 +550,7 @@ public class TypeConvertor {
if (b instanceof Contributor) if (b instanceof Contributor)
return (Contributor) b; return (Contributor) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Contributor"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Contributor");
} }
public static UsageContext castToUsageContext(Base b) throws FHIRException { public static UsageContext castToUsageContext(Base b) throws FHIRException {
@ -558,7 +561,7 @@ public class TypeConvertor {
if (b instanceof UsageContext) if (b instanceof UsageContext)
return (UsageContext) b; return (UsageContext) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a UsageContext"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a UsageContext");
} }
public static RelatedArtifact castToRelatedArtifact(Base b) throws FHIRException { public static RelatedArtifact castToRelatedArtifact(Base b) throws FHIRException {
@ -569,7 +572,7 @@ public class TypeConvertor {
if (b instanceof RelatedArtifact) if (b instanceof RelatedArtifact)
return (RelatedArtifact) b; return (RelatedArtifact) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a RelatedArtifact"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a RelatedArtifact");
} }
public static ContactPoint castToContactPoint(Base b) throws FHIRException { public static ContactPoint castToContactPoint(Base b) throws FHIRException {
@ -580,7 +583,7 @@ public class TypeConvertor {
if (b instanceof ContactPoint) if (b instanceof ContactPoint)
return (ContactPoint) b; return (ContactPoint) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a ContactPoint"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a ContactPoint");
} }
public static Timing castToTiming(Base b) throws FHIRException { public static Timing castToTiming(Base b) throws FHIRException {
@ -591,7 +594,7 @@ public class TypeConvertor {
if (b instanceof Timing) if (b instanceof Timing)
return (Timing) b; return (Timing) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Timing"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Timing");
} }
public static Reference castToReference(Base b) throws FHIRException { public static Reference castToReference(Base b) throws FHIRException {
@ -603,11 +606,11 @@ public class TypeConvertor {
return (Reference) b; return (Reference) b;
else if (b.isPrimitive() && Utilities.isURL(b.primitiveValue())) else if (b.isPrimitive() && Utilities.isURL(b.primitiveValue()))
return new Reference().setReference(b.primitiveValue()); return new Reference().setReference(b.primitiveValue());
else if (b instanceof org.hl7.fhir.r5.elementmodel.Element && b.fhirType().equals("Reference")) { else if (b instanceof org.hl7.fhir.r5.elementmodel.Element && Utilities.tail(b.fhirType()).equals("Reference")) {
org.hl7.fhir.r5.elementmodel.Element e = (org.hl7.fhir.r5.elementmodel.Element) b; org.hl7.fhir.r5.elementmodel.Element e = (org.hl7.fhir.r5.elementmodel.Element) b;
return new Reference().setReference(e.getChildValue("reference")).setDisplay(e.getChildValue("display")); return new Reference().setReference(e.getChildValue("reference")).setDisplay(e.getChildValue("display"));
} else } else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Reference"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Reference");
} }
public static Meta castToMeta(Base b) throws FHIRException { public static Meta castToMeta(Base b) throws FHIRException {
@ -618,7 +621,7 @@ public class TypeConvertor {
if (b instanceof Meta) if (b instanceof Meta)
return (Meta) b; return (Meta) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Meta"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Meta");
} }
@ -630,7 +633,7 @@ public class TypeConvertor {
if (b instanceof MarketingStatus) if (b instanceof MarketingStatus)
return (MarketingStatus) b; return (MarketingStatus) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a MarketingStatus"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a MarketingStatus");
} }
public static Statistic castToStatistic(Base b) throws FHIRException { public static Statistic castToStatistic(Base b) throws FHIRException {
@ -641,7 +644,7 @@ public class TypeConvertor {
if (b instanceof Statistic) if (b instanceof Statistic)
return (Statistic) b; return (Statistic) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Statistic"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Statistic");
} }
@ -653,7 +656,7 @@ public class TypeConvertor {
if (b instanceof OrderedDistribution) if (b instanceof OrderedDistribution)
return (OrderedDistribution) b; return (OrderedDistribution) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a OrderedDistribution"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a OrderedDistribution");
} }
public static ProductShelfLife castToProductShelfLife(Base b) throws FHIRException { public static ProductShelfLife castToProductShelfLife(Base b) throws FHIRException {
@ -664,7 +667,7 @@ public class TypeConvertor {
if (b instanceof ProductShelfLife) if (b instanceof ProductShelfLife)
return (ProductShelfLife) b; return (ProductShelfLife) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a ProductShelfLife"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a ProductShelfLife");
} }
public static ProdCharacteristic castToProdCharacteristic(Base b) throws FHIRException { public static ProdCharacteristic castToProdCharacteristic(Base b) throws FHIRException {
@ -675,7 +678,7 @@ public class TypeConvertor {
if (b instanceof ProdCharacteristic) if (b instanceof ProdCharacteristic)
return (ProdCharacteristic) b; return (ProdCharacteristic) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a ProdCharacteristic"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a ProdCharacteristic");
} }
@ -687,7 +690,7 @@ public class TypeConvertor {
if (b instanceof SubstanceAmount) if (b instanceof SubstanceAmount)
return (SubstanceAmount) b; return (SubstanceAmount) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a SubstanceAmount"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a SubstanceAmount");
} }
public static Extension castToExtension(Base b) throws FHIRException { public static Extension castToExtension(Base b) throws FHIRException {
@ -698,7 +701,7 @@ public class TypeConvertor {
if (b instanceof Extension) if (b instanceof Extension)
return (Extension) b; return (Extension) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Extension"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Extension");
} }
public static Resource castToResource(Base b) throws FHIRException { public static Resource castToResource(Base b) throws FHIRException {
@ -709,7 +712,7 @@ public class TypeConvertor {
if (b instanceof Resource) if (b instanceof Resource)
return (Resource) b; return (Resource) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Resource"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Resource");
} }
public static Narrative castToNarrative(Base b) throws FHIRException { public static Narrative castToNarrative(Base b) throws FHIRException {
@ -720,7 +723,7 @@ public class TypeConvertor {
if (b instanceof Narrative) if (b instanceof Narrative)
return (Narrative) b; return (Narrative) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Narrative"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Narrative");
} }
@ -732,7 +735,7 @@ public class TypeConvertor {
if (b instanceof ElementDefinition) if (b instanceof ElementDefinition)
return (ElementDefinition) b; return (ElementDefinition) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a ElementDefinition"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a ElementDefinition");
} }
public static DataRequirement castToDataRequirement(Base b) throws FHIRException { public static DataRequirement castToDataRequirement(Base b) throws FHIRException {
@ -743,7 +746,7 @@ public class TypeConvertor {
if (b instanceof DataRequirement) if (b instanceof DataRequirement)
return (DataRequirement) b; return (DataRequirement) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a DataRequirement"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a DataRequirement");
} }
public static Expression castToExpression(Base b) throws FHIRException { public static Expression castToExpression(Base b) throws FHIRException {
@ -754,7 +757,7 @@ public class TypeConvertor {
if (b instanceof Expression) if (b instanceof Expression)
return (Expression) b; return (Expression) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Expression"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Expression");
} }
@ -766,7 +769,7 @@ public class TypeConvertor {
if (b instanceof ParameterDefinition) if (b instanceof ParameterDefinition)
return (ParameterDefinition) b; return (ParameterDefinition) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a ParameterDefinition"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a ParameterDefinition");
} }
public static TriggerDefinition castToTriggerDefinition(Base b) throws FHIRException { public static TriggerDefinition castToTriggerDefinition(Base b) throws FHIRException {
@ -777,7 +780,7 @@ public class TypeConvertor {
if (b instanceof TriggerDefinition) if (b instanceof TriggerDefinition)
return (TriggerDefinition) b; return (TriggerDefinition) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a TriggerDefinition"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a TriggerDefinition");
} }
public static ExtendedContactDetail castToExtendedContactDetail(Base b) throws FHIRException { public static ExtendedContactDetail castToExtendedContactDetail(Base b) throws FHIRException {
@ -788,7 +791,7 @@ public class TypeConvertor {
if (b instanceof ExtendedContactDetail) if (b instanceof ExtendedContactDetail)
return (ExtendedContactDetail) b; return (ExtendedContactDetail) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a ExtendedContactDetail"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a ExtendedContactDetail");
} }
@ -810,7 +813,7 @@ public class TypeConvertor {
throw new FHIRException(e); throw new FHIRException(e);
} }
} else } else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to XHtml"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to XHtml");
} }
public static String castToXhtmlString(Base b) throws FHIRException { public static String castToXhtmlString(Base b) throws FHIRException {
@ -829,7 +832,7 @@ public class TypeConvertor {
} else if (b instanceof StringType) { } else if (b instanceof StringType) {
return ((StringType) b).asStringValue(); return ((StringType) b).asStringValue();
} else } else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to XHtml string"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to XHtml string");
} }
@ -841,7 +844,7 @@ public class TypeConvertor {
if (b instanceof VirtualServiceDetail) if (b instanceof VirtualServiceDetail)
return (VirtualServiceDetail) b; return (VirtualServiceDetail) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a VirtualServiceDetail"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a VirtualServiceDetail");
} }
@ -853,7 +856,7 @@ public class TypeConvertor {
if (b instanceof Availability) if (b instanceof Availability)
return (Availability) b; return (Availability) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Availability"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a Availability");
} }
@ -865,6 +868,6 @@ public class TypeConvertor {
if (b instanceof MonetaryComponent) if (b instanceof MonetaryComponent)
return (MonetaryComponent) b; return (MonetaryComponent) b;
else else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a MonetaryComponent"); throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a MonetaryComponent");
} }
} }

View File

@ -1719,8 +1719,13 @@ public class StructureMapUtilities {
Base v = null; Base v = null;
if (tgt.hasTransform()) { if (tgt.hasTransform()) {
v = runTransform(rulePath, context, map, group, tgt, vars, dest, tgt.getElement(), srcVar, atRoot); v = runTransform(rulePath, context, map, group, tgt, vars, dest, tgt.getElement(), srcVar, atRoot);
if (v != null && dest != null) if (v != null && dest != null) {
v = dest.setProperty(tgt.getElement().hashCode(), tgt.getElement(), v); // reset v because some implementations may have to rewrite v when setting the value try {
v = dest.setProperty(tgt.getElement().hashCode(), tgt.getElement(), v); // reset v because some implementations may have to rewrite v when setting the value
} catch (Exception e) {
throw new FHIRException("Error setting "+tgt.getElement()+" on "+dest.fhirType()+" for rule "+rulePath+" to value "+v.toString()+": "+e.getMessage(), e);
}
}
} else if (dest != null) { } else if (dest != null) {
if (tgt.hasListMode(StructureMapTargetListMode.SHARE)) { if (tgt.hasListMode(StructureMapTargetListMode.SHARE)) {
v = sharedVars.get(VariableMode.SHARED, tgt.getListRuleId()); v = sharedVars.get(VariableMode.SHARED, tgt.getListRuleId());

View File

@ -11,6 +11,9 @@ import org.apache.commons.lang3.NotImplementedException;
import org.fhir.ucum.UcumException; import org.fhir.ucum.UcumException;
import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.PathEngineException; import org.hl7.fhir.exceptions.PathEngineException;
import org.hl7.fhir.r5.elementmodel.Manager;
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
import org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement;
import org.hl7.fhir.r5.formats.JsonParser; import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.formats.XmlParser; import org.hl7.fhir.r5.formats.XmlParser;
import org.hl7.fhir.r5.model.*; import org.hl7.fhir.r5.model.*;
@ -204,7 +207,12 @@ public class FHIRPathTests {
if (node != null) { if (node != null) {
try { try {
outcome = fp.evaluate(res, node); if ("element".equals(test.getAttribute("mode"))) {
List<NamedElement> e = Manager.parse(fp.getWorker(), TestingUtilities.loadTestResourceStream("r5", input), input.endsWith(".json") ? FhirFormat.JSON : FhirFormat.XML);
outcome = fp.evaluate(e.get(0).getElement(), node);
} else {
outcome = fp.evaluate(res, node);
}
Assertions.assertTrue(fail == TestResultType.OK, String.format("Expected exception didn't occur executing %s", expression)); Assertions.assertTrue(fail == TestResultType.OK, String.format("Expected exception didn't occur executing %s", expression));
} catch (Exception e) { } catch (Exception e) {
System.out.println("Execution Error: "+e.getMessage()); System.out.println("Execution Error: "+e.getMessage());

View File

@ -1184,7 +1184,7 @@ public class Utilities {
if (ref != null && ref.contains(":")) { if (ref != null && ref.contains(":")) {
String scheme = ref.substring(0, ref.indexOf(":")); String scheme = ref.substring(0, ref.indexOf(":"));
String details = ref.substring(ref.indexOf(":")+1); String details = ref.substring(ref.indexOf(":")+1);
return (existsInList(scheme, "http", "https", "urn") || (isToken(scheme) && scheme.equals(scheme.toLowerCase())) || Utilities.startsWithInList(ref, "urn:iso:", "urn:iso-iec:", "urn:iso-cie:", "urn:iso-astm:", "urn:iso-ieee:", "urn:iec:")) return (existsInList(scheme, "http", "https", "urn", "file:") || (isToken(scheme) && scheme.equals(scheme.toLowerCase())) || Utilities.startsWithInList(ref, "urn:iso:", "urn:iso-iec:", "urn:iso-cie:", "urn:iso-astm:", "urn:iso-ieee:", "urn:iec:"))
&& details != null && details.length() > 0 && !details.contains(" "); // rfc5141 && details != null && details.length() > 0 && !details.contains(" "); // rfc5141
} }
return false; return false;
@ -2002,6 +2002,28 @@ public class Utilities {
return ret; return ret;
} }
public static List<String> splitStrings(String src, String regex) {
List<String> ret = new ArrayList<>();
for (String m : src.split(regex)) {
ret.add(m);
}
return ret;
}
public static String stripPara(String p) {
if (noString(p)) {
return "";
}
p = p.trim();
if (p.startsWith("<p>")) {
p = p.substring(3);
}
if (p.endsWith("</p>")) {
p = p.substring(0, p.length()-4);
}
return p;
}
//public static boolean !isWhitespace(String s) { //public static boolean !isWhitespace(String s) {

View File

@ -81,11 +81,11 @@ public class BundleValidator extends BaseValidator {
} }
if (type.equals(MESSAGE)) { if (type.equals(MESSAGE)) {
Element resource = firstEntry.getNamedChild(RESOURCE); Element resource = firstEntry.getNamedChild(RESOURCE);
String id = resource.getNamedChildValue(ID);
if (rule(errors, NO_RULE_DATE, IssueType.INVALID, firstEntry.line(), firstEntry.col(), stack.addToLiteralPath(ENTRY, PATH_ARG), resource != null, I18nConstants.BUNDLE_BUNDLE_ENTRY_NOFIRSTRESOURCE)) { if (rule(errors, NO_RULE_DATE, IssueType.INVALID, firstEntry.line(), firstEntry.col(), stack.addToLiteralPath(ENTRY, PATH_ARG), resource != null, I18nConstants.BUNDLE_BUNDLE_ENTRY_NOFIRSTRESOURCE)) {
String id = resource.getNamedChildValue(ID);
ok = validateMessage(errors, entries, resource, firstStack.push(resource, -1, null, null), fullUrl, id) && ok; ok = validateMessage(errors, entries, resource, firstStack.push(resource, -1, null, null), fullUrl, id) && ok;
ok = checkAllInterlinked(errors, entries, stack, bundle, true) && ok;
} }
ok = checkAllInterlinked(errors, entries, stack, bundle, true) && ok;
} }
if (type.equals(SEARCHSET)) { if (type.equals(SEARCHSET)) {
checkSearchSet(errors, bundle, entries, stack); checkSearchSet(errors, bundle, entries, stack);
@ -600,7 +600,9 @@ public class BundleValidator extends BaseValidator {
} }
Set<EntrySummary> visited = new HashSet<>(); Set<EntrySummary> visited = new HashSet<>();
visitLinked(visited, entryList.get(0)); if (entryList.size() > 0) {
visitLinked(visited, entryList.get(0));
}
visitBundleLinks(visited, entryList, bundle); visitBundleLinks(visited, entryList, bundle);
boolean foundRevLinks; boolean foundRevLinks;
do { do {

View File

@ -154,7 +154,7 @@ public class ValueSetValidator extends BaseValidator {
} }
cc++; cc++;
} }
if (parent.isValidateValueSetCodesOnTxServer() && batch.size() > 0) { if (parent.isValidateValueSetCodesOnTxServer() && batch.size() > 0 & !context.isNoTerminologyServer()) {
long t = System.currentTimeMillis(); long t = System.currentTimeMillis();
if (parent.isDebug()) { if (parent.isDebug()) {
System.out.println(" : Validate "+batch.size()+" codes from "+system+" for "+vsid); System.out.println(" : Validate "+batch.size()+" codes from "+system+" for "+vsid);

View File

@ -68,6 +68,8 @@ public class R4R5MapTester implements IValidatorResourceFetcher {
private int validated; private int validated;
private int error; private int error;
private int back; private int back;
private int elements;
private int lostElements;
public void example() { public void example() {
total++; total++;
@ -132,6 +134,22 @@ public class R4R5MapTester implements IValidatorResourceFetcher {
public void back() { public void back() {
back++; back++;
} }
public void elements(int i) {
elements = elements+i;
}
public void lost(int i) {
lostElements = lostElements + i;
}
public int elementsCount() {
return elements;
}
public int lostCount() {
return lostElements;
}
} }
private boolean saveProcess = true; private boolean saveProcess = true;
@ -143,6 +161,8 @@ public class R4R5MapTester implements IValidatorResourceFetcher {
private InstanceValidator validator; private InstanceValidator validator;
private StringBuilder log;
public static void main(String[] args) throws JsonException, IOException { public static void main(String[] args) throws JsonException, IOException {
// arg[0] is the location of the fhir-extensions repo // arg[0] is the location of the fhir-extensions repo
@ -150,6 +170,7 @@ public class R4R5MapTester implements IValidatorResourceFetcher {
} }
public void testMaps(String src, String maps, String filter) throws JsonException, IOException { public void testMaps(String src, String maps, String filter) throws JsonException, IOException {
log = new StringBuilder();
log("Load Test Outcomes"); log("Load Test Outcomes");
JsonObject json = JsonParser.parseObjectFromFile(Utilities.path(src, "input", "_data", "conversions.json")); JsonObject json = JsonParser.parseObjectFromFile(Utilities.path(src, "input", "_data", "conversions.json"));
log("Load R5"); log("Load R5");
@ -200,14 +221,17 @@ public class R4R5MapTester implements IValidatorResourceFetcher {
log(" "+rn); log(" "+rn);
JsonObject o = json.getJsonObject(rn); JsonObject o = json.getJsonObject(rn);
StructureDefinition sd = context.fetchTypeDefinition(rn); StructureDefinition sd = context.fetchTypeDefinition(rn);
List<StructureMap> mapSrc = utils.getMapsForUrl(allMaps, sd.getUrl(), StructureMapInputMode.SOURCE); if (sd != null) {
List<StructureMap> mapTgt = utils.getMapsForUrl(allMaps, sd.getUrl(), StructureMapInputMode.TARGET); List<StructureMap> mapSrc = utils.getMapsForUrl(allMaps, sd.getUrl(), StructureMapInputMode.SOURCE);
changed = checkMaps(sd, o.getJsonObject("r4"), "r4", "http://hl7.org/fhir/4.0", mapSrc, mapTgt, r4Examples) || changed; List<StructureMap> mapTgt = utils.getMapsForUrl(allMaps, sd.getUrl(), StructureMapInputMode.TARGET);
changed = checkMaps(sd, o.getJsonObject("r4b"), "r4b", "http://hl7.org/fhir/4.3", mapSrc, mapTgt, r4bExamples) || changed; changed = checkMaps(sd, o.getJsonObject("r4"), "r4", "http://hl7.org/fhir/4.0", mapSrc, mapTgt, r4Examples) || changed;
JsonParser.compose(json, new FileOutputStream(Utilities.path(src, "input", "_data", "conversions.json")), true); changed = checkMaps(sd, o.getJsonObject("r4b"), "r4b", "http://hl7.org/fhir/4.3", mapSrc, mapTgt, r4bExamples) || changed;
JsonParser.compose(json, new FileOutputStream(Utilities.path(src, "input", "_data", "conversions.json")), true);
}
System.out.println(" .. done"); System.out.println(" .. done");
} }
} }
TextFile.stringToFile(log.toString(), Utilities.path(src, "input", "_data", "validation.log"));
log("Done!"); log("Done!");
// load R4 // load R4
// load R4B // load R4B
@ -301,11 +325,12 @@ public class R4R5MapTester implements IValidatorResourceFetcher {
private void testRoundTrips(StructureDefinition sd, JsonObject json, ResolvedGroup tgtG, ResolvedGroup srcG, StructureDefinition tsd, NpmPackage examples, String code) throws IOException { private void testRoundTrips(StructureDefinition sd, JsonObject json, ResolvedGroup tgtG, ResolvedGroup srcG, StructureDefinition tsd, NpmPackage examples, String code) throws IOException {
Stats stats = new Stats(); Stats stats = new Stats();
for (String s : examples.listResources(tsd.getType())) { for (String s : examples.listResources(tsd.getType())) {
log(" Test "+examples.id()+"::"+s); log(" Test "+examples.id()+"::"+s, false);
try { try {
testRoundTrip(json, sd, tsd, tgtG, srcG, stats, examples.load("package", s), code); log(" "+testRoundTrip(json, sd, tsd, tgtG, srcG, stats, examples.load("package", s), code)+"%");
} catch (Exception e) { } catch (Exception e) {
log("error: "+e.getMessage()); log("error: "+e.getMessage());
e.printStackTrace();
stats.error("Error: "+e.getMessage()); stats.error("Error: "+e.getMessage());
} }
} }
@ -317,15 +342,22 @@ public class R4R5MapTester implements IValidatorResourceFetcher {
json.set("r5InError", stats.errorCount()); json.set("r5InError", stats.errorCount());
json.remove("r5validatedOK"); json.remove("r5validatedOK");
json.set("convertToR4OK", stats.backCount()); json.set("convertToR4OK", stats.backCount());
json.set("elementsConverted", stats.elementsCount());
if (stats.elementsCount() > 0) {
json.set("elementsLost", (stats.lostCount() * 100) / stats.elementsCount());
} else {
json.set("elementsLost", 0);
}
if (stats.ok()) { if (stats.ok()) {
json.set("testColor", "#d4ffdf"); json.set("testColor", "#d4ffdf");
} }
} }
private void testRoundTrip(JsonObject json, StructureDefinition sd, StructureDefinition tsd, ResolvedGroup tgtG, ResolvedGroup srcG, Stats stats, InputStream stream, String code) throws FHIRFormatError, DefinitionException, FHIRException, IOException { private int testRoundTrip(JsonObject json, StructureDefinition sd, StructureDefinition tsd, ResolvedGroup tgtG, ResolvedGroup srcG, Stats stats, InputStream stream, String code) throws FHIRFormatError, DefinitionException, FHIRException, IOException {
stats.example(); stats.example();
Element r4 = new org.hl7.fhir.r5.elementmodel.JsonParser(context).setLogical(tsd).parseSingle(stream); Element r4 = new org.hl7.fhir.r5.elementmodel.JsonParser(context).setLogical(tsd).parseSingle(stream);
stats.parsed(); stats.parsed();
int elementCountBefore = r4.countDescendents()+1;
String id = r4.getIdBase(); String id = r4.getIdBase();
json.remove(id); json.remove(id);
checkSave(id+"."+code, "loaded", r4); checkSave(id+"."+code, "loaded", r4);
@ -347,18 +379,24 @@ public class R4R5MapTester implements IValidatorResourceFetcher {
boolean valid = true; boolean valid = true;
for (ValidationMessage vm : r5validationErrors) { for (ValidationMessage vm : r5validationErrors) {
if (vm.isError()) { if (vm.isError()) {
// json.forceObject(id).forceArray("r5-errors").add(vm.summary()); log.append(vm.summary());
log.append("\r\n");
valid = false; valid = false;
} }
} }
if (valid) {
log.append("All OK\r\n");
}
log.append("\r\n");
stats.valid(valid); stats.valid(valid);
} catch (Exception e) { } catch (Exception e) {
json.forceObject(id).set("validation-error", e.getMessage()); json.forceObject(id).set("validation-error", e.getMessage());
throw e; throw e;
} }
Element rt4 = null;
try { try {
Element rt4 = Manager.build(context, tsd); rt4 = Manager.build(context, tsd);
utils.transform(context, r5, srcG.getTargetMap(), rt4); utils.transform(context, r5, srcG.getTargetMap(), rt4);
stats.back(); stats.back();
checkSave(id+"."+code, "returned", r4); checkSave(id+"."+code, "returned", r4);
@ -366,6 +404,10 @@ public class R4R5MapTester implements IValidatorResourceFetcher {
json.forceObject(id).set("return-error", e.getMessage()); json.forceObject(id).set("return-error", e.getMessage());
throw e; throw e;
} }
int elementCountAfter = rt4.countDescendents()+1;
stats.elements(elementCountBefore);
stats.lost(elementCountBefore - elementCountAfter);
return (elementCountAfter * 100) / elementCountBefore;
} }
private void checkSave(String id, String state, Element e) throws FHIRException, FileNotFoundException, IOException { private void checkSave(String id, String state, Element e) throws FHIRException, FileNotFoundException, IOException {
@ -381,7 +423,15 @@ public class R4R5MapTester implements IValidatorResourceFetcher {
} }
private void log(String msg) { private void log(String msg) {
System.out.println(msg); log(msg, true);
}
private void log(String msg, boolean ln) {
log.append(msg+"\r\n");
if (ln) {
System.out.println(msg);
} else {
System.out.print(msg+" ");
}
} }
@Override @Override

View File

@ -19,7 +19,7 @@
<properties> <properties>
<hapi_fhir_version>6.2.1</hapi_fhir_version> <hapi_fhir_version>6.2.1</hapi_fhir_version>
<validator_test_case_version>1.2.20</validator_test_case_version> <validator_test_case_version>1.2.21-SNAPSHOT</validator_test_case_version>
<junit_jupiter_version>5.7.1</junit_jupiter_version> <junit_jupiter_version>5.7.1</junit_jupiter_version>
<junit_platform_launcher_version>1.8.2</junit_platform_launcher_version> <junit_platform_launcher_version>1.8.2</junit_platform_launcher_version>
<maven_surefire_version>3.0.0-M5</maven_surefire_version> <maven_surefire_version>3.0.0-M5</maven_surefire_version>