Search in sources :

Example 11 with TriggerDefinition

use of org.hl7.fhir.r4.model.TriggerDefinition 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)

Example 12 with TriggerDefinition

use of org.hl7.fhir.r4.model.TriggerDefinition in project eCRNow by drajer-health.

the class ValueSetServiceImpl method createPlanDefinitionAction.

@Override
public void createPlanDefinitionAction(TriggerDefinition triggerDefinition) {
    List<DataRequirement> datareqs = triggerDefinition.getData();
    Set<ValueSet> grouperToValueSets = new HashSet<>();
    Set<ValueSet> grouperToCovidValueSets = new HashSet<>();
    for (DataRequirement d : datareqs) {
        DataRequirementCodeFilterComponent codeFilter = d.getCodeFilterFirstRep();
        logger.debug(" Getting Value Set List for Grouper {}", codeFilter.getValueSet());
        List<CanonicalType> valueSetIdList = ApplicationUtils.getValueSetListFromGrouper(codeFilter.getValueSet());
        logger.debug(" Size of valueSetIdList = {}", ((valueSetIdList == null) ? "Null" : valueSetIdList.size()));
        grouperToValueSets = ApplicationUtils.getValueSetByIds(valueSetIdList);
        logger.debug(" Size of Value Sets for Grouper : {}", grouperToValueSets.size());
        grouperToCovidValueSets = ApplicationUtils.getCovidValueSetByIds(valueSetIdList);
        logger.debug(" Size of Covid Value Sets for Grouper : {}", grouperToCovidValueSets.size());
    }
    DataRequirement dataRequirement = triggerDefinition.getDataFirstRep();
    DataRequirementCodeFilterComponent codeFilter = dataRequirement.getCodeFilterFirstRep();
    List<CanonicalType> valueSetIdList = ApplicationUtils.getValueSetListFromGrouper(codeFilter.getValueSet());
    Set<ValueSet> valueSets = ApplicationUtils.getValueSetByIds(valueSetIdList);
    ValueSet valuSetGrouper = ApplicationUtils.getValueSetGrouperFromId(codeFilter.getValueSet());
    String path = dataRequirement.getType() + "." + codeFilter.getPath();
    logger.debug(" Trigger Path to Grouper Map {} , Grouper {}", path, valuSetGrouper == null ? "NULL" : valuSetGrouper.getId());
    ValueSetSingleton.getInstance().getTriggerPathToValueSetsMap().put(path, valueSets);
    if (ValueSetSingleton.getInstance().getTriggerPathToGrouperMap().containsKey(path)) {
        logger.debug(" Found Path in Grouper Map for {}", path);
        if (Boolean.FALSE.equals(ApplicationUtils.isSetContainsValueSet(ValueSetSingleton.getInstance().getTriggerPathToGrouperMap().get(path), valuSetGrouper))) {
            ValueSetSingleton.getInstance().getTriggerPathToGrouperMap().get(path).add(valuSetGrouper);
        }
    } else {
        logger.debug(" Did not Find Path in Grouper Map for {}", path);
        Set<ValueSet> vs = new HashSet<>();
        vs.add(valuSetGrouper);
        ValueSetSingleton.getInstance().getTriggerPathToGrouperMap().put(path, vs);
    }
    if (valuSetGrouper != null) {
        logger.debug(" Adding Grouper Id {} to map", codeFilter.getValueSet());
        ValueSetSingleton.getInstance().addGrouperToValueSetMap(valuSetGrouper.getId(), grouperToValueSets);
        ValueSetSingleton.getInstance().addGrouperToCovidValueSetMap(valuSetGrouper.getId(), grouperToCovidValueSets);
    }
}
Also used : DataRequirement(org.hl7.fhir.r4.model.DataRequirement) ValueSet(org.hl7.fhir.r4.model.ValueSet) DataRequirementCodeFilterComponent(org.hl7.fhir.r4.model.DataRequirement.DataRequirementCodeFilterComponent) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) HashSet(java.util.HashSet)

Aggregations

FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)3 HashSet (java.util.HashSet)2 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)2 DataRequirement (org.hl7.fhir.r4.model.DataRequirement)2 DataRequirementCodeFilterComponent (org.hl7.fhir.r4.model.DataRequirement.DataRequirementCodeFilterComponent)2 TriggerDefinition (org.hl7.fhir.r4.model.TriggerDefinition)2 ValueSet (org.hl7.fhir.r4.model.ValueSet)2 ActionData (com.drajer.eca.model.ActionData)1 CloseOutEicrAction (com.drajer.eca.model.CloseOutEicrAction)1 CreateEicrAction (com.drajer.eca.model.CreateEicrAction)1 CreateEicrAfterRecheckAction (com.drajer.eca.model.CreateEicrAfterRecheckAction)1 EcrActionTypes (com.drajer.eca.model.EventTypes.EcrActionTypes)1 MatchTriggerAction (com.drajer.eca.model.MatchTriggerAction)1 PeriodicUpdateEicrAction (com.drajer.eca.model.PeriodicUpdateEicrAction)1 SubmitEicrAction (com.drajer.eca.model.SubmitEicrAction)1 TimingSchedule (com.drajer.eca.model.TimingSchedule)1 ValidateEicrAction (com.drajer.eca.model.ValidateEicrAction)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)1