I am creating a website of Hospital Management system. I have a Patients controller and a Medical Report controller. Every patient has an action of "View Report". When the user clicks on view report, he/she should be directed to the Medical Report and only that field pertaining to the Patient_id in Patients Controller should be displayed. How do I go about it?
Patients table:
<?php
namespace App\Model\Table;
use Search\Manager;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
class PatientsTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->table('patients');
$this->displayField('Patient_ID');
$this->primaryKey('Patient_ID');
$this->addBehavior('Search.Search');
$this->searchManager()
->value('Patient_ID');
}
public function validationDefault(Validator $validator)
{
$validator
->allowEmpty('Patient_ID', 'create');
$validator
->requirePresence('Name', 'create')
->notEmpty('Name');
$validator
->requirePresence('Address', 'create')
->notEmpty('Address');
$validator
->date('DOB')
->requirePresence('DOB', 'create')
->notEmpty('DOB');
$validator
->allowEmpty('Contact');
$validator
->requirePresence('Gender', 'create')
->notEmpty('Gender');
$validator
->allowEmpty('Blood_Group');
return $validator;
}
}
MedicalReport table:
<?php
namespace App\Model\Table;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
class MedicalReportTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->table('medical_report');
$this->displayField('Report_No');
$this->primaryKey('Report_No');
}
public function validationDefault(Validator $validator)
{
$validator
->requirePresence('Patient_ID', 'create')
->notEmpty('Patient_ID');
$validator
->requirePresence('Report_No', 'create');
$validator
->date('R_date')
->requirePresence('R_date', 'create')
->notEmpty('R_date');
$validator
->date('C_date')
->requirePresence('C_date');
$validator
->requirePresence('Room_No');
$validator
->allowEmpty('Diet');
$validator
->numeric('Payment')
->requirePresence('Payment');
return $validator;
}
}
You can use CakePHP's HtmlHelper to create an URL to view the Medical Report like so:
This would create something like:
<a href="/medical-reports/view/123" class="button" target="_blank">View Report</a>
Read more about the
HtmlHelper::link();
MedicalReportsController.php
In your controller you can create the
view()
function that defines the code for the action.The
set()
function sends data to the View from the Controller.