diff --git a/config/cakepdf.php b/config/cakepdf.php
index b5974f37d7..2994e72fa1 100755
--- a/config/cakepdf.php
+++ b/config/cakepdf.php
@@ -10,6 +10,7 @@
'dpi' => 96,
'no-stop-slow-scripts' => true,
'enable-local-file-access' => true,
+ '--javascript-delay' =>5000
],
],
'margin' => [
diff --git a/config/routes.php b/config/routes.php
index a88439f713..8ddff50166 100755
--- a/config/routes.php
+++ b/config/routes.php
@@ -44,7 +44,7 @@
*/
Router::defaultRouteClass(DashedRoute::class);
-Router::extensions(['json', 'xml', 'csv']);
+Router::extensions(['json', 'xml', 'csv','pdf']);
Router::prefix('api', function ($routes) {
$routes->setExtensions(['json', 'xml','pdf']);
$routes->resources('Sadrs', [
diff --git a/src/Controller/Manager/CommentsController.php b/src/Controller/Manager/CommentsController.php
index 9a66baceeb..a7c2f47fc7 100755
--- a/src/Controller/Manager/CommentsController.php
+++ b/src/Controller/Manager/CommentsController.php
@@ -4,6 +4,7 @@
namespace App\Controller\Manager;
use App\Controller\AppController;
+use Cake\Filesystem\File;
use Cake\ORM\TableRegistry;
use Cake\Utility\Text;
use Cake\View\Helper\HtmlHelper;
@@ -16,6 +17,7 @@
*/
class CommentsController extends AppController
{
+
/**
* Index method
*
@@ -204,4 +206,35 @@ public function delete($id = null)
return $this->redirect(['action' => 'index']);
}
+
+ public function commentFileDownload($id = null)
+ {
+ $attachment = $this->Attachments->get($id);
+
+ if (!$attachment) {
+ $this->Flash->error(__('The requested file does not exist!'));
+ return $this->redirect($this->referer());
+ }
+
+ // Get the directory name and file name from the attachment entity
+ $directory = $attachment->dirname;
+ $fileName = $attachment->basename;
+
+ // Construct the full file path
+ $filePath = ROOT . DS . $directory . $fileName;
+
+ // Create a File object for the file
+ $file = new File($filePath);
+ if (!$file->exists()) {
+ $this->Flash->error(__('The requested file does not exist!'));
+ return $this->redirect($this->referer());
+ }
+
+ $response = $this->response->withFile(
+ $file->path,
+ ['download' => true, 'name' => $attachment->basename]
+ );
+
+ return $response;
+ }
}
diff --git a/src/Controller/Manager/SadrsController.php b/src/Controller/Manager/SadrsController.php
index 71c24f57a3..431c3207ca 100755
--- a/src/Controller/Manager/SadrsController.php
+++ b/src/Controller/Manager/SadrsController.php
@@ -15,7 +15,7 @@
class SadrsController extends AppController
{
-
+
public $page_options = array('25' => '25', '50' => '50', '100' => '100');
/**
* Index method
@@ -24,26 +24,26 @@ class SadrsController extends AppController
*/
public function index()
- {
+ {
$criteria = array();
$criteria['Sadrs.deleted'] = false;
$criteria['Sadrs.archived'] = false;
$criteria['Sadrs.submitted'] = 2;
$criteria['Sadrs.copied !='] = '1';
$limit = $this->request->getQuery('pages', 1000); // Default to 10 if 'pages' is not set
-
+
$this->paginate = [
'contain' => array('Users', 'Pqmps', 'Medications', 'Counties', 'SubCounties', 'Designations'),
'conditions' => $criteria
- ];
+ ];
$this->paginate = [
'contain' => ['Users', 'Pqmps', 'Medications', 'Counties', 'SubCounties', 'Designations'],
'conditions' => $criteria,
'order' => ['Sadrs.created' => 'DESC'],
- 'limit'=>$limit
- ];
+ 'limit' => $limit
+ ];
$sadrs = $this->paginate($this->Sadrs->find('search', ['search' => $this->request->getQuery()]));
-
+
$this->set('sadrs', $sadrs);
$this->set('page_options', $this->page_options);
}
@@ -56,12 +56,67 @@ public function index()
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
+ public function download($id = null)
+ {
+ // Retrieve the Sadr record with all related data
+ $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;
+ // Set the Sadr data to be used in the template
+ $this->set(compact('sadr'));
+
+ // Define the filename for download
+ $filename = 'SADR_' . $sadr['id'] . '.xml';
+
+ // Render the template and set the response for download
+ $this->viewBuilder()->enableAutoLayout(false); // Disable the layout
+ $this->response = $this->response
+ ->withType('xml') // Set the response content type to XML
+ ->withDownload($filename); // Force the file download
+
+ return $this->render('download');
+ // $filename = 'SADR_' . $sadr['id'] . '.xml';
+ // $sadr = json_encode($sadr);
+
+ // // Set the response headers for file download
+ // $response = $this->response
+ // ->withType('xml') // Set the response content type to XML
+ // ->withStringBody($sadr) // Set the XML content as the body
+ // ->withDownload($filename); // Force the file download
+
+ // return $response;
+ }
+
+
+
public function view($id = null)
{
$sadr = $this->Sadrs->get($id, [
- 'contain' => ['Users', 'Pqmps', 'ExternalComment'=>['Attachments'], 'Medications', 'Counties', 'Attachments', 'SubCounties', 'Designations', 'SadrDescriptions', 'SadrFollowups', 'SadrListOfDrugs', 'SadrListOfMedicines', 'SadrReaction'],
+ 'contain' => ['Users', 'Pqmps', 'ExternalComment' => ['Attachments'], 'Medications', 'Counties', 'Attachments', 'SubCounties', 'Designations', 'SadrDescriptions', 'SadrFollowups', 'SadrListOfDrugs' => [
+ 'Routes',
+ 'Frequencies',
+ 'Doses'
+ ], 'SadrListOfMedicines', 'SadrReaction'],
]);
+ if ($this->request->getParam('_ext') === 'pdf') {
+ // debug($sadr);
+ // exit;
+ $reference_no = $sadr['reference_no'];
+ // debug($reference_no);
+ $reference_no = str_replace('/', '_', $reference_no);
+ // debug($reference_no);
+ // exit;
+ $this->viewBuilder()->enableAutoLayout(false);
+ $this->viewBuilder()->setClassName('CakePdf.Pdf');
+ $this->viewBuilder()->setOptions([
+ 'pdfConfig' => [
+ 'filename' => $reference_no . '' . '.pdf'
+ ]
+ ]);
+ }
$this->set(compact('sadr'));
}
diff --git a/src/Controller/Reporter/SadrsController.php b/src/Controller/Reporter/SadrsController.php
index a668668225..377ff6b055 100755
--- a/src/Controller/Reporter/SadrsController.php
+++ b/src/Controller/Reporter/SadrsController.php
@@ -56,7 +56,9 @@ public function index()
public function view($id = null)
{
$sadr = $this->Sadrs->get($id, [
- 'contain' => ['Users', 'Pqmps', 'ExternalComment' => ['Attachments'], 'Medications', 'Counties', 'Attachments', 'SubCounties', 'Designations', 'SadrDescriptions', 'SadrFollowups', 'SadrListOfDrugs', 'SadrListOfMedicines', 'SadrReaction'],
+ 'contain' => ['Users', 'Pqmps', 'ExternalComment' => ['Attachments'], 'Medications', 'Counties', 'Attachments', 'SubCounties', 'Designations', 'SadrDescriptions', 'SadrFollowups', 'SadrListOfDrugs'=>[
+ 'Routes','Frequencies','Doses'
+ ], 'SadrListOfMedicines', 'SadrReaction'],
]);
// debug($sadr);
// exit;
diff --git a/src/Model/Table/SadrListOfDrugsTable.php b/src/Model/Table/SadrListOfDrugsTable.php
index 35d8d0dda2..f1af96972a 100755
--- a/src/Model/Table/SadrListOfDrugsTable.php
+++ b/src/Model/Table/SadrListOfDrugsTable.php
@@ -78,76 +78,33 @@ public function initialize(array $config): void
*/
public function validationDefault(Validator $validator): Validator
{
- $validator
- ->integer('sadr_id')
- ->allowEmptyString('sadr_id');
-
- $validator
- ->integer('sadr_followup_id')
- ->allowEmptyString('sadr_followup_id');
-
- $validator
- ->integer('dose_id')
- ->allowEmptyString('dose_id');
-
- $validator
- ->integer('route_id')
- ->allowEmptyString('route_id');
$validator
- ->integer('frequency_id')
- ->allowEmptyString('frequency_id');
+ ->notEmptyString('drug_name', 'Please provide drug name');
$validator
- ->scalar('frequency_id_other')
- ->maxLength('frequency_id_other', 255)
- ->allowEmptyString('frequency_id_other');
+ ->notEmptyString('brand_name', 'Please specify the brand name of the suspected drug');
$validator
- ->scalar('drug_name')
- ->maxLength('drug_name', 255)
- ->allowEmptyString('drug_name');
+ ->notEmptyString('dose', 'Please specify the dosage')
+ ->numeric('dose', 'dose must be a numeric value.'); // Enforce numeric validation if input is provided
$validator
- ->scalar('brand_name')
- ->maxLength('brand_name', 255)
- ->allowEmptyString('brand_name');
+ ->notEmptyString('dose_id', 'Please specify the dose units');
$validator
- ->scalar('batch_no')
- ->maxLength('batch_no', 255)
- ->allowEmptyString('batch_no');
+ ->notEmptyString('route_id', 'Please specify the route');
$validator
- ->scalar('manufacturer')
- ->maxLength('manufacturer', 255)
- ->allowEmptyString('manufacturer');
+ ->notEmptyString('frequency_id', 'Please specify the frequency');
$validator
- ->scalar('dose')
- ->maxLength('dose', 100)
- ->allowEmptyString('dose');
+ ->notEmptyString('start_date', 'Please specify the start date for the suspected drug');
- $validator
- ->date('start_date')
- ->allowEmptyDate('start_date');
-
- $validator
- ->date('stop_date')
- ->allowEmptyDate('stop_date');
-
- $validator
- ->scalar('indication')
- ->maxLength('indication', 100)
- ->allowEmptyString('indication');
-
- $validator
- ->scalar('suspected_drug')
- ->maxLength('suspected_drug', 100)
- ->allowEmptyString('suspected_drug');
return $validator;
}
+
/**
* Returns a rules checker object that will be used for validating
diff --git a/src/Model/Table/SadrsTable.php b/src/Model/Table/SadrsTable.php
index 68f6afd7b8..e9cd7523eb 100755
--- a/src/Model/Table/SadrsTable.php
+++ b/src/Model/Table/SadrsTable.php
@@ -207,8 +207,6 @@ public function initialize(array $config): void
public function validationDefault(Validator $validator): Validator
{
-
-
// Set validation rules here *****
$validator
@@ -283,8 +281,41 @@ public function validationDefault(Validator $validator): Validator
return true; // If no date_of_birth, skip validation
},
'message' => 'Date of onset of reaction must be on or after date of birth.',
+ ])
+ ->add('date_of_onset_of_reaction', 'dateAfterStartDates', [
+ 'rule' => function ($value, $context) {
+ // Check if sadr_list_of_drugs is present and loop through it
+ if (!empty($context['data']['sadr_list_of_drugs'])) {
+ foreach ($context['data']['sadr_list_of_drugs'] as $drug) {
+ // Check if the drug is suspected and has a start_date
+ if (!empty($drug['start_date']) && !empty($drug['suspected_drug']) && $drug['suspected_drug'] == 1) {
+ // Compare the date_of_onset_of_reaction with start_date
+ if (strtotime($value) <= strtotime($drug['start_date'])) {
+ return false; // Validation fails if date is not after start_date
+ }
+ }
+ }
+ }
+ return true; // Validation passes if all checks are satisfied
+ },
+ 'message' => 'The date of onset of the reaction must come after the start date of the suspected drug(s).',
+ ]);
+
+ $validator ->add('sadr_list_of_drugs', 'atLeastOneSuspectedDrug', [
+ 'rule' => function ($value, $context) {
+ // Check if sadr_list_of_drugs is present and loop through it
+ if (!empty($context['data']['sadr_list_of_drugs'])) {
+ foreach ($context['data']['sadr_list_of_drugs'] as $drug) {
+ // Check if at least one drug is suspected
+ if (!empty($drug['suspected_drug']) && $drug['suspected_drug'] == 1) {
+ return true; // Validation passes if at least one suspected drug is found
+ }
+ }
+ }
+ return false; // Validation fails if no suspected drugs are found
+ },
+ 'message' => 'At least one drug must be marked as suspected.',
]);
-
$validator
->scalar('description_of_reaction')
@@ -306,6 +337,8 @@ public function validationDefault(Validator $validator): Validator
$validator
->scalar('outcome')
->notEmptyString('outcome', 'Please specify outcome');
+
+
$validator
->scalar('reporter_name')
->notEmptyString('reporter_name', 'Please provide reporter name');
@@ -324,6 +357,9 @@ public function validationDefault(Validator $validator): Validator
->scalar('weight')
->allowEmptyString('weight') // Allow empty weight
->numeric('weight', 'Weight must be a numeric value.'); // Enforce numeric validation if input is provided
+
+
+
$validator
->scalar('height')
->allowEmptyString('height') // Allow empty height
diff --git a/templates/Manager/Sadrs/download.php b/templates/Manager/Sadrs/download.php
new file mode 100755
index 0000000000..ff14660443
--- /dev/null
+++ b/templates/Manager/Sadrs/download.php
@@ -0,0 +1,319 @@
+'; echo "\n"; ?>
+
+
(FOM001/HPT/VMS/SOP/001)
+REPORT TITLE: | ++ | REPORT ID: | +
+ + + |
+
+ The report is on:+Suspected adverse drug reaction +Suspected Therapeutic ineffectiveness +Suspected misuse, abuse and / or dependence on medicines +Off-label Use + |
+
+ Product category (Tick appropriate box)+Medicinal product +Herbal product +Cosmeceuticals +Others ++ |
+
NAME OF INSTITUTION: | ++ | COUNTY: | ++ |
ADDRESS: | ++ | SUB-COUNTY: | ++ |
INSTITUTION CODE: | ++ | Phone: | ++ |
PATIENT'S INITIALS: | +request->getSession()->read('Auth.User.user_type') != 'Public Health Program') echo $sadr['patient_name'] ?> | +WARD / CLINIC: | ++ |
IP/OP. NO.: | ++ | PATIENT'S ADDRESS: | +request->getSession()->read('Auth.User.user_type') != 'Public Health Program') echo $sadr['patient_address'] ?> | +
DATE OF BIRTH: | ++ | GENDER: | ++ |
AGE GROUP: | ++ | PREGNANCY STATUS: | ++ |
ANY KNOWN ALLERGY: | + |
+ WEIGHT (kg): | ++ |
If yes specify: | ++ | HEIGHT (cm): | ++ |
DIAGNOSIS: | ++ | ||
REACTION: | ++ | ||
+ |
+ " . $reaction['reaction'] . " "; + endforeach; ?> + + |
+ ||
DATE OF ONSET OF REACTION: | ++ | + | + |
BRIEF DESCRIPTION OF REACTION: | ++ + | +||
MEDICAL HISTORY: | ++ |
+ List all medicines being currently used by the patient including OTC, and herbal products (* Tick the suspected medicine) + | +||||||||||
---|---|---|---|---|---|---|---|---|---|---|
INN/GENERIC NAME | +BRAND NAME * | +BATCH/ LOT NO. | +MANUFACTURER | ++ | ROUTE AND FREQUENCY | +DATE STARTED | +DATE STOPPED | +INDICATION | ++ + | +|
+ | + | + | + | + | + | + + |
+ + | + | + | ✓"; + } ?> | +
+ Past medication history (List all medicines used in the last 3 months including OTC, herbals, if pregnant indicate medicines used in the 1st trimester) + | +|||||||||
---|---|---|---|---|---|---|---|---|---|
INN/GENERIC NAME | +BRAND NAME | +BATCH/ LOT NO. | +MANUFACTURER | ++ | ROUTE AND FREQUENCY | +DATE STARTED | +DATE STOPPED | +INDICATION | +|
+ | + | + | + | + | + | + + |
+ + | + | + |
+ Dechallenge/Rechallenge+ |
+
+ Grading of the reaction /event+ |
+ ||
Did the reaction resolve after the drug was stopped or when the dose was reduced? | ++ | Severity of reaction: | ++ |
Did the reaction reappear after the drug was reintroduced? | ++ | Is the reaction serious: | ++ |
Any lab investigations and results: | ++ | Criteria/reason for seriousness: | ++ |
Outcome: | ++ | Action taken: | ++ |
ANY OTHER COMMENT: | ++ |
# | ++ | + |
---|---|---|
+ | + + | ++ |
NAME OF PERSON REPORTING: | ++ | E-MAIL ADDRESS: | ++ |
DESIGNATION: | ++ | PHONE NO. | ++ |
Date: | ++ | + | + |
Is the person submitting different from reporter? | ++ |
NAME OF PERSON REPORTING: | ++ | E-MAIL ADDRESS: | ++ |
DESIGNATION: | ++ | PHONE NO. | ++ |
Date: | ++ | + | + |