Search in sources :

Example 91 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project org.hl7.fhir.core by hapifhir.

the class TerminologyClientR5 method read.

@Override
public CanonicalResource read(String type, String id) {
    Class<Resource> t;
    try {
        // todo: do we have to deal with any resource renaming? Use cases are limited...
        t = (Class<Resource>) Class.forName("org.hl7.fhir.r5.model." + type);
    } catch (ClassNotFoundException e) {
        throw new FHIRException("Unable to fetch resources of type " + type + " in R5");
    }
    org.hl7.fhir.r5.model.Resource r5 = client.read(t, id);
    if (r5 != null) {
        throw new FHIRException("Unable to convert resource " + Utilities.pathURL(getAddress(), type, id) + " to R5 (internal representation)");
    }
    if (!(r5 instanceof CanonicalResource)) {
        throw new FHIRException("Unable to convert resource " + Utilities.pathURL(getAddress(), type, id) + " to R5 canonical resource (internal representation)");
    }
    return (CanonicalResource) r5;
}
Also used : org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 92 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project org.hl7.fhir.core by hapifhir.

the class ADLImporter method execute.

private void execute() throws Exception {
    // load config
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    adlConfig = builder.parse(new FileInputStream(config)).getDocumentElement();
    // load ADL
    builder = factory.newDocumentBuilder();
    adl = builder.parse(new FileInputStream(source)).getDocumentElement();
    check("root", adl.getNamespaceURI(), "http://schemas.openehr.org/v1", "Wrong namespace for ADL XML");
    check("root", adl.getNodeName(), "archetype", "Wrong XML for ADL XML");
    check("root", XMLUtil.getNamedChild(adl, "adl_version").getTextContent(), "1.4", "unsupported ADL version");
    String id = XMLUtil.getFirstChild(XMLUtil.getNamedChild(adl, "archetype_id")).getTextContent().split("\\.")[1];
    // create structure definition
    StructureDefinition sd = new StructureDefinition();
    sd.setId(id);
    // populate metadata
    Element description = XMLUtil.getNamedChild(adl, "description");
    Element details = XMLUtil.getNamedChild(description, "details");
    sd.setDescription(XMLUtil.getNamedChild(details, "purpose").getTextContent());
    sd.setCopyright(XMLUtil.getNamedChild(details, "copyright").getTextContent());
    sd.setPurpose("Use:\r\n" + XMLUtil.getNamedChild(details, "use").getTextContent() + "\r\n\r\nMisuse:\r\n" + XMLUtil.getNamedChild(details, "misuse").getTextContent());
    List<Element> set = new ArrayList<Element>();
    XMLUtil.getNamedChildren(details, "keywords", set);
    for (Element e : set) sd.addKeyword().setDisplay(e.getTextContent());
    String status = XMLUtil.getNamedChild(description, "lifecycle_state").getTextContent();
    if ("CommitteeDraft".equals(status) || "AuthorDraft".equals(status))
        sd.setStatus(PublicationStatus.DRAFT);
    else
        throw new Exception("Unknown life cycle state " + XMLUtil.getNamedChild(description, "lifecycle_state").getTextContent());
    // load texts from ontology
    Element ontology = XMLUtil.getNamedChild(adl, "ontology");
    Element term_definitions = XMLUtil.getNamedChild(ontology, "term_definitions");
    set.clear();
    XMLUtil.getNamedChildren(term_definitions, "items", set);
    for (Element item : set) {
        processTextItem(item);
    }
    // load data and protocol
    Element definition = XMLUtil.getNamedChild(adl, "definition");
    NodeTreeEntry root = new NodeTreeEntry();
    root.setTypeName(XMLUtil.getNamedChild(definition, "rm_type_name").getTextContent());
    root.setAtCode(XMLUtil.getNamedChild(definition, "node_id").getTextContent());
    root.setName(generateToken(root.getAtCode(), true));
    sd.setName(root.getName());
    root.setCardinality(readCardinality("root", XMLUtil.getNamedChild(definition, "occurrences")));
    set.clear();
    XMLUtil.getNamedChildren(definition, "attributes", set);
    for (Element item : set) {
        // we're actually skipping this level - we don't care about data protocol etc.
        // XMLUtil.getNamedChild(XMLUtil.getNamedChild(item, "children"), "attributes");
        Element attributes = item;
        loadChildren(root.getAtCode(), root, attributes);
    }
    dumpChildren("", root);
    genElements(sd, root.getName(), root);
    // save
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(dest), sd);
    System.out.println("done. saved as " + dest);
}
Also used : XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream)

Example 93 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project org.hl7.fhir.core by hapifhir.

the class TerminologyClientR2 method read.

@Override
public CanonicalResource read(String type, String id) {
    Class<Resource> t;
    try {
        // todo: do we have to deal with any resource renaming? Use cases are limited...
        t = (Class<Resource>) Class.forName("org.hl7.fhir.dstu2.model." + type);
    } catch (ClassNotFoundException e) {
        throw new FHIRException("Unable to fetch resources of type " + type + " in R2");
    }
    org.hl7.fhir.dstu2.model.Resource r2 = client.read(t, id);
    if (r2 == null) {
        throw new FHIRException("Unable to fetch resource " + Utilities.pathURL(getAddress(), type, id));
    }
    org.hl7.fhir.r5.model.Resource r5 = VersionConvertorFactory_10_50.convertResource(r2);
    if (r5 != null) {
        throw new FHIRException("Unable to convert resource " + Utilities.pathURL(getAddress(), type, id) + " to R5 (internal representation)");
    }
    if (!(r5 instanceof CanonicalResource)) {
        throw new FHIRException("Unable to convert resource " + Utilities.pathURL(getAddress(), type, id) + " to R5 canonical resource (internal representation)");
    }
    return (CanonicalResource) r5;
}
Also used : Resource(org.hl7.fhir.dstu2.model.Resource) Resource(org.hl7.fhir.dstu2.model.Resource) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 94 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method funcExists.

private List<Base> funcExists(ExecutionContext context, List<Base> focus, ExpressionNode exp) {
    List<Base> result = new ArrayList<Base>();
    // R2 - can't use ElementUtil
    result.add(new BooleanType(!focus.isEmpty()));
    return result;
}
Also used : ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.dstu2.model.BooleanType) Base(org.hl7.fhir.dstu2.model.Base)

Example 95 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method parse.

// --- public API -------------------------------------------------------
/**
 * Parse a path for later use using execute
 *
 * @param path
 * @return
 * @throws PathEngineException
 * @throws Exception
 */
public ExpressionNode parse(String path) throws FHIRLexerException {
    FHIRLexer lexer = new FHIRLexer(path);
    if (lexer.done())
        throw lexer.error("Path cannot be empty");
    ExpressionNode result = parseExpression(lexer, true);
    if (!lexer.done())
        throw lexer.error("Premature ExpressionNode termination at unexpected token \"" + lexer.getCurrent() + "\"");
    result.check();
    return result;
}
Also used : ExpressionNode(org.hl7.fhir.dstu2.model.ExpressionNode)

Aggregations

ArrayList (java.util.ArrayList)82 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)43 List (java.util.List)41 FHIRException (org.hl7.fhir.exceptions.FHIRException)40 Date (java.util.Date)39 IOException (java.io.IOException)38 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)35 Test (org.junit.jupiter.api.Test)35 Resource (org.hl7.fhir.r4.model.Resource)34 Collectors (java.util.stream.Collectors)29 Coding (org.hl7.fhir.r4.model.Coding)27 Reference (org.hl7.fhir.r4.model.Reference)27 Timer (com.codahale.metrics.Timer)26 HashMap (java.util.HashMap)25 Bundle (org.hl7.fhir.r4.model.Bundle)25 Reference (org.hl7.fhir.dstu3.model.Reference)24 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)23 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)21 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)21 JsonObject (com.google.gson.JsonObject)20