Ejemplo n.º 1
0
/**
 * Function to check for lists item of a patient. Fully customizable and includes diagnoses, medications,
 * allergies, and surgeries.
 *
 * @param  string  $patient_id  pid of selected patient.
 * @param  string  $type        type (medical_problem, allergy, medication, etc)
 * @param  string  $value       value searching for
 * @param  string  $dateTarget  target date(format Y-m-d H:i:s).
 * @return boolean              true if check passed, otherwise false
 */
function exist_lists_item($patient_id, $type, $value, $dateTarget)
{
    // Set date to current if not set
    $dateTarget = $dateTarget ? $dateTarget : date('Y-m-d H:i:s');
    // Attempt to explode the value into a code type and code (if applicable)
    $value_array = explode("::", $value);
    if (count($value_array) == 2) {
        // Collect the code type and code
        $code_type = $value_array[0];
        $code = $value_array[1];
        if ($code_type == 'CUSTOM') {
            // Deal with custom code type first (title column in lists table)
            $response = sqlQueryCdrEngine("SELECT * FROM `lists` " . "WHERE `type`=? " . "AND `pid`=? " . "AND `title`=? " . "AND ( (`begdate` IS NULL AND `date`<=?) OR (`begdate` IS NOT NULL AND `begdate`<=?) ) " . "AND ( (`enddate` IS NULL) OR (`enddate` IS NOT NULL AND `enddate`>=?) )", array($type, $patient_id, $code, $dateTarget, $dateTarget, $dateTarget));
            if (!empty($response)) {
                return true;
            }
        } else {
            // Deal with the set code types (diagnosis column in lists table)
            $response = sqlQueryCdrEngine("SELECT * FROM `lists` " . "WHERE `type`=? " . "AND `pid`=? " . "AND `diagnosis` LIKE ? " . "AND ( (`begdate` IS NULL AND `date`<=?) OR (`begdate` IS NOT NULL AND `begdate`<=?) ) " . "AND ( (`enddate` IS NULL) OR (`enddate` IS NOT NULL AND `enddate`>=?) )", array($type, $patient_id, "%" . $code_type . ":" . $code . "%", $dateTarget, $dateTarget, $dateTarget));
            if (!empty($response)) {
                return true;
            }
        }
    } else {
        // count($value_array) == 1
        // Search the title column in lists table
        //   Yes, this is essentially the same as the code type listed as CUSTOM above. This provides flexibility and will ensure compatibility.
        $response = sqlQueryCdrEngine("SELECT * FROM `lists` " . "WHERE `type`=? " . "AND `pid`=? " . "AND `title`=? " . "AND ( (`begdate` IS NULL AND `date`<=?) OR (`begdate` IS NOT NULL AND `begdate`<=?) ) " . "AND ( (`enddate` IS NULL) OR (`enddate` IS NOT NULL AND `enddate`>=?) )", array($type, $patient_id, $value, $dateTarget, $dateTarget, $dateTarget));
        if (!empty($response)) {
            return true;
        }
    }
    return false;
}
Ejemplo n.º 2
0
/**
 * Function to send reminders.
 *
 * Function that sends reminders and returns an array with a specific data structure.
 * <pre>The data structure of the return array includes the following elements
 *   'total_pre_unsent_reminders'  - Number of reminders before processing.
 *   'total_post_unsent_reminders' - Number of reminders after processing.
 *   'number_success_emails'       - Number of successfully sent email reminders.
 *   'number_failed_emails'        - Number of failed sent email reminders.
 *   'number_success_calls'        - Number of successfully call reminders.
 *   'number_failed_calls'         - Number of failed call reminders.
 * </pre>
 *
 * @return array                 see above for data structure of returned array
 */
function send_reminders()
{
    $logging = array();
    // Collect active reminders that have not yet been sent.
    $active_unsent_reminders = fetch_reminders('', 'unsent');
    $logging['total_pre_unsent_reminders'] = count($active_unsent_reminders);
    // Send the unsent reminders
    $logging['number_success_emails'] = 0;
    $logging['number_failed_emails'] = 0;
    $logging['number_success_calls'] = 0;
    $logging['number_failed_calls'] = 0;
    foreach ($active_unsent_reminders as $reminder) {
        // Collect patient information that reminder is going to.
        $sql = "SELECT `fname`, `lname`, `email`, `phone_home`, `hipaa_voice`, `hipaa_allowemail` from `patient_data` where `pid`=?";
        $result = sqlQueryCdrEngine($sql, array($reminder['pid']));
        $patientfname = $result['fname'];
        $patientlname = $result['lname'];
        $patientemail = $result['email'];
        $patientphone = $result['phone_home'];
        $hipaa_voice = $result['hipaa_voice'];
        $hipaa_allowemail = $result['hipaa_allowemail'];
        // Email to patient if Allow Email and set reminder sent flag.
        if ($hipaa_allowemail == "YES") {
            $mail = new MyMailer();
            $sender_name = $GLOBALS['patient_reminder_sender_name'];
            $email_address = $GLOBALS['patient_reminder_sender_email'];
            $mail->FromName = $sender_name;
            // required
            $mail->Sender = $email_address;
            // required
            $mail->From = $email_address;
            // required
            $mail->AddAddress($patientemail, $patientfname . ", " . $patientlname);
            // required
            $mail->AddReplyTo($email_address, $sender_name);
            // required
            $category_title = generate_display_field(array('data_type' => '1', 'list_id' => 'rule_action_category'), $reminder['category']);
            $item_title = generate_display_field(array('data_type' => '1', 'list_id' => 'rule_action'), $reminder['item']);
            $mail->Body = "Dear " . $patientfname . ", This is a message from your clinic to remind you of your " . $category_title . ": " . $item_title;
            $mail->Subject = "Clinic Reminder";
            if ($mail->Send()) {
                // deal with and keep track of this successful email
                sqlStatementCdrEngine("UPDATE `patient_reminders` SET `email_status`='1', `date_sent`=NOW() WHERE id=?", array($reminder['id']));
                $logging['number_success_emails']++;
            } else {
                // deal with and keep track of this unsuccesful email
                $logging['number_failed_emails']++;
            }
        }
        // Call to patient if Allow Voice Message and set reminder sent flag.
        if ($hipaa_voice == "YES") {
            /******************************************************************************
            *     // Maviq does not work, is not currently supported, and seems to break on windows servers, so this
            *     //  feature has been commented out for now.
            *     // Automated VOIP service provided by Maviq. Please visit http://signup.maviq.com for more information.
            *      $siteId = $GLOBALS['phone_gateway_username'];
            *      $token = $GLOBALS['phone_gateway_password'];
            *      $endpoint = $GLOBALS['phone_gateway_url'];
            *      $client = new MaviqClient($siteId, $token, $endpoint);
            *      //Set up params.
            *      $data = array(
            *        "firstName" => $patientfname,
            *        "lastName" => $patientlname,
            *        "phone" => $patientphone,
            *        //"apptDate" => "$scheduled_date[1]/$scheduled_date[2]/$scheduled_date[0]",
            *        "timeRange" => "10-18",
            *        "type" => "reminder",
            *        "timeZone" => date('P'),
            *        "greeting" => str_replace("[[sender]]", $sender_name, str_replace("[[patient_name]]", $patientfname, $myrow['reminder_content']))
            *      );
            *
            *      // Make the call.
            *      $response = $client->sendRequest("appointment", "POST", $data);
            *
            *      if ($response->IsError) {
            *        // deal with and keep track of this unsuccessful call
            *        $logging['number_failed_calls']++;
            *      }
            *      else {
            *        // deal with and keep track of this succesful call
            *        sqlStatementCdrEngine("UPDATE `patient_reminders` SET `voice_status`='1', `date_sent`=NOW() WHERE id=?", array($reminder['id']) );
            *        $logging['number_success_calls']++;
            *      }
            *******************************************************************************/
        }
    }
    // For logging purposes only:
    //  Collect active reminders that have not yet been sent.
    $logging['total_post_unsent_reminders'] = count(fetch_reminders('', 'unsent'));
    return $logging;
}