updated streamline-setup v2

This commit is contained in:
2025-01-15 08:53:49 -08:00
committed by alec.turner
parent a2ce9248f0
commit 4b569f81b0
20228 changed files with 2932048 additions and 63204 deletions
@@ -43,6 +43,13 @@ use Streamline\Models\User;
use Streamline\Models\Consultation;
use Streamline\Models\OrderedSundry;
use Streamline\Models\Services;
use Streamline\Models\WardInpatientDetailedNote;
use Streamline\Models\GeneralSettings;
use Streamline\Models\DischargeMortalityRisk;
use Barryvdh\DomPDF\Facade\Pdf as DomPDF;
class PatientEpisodeController extends Controller
{
@@ -71,7 +78,7 @@ class PatientEpisodeController extends Controller
$categories = DB::table('patient_categories')->where('available', 1)->pluck("name", "id");
$marital_statuses = DB::table('marital_statuses')->pluck("name", "id");
$diagnoses = DB::table('diagnoses')->where('available', 1)->pluck("name", "id");
$clinics = DB::table('clinics')->pluck("name", "id")->prepend('- select -', '');;
$clinics = DB::table('clinics')->pluck("name", "id")->prepend('- select -', '');
$relationships = DB::table('family_relations')->pluck('name', 'id');
$occupations = DB::table('occupations')->pluck('name', 'id');
$patient_categories = DB::table('patient_categories')->where('available', 1)->pluck('name', 'id');
@@ -86,7 +93,7 @@ class PatientEpisodeController extends Controller
$known_patient_alerts = Alert::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
$drug_categories_array = DB::table('drug_categories')->pluck('name', 'id');
//$special_clinics = DB::table('clinics')->where('slug', '!=', 'general')->pluck("name", "id")->prepend('GENERAL OPD', 'general_opd')->prepend('- select -', '');
$special_clinics = DB::table('clinics')->where('available', 1)->whereNull('deleted_at')->pluck("name", "id")->prepend('- select -', '');
$special_clinics = DB::table('clinics')->where('available', 1)->whereNull('deleted_at')->orderBy('name', 'asc')->pluck("name", "id")->prepend('- select -', '');
$wards = DB::table('wards')->where('available', 1)->whereNull('deleted_at')->pluck("name", "id")->prepend('- select -', '');
$users_collection = DB::table('users')->orderBy("first_name", "asc")->select("id")->get()->toArray();
$users_array = [];
@@ -209,11 +216,8 @@ class PatientEpisodeController extends Controller
return redirect('/patient_episodes/');
}
} catch (QueryException $e) {
$errorCode = $e->errorInfo[1];
if ($errorCode == 1062) { //error code for duplicate entry to a unique field
flash("This episode already exists!")->error();
return back()->withInput();
}
flash("An error occurred")->error();
return back()->withInput();
}
}
@@ -238,7 +242,6 @@ class PatientEpisodeController extends Controller
*/
public function route_patient_episode(Request $request)
{
//set session for episode_id
session()->put('episode_id', $request->episode_id);
$is_patient_allowed_to_do_consultation = $this->is_patient_allowed_to_have_consultation(session()->get('patient_id'), $request->episode_id);
@@ -315,7 +318,7 @@ class PatientEpisodeController extends Controller
case 'base_refraction_exam':
return redirect('/eye_clinic/base_exam_refraction');
case 'eye_glasses':
return redirect('/eye_glasses/order');
return redirect('/opticals/order');
case 'treatment_sheet':
session()->put(['treatment_sheet_route' => 'patient_home']);
return redirect('treatment_sheet/view');
@@ -447,7 +450,7 @@ class PatientEpisodeController extends Controller
$service_order->updated_by = auth()->user()->id;
$service_order->save();
$episode->consultation_id = $consultation->id;
$episode->consultation_id = $consultation_record->id;
}
}
@@ -520,11 +523,8 @@ class PatientEpisodeController extends Controller
return redirect('/patient_episodes/');
} catch (QueryException $e) {
$errorCode = $e->errorInfo[1];
if ($errorCode == 1062) { //error code for duplicate entry to a unique field
flash("This episode already exists!")->error();
return back()->withInput();
}
flash("An error occurred")->error();
return back()->withInput();
}
}
@@ -560,11 +560,8 @@ class PatientEpisodeController extends Controller
flash("Patient admitted in " . $ward_name)->success();
return redirect('/patient_episodes/');
} catch (QueryException $e) {
$errorCode = $e->errorInfo[1];
if ($errorCode == 1062) { //error code for duplicate entry to a unique field
flash("This episode already exists!")->error();
return back()->withInput();
}
flash("An error occurred")->error();
return back()->withInput();
}
}
@@ -749,11 +746,8 @@ class PatientEpisodeController extends Controller
return redirect('/patient_episodes/');
} catch (QueryException $e) {
$errorCode = $e->errorInfo[1];
if ($errorCode == 1062) { //error code for duplicate entry to a unique field
flash("This episode already exists!")->error();
return back()->withInput();
}
flash("An error occurred")->error();
return back()->withInput();
}
}
@@ -775,17 +769,18 @@ class PatientEpisodeController extends Controller
flash("Episode has started")->success();
return redirect('/investigations/investigations_review');
} catch (QueryException $e) {
$errorCode = $e->errorInfo[1];
if ($errorCode == 1062) { //error code for duplicate entry to a unique field
flash("This episode already exists!")->error();
return back()->withInput();
}
flash("An error occurred")->error();
return back()->withInput();
}
}
public function episode_summary($episode_id)
{
$patient_id = session()->get('patient_id');
$general_settings = json_decode(GeneralSettings::find(1)->data, true);
$episode_summary_content_setting = $general_settings['episode_summary_content'] ?? '';
if(is_eye_module_enabled() && is_patient_in_eye_clinic($episode_id)) {
$main_exam = EyeClinicMainExam::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
@@ -813,10 +808,35 @@ class PatientEpisodeController extends Controller
$sundries_results = Sundry::select('id', 'name')->get();
/* Patient File : It should show Diagnosis, Prescriptions, Lab results, Procedures */
$consultation = Consultation::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
$treatments = Treatment::where(["patient_id" => $patient_id, "episode_id" => $episode_id])->get(); //fetch treatment the way Douglas fetches it in printing the treatment receipt
$ordered_procedures = OrderedProcedure::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
$ordered_sundries = OrderedSundry::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
$ordered_services = OrderedService::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
$treatments = null;
if (is_array($episode_summary_content_setting) && in_array(10, $episode_summary_content_setting ?? '') ){
$treatments = Treatment::where(["patient_id" => $patient_id, "episode_id" => $episode_id])->get();
}
$ordered_procedures = null;
if (is_array($episode_summary_content_setting) && in_array(4, $episode_summary_content_setting ?? '') ){
$ordered_procedures = OrderedProcedure::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
}
$ordered_sundries = null;
if (is_array($episode_summary_content_setting) && in_array(8, $episode_summary_content_setting ?? '') ){
$ordered_sundries = OrderedSundry::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
}
$ordered_services = null;
if (is_array($episode_summary_content_setting) && in_array(6, $episode_summary_content_setting ?? '') ){
$ordered_services = OrderedService::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
}
$inpatient_infos = InpatientInfo::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
$antenatal_data = DB::table('ante_natal_clinic_followups')->where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
@@ -833,67 +853,47 @@ class PatientEpisodeController extends Controller
//triage details
$triage = null;
if ($episode && $episode->triage_id) {
$triage = \Streamline\Models\Triage::where(['id' => $episode->triage_id])->first();
}
if (is_array($episode_summary_content_setting) && in_array(3, $episode_summary_content_setting ?? '') ){
if ($episode && $episode->triage_id) {
$triage = \Streamline\Models\Triage::where(['id' => $episode->triage_id])->first();
}
}
// get all symptoms
$symptoms = DB::table('symptoms')->where('available', 1)->pluck("name", "id");
$symptoms = '';
if (is_array($episode_summary_content_setting) && in_array(5, $episode_summary_content_setting ?? '') ){
$symptoms = DB::table('symptoms')->where('available', 1)->pluck("name", "id");
}
foreach ($ordered_investigations as $investigation) {
$investigation_ids = explode(",", $investigation->investigation_id);
$inpatient_status = explode(",", $investigation->for_inpatient);
// investigations setting check
if (is_array($episode_summary_content_setting) && in_array(2, $episode_summary_content_setting ?? '') ){
foreach ($ordered_investigations as $investigation) {
$investigation_ids = explode(",", $investigation->investigation_id);
$inpatient_status = explode(",", $investigation->for_inpatient);
// check if results are available for this investigation
if (in_array($investigation->id, $investigation_results_order_ids)) {
// get the key if available
$key = array_search($investigation->id, $investigation_results_order_ids);
// check if results are available for this investigation
if (in_array($investigation->id, $investigation_results_order_ids)) {
// get the key if available
$key = array_search($investigation->id, $investigation_results_order_ids);
// get the results object
$results = InvestigationResults::find($key);
// get the results object
$results = InvestigationResults::find($key);
// exclude obstetric u/s results
if ($results->result_type != "Ultrasound_Obstetric") {
$investigation_results = explode(",", $results->value);
$investigation_per_valid = explode(",", $results->per_investigation);
$investigation_comments = explode(",", $results->comment);
// exclude obstetric u/s results
if ($results->result_type != "Ultrasound_Obstetric") {
$investigation_results = explode(",", $results->value);
$investigation_per_valid = explode(",", $results->per_investigation);
$investigation_comments = explode(",", $results->comment);
if ($results->all_authenticated == 1) {
for ($i = 0; $i < count($inpatient_status); $i++) {
if ($inpatient_status[$i] == 0) {
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$opd_investigations['name'][] = $result->name;
$opd_investigations['value'][] = $investigation_results[$i];
$opd_investigations['comment'][] = $investigation_comments[$i];
if($result->range_type == 1) {
$opd_investigations['normal_ranges'][] = get_dynamic_normal_range($result->id, get_patient_age_group($patient_id), get_name($patient_id, 'id', 'gender', 'patients'));
} else {
$opd_investigations['normal_ranges'][] = $result->normal_ranges;
}
$opd_investigations['type'][] = $result->type;
}
} else {
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$ward_investigations['name'][] = $result->name;
$ward_investigations['value'][] = $investigation_results[$i];
$ward_investigations['comment'][] = $investigation_comments[$i];
$ward_investigations['type'][] = $result->type;
}
}
}
} else {
for ($i = 0; $i < count($inpatient_status); $i++) {
if ($investigation_per_valid[$i] == 1) {
// this investigation is authenticated
if ($results->all_authenticated == 1) {
for ($i = 0; $i < count($inpatient_status); $i++) {
if ($inpatient_status[$i] == 0) {
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$opd_investigations['name'][] = $result->name;
$opd_investigations['value'][] = $investigation_results[$i];
$opd_investigations['comment'][] = $investigation_comments[$i];
if($result->range_type == 1) {
$opd_investigations['normal_ranges'][] = get_dynamic_normal_range($result->id, get_patient_age_group($patient_id), get_name($patient_id, 'id', 'gender', 'patients'));
@@ -901,7 +901,6 @@ class PatientEpisodeController extends Controller
$opd_investigations['normal_ranges'][] = $result->normal_ranges;
}
$opd_investigations['comment'][] = $investigation_comments[$i];
$opd_investigations['type'][] = $result->type;
}
} else {
@@ -913,69 +912,117 @@ class PatientEpisodeController extends Controller
$ward_investigations['type'][] = $result->type;
}
}
} else {
if ($inpatient_status[$i] == 0) {
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$opd_investigations['name'][] = $result->name;
$opd_investigations['value'][] = "Pending";
}
} else {
for ($i = 0; $i < count($inpatient_status); $i++) {
if ($investigation_per_valid[$i] == 1) {
// this investigation is authenticated
if ($inpatient_status[$i] == 0) {
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$opd_investigations['name'][] = $result->name;
$opd_investigations['value'][] = $investigation_results[$i];
if($result->range_type == 1) {
$opd_investigations['normal_ranges'][] = get_dynamic_normal_range($result->id, get_patient_age_group($patient_id), get_name($patient_id, 'id', 'gender', 'patients'));
} else {
$opd_investigations['normal_ranges'][] = $result->normal_ranges;
if($result->range_type == 1) {
$opd_investigations['normal_ranges'][] = get_dynamic_normal_range($result->id, get_patient_age_group($patient_id), get_name($patient_id, 'id', 'gender', 'patients'));
} else {
$opd_investigations['normal_ranges'][] = $result->normal_ranges;
}
$opd_investigations['comment'][] = $investigation_comments[$i];
$opd_investigations['type'][] = $result->type;
}
} else {
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$ward_investigations['name'][] = $result->name;
$ward_investigations['value'][] = $investigation_results[$i];
$ward_investigations['comment'][] = $investigation_comments[$i];
$ward_investigations['type'][] = $result->type;
}
$opd_investigations['comment'][] = "Pending";
}
} else {
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$ward_investigations['name'][] = $result->name;
$ward_investigations['value'][] = "Pending";
$ward_investigations['comment'][] = "Pending";
if ($inpatient_status[$i] == 0) {
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$opd_investigations['name'][] = $result->name;
$opd_investigations['value'][] = "Pending";
if($result->range_type == 1) {
$opd_investigations['normal_ranges'][] = get_dynamic_normal_range($result->id, get_patient_age_group($patient_id), get_name($patient_id, 'id', 'gender', 'patients'));
} else {
$opd_investigations['normal_ranges'][] = $result->normal_ranges;
}
$opd_investigations['comment'][] = "Pending";
}
} else {
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$ward_investigations['name'][] = $result->name;
$ward_investigations['value'][] = "Pending";
$ward_investigations['comment'][] = "Pending";
}
}
}
}
}
}
}
} else {
for ($i = 0; $i < count($inpatient_status); $i++) {
if ($inpatient_status[$i] == 0) {
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$opd_investigations['name'][] = $result->name;
$opd_investigations['value'][] = "Pending";
} else {
for ($i = 0; $i < count($inpatient_status); $i++) {
if ($inpatient_status[$i] == 0) {
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$opd_investigations['name'][] = $result->name;
$opd_investigations['value'][] = "Pending";
if($result->range_type == 1) {
$opd_investigations['normal_ranges'][] = get_dynamic_normal_range($result->id, get_patient_age_group($patient_id), get_name($patient_id, 'id', 'gender', 'patients'));
} else {
$opd_investigations['normal_ranges'][] = $result->normal_ranges;
if($result->range_type == 1) {
$opd_investigations['normal_ranges'][] = get_dynamic_normal_range($result->id, get_patient_age_group($patient_id), get_name($patient_id, 'id', 'gender', 'patients'));
} else {
$opd_investigations['normal_ranges'][] = $result->normal_ranges;
}
$opd_investigations['comment'][] = "Pending";
}
} else {
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$ward_investigations['name'][] = $result->name;
$ward_investigations['value'][] = "Pending";
$ward_investigations['comment'][] = "Pending";
}
$opd_investigations['comment'][] = "Pending";
}
} else {
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$ward_investigations['name'][] = $result->name;
$ward_investigations['value'][] = "Pending";
$ward_investigations['comment'][] = "Pending";
}
}
}
}
}
}
$discharge_mortality_risk = null;
$priority_signs_records = null;
$emergency_signs = null;
$emergencySigns = null;
if(between($years, 0, 12)) {
$priority_signs_records = PrioritySign::where('triage_id', $episode->triage_id)->first();
if (is_array($episode_summary_content_setting) && in_array(9, $episode_summary_content_setting ?? '') ){
$priority_signs_records = PrioritySign::where('triage_id', $episode->triage_id)->first();
}
if ($priority_signs_records) {
$priority_signs = unserialize($priority_signs_records->signs);
}
$emergency_signs = EmergencySign::where('triage_id', $episode->triage_id)->first();
if (is_array($episode_summary_content_setting) && in_array(11, $episode_summary_content_setting ?? '') ){
$emergency_signs = EmergencySign::where('triage_id', $episode->triage_id)->first();
}
if (!empty($emergency_signs)) {
$airway = unserialize($emergency_signs->airway);
$circulation = unserialize($emergency_signs->circulation);
@@ -983,10 +1030,22 @@ class PatientEpisodeController extends Controller
$dehydration = unserialize($emergency_signs->dehydration);
$emergencySigns= array_merge($airway,$circulation, $dehydration,$neurological);
foreach($emergencySigns as $key => $sign) if($sign == 'Yes') $emergent_signs[] = $key;
}
}
if (is_array($episode_summary_content_setting) && in_array(13, $episode_summary_content_setting ?? '') ){
$discharge_mortality_risk = DischargeMortalityRisk::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
}
}
$cons_notes = [];
if (is_array($episode_summary_content_setting) && in_array(12, $episode_summary_content_setting ?? '') ){
$cons_notes = WardInpatientDetailedNote::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'ward_id' => 0])->latest()->get(['investigation_and_management_plan_comments', 'clinic_examination_comments', 'history_comments', 'created_by','created_at']);
}
$data = [
'main_exam' => $main_exam,
@@ -1016,9 +1075,15 @@ class PatientEpisodeController extends Controller
'triage' =>$triage,
'priority_signs' => $priority_signs,
'emergent_signs'=> $emergent_signs,
'years'=>$years
'discharge_mortality_risk' => $discharge_mortality_risk,
'cons_notes' => $cons_notes,
'years'=>$years,
'episode_summary_content_setting' => $episode_summary_content_setting,
];
// return view('patients::patient_episodes/episode_summary', $data);
$pdf = SnappyPDF::loadView('patients::patient_episodes/episode_summary', $data)
->setOrientation('portrait')
->setOption('margin-bottom', 7)
@@ -1198,16 +1263,9 @@ class PatientEpisodeController extends Controller
return redirect('/patient_episodes/');
}
} catch (QueryException $e) {
$errorCode = $e->errorInfo[1];
if ($errorCode == 1062) { //error code for duplicate entry to a unique field
flash("This episode already exists!")->error();
return back()->withInput();
}
flash("An error occurred")->error();
return back()->withInput();
}
/*================= end of creation of new episode on starting an appointment =================*/
flash("Patient follow up completed successfully")->success();
return redirect('/patient_episodes/set_patient_id/' . $patient_id);
} else {
flash("An error occurred!")->error();
return back()->withInput();
@@ -1241,7 +1299,7 @@ class PatientEpisodeController extends Controller
$diagnoses = DB::table('diagnoses')->where('available', 1)->pluck("name", "id");
$clinics = DB::table('clinics')->pluck("name", "id")->prepend('- select -', '');
$special_clinics = DB::table('clinics')->where('available', 1)->whereNull('deleted_at')->pluck("name", "id")->prepend('- select -', '');
$special_clinics = DB::table('clinics')->where('available', 1)->whereNull('deleted_at')->orderBy('name', 'asc')->pluck("name", "id")->prepend('- select -', '');
$wards = DB::table('wards')->where('available', 1)->pluck("name", "id")->prepend('- select -', '');
$users_collection = DB::table('users')->orderBy("first_name", "asc")->select("id")->get()->toArray();
$users_array = [];
@@ -1595,7 +1653,9 @@ class PatientEpisodeController extends Controller
$ordered_sundry->episode_id = $episode_id_to_keep;
$ordered_sundry->update();
}
$tables = ['ward_inpatient_sheet_nurse_comments', 'ward_inpatient_detailed_notes', 'ward_dispensing_per_charts', 'patient_documents', 'patient_one_off_discounts', 'triage_nutrition', 'triage_news', 'surgeries', 'sundries_deposits', 'smart_triage', 'patient_refunds', 'patient_account_consumptions', 'patient_appointments', 'phone_followup_patients', 'point_of_sale_records', 'procedure_deposits', 'cancel_patient_transactions', 'central_billing_deposits', 'chronic_patients', 'chi_deposits', 'debtors', 'debt_plan', 'dependants_consumptions', 'family_account_consumptions', 'inpatient_attendant_passes', 'inpatient_ward_discounts', 'inpatient_sheet_audits', 'maternity_delivery_records', 'maternity_inpatients', 'mental_health_consultation', 'ordered_investigations', 'ordered_procedures'];
// TODO Refactor this merge to be in a separate controller and remove repeated table throughs by using one-to-many relationships
$tables = ['ward_inpatient_sheet_nurse_comments', 'ward_inpatient_detailed_notes', 'patient_documents', 'patient_one_off_discounts', 'triage_nutrition', 'triage_news', 'surgeries', 'sundries_deposits', 'smart_triage', 'patient_refunds', 'patient_account_consumptions', 'patient_appointments', 'phone_followup_patients', 'point_of_sale_records', 'procedure_deposits', 'cancel_patient_transactions', 'central_billing_deposits', 'chronic_patients', 'chi_deposits', 'debtors', 'debt_plan', 'dependants_consumptions', 'family_account_consumptions', 'inpatient_attendant_passes', 'inpatient_ward_discounts', 'inpatient_sheet_audits', 'maternity_delivery_records', 'maternity_inpatients', 'mental_health_consultation', 'ordered_investigations', 'ordered_procedures'];
foreach ($tables as $table) {
$episodes = DB::table($table)->where('episode_id', $episode_id_to_delete)->get();
foreach ($episodes as $episode) DB::table($table)->where('id', $episode->id)->update(['episode_id' => $episode_id_to_keep]);
@@ -1616,12 +1676,15 @@ class PatientEpisodeController extends Controller
public function check_clinical_consultation_payment(Request $request)
{
$service_deposit = \Streamline\Models\ServiceDeposit::where('episode_id', $request->episode_id)->first();
if ($service_deposit) {
return "paid";
}
return "unpaid";
$is_patient_allowed_to_do_consultation = $this->is_patient_allowed_to_have_consultation($request->patient_id, $request->episode_id);
if ($is_patient_allowed_to_do_consultation) {
if($request->action == 'consultation_with_notes') session()->put('consultation_with_notes', 1);
else session()->put('consultation_with_notes', 0);
session()->put(['patient_id' => $request->patient_id]);
session()->put(['episode_id' => $request->episode_id]);
return response()->json('/consultation/route');
}
else return response()->json("unpaid");
}
public function is_patient_allowed_to_have_consultation($patient_id, $episode_id)