mirror of
https://github.com/hapifhir/org.hl7.fhir.core.git
synced 2025-03-02 17:39:11 +00:00
check extensions with fhirpath context
This commit is contained in:
parent
f30fda2382
commit
e697ec1c4c
@ -1034,6 +1034,7 @@ public class I18nConstants {
|
||||
public static final String BUNDLE_BUNDLE_ENTRY_FOUND_MULTIPLE_FRAGMENT = "BUNDLE_BUNDLE_ENTRY_FOUND_MULTIPLE_FRAGMENT";
|
||||
public static final String XHTML_IDREF_NOT_FOUND = "XHTML_IDREF_NOT_FOUND";
|
||||
public static final String XHTML_IDREF_NOT_MULTIPLE_MATCHES = "XHTML_IDREF_NOT_MULTIPLE_MATCHES";
|
||||
public static final String SD_CONTEXT_SHOULD_NOT_BE_FHIRPATH = "SD_CONTEXT_SHOULD_NOT_BE_FHIRPATH";
|
||||
}
|
||||
|
||||
|
||||
|
@ -933,6 +933,7 @@ NO_VALID_DISPLAY_FOUND_other = No valid Display Names found for {1}#{2} in the l
|
||||
SD_NO_CONTEXT_WHEN_NOT_EXTENSION = The type is {0} so an extension context should not be specified
|
||||
SD_NO_CONTEXT_INV_WHEN_NOT_EXTENSION = The type is {0} so an extension context invariants should not be specified
|
||||
SD_CONTEXT_SHOULD_NOT_BE_ELEMENT = Review the extension type for {1}: extensions should not have a context of {0} unless it''s really intended that they can be used anywhere
|
||||
SD_CONTEXT_SHOULD_NOT_BE_FHIRPATH = Review the extension type for {1}: the context of {0} appears to be a simple element, so the context type should be 'element' not 'fhirpath'
|
||||
ED_PATH_WRONG_TYPE_MATCH = The path must be ''{0}'' not ''{1}'' when the type list is not constrained
|
||||
ATTEMPT_TO_CHANGE_SLICING = The element at {0} defines the slicing {1} but then an element in the slicing {2} tries to redefine the slicing to {3}
|
||||
REPEAT_SLICING_IGNORED = The element at {0} defines the slicing but then an element in the slicing {2} repeats it, which is ignored
|
||||
|
@ -270,7 +270,7 @@ public class StructureDefinitionValidator extends BaseValidator {
|
||||
// this is ok (it must have this), and there's nothing to check
|
||||
} else if (child.getName().equals("binding")) {
|
||||
if (rule(errors, "2023-05-27", IssueType.INVALID, stack.getLiteralPath(), bd.hasBinding(),
|
||||
I18nConstants.SD_OBGLIGATION_PROFILE_ILLEGAL_BINDING, id)) {
|
||||
I18nConstants.SD_OBGLIGATION_PROFILE_ILLEGAL_BINDING, id)) {
|
||||
ok = validateObligationProfileElementBinding(errors, child, stack, id, bd) && ok;
|
||||
} else {
|
||||
ok = false;
|
||||
@ -357,6 +357,8 @@ public class StructureDefinitionValidator extends BaseValidator {
|
||||
}
|
||||
if ("element".equals(ct) && "Element".equals(cv)) {
|
||||
warning(errors, "2023-04-23", IssueType.BUSINESSRULE, n.getLiteralPath(), false, I18nConstants.SD_CONTEXT_SHOULD_NOT_BE_ELEMENT, cv, src.getNamedChildValue("id", false));
|
||||
} else if ("fhirpath".equals(ct)) {
|
||||
warning(errors, "2023-12-05", IssueType.BUSINESSRULE, n.getLiteralPath(), !isElement(cv), I18nConstants.SD_CONTEXT_SHOULD_NOT_BE_FHIRPATH, cv, src.getNamedChildValue("id", false));
|
||||
}
|
||||
} else {
|
||||
ok = rule(errors, "2023-04-23", IssueType.INVALID, n.getLiteralPath(), false, I18nConstants.SD_NO_CONTEXT_WHEN_NOT_EXTENSION, type) && ok;
|
||||
@ -374,6 +376,16 @@ public class StructureDefinitionValidator extends BaseValidator {
|
||||
return ok;
|
||||
}
|
||||
|
||||
private boolean isElement(String cv) {
|
||||
String tn = cv.contains(".") ? cv.substring(0, cv.indexOf(".")) : cv;
|
||||
StructureDefinition sd = context.fetchTypeDefinition(tn);
|
||||
if (sd != null) {
|
||||
return sd.getSnapshot().getElementByPath(cv) != null;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean validateElementList(List<ValidationMessage> errors, Element elementList, NodeStack stack, boolean snapshot, boolean hasSnapshot, StructureDefinition sd, String typeName, boolean logical, boolean constraint, String rootPath, String profileUrl, String profileType, StructureDefinition base) {
|
||||
Map<String, String> invariantMap = new HashMap<>();
|
||||
boolean ok = true;
|
||||
@ -457,8 +469,8 @@ public class StructureDefinitionValidator extends BaseValidator {
|
||||
ok = validateBinding(errors, binding, stack.push(binding, -1, null, null), typeCodes, snapshot, path) && ok;
|
||||
} else {
|
||||
// this is a good idea but there's plenty of cases where the rule isn't met; maybe one day it's worth investing the time to exclude these cases and bring this rule back
|
||||
// String bt = boundType(typeCodes);
|
||||
// hint(errors, UNKNOWN_DATE_TIME, IssueType.BUSINESSRULE, stack.getLiteralPath(), !snapshot || bt == null, I18nConstants.SD_ED_SHOULD_BIND, element.getNamedChildValue("path", false), bt);
|
||||
// String bt = boundType(typeCodes);
|
||||
// hint(errors, UNKNOWN_DATE_TIME, IssueType.BUSINESSRULE, stack.getLiteralPath(), !snapshot || bt == null, I18nConstants.SD_ED_SHOULD_BIND, element.getNamedChildValue("path", false), bt);
|
||||
}
|
||||
if (!typeCodes.isEmpty()) {
|
||||
if (element.hasChild("maxLength", false)) {
|
||||
@ -662,16 +674,16 @@ public class StructureDefinitionValidator extends BaseValidator {
|
||||
}
|
||||
|
||||
private Element getParent(List<Element> elements, Element te) {
|
||||
int i = elements.indexOf(te) - 1;
|
||||
String path = te.getNamedChildValue("path", false);
|
||||
while (i >= 0) {
|
||||
String p = elements.get(i).getNamedChildValue("path", false);
|
||||
if (path.startsWith(p+".")) {
|
||||
return elements.get(i);
|
||||
}
|
||||
i--;
|
||||
}
|
||||
return null;
|
||||
int i = elements.indexOf(te) - 1;
|
||||
String path = te.getNamedChildValue("path", false);
|
||||
while (i >= 0) {
|
||||
String p = elements.get(i).getNamedChildValue("path", false);
|
||||
if (path.startsWith(p+".")) {
|
||||
return elements.get(i);
|
||||
}
|
||||
i--;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<String> getTypesForElement(List<Element> elements, Element element, String profileType) {
|
||||
@ -803,9 +815,9 @@ public class StructureDefinitionValidator extends BaseValidator {
|
||||
case "Element" :return addCharacteristicsForType(set);
|
||||
case "Base" :return addCharacteristicsForType(set);
|
||||
default:
|
||||
// if (!context.getResourceNames().contains(tc)) {
|
||||
// System.out.println("Unhandled data type in addCharacteristics: "+tc);
|
||||
// }
|
||||
// if (!context.getResourceNames().contains(tc)) {
|
||||
// System.out.println("Unhandled data type in addCharacteristics: "+tc);
|
||||
// }
|
||||
return addCharacteristicsForType(set);
|
||||
}
|
||||
}
|
||||
@ -1060,7 +1072,7 @@ public class StructureDefinitionValidator extends BaseValidator {
|
||||
private boolean isReferenceableTarget(StructureDefinition t) {
|
||||
for (Extension ext : t.getExtensionsByUrl(ExtensionConstants.EXT_SDTYPE_CHARACTERISTICS)) {
|
||||
if (ext.hasValue()) {
|
||||
String c = ext.getValue().primitiveValue();
|
||||
String c = ext.getValue().primitiveValue();
|
||||
if ("can-be-target".equals(c)) {
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user