createFromPrescriptionItem() public method

Takes a prescription item and sets the appropriate medication values from it.
public createFromPrescriptionItem ( $item )
$item
 /**
  * Get or Create a Medication instance for the given patient id and item id.
  *
  * @TODO: consider error checking for Medication already existing?
  *
  * @param $patient_id
  * @param $item_id
  *
  * @return Medication
  *
  * @throws Exception
  */
 public function getMedicationForPrescriptionItem($patient_id, $item_id)
 {
     if ($item = OphDrPrescription_Item::model()->with('prescription.event.episode')->findByPk($item_id)) {
         if ($item->prescription->event->episode->patient_id != $patient_id) {
             throw new Exception('prescription item id and patient id must match');
         }
         $medication = new Medication();
         $medication->createFromPrescriptionItem($item);
         return $medication;
     }
 }
Example #2
0
 /**
  * Gets the previous medications linked with items from the prescription events.
  *
  * @return array
  */
 public function get_previous_medications()
 {
     $medicationCriteria = new CDbCriteria(array('order' => 'created_date DESC'));
     $medicationCriteria->addCondition('end_date is not null and end_date < NOW()');
     $medications = $this->patientMedications($medicationCriteria);
     $medicationsFromPrescriptions = $this->prescriptionMedicationIds();
     $prescriptionItems = $this->prescriptionItems($medicationsFromPrescriptions);
     if ($prescriptionItems) {
         foreach ($prescriptionItems as $item) {
             $medication = new Medication();
             $medication->createFromPrescriptionItem($item);
             if ($medication->isPreviousMedication()) {
                 $medications[] = $medication;
             }
         }
     }
     usort($medications, array($this, 'sortMedications'));
     return $medications;
 }