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 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 {
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
@ -280,6 +287,7 @@ public class ProfileUtilities extends TranslatingUtilities {
private Set<String> masterSourceFileNames;
private Map<ElementDefinition, SourcedChildDefinitions> childMapCache = new HashMap<>();
private AllowUnknownProfile allowUnknownProfile = AllowUnknownProfile.ALL_TYPES;
private MappingMergeModeOption mappingMergeMode = MappingMergeModeOption.APPEND;
public ProfileUtilities(IWorkerContext context, List<ValidationMessage> messages, ProfileKnowledgeProvider pkp, FHIRPathEngine fpe) {
super();
@ -2263,25 +2271,11 @@ public class ProfileUtilities extends TranslatingUtilities {
}
if (derived.hasMapping()) {
// todo: mappings are not cumulative - one replaces another
if (!Base.compareDeep(derived.getMapping(), base.getMapping(), false)) {
for (ElementDefinitionMappingComponent s : derived.getMapping()) {
boolean found = false;
for (ElementDefinitionMappingComponent d : base.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);
}
}
List<ElementDefinitionMappingComponent> list = new ArrayList<>();
list.addAll(base.getMapping());
base.getMapping().clear();
addMappings(base.getMapping(), list);
addMappings(base.getMapping(), derived.getMapping());
}
for (ElementDefinitionMappingComponent m : base.getMapping()) {
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) {
boolean ok = false;
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();

View File

@ -23,7 +23,7 @@ public class TypeConvertor {
else if (b.isMetadataBased())
return ((org.hl7.fhir.r5.elementmodel.Element) b).asType();
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)
return (BooleanType) b;
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 {
@ -44,7 +44,7 @@ public class TypeConvertor {
if (b instanceof IntegerType)
return (IntegerType) b;
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 {
@ -54,7 +54,7 @@ public class TypeConvertor {
if (b instanceof Integer64Type)
return (Integer64Type) b;
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 {
@ -66,7 +66,7 @@ public class TypeConvertor {
else if (b.hasPrimitiveValue())
return new DecimalType(b.primitiveValue());
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 {
@ -76,7 +76,7 @@ public class TypeConvertor {
if (b instanceof Base64BinaryType)
return (Base64BinaryType) b;
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 {
@ -86,7 +86,7 @@ public class TypeConvertor {
if (b instanceof InstantType)
return (InstantType) b;
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 {
@ -99,7 +99,7 @@ public class TypeConvertor {
else if (b.hasPrimitiveValue())
return new StringType(b.primitiveValue());
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 {
@ -112,7 +112,7 @@ public class TypeConvertor {
else if (b.hasPrimitiveValue())
return new UriType(b.primitiveValue());
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 {
@ -125,7 +125,7 @@ public class TypeConvertor {
else if (b.hasPrimitiveValue())
return new UrlType(b.primitiveValue());
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 {
@ -138,7 +138,7 @@ public class TypeConvertor {
else if (b.hasPrimitiveValue())
return new CanonicalType(b.primitiveValue());
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 {
@ -151,7 +151,7 @@ public class TypeConvertor {
else if (b.hasPrimitiveValue())
return new DateType(b.primitiveValue());
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 {
@ -164,7 +164,7 @@ public class TypeConvertor {
else if (b.fhirType().equals("dateTime"))
return new DateTimeType(b.primitiveValue());
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 {
@ -175,7 +175,7 @@ public class TypeConvertor {
if (b instanceof TimeType)
return (TimeType) b;
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 {
@ -190,7 +190,7 @@ public class TypeConvertor {
} else if (b.isPrimitive())
return new CodeType(b.primitiveValue());
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 {
@ -201,7 +201,7 @@ public class TypeConvertor {
if (b instanceof OidType)
return (OidType) b;
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 {
@ -212,7 +212,7 @@ public class TypeConvertor {
if (b instanceof IdType)
return (IdType) b;
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 {
@ -223,7 +223,7 @@ public class TypeConvertor {
if (b instanceof UnsignedIntType)
return (UnsignedIntType) b;
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 {
@ -234,7 +234,7 @@ public class TypeConvertor {
if (b instanceof PositiveIntType)
return (PositiveIntType) b;
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 {
@ -247,7 +247,7 @@ public class TypeConvertor {
else if (b.hasPrimitiveValue())
return new MarkdownType(b.primitiveValue());
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 {
@ -258,7 +258,7 @@ public class TypeConvertor {
if (b instanceof Annotation)
return (Annotation) b;
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 {
@ -269,7 +269,7 @@ public class TypeConvertor {
if (b instanceof Dosage)
return (Dosage) b;
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)
return (Attachment) b;
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 {
@ -292,7 +292,7 @@ public class TypeConvertor {
if (b instanceof Identifier)
return (Identifier) b;
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 {
@ -313,7 +313,7 @@ public class TypeConvertor {
cc.addCoding().setCode(((StringType) b).asStringValue());
return cc;
} 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 {
@ -336,7 +336,7 @@ public class TypeConvertor {
cc.getConcept().addCoding().setCode(((StringType) b).asStringValue());
return cc;
} 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 {
@ -347,7 +347,7 @@ public class TypeConvertor {
if (b instanceof Population)
return (Population) b;
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()) {
return new Coding().setCode(b.primitiveValue());
} 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) {
ICoding c = (ICoding) b;
@ -383,7 +383,7 @@ public class TypeConvertor {
} else if (b.isPrimitive()) {
return new Coding().setCode(b.primitiveValue());
} 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)
return (Quantity) b;
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 {
@ -406,7 +406,7 @@ public class TypeConvertor {
if (b instanceof Count)
return (Count) b;
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 {
@ -416,8 +416,11 @@ public class TypeConvertor {
if (b instanceof Money)
return (Money) b;
else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to an Money");
else if (b instanceof org.hl7.fhir.r5.elementmodel.Element && Utilities.tail(b.fhirType()).equals("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 {
@ -428,7 +431,7 @@ public class TypeConvertor {
if (b instanceof Duration)
return (Duration) b;
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 {
@ -448,7 +451,7 @@ public class TypeConvertor {
sq.setCodeElement(q.getCodeElement());
return sq;
} 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 {
@ -459,7 +462,7 @@ public class TypeConvertor {
if (b instanceof Range)
return (Range) b;
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 {
@ -470,7 +473,7 @@ public class TypeConvertor {
if (b instanceof Period)
return (Period) b;
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 {
@ -481,7 +484,7 @@ public class TypeConvertor {
if (b instanceof Ratio)
return (Ratio) b;
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 {
@ -492,7 +495,7 @@ public class TypeConvertor {
if (b instanceof SampledData)
return (SampledData) b;
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 {
@ -503,7 +506,7 @@ public class TypeConvertor {
if (b instanceof Signature)
return (Signature) b;
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 {
@ -514,7 +517,7 @@ public class TypeConvertor {
if (b instanceof HumanName)
return (HumanName) b;
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 {
@ -525,7 +528,7 @@ public class TypeConvertor {
if (b instanceof Address)
return (Address) b;
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 {
@ -536,7 +539,7 @@ public class TypeConvertor {
if (b instanceof ContactDetail)
return (ContactDetail) b;
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 {
@ -547,7 +550,7 @@ public class TypeConvertor {
if (b instanceof Contributor)
return (Contributor) b;
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 {
@ -558,7 +561,7 @@ public class TypeConvertor {
if (b instanceof UsageContext)
return (UsageContext) b;
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 {
@ -569,7 +572,7 @@ public class TypeConvertor {
if (b instanceof RelatedArtifact)
return (RelatedArtifact) b;
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 {
@ -580,7 +583,7 @@ public class TypeConvertor {
if (b instanceof ContactPoint)
return (ContactPoint) b;
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 {
@ -591,7 +594,7 @@ public class TypeConvertor {
if (b instanceof Timing)
return (Timing) b;
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 {
@ -603,11 +606,11 @@ public class TypeConvertor {
return (Reference) b;
else if (b.isPrimitive() && Utilities.isURL(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;
return new Reference().setReference(e.getChildValue("reference")).setDisplay(e.getChildValue("display"));
} 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 {
@ -618,7 +621,7 @@ public class TypeConvertor {
if (b instanceof Meta)
return (Meta) b;
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)
return (MarketingStatus) b;
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 {
@ -641,7 +644,7 @@ public class TypeConvertor {
if (b instanceof Statistic)
return (Statistic) b;
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)
return (OrderedDistribution) b;
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 {
@ -664,7 +667,7 @@ public class TypeConvertor {
if (b instanceof ProductShelfLife)
return (ProductShelfLife) b;
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 {
@ -675,7 +678,7 @@ public class TypeConvertor {
if (b instanceof ProdCharacteristic)
return (ProdCharacteristic) b;
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)
return (SubstanceAmount) b;
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 {
@ -698,7 +701,7 @@ public class TypeConvertor {
if (b instanceof Extension)
return (Extension) b;
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 {
@ -709,7 +712,7 @@ public class TypeConvertor {
if (b instanceof Resource)
return (Resource) b;
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 {
@ -720,7 +723,7 @@ public class TypeConvertor {
if (b instanceof Narrative)
return (Narrative) b;
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)
return (ElementDefinition) b;
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 {
@ -743,7 +746,7 @@ public class TypeConvertor {
if (b instanceof DataRequirement)
return (DataRequirement) b;
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 {
@ -754,7 +757,7 @@ public class TypeConvertor {
if (b instanceof Expression)
return (Expression) b;
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)
return (ParameterDefinition) b;
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 {
@ -777,7 +780,7 @@ public class TypeConvertor {
if (b instanceof TriggerDefinition)
return (TriggerDefinition) b;
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 {
@ -788,7 +791,7 @@ public class TypeConvertor {
if (b instanceof ExtendedContactDetail)
return (ExtendedContactDetail) b;
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);
}
} 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 {
@ -829,7 +832,7 @@ public class TypeConvertor {
} else if (b instanceof StringType) {
return ((StringType) b).asStringValue();
} 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)
return (VirtualServiceDetail) b;
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)
return (Availability) b;
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)
return (MonetaryComponent) b;
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;
if (tgt.hasTransform()) {
v = runTransform(rulePath, context, map, group, tgt, vars, dest, tgt.getElement(), srcVar, atRoot);
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
if (v != null && dest != null) {
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) {
if (tgt.hasListMode(StructureMapTargetListMode.SHARE)) {
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.hl7.fhir.exceptions.FHIRException;
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.XmlParser;
import org.hl7.fhir.r5.model.*;
@ -204,7 +207,12 @@ public class FHIRPathTests {
if (node != null) {
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));
} catch (Exception e) {
System.out.println("Execution Error: "+e.getMessage());

View File

@ -1184,7 +1184,7 @@ public class Utilities {
if (ref != null && ref.contains(":")) {
String scheme = ref.substring(0, ref.indexOf(":"));
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
}
return false;
@ -2002,6 +2002,28 @@ public class Utilities {
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) {

View File

@ -81,11 +81,11 @@ public class BundleValidator extends BaseValidator {
}
if (type.equals(MESSAGE)) {
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)) {
String id = resource.getNamedChildValue(ID);
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)) {
checkSearchSet(errors, bundle, entries, stack);
@ -600,7 +600,9 @@ public class BundleValidator extends BaseValidator {
}
Set<EntrySummary> visited = new HashSet<>();
visitLinked(visited, entryList.get(0));
if (entryList.size() > 0) {
visitLinked(visited, entryList.get(0));
}
visitBundleLinks(visited, entryList, bundle);
boolean foundRevLinks;
do {

View File

@ -154,7 +154,7 @@ public class ValueSetValidator extends BaseValidator {
}
cc++;
}
if (parent.isValidateValueSetCodesOnTxServer() && batch.size() > 0) {
if (parent.isValidateValueSetCodesOnTxServer() && batch.size() > 0 & !context.isNoTerminologyServer()) {
long t = System.currentTimeMillis();
if (parent.isDebug()) {
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 error;
private int back;
private int elements;
private int lostElements;
public void example() {
total++;
@ -132,6 +134,22 @@ public class R4R5MapTester implements IValidatorResourceFetcher {
public void 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;
@ -143,6 +161,8 @@ public class R4R5MapTester implements IValidatorResourceFetcher {
private InstanceValidator validator;
private StringBuilder log;
public static void main(String[] args) throws JsonException, IOException {
// 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 {
log = new StringBuilder();
log("Load Test Outcomes");
JsonObject json = JsonParser.parseObjectFromFile(Utilities.path(src, "input", "_data", "conversions.json"));
log("Load R5");
@ -200,14 +221,17 @@ public class R4R5MapTester implements IValidatorResourceFetcher {
log(" "+rn);
JsonObject o = json.getJsonObject(rn);
StructureDefinition sd = context.fetchTypeDefinition(rn);
List<StructureMap> mapSrc = utils.getMapsForUrl(allMaps, sd.getUrl(), StructureMapInputMode.SOURCE);
List<StructureMap> mapTgt = utils.getMapsForUrl(allMaps, sd.getUrl(), StructureMapInputMode.TARGET);
changed = checkMaps(sd, o.getJsonObject("r4"), "r4", "http://hl7.org/fhir/4.0", mapSrc, mapTgt, r4Examples) || changed;
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);
if (sd != null) {
List<StructureMap> mapSrc = utils.getMapsForUrl(allMaps, sd.getUrl(), StructureMapInputMode.SOURCE);
List<StructureMap> mapTgt = utils.getMapsForUrl(allMaps, sd.getUrl(), StructureMapInputMode.TARGET);
changed = checkMaps(sd, o.getJsonObject("r4"), "r4", "http://hl7.org/fhir/4.0", mapSrc, mapTgt, r4Examples) || changed;
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");
}
}
TextFile.stringToFile(log.toString(), Utilities.path(src, "input", "_data", "validation.log"));
log("Done!");
// load R4
// 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 {
Stats stats = new Stats();
for (String s : examples.listResources(tsd.getType())) {
log(" Test "+examples.id()+"::"+s);
log(" Test "+examples.id()+"::"+s, false);
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) {
log("error: "+e.getMessage());
e.printStackTrace();
stats.error("Error: "+e.getMessage());
}
}
@ -317,15 +342,22 @@ public class R4R5MapTester implements IValidatorResourceFetcher {
json.set("r5InError", stats.errorCount());
json.remove("r5validatedOK");
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()) {
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();
Element r4 = new org.hl7.fhir.r5.elementmodel.JsonParser(context).setLogical(tsd).parseSingle(stream);
stats.parsed();
int elementCountBefore = r4.countDescendents()+1;
String id = r4.getIdBase();
json.remove(id);
checkSave(id+"."+code, "loaded", r4);
@ -347,18 +379,24 @@ public class R4R5MapTester implements IValidatorResourceFetcher {
boolean valid = true;
for (ValidationMessage vm : r5validationErrors) {
if (vm.isError()) {
// json.forceObject(id).forceArray("r5-errors").add(vm.summary());
log.append(vm.summary());
log.append("\r\n");
valid = false;
}
}
if (valid) {
log.append("All OK\r\n");
}
log.append("\r\n");
stats.valid(valid);
} catch (Exception e) {
json.forceObject(id).set("validation-error", e.getMessage());
throw e;
}
Element rt4 = null;
try {
Element rt4 = Manager.build(context, tsd);
rt4 = Manager.build(context, tsd);
utils.transform(context, r5, srcG.getTargetMap(), rt4);
stats.back();
checkSave(id+"."+code, "returned", r4);
@ -366,6 +404,10 @@ public class R4R5MapTester implements IValidatorResourceFetcher {
json.forceObject(id).set("return-error", e.getMessage());
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 {
@ -381,7 +423,15 @@ public class R4R5MapTester implements IValidatorResourceFetcher {
}
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

View File

@ -19,7 +19,7 @@
<properties>
<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_platform_launcher_version>1.8.2</junit_platform_launcher_version>
<maven_surefire_version>3.0.0-M5</maven_surefire_version>