Search in sources :

Example 46 with ImplementationGuide

use of org.hl7.fhir.dstu3.model.ImplementationGuide in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeImplementationGuideImplementationGuidePackageComponent.

protected void composeImplementationGuideImplementationGuidePackageComponent(Complex parent, String parentType, String name, ImplementationGuide.ImplementationGuidePackageComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "package", name, element, index);
    if (element.hasNameElement())
        composeString(t, "ImplementationGuide", "name", element.getNameElement(), -1);
    if (element.hasDescriptionElement())
        composeString(t, "ImplementationGuide", "description", element.getDescriptionElement(), -1);
    for (int i = 0; i < element.getResource().size(); i++) composeImplementationGuideImplementationGuidePackageResourceComponent(t, "ImplementationGuide", "resource", element.getResource().get(i), i);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Example 47 with ImplementationGuide

use of org.hl7.fhir.dstu3.model.ImplementationGuide in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method cacheResource.

public void cacheResource(Resource r) throws FHIRException {
    synchronized (lock) {
        Map<String, Resource> map = allResourcesById.get(r.fhirType());
        if (map == null) {
            map = new HashMap<String, Resource>();
            allResourcesById.put(r.fhirType(), map);
        }
        map.put(r.getId(), r);
        if (r instanceof MetadataResource) {
            MetadataResource m = (MetadataResource) r;
            String url = m.getUrl();
            if (!allowLoadingDuplicates && hasResource(r.getClass(), url))
                throw new DefinitionException("Duplicate Resource " + url);
            if (r instanceof StructureDefinition)
                seeMetadataResource((StructureDefinition) m, structures, false);
            else if (r instanceof ValueSet)
                seeMetadataResource((ValueSet) m, valueSets, false);
            else if (r instanceof CodeSystem)
                seeMetadataResource((CodeSystem) m, codeSystems, false);
            else if (r instanceof ImplementationGuide)
                seeMetadataResource((ImplementationGuide) m, guides, false);
            else if (r instanceof CapabilityStatement)
                seeMetadataResource((CapabilityStatement) m, capstmts, false);
            else if (r instanceof SearchParameter)
                seeMetadataResource((SearchParameter) m, searchParameters, false);
            else if (r instanceof PlanDefinition)
                seeMetadataResource((PlanDefinition) m, plans, false);
            else if (r instanceof OperationDefinition)
                seeMetadataResource((OperationDefinition) m, operations, false);
            else if (r instanceof Questionnaire)
                seeMetadataResource((Questionnaire) m, questionnaires, true);
            else if (r instanceof ConceptMap)
                seeMetadataResource((ConceptMap) m, maps, false);
            else if (r instanceof StructureMap)
                seeMetadataResource((StructureMap) m, transforms, false);
            else if (r instanceof NamingSystem)
                systems.add((NamingSystem) r);
        }
    }
}
Also used : DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Example 48 with ImplementationGuide

use of org.hl7.fhir.dstu3.model.ImplementationGuide in project org.hl7.fhir.core by hapifhir.

the class CapabilityStatementComparer method compare.

public CapabilityStatementComparison compare(CapabilityStatement left, CapabilityStatement right) {
    if (left == null)
        throw new DefinitionException("No CapabilityStatement provided (left)");
    if (right == null)
        throw new DefinitionException("No CapabilityStatement provided (right)");
    CapabilityStatementComparison res = new CapabilityStatementComparison(left, right);
    session.identify(res);
    CapabilityStatement cs = new CapabilityStatement();
    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());
    CapabilityStatement cs1 = new CapabilityStatement();
    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());
    compareMetadata(left, right, res.getMetadata(), res);
    comparePrimitives("kind", left.getKindElement(), right.getKindElement(), res.getMetadata(), IssueSeverity.ERROR, res);
    compareCanonicalList("instantiates", left.getInstantiates(), right.getInstantiates(), res.getMetadata(), IssueSeverity.ERROR, res, cs.getInstantiates(), cs1.getInstantiates());
    compareCanonicalList("imports", left.getImports(), right.getImports(), res.getMetadata(), IssueSeverity.ERROR, res, cs.getImports(), cs1.getImports());
    comparePrimitives("software.name", left.getSoftware().getNameElement(), right.getSoftware().getNameElement(), res.getMetadata(), IssueSeverity.ERROR, res);
    comparePrimitives("software.version", left.getSoftware().getVersionElement(), right.getSoftware().getVersionElement(), res.getMetadata(), IssueSeverity.ERROR, res);
    comparePrimitives("software.releaseDate", left.getSoftware().getReleaseDateElement(), right.getSoftware().getReleaseDateElement(), res.getMetadata(), IssueSeverity.ERROR, res);
    comparePrimitives("implementation.description", left.getImplementation().getDescriptionElement(), right.getImplementation().getDescriptionElement(), res.getMetadata(), IssueSeverity.ERROR, res);
    comparePrimitives("implementation.url", left.getImplementation().getUrlElement(), right.getImplementation().getUrlElement(), res.getMetadata(), IssueSeverity.ERROR, res);
    comparePrimitives("fhirVersion", left.getFhirVersionElement(), right.getFhirVersionElement(), res.getMetadata(), IssueSeverity.ERROR, res);
    compareCodeList("format", left.getFormat(), right.getFormat(), res.getMetadata(), IssueSeverity.ERROR, res, cs.getFormat(), cs1.getFormat());
    compareCodeList("patchFormat", left.getPatchFormat(), right.getPatchFormat(), res.getMetadata(), IssueSeverity.ERROR, res, cs.getPatchFormat(), cs1.getPatchFormat());
    compareCanonicalList("implementationGuide", left.getImplementationGuide(), right.getImplementationGuide(), res.getMetadata(), IssueSeverity.ERROR, res, cs.getImplementationGuide(), cs1.getImplementationGuide());
    compareRests(left.getRest(), right.getRest(), res.getCombined(), res.getUnion().getRest(), res.getIntersection().getRest(), res.getUnion(), res.getIntersection(), res, "CapabilityStatement.rest");
    return res;
}
Also used : CapabilityStatement(org.hl7.fhir.r5.model.CapabilityStatement) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) Date(java.util.Date)

Example 49 with ImplementationGuide

use of org.hl7.fhir.dstu3.model.ImplementationGuide in project org.hl7.fhir.core by hapifhir.

the class InstanceValidator method start.

// checkSpecials = we're only going to run these tests if we are actually validating this content (as opposed to we looked it up)
private void start(ValidatorHostContext hostContext, List<ValidationMessage> errors, Element resource, Element element, StructureDefinition defn, NodeStack stack) throws FHIRException {
    checkLang(resource, stack);
    if (crumbTrails) {
        element.addMessage(signpost(errors, IssueType.INFORMATIONAL, element.line(), element.col(), stack.getLiteralPath(), I18nConstants.VALIDATION_VAL_PROFILE_SIGNPOST, defn.getUrl()));
    }
    if (BUNDLE.equals(element.fhirType())) {
        resolveBundleReferences(element, new ArrayList<Element>());
    }
    startInner(hostContext, errors, resource, element, defn, stack, hostContext.isCheckSpecials());
    Element meta = element.getNamedChild(META);
    if (meta != null) {
        List<Element> profiles = new ArrayList<Element>();
        meta.getNamedChildren("profile", profiles);
        int i = 0;
        for (Element profile : profiles) {
            StructureDefinition sd = context.fetchResource(StructureDefinition.class, profile.primitiveValue());
            if (!defn.getUrl().equals(profile.primitiveValue())) {
                // is this a version specific reference?
                VersionURLInfo vu = VersionUtilities.parseVersionUrl(profile.primitiveValue());
                if (vu != null) {
                    if (!VersionUtilities.versionsCompatible(vu.getVersion(), context.getVersion())) {
                        hint(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath() + ".meta.profile[" + i + "]", false, I18nConstants.VALIDATION_VAL_PROFILE_OTHER_VERSION, vu.getVersion());
                    } else if (vu.getUrl().equals(defn.getUrl())) {
                        hint(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath() + ".meta.profile[" + i + "]", false, I18nConstants.VALIDATION_VAL_PROFILE_THIS_VERSION_OK);
                    } else {
                        StructureDefinition sdt = context.fetchResource(StructureDefinition.class, vu.getUrl());
                        rule(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath() + ".meta.profile[" + i + "]", false, I18nConstants.VALIDATION_VAL_PROFILE_THIS_VERSION_OTHER, sdt == null ? "null" : sdt.getType());
                    }
                } else {
                    if (sd == null) {
                        // we'll try fetching it directly from it's source, but this is likely to fail later even if the resolution succeeds
                        if (fetcher == null) {
                            warning(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath() + ".meta.profile[" + i + "]", false, I18nConstants.VALIDATION_VAL_PROFILE_UNKNOWN, profile.primitiveValue());
                        } else if (!fetcher.fetchesCanonicalResource(this, profile.primitiveValue())) {
                            warning(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath() + ".meta.profile[" + i + "]", false, I18nConstants.VALIDATION_VAL_PROFILE_UNKNOWN_NOT_POLICY, profile.primitiveValue());
                        } else {
                            try {
                                sd = (StructureDefinition) fetcher.fetchCanonicalResource(this, profile.primitiveValue());
                            } catch (Exception e) {
                                if (STACK_TRACE)
                                    e.printStackTrace();
                                warning(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath() + ".meta.profile[" + i + "]", false, I18nConstants.VALIDATION_VAL_PROFILE_UNKNOWN_ERROR, profile.primitiveValue(), e.getMessage());
                            }
                            if (sd != null) {
                                context.cacheResource(sd);
                            }
                        }
                    }
                    if (sd != null) {
                        if (crumbTrails) {
                            element.addMessage(signpost(errors, IssueType.INFORMATIONAL, element.line(), element.col(), stack.getLiteralPath(), I18nConstants.VALIDATION_VAL_PROFILE_SIGNPOST_META, sd.getUrl()));
                        }
                        stack.resetIds();
                        startInner(hostContext, errors, resource, element, sd, stack, false);
                    }
                }
            }
            i++;
        }
    }
    String rt = element.fhirType();
    for (ImplementationGuide ig : igs) {
        for (ImplementationGuideGlobalComponent gl : ig.getGlobal()) {
            if (rt.equals(gl.getType())) {
                StructureDefinition sd = context.fetchResource(StructureDefinition.class, gl.getProfile());
                if (warning(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath(), sd != null, I18nConstants.VALIDATION_VAL_GLOBAL_PROFILE_UNKNOWN, gl.getProfile())) {
                    if (crumbTrails) {
                        element.addMessage(signpost(errors, IssueType.INFORMATIONAL, element.line(), element.col(), stack.getLiteralPath(), I18nConstants.VALIDATION_VAL_PROFILE_SIGNPOST_GLOBAL, sd.getUrl(), ig.getUrl()));
                    }
                    stack.resetIds();
                    startInner(hostContext, errors, resource, element, sd, stack, false);
                }
            }
        }
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ImplementationGuideGlobalComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideGlobalComponent) ImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide) NamedElement(org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement) IndexedElement(org.hl7.fhir.validation.instance.utils.IndexedElement) SpecialElement(org.hl7.fhir.r5.elementmodel.Element.SpecialElement) Element(org.hl7.fhir.r5.elementmodel.Element) ArrayList(java.util.ArrayList) VersionURLInfo(org.hl7.fhir.utilities.VersionUtilities.VersionURLInfo) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) FHIRLexerException(org.hl7.fhir.r5.utils.FHIRLexer.FHIRLexerException)

Example 50 with ImplementationGuide

use of org.hl7.fhir.dstu3.model.ImplementationGuide in project org.hl7.fhir.core by hapifhir.

the class Scanner method validateScan.

protected List<ScanOutputItem> validateScan(List<String> sources, Set<String> guides) throws FHIRException, IOException, EOperationOutcome {
    List<String> refs = new ArrayList<>();
    ValidatorUtils.parseSources(sources, refs, getContext());
    List<ScanOutputItem> res = new ArrayList();
    for (String ref : refs) {
        Content cnt = getIgLoader().loadContent(ref, "validate", false);
        List<ValidationMessage> messages = new ArrayList<>();
        Element e = null;
        try {
            System.out.println("Validate " + ref);
            messages.clear();
            e = getValidator().validate(null, messages, new ByteArrayInputStream(cnt.focus), cnt.cntType);
            res.add(new ScanOutputItem(ref, null, null, ValidatorUtils.messagesToOutcome(messages, getContext(), getFhirPathEngine())));
        } catch (Exception ex) {
            res.add(new ScanOutputItem(ref, null, null, exceptionToOutcome(ex)));
        }
        if (e != null) {
            String rt = e.fhirType();
            for (String u : guides) {
                ImplementationGuide ig = getContext().fetchResource(ImplementationGuide.class, u);
                System.out.println("Check Guide " + ig.getUrl());
                String canonical = ig.getUrl().contains("/Impl") ? ig.getUrl().substring(0, ig.getUrl().indexOf("/Impl")) : ig.getUrl();
                String url = getGlobal(ig, rt);
                if (url != null) {
                    try {
                        System.out.println("Validate " + ref + " against " + ig.getUrl());
                        messages.clear();
                        getValidator().validate(null, messages, new ByteArrayInputStream(cnt.focus), cnt.cntType, url);
                        res.add(new ScanOutputItem(ref, ig, null, ValidatorUtils.messagesToOutcome(messages, getContext(), getFhirPathEngine())));
                    } catch (Exception ex) {
                        res.add(new ScanOutputItem(ref, ig, null, exceptionToOutcome(ex)));
                    }
                }
                Set<String> done = new HashSet<>();
                for (StructureDefinition sd : getContext().allStructures()) {
                    if (!done.contains(sd.getUrl())) {
                        done.add(sd.getUrl());
                        if (sd.getUrl().startsWith(canonical) && rt.equals(sd.getType())) {
                            try {
                                System.out.println("Validate " + ref + " against " + sd.getUrl());
                                messages.clear();
                                validator.validate(null, messages, new ByteArrayInputStream(cnt.focus), cnt.cntType, Collections.singletonList(sd));
                                res.add(new ScanOutputItem(ref, ig, sd, ValidatorUtils.messagesToOutcome(messages, getContext(), getFhirPathEngine())));
                            } catch (Exception ex) {
                                res.add(new ScanOutputItem(ref, ig, sd, exceptionToOutcome(ex)));
                            }
                        }
                    }
                }
            }
        }
    }
    return res;
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide) Element(org.hl7.fhir.r5.elementmodel.Element) FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ScanOutputItem(org.hl7.fhir.validation.cli.model.ScanOutputItem)

Aggregations

ImplementationGuide (org.hl7.fhir.r5.model.ImplementationGuide)16 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)13 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)12 FHIRException (org.hl7.fhir.exceptions.FHIRException)11 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)9 File (java.io.File)8 JsonObject (com.google.gson.JsonObject)7 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)7 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)7 XmlParser (org.hl7.fhir.r5.formats.XmlParser)6 SearchParameter (org.hl7.fhir.r5.model.SearchParameter)5 Gson (com.google.gson.Gson)4 GsonBuilder (com.google.gson.GsonBuilder)4 JsonArray (com.google.gson.JsonArray)4 FileInputStream (java.io.FileInputStream)4 FileOutputStream (java.io.FileOutputStream)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 CanonicalResource (org.hl7.fhir.r5.model.CanonicalResource)4 ValueSet (org.hl7.fhir.r5.model.ValueSet)4