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

...

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
//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

Some important notes about ACME-alerts.drl are:

  • Lines #25 and #50 define the 2 rules
  • In "New Patient Admission" rule (the other rule is similar):
    • Line #35 logs information
    • Line #37 inserts a new ResolvableActionNotificationCandidateFact that will end up notifying the ActionAgent about a new Alert.
    • Line #44 specifies the Template id that we want to use. Templates and their Ids are defined in the ActionAgent.