Merge pull request #1512 from hapifhir/gg-wip

Gg wip
This commit is contained in:
Grahame Grieve 2023-12-06 14:05:08 +11:00 committed by GitHub
commit f8572d1adb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 39 deletions

View File

@ -82,7 +82,7 @@ public class CanonicalResourceUtilities {
if (wgext == null) {
wgext = res.getOwnerDocument().createElementNS(Constants.NS_FHIR_ROOT, "extension");
wgext.setAttribute("url", ToolingExtensions.EXT_WORKGROUP);
org.w3c.dom.Element after = XMLUtil.getFirstChild(res, "modifierExtension", "url", "identifier", "version", "status");
org.w3c.dom.Element after = XMLUtil.getFirstChild(res, "modifierExtension", "url", "identifier", "version", "status", "name", "title");
if (after == null) {
after = XMLUtil.getLastChild(res, "id", "meta", "text", "implicitRules", "language", "text", "contained");
if (after != null) {
@ -90,6 +90,7 @@ public class CanonicalResourceUtilities {
}
}
res.insertBefore(wgext, after);
res.insertBefore(res.getOwnerDocument().createTextNode("/n "), after);
}
XMLUtil.clearChildren(wgext);
org.w3c.dom.Element valueCode = res.getOwnerDocument().createElementNS(Constants.NS_FHIR_ROOT, "valueCode");
@ -99,7 +100,7 @@ public class CanonicalResourceUtilities {
org.w3c.dom.Element pub = XMLUtil.getNamedChild(res, "publisher");
if (pub == null) {
pub = res.getOwnerDocument().createElementNS(Constants.NS_FHIR_ROOT, "publisher");
org.w3c.dom.Element after = XMLUtil.getFirstChild(res, "contact", "description", "useContext", "jurisdiction", "purpose", "copyright");
org.w3c.dom.Element after = XMLUtil.getFirstChild(res, "contact", "relatedArtifact", "description", "useContext", "jurisdiction", "purpose", "copyright");
res.insertBefore(pub, after);
}
pub.setAttribute("value", "HL7 International / "+wg.getName());

View File

@ -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";
}

View File

@ -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

View File

@ -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)) {
@ -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);
}
}