Get the current worklist patient attributes indexed by the worklist mapping Ids.
public getCurrentAttributesById ( ) : array | ||
리턴 | array |
/** * @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()); }
/** * @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; }