Skip to content

Commit

Permalink
Upgrade dependencies to HAPI-FHIR 6.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
qligier committed Nov 29, 2023
1 parent 5b830e7 commit 47fbd5f
Show file tree
Hide file tree
Showing 14 changed files with 9,629 additions and 9,414 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities;
import org.hl7.fhir.r5.utils.validation.IResourceValidator;
import org.hl7.fhir.utilities.ByteProvider;
import org.hl7.fhir.utilities.FhirPublication;
import org.hl7.fhir.utilities.json.model.JsonObject;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
Expand Down Expand Up @@ -246,8 +247,8 @@ public Resource transformToFhir(String input, boolean inputJson, String mapUri)
public String transform(String input, boolean inputJson, String mapUri, boolean outputJson)
throws FHIRException, IOException {
log.info("Start transform: " + mapUri);
Element transformed = transform(input.getBytes("UTF-8"), (inputJson ? FhirFormat.JSON : FhirFormat.XML),
mapUri);
Element transformed = transform(ByteProvider.forBytes(input.getBytes("UTF-8")), (inputJson ? FhirFormat.JSON : FhirFormat.XML),
mapUri);
ByteArrayOutputStream boas = new ByteArrayOutputStream();
if (outputJson)
new org.hl7.fhir.r5.elementmodel.JsonParser(getContext()).compose(transformed, boas,
Expand All @@ -268,10 +269,10 @@ public String transform(String input, boolean inputJson, String mapUri, boolean
* MatchboxStructureMapUtilities
*/
@Override
public org.hl7.fhir.r5.elementmodel.Element transform(byte[] source, FhirFormat cntType, String mapUri)
public org.hl7.fhir.r5.elementmodel.Element transform(ByteProvider source, FhirFormat cntType, String mapUri)
throws FHIRException, IOException {
SimpleWorkerContext context = this.getContext();
org.hl7.fhir.r5.elementmodel.Element src = Manager.parseSingle(context, new ByteArrayInputStream(source),
org.hl7.fhir.r5.elementmodel.Element src = Manager.parseSingle(context, new ByteArrayInputStream(source.getBytes()),
cntType);
return transform(src, mapUri);
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.utilities.xml.XMLWriter;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;

public class XmlParser extends ParserBase {
Expand All @@ -98,8 +100,6 @@ public void setSchemaPath(String schemaPath) {
this.schemaPath = schemaPath;
}



public boolean isAllowXsiLocation() {
return allowXsiLocation;
}
Expand Down Expand Up @@ -154,6 +154,7 @@ public List<NamedElement> parse(InputStream stream) throws FHIRFormatError, Defi
nullTransformer.transform(saxSource, domResult);
} else {
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(new NullErrorHandler());
doc = builder.parse(stream);
}
} catch (Exception e) {
Expand Down Expand Up @@ -296,19 +297,29 @@ public Element parse(org.w3c.dom.Element base, String type) throws Exception {
private void parseChildren(String path, org.w3c.dom.Element node, Element element) throws FHIRFormatError, FHIRException, IOException, DefinitionException {
// this parsing routine retains the original order in a the XML file, to support validation
reapComments(node, element);

String xsiType = XMLUtil.getXsiType(node);
List<Property> properties = element.getProperty().getChildProperties(element.getName(), xsiType);
List<Property> properties = element.getProperty().getChildProperties(element.getName(), XMLUtil.getXsiType(node));

String text = XMLUtil.getDirectText(node).trim();
int line = line(node, false);
int col = col(node, false);
if (!Utilities.noString(text)) {
Property property = getTextProp(properties);
if (property != null) {
Element n = new Element(property.getName(), property, property.getType(), text).markLocation(line, col);
n.setPath(element.getPath()+"."+property.getName());
element.getChildren().add(n);
if ("ED.data[x]".equals(property.getDefinition().getId()) || (property.getDefinition()!=null && property.getDefinition().getBase()!=null && "ED.data[x]".equals(property.getDefinition().getBase().getPath()))) {
if ("B64".equals(node.getAttribute("representation"))) {
Element n = new Element("dataBase64Binary", property, "base64Binary", text).markLocation(line, col);
n.setPath(element.getPath()+"."+property.getName());
element.getChildren().add(n);
} else {
Element n = new Element("dataString", property, "string", text).markLocation(line, col);
n.setPath(element.getPath()+"."+property.getName());
element.getChildren().add(n);
}
} else {
Element n = new Element(property.getName(), property, property.getType(), text).markLocation(line, col);
n.setPath(element.getPath()+"."+property.getName());
element.getChildren().add(n);
}
}
else {
Node n = node.getFirstChild();
Expand Down Expand Up @@ -416,7 +427,7 @@ private void parseChildren(String path, org.w3c.dom.Element node, Element elemen
boolean ok = true;
if (property.isChoice()) {
if (property.getDefinition().hasRepresentation(PropertyRepresentation.TYPEATTR)) {
xsiType = ((org.w3c.dom.Element) child).getAttributeNS(FormatUtilities.NS_XSI, "type");
String xsiType = ((org.w3c.dom.Element) child).getAttributeNS(FormatUtilities.NS_XSI, "type");
if (Utilities.noString(xsiType)) {
if (ToolingExtensions.hasExtension(property.getDefinition(), "http://hl7.org/fhir/StructureDefinition/elementdefinition-defaulttype")) {
xsiType = ToolingExtensions.readStringExtension(property.getDefinition(), "http://hl7.org/fhir/StructureDefinition/elementdefinition-defaulttype");
Expand All @@ -442,8 +453,9 @@ private void parseChildren(String path, org.w3c.dom.Element node, Element elemen
parseChildren(npath, (org.w3c.dom.Element) child, n);
}
}
} else
logError(ValidationMessage.NO_RULE_DATE, line(child, false), col(child, false), path, IssueType.STRUCTURE, context.formatMessage(I18nConstants.UNDEFINED_ELEMENT_, child.getLocalName()), IssueSeverity.ERROR);
} else {
logError(ValidationMessage.NO_RULE_DATE, line(child, false), col(child, false), path, IssueType.STRUCTURE, context.formatMessage(I18nConstants.UNDEFINED_ELEMENT_, child.getLocalName(), path), IssueSeverity.ERROR);
}
} else if (child.getNodeType() == Node.CDATA_SECTION_NODE){
logError(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 Down Expand Up @@ -823,4 +835,20 @@ private String checkHeader(InputStream stream) throws IOException {
return "?xml-p2?";
}

class NullErrorHandler implements ErrorHandler {
@Override
public void fatalError(SAXParseException e) {
// do nothing
}

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

@Override
public void warning(SAXParseException e) {
// do nothing
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.hl7.fhir.r5.model.TypeDetails;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.utils.FHIRPathUtilityClasses.FunctionDetails;
import org.hl7.fhir.r5.utils.validation.IResourceValidator;
import org.hl7.fhir.utilities.validation.ValidationMessage;

Expand Down
Loading

0 comments on commit 47fbd5f

Please sign in to comment.