Пример #1
0
 public function modify($param, $old_key)
 {
     if ($param['key'] == $old_key) {
         $sql = "UPDATE pages SET `title` = '" . $param['title'] . "', `body` = '" . $param['body'] . "' WHERE `key` = '" . $param['key'] . "'";
         $this->makeSql($sql, FALSE);
         return TRUE;
     } else {
         $sql = "SELECT `key` FROM pages WHERE `key` = '" . $param['key'] . "'";
         $result = makeSql($sql, TRUE);
         if (count($result) > 0) {
             return FALSE;
         } else {
             $sql = "UPDATE pages SET `key` = '" . $param['key'] . "', `title` = '" . $param['title'] . "', `body` = '" . $param['body'] . "' WHERE `key` = '" . $old_key . "'";
             $this->makeSql($sql, FALSE);
             return TRUE;
         }
     }
     // some magic ...
     // return true|false
 }
Пример #2
0
 function setAsDelinquent()
 {
     $in['uRec'] = $this->uRec;
     $in['paymentDelinquent'] = 1;
     $sql = "SELECT * FROM stripeAuth WHERE uRec=" . $in['uRec'];
     $id = 0;
     if ($rc = dbQuery($sql)) {
         if ($row = dbFetch($rc)) {
             $id = $row["id"];
             $update = true;
         } else {
             $update = false;
         }
     } else {
         logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
     }
     if ($update) {
         $sql = "UPDATE stripeAuth " . makeSql($in, "update") . " WHERE id={$id} ";
     } else {
         $sql = "INSERT INTO stripeAuth " . makeSql($in, "insert");
     }
     if ($rc = dbQuery($sql)) {
         logit(INFO, 'set customer as delinquent| sql: ' . $sql);
     } else {
         logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
         return false;
     }
 }
Пример #3
0
 function calculateAttentionScore()
 {
     global $user;
     logit(INFO, "Starting Attention Score Calculator");
     $att = new AttentionAlerts();
     $med = new Meds();
     $user = new User();
     $trends = new UserMetrics();
     //check for flag
     if ($time = getFlag("MetiAttentionRun")) {
         $e = round((time() - $time) / 60, 2);
         //get hours
         if ($e > 360) {
             logit(WARN, "Error: calculateAttentionScore says it's been running for 6 hours " . __FILE__ . " on line: " . __LINE__);
         }
         logit(REPORT, " MetiAttention run aborted because it says it's still running. (Runtime: {$e} minutes, flag: MetiAttentionRun) in " . __FILE__ . " on line: " . __LINE__);
         return false;
     } else {
         setFlag("MetiAttentionRun", time());
     }
     //ok flags are fine let's run this. Round up them doggies
     $sql = "SELECT * FROM users WHERE userType = 1 AND disabled = 0 ";
     if ($rc = dbQuery($sql)) {
         while ($row = dbFetch($rc)) {
             if (CLI_ECHO) {
                 logit(INFO, "uRec: {$row["uRec"]}");
             }
             $uRec = $row["uRec"];
             $user->setUser($uRec);
             $user->getUser();
             //$trends->setUser();
             //$trends->getLatestSurveyCats();
             $this->attentionAggregate = array();
             $this->attentionAggregate["meds"] = 0;
             $this->attentionAggregate["survey"] = 0;
             $this->attentionAggregate["activity"] = 0;
             $this->attentionAggregate["medsAbs"] = 0;
             //remove med related scres
             $sql = "DELETE FROM attentionFlags WHERE uRec = '{$uRec}' AND (type = '{$att->attentionMeds}' OR type = '{$att->attentionMedAbs}') ";
             if ($rctemp = dbQuery($sql)) {
                 //calc med score.
                 $sql = "SELECT * FROM userMedCompliance WHERE uRec = '{$uRec}' AND period = '30' AND days = '30' ";
                 if ($rcMed = dbQuery($sql)) {
                     $med30 = array();
                     $med30Abs = array();
                     while ($rowMed = dbFetch($rcMed)) {
                         $med30[$rowMed["medId"]] = $rowMed["taken"] / $rowMed["doses"];
                         //if patient has reported more than 50% record med compliance
                         if ($rowMed["doses"] and $rowMed["unreported"] / $rowMed["doses"] < 0.5) {
                             $med30Abs[$rowMed["medId"]] = $rowMed["taken"] / $rowMed["doses"];
                         }
                     }
                 } else {
                     logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
                 }
                 //calculate abs med compliance
                 if (is_array($med30) or is_array($med30Abs)) {
                     $med->setUser();
                     $med->getUserMeds(TRUE, FALSE);
                 }
                 if (is_array($med30Abs)) {
                     $temp = array();
                     //let's write flags for each
                     foreach ($med30Abs as $key => $value) {
                         $score = 0;
                         if ($value < 0.8) {
                             if ($value < 0.6) {
                                 $score = 3;
                             } elseif ($value < 0.7) {
                                 $score = 2;
                             } else {
                                 $score = 1;
                             }
                             $temp[] = $score;
                             $in = "";
                             $in["uRec"] = $uRec;
                             $in["ref"] = $key;
                             $in["weight"] = $score;
                             $in["type"] = $att->attentionMedAbs;
                             $in["note"] = $med->userMeds[$key]["medOther"] . " compliance is " . round($value * 100, 0) . "%";
                             $in["expire"] = dbDate("+7 days");
                             $sql = "INSERT INTO attentionFlags " . makeSql($in, "insert");
                             if ($rcTemp = dbQuery($sql)) {
                             } else {
                                 logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
                             }
                         }
                     }
                     //end for
                     //get highest score
                     if (count($temp) > 0) {
                         $this->attentionAggregate["medsAbs"] = max($temp);
                     }
                 }
                 $medAlertList = array();
                 //calculate window trend for med compliance
                 //ok we got all of the 30s now let's get the 7s
                 if (is_array($med30)) {
                     foreach ($med30 as $key => $value) {
                         $sql = "SELECT * FROM userMedCompliance WHERE medId = '{$key}' AND uRec = '{$uRec}' AND period = '7' AND days = '7' ";
                         if ($rcMed = dbQuery($sql)) {
                             while ($rowMed = dbFetch($rcMed)) {
                                 $med7 = $rowMed["taken"] / $rowMed["doses"];
                                 if ($value > 0) {
                                     $d = ($med7 - $value) / $value;
                                     $delta = round($d * 100);
                                 } else {
                                     $delta = 0;
                                 }
                                 //got the delta, now let's calc att score
                                 $medScore = 0;
                                 if (is_numeric($delta) and $delta < -19) {
                                     if ($delta < -60) {
                                         $medScore = 3;
                                     } elseif ($delta < -40) {
                                         $medScore = 2;
                                     } else {
                                         $medScore = 1;
                                     }
                                     $this->attentionAggregate["meds"] = max($this->attentionAggregate["meds"], $medScore);
                                     //save score for this med.
                                     $in = "";
                                     $in["uRec"] = $uRec;
                                     $in["ref"] = $key;
                                     $in["weight"] = $medAlertList[] = $medScore;
                                     $in["type"] = $att->attentionMeds;
                                     $in["note"] = $med->userMeds[$key]["medOther"] . " compliance has declined by " . abs($delta) . "%";
                                     $in["expire"] = dbDate("+7 days");
                                     $sql = "INSERT INTO attentionFlags " . makeSql($in, "insert");
                                     if ($rcTemp = dbQuery($sql)) {
                                     } else {
                                         logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
                                     }
                                 }
                             }
                         } else {
                             logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
                         }
                     }
                     //end med 30 loop
                 }
                 //aggregate meds
                 //if (count($medAlertList) > 0 ) $this->attentionAggregate["meds"] = array_sum($medAlertList) / count($medAlertList);
             } else {
                 logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
             }
             //lookup survey
             $sql = "DELETE FROM attentionFlags WHERE uRec = '{$uRec}' AND type = '{$att->attentionSurvey}' ";
             if ($rctemp = dbQuery($sql)) {
                 $trends->setUser();
                 $s = $trends->getLatestSurveyCats();
                 $delta = $s["min"];
                 $surveyScore = 0;
                 if (is_numeric($delta) and $delta < -11) {
                     if ($delta < -39) {
                         $surveyScore = 3;
                     } elseif ($delta < -19) {
                         $surveyScore = 2;
                     } else {
                         $surveyScore = 1;
                     }
                     $this->attentionAggregate["survey"] = max($this->attentionAggregate["survey"], $surveyScore);
                     //save score
                     $in = "";
                     $in["uRec"] = $uRec;
                     $in["ref"] = 0;
                     $in["weight"] = $surveyScore;
                     $in["type"] = $att->attentionSurvey;
                     $in["note"] = "We\\'ve noticed a drop in some survey answers in the past 30 days.";
                     $in["expire"] = dbDate("+7 days");
                     $sql = "INSERT INTO attentionFlags " . makeSql($in, "insert");
                     if ($rcTemp = dbQuery($sql)) {
                     } else {
                         logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
                     }
                 }
             } else {
                 logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
             }
             //lookup activity
             $sql = "DELETE FROM attentionFlags WHERE uRec = '{$uRec}' AND type = '{$att->attentionActivity}' ";
             if ($rctemp = dbQuery($sql)) {
                 $delta = $row["activityChange"];
                 $activityScore = 0;
                 if (is_numeric($delta) and $delta < -19) {
                     if ($delta < -59) {
                         $activityScore = 3;
                     } elseif ($delta < -39) {
                         $activityScore = 2;
                     } else {
                         $activityScore = 1;
                     }
                     $this->attentionAggregate["activity"] = $activityScore;
                     //save score
                     $in = "";
                     $in["uRec"] = $uRec;
                     $in["ref"] = 0;
                     $in["weight"] = $activityScore;
                     $in["type"] = $att->attentionActivity;
                     $in["note"] = "C3HealthLink interaction has dropped by " . abs($delta) . "% in the past 30 days.";
                     $in["expire"] = dbDate("+7 days");
                     $sql = "INSERT INTO attentionFlags " . makeSql($in, "insert");
                     if ($rcTemp = dbQuery($sql)) {
                     } else {
                         logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
                     }
                 }
             }
             //let's get the other alert scores
             $sqlArr = array();
             $sqlArr["attentionDiaryRank"] = "SELECT MAX(weight) FROM attentionFlags WHERE uRec= {$uRec} AND type = {$att->attentionDiaryRank} ";
             $sqlArr["attentionDiaryKeyword"] = "SELECT MAX(weight) FROM attentionFlags WHERE uRec= {$uRec} AND type = {$att->attentionDiaryKeyword} ";
             $sqlArr["attentionSideEffect"] = "SELECT MAX(weight) FROM attentionFlags WHERE uRec= {$uRec} AND type = {$att->attentionSideEffect} ";
             $sqlArr["attentionMedComment"] = "SELECT MAX(weight) FROM attentionFlags WHERE uRec= {$uRec} AND type = {$att->attentionMedComment} ";
             foreach ($sqlArr as $key => $value) {
                 $this->attentionAggregate[$key] = 0;
                 if ($rcTemp = dbQuery($value)) {
                     if ($rowTemp = dbFetch($rcTemp)) {
                         $t = array_pop($rowTemp);
                         if ($t) {
                             $this->attentionAggregate[$key] = $t;
                         }
                         //logit(INFO,"$key : {$this->attentionAggregate[$key]}");
                     }
                 } else {
                     logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
                 }
             }
             //logit(INFO,"ME: ".print_r($this->attentionAggregate,1));
             //calculate
             /*
             	The max score is 18 but it's very rare anyone will hit max in all six categories so we assume anything above 6 is a red alert
             */
             $attAggTotal = array_sum($this->attentionAggregate);
             if ($attAggTotal > 0 and $attAggTotal < 4) {
                 $attScore = 2;
             } elseif ($attAggTotal > 3 and $attAggTotal < 7) {
                 $attScore = 3;
             } elseif ($attAggTotal > 6) {
                 $attScore = 4;
             } elseif ($user->active) {
                 $attScore = 1;
             } else {
                 $attScore = 0;
             }
             //logit(INFO,"SCORE: $attScore\t MEAN: $attAggMean\tTOTAL: $attAggTotal\tMAX: $attMax");
             //				$sql = "UPDATE users SET attScore = $attScore WHERE uRec = '$uRec' ";
             //				if (!$rcTemp = dbQuery($sql)) logit(WARN,"Error:  in ".__FILE__." on line: ".__LINE__);
         }
         //urec loop
     } else {
         logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
     }
     clearFlag("MetiAttentionRun");
     logit(INFO, "Ending Attention Score Calculator");
     return true;
 }
Пример #4
0
 function saveStats()
 {
     foreach ($this->stats as $entry) {
         $in = array();
         $in['uRec'] = $this->user->uRec;
         $in['device'] = $this->device;
         $in['date'] = $entry->date;
         $in['metric'] = $entry->metric;
         $in['value'] = $entry->value;
         //check
         $sql = "SELECT * FROM deviceData WHERE device={$this->device} AND date='" . $in["date"] . "' AND uRec='{$this->uRec}'" . " AND metric=" . $in['metric'];
         $id = 0;
         if ($rc = dbQuery($sql)) {
             if ($row = dbFetch($rc)) {
                 $id = $row["id"];
                 $update = true;
             } else {
                 $update = false;
             }
         } else {
             logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
         }
         if ($update) {
             $sql = "UPDATE deviceData " . makeSql($in, "update") . " WHERE id={$id} ";
         } else {
             $sql = "INSERT INTO deviceData " . makeSql($in, "insert");
         }
         if (!dbQuery($sql)) {
             logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
             return false;
         }
     }
     return true;
 }