From 4b9af59802fdcfaad26af053a3008c897aa767cb Mon Sep 17 00:00:00 2001 From: itskiprotich Date: Fri, 27 Sep 2024 17:20:30 +0300 Subject: [PATCH] UPD: SADR -> manager copy --- src/Controller/Manager/SadrsController.php | 151 +++++++++++++++++- templates/Manager/Sadrs/edit.php | 168 +++++++-------------- templates/Users/register.php | 4 +- templates/element/comments/add.php | 9 +- 4 files changed, 201 insertions(+), 131 deletions(-) diff --git a/src/Controller/Manager/SadrsController.php b/src/Controller/Manager/SadrsController.php index 431c3207c..3d1dec652 100755 --- a/src/Controller/Manager/SadrsController.php +++ b/src/Controller/Manager/SadrsController.php @@ -5,6 +5,7 @@ namespace App\Controller\Manager; use App\Controller\AppController; +use Cake\Http\Exception\NotFoundException; /** * Sadrs Controller @@ -62,8 +63,8 @@ public function download($id = null) $sadr = $this->Sadrs->get($id, [ 'contain' => ['Users', 'Pqmps', 'ExternalComment' => ['Attachments'], 'Medications', 'Counties', 'Attachments', 'SubCounties', 'Designations', 'SadrDescriptions', 'SadrFollowups', 'SadrListOfDrugs' => ['Routes', 'Frequencies', 'Doses'], 'SadrListOfMedicines', 'SadrReaction'], ]); -// debug($sadr); -// exit; + // debug($sadr); + // exit; // Set the Sadr data to be used in the template $this->set(compact('sadr')); @@ -156,26 +157,160 @@ public function add() public function edit($id = null) { $sadr = $this->Sadrs->get($id, [ - 'contain' => [], + 'contain' => ['Attachments', 'SadrReaction', 'SadrListOfDrugs', 'SadrListOfMedicines'], ]); if ($this->request->is(['patch', 'post', 'put'])) { - $sadr = $this->Sadrs->patchEntity($sadr, $this->request->getData()); - if ($this->Sadrs->save($sadr)) { - $this->Flash->success(__('The sadr has been saved.')); + $data = $this->request->getData(); + $validate = false; + if (!empty($this->request->getData('submitReport'))) { + $validate = true; + } + $sadr = $this->Sadrs->patchEntity($sadr, $data, [ + 'validate' => $validate, + 'associated' => [ + 'Attachments', + 'SadrReaction', + 'SadrListOfDrugs'=>[ 'validate' => $validate], + 'SadrListOfMedicines'=>[ 'validate' => $validate], + ] + ]); - return $this->redirect(['action' => 'index']); + if ($this->Sadrs->save($sadr, ['validate' => $validate, 'deep' => true])) { + if (!empty($this->request->getData('submitReport'))) { + $sadr = $this->Sadrs->get($id, [ + 'contain' => ['Attachments', 'SadrReaction'], + ]); + $dataTable = $this->getTableLocator()->get('sadrs'); + // Update the field using the query builder + $result = $dataTable->query() + ->update() + ->set([ + 'submitted' => 2, + 'submitted_date' => date("Y-m-d H:i:s"), + ]) + ->where(['id' => $id]) + ->execute(); + + + $sadr = $this->Sadrs->get($id, [ + 'contain' => ['Attachments', 'SadrReaction'], + ]); + + $this->Flash->success(__('The SADR has been submitted')); + return $this->redirect(array('action' => 'view', $sadr->id)); + } else { + $sadr = $this->Sadrs->get($id, [ + 'contain' => ['Attachments', 'SadrReaction', 'SadrListOfDrugs', 'SadrListOfMedicines'], + ]); + + $this->request = $this->request->withParsedBody($sadr->toArray()); + $this->Flash->success(__('The SADR has been saved')); + return $this->redirect($this->referer()); + } + } else { + $errors = $sadr->getErrors(); + $this->Flash->error(__('The SADR could not be saved. Please review the error(s) and resubmit and try again.')); } - $this->Flash->error(__('The sadr could not be saved. Please, try again.')); } + $this->request = $this->request->withParsedBody($sadr->toArray()); + $users = $this->Sadrs->Users->find('list', ['limit' => 200])->all(); $pqmps = $this->Sadrs->Pqmps->find('list', ['limit' => 200])->all(); $medications = $this->Sadrs->Medications->find('list', ['limit' => 200])->all(); $counties = $this->Sadrs->Counties->find('list', ['limit' => 200])->all(); $subCounties = $this->Sadrs->SubCounties->find('list', ['limit' => 200])->all(); $designations = $this->Sadrs->Designations->find('list', ['limit' => 200])->all(); + $routes = $this->Sadrs->SadrListOfDrugs->Routes->find('list'); + $this->set(compact('routes')); + $frequency = $this->Sadrs->SadrListOfDrugs->Frequencies->find('list'); + $this->set(compact('frequency')); + $dose = $this->Sadrs->SadrListOfDrugs->Doses->find('list'); + $this->set(compact('dose')); $this->set(compact('sadr', 'users', 'pqmps', 'medications', 'counties', 'subCounties', 'designations')); } + public function copy($id = null) + { + $sadr = $this->Sadrs->get($id, [ + 'contain' => ['SadrListOfDrugs', 'SadrReaction', 'SadrDescriptions', 'SadrListOfMedicines'] + ]); + + if (!$sadr) { + throw new NotFoundException(__('Invalid SADR')); + } + // debug($sadr); + // exit; + // Check if a clean copy already exists + if ($sadr->copied) { + $this->Flash->error(__('A clean copy already exists. Click on edit to update changes.')); + return $this->redirect(['action' => 'index']); + } + + // Remove unwanted IDs + $sadrListOfDrug = $sadr->get('sadr_list_of_drugs'); + // debug($sadrListOfDrug); + // exit; + if ($sadrListOfDrug) { + foreach ($sadrListOfDrug as &$drug) { + unset($drug->id); + } + } + $sadrListOfMedicine = $sadr->get('sadr_list_of_medicines'); + + if ($sadrListOfMedicine) { + foreach ($sadrListOfMedicine as &$medicine) { + unset($medicine->id); + } + } + + unset($sadr->id); + $dataSave = $sadr->toArray(); + if ($sadrListOfDrug) { + $dataSave['sadr_list_of_drugs'] = $sadrListOfDrug; + } + if ($sadrListOfMedicine) { + $dataSave['sadr_list_of_medicines'] = $sadrListOfMedicine; + } + $dataSave['sadr_id'] = $id; + $dataSave['user_id'] = $this->Auth->user('id'); + $dataSave['copied'] = 2; + + + // debug($dataSave); + // exit; + + // Mark the original SADR as copied + $dataTable = $this->getTableLocator()->get('sadrs'); + // Update the field using the query builder + $result = $dataTable->query() + ->update() + ->set([ + 'copied' => 1 + ]) + ->where(['id' => $id]) + ->execute(); + // Save the new clean copy + + $sadr = $this->Sadrs->newEmptyEntity(); + + $sadr = $this->Sadrs->patchEntity($sadr, $dataSave, [ + 'validate' => false, + 'associated' => [ + 'Attachments', + 'SadrReaction', + 'SadrListOfDrugs', + 'SadrListOfMedicines' + ] + ]); + + if ($this->Sadrs->save($sadr, ['validate' => false, 'deep' => true])) { + $this->Flash->success(__('Clean copy of ' . $dataSave['reference_no'] . ' has been created.')); + return $this->redirect(['action' => 'edit', $sadr->id]); + } else { + $this->Flash->error(__('The clean copy could not be created. Please, try again.')); + return $this->redirect($this->referer()); + } + } /** * Delete method * diff --git a/templates/Manager/Sadrs/edit.php b/templates/Manager/Sadrs/edit.php index ed24182e5..5852dc310 100755 --- a/templates/Manager/Sadrs/edit.php +++ b/templates/Manager/Sadrs/edit.php @@ -1,121 +1,59 @@ assign('SADR', 'active'); ?> -
- -
-
- Form->create($sadr) ?> -
- - Form->control('sadr_id'); - echo $this->Form->control('user_id', ['options' => $users, 'empty' => true]); - echo $this->Form->control('pqmp_id', ['options' => $pqmps, 'empty' => true]); - echo $this->Form->control('medication_id', ['options' => $medications, 'empty' => true]); - echo $this->Form->control('county_id', ['options' => $counties, 'empty' => true]); - echo $this->Form->control('sub_county_id', ['options' => $subCounties, 'empty' => true]); - echo $this->Form->control('designation_id', ['options' => $designations, 'empty' => true]); - echo $this->Form->control('reference_no'); - echo $this->Form->control('vigiflow_id'); - echo $this->Form->control('report_title'); - echo $this->Form->control('report_type'); - echo $this->Form->control('report_sadr'); - echo $this->Form->control('report_therapeutic'); - echo $this->Form->control('report_misuse'); - echo $this->Form->control('report_off_label'); - echo $this->Form->control('product_category'); - echo $this->Form->control('medicinal_product'); - echo $this->Form->control('blood_products'); - echo $this->Form->control('herbal_product'); - echo $this->Form->control('cosmeceuticals'); - echo $this->Form->control('product_other'); - echo $this->Form->control('product_specify'); - echo $this->Form->control('name_of_institution'); - echo $this->Form->control('institution_code'); - echo $this->Form->control('address'); - echo $this->Form->control('contact'); - echo $this->Form->control('patient_name'); - echo $this->Form->control('ip_no'); - echo $this->Form->control('date_of_birth'); - echo $this->Form->control('age_group'); - echo $this->Form->control('patient_address'); - echo $this->Form->control('ward'); - echo $this->Form->control('gender'); - echo $this->Form->control('known_allergy'); - echo $this->Form->control('known_allergy_specify'); - echo $this->Form->control('pregnant'); - echo $this->Form->control('pregnancy_status'); - echo $this->Form->control('weight'); - echo $this->Form->control('height'); - echo $this->Form->control('diagnosis'); - echo $this->Form->control('reaction'); - echo $this->Form->control('medical_history'); - echo $this->Form->control('date_of_onset_of_reaction'); - echo $this->Form->control('description_of_reaction'); - echo $this->Form->control('reaction_resolve'); - echo $this->Form->control('reaction_reappear'); - echo $this->Form->control('lab_investigation'); - echo $this->Form->control('severity'); - echo $this->Form->control('serious'); - echo $this->Form->control('serious_reason'); - echo $this->Form->control('action_taken'); - echo $this->Form->control('outcome'); - echo $this->Form->control('causality'); - echo $this->Form->control('any_other_comment'); - echo $this->Form->control('reporter_name'); - echo $this->Form->control('reporter_email'); - echo $this->Form->control('reporter_phone'); - echo $this->Form->control('submitted'); - echo $this->Form->control('emails'); - echo $this->Form->control('active'); - echo $this->Form->control('device'); - echo $this->Form->control('deleted'); - echo $this->Form->control('archived'); - echo $this->Form->control('archived_date', ['empty' => true]); - echo $this->Form->control('deleted_date', ['empty' => true]); - echo $this->Form->control('notified'); - echo $this->Form->control('reporter_date', ['empty' => true]); - echo $this->Form->control('person_submitting'); - echo $this->Form->control('reporter_name_diff'); - echo $this->Form->control('reporter_designation_diff'); - echo $this->Form->control('reporter_email_diff'); - echo $this->Form->control('reporter_phone_diff'); - echo $this->Form->control('reporter_date_diff', ['empty' => true]); - echo $this->Form->control('assigned_to'); - echo $this->Form->control('assigned_by'); - echo $this->Form->control('assigned_date', ['empty' => true]); - echo $this->Form->control('vigiflow_message'); - echo $this->Form->control('vigiflow_ref'); - echo $this->Form->control('vigiflow_date', ['empty' => true]); - echo $this->Form->control('webradr_ref'); - echo $this->Form->control('webradr_date', ['empty' => true]); - echo $this->Form->control('submitted_date', ['empty' => true]); - echo $this->Form->control('webradr_message'); - echo $this->Form->control('copied'); +
+
+
+
+ element('sadr/sadr_edit');?> +
+
+
+
+ +
+
FEEDBACK
+
+
+ element('comments/list', ['comments' => $sadr['ExternalComment']]); + ?> +
+
+ element('comments/add', [ + 'model' => ['model_id' => $sadr['id'], 'foreign_key' => $sadr['id'], + 'model' => 'Sadr', 'category' => 'external', 'url' => 'report_feedback']]) ?> - - Form->button(__('Submit')) ?> - Form->end() ?> +
+
+
-
+ \ No newline at end of file diff --git a/templates/Users/register.php b/templates/Users/register.php index 2ad7ed0f0..bfbaa874e 100755 --- a/templates/Users/register.php +++ b/templates/Users/register.php @@ -27,9 +27,7 @@ echo $this->Form->control('password', [ 'label' => 'Password ', 'escape' => false, - 'templates' => [ - 'inputContainerError' => '
{{content}}{{error}}
', - ], + ]); echo $this->Form->control('confirm_password', ['type' => 'password', 'label' => 'Confirm Password ', 'escape' => false]); diff --git a/templates/element/comments/add.php b/templates/element/comments/add.php index 4200d5008..d820f3bee 100755 --- a/templates/element/comments/add.php +++ b/templates/element/comments/add.php @@ -13,8 +13,7 @@ echo $this->Form->control('model_id', ['type' => 'hidden', 'value' => $model['model_id'], 'escape' => false]); echo $this->Form->control('foreign_key', ['type' => 'hidden', 'value' => $model['foreign_key']]); echo $this->Form->control('model', ['type' => 'hidden', 'value' => $model['model']]); - -// echo $this->Form->control('model', ['type' => 'hidden', 'value' => 'ssssss']); + echo $this->Form->control('category', ['type' => 'hidden', 'value' => $model['category']]); echo $this->Form->control('user_id', ['type' => 'hidden', 'value' => $this->request->getSession()->read('Auth.User.id')]); ?> @@ -30,9 +29,9 @@ echo $this->Form->control('review', ['label' => array('class' => 'required'), 'type' => 'textarea']); } else { - echo $this->Form->control('subject', ['label' => array('class' => 'required', 'text' => 'Subject')]); - echo $this->Form->control('content', ['label' => array('class' => 'required'), 'type' => 'textarea']); - + echo $this->Form->control('subject', ['label' => array('class' => 'form-control required', 'text' => 'Subject')]); + echo '
'; + echo $this->Form->control('content', ['label' => array('class' => ' form-control required'), 'type' => 'textarea']); } ?>