Inheritance: extends BaseActiveRecordVersioned
 /**
  * @dataProvider getCurrentAttributesByIdProvider
  *
  * @param $wp_attrs
  */
 public function test_getCurrentAttributesById($wp_attrs)
 {
     $worklist_patient_attrs = array();
     $expected = array();
     foreach ($wp_attrs as $attr) {
         $wpa = ComponentStubGenerator::generate('WorklistPatientAttribute', $attr);
         $expected[$attr['worklist_attribute_id']] = $wpa;
         $worklist_patient_attrs[] = $wpa;
     }
     $worklist_patient = new WorklistPatient();
     $worklist_patient->worklist_attributes = $worklist_patient_attrs;
     $this->assertEquals($expected, $worklist_patient->getCurrentAttributesById());
 }
Example #2
0
 /**
  * @param WorklistPatient $worklist_patient
  * @param array           $attributes
  *
  * @return bool
  *
  * @throws CDbException
  * @throws Exception
  */
 public function setAttributesForWorklistPatient(WorklistPatient $worklist_patient, $attributes = array())
 {
     $transaction = $this->startTransaction();
     $worklist = $worklist_patient->worklist;
     try {
         $current_attributes = $worklist_patient->getCurrentAttributesById();
         $valid_attributes = $worklist->getMappingAttributeIdsByName();
         foreach ($attributes as $attr => $val) {
             if (!array_key_exists($attr, $valid_attributes)) {
                 throw new Exception("Unrecognised attribute {$attr} for {$worklist->name}");
             }
             $wlattr = isset($current_attributes[$valid_attributes[$attr]]) ? $current_attributes[$valid_attributes[$attr]] : $this->getInstanceForClass('WorklistPatientAttribute');
             $wlattr->attributes = array('worklist_patient_id' => $worklist_patient->id, 'worklist_attribute_id' => $valid_attributes[$attr], 'attribute_value' => $val);
             if (!$wlattr->save()) {
                 throw new Exception("Unable to save attribute {$attr} for patient worklist.");
             }
         }
         // TODO: decide if we should check for current attributes that are no longer valid
         // and delete them here.
         if ($transaction) {
             $transaction->commit();
         }
     } catch (Exception $e) {
         $this->addError($e->getMessage());
         throw $e;
         if ($transaction) {
             $transaction->rollback();
         }
         return false;
     }
     return true;
 }
 /**
  * @dataProvider partialUpdate_Provider
  *
  * @param $initial_put
  * @param $partial_put
  * @param $expected_values
  */
 public function testPartialUpdate($initial, $partial, $expected_values, $error = null)
 {
     $this->put('PartialUpdate', $initial);
     $id = $this->xPathQuery('/Success//Id')->item(0)->nodeValue;
     $appt = WorklistPatient::model()->findByPk($id);
     $this->assertNotNull($appt);
     if ($error) {
         $this->setExpectedHttpError($error[0]);
     }
     $this->put('PartialUpdate', $partial, array('X-OE-Partial-Record' => 1));
     //var_dump($this->response->getBody(true));
     $patient = WorklistPatient::model()->findByPk($id);
     $this->assertExpectedValuesMatch($expected_values, $patient);
     if ($error) {
         $this->assertFailureMessage($error[1]);
     }
 }