Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into do-20240122-base-en…
Browse files Browse the repository at this point in the history
…gine
  • Loading branch information
dotasek committed Jun 17, 2024
2 parents b24fb10 + b970653 commit fbf2d01
Show file tree
Hide file tree
Showing 44 changed files with 1,787 additions and 788 deletions.
Binary file modified i18n-coverage-table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion i18n-coverage.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Locale,Coverage #,Coverage %
de,835,42%
es,718,36%
ja,906,46%
ja,906,45%
nl,1376,69%
Original file line number Diff line number Diff line change
Expand Up @@ -453,5 +453,16 @@ public boolean isAbstractType(String typeName) {
return false;
}

public boolean isDomainResource(String typeName) {
StructureDefinition sd = context.fetchTypeDefinition(typeName);
while (sd != null) {
if ("DomainResource".equals(sd.getType())) {
return true;
}
sd = context.fetchResource(StructureDefinition.class, sd.getBaseDefinition());
}
return false;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,21 @@ public boolean hasPackage(String id, String ver) {
}

public boolean hasPackage(String idAndver) {
return loadedPackages.contains(idAndver);
if (loadedPackages.contains(idAndver)) {
return true;
}
// not clear whether the same logic should apply to other cross-version packages?
if (idAndver.startsWith("hl7.fhir.uv.extensions")) {
String v = idAndver.substring(idAndver.lastIndexOf("#")+1);
for (String s : loadedPackages) {
String v2 = s.substring(s.lastIndexOf("#")+1);
if (s.startsWith("hl7.fhir.uv.extensions.") && VersionUtilities.versionsMatch(v, v2)) {
return true;
}
}
}
return false;

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ public void compose(Element e, OutputStream stream, OutputStyle style, String id
prop("resourceType", e.getType(), null);
Set<String> done = new HashSet<String>();
for (Element child : e.getChildren()) {
compose(e.getName(), e, done, child);
compose(e.getName(), e, done, child, "");
}
json.endObject();
json.finish();
Expand All @@ -804,28 +804,28 @@ public void compose(Element e, JsonCreator json) throws Exception {
prop("resourceType", e.getType(), linkResolver == null ? null : linkResolver.resolveProperty(e.getProperty()));
Set<String> done = new HashSet<String>();
for (Element child : e.getChildren()) {
compose(e.getName(), e, done, child);
compose(e.getName(), e, done, child, "");
}
json.endObject();
json.finish();
}

private void compose(String path, Element e, Set<String> done, Element child) throws IOException {
private void compose(String path, Element e, Set<String> done, Element child, String tgtPath) throws IOException {
checkComposeComments(child);
if (wantCompose(path, child)) {
boolean isList = child.hasElementProperty() ? child.getElementProperty().isList() : child.getProperty().isList();
if (!isList) {// for specials, ignore the cardinality of the stated type
compose(path, child);
compose(path, child, tgtPath);
} else if (!done.contains(child.getName())) {
done.add(child.getName());
List<Element> list = e.getChildrenByName(child.getName());
composeList(path, list);
composeList(path, list, tgtPath);
}
}
}


private void composeList(String path, List<Element> list) throws IOException {
private void composeList(String path, List<Element> list, String tgtPath) throws IOException {
// there will be at least one element
String name = list.get(0).getName();
boolean complex = true;
Expand Down Expand Up @@ -858,6 +858,7 @@ private void composeList(String path, List<Element> list) throws IOException {
}
if (complex) {
openArray(name, linkResolver == null ? null : linkResolver.resolveProperty(list.get(0).getProperty()));
int i = 0;
for (Element item : list) {
if (item.hasChildren()) {
open(null,null);
Expand All @@ -872,11 +873,21 @@ private void composeList(String path, List<Element> list) throws IOException {
}
Set<String> done = new HashSet<String>();
for (Element child : item.getChildren()) {
compose(path+"."+name+"[]", item, done, child);
String tp = tgtPath;
if (child.getSpecial() == SpecialElement.BUNDLE_ENTRY) {
if (Utilities.noString(tp)) {
tp = "Bnd."+i+".";
} else {
tp = tgtPath+i+".";
}
}
compose(path+"."+name+"[]", item, done, child, tp);
}
close();
} else
} else {
json.nullValue();
}
i++;
}
closeArray();
}
Expand All @@ -903,14 +914,14 @@ else if (Utilities.existsInList(type, "decimal"))
json.value(item.getValue());
}

private void compose(String path, Element element) throws IOException {
private void compose(String path, Element element, String tgtPath) throws IOException {
String name = element.getName();
if (element.isPrimitive() || isPrimitive(element.getType())) {
if (element.hasValue())
primitiveValue(name, element);
name = "_"+name;
if (element.getType().equals("xhtml"))
json.anchor("end-xhtml");
json.anchor(tgtPath+"end-xhtml");
}
if (element.hasChildren()) {
open(name, linkResolver == null ? null : linkResolver.resolveProperty(element.getProperty()));
Expand All @@ -925,7 +936,7 @@ private void compose(String path, Element element) throws IOException {
}
Set<String> done = new HashSet<String>();
for (Element child : element.getChildren()) {
compose(path+"."+element.getName(), element, done, child);
compose(path+"."+element.getName(), element, done, child, tgtPath);
}
close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public XmlParser(IWorkerContext context) {
}

private String schemaPath;
private int bundleEntryCounter = 0;

public String getSchemaPath() {
return schemaPath;
Expand All @@ -117,10 +118,10 @@ public void setAllowXsiLocation(boolean allowXsiLocation) {
}

public List<ValidatedFragment> parse(InputStream inStream) throws FHIRFormatError, DefinitionException, FHIRException, IOException {

byte[] content = TextFile.streamToBytes(inStream);
ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "xml", content, false);

ByteArrayInputStream stream = new ByteArrayInputStream(content);
Document doc = null;
try {
Expand Down Expand Up @@ -318,7 +319,7 @@ private StructureDefinition findLegalConstraint(String xsiType, String actualTyp
}
return null;
}

public Element parse(List<ValidationMessage> errors, org.w3c.dom.Element base, String type) throws Exception {
StructureDefinition sd = getDefinition(errors, 0, 0, FormatUtilities.FHIR_NS, type);
Element result = new Element(base.getLocalName(), new Property(context, sd.getSnapshot().getElement().get(0), sd, getProfileUtilities(), getContextUtilities())).setFormat(FhirFormat.XML).setNativeObject(base);
Expand Down Expand Up @@ -429,7 +430,7 @@ private void parseChildren(List<ValidationMessage> errors, String path, org.w3c.
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
Property property = getElementProp(properties, child.getLocalName(), child.getNamespaceURI());

if (property != null) {
if (property.getName().equals(lastName)) {
repeatCount++;
Expand Down Expand Up @@ -507,13 +508,13 @@ private void parseChildren(List<ValidationMessage> errors, String path, org.w3c.
lastName = cgProp.getName();
repeatCount = 0;
}

String npath = path+"/"+pathPrefix(cgProp.getXmlNamespace())+cgProp.getName();
String name = cgProp.getName();
Element cgn = new Element(cgProp.getName(), cgProp).setFormat(FhirFormat.XML);
cgn.setPath(element.getPath()+"."+cgProp.getName()+"["+repeatCount+"]");
element.getChildren().add(cgn);

npath = npath+"/"+pathPrefix(child.getNamespaceURI())+child.getLocalName();
name = child.getLocalName();
Element n = new Element(name, property).markLocation(line(child, false), col(child, false)).setFormat(FhirFormat.XML).setNativeObject(child);
Expand All @@ -534,20 +535,20 @@ private void parseChildren(List<ValidationMessage> errors, String path, org.w3c.
lastName = cgProp.getName();
repeatCount = 0;
}

String npath = path+"/"+pathPrefix(cgProp.getXmlNamespace())+cgProp.getName();
String name = cgProp.getName();
Element cgn = new Element(cgProp.getName(), cgProp).setFormat(FhirFormat.XML);
cgn.setPath(element.getPath()+"."+cgProp.getName()+"["+repeatCount+"]");
element.getChildren().add(cgn);

npath = npath+"/text()";
name = mtProp.getName();
Element n = new Element(name, mtProp, mtProp.getType(), child.getTextContent().trim()).markLocation(line(child, false), col(child, false)).setFormat(FhirFormat.XML).setNativeObject(child);
cgn.getChildren().add(n);
n.setPath(element.getPath()+"."+mtProp.getName());


} else if (child.getNodeType() == Node.CDATA_SECTION_NODE) {
logError(errors, ValidationMessage.NO_RULE_DATE, line(child, false), col(child, false), path, IssueType.STRUCTURE, context.formatMessage(I18nConstants.CDATA_IS_NOT_ALLOWED), IssueSeverity.ERROR);
} else if (!Utilities.existsInList(child.getNodeType(), 3, 8)) {
Expand All @@ -565,7 +566,7 @@ private Property getChoiceGroupProp(List<Property> properties) {
}
return null;
}

private boolean validAttrValue(String value) {
if (version == null) {
return true;
Expand Down Expand Up @@ -608,7 +609,7 @@ public int compare(Property o1, Property o2) {
return p;
}
}


return null;
}
Expand Down Expand Up @@ -737,7 +738,7 @@ public void compose(Element e, OutputStream stream, OutputStyle style, String ba
if (hasTypeAttr(e))
xml.namespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");
addNamespaces(xml, e);
composeElement(xml, e, e.getType(), true);
composeElement(xml, e, e.getType(), true, "");
xml.end();
}

Expand Down Expand Up @@ -795,11 +796,11 @@ public void compose(Element e, IXMLWriter xml) throws Exception {
if (schemaPath != null) {
xml.setSchemaLocation(FormatUtilities.FHIR_NS, Utilities.pathURL(schemaPath, e.fhirType()+".xsd"));
}
composeElement(xml, e, e.getType(), true);
composeElement(xml, e, e.getType(), true, "");
xml.end();
}

private void composeElement(IXMLWriter xml, Element element, String elementName, boolean root) throws IOException, FHIRException {
private void composeElement(IXMLWriter xml, Element element, String elementName, boolean root, String tgtPath) throws IOException, FHIRException {
if (showDecorations) {
@SuppressWarnings("unchecked")
List<ElementDecoration> decorations = (List<ElementDecoration>) element.getUserData("fhir.decorations");
Expand Down Expand Up @@ -833,7 +834,7 @@ private void composeElement(IXMLWriter xml, Element element, String elementName,
new CDANarrativeFormat().convert(xml, new XhtmlParser().parseFragment(rawXhtml));
} else {
xml.escapedText(rawXhtml);
xml.anchor("end-xhtml");
xml.anchor(tgtPath+"end-xhtml");
}
} else if (isText(element.getProperty())) {
if (linkResolver != null)
Expand All @@ -857,7 +858,7 @@ private void composeElement(IXMLWriter xml, Element element, String elementName,
}
}
for (Element child : element.getChildren())
composeElement(xml, child, child.getName(), false);
composeElement(xml, child, child.getName(), false, tgtPath);
xml.exit(element.getProperty().getXmlNamespace(),elementName);
} else
xml.element(elementName);
Expand Down Expand Up @@ -908,8 +909,18 @@ private void composeElement(IXMLWriter xml, Element element, String elementName,
if (linkResolver != null)
xml.link(linkResolver.resolveProperty(element.getProperty()));
xml.text(child.getValue());
} else if (!isAttr(child.getProperty()))
composeElement(xml, child, child.getName(), false);
} else if (!isAttr(child.getProperty())) {
String tp = tgtPath;
if (child.getSpecial() == SpecialElement.BUNDLE_ENTRY) {
bundleEntryCounter ++;
if (Utilities.noString(tp)) {
tp = "Bnd."+bundleEntryCounter+".";
} else {
tp = tgtPath+bundleEntryCounter+".";
}
}
composeElement(xml, child, child.getName(), false, tp);
}
}
}
if (!root && element.getSpecial() != null)
Expand All @@ -924,12 +935,12 @@ private String makeNamespaceAbbrev(Property property, IXMLWriter xml) {
ElementDefinition ed = property.getDefinition();
String ns = property.getXmlNamespace();
String n = property.getXmlName();

String diff = property.getName().toLowerCase().replace(n.toLowerCase(), "");
if (!Utilities.noString(diff) && diff.length() <= 5 && Utilities.isToken(diff) && !xml.abbreviationDefined(diff)) {
return diff;
}

int i = ns.length()-1;
while (i > 0) {
if (Character.isAlphabetic(ns.charAt(i)) || Character.isDigit(ns.charAt(i))) {
Expand All @@ -942,7 +953,7 @@ private String makeNamespaceAbbrev(Property property, IXMLWriter xml) {
if (!Utilities.noString(tail) && tail.length() <= 5 && Utilities.isToken(tail) && !xml.abbreviationDefined(tail)) {
return tail;
}

i = 0;
while (xml.abbreviationDefined("ns"+i)) {
i++;
Expand Down Expand Up @@ -1008,17 +1019,17 @@ private String checkHeader(List<ValidationMessage> errors, InputStream stream) t
class NullErrorHandler implements ErrorHandler {
@Override
public void fatalError(SAXParseException e) {
// do nothing
// do nothing
}

@Override
public void error(SAXParseException e) {
// do nothing
// do nothing
}

@Override
public void warning(SAXParseException e) {
// do nothing
// do nothing
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1068,19 +1068,14 @@ private List<PropertyWrapper> splitExtensions(StructureDefinition profile, List<
ed = xverManager.makeDefinition(url);
new ContextUtilities(getContext().getWorker()).generateSnapshot(ed);
getContext().getWorker().cacheResource(ed);
}
}
}
if (p.getName().equals("modifierExtension") && ed == null) {
throw new DefinitionException("Unknown modifier extension "+url);
}
PropertyWrapper pe = map.get(p.getName()+"["+url+"]");
if (pe == null) {
if (ed == null) {
if (url != null && url.startsWith("http://hl7.org/fhir") && !url.startsWith("http://hl7.org/fhir/us")) {
if (!ProfileUtilities.isSuppressIgnorableExceptions()) {
throw new DefinitionException("unknown extension "+url);
}
}
// System.out.println("unknown extension "+url);
pe = new PropertyWrapperDirect(this.context, new Property(p.getName()+"["+url+"]", p.getTypeCode(), p.getDefinition(), p.getMinCardinality(), p.getMaxCardinality(), ex), null);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private boolean generateExpansion(XhtmlNode x, ValueSet vs, boolean header, List
if (vs.getExpansion().hasTotal()) {
if (count != vs.getExpansion().getTotal()) {
x.para().style("border: maroon 1px solid; background-color: #FFCCCC; font-weight: bold; padding: 8px")
.addText(context.formatPhrase(hasFragment ? RenderingContext.VALUE_SET_HAS_AT_LEAST : RenderingContext.VALUE_SET_HAS, vs.getExpansion().getTotal()));
.addText(context.formatPhrase(hasFragment ? RenderingContext.VALUE_SET_HAS_AT_LEAST : RenderingContext.VALUE_SET_HAS, vs.getExpansion().getTotal(), count));
} else {
x.para().tx(context.formatPhrase(hasFragment ? RenderingContext.VALUE_SET_CONTAINS_AT_LEAST : RenderingContext.VALUE_SET_CONTAINS, vs.getExpansion().getTotal()));
}
Expand Down
Loading

0 comments on commit fbf2d01

Please sign in to comment.