Search in sources :

Example 1 with ProfileComparer

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

the class ProfileUtilitiesTests method execute.

public void execute(String[] args) throws FileNotFoundException, IOException, FHIRException {
    System.out.println("loading context");
    context = SimpleWorkerContext.fromPack(Utilities.path(root, "validation.zip"));
    comp = new ProfileComparer(context);
    compare("patient-daf-dafpatient.profile.xml", "patient-qicore-qicore-patient.profile.xml");
    compare("encounter-daf-dafencounter.profile.xml", "encounter-qicore-qicore-encounter.profile.xml");
    compare("substance-daf-dafsubstance.profile.xml", "substance-qicore-qicore-substance.profile.xml");
    compare("medication-daf-dafmedication.profile.xml", "medication-qicore-qicore-medication.profile.xml");
    compare("procedure-daf-dafprocedure.profile.xml", "procedure-qicore-qicore-procedure.profile.xml");
    compare("familymemberhistory-daf-daffamilymemberhistory.profile.xml", "familymemberhistory-qicore-qicore-familymemberhistory.profile.xml");
    compare("immunization-daf-dafimmunization.profile.xml", "immunization-qicore-qicore-immunization.profile.xml");
    compare("condition-daf-dafcondition.profile.xml", "condition-qicore-qicore-condition.profile.xml");
    compare("allergyintolerance-daf-dafallergyintolerance.profile.xml", "allergyintolerance-qicore-qicore-allergyintolerance.profile.xml");
    compare("medicationadministration-daf-dafmedicationadministration.profile.xml", "medicationadministration-qicore-qicore-medicationadministration.profile.xml");
    compare("medicationdispense-daf-dafmedicationdispense.profile.xml", "medicationdispense-qicore-qicore-medicationdispense.profile.xml");
    compare("medicationprescription-daf-dafmedicationprescription.profile.xml", "medicationprescription-qicore-qicore-medicationprescription.profile.xml");
    compare("medicationstatement-daf-dafmedicationstatement.profile.xml", "medicationstatement-qicore-qicore-medicationstatement.profile.xml");
    compare("observation-daf-smokingstatus-dafsmokingstatus.profile.xml", "observation-qicore-qicore-observation.profile.xml");
    compare("observation-daf-vitalsigns-dafvitalsigns.profile.xml", "observation-qicore-qicore-observation.profile.xml");
    // compare("observation-daf-results-dafresultobs.profile.xml", "observation-qicore-qicore-observation.profile.xml");
    // compare("diagnosticorder-daf-dafdiagnosticorder.profile.xml", "diagnosticorder-qicore-qicore-diagnosticorder.profile.xml");
    // compare("diagnosticreport-daf-dafdiagnosticreport.profile.xml", "diagnosticreport-qicore-qicore-diagnosticreport.profile.xml");
    System.out.println("processing output");
    for (ProfileComparison outcome : comp.getComparisons()) {
        if (outcome.getSubset() != null)
            new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "intersection-" + outcome.getId() + ".xml")), outcome.getSubset());
        if (outcome.getSuperset() != null)
            new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "union-" + outcome.getId() + ".xml")), outcome.getSuperset());
        System.out.println("\r\n" + outcome.getId() + ": Comparison of " + outcome.getLeft().getUrl() + " and " + outcome.getRight().getUrl());
        for (ValidationMessage vm : outcome.getMessages()) if (vm.getLevel() == IssueSeverity.INFORMATION)
            System.out.println(vm.summary());
        for (ValidationMessage vm : outcome.getMessages()) if (vm.getLevel() == IssueSeverity.WARNING)
            System.out.println(vm.summary());
        for (ValidationMessage vm : outcome.getMessages()) if (vm.getLevel() == IssueSeverity.ERROR)
            System.out.println(vm.summary());
        for (ValidationMessage vm : outcome.getMessages()) if (vm.getLevel() == IssueSeverity.FATAL)
            System.out.println(vm.summary());
        System.out.println("done. " + Integer.toString(outcome.getMessages().size()) + " messages");
        System.out.println("=================================================================");
    }
}
Also used : ProfileComparison(org.hl7.fhir.dstu3.conformance.ProfileComparer.ProfileComparison) XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileComparer(org.hl7.fhir.dstu3.conformance.ProfileComparer) FileOutputStream(java.io.FileOutputStream)

Example 2 with ProfileComparer

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

the class ComparisonRenderer method renderProfile.

private void renderProfile(String id, ProfileComparison comp) throws IOException {
    String template = templates.get("Profile");
    Map<String, Base> vars = new HashMap<>();
    ProfileComparer cs = new ProfileComparer(session, new ProfileUtilities(session.getContextLeft(), null, session.getPkp()), new ProfileUtilities(session.getContextRight(), null, session.getPkp()));
    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("structure", new StringType(new XhtmlComposer(true).compose(cs.renderStructure(comp, "", "", "http://hl7.org/fhir"))));
    String cnt = processTemplate(template, "CodeSystem", vars);
    TextFile.stringToFile(cnt, file(comp.getId() + ".html"));
    new org.hl7.fhir.r4b.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(folder, comp.getId() + "-union.json")), comp.getUnion());
    new org.hl7.fhir.r4b.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(folder, comp.getId() + "-intersection.json")), comp.getIntersection());
}
Also used : HashMap(java.util.HashMap) ProfileUtilities(org.hl7.fhir.r4b.conformance.ProfileUtilities) StringType(org.hl7.fhir.r4b.model.StringType) FileOutputStream(java.io.FileOutputStream) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) Base(org.hl7.fhir.r4b.model.Base)

Example 3 with ProfileComparer

use of org.hl7.fhir.r5.comparison.ProfileComparer 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 4 with ProfileComparer

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

the class ComparisonRenderer method renderProfile.

private void renderProfile(String id, ProfileComparison comp) throws IOException {
    String template = templates.get("Profile");
    Map<String, Base> vars = new HashMap<>();
    ProfileComparer cs = new ProfileComparer(session, new ProfileUtilities(session.getContextLeft(), null, session.getPkp()), new ProfileUtilities(session.getContextRight(), null, session.getPkp()));
    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("structure", new StringType(new XhtmlComposer(true).compose(cs.renderStructure(comp, "", "", "http://hl7.org/fhir"))));
    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) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) 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 5 with ProfileComparer

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

the class ComparisonTests method test.

@ParameterizedTest(name = "{index}: id {0}")
@MethodSource("data")
public void test(String name, JsonObject content) throws Exception {
    this.content = content;
    if (content.has("use-test") && !content.get("use-test").getAsBoolean())
        return;
    if (context == null) {
        System.out.println("---- Load R5 ----------------------------------------------------------------");
        context = TestingUtilities.getSharedWorkerContext();
        FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
        NpmPackage npm = pcm.loadPackage("hl7.fhir.us.core#3.1.0");
        BaseWorkerContext bc = (BaseWorkerContext) context;
        boolean dupl = bc.isAllowLoadingDuplicates();
        bc.setAllowLoadingDuplicates(true);
        context.loadFromPackage(npm, new R4ToR5Loader(new String[] { "CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem" }, new NullLoaderKnowledgeProviderR5(), context.getVersion()));
        bc.setAllowLoadingDuplicates(dupl);
    }
    if (!new File(Utilities.path("[tmp]", "comparison")).exists()) {
        System.out.println("---- Set up Output ----------------------------------------------------------");
        Utilities.createDirectory(Utilities.path("[tmp]", "comparison"));
        FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
        NpmPackage npm = pcm.loadPackage(CommonPackages.ID_PUBPACK, CommonPackages.VER_PUBPACK);
        for (String f : npm.list("other")) {
            TextFile.streamToFile(npm.load("other", f), Utilities.path("[tmp]", "comparison", f));
        }
    }
    System.out.println("---- " + name + " ----------------------------------------------------------------");
    CanonicalResource left = load("left");
    CanonicalResource right = load("right");
    ComparisonSession session = new ComparisonSession(context, context, "Comparison Tests", null);
    if (left instanceof CodeSystem && right instanceof CodeSystem) {
        CodeSystemComparer cs = new CodeSystemComparer(session);
        CodeSystemComparison csc = cs.compare((CodeSystem) left, (CodeSystem) right);
        Assertions.assertTrue(csc.getUnion().getConcept().size() > csc.getIntersection().getConcept().size());
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-union.json")), csc.getUnion());
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-intersection.json")), csc.getIntersection());
        String xmle = new XhtmlComposer(true).compose(cs.renderErrors(csc));
        String xml1 = new XhtmlComposer(true).compose(cs.renderMetadata(csc, "", ""));
        String xml2 = new XhtmlComposer(true).compose(cs.renderConcepts(csc, "", ""));
        TextFile.stringToFile(HEADER + hd("Messages") + xmle + BREAK + hd("Metadata") + xml1 + BREAK + hd("Concepts") + xml2 + FOOTER, Utilities.path("[tmp]", "comparison", name + ".html"));
        checkOutcomes(csc.getMessages(), content);
    } else if (left instanceof ValueSet && right instanceof ValueSet) {
        ValueSetComparer cs = new ValueSetComparer(session);
        ValueSetComparison csc = cs.compare((ValueSet) left, (ValueSet) right);
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-union.json")), csc.getUnion());
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-intersection.json")), csc.getIntersection());
        String xmle = new XhtmlComposer(true).compose(cs.renderErrors(csc));
        String xml1 = new XhtmlComposer(true).compose(cs.renderMetadata(csc, "", ""));
        String xml2 = new XhtmlComposer(true).compose(cs.renderCompose(csc, "", ""));
        String xml3 = new XhtmlComposer(true).compose(cs.renderExpansion(csc, "", ""));
        TextFile.stringToFile(HEADER + hd("Messages") + xmle + BREAK + hd("Metadata") + xml1 + BREAK + hd("Definition") + xml2 + BREAK + hd("Expansion") + xml3 + FOOTER, Utilities.path("[tmp]", "comparison", name + ".html"));
        checkOutcomes(csc.getMessages(), content);
    } else if (left instanceof StructureDefinition && right instanceof StructureDefinition) {
        ProfileUtilities utils = new ProfileUtilities(context, null, null);
        genSnapshot(utils, (StructureDefinition) left);
        genSnapshot(utils, (StructureDefinition) right);
        ProfileComparer pc = new ProfileComparer(session, utils, utils);
        ProfileComparison csc = pc.compare((StructureDefinition) left, (StructureDefinition) right);
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-union.json")), csc.getUnion());
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-intersection.json")), csc.getIntersection());
        String xmle = new XhtmlComposer(true).compose(pc.renderErrors(csc));
        String xml1 = new XhtmlComposer(true).compose(pc.renderMetadata(csc, "", ""));
        String xml2 = new XhtmlComposer(true).compose(pc.renderStructure(csc, "", "", "http://hl7.org/fhir"));
        // String xml3 = new XhtmlComposer(true).compose(cs.renderExpansion(csc, "", ""));
        TextFile.stringToFile(HEADER + hd("Messages") + xmle + BREAK + hd("Metadata") + xml1 + BREAK + hd("Structure") + xml2 + FOOTER, Utilities.path("[tmp]", "comparison", name + ".html"));
        checkOutcomes(csc.getMessages(), content);
    } else if (left instanceof CapabilityStatement && right instanceof CapabilityStatement) {
        CapabilityStatementComparer pc = new CapabilityStatementComparer(session);
        CapabilityStatementComparison csc = pc.compare((CapabilityStatement) left, (CapabilityStatement) right);
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-union.json")), csc.getUnion());
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-intersection.json")), csc.getIntersection());
        String xmle = new XhtmlComposer(true).compose(pc.renderErrors(csc));
        String xml1 = new XhtmlComposer(true).compose(pc.renderMetadata(csc, "", ""));
        String xml2 = new XhtmlComposer(true).compose(pc.renderStatements(csc, "", ""));
        // String xml3 = new XhtmlComposer(true).compose(cs.renderExpansion(csc, "", ""));
        TextFile.stringToFile(HEADER + hd("Messages") + xmle + BREAK + hd("Metadata") + xml1 + BREAK + hd("Structure") + xml2 + FOOTER, Utilities.path("[tmp]", "comparison", name + ".html"));
        checkOutcomes(csc.getMessages(), content);
    } else {
        throw new FHIRException("Can't compare " + left.fhirType() + " to " + right.fhirType());
    }
}
Also used : ProfileComparison(org.hl7.fhir.r5.comparison.ProfileComparer.ProfileComparison) ComparisonSession(org.hl7.fhir.r5.comparison.ComparisonSession) ProfileComparer(org.hl7.fhir.r5.comparison.ProfileComparer) BaseWorkerContext(org.hl7.fhir.r5.context.BaseWorkerContext) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) CapabilityStatementComparison(org.hl7.fhir.r5.comparison.CapabilityStatementComparer.CapabilityStatementComparison) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) CapabilityStatement(org.hl7.fhir.r5.model.CapabilityStatement) CapabilityStatementComparer(org.hl7.fhir.r5.comparison.CapabilityStatementComparer) ValueSet(org.hl7.fhir.r5.model.ValueSet) JsonParser(org.hl7.fhir.r5.formats.JsonParser) FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) ValueSetComparison(org.hl7.fhir.r5.comparison.ValueSetComparer.ValueSetComparison) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) JsonParser(org.hl7.fhir.r5.formats.JsonParser) FHIRException(org.hl7.fhir.exceptions.FHIRException) CodeSystemComparer(org.hl7.fhir.r5.comparison.CodeSystemComparer) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) CodeSystemComparison(org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) R4ToR5Loader(org.hl7.fhir.convertors.loaders.loaderR5.R4ToR5Loader) FileOutputStream(java.io.FileOutputStream) ValueSetComparer(org.hl7.fhir.r5.comparison.ValueSetComparer) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) NullLoaderKnowledgeProviderR5(org.hl7.fhir.convertors.loaders.loaderR5.NullLoaderKnowledgeProviderR5) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

FileOutputStream (java.io.FileOutputStream)5 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 ProfileUtilities (org.hl7.fhir.r5.conformance.ProfileUtilities)3 XhtmlComposer (org.hl7.fhir.utilities.xhtml.XhtmlComposer)3 HashMap (java.util.HashMap)2 ProfileUtilities (org.hl7.fhir.r4b.conformance.ProfileUtilities)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 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)2 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)2 ValueSet (org.hl7.fhir.r5.model.ValueSet)2 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)2 File (java.io.File)1 NullLoaderKnowledgeProviderR5 (org.hl7.fhir.convertors.loaders.loaderR5.NullLoaderKnowledgeProviderR5)1 R4ToR5Loader (org.hl7.fhir.convertors.loaders.loaderR5.R4ToR5Loader)1 XmlParser (org.hl7.fhir.dstu2.formats.XmlParser)1 ProfileComparer (org.hl7.fhir.dstu2.utils.ProfileComparer)1 ProfileComparison (org.hl7.fhir.dstu2.utils.ProfileComparer.ProfileComparison)1 ProfileComparer (org.hl7.fhir.dstu3.conformance.ProfileComparer)1