Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

...

Facilities
FacilityIdOrganizationIdNameTimezoneNFCEnabledNFCSelfModificationEnabledBarCodeEnabled
ACME-PHACME

 Pearl Harbor

US/Hawaii

truefalsefalse

...

SurveyTemplates
SurveyIdName
1New Line Report
2Line Maintenance
3Infection Report
4Breast Milk Report
5Patient Demographics
6Patient Discharge
7Patient Open Lines
8Form Open Lines
9Admission Questions
10Patient Final Discharge
11AUDIT
12MDQ

7. Organization's Alerts

7.1 SurveyAgent

Remember that Alerts are generated by the SurveyAgent. For this scenario we are going to have 2 rules generating alerts: 'New Patient Admission" and "Milk Importance Not Discussed".

For this scenario, we are going to place both rules in a single .drl file. The name of the file will be ACME-alerts.drl

 

Code Block
languagejava
linenumberstrue
package org.socraticgrid.survey.agent;
import org.drools.mas.body.content.*;
import org.drools.mas.action.message.*;
import org.drools.mas.action.message.types.*;
import org.drools.mas.action.message.invokers.*;
import org.socraticgrid.survey.agent.api.model.SurveySubmissionFact;
import org.socraticgrid.survey.agent.api.model.SurveySubmissionAnswerFact;
import org.socraticgrid.survey.agent.api.model.PreValidationResult;
import org.socraticgrid.survey.agent.log.RulesLoggerHelper;
import org.socraticgrid.surveys.model.*;
import org.socraticgrid.surveys.service.SurveyService;
import org.socraticgrid.alertmanager.service.AlertService;
import org.slf4j.Logger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Date;
import org.drools.mas.action.helpers.*;
/* Global Services */
global SurveyService surveyService;
global AlertService alertService;
global Logger logger;
rule "New Patient Admission"
when
    //There is a Submission of a #5 Survey
    //And there alert was not previously sent.
    $s: SurveySubmissionFact(
            surveyId == 5,
            $chartId: q["q008"],
            alertService.parameterizedAlertExists($s.getPatientId(), "New Patient Admission") == false
    )
then
    RulesLoggerHelper.debug(logger, drools, "New Admission detected: {}", $s);

    templateVariables.put("common_patient_chartId", $chartId);
    insert( new ResolvableActionAgentNotificationCandidateFact(
        drools.getRule().getName(),     //sourceRule
        "ADMISSION",                          //sourceProgram
        (SurveySubmissionFact)$s,      //sourceFact
        $s.getPatientId(),                      //sourcePatient
        "HIGH",                                     //priority
        "ACME-NewAdmission",                   //template
        "10s",                                        //timeout
        templateVariables                     //template variables
));
end

rule "Milk Importance Not Discussed"
when
    //There is a Submission of a #4 Survey
    $s: SurveySubmissionFact(
            surveyId == 4,
            q["q007"] == "No"
    )
then
    RulesLoggerHelper.debug(logger, drools, "Milk Importance Not Discussed: {}", $s);
    insert( new ResolvableActionAgentNotificationCandidateFact(
        drools.getRule().getName(),     //sourceRule
        "NCCC",                                    //sourceProgram
        (SurveySubmissionFact)$s,      //sourceFact
        $s.getPatientId(),                      //sourcePatient
        "HIGH",                                     //priority
        "ACME-NotDiscussed",            //template
        "10s",                                        //timeout
        null                                           //template variables
));
end