Created
May 19, 2017 13:32
-
-
Save iaditya/84c4381ce1410b2dc1b0a24dc346961d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function drugAlert() { | |
/** | |
* run on terminal | |
* | |
* bin/cake Alerts drugAlert | |
* | |
*/ | |
// send notification to patient/caregiver/provider/fAdmin | |
$after_two_day = 2880; | |
$duration = 60; | |
$start = Time::now()->addMinutes($after_two_day)->toDateTimeString(); | |
$end = Time::now()->addMinutes($duration + $after_two_day)->toDateTimeString(); | |
$query = $this->PrescriptionItems->find('all') | |
->where(['PrescriptionItems.days IS NOT' => null]); | |
$prescription_items = $query->select(['PrescriptionItems.prescription_id', 'PrescriptionItems.drug_id']); | |
//->where(['ADDDATE(PrescriptionItems.created, PrescriptionItems.days) BETWEEN :now AND :then']) | |
//->bind(':now', $start, 'time') | |
//->bind(':then', $end, 'time') | |
//->toArray(); | |
//$this->out(print_r($prescription_items, true)); exit; | |
foreach ($prescription_items as $prescription_item) { | |
$prescriptions = $this->Prescriptions->findById($prescription_item->prescription_id); | |
$drug = $this->Drugs->findById($prescription_item->drug_id); | |
if(!empty($prescriptions->first())) { | |
$prescription = $prescriptions->first(); | |
//For patient | |
if(!empty($prescription->patient_id)) { | |
$patient_user_id = $this->Patients->findById($prescription->patient_id)->first(); | |
if(!empty($patient_user_id)) { | |
$this->out(print_r("Drug Refill notification send to patient USER ID - " . $patient_user_id->user_id, true)); | |
//send notification | |
} | |
} | |
// For provider | |
if(!empty($prescription->provider_id)) { | |
$provider_user_id = $this->Providers->findById($prescription->provider_id)->first(); | |
if(!empty($provider_user_id)) { | |
$this->out(print_r("Drug Refill notification send to provider USER ID - " . $provider_user_id->user_id, true)); | |
//send notification | |
} | |
} | |
//For facilityAdmin & Facility | |
if(!empty($prescription->facility_id)) { | |
//$patient_user_id = $this->Facilities->findById($prescription->provider_id)->first()->user_id; | |
$facilityAdmin_user_ids = $this->FacilityAdmins->findByFacilityId($prescription->facility_id); | |
foreach ($facilityAdmin_user_ids as $facilityAdmin_user_id) { | |
$fadmin_user_id = $facilityAdmin_user_id->user_id; | |
if(!empty($fadmin_user_id)) { | |
$this->out(print_r("Drug Refill notification send to fAdmin USER ID - " . $fadmin_user_id, true)); | |
//send notification | |
} | |
} | |
} | |
} | |
} | |
$this->out(print_r($start, true)); | |
$this->out(print_r($end, true)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment