Skip to content

Commit

Permalink
UPD: SADR -> manager copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Itskiprotich committed Sep 27, 2024
1 parent c457df9 commit 4b9af59
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 131 deletions.
151 changes: 143 additions & 8 deletions src/Controller/Manager/SadrsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Controller\Manager;

use App\Controller\AppController;
use Cake\Http\Exception\NotFoundException;

/**
* Sadrs Controller
Expand Down Expand Up @@ -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'));

Expand Down Expand Up @@ -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
*
Expand Down
168 changes: 53 additions & 115 deletions templates/Manager/Sadrs/edit.php
Original file line number Diff line number Diff line change
@@ -1,121 +1,59 @@
<?php
/**
* @var \App\View\AppView $this
* @var \App\Model\Entity\Sadr $sadr
* @var string[]|\Cake\Collection\CollectionInterface $users
* @var string[]|\Cake\Collection\CollectionInterface $pqmps
* @var string[]|\Cake\Collection\CollectionInterface $medications
* @var string[]|\Cake\Collection\CollectionInterface $counties
* @var string[]|\Cake\Collection\CollectionInterface $subCounties
* @var string[]|\Cake\Collection\CollectionInterface $designations
*/
$this->assign('SADR', 'active');
?>
<div class="row">
<aside class="column">
<div class="side-nav">
<h4 class="heading"><?= __('Actions') ?></h4>
<?= $this->Form->postLink(
__('Delete'),
['action' => 'delete', $sadr->id],
['confirm' => __('Are you sure you want to delete # {0}?', $sadr->id), 'class' => 'side-nav-item']
) ?>
<?= $this->Html->link(__('List Sadrs'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>


<!-- SADR
================================================== -->
<section id="sadrsview">
<ul class="nav nav-tabs">
<li><a href="#formview" data-toggle="tab">Original</a></li>
<li class="active"><a href="#formedit" data-toggle="tab"><?php echo (!empty($sadr['reference_no'])) ? $sadr['reference_no'] : $sadr['id'] ; ?></a></li>
</ul>

<div class="tab-content">
<div class="tab-pane" id="formview">
<div class="row-fluid">
<div class="span10">
<?php echo $this->element('sadr/sadr_view');?>
</div>
<div class="span2">
<?php
echo $this->Html->link('Download PDF', array('controller'=>'sadrs','action'=>'view', '_ext'=> 'pdf', $sadr['id']),
array('class' => 'btn btn-primary btn-block mapop', 'title'=>'Download PDF',
'data-content' => 'Download the pdf version of the report',));
?>
<hr>

</div>
</div>
</aside>
<div class="column-responsive column-80">
<div class="sadrs form content">
<?= $this->Form->create($sadr) ?>
<fieldset>
<legend><?= __('Edit Sadr') ?></legend>
<?php
echo $this->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');
</div>
<div class="tab-pane active" id="formedit">
<div class="row-fluid">
<div class="span12">
<?php echo $this->element('sadr/sadr_edit');?>
</div>
</div>
</div>
<div class="tab-pane" id="external_report_comments">
<!-- 12600 Letters debat -->
<div class="amend-form">
<h5 class="text-info"><u>FEEDBACK</u></h5>
<div class="row-fluid">
<div class="span8">
<?php
echo $this->element('comments/list', ['comments' => $sadr['ExternalComment']]);
?>
</div>
<div class="span4 lefty">
<?php
echo $this->element('comments/add', [
'model' => ['model_id' => $sadr['id'], 'foreign_key' => $sadr['id'],
'model' => 'Sadr', 'category' => 'external', 'url' => 'report_feedback']])
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
4 changes: 1 addition & 3 deletions templates/Users/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
echo $this->Form->control('password', [
'label' => 'Password ',
'escape' => false,
'templates' => [
'inputContainerError' => '<div class="input {{type}}{{required}} error">{{content}}{{error}}</div>',
],

]);

echo $this->Form->control('confirm_password', ['type' => 'password', 'label' => 'Confirm Password ', 'escape' => false]);
Expand Down
9 changes: 4 additions & 5 deletions templates/element/comments/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')]);
?>
Expand All @@ -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 '<br>';
echo $this->Form->control('content', ['label' => array('class' => ' form-control required'), 'type' => 'textarea']);
}
?>
</div>
Expand Down

0 comments on commit 4b9af59

Please sign in to comment.