function edit($id = null) { if (!$id && empty($this->data)) { $this->Session->setFlash(__('Invalid ResultLookup', true)); $this->redirect(array('action' => 'index')); } if (!empty($this->data)) { parent::archive($id); $this->data = Set::insert($this->data, 'ResultLookup.user_id', $this->Auth->user('id')); if ($this->ResultLookup->save($this->data)) { $this->Session->setFlash(__('The ResultLookup has been saved', true)); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('The ResultLookup could not be saved. Please, try again.', true)); } } if (empty($this->data)) { $this->data = $this->ResultLookup->read(null, $id); $test_id = $this->data['ResultLookup']['test_id']; $this->set('test_id', $test_id); $this->set('id', $id); } $tests = $this->ResultLookup->Test->find('list'); $this->set(compact('tests')); }
function delete($id = null) { if (!$id) { $this->Session->setFlash(__('Invalid id for Group', true)); $this->redirect(array('action' => 'index')); } parent::archive($id); if ($this->Group->del($id)) { $this->Session->setFlash(__('Group deleted', true)); $this->redirect(array('action' => 'index')); } }
function edit($id = null) { if (!$id && empty($this->data)) { $this->Session->setFlash(__('Invalid Test', true)); $this->redirect(array('action' => 'index')); } if (!empty($this->data)) { parent::archive($id); $this->data = Set::insert($this->data, 'Test.user_id', $this->Auth->user('id')); if ($this->Test->save($this->data)) { $this->Session->setFlash(__('The Test has been saved', true)); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('The Test could not be saved. Please, try again.', true)); } } if (empty($this->data)) { $this->data = $this->Test->read(null, $id); } }
/** * If the status of the row with PID $pid is FALSE (i.e. the patient is * inactive) then toggle to active (with appropriate auditing) and redirect * to the referring page. Otherwise, show a form for InactiveReason which, * when submitted and written to database, redirects to the original * referer. */ function toggleStatus($pid = NULL) { // Check $pid is valid if (!$pid || !$this->Patient->isValidPID($pid) || !$this->Patient->valueExists($pid, 'Patient', 'pid')) { $this->redirect(array('action' => 'index')); } $this->Patient->id = $pid; if ($this->Patient->field('status')) { // `status' is currently TRUE, so we either need to display the form to // choose an inactive reason, or receive the submission of said form if (isset($this->data)) { // Archive the current row parent::archive($pid); // Perform the toggle $data['Patient']['pid'] = $pid; $data['Patient']['status'] = FALSE; $data['Patient']['inactive_reason_id'] = $this->data['Patient']['inactive_reason_id']; $data['Patient']['status_timestamp'] = $this->data['Patient']['status_timestamp']; $this->Patient->save($data); // Redirect back to where you came from $this->redirect($this->data['Patient']['referer']); } else { $this->set(array('pid' => $pid, 'referer' => $this->referer(), 'inactive_reasons' => $this->InactiveReason->find('list'))); } } else { // `status' is currently FALSE, so toggle it to true // Archive the current row parent::archive($pid); // Perform the toggle $data['Patient']['pid'] = $pid; $data['Patient']['status'] = TRUE; $data['Patient']['inactive_reason_id'] = NULL; $data['Patient']['status_timestamp'] = date('c'); $this->Patient->save($data); // Redirect back to where you came from $this->redirect($this->referer()); } }
/** * Edit a row in the MedicalInformation table, with appropriate auditing */ function edit($pid = NULL) { // Check $pid is okay if (empty($pid) || !$this->Patient->isValidPID($pid) || !$this->Patient->valueExists($pid, 'Patient', 'pid')) { $this->redirect(array('controller' => 'patients', 'action' => 'index')); } // If there's somehow not a row in the medical_informations table, then // create it now. Hopefully this will never happen, but it might if, say // the connection was lost in the middle of adding a new patient. if (!$this->MedicalInformation->valueExists($pid, 'MedicalInformation', 'pid')) { $this->MedicalInformation->save(array('MedicalInformation' => array('pid' => $pid))); } // If some data has been sent, then archive and edit the database table, // then redirect to PatientsController::view if (isset($this->data)) { $this->data['MedicalInformation']['user_id'] = $this->Auth->user('id'); // Necessary because if validation fails we want $this->data to be // pristine $data = $this->data; // Fix all of the dates to ISO 8601 foreach (array('hiv_positive_date', 'hiv_positive_clinic_start_date', 'art_start_date', 'art_eligibility_date', 'transfer_in_date', 'transfer_out_date') as $dateField) { if (!empty($data['MedicalInformation'][$dateField]['day']) && !empty($data['MedicalInformation'][$dateField]['month']) && !empty($data['MedicalInformation'][$dateField]['year'])) { $data['MedicalInformation'][$dateField] = $data['MedicalInformation'][$dateField]['year'] . '-' . $data['MedicalInformation'][$dateField]['month'] . '-' . $data['MedicalInformation'][$dateField]['day']; } else { $data['MedicalInformation'][$dateField] = NULL; } } // Archive the existing data parent::archive($pid); $medicalInformation = $this->data['MedicalInformation']; $artRegimen = $this->data['ArtRegimen']; $artInterruption = $this->data['ArtInterruption']; $artSubstitution = $this->data['ArtSubstitution']; $invalidReg = array(); $invalidInt = array(); $invalidSub = array(); $invalidMed = array(); $intAdd = array(); $subAdd = array(); $regAdd = array(); $this->MedicalInformation->set(array('MedicalInformation' => $medicalInformation)); if (!$this->MedicalInformation->validates()) { $invalidMed = $this->MedicalInformation->validationErrors; unset($this->MedicalInformation->validationErrors); } $counter = 0; foreach ($artRegimen as $i) { if ($i['regimen_id'] != Null) { $i = Set::insert($i, 'pid', $pid); $this->MedicalInformation->ArtRegimen->set(array('ArtRegimen' => $i)); if (!$this->MedicalInformation->ArtRegimen->validates()) { $invalidReg[$counter] = $this->MedicalInformation->ArtRegimen->validationErrors; unset($this->MedicalInformation->ArtRegimen->validationErrors); } $regAdd[] = $i; } $counter++; } $counter = 0; foreach ($artInterruption as $i) { if ($i['interruption_date'] != Null and $i['art_interruption_reason_id'] != Null and $i['restart_date'] != Null) { $i = Set::insert($i, 'pid', $pid); $this->MedicalInformation->ArtInterruption->set(array('ArtInterruption' => $i)); if (!$this->MedicalInformation->ArtInterruption->validates()) { $invalidInt[$counter] = $this->MedicalInformation->ArtInterruption->validationErrors; unset($this->MedicalInformation->ArtInterruption->validationErrors); } $intAdd[] = $i; } $counter++; } $counter = 0; foreach ($artSubstitution as $i) { if ($i['date'] != Null and $i['regimen_id'] != Null and $i['art_substitution_reason_id'] != Null) { $i = Set::insert($i, 'pid', $pid); $this->MedicalInformation->ArtSubstitution->set(array('ArtSubstitution' => $i)); if (!$this->MedicalInformation->ArtSubstitution->validates()) { debug('hei'); $invalidSub[$counter] = $this->MedicalInformation->ArtSubstitution->validationErrors; unset($this->MedicalInformation->ArtSubstitution->validationErrors); } $subAdd[] = $i; } $counter++; } if (empty($invalidReg) and empty($invalidInt) and empty($invalidSub) and empty($invalidMed)) { $this->MedicalInformation->create(); $this->MedicalInformation->save(array('MedicalInformation' => $medicalInformation)); foreach ($subAdd as $value) { $this->MedicalInformation->ArtSubstitution->create(); $this->MedicalInformation->ArtSubstitution->save(array('ArtSubstitution' => $value)); } foreach ($intAdd as $value) { $this->MedicalInformation->ArtInterruption->create(); $this->MedicalInformation->ArtInterruption->save(array('ArtInterruption' => $value)); } foreach ($regAdd as $value) { $this->MedicalInformation->ArtRegimen->create(); $this->MedicalInformation->ArtRegimen->save(array('ArtRegimen' => $value)); } $this->Session->setFlash('Record updated'); $this->redirect(array('controller' => 'patients', 'action' => 'view/' . $pid)); } else { $this->MedicalInformation->validationErrors = $invalidMed; $this->MedicalInformation->ArtRegimen->validationErrors = $invalidReg; $this->MedicalInformation->ArtSubstitution->validationErrors = $invalidSub; $this->MedicalInformation->ArtInterruption->validationErrors = $invalidInt; $this->Session->setFlash('Could not update record'); } } // We need to set some stuff before the form can be displayed if (!isset($this->data)) { // if condition required in case validation has failed $this->data = $this->MedicalInformation->findByPid($pid); $id = 2; $tmp = array(); foreach (array_keys($this->data['ArtSubstitution']) as $key) { if ($this->data['ArtSubstitution'][$key]['art_line'] == 2) { $tmp[$id] = $this->data['ArtSubstitution'][$key]; $id++; } else { $tmp[$key] = $this->data['ArtSubstitution'][$key]; } } $this->data['ArtSubstitution'] = $tmp; $id = 1; foreach (array_keys($this->data['ArtRegimen']) as $key) { if ($this->data['ArtRegimen'][$key]['art_line'] == 2) { $this->data['ArtRegimen'][$id] = $this->data['ArtRegimen'][$key]; unset($this->data['ArtRegimen'][$key]); } } } $this->set(array('fullname' => $this->Patient->field('forenames', array('pid' => $pid)) . ' ' . $this->Patient->field('surname', array('pid' => $pid)), 'medical_information' => $this->MedicalInformation->read(NULL, $pid), 'patient_sources' => $this->PatientSource->find('list'), 'fundings' => $this->Funding->find('list'), 'hiv_positive_test_locations' => $this->Location->generatetreelist(null, null, null, '-'), 'art_service_types' => $this->ArtServiceType->find('list'), 'art_starting_regimens' => $this->Regimen->find('list'), 'art_indications' => $this->ArtIndication->find('list'), 'transfer_in_districts' => $this->Location->generatetreelist(null, null, null, '-'), 'pep_reasons' => $this->PepReason->find('list'), 'art_second_line_reasons' => $this->ArtSecondLineReason->find('list'), 'regimens' => $this->Regimen->find('list'), 'art_substitution_reasons' => $this->ArtSubstitutionReason->find('list'), 'art_interruption_reasons' => $this->ArtInterruptionReason->find('list'))); }