Search in sources :

Example 6 with CodeSystemComparison

use of org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison in project org.hl7.fhir.core by hapifhir.

the class CodeSystemComparer method compare.

public CodeSystemComparison compare(CodeSystem left, CodeSystem right) {
    if (left == null)
        throw new DefinitionException("No CodeSystem provided (left)");
    if (right == null)
        throw new DefinitionException("No CodeSystem provided (right)");
    CodeSystemComparison res = new CodeSystemComparison(left, right);
    session.identify(res);
    CodeSystem cs = new CodeSystem();
    res.setUnion(cs);
    session.identify(cs);
    cs.setName("Union" + left.getName() + "And" + right.getName());
    cs.setTitle("Union of " + left.getTitle() + " And " + right.getTitle());
    cs.setStatus(left.getStatus());
    cs.setDate(new Date());
    for (PropertyComponent pL : left.getProperty()) {
        cs.addProperty(pL.copy());
    }
    for (PropertyComponent pR : left.getProperty()) {
        PropertyComponent pL = findProperty(left, pR);
        if (pL == null) {
            String code = getUniqued(pR.getCode(), cs.getProperty());
            cs.addProperty(pR.copy().setCode(code));
        } else {
            res.getPropMap().put(pR.getCode(), pL.getCode());
        }
    }
    CodeSystem cs1 = new CodeSystem();
    res.setIntersection(cs1);
    session.identify(cs1);
    cs1.setName("Intersection" + left.getName() + "And" + right.getName());
    cs1.setTitle("Intersection of " + left.getTitle() + " And " + right.getTitle());
    cs1.setStatus(left.getStatus());
    cs1.setDate(new Date());
    cs1.getProperty().addAll(cs.getProperty());
    compareMetadata(left, right, res.getMetadata(), res);
    comparePrimitives("caseSensitive", left.getCaseSensitiveElement(), right.getCaseSensitiveElement(), res.getMetadata(), IssueSeverity.ERROR, res);
    comparePrimitives("hierarchyMeaning", left.getHierarchyMeaningElement(), right.getHierarchyMeaningElement(), res.getMetadata(), IssueSeverity.ERROR, res);
    comparePrimitives("compositional", left.getCompositionalElement(), right.getCompositionalElement(), res.getMetadata(), IssueSeverity.WARNING, res);
    comparePrimitives("versionNeeded", left.getVersionNeededElement(), right.getVersionNeededElement(), res.getMetadata(), IssueSeverity.INFORMATION, res);
    comparePrimitives("content", left.getContentElement(), right.getContentElement(), res.getMetadata(), IssueSeverity.WARNING, res);
    compareConcepts(left.getConcept(), right.getConcept(), res.getCombined(), res.getUnion().getConcept(), res.getIntersection().getConcept(), res.getUnion(), res.getIntersection(), res, "CodeSystem.concept");
    return res;
}
Also used : ConceptPropertyComponent(org.hl7.fhir.r4b.model.CodeSystem.ConceptPropertyComponent) PropertyComponent(org.hl7.fhir.r4b.model.CodeSystem.PropertyComponent) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) CodeSystem(org.hl7.fhir.r4b.model.CodeSystem) Date(java.util.Date)

Example 7 with CodeSystemComparison

use of org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison in project org.hl7.fhir.core by hapifhir.

the class ComparisonSession method compare.

public ResourceComparison compare(CanonicalResource left, CanonicalResource right) throws DefinitionException, FHIRFormatError, IOException {
    if (left != null && right != null) {
        String key = key(left.getUrl(), left.getVersion(), right.getUrl(), right.getVersion());
        if (compares.containsKey(key)) {
            // this can happen when profiles refer to each other
            return compares.get(key);
        }
        compares.put(key, null);
        try {
            if (left instanceof CodeSystem && right instanceof CodeSystem) {
                CodeSystemComparer cs = new CodeSystemComparer(this);
                CodeSystemComparison csc = cs.compare((CodeSystem) left, (CodeSystem) right);
                compares.put(key, csc);
                return csc;
            } else if (left instanceof ValueSet && right instanceof ValueSet) {
                ValueSetComparer cs = new ValueSetComparer(this);
                ValueSetComparison csc = cs.compare((ValueSet) left, (ValueSet) right);
                compares.put(key, csc);
                return csc;
            } else if (left instanceof StructureDefinition && right instanceof StructureDefinition) {
                ProfileComparer cs = new ProfileComparer(this, new ProfileUtilities(contextLeft, null, pkp), new ProfileUtilities(contextRight, null, pkp));
                ProfileComparison csc = cs.compare((StructureDefinition) left, (StructureDefinition) right);
                compares.put(key, csc);
                return csc;
            } else {
                throw new FHIRException("Unable to compare resources of type " + left.fhirType() + " and " + right.fhirType());
            }
        } catch (Throwable e) {
            ResourceComparer.PlaceHolderComparison csc = new ResourceComparer.PlaceHolderComparison(left, right, e);
            compares.put(key, csc);
            return csc;
        }
    } else if (left != null) {
        String key = key(left.getUrl(), left.getVersion(), left.getUrl(), left.getVersion());
        if (compares.containsKey(key)) {
            return compares.get(key);
        }
        ResourceComparer.PlaceHolderComparison csc = new ResourceComparer.PlaceHolderComparison(left, right);
        compares.put(key, csc);
        return csc;
    } else {
        String key = key(right.getUrl(), right.getVersion(), right.getUrl(), right.getVersion());
        if (compares.containsKey(key)) {
            return compares.get(key);
        }
        ResourceComparer.PlaceHolderComparison csc = new ResourceComparer.PlaceHolderComparison(left, right);
        compares.put(key, csc);
        return csc;
    }
}
Also used : ProfileComparison(org.hl7.fhir.r4b.comparison.ProfileComparer.ProfileComparison) ValueSetComparison(org.hl7.fhir.r4b.comparison.ValueSetComparer.ValueSetComparison) CodeSystem(org.hl7.fhir.r4b.model.CodeSystem) FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) CodeSystemComparison(org.hl7.fhir.r4b.comparison.CodeSystemComparer.CodeSystemComparison) ProfileUtilities(org.hl7.fhir.r4b.conformance.ProfileUtilities) ValueSet(org.hl7.fhir.r4b.model.ValueSet)

Example 8 with CodeSystemComparison

use of org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison in project org.hl7.fhir.core by hapifhir.

the class ComparisonRenderer method renderCodeSystem.

private void renderCodeSystem(String id, CodeSystemComparison comp) throws IOException {
    String template = templates.get("CodeSystem");
    Map<String, Base> vars = new HashMap<>();
    CodeSystemComparer cs = new CodeSystemComparer(session);
    vars.put("left", new StringType(comp.getLeft().present()));
    vars.put("right", new StringType(comp.getRight().present()));
    vars.put("leftId", new StringType(comp.getLeft().getId()));
    vars.put("rightId", new StringType(comp.getRight().getId()));
    vars.put("leftUrl", new StringType(comp.getLeft().getUrl()));
    vars.put("rightUrl", new StringType(comp.getRight().getUrl()));
    vars.put("errors", new StringType(new XhtmlComposer(true).compose(cs.renderErrors(comp))));
    vars.put("metadata", new StringType(new XhtmlComposer(true).compose(cs.renderMetadata(comp, "", ""))));
    vars.put("concepts", new StringType(new XhtmlComposer(true).compose(cs.renderConcepts(comp, "", ""))));
    String cnt = processTemplate(template, "CodeSystem", vars);
    TextFile.stringToFile(cnt, file(comp.getId() + ".html"));
    new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(folder, comp.getId() + "-union.json")), comp.getUnion());
    new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(folder, comp.getId() + "-intersection.json")), comp.getIntersection());
}
Also used : HashMap(java.util.HashMap) StringType(org.hl7.fhir.r5.model.StringType) FileOutputStream(java.io.FileOutputStream) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) Base(org.hl7.fhir.r5.model.Base)

Example 9 with CodeSystemComparison

use of org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison in project org.hl7.fhir.core by hapifhir.

the class CodeSystemComparer method compare.

public CodeSystemComparison compare(CodeSystem left, CodeSystem right) {
    if (left == null)
        throw new DefinitionException("No CodeSystem provided (left)");
    if (right == null)
        throw new DefinitionException("No CodeSystem provided (right)");
    CodeSystemComparison res = new CodeSystemComparison(left, right);
    session.identify(res);
    CodeSystem cs = new CodeSystem();
    res.setUnion(cs);
    session.identify(cs);
    cs.setName("Union" + left.getName() + "And" + right.getName());
    cs.setTitle("Union of " + left.getTitle() + " And " + right.getTitle());
    cs.setStatus(left.getStatus());
    cs.setDate(new Date());
    for (PropertyComponent pL : left.getProperty()) {
        cs.addProperty(pL.copy());
    }
    for (PropertyComponent pR : left.getProperty()) {
        PropertyComponent pL = findProperty(left, pR);
        if (pL == null) {
            String code = getUniqued(pR.getCode(), cs.getProperty());
            cs.addProperty(pR.copy().setCode(code));
        } else {
            res.getPropMap().put(pR.getCode(), pL.getCode());
        }
    }
    CodeSystem cs1 = new CodeSystem();
    res.setIntersection(cs1);
    session.identify(cs1);
    cs1.setName("Intersection" + left.getName() + "And" + right.getName());
    cs1.setTitle("Intersection of " + left.getTitle() + " And " + right.getTitle());
    cs1.setStatus(left.getStatus());
    cs1.setDate(new Date());
    cs1.getProperty().addAll(cs.getProperty());
    compareMetadata(left, right, res.getMetadata(), res);
    comparePrimitives("caseSensitive", left.getCaseSensitiveElement(), right.getCaseSensitiveElement(), res.getMetadata(), IssueSeverity.ERROR, res);
    comparePrimitives("hierarchyMeaning", left.getHierarchyMeaningElement(), right.getHierarchyMeaningElement(), res.getMetadata(), IssueSeverity.ERROR, res);
    comparePrimitives("compositional", left.getCompositionalElement(), right.getCompositionalElement(), res.getMetadata(), IssueSeverity.WARNING, res);
    comparePrimitives("versionNeeded", left.getVersionNeededElement(), right.getVersionNeededElement(), res.getMetadata(), IssueSeverity.INFORMATION, res);
    comparePrimitives("content", left.getContentElement(), right.getContentElement(), res.getMetadata(), IssueSeverity.WARNING, res);
    compareConcepts(left.getConcept(), right.getConcept(), res.getCombined(), res.getUnion().getConcept(), res.getIntersection().getConcept(), res.getUnion(), res.getIntersection(), res, "CodeSystem.concept");
    return res;
}
Also used : PropertyComponent(org.hl7.fhir.r5.model.CodeSystem.PropertyComponent) ConceptPropertyComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptPropertyComponent) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) Date(java.util.Date)

Example 10 with CodeSystemComparison

use of org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison in project org.hl7.fhir.core by hapifhir.

the class CodeSystemComparer method intersect.

private ConceptDefinitionComponent intersect(ConceptDefinitionComponent l, ConceptDefinitionComponent r, CodeSystemComparison res) {
    ConceptDefinitionComponent cd = l.copy();
    if (l.hasDisplay() && !r.hasDisplay()) {
        cd.setDisplay(null);
    }
    if (l.hasDefinition() && !r.hasDefinition()) {
        cd.setDefinition(null);
    }
    intersectProps(cd, l, r, res);
    // mergeDesignations(cd, l, r);
    return cd;
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)

Aggregations

ConceptPropertyComponent (org.hl7.fhir.r4b.model.CodeSystem.ConceptPropertyComponent)5 ConceptPropertyComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptPropertyComponent)5 ArrayList (java.util.ArrayList)4 ConceptDefinitionComponent (org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent)4 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)4 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)4 FileOutputStream (java.io.FileOutputStream)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 CodeSystem (org.hl7.fhir.r4b.model.CodeSystem)3 PropertyComponent (org.hl7.fhir.r4b.model.CodeSystem.PropertyComponent)3 PropertyComponent (org.hl7.fhir.r5.model.CodeSystem.PropertyComponent)3 XhtmlComposer (org.hl7.fhir.utilities.xhtml.XhtmlComposer)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)2 CodeSystemComparison (org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison)2 ProfileComparison (org.hl7.fhir.r5.comparison.ProfileComparer.ProfileComparison)2 ValueSetComparison (org.hl7.fhir.r5.comparison.ValueSetComparer.ValueSetComparison)2 ProfileUtilities (org.hl7.fhir.r5.conformance.ProfileUtilities)2 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)2