Search in sources :

Example 31 with CanonicalResource

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

the class CanonicalResourceComparer method compareCodeableConceptList.

protected void compareCodeableConceptList(String name, List<CodeableConcept> left, List<CodeableConcept> right, Map<String, StructuralMatch<String>> comp, IssueSeverity level, CanonicalResourceComparison<? extends CanonicalResource> res, List<CodeableConcept> union, List<CodeableConcept> intersection) {
    List<CodeableConcept> matchR = new ArrayList<>();
    StructuralMatch<String> combined = new StructuralMatch<String>();
    for (CodeableConcept l : left) {
        CodeableConcept r = findCodeableConceptInList(right, l);
        if (r == null) {
            union.add(l);
            combined.getChildren().add(new StructuralMatch<String>(gen(l), vm(IssueSeverity.INFORMATION, "Removed the item '" + gen(l) + "'", fhirType() + "." + name, res.getMessages())));
        } else {
            matchR.add(r);
            union.add(r);
            intersection.add(r);
            StructuralMatch<String> sm = new StructuralMatch<String>(gen(l), gen(r));
            combined.getChildren().add(sm);
        }
    }
    for (CodeableConcept r : right) {
        if (!matchR.contains(r)) {
            union.add(r);
            combined.getChildren().add(new StructuralMatch<String>(vm(IssueSeverity.INFORMATION, "Added the item '" + gen(r) + "'", fhirType() + "." + name, res.getMessages()), gen(r)));
        }
    }
    comp.put(name, combined);
}
Also used : ArrayList(java.util.ArrayList) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept)

Example 32 with CanonicalResource

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

the class CanonicalResourceComparer method compareCanonicalList.

protected void compareCanonicalList(String name, List<CanonicalType> left, List<CanonicalType> right, Map<String, StructuralMatch<String>> comp, IssueSeverity level, CanonicalResourceComparison<? extends CanonicalResource> res, List<CanonicalType> union, List<CanonicalType> intersection) {
    List<CanonicalType> matchR = new ArrayList<>();
    StructuralMatch<String> combined = new StructuralMatch<String>();
    for (CanonicalType l : left) {
        CanonicalType r = findCanonicalInList(right, l);
        if (r == null) {
            union.add(l);
            combined.getChildren().add(new StructuralMatch<String>(l.getValue(), vm(IssueSeverity.INFORMATION, "Removed the item '" + l.getValue() + "'", fhirType() + "." + name, res.getMessages())));
        } else {
            matchR.add(r);
            union.add(r);
            intersection.add(r);
            StructuralMatch<String> sm = new StructuralMatch<String>(l.getValue(), r.getValue());
            combined.getChildren().add(sm);
        }
    }
    for (CanonicalType r : right) {
        if (!matchR.contains(r)) {
            union.add(r);
            combined.getChildren().add(new StructuralMatch<String>(vm(IssueSeverity.INFORMATION, "Added the item '" + r.getValue() + "'", fhirType() + "." + name, res.getMessages()), r.getValue()));
        }
    }
    comp.put(name, combined);
}
Also used : ArrayList(java.util.ArrayList) CanonicalType(org.hl7.fhir.r5.model.CanonicalType)

Example 33 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.r5.model.CanonicalResource) Resource(org.hl7.fhir.r5.model.Resource) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource)

Example 34 with CanonicalResource

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

the class InstanceValidator method isCorrectCanonicalType.

private boolean isCorrectCanonicalType(Resource r, CanonicalType p) {
    String url = p.getValue();
    String t = null;
    StructureDefinition sd = context.fetchResource(StructureDefinition.class, url);
    if (sd != null) {
        t = sd.getType();
    } else if (url.startsWith("http://hl7.org/fhir/StructureDefinition/")) {
        t = url.substring("http://hl7.org/fhir/StructureDefinition/".length());
    } else {
        return false;
    }
    return Utilities.existsInList(t, "Resource", "CanonicalResource") || t.equals(r.fhirType());
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition)

Example 35 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.r4b.model.OperationOutcome) CanonicalResource(org.hl7.fhir.r4b.model.CanonicalResource) Resource(org.hl7.fhir.r4b.model.Resource) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) ValueSetExpansionOutcome(org.hl7.fhir.r4b.terminologies.ValueSetExpander.ValueSetExpansionOutcome) File(java.io.File) ValueSet(org.hl7.fhir.r4b.model.ValueSet) CanonicalResource(org.hl7.fhir.r4b.model.CanonicalResource) FileInputStream(java.io.FileInputStream)

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