Merge pull request #1447 from hapifhir/2023-09-gg-cda-fixes

2023 09 gg cda fixes
This commit is contained in:
Grahame Grieve 2023-09-29 19:23:05 +10:00 committed by GitHub
commit 0d4e1af1a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 234 additions and 27 deletions

View File

@ -92,6 +92,7 @@ import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingCompo
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionSnapshotComponent;
import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule;
import org.hl7.fhir.r5.model.UriType;
import org.hl7.fhir.r5.model.UsageContext;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent;
import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent;
@ -2691,6 +2692,14 @@ public class ProfileUtilities extends TranslatingUtilities {
if (d.hasValueSet()) {
nb.setValueSet(d.getValueSet());
}
for (ElementDefinitionBindingAdditionalComponent ab : d.getAdditional()) {
ElementDefinitionBindingAdditionalComponent eab = getMatchingAdditionalBinding(nb, ab);
if (eab != null) {
mergeAdditionalBinding(eab, ab);
} else {
nb.getAdditional().add(ab);
}
}
base.setBinding(nb);
} else if (trimDifferential)
derived.setBinding(null);
@ -2790,6 +2799,42 @@ public class ProfileUtilities extends TranslatingUtilities {
//updateURLs(url, webUrl, dest);
}
private void mergeAdditionalBinding(ElementDefinitionBindingAdditionalComponent dest, ElementDefinitionBindingAdditionalComponent source) {
for (UsageContext t : source.getUsage()) {
if (!hasUsage(dest, t)) {
dest.addUsage(t);
}
}
if (source.getAny()) {
source.setAny(true);
}
if (source.hasShortDoco()) {
dest.setShortDoco(source.getShortDoco());
}
if (source.hasDocumentation()) {
dest.setDocumentation(source.getDocumentation());
}
}
private boolean hasUsage(ElementDefinitionBindingAdditionalComponent dest, UsageContext tgt) {
for (UsageContext t : dest.getUsage()) {
if (t.getCode() != null && t.getCode().matches(tgt.getCode()) && t.getValue() != null && t.getValue().equals(tgt.getValue())) {
return true;
}
}
return false;
}
private ElementDefinitionBindingAdditionalComponent getMatchingAdditionalBinding(ElementDefinitionBindingComponent nb,ElementDefinitionBindingAdditionalComponent ab) {
for (ElementDefinitionBindingAdditionalComponent t : nb.getAdditional()) {
if (t.getValueSet() != null && t.getValueSet().equals(ab.getValueSet()) && t.getPurpose() == ab.getPurpose()) {
return t;
}
}
return null;
}
private void mergeExtensions(Element tgt, Element src) {
tgt.getExtension().addAll(src.getExtension());
}

View File

@ -422,7 +422,7 @@ public class FmlParser extends ParserBase {
lexer.token("(");
boolean done = false;
while (!done) {
parseParameter(ref, lexer);
parseParameter(ref, lexer, false);
done = !lexer.hasToken(",");
if (!done)
lexer.next();
@ -527,7 +527,7 @@ public class FmlParser extends ParserBase {
target.makeElement("transform").markLocation(loc).setValue(name);
lexer.token("(");
if (target.getChildValue("transform").equals(StructureMapTransform.EVALUATE.toCode())) {
parseParameter(target, lexer);
parseParameter(target, lexer, true);
lexer.token(",");
loc = lexer.getCurrentLocation();
ExpressionNode node = fpe.parse(lexer);
@ -535,7 +535,7 @@ public class FmlParser extends ParserBase {
target.addElement("parameter").markLocation(loc).makeElement("valueString").setValue(node.toString());
} else {
while (!lexer.hasToken(")")) {
parseParameter(target, lexer);
parseParameter(target, lexer, true);
if (!lexer.hasToken(")"))
lexer.token(",");
}
@ -568,9 +568,9 @@ public class FmlParser extends ParserBase {
}
}
private void parseParameter(Element ref, FHIRLexer lexer) throws FHIRLexerException, FHIRFormatError {
private void parseParameter(Element ref, FHIRLexer lexer, boolean isTarget) throws FHIRLexerException, FHIRFormatError {
boolean r5 = VersionUtilities.isR5Plus(context.getVersion());
String name = r5 ? "parameter" : "variable";
String name = r5 || isTarget ? "parameter" : "variable";
if (ref.hasChildren(name) && !ref.getChildByName(name).isList()) {
throw lexer.error("variable on target is not a list, so can't add an element");
} else if (!lexer.isConstant()) {

View File

@ -143,9 +143,12 @@ public abstract class ParserBase {
protected StructureDefinition getDefinition(List<ValidationMessage> errors, int line, int col, String ns, String name) throws FHIRFormatError {
if (logical != null) {
String expectedName = ToolingExtensions.readStringExtension(logical, "http://hl7.org/fhir/StructureDefinition/elementdefinition-name");
String expectedName = ToolingExtensions.readStringExtension(logical, "http://hl7.org/fhir/StructureDefinition/elementdefinition-xml-name");
if (expectedName == null) {
expectedName = logical.getType();
if (Utilities.isAbsoluteUrl(expectedName)) {
expectedName = expectedName.substring(expectedName.lastIndexOf("/")+1);
}
}
String expectedNamespace = ToolingExtensions.readStringExtension(logical, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace");
if (matchesNamespace(expectedNamespace, ns) && matchesName(expectedName, name)) {

View File

@ -38,7 +38,9 @@ import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@ -357,13 +359,19 @@ public class XmlParser extends ParserBase {
if (property != null) {
String av = attr.getNodeValue();
if (ToolingExtensions.hasExtension(property.getDefinition(), ToolingExtensions.EXT_DATE_FORMAT))
av = convertForDateFormatFromExternal(ToolingExtensions.readStringExtension(property.getDefinition(), ToolingExtensions.EXT_DATE_FORMAT), av);
av = convertForDateFormatFromExternal(ToolingExtensions.readStringExtension(property.getDefinition(), ToolingExtensions.EXT_DATE_FORMAT), av);
if (property.getName().equals("value") && element.isPrimitive())
element.setValue(av);
else {
Element n = new Element(property.getName(), property, property.getType(), av).markLocation(line, col);
n.setPath(element.getPath()+"."+property.getName());
element.getChildren().add(n);
String[] vl = {av};
if (property.isList() && av.contains(" ")) {
vl = av.split(" ");
}
for (String v : vl) {
Element n = new Element(property.getName(), property, property.getType(), v).markLocation(line, col);
n.setPath(element.getPath()+"."+property.getName());
element.getChildren().add(n);
}
}
} else {
boolean ok = false;
@ -739,11 +747,20 @@ public class XmlParser extends ParserBase {
}
} else {
setXsiTypeIfIsTypeAttr(xml, element);
Set<String> handled = new HashSet<>();
for (Element child : element.getChildren()) {
if (isAttr(child.getProperty()) && wantCompose(element.getPath(), child)) {
if (!handled.contains(child.getName()) && isAttr(child.getProperty()) && wantCompose(element.getPath(), child)) {
handled.add(child.getName());
String av = child.getValue();
if (child.getProperty().isList()) {
for (Element c2 : element.getChildren()) {
if (c2 != child && c2.getName().equals(child.getName())) {
av = av + " "+c2.getValue();
}
}
}
if (linkResolver != null)
xml.link(linkResolver.resolveType(child.getType()));
String av = child.getValue();
if (ToolingExtensions.hasExtension(child.getProperty().getDefinition(), ToolingExtensions.EXT_DATE_FORMAT))
av = convertForDateFormatToExternal(ToolingExtensions.readStringExtension(child.getProperty().getDefinition(), ToolingExtensions.EXT_DATE_FORMAT), av);
xml.attribute(child.getProperty().getXmlNamespace(),child.getProperty().getXmlName(), av);

View File

@ -186,6 +186,18 @@ public class AdditionalBindingsRenderer {
return abr;
}
protected AdditionalBindingDetail additionalBinding(ElementDefinitionBindingAdditionalComponent ab) {
AdditionalBindingDetail abr = new AdditionalBindingDetail();
abr.purpose = ab.getPurpose().toCode();
abr.valueSet = ab.getValueSet();
abr.doco = ab.getDocumentation();
abr.docoShort = ab.getShortDoco();
abr.usage = ab.hasUsage() ? ab.getUsageFirstRep() : null;
abr.any = ab.getAny();
abr.isUnchanged = ab.hasUserData(ProfileUtilities.UD_DERIVATION_EQUALS);
return abr;
}
public String render() throws IOException {
if (bindings.isEmpty()) {
return "";
@ -455,4 +467,40 @@ public class AdditionalBindingsRenderer {
}
public void seeAdditionalBindings(ElementDefinition definition, ElementDefinition compDef, boolean compare) {
HashMap<String, AdditionalBindingDetail> compBindings = new HashMap<String, AdditionalBindingDetail>();
if (compare && compDef.getBinding().getAdditional() != null) {
for (ElementDefinitionBindingAdditionalComponent ab : compDef.getBinding().getAdditional()) {
AdditionalBindingDetail abr = additionalBinding(ab);
if (compBindings.containsKey(abr.getKey())) {
abr.incrementCount();
}
compBindings.put(abr.getKey(), abr);
}
}
for (ElementDefinitionBindingAdditionalComponent ab : definition.getBinding().getAdditional()) {
AdditionalBindingDetail abr = additionalBinding(ab);
if (compare && compDef != null) {
AdditionalBindingDetail match = null;
do {
match = compBindings.get(abr.getKey());
if (abr.alreadyMatched())
abr.incrementCount();
} while (match!=null && abr.alreadyMatched());
if (match!=null)
abr.setCompare(match);
bindings.add(abr);
if (abr.compare!=null)
compBindings.remove(abr.compare.getKey());
} else
bindings.add(abr);
}
for (AdditionalBindingDetail b: compBindings.values()) {
b.removed = true;
bindings.add(b);
}
}
}

View File

@ -68,6 +68,7 @@ import org.hl7.fhir.r5.model.UriType;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.StructureDefinitionRenderer.InternalMarkdownProcessor;
import org.hl7.fhir.r5.renderers.StructureDefinitionRenderer.SourcedElementDefinition;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.GenerationRules;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.KnownLinkType;
@ -157,6 +158,25 @@ public class StructureDefinitionRenderer extends ResourceRenderer {
//
// }
public class SourcedElementDefinition {
private StructureDefinition profile;
private ElementDefinition definition;
protected SourcedElementDefinition(StructureDefinition profile, ElementDefinition definition) {
super();
this.profile = profile;
this.definition = definition;
}
public StructureDefinition getProfile() {
return profile;
}
public ElementDefinition getDefinition() {
return definition;
}
}
public class InternalMarkdownProcessor implements IMarkdownProcessor {
@Override
@ -1320,6 +1340,22 @@ public class StructureDefinitionRenderer extends ResourceRenderer {
}
}
}
if (logicalModel) {
List<SourcedElementDefinition> ancestors = new ArrayList<>();
getAncestorElements(profile, ancestors);
if (ancestors.size() > 0) {
c.addPiece(gen.new Piece("br"));
c.addPiece(gen.new Piece(null, "Elements defined in Ancestors: ", null));
boolean first = true;
for (SourcedElementDefinition ed : ancestors) {
if (first)
first = false;
else
c.addPiece(gen.new Piece(null, ", ", null));
c.addPiece(gen.new Piece(ed.getProfile().getWebPath(), (isAttr(ed) ? "@" : "")+ed.getDefinition().getName(), ed.getDefinition().getDefinition()));
}
}
}
}
if (definition.getPath().endsWith("url") && definition.hasFixed()) {
c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "\""+buildJson(definition.getFixed())+"\"", null).addStyle("color: darkgreen")));
@ -1552,6 +1588,7 @@ public class StructureDefinitionRenderer extends ResourceRenderer {
}
AdditionalBindingsRenderer abr = new AdditionalBindingsRenderer(context.getPkp(), corePath, profile, definition.getPath(), rc, null, this);
abr.seeAdditionalBindings(definition, null, false);
if (binding.hasExtension(ToolingExtensions.EXT_MAX_VALUESET)) {
abr.seeMaxBinding(ToolingExtensions.getExtension(binding, ToolingExtensions.EXT_MAX_VALUESET));
}
@ -1651,6 +1688,26 @@ public class StructureDefinitionRenderer extends ResourceRenderer {
return c;
}
private boolean isAttr(SourcedElementDefinition ed) {
for (Enumeration<PropertyRepresentation> t : ed.getDefinition().getRepresentation()) {
if (t.getValue() == PropertyRepresentation.XMLATTR) {
return true;
}
}
return false;
}
private void getAncestorElements(StructureDefinition profile, List<SourcedElementDefinition> ancestors) {
StructureDefinition base = context.getContext().fetchResource(StructureDefinition.class, profile.getBaseDefinition());
if (base != null) {
getAncestorElements(base, ancestors);
for (ElementDefinition ed : base.getDifferential().getElement()) {
if (Utilities.charCount(ed.getPath(), '.') == 1) {
ancestors.add(new SourcedElementDefinition(base, ed));
}
}
}
}
private void addCanonicalListExt(HierarchicalTableGenerator gen, Cell c, List<Extension> list, String start, boolean bold) {
List<CanonicalType> clist = new ArrayList<>();

View File

@ -686,6 +686,9 @@ public class ValueSetValidator extends ValueSetProcessBase {
private ValidationResult validateCode(String path, Coding code, CodeSystem cs, CodeableConcept vcc, ValidationProcessInfo info) {
ConceptDefinitionComponent cc = cs.hasUserData("tx.cs.special") ? ((SpecialCodeSystem) cs.getUserData("tx.cs.special")).findConcept(code) : findCodeInConcept(cs.getConcept(), code.getCode(), allAltCodes);
if (cc == null) {
cc = findSpecialConcept(code, cs);
}
if (cc == null) {
if (cs.getContent() == CodeSystemContentMode.FRAGMENT) {
String msg = context.formatMessage(I18nConstants.UNKNOWN_CODE__IN_FRAGMENT, code.getCode(), cs.getVersionedUrl());
@ -759,6 +762,28 @@ public class ValueSetValidator extends ValueSetProcessBase {
}
}
private ConceptDefinitionComponent findSpecialConcept(Coding c, CodeSystem cs) {
// handling weird special cases in v2 code systems
if ("http://terminology.hl7.org/CodeSystem/v2-0203".equals(cs.getUrl())) {
String code = c.getCode();
if (code != null && code.startsWith("NN") && code.length() > 3) {
ConceptDefinitionComponent cd = findCountryCode(code.substring(2));
if (cd != null) {
return new ConceptDefinitionComponent(code).setDisplay("National Identifier for "+cd.getDisplay());
}
}
}
// 0396: HL7nnnn, IBTnnnn, ISOnnnn, X12Dennnn, 99zzz
// 0335: PRNxxx
return null;
}
private ConceptDefinitionComponent findCountryCode(String code) {
ValidationResult vr = context.validateCode(new ValidationOptions(), "urn:iso:std:iso:3166", null, code, null);
return vr == null || !vr.isOk() ? null : new ConceptDefinitionComponent(code).setDisplay(vr.getDisplay()).setDefinition(vr.getDefinition());
}
private IssueSeverity dispWarning() {
return options.isDisplayWarningMode() ? IssueSeverity.WARNING : IssueSeverity.ERROR;
}
@ -811,15 +836,6 @@ public class ValueSetValidator extends ValueSetProcessBase {
return null;
}
private String gen(Coding code) {
if (code.hasSystem()) {
return code.getSystem()+"#"+code.getCode();
} else {
return null;
}
}
private String getValueSetSystemOrNull() throws FHIRException {
if (valueset == null) {
return null;

View File

@ -6,6 +6,6 @@ public class CommonPackages {
public static final String VER_XVER = "0.0.12";
public static final String ID_PUBPACK = "hl7.fhir.pubpack";
public static final String VER_PUBPACK = "0.1.5";
public static final String VER_PUBPACK = "0.1.6";
}

View File

@ -394,10 +394,10 @@ Does_not_match_slice_ = Does not match slice ''{0}'' (discriminator: {1})
Profile__does_not_match_for__because_of_the_following_profile_issues__ = Profile {0} does not match for {1} because of the following profile issues: {2}
This_element_does_not_match_any_known_slice_ = This element does not match any known slice {0}
defined_in_the_profile = Defined in the profile
This_does_not_appear_to_be_a_FHIR_resource_unknown_name_ = This does not appear to be a FHIR resource (unknown name ''{0}'')
This_cannot_be_parsed_as_a_FHIR_object_no_name = This cannot be parsed as a FHIR object (no name)
This_does_not_appear_to_be_a_FHIR_resource_unknown_namespacename_ = This does not appear to be a FHIR resource (unknown namespace/name ''{0}::{1}'')
This__cannot_be_parsed_as_a_FHIR_object_no_namespace = This ''{0}'' cannot be parsed as a FHIR object (no namespace)
This_does_not_appear_to_be_a_FHIR_resource_unknown_name_ = This content cannot be parsed (unknown or unrecognised XML root element name ''{0}'')
This_cannot_be_parsed_as_a_FHIR_object_no_name = This content cannot be parsed (no name)
This_does_not_appear_to_be_a_FHIR_resource_unknown_namespacename_ = This content cannot be parsed (unknown or unrecognised XML Root element namespace/name ''{0}::{1}'')
This__cannot_be_parsed_as_a_FHIR_object_no_namespace = This ''{0}'' cannot be parsed (no namespace on the XML Root element)
Unable_to_find_resourceType_property = Unable to find resourceType property
Error_parsing_JSON_the_primitive_value_must_be_a_string = Error parsing JSON: the primitive value must be a string
Error_parsing_JSON_the_primitive_value_must_be_a_number = Error parsing JSON: the primitive value must be a number

View File

@ -1169,7 +1169,7 @@ public class StructureMapValidator extends BaseValidator {
Element g = (Element) grp.getTargetGroup().getUserData("element.source");
if (g.hasUserData("structuremap.parameters")) {
VariableSet pvars = (VariableSet) g.getUserData("structuremap.parameters");
rule(errors, "2023-03-01", IssueType.INVALID, dependent.line(), dependent.col(), stack.getLiteralPath(), pvars.matches(lvars), I18nConstants.SM_DEPENDENT_PARAM_TYPE_MISMATCH_DUPLICATE, grp.getTargetGroup().getName(), pvars.summary(), lvars.summary());
warning(errors, "2023-03-01", IssueType.INVALID, dependent.line(), dependent.col(), stack.getLiteralPath(), pvars.matches(lvars), I18nConstants.SM_DEPENDENT_PARAM_TYPE_MISMATCH_DUPLICATE, grp.getTargetGroup().getName(), pvars.summary(), lvars.summary());
} else {
g.setUserData("structuremap.parameters", lvars);
}

View File

@ -163,6 +163,27 @@ v: {
"code" : "US",
"system" : "urn:iso:std:iso:3166",
"version" : "2018",
"issues" : {
"resourceType" : "OperationOutcome"
}
}
-------------------------------------------------------------------------------------
{"code" : {
"system" : "urn:iso:std:iso:3166",
"code" : "FIN"
}, "valueSet" :null, "langs":"", "useServer":"true", "useClient":"true", "guessSystem":"false", "valueSetMode":"ALL_CHECKS", "displayWarningMode":"false", "versionFlexible":"true", "profile": {
"resourceType" : "Parameters",
"parameter" : [{
"name" : "profile-url",
"valueString" : "http://hl7.org/fhir/ExpansionProfile/dc8fd4bc-091a-424a-8a3b-6198ef146891"
}]
}}####
v: {
"display" : "Finland",
"code" : "FIN",
"system" : "urn:iso:std:iso:3166",
"version" : "2018",
"unknown-systems" : "",
"issues" : {
"resourceType" : "OperationOutcome"