Search in sources :

Example 46 with PlanDefinition

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

the class BaseWorkerContext method cacheResourceFromPackage.

public void cacheResourceFromPackage(Resource r, PackageVersion packageInfo) throws FHIRException {
    synchronized (lock) {
        Map<String, ResourceProxy> map = allResourcesById.get(r.fhirType());
        if (map == null) {
            map = new HashMap<String, ResourceProxy>();
            allResourcesById.put(r.fhirType(), map);
        }
        if ((packageInfo == null || !packageInfo.isExamplesPackage()) || !map.containsKey(r.getId())) {
            map.put(r.getId(), new ResourceProxy(r));
        } else {
            System.out.println("Ignore " + r.fhirType() + "/" + r.getId() + " from package " + packageInfo.toString());
        }
        if (r instanceof CodeSystem || r instanceof NamingSystem) {
            oidCache.clear();
        }
        if (r instanceof CanonicalResource) {
            CanonicalResource m = (CanonicalResource) r;
            String url = m.getUrl();
            if (!allowLoadingDuplicates && hasResource(r.getClass(), url)) {
                // spcial workaround for known problems with existing packages
                if (Utilities.existsInList(url, "http://hl7.org/fhir/SearchParameter/example")) {
                    return;
                }
                throw new DefinitionException(formatMessage(I18nConstants.DUPLICATE_RESOURCE_, url));
            }
            if (r instanceof StructureDefinition) {
                StructureDefinition sd = (StructureDefinition) m;
                if ("1.4.0".equals(version)) {
                    fixOldSD(sd);
                }
                structures.see(sd, packageInfo);
            } else if (r instanceof ValueSet) {
                valueSets.see((ValueSet) m, packageInfo);
            } else if (r instanceof CodeSystem) {
                CodeSystemUtilities.crossLinkCodeSystem((CodeSystem) r);
                codeSystems.see((CodeSystem) m, packageInfo);
            } else if (r instanceof ImplementationGuide) {
                guides.see((ImplementationGuide) m, packageInfo);
            } else if (r instanceof CapabilityStatement) {
                capstmts.see((CapabilityStatement) m, packageInfo);
            } else if (r instanceof Measure) {
                measures.see((Measure) m, packageInfo);
            } else if (r instanceof Library) {
                libraries.see((Library) m, packageInfo);
            } else if (r instanceof SearchParameter) {
                searchParameters.see((SearchParameter) m, packageInfo);
            } else if (r instanceof PlanDefinition) {
                plans.see((PlanDefinition) m, packageInfo);
            } else if (r instanceof OperationDefinition) {
                operations.see((OperationDefinition) m, packageInfo);
            } else if (r instanceof Questionnaire) {
                questionnaires.see((Questionnaire) m, packageInfo);
            } else if (r instanceof ConceptMap) {
                maps.see((ConceptMap) m, packageInfo);
            } else if (r instanceof StructureMap) {
                transforms.see((StructureMap) m, packageInfo);
            } else if (r instanceof NamingSystem) {
                systems.see((NamingSystem) m, packageInfo);
            }
        }
    }
}
Also used : Questionnaire(org.hl7.fhir.r4b.model.Questionnaire) ImplementationGuide(org.hl7.fhir.r4b.model.ImplementationGuide) CodeSystem(org.hl7.fhir.r4b.model.CodeSystem) CanonicalResourceProxy(org.hl7.fhir.r4b.context.CanonicalResourceManager.CanonicalResourceProxy) ResourceProxy(org.hl7.fhir.r4b.context.BaseWorkerContext.ResourceProxy) StructureMap(org.hl7.fhir.r4b.model.StructureMap) StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) NamingSystem(org.hl7.fhir.r4b.model.NamingSystem) CapabilityStatement(org.hl7.fhir.r4b.model.CapabilityStatement) Measure(org.hl7.fhir.r4b.model.Measure) PlanDefinition(org.hl7.fhir.r4b.model.PlanDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) Library(org.hl7.fhir.r4b.model.Library) SearchParameter(org.hl7.fhir.r4b.model.SearchParameter) ConceptMap(org.hl7.fhir.r4b.model.ConceptMap) CanonicalResource(org.hl7.fhir.r4b.model.CanonicalResource) ValueSet(org.hl7.fhir.r4b.model.ValueSet) OperationDefinition(org.hl7.fhir.r4b.model.OperationDefinition)

Example 47 with PlanDefinition

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

the class BaseWorkerContext method registerResourceFromPackage.

public void registerResourceFromPackage(CanonicalResourceProxy r, PackageVersion packageInfo) throws FHIRException {
    synchronized (lock) {
        Map<String, ResourceProxy> map = allResourcesById.get(r.getType());
        if (map == null) {
            map = new HashMap<String, ResourceProxy>();
            allResourcesById.put(r.getType(), map);
        }
        if ((packageInfo == null || !packageInfo.isExamplesPackage()) || !map.containsKey(r.getId())) {
            map.put(r.getId(), new ResourceProxy(r));
        }
        String url = r.getUrl();
        if (!allowLoadingDuplicates && hasResource(r.getType(), url)) {
            // spcial workaround for known problems with existing packages
            if (Utilities.existsInList(url, "http://hl7.org/fhir/SearchParameter/example")) {
                return;
            }
            throw new DefinitionException(formatMessage(I18nConstants.DUPLICATE_RESOURCE_, url));
        }
        switch(r.getType()) {
            case "StructureDefinition":
                if ("1.4.0".equals(version)) {
                    StructureDefinition sd = (StructureDefinition) r.getResource();
                    fixOldSD(sd);
                }
                structures.register(r, packageInfo);
                break;
            case "ValueSet":
                valueSets.register(r, packageInfo);
                break;
            case "CodeSystem":
                codeSystems.register(r, packageInfo);
                break;
            case "ImplementationGuide":
                guides.register(r, packageInfo);
                break;
            case "CapabilityStatement":
                capstmts.register(r, packageInfo);
                break;
            case "Measure":
                measures.register(r, packageInfo);
                break;
            case "Library":
                libraries.register(r, packageInfo);
                break;
            case "SearchParameter":
                searchParameters.register(r, packageInfo);
                break;
            case "PlanDefinition":
                plans.register(r, packageInfo);
                break;
            case "OperationDefinition":
                operations.register(r, packageInfo);
                break;
            case "Questionnaire":
                questionnaires.register(r, packageInfo);
                break;
            case "ConceptMap":
                maps.register(r, packageInfo);
                break;
            case "StructureMap":
                transforms.register(r, packageInfo);
                break;
            case "NamingSystem":
                systems.register(r, packageInfo);
                break;
        }
    }
}
Also used : StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) CanonicalResourceProxy(org.hl7.fhir.r4b.context.CanonicalResourceManager.CanonicalResourceProxy) ResourceProxy(org.hl7.fhir.r4b.context.BaseWorkerContext.ResourceProxy)

Example 48 with PlanDefinition

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

the class RdfParser method composePlanDefinitionPlanDefinitionActionParticipantComponent.

protected void composePlanDefinitionPlanDefinitionActionParticipantComponent(Complex parent, String parentType, String name, PlanDefinition.PlanDefinitionActionParticipantComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "participant", name, element, index);
    if (element.hasTypeElement())
        composeEnum(t, "PlanDefinition", "type", element.getTypeElement(), -1);
    if (element.hasRole())
        composeCodeableConcept(t, "PlanDefinition", "role", element.getRole(), -1);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Example 49 with PlanDefinition

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

the class DataRenderer method isCanonical.

private boolean isCanonical(String path) {
    if (!path.endsWith(".url"))
        return false;
    String t = path.substring(0, path.length() - 4);
    StructureDefinition sd = getContext().getWorker().fetchTypeDefinition(t);
    if (sd == null)
        return false;
    if (Utilities.existsInList(t, VersionUtilities.getCanonicalResourceNames(getContext().getWorker().getVersion()))) {
        return true;
    }
    if (Utilities.existsInList(t, "ActivityDefinition", "CapabilityStatement", "CapabilityStatement2", "ChargeItemDefinition", "Citation", "CodeSystem", "CompartmentDefinition", "ConceptMap", "ConditionDefinition", "EventDefinition", "Evidence", "EvidenceReport", "EvidenceVariable", "ExampleScenario", "GraphDefinition", "ImplementationGuide", "Library", "Measure", "MessageDefinition", "NamingSystem", "PlanDefinition"))
        return true;
    return sd.getBaseDefinitionElement().hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-codegen-super");
}
Also used : StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition)

Example 50 with PlanDefinition

use of org.hl7.fhir.r4b.model.PlanDefinition in project eCRNow by drajer-health.

the class PlanDefinitionProcessor method processResourceBundle.

public void processResourceBundle() {
    // Reading Bundle with Id 506 from ersd server.
    // Bundle esrdBundle =
    // esrdClient.read().resource(Bundle.class).withId("506").execute();
    logger.info(" Reading ERSD Bundle File ");
    Bundle ersdBundle = readErsdBundleFromFile();
    Bundle actualErsdBundle = null;
    if (ersdBundle != null) {
        if (ersdBundle.getEntry() != null) {
            logger.info(" Bundle has been created with Entries : {}", ersdBundle.getEntry().size());
        }
        // Check to see if this is a searchset bundle.
        if (ersdBundle.getType() == Bundle.BundleType.SEARCHSET) {
            // Check if there is a bundle of type collection and use it.
            // Typically it will be the first one.
            logger.info("Found a Bundle from a search result, containing the actual ERSD Bundle");
            List<BundleEntryComponent> innerBundle = ersdBundle.getEntry();
            for (BundleEntryComponent bundleEntry : innerBundle) {
                if (Optional.ofNullable(bundleEntry).isPresent() && bundleEntry.getResource().getResourceType().equals(ResourceType.Bundle)) {
                    logger.debug(" Found a bundle within a bundle ");
                    Bundle ib = (Bundle) (bundleEntry.getResource());
                    if (ib.getType() == Bundle.BundleType.COLLECTION && ib.getId().contains(ERSD_BUNDLE_ID_STRING)) {
                        logger.info(" Found the bundle which is the actual ERSD Bundle file ");
                        actualErsdBundle = ib;
                        break;
                    }
                }
            }
        }
        List<BundleEntryComponent> bundleEntries = null;
        if (actualErsdBundle != null) {
            logger.info(" Inner ERSD Bundle Found from where we need to extract the plan definition");
            bundleEntries = actualErsdBundle.getEntry();
        } else {
            logger.info(" Bundle read from configuration is a valid bundle to extract the plan definition");
            bundleEntries = ersdBundle.getEntry();
        }
        ValueSet valueSet = null;
        PlanDefinition planDefinition = null;
        List<PlanDefinitionActionComponent> actions = null;
        List<TriggerDefinition> triggerDefinitionsList = null;
        Set<ValueSet> covidValuesets = new HashSet<>();
        Set<ValueSet> valuesets = new HashSet<>();
        Set<ValueSet> grouperValueSets = new HashSet<>();
        Map<EventTypes.EcrActionTypes, Set<AbstractAction>> acts = new HashMap<>();
        for (BundleEntryComponent bundleEntry : bundleEntries) {
            if (Optional.ofNullable(bundleEntry).isPresent()) {
                logger.debug(" Bundle Entries present and is of type {}", bundleEntry.getResource().getResourceType());
                if (bundleEntry.getResource().getResourceType().equals(ResourceType.ValueSet)) {
                    logger.debug(" Found Value set");
                    valueSet = (ValueSet) bundleEntry.getResource();
                    if (ApplicationUtils.isACovidValueSet(valueSet)) {
                        logger.debug(" Found a COVID Value Set {}", valueSet.getId());
                        valueSetService.createValueSet(valueSet);
                        covidValuesets.add(valueSet);
                        valuesets.add(valueSet);
                    } else if (ApplicationUtils.isAGrouperValueSet(valueSet)) {
                        logger.debug(" Found a Grouper Value Set {}", valueSet.getId());
                        valueSetService.createValueSetGrouper(valueSet);
                        grouperValueSets.add(valueSet);
                    } else {
                        logger.debug(" Found a Regular Value Set {}", valueSet.getId());
                        valueSetService.createValueSet(valueSet);
                        valuesets.add(valueSet);
                    }
                } else if (bundleEntry.getResource().getResourceType().equals(ResourceType.Library)) {
                    logger.debug(" Found the Library ");
                    Library lib = (Library) bundleEntry.getResource();
                    if (lib.getId().contains("rctc")) {
                        logger.debug(" Adding Rctc Version to the Action Repo {}", lib.getVersion());
                        ActionRepo.getInstance().setRctcVersion(lib.getVersion());
                    }
                }
            }
        }
        ValueSetSingleton.getInstance().setCovidValueSets(covidValuesets);
        ValueSetSingleton.getInstance().setValueSets(valuesets);
        ValueSetSingleton.getInstance().setGrouperValueSets(grouperValueSets);
        for (BundleEntryComponent bundleEntry : bundleEntries) {
            if (Optional.ofNullable(bundleEntry).isPresent()) {
                if (bundleEntry.getResource().getResourceType().equals(ResourceType.PlanDefinition)) {
                    planDefinition = (PlanDefinition) bundleEntry.getResource();
                    actions = planDefinition.getAction();
                    logger.info(" Found Plan Definition ");
                    if (actions != null && !actions.isEmpty()) {
                        for (PlanDefinitionActionComponent action : actions) {
                            if (action.getId().equals("match-trigger")) {
                                logger.info(" Identified Match Trigger EICR Action ");
                                MatchTriggerAction mta = new MatchTriggerAction();
                                populateActionData(mta, acts, action, EcrActionTypes.MATCH_TRIGGER);
                                triggerDefinitionsList = action.getTrigger();
                                if (triggerDefinitionsList != null && !triggerDefinitionsList.isEmpty()) {
                                    logger.info(" Number of Trigger Definitions {}", triggerDefinitionsList.size());
                                    for (TriggerDefinition triggerDefinition : triggerDefinitionsList) {
                                        valueSetService.createPlanDefinitionAction(triggerDefinition);
                                    }
                                }
                            } else if (action.getId().equals("create-eicr")) {
                                logger.info(" Identified Create EICR Action ");
                                CreateEicrAction mta = new CreateEicrAction();
                                populateActionData(mta, acts, action, EcrActionTypes.CREATE_EICR);
                            } else if (action.getId().equals("periodic-update-eicr")) {
                                logger.info(" Identified Periodic Update EICR Action ");
                                PeriodicUpdateEicrAction mta = new PeriodicUpdateEicrAction();
                                populateActionData(mta, acts, action, EcrActionTypes.PERIODIC_UPDATE_EICR);
                            } else if (action.getId().equals("create-eicr-after-recheck")) {
                                logger.info(" Identified Create EICR After Recheck Action ");
                                CreateEicrAfterRecheckAction cra = new CreateEicrAfterRecheckAction();
                                populateActionData(cra, acts, action, EcrActionTypes.CREATE_EICR_AFTER_RECHECK);
                            } else if (action.getId().equals("close-out-eicr")) {
                                logger.info(" Identified Close Out EICR Action ");
                                CloseOutEicrAction mta = new CloseOutEicrAction();
                                populateActionData(mta, acts, action, EcrActionTypes.CLOSE_OUT_EICR);
                            } else if (action.getId().equals("validate-eicr")) {
                                logger.info(" Identified Validate EICR Action ");
                                ValidateEicrAction mta = new ValidateEicrAction();
                                populateActionData(mta, acts, action, EcrActionTypes.VALIDATE_EICR);
                            } else if (action.getId().equals("route-and-send-eicr")) {
                                logger.info(" Identified Submit EICR Action ");
                                SubmitEicrAction mta = new SubmitEicrAction();
                                populateActionData(mta, acts, action, EcrActionTypes.SUBMIT_EICR);
                                populateRRCheckAction(acts, mta);
                            }
                        }
                    }
                }
            }
        }
        if (acts != null) {
            ActionRepo.getInstance().setActions(acts);
            ActionRepo.getInstance().setupTriggerBasedActions();
        }
    }
}
Also used : ValueSet(org.hl7.fhir.r4.model.ValueSet) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CreateEicrAfterRecheckAction(com.drajer.eca.model.CreateEicrAfterRecheckAction) Bundle(org.hl7.fhir.r4.model.Bundle) TriggerDefinition(org.hl7.fhir.r4.model.TriggerDefinition) EcrActionTypes(com.drajer.eca.model.EventTypes.EcrActionTypes) CloseOutEicrAction(com.drajer.eca.model.CloseOutEicrAction) ValidateEicrAction(com.drajer.eca.model.ValidateEicrAction) CreateEicrAction(com.drajer.eca.model.CreateEicrAction) SubmitEicrAction(com.drajer.eca.model.SubmitEicrAction) MatchTriggerAction(com.drajer.eca.model.MatchTriggerAction) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) PlanDefinition(org.hl7.fhir.r4.model.PlanDefinition) Library(org.hl7.fhir.r4.model.Library) PlanDefinitionActionComponent(org.hl7.fhir.r4.model.PlanDefinition.PlanDefinitionActionComponent) ValueSet(org.hl7.fhir.r4.model.ValueSet) PeriodicUpdateEicrAction(com.drajer.eca.model.PeriodicUpdateEicrAction) HashSet(java.util.HashSet)

Aggregations

Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)8 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)8 PlanDefinition (org.hl7.fhir.dstu3.model.PlanDefinition)7 PlanDefinition (org.hl7.fhir.r4.model.PlanDefinition)7 SystemRequestDetails (ca.uhn.fhir.jpa.partition.SystemRequestDetails)6 Test (org.junit.jupiter.api.Test)6 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 ArrayList (java.util.ArrayList)5 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)5 JsonObject (com.google.gson.JsonObject)4 DomainResource (org.hl7.fhir.dstu3.model.DomainResource)4 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)3 Library (org.hl7.fhir.r4.model.Library)3 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)3 CanonicalResourceProxy (org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy)3 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)3 FhirContext (ca.uhn.fhir.context.FhirContext)2 Operation (ca.uhn.fhir.rest.annotation.Operation)2 RequestDetails (ca.uhn.fhir.rest.api.server.RequestDetails)2