Search in sources :

Example 21 with ValueSetComparison

use of org.hl7.fhir.r4b.comparison.ValueSetComparer.ValueSetComparison 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.r5.comparison.ProfileComparer.ProfileComparison) ValueSetComparison(org.hl7.fhir.r5.comparison.ValueSetComparer.ValueSetComparison) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) CodeSystemComparison(org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Aggregations

ValueSet (org.hl7.fhir.r5.model.ValueSet)6 ValueSet (org.hl7.fhir.r4b.model.ValueSet)5 ArrayList (java.util.ArrayList)4 ValueSetComparison (org.hl7.fhir.r5.comparison.ValueSetComparer.ValueSetComparison)4 HierarchicalTableGenerator (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator)4 TableModel (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel)4 FileOutputStream (java.io.FileOutputStream)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 ValueSetComparison (org.hl7.fhir.r4b.comparison.ValueSetComparer.ValueSetComparison)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 Element (org.hl7.fhir.r4b.model.Element)2 ElementDefinitionBindingComponent (org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent)2 ValueSetExpansionContainsComponent (org.hl7.fhir.r4b.model.ValueSet.ValueSetExpansionContainsComponent)2 CodeSystemComparison (org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison)2 ProfileComparison (org.hl7.fhir.r5.comparison.ProfileComparer.ProfileComparison)2 ProfileUtilities (org.hl7.fhir.r5.conformance.ProfileUtilities)2 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)2