Search in sources :

Example 1 with PlanDefinitionActionComponent

use of org.hl7.fhir.r4.model.PlanDefinition.PlanDefinitionActionComponent in project pathling by aehrc.

the class LightweightFhirEncodersTest method testIdCollection.

@Test
public void testIdCollection() {
    final ExpressionEncoder<PlanDefinition> encoder = fhirEncoders.of(PlanDefinition.class);
    final PlanDefinition planDefinition = new PlanDefinition();
    final PlanDefinitionActionComponent actionComponent = planDefinition.getActionFirstRep();
    actionComponent.addGoalId(new IdType("Condition", "goal-1", "1").getValue());
    actionComponent.addGoalId(new IdType("Condition", "goal-2", "2").getValue());
    actionComponent.addGoalId(new IdType("Patient", "goal-3", "3").getValue());
    assertSerDeIsIdentity(encoder, planDefinition);
}
Also used : PlanDefinitionActionComponent(org.hl7.fhir.r4.model.PlanDefinition.PlanDefinitionActionComponent) Test(org.junit.Test)

Example 2 with PlanDefinitionActionComponent

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

PlanDefinitionActionComponent (org.hl7.fhir.r4.model.PlanDefinition.PlanDefinitionActionComponent)2 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 ValidateEicrAction (com.drajer.eca.model.ValidateEicrAction)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Bundle (org.hl7.fhir.r4.model.Bundle)1 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)1 Library (org.hl7.fhir.r4.model.Library)1 PlanDefinition (org.hl7.fhir.r4.model.PlanDefinition)1 TriggerDefinition (org.hl7.fhir.r4.model.TriggerDefinition)1 ValueSet (org.hl7.fhir.r4.model.ValueSet)1 Test (org.junit.Test)1