Search in sources :

Example 61 with CanonicalResource

use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.

the class TerminologyClientR4 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.r4.model." + type);
    } catch (ClassNotFoundException e) {
        throw new FHIRException("Unable to fetch resources of type " + type + " in R2");
    }
    org.hl7.fhir.r4.model.Resource r4 = client.read(t, id);
    if (r4 == null) {
        throw new FHIRException("Unable to fetch resource " + Utilities.pathURL(getAddress(), type, id));
    }
    org.hl7.fhir.r5.model.Resource r5 = VersionConvertorFactory_40_50.convertResource(r4);
    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.r4.model.Resource) Resource(org.hl7.fhir.r4.model.Resource) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 62 with CanonicalResource

use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.

the class TerminologyClientR3 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.dstu3.model." + type);
    } catch (ClassNotFoundException e) {
        throw new FHIRException("Unable to fetch resources of type " + type + " in R2");
    }
    org.hl7.fhir.dstu3.model.Resource r3 = client.read(t, id);
    if (r3 == null) {
        throw new FHIRException("Unable to fetch resource " + Utilities.pathURL(getAddress(), type, id));
    }
    org.hl7.fhir.r5.model.Resource r5 = VersionConvertorFactory_30_50.convertResource(r3);
    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.dstu3.model.Resource) Resource(org.hl7.fhir.dstu3.model.Resource) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 63 with CanonicalResource

use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.

the class ValueSetExpansionCache method loadCache.

private void loadCache() throws FHIRFormatError, IOException {
    File[] files = new File(cacheFolder).listFiles();
    for (File f : files) {
        if (f.getName().endsWith(".xml")) {
            final FileInputStream is = new FileInputStream(f);
            try {
                Resource r = context.newXmlParser().setOutputStyle(OutputStyle.PRETTY).parse(is);
                if (r instanceof OperationOutcome) {
                    OperationOutcome oo = (OperationOutcome) r;
                    expansions.put(ToolingExtensions.getExtension(oo, VS_ID_EXT).getValue().toString(), new ValueSetExpansionOutcome(new XhtmlComposer(XhtmlComposer.XML, false).composePlainText(oo.getText().getDiv()), TerminologyServiceErrorClass.UNKNOWN));
                } else if (r instanceof ValueSet) {
                    ValueSet vs = (ValueSet) r;
                    if (vs.hasExpansion())
                        expansions.put(vs.getUrl(), new ValueSetExpansionOutcome(vs));
                    else {
                        canonicals.put(vs.getUrl(), vs);
                        if (vs.hasVersion())
                            canonicals.put(vs.getUrl() + "|" + vs.getVersion(), vs);
                    }
                } else if (r instanceof CanonicalResource) {
                    CanonicalResource md = (CanonicalResource) r;
                    canonicals.put(md.getUrl(), md);
                    if (md.hasVersion())
                        canonicals.put(md.getUrl() + "|" + md.getVersion(), md);
                }
            } finally {
                IOUtils.closeQuietly(is);
            }
        }
    }
}
Also used : OperationOutcome(org.hl7.fhir.r5.model.OperationOutcome) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) Resource(org.hl7.fhir.r5.model.Resource) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) ValueSetExpansionOutcome(org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome) File(java.io.File) ValueSet(org.hl7.fhir.r5.model.ValueSet) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) FileInputStream(java.io.FileInputStream)

Example 64 with CanonicalResource

use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.

the class CapabilityStatementComparer method addPrimitiveTypeRow.

@SuppressWarnings("rawtypes")
private Row addPrimitiveTypeRow(HierarchicalTableGenerator gen, List<Row> rows, StructuralMatch<Element> t, CapabilityStatementComparison comparison) {
    Row r = gen.new Row();
    rows.add(r);
    r.getCells().add(gen.new Cell(null, null, t.getName(), null, null));
    PrimitiveType left = t.hasLeft() ? (PrimitiveType) t.getLeft() : null;
    PrimitiveType right = t.hasRight() ? (PrimitiveType) t.getRight() : null;
    CanonicalResource crL = left == null ? null : (CanonicalResource) session.getContextLeft().fetchResource(Resource.class, left.primitiveValue());
    CanonicalResource crR = right == null ? null : (CanonicalResource) session.getContextRight().fetchResource(Resource.class, right.primitiveValue());
    String refL = crL != null && crL.hasUserData("path") ? crL.getUserString("path") : null;
    String dispL = crL != null && refL != null ? crL.present() : left == null ? "" : left.primitiveValue();
    String refR = crR != null && crR.hasUserData("path") ? crR.getUserString("path") : null;
    String dispR = crR != null && refR != null ? crR.present() : right == null ? "" : right.primitiveValue();
    r.getCells().add(style(gen.new Cell(null, refL, dispL, null, null), left != null ? left.primitiveValue() : null, right != null ? right.primitiveValue() : null, true));
    r.getCells().add(gen.new Cell(null, null, "", null, null));
    r.getCells().add(style(gen.new Cell(null, refR, dispR, null, null), left != null ? left.primitiveValue() : null, right != null ? right.primitiveValue() : null, false));
    r.getCells().add(gen.new Cell(null, null, "", null, null));
    r.getCells().add(cellForMessages(gen, t.getMessages()));
    return r;
}
Also used : PrimitiveType(org.hl7.fhir.r4b.model.PrimitiveType) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) CanonicalResource(org.hl7.fhir.r4b.model.CanonicalResource)

Example 65 with CanonicalResource

use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.

the class ComparisonSession method compare.

public ResourceComparison compare(String left, String right) throws DefinitionException, FHIRFormatError, IOException {
    CanonicalResource l = (CanonicalResource) contextLeft.fetchResource(Resource.class, left);
    if (l == null) {
        throw new DefinitionException("Unable to resolve " + left);
    }
    CanonicalResource r = (CanonicalResource) contextRight.fetchResource(Resource.class, right);
    if (r == null) {
        throw new DefinitionException("Unable to resolve " + right);
    }
    return compare(l, r);
}
Also used : CanonicalResource(org.hl7.fhir.r4b.model.CanonicalResource) Resource(org.hl7.fhir.r4b.model.Resource) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) CanonicalResource(org.hl7.fhir.r4b.model.CanonicalResource)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)20 CanonicalResource (org.hl7.fhir.r5.model.CanonicalResource)19 ArrayList (java.util.ArrayList)17 File (java.io.File)11 CanonicalResource (org.hl7.fhir.r4b.model.CanonicalResource)10 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)10 XmlParser (org.hl7.fhir.r5.formats.XmlParser)9 org.hl7.fhir.r5.model (org.hl7.fhir.r5.model)9 BundleEntryComponent (org.hl7.fhir.r5.model.Bundle.BundleEntryComponent)9 FileOutputStream (java.io.FileOutputStream)8 IOException (java.io.IOException)8 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)8 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)8 Resource (org.hl7.fhir.r5.model.Resource)8 ValueSet (org.hl7.fhir.r5.model.ValueSet)8 FileNotFoundException (java.io.FileNotFoundException)7 Resource (org.hl7.fhir.r4b.model.Resource)7 CodeSystem (org.hl7.fhir.r4b.model.CodeSystem)5 SearchParameter (org.hl7.fhir.r5.model.SearchParameter)5 FileInputStream (java.io.FileInputStream)4