Fixes to validator for new CDA package (proper handling of logical model types)

This commit is contained in:
Grahame Grieve 2023-07-07 09:38:55 +10:00
parent 9a48340b6c
commit c6e68dc9c6
3 changed files with 10 additions and 5 deletions

View File

@ -175,10 +175,11 @@ public abstract class ParserBase {
}
for (StructureDefinition sd : context.fetchResourcesByType(StructureDefinition.class)) {
if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && !sd.getUrl().startsWith("http://hl7.org/fhir/StructureDefinition/de-")) {
if(name.equals(sd.getType()) && (ns == null || ns.equals(FormatUtilities.FHIR_NS)) && !ToolingExtensions.hasExtension(sd, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"))
String type = urlTail(sd.getType());
if(name.equals(type) && (ns == null || ns.equals(FormatUtilities.FHIR_NS)) && !ToolingExtensions.hasExtension(sd, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"))
return sd;
String sns = ToolingExtensions.readStringExtension(sd, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace");
if ((name.equals(sd.getType()) || name.equals(sd.getName())) && ns != null && ns.equals(sns))
if ((name.equals(type) || name.equals(sd.getName())) && ns != null && ns.equals(sns))
return sd;
}
}
@ -186,6 +187,10 @@ public abstract class ParserBase {
return null;
}
private String urlTail(String type) {
return type == null || !type.contains("/") ? type : type.substring(type.lastIndexOf("/")+1);
}
protected StructureDefinition getDefinition(int line, int col, String name) throws FHIRFormatError {
if (name == null) {
logError(ValidationMessage.NO_RULE_DATE, line, col, name, IssueType.STRUCTURE, context.formatMessage(I18nConstants.THIS_CANNOT_BE_PARSED_AS_A_FHIR_OBJECT_NO_NAME), IssueSeverity.FATAL);

View File

@ -373,7 +373,7 @@ public class Property {
ok = true;
if (Utilities.isAbsoluteUrl(tr.getWorkingCode())) {
StructureDefinition sdt = context.fetchResource(StructureDefinition.class, tr.getWorkingCode());
if (sdt != null && sdt.getType().equals(t)) {
if (sdt != null && sdt.getTypeTail().equals(t)) {
url = tr.getWorkingCode();
ok = true;
}

View File

@ -3968,7 +3968,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
long t = System.nanoTime();
StructureDefinition sd = context.fetchResource(StructureDefinition.class, url, src);
timeTracker.sd(t);
if (sd != null && (sd.getType().equals(type) || sd.getUrl().equals(type)) && sd.hasSnapshot()) {
if (sd != null && (sd.getTypeTail().equals(type) || sd.getUrl().equals(type)) && sd.hasSnapshot()) {
return sd;
}
if (sd.getAbstract()) {
@ -6334,7 +6334,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
}
}
// validate
if (rule(errors, NO_RULE_DATE, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), resourceName.equals(defn.getType()), I18nConstants.VALIDATION_VAL_PROFILE_WRONGTYPE,
if (rule(errors, NO_RULE_DATE, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), resourceName.equals(defn.getTypeTail()), I18nConstants.VALIDATION_VAL_PROFILE_WRONGTYPE,
defn.getType(), resourceName, defn.getVersionedUrl())) {
ok = start(hostContext, errors, element, element, defn, stack, pct, mode); // root is both definition and type
} else {