mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 10:41:32 +00:00
1747 lines
111 KiB
PHP
Executable File
1747 lines
111 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\Antenatal\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Streamline\Models\Alert;
|
|
use Streamline\Models\Allergy;
|
|
use Streamline\Models\Patient;
|
|
use Streamline\Models\PatientDocument;
|
|
use Streamline\Models\PatientEpisode;
|
|
use Streamline\Models\Triage;
|
|
use Streamline\Models\Treatment;
|
|
use Streamline\Models\OrderedProcedure;
|
|
use Streamline\Models\OrderedInvestigation;
|
|
use Streamline\Models\OrderedSundry;
|
|
use Streamline\Models\InvestigationResults;
|
|
use Streamline\Models\AnteNatalClinicRegistration;
|
|
use Streamline\Models\ObstetricHistory;
|
|
use Streamline\Models\AnteNatalClinicBloodTransfusion;
|
|
use Streamline\Models\AncVdrlHiv;
|
|
use Streamline\Models\AnteNatalClinicLie;
|
|
use Streamline\Models\AnteNatalClinicPresentation;
|
|
use Streamline\Models\AnteNatalClinicPosition;
|
|
use Streamline\Models\AnteNatalClinicEngagement;
|
|
use Streamline\Models\AnteNatalClinicFollowup;
|
|
use Streamline\Models\HeartRegularity;
|
|
use Streamline\Models\InpatientInfo;
|
|
use Streamline\Models\FamilyPlanningMethod;
|
|
use Streamline\Models\CaesarianSection;
|
|
use Streamline\Models\GenderViolence;
|
|
use Streamline\Models\UterusOperation;
|
|
use Streamline\Models\AntenatalMotherHistory;
|
|
use Streamline\Models\AncDeliveryPlan;
|
|
use Streamline\Models\Consultation;
|
|
use Streamline\Models\ChronicPatient;
|
|
use Streamline\Models\Drug;
|
|
use Streamline\Models\Surgery;
|
|
use Streamline\Models\Procedure;
|
|
use Carbon\Carbon;
|
|
use Streamline\Models\Investigation;
|
|
use Barryvdh\Snappy\Facades\SnappyPdf;
|
|
use Streamline\Models\Clinic;
|
|
class AnteNatalClinicController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
}
|
|
public static $obstetric_outcomes = ['' => "-- Select--", '1' => "Fresh SB", '2' => "Live Multiple", '3' => "Live Singleton", '4' => "Mascerated SB", '5' => "Spontaneous Abortion"];
|
|
public static $child_immunisation_status = ['' => "-- Select--", '1' => "Not Started", '2' => "Ongoing", '3' => "Completed"];
|
|
public static $menses_amount = ['' => "-- Select--", '1' => "Heavy", '2' => "Normal", '3' => "Completed"];
|
|
public static $family_history = ['1' => "Diabetes", '2' => "Sickel cell", '3' => "Hypertension", '4' => "Twins", '5' => "Others"];
|
|
public static $fractures = ['1' => "Pelvis", '2' => "Spine", '3' => "Femur"];
|
|
public static $obs_gyn = ['1' => "D & C", '2' => "Ectopic pregnancy", '3' => "PPH", '4' => "Retained Placenta"];
|
|
public static $medical_presentations = ['1' => "STIs", '2' => "Cardiac Disease", '3' => "Asthma", '4' => "Sickel cell", '5' => "Kidney disease", '6' => "Diabetes", '7' => "Hypertension", '8' => "Cardiac disease", '9' => "Epilepsy (Seizures)", '10' => "Tuberculosis"];
|
|
/**
|
|
* Display a listing of all patient pregnancies.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$episode_id = session()->get('episode_id');
|
|
$patient_id = session()->get('patient_id');
|
|
$patient = Patient::find($patient_id);
|
|
$categories = DB::table('patient_categories')->pluck("name", "id");
|
|
$marital_statuses = DB::table('marital_statuses')->pluck("name", "id");
|
|
$drug_categories = DB::table('drug_categories')->get();
|
|
$documents = PatientDocument::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$known_patient_allergies = Allergy::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$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');
|
|
|
|
$anc_registrations = AnteNatalClinicRegistration::where(['patient_id' => $patient_id])->orderBy('created_at', 'desc')->paginate(20);
|
|
return view('antenatal::ante_natal_clinic.index', compact('patient_id', 'patient', 'anc_registrations', 'categories', 'marital_statuses', 'drug_categories', 'documents', 'known_patient_allergies', 'known_patient_alerts', 'drug_categories_array'));
|
|
}
|
|
|
|
/**
|
|
* Display a listing of all ante natal visits.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index_visits()
|
|
{
|
|
$episode_id = session()->get('episode_id');
|
|
$patient_id = session()->get('patient_id');
|
|
$patient = Patient::find($patient_id);
|
|
$categories = DB::table('patient_categories')->pluck("name", "id");
|
|
$marital_statuses = DB::table('marital_statuses')->pluck("name", "id");
|
|
$drug_categories = DB::table('drug_categories')->get();
|
|
$documents = PatientDocument::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$known_patient_allergies = Allergy::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$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');
|
|
|
|
$anc_followup_records = AnteNatalClinicFollowup::where(['patient_id' => $patient_id])->orderBy('created_at', 'desc')->get()->groupBy('ante_natal_clinic_registration_id');
|
|
return view('antenatal::ante_natal_clinic.index_visits', compact('patient_id', 'patient', 'anc_followup_records', 'categories', 'marital_statuses', 'drug_categories', 'documents', 'known_patient_allergies', 'known_patient_alerts', 'drug_categories_array'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
$episode_id = session()->get('episode_id');
|
|
$patient_id = session()->get('patient_id');
|
|
$existing_anc_registration = AnteNatalClinicRegistration::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
|
|
//if an anc_registration of this episode exists, show the details page instead
|
|
if (!is_null($existing_anc_registration)) {
|
|
if ($existing_anc_registration->complete == 0) {
|
|
//
|
|
}
|
|
flash('Pregnancy record for this episode already exists')->error();
|
|
return redirect('ante_natal_clinic');
|
|
}
|
|
|
|
$patient = Patient::where(['id' => $patient_id])->first();
|
|
$previous_medical_conditions = AnteNatalMotherHistory::where([['patient_id', $patient_id],['episode_id', '<>', $episode_id]])->latest()->first(['medical_presentations']);
|
|
$last_five_pregnancies = AnteNatalClinicRegistration::where([['patient_id', $patient_id],['episode_id', '<>', $episode_id]])->latest()->take(5)->get();
|
|
$categories = DB::table('patient_categories')->pluck("name", "id");
|
|
$marital_statuses = DB::table('marital_statuses')->pluck("name", "id");
|
|
$diagnoses = DB::table('diagnoses')->whereNull('deleted_at')->orderBy('name', 'asc')->pluck("name", "id")->prepend('- select -', '');
|
|
$drug_categories = DB::table('drug_categories')->get();
|
|
$documents = PatientDocument::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$known_patient_allergies = Allergy::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$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');
|
|
$family_planning_methods = FamilyPlanningMethod::orderBy('name', 'asc')->pluck("name", "id")->prepend('- Select -', '');
|
|
$gender_based_violence = GenderViolence::orderBy('name', 'asc')->pluck("name", "id")->prepend('- Select -', '');
|
|
$uterus_operations = Procedure::where('hmis_category_inpatient', 10046)->orderBy('name', 'asc')->pluck("name", "id")->prepend('- Select -', '');
|
|
$caesarian_sections = CaesarianSection::orderBy('name', 'asc')->pluck("name", "id")->prepend('- Select -', '');
|
|
$triage_id = get_name($episode_id, "id", "triage_id", "patient_episodes");
|
|
$triage = Triage::where(['id' => $triage_id])->first();
|
|
// collect chronic drug ids as array
|
|
$chronic_drugs_array = ChronicPatient::where('patient_id', $patient_id)->whereNotNull('drug_id')->get(['drug_id']);
|
|
$chronic_results = Drug::whereIn('id', $chronic_drugs_array)->get();
|
|
//select treatment
|
|
$treatment = Treatment::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'tta' => 0])->first();
|
|
$blood_groups = DB::table('blood_groups')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
$referrals = DB::table('referral_hospitals')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
$accuracies = DB::table('ante_natal_clinic_accuracies')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
$anc_outcomes = DB::table('ante_natal_clinic_outcomes')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
$obstetric_history_details = ObstetricHistory::where(['patient_id' => $patient_id])->orderBy('obstetric_date', 'desc')->get();
|
|
$hiv_statuses = ['' => '-- Select --', '0' => 'Negative', '1' => 'Positive', '3' => 'Unknown'];
|
|
$previous_consultations = Consultation::leftJoin('patient_episodes as p','p.id','consultations.episode_id')->where([['consultations.patient_id', $patient_id],['episode_id', '<>',$episode_id]])->latest()->take(5)->get(['consultations.created_at','p.clinic_id', 'primary_diagnosis', 'other_diagnoses', 'consultations.created_by','episode_id','consultations.id']);
|
|
$previous_surgeries = Surgery::where([['patient_id', $patient_id],['episode_id', '<>',$episode_id]])->latest()->take(5)->get(['created_at', 'primary_diagnosis', 'other_diagnoses', 'created_by','episode_id','procedure_id']);
|
|
/* episode details */
|
|
$episode = PatientEpisode::find($episode_id);
|
|
/* get treatment */
|
|
$treatments = Treatment::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'tta' => 0])->get();
|
|
/* get ordered procedures */
|
|
$ordered_procedures = OrderedProcedure::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
//check for ordered investigations,procedures and treatment
|
|
$ordered_investigations = OrderedInvestigation::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
/* get ordered sundries */
|
|
$ordered_sundries = OrderedSundry::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
//check for authenticated investigations
|
|
$investigation_results = InvestigationResults::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
$diagnoses_all = DB::table('diagnoses')->select('id', 'prompts', 'reference_areas', 'reference_names')->get();
|
|
/* ======== added to cater for review episode =========*/
|
|
$is_episode_a_review = check_if_episode_is_a_followup($episode->id);
|
|
$parent_episode_treatments = [];
|
|
$parent_episode_ordered_procedures = [];
|
|
$parent_episode_ordered_investigations = [];
|
|
$parent_episode_ordered_sundries = [];
|
|
$parent_episode_investigation_results = [];
|
|
|
|
if ($is_episode_a_review) {
|
|
$parent_episode_details = PatientEpisode::find($episode->parent_episode_id);
|
|
|
|
$parent_episode_treatments = Treatment::where(['patient_id' => $patient_id, 'episode_id' => $parent_episode_details->id, 'tta' => 0])->get();
|
|
$parent_episode_ordered_procedures = OrderedProcedure::where(['patient_id' => $patient_id, 'episode_id' => $parent_episode_details->id])->get();
|
|
$parent_episode_ordered_investigations = OrderedInvestigation::where(['patient_id' => $patient_id, 'episode_id' => $parent_episode_details->id])->get();
|
|
/* get ordered sundries */
|
|
$parent_episode_ordered_sundries = OrderedSundry::where(['patient_id' => $patient_id, 'episode_id' => $parent_episode_details->id])->get();
|
|
//check for authenticated investigations
|
|
$parent_episode_investigation_results = InvestigationResults::where(['patient_id' => $patient_id, 'episode_id' => $parent_episode_details->id])->get();
|
|
}
|
|
/* ========end of varibales added to cater for review episodes ========*/
|
|
|
|
return view('antenatal::ante_natal_clinic.create', compact('patient', 'patient_id', 'previous_surgeries','previous_medical_conditions', 'episode_id', 'gender_based_violence', 'last_five_pregnancies', 'uterus_operations', 'caesarian_sections', 'triage', 'treatment', 'categories', 'marital_statuses', 'drug_categories', 'documents', 'blood_groups', 'hiv_statuses', 'accuracies', 'referrals', 'anc_outcomes', 'known_patient_allergies', 'known_patient_alerts', 'drug_categories_array', 'obstetric_history_details', 'episode', 'ordered_procedures', 'ordered_investigations', 'investigation_results', 'treatments', 'ordered_sundries', 'parent_episode_treatments', 'parent_episode_ordered_procedures', 'parent_episode_ordered_sundries', 'parent_episode_ordered_investigations', 'parent_episode_investigation_results', 'family_planning_methods','previous_consultations', 'diagnoses','chronic_results'));
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
|
|
|
|
|
|
$url = "";
|
|
/* try to perform this set of db transactions and if any fails, rollback everything */
|
|
DB::transaction(function () use ($request) {
|
|
$patient_id = session()->get('patient_id');
|
|
$episode_id = session()->get('episode_id');
|
|
$gravida = $request->gravida;
|
|
$para = $request->para;
|
|
$abortion = $request->abortion;
|
|
$postpartum = $request->postpartum;
|
|
$clinic_id = get_name('ante_natal', 'slug', 'id', 'clinics'); //get the id for antenatal clinic from clinics table
|
|
for ($k = 1; $k <= $request->pregnancy_number; $k++) {
|
|
$pregnancy = 'pregnancy_'.$k;
|
|
$obs_date = $pregnancy.'_obstetric_date';
|
|
$gestation = $pregnancy.'_gestation';
|
|
$outcome = $pregnancy.'_obstetric_outcome';
|
|
$abortion_outcome = $pregnancy.'_abortion_outcome';
|
|
$stillbirth_type = $pregnancy.'_stillbirth_type';
|
|
$delivery_type = $pregnancy.'_delivery_type';
|
|
$classification = $pregnancy.'_classification';
|
|
$puerperium = $pregnancy.'_puerperium';
|
|
$pregnancy_complication = $pregnancy.'_pregnancy_complication';
|
|
$child_name = $pregnancy.'_child_name';
|
|
$child_gender = $pregnancy.'_child_gender';
|
|
$child_patient_number = $pregnancy.'_child_patient_number';
|
|
$child_birth_weight = $pregnancy.'_child_birth_weight';
|
|
$child_immunisation_status = $pregnancy.'_child_immunisation_status';
|
|
$child_health_condition = $pregnancy.'_child_health_condition';
|
|
$child_counter = !empty($request->$child_name[0]) ? count($request->$child_name) : 0;
|
|
$children = [];
|
|
if ($child_counter > 0) {
|
|
for ($t = 0; $t < $child_counter; $t++) {
|
|
$children[] = [
|
|
'health_condition' => $request->$child_health_condition[$t], 'immunisation_status' => $request->$child_immunisation_status[$t], 'birth_weight' => $request->$child_birth_weight[$t],
|
|
'patient_number' => $request->$child_patient_number[$t], 'gender' => $request->$child_gender[$t], 'name' => $request->$child_name[$t]
|
|
];
|
|
}
|
|
}
|
|
$obstetric_history = new ObstetricHistory;
|
|
$obstetric_history->patient_id = $patient_id;
|
|
$obstetric_history->episode_id = $episode_id;
|
|
$obstetric_history->obstetric_date = isset($request->$obs_date) ? Carbon::createFromFormat('d/m/Y', $request->$obs_date)->toDateString() : null;
|
|
$obstetric_history->gestation = $request->$gestation;
|
|
$obstetric_history->outcome = $request->$outcome;
|
|
$obstetric_history->stillbirth_type = $request->$stillbirth_type;
|
|
$obstetric_history->clinic_id = $clinic_id;
|
|
$obstetric_history->abortion_outcome = $request->$abortion_outcome;
|
|
$obstetric_history->delivery_type = $request->$delivery_type;
|
|
$obstetric_history->classification = $request->$classification;
|
|
$obstetric_history->puerperium = $request->$puerperium;
|
|
$obstetric_history->pregnancy_complication = $request->$pregnancy_complication;
|
|
$obstetric_history->children = !empty($children)? json_encode($children) : null;
|
|
$obstetric_history->created_by = auth()->user()->id;
|
|
$obstetric_history->save();
|
|
}
|
|
// PPH
|
|
$previous_pph = $request->previous_pph;
|
|
$pph_details = $request->pph_details;
|
|
$previous_scar = $request->previous_scar;
|
|
$scar_number = $request->scar_number;
|
|
$scar_indication = $request->scar_indication;
|
|
$other_comments = $request->other_comments;
|
|
// Blood Transfusion
|
|
$blood_group = $request->blood_group;
|
|
$transfusion_date_array = (!empty($request->transfusion_date[0]) && (!empty($request->no_of_units[0]) || !empty($request->transfusion_comment[0])))? $request->transfusion_date:null;
|
|
$number_of_units_array = $request->no_of_units;
|
|
$transfusion_comment_array = $request->transfusion_comment;
|
|
// VDRL/Hiv
|
|
$hiv_result = $request->hiv_result?? '';
|
|
$vdrl_result = $request->vdrl_result?? '';
|
|
$vdrl_date = !empty($request->vdrl_date) ? Carbon::createFromFormat('d/m/Y', $request->vdrl_date)->toDateString() : null;
|
|
$hiv_date = !empty($request->hiv_date) ? Carbon::createFromFormat('d/m/Y', $request->hiv_date)->toDateString() : null;
|
|
$vdrl_location = $request->vdrl_location;
|
|
$hiv_location = $request->hiv_location;
|
|
//physique
|
|
$height = $request->height;
|
|
$weight = $request->weight;
|
|
$bmi = $request->bmi;
|
|
// This pregnancy
|
|
$lmp = isset($request->lmp) ? Carbon::createFromFormat('d/m/Y', $request->lmp)->toDateString() : null;
|
|
$accuracy = $request->accuracy;
|
|
$edd = isset($request->edd) ? Carbon::createFromFormat('d/m/Y', $request->edd)->toDateString() : null;
|
|
$referral = $request->refferal;
|
|
$general_comments = $request->comments;
|
|
//$triage_details = Triage::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
|
|
//$clinic_id = $triage_details->clinic_allocation;
|
|
// ART
|
|
$art_treatment_center = $request->art_treatment_center;
|
|
$art_treatment_number = $request->art_treatment_number;
|
|
|
|
$anc_registration = new AnteNatalClinicRegistration;
|
|
$anc_registration->patient_id = $patient_id;
|
|
$anc_registration->episode_id = $episode_id;
|
|
$anc_registration->gravida = $gravida;
|
|
$anc_registration->para = $para;
|
|
$anc_registration->abortion = $abortion;
|
|
$anc_registration->ectopic_pregnancies = $request->ectopic_pregnancies;
|
|
//$anc_registration->postpartum = $postpartum;
|
|
$anc_registration->previous_pph = $previous_pph;
|
|
$anc_registration->previous_pph_details = $pph_details;
|
|
$anc_registration->previous_scar = $previous_scar;
|
|
$anc_registration->previous_scar_number = $scar_number;
|
|
$anc_registration->previous_scar_indication = $scar_indication;
|
|
$anc_registration->other_comments = $other_comments;
|
|
$anc_registration->height = $height;
|
|
$anc_registration->weight = $weight;
|
|
$anc_registration->bmi = $bmi;
|
|
$anc_registration->lmp = $lmp;
|
|
$anc_registration->accuracy = $accuracy;
|
|
$anc_registration->edd = $edd;
|
|
$anc_registration->other_facility_visited_name = $request->other_facility_visited_name;
|
|
$anc_registration->other_facility_visit_date = isset($request->other_facility_visit_date)? Carbon::createFromFormat('d/m/Y',$request->other_facility_visit_date)->toDateString():null;
|
|
$anc_registration->woa_weeks = $request->woa_weeks;
|
|
$anc_registration->complications = !empty($request->complications)? implode(',', $request->complications):null;
|
|
$anc_registration->other_complications = $request->complications_others_input?? null;
|
|
$anc_registration->hospital_visits = $request->hospital_visits?? null;
|
|
$anc_registration->hospital_visit_reason = $request->hospital_visits_input?? null;
|
|
$anc_registration->referral_from = $referral;
|
|
$anc_registration->general_comments = $general_comments;
|
|
$anc_registration->created_by = auth()->user()->id;
|
|
if ($request->get('submit-btn') == 'complete') {
|
|
$anc_registration->completed = 1;
|
|
$anc_registration->save();
|
|
} else {
|
|
$anc_registration->save();
|
|
}
|
|
|
|
$registration_id = $anc_registration->id; //get the registration id
|
|
if (!empty($vdrl_result) || isset($hiv_result)){
|
|
$anc_vdrl_hiv_data = new AncVdrlHiv;
|
|
$anc_vdrl_hiv_data->patient_id = $patient_id;
|
|
$anc_vdrl_hiv_data->episode_id = $episode_id;
|
|
$anc_vdrl_hiv_data->registration_id = $registration_id;
|
|
$anc_vdrl_hiv_data->vdrl_result = $vdrl_result;
|
|
$anc_vdrl_hiv_data->vdrl_date = $vdrl_date;
|
|
$anc_vdrl_hiv_data->vdrl_location = $vdrl_location;
|
|
$anc_vdrl_hiv_data->hiv_result = $hiv_result;
|
|
$anc_vdrl_hiv_data->hiv_date = $hiv_date;
|
|
$anc_vdrl_hiv_data->hiv_location = $hiv_location;
|
|
$anc_vdrl_hiv_data->art_treatment_center = $art_treatment_center;
|
|
$anc_vdrl_hiv_data->art_treatment_number = $art_treatment_number;
|
|
$anc_vdrl_hiv_data->created_by = auth()->user()->id;
|
|
$anc_vdrl_hiv_data->save();
|
|
}
|
|
|
|
//store antenatal blood transfusions
|
|
if(!empty($transfusion_date_array)) for ($i = 0; $i < count($transfusion_date_array); $i++) {
|
|
$anc_blood_transfusion = new AnteNatalClinicBloodTransfusion;
|
|
$anc_blood_transfusion->patient_id = $patient_id;
|
|
$anc_blood_transfusion->episode_id = $episode_id;
|
|
$anc_blood_transfusion->registration_id = $registration_id;
|
|
$anc_blood_transfusion->blood_group_id = $blood_group;
|
|
$anc_blood_transfusion->transfusion_date = isset($transfusion_date_array[$i]) ? Carbon::createFromFormat('d/m/Y', $transfusion_date_array[$i])->toDateString() : null;
|
|
$anc_blood_transfusion->number_of_units = $number_of_units_array[$i];
|
|
$anc_blood_transfusion->comments = $transfusion_comment_array[$i];
|
|
$anc_blood_transfusion->created_by = auth()->user()->id;
|
|
$anc_blood_transfusion->save();
|
|
}
|
|
|
|
//Store Mother's History
|
|
$mother_history = new AntenatalMotherHistory();
|
|
$mother_history->patient_id = $patient_id;
|
|
$mother_history->episode_id = $episode_id;
|
|
$mother_history->registration_id = $registration_id;
|
|
$mother_history->menses_length =$request->menses_length;
|
|
$mother_history->cycle_time =$request->cycle_time;
|
|
$mother_history->menses_amount =$request->menses_amount;
|
|
$mother_history->family_planning = $request->family_planning?? null;
|
|
$mother_history->date_discontinued =$request->date_discontinued;
|
|
$mother_history->why_stop_family_planning =$request->why_stop_family_planning;
|
|
$mother_history->any_medications =!empty($request->any_medications)? implode(',', $request->any_medications):null;
|
|
$mother_history->other_any_medications =$request->any_medications_others_input;
|
|
$mother_history->medical_presentations_others_input = $request->medical_presentations_others_input;
|
|
$mother_history->medical_presentations = !empty($request->medical_presentations)? implode(',', $request->medical_presentations):null;
|
|
$mother_history->surgical_history = !empty($request->surgical_history)? implode(',', $request->surgical_history):null;
|
|
$mother_history->surgical_history_operations =$request->surgical_history_operations_input;
|
|
$mother_history->surgical_history_blood_transfusion =$request->surgical_history_blood_transfusion_input;
|
|
$mother_history->obs_gyn =!empty($request->obs_gyn)? implode(',', $request->obs_gyn):null;
|
|
$mother_history->caesarian_section =$request->caesarian_section;
|
|
$mother_history->uterus_operations =$request->uterus_operations;
|
|
foreach($request->uterus_operations_name as $key => $operation){
|
|
if(!empty($operation)) $uterine_operations[] =['name'=>$operation, 'date'=>$request->uterus_operations_date[$key], 'facility_name'=>$request->uterus_operations_facility_name[$key]];
|
|
}
|
|
foreach($request->other_operations_name as $key => $operation){
|
|
if(!empty($operation)) $other_surgeries[] =['name'=>$operation, 'date'=>$request->other_operations_date[$key], 'facility_name'=>$request->other_operations_facility_name[$key]];
|
|
}
|
|
$mother_history->uterine_surgeries = !empty($uterine_operations)? json_encode($uterine_operations):null;
|
|
$mother_history->other_surgeries = !empty($other_surgeries)? json_encode($other_surgeries):null;
|
|
$mother_history->family_history =!empty($request->family_history)? implode(',', $request->family_history): null;
|
|
$mother_history->sgbv =$request->sgbv;
|
|
$mother_history->sgbv_risk =!empty($request->sgbv_sgbv_risk_input)? implode(',', $request->sgbv_sgbv_risk_input):null;
|
|
$mother_history->fractures =!empty($request->fractures)? implode(',', $request->fractures):null;
|
|
$fractures[] = ['date'=>$request->fractures_pelvis_date?? null, 'details'=>$request->fractures_pelvis_input?? null];
|
|
$fractures[] = ['date'=>$request->fractures_spine_date?? null, 'details'=>$request->fractures_spine_input?? null];
|
|
$fractures[] = ['date'=>$request->fractures_femur_date?? null, 'details'=>$request->fractures_femur_input?? null];
|
|
$mother_history->fracture_details = json_encode($fractures);
|
|
$mother_history->husband_health =$request->husband_health;
|
|
$mother_history->created_by =auth()->user()->id;
|
|
$mother_history->save();
|
|
});
|
|
|
|
// redirect according to what button has been clicked
|
|
switch ($request->get('submit-btn')):
|
|
case 'investigation':
|
|
$url = 'investigations/investigations_review';
|
|
break;
|
|
|
|
case 'treatment':
|
|
$url = 'prescriptions/create';
|
|
break;
|
|
|
|
case 'procedures':
|
|
$url = 'order_procedures';
|
|
break;
|
|
|
|
case 'sundries':
|
|
$url = 'order_sundries';
|
|
break;
|
|
|
|
case 'complete':
|
|
$url = 'patient_episodes';
|
|
break;
|
|
|
|
case 'save_consultation':
|
|
$url = '/patient_flow_monitoring/index';
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
endswitch;
|
|
flash('Ante Natal Clinic Registration successful')->success();
|
|
return redirect($url);
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id)
|
|
{
|
|
$anc_registration_details = AnteNatalClinicRegistration::find($id);
|
|
$episode_id = $anc_registration_details->episode_id;
|
|
$patient_id = session()->get('patient_id');
|
|
$patient = Patient::where(['id' => $patient_id])->first();
|
|
$last_five_pregnancies = AnteNatalClinicRegistration::where([['patient_id', $patient_id], ['id','<>', $id]])->orderBy('created_at','desc')->take(5)->get();
|
|
$categories = DB::table('patient_categories')->pluck("name", "id");
|
|
$marital_statuses = DB::table('marital_statuses')->pluck("name", "id");
|
|
$drug_categories = DB::table('drug_categories')->get();
|
|
$previous_medical_conditions = AnteNatalMotherHistory::where([['patient_id', $patient_id],['episode_id', '<>', $episode_id]])->latest()->first(['medical_presentations']);
|
|
$documents = \Streamline\Models\PatientDocument::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$known_patient_allergies = \Streamline\Models\Allergy::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$known_patient_alerts = \Streamline\Models\Alert::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$drug_categories_array = DB::table('drug_categories')->pluck('name', 'id');
|
|
$anc_outcomes = DB::table('ante_natal_clinic_outcomes')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
$triage = Triage::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
|
|
$obstetric_history_details = ObstetricHistory::where(['patient_id' => $patient_id])->orderBy('obstetric_date', 'desc')->get();
|
|
$anc_blood_transfusion_details_collection = AnteNatalClinicBloodTransfusion::where(['patient_id' => $patient_id])->get();
|
|
$dispensed_treatment = Treatment::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'tta' => 0])->first();
|
|
$ordered_procedures = OrderedProcedure::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
$anc_vdrl_hiv_details = AncVdrlHiv::where(['registration_id' => $anc_registration_details->id])->first();
|
|
$hiv_statuses = ['' => '-- Select --', '0' => 'Negative', '1' => 'Positive', '3' => 'Unknown'];
|
|
$family_planning_methods = FamilyPlanningMethod::orderBy('name', 'asc')->pluck("name", "id")->prepend('- Select -', '');
|
|
$gender_based_violence = GenderViolence::orderBy('name', 'asc')->pluck("name", "id")->prepend('- Select -', '');
|
|
$uterus_operations = Procedure::where('hmis_category_inpatient', 10046)->orderBy('name', 'asc')->pluck("name", "id")->prepend('- Select -', '');
|
|
$caesarian_sections = CaesarianSection::orderBy('name', 'asc')->pluck("name", "id")->prepend('- Select -', '');
|
|
$mother_history = AntenatalMotherHistory::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'registration_id' =>$anc_registration_details->id])->first();
|
|
$accuracies = DB::table('ante_natal_clinic_accuracies')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
$referrals = DB::table('referral_hospitals')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
$blood_groups = DB::table('blood_groups')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
// collect chronic drug ids as array
|
|
$chronic_drugs_array = ChronicPatient::where('patient_id', $patient_id)->whereNotNull('drug_id')->get(['drug_id']);
|
|
$chronic_results = Drug::whereIn('id', $chronic_drugs_array)->get(['id', 'name']);
|
|
$previous_consultations = Consultation::leftJoin('patient_episodes as p','p.id','consultations.episode_id')->where([['consultations.patient_id', $patient_id],['episode_id', '<>',$episode_id]])->latest()->take(5)->get(['consultations.created_at','p.clinic_id', 'primary_diagnosis', 'other_diagnoses', 'consultations.created_by','episode_id','consultations.id']);
|
|
/* episode details */
|
|
$episode = PatientEpisode::find($episode_id);
|
|
$previous_surgeries = Surgery::where([['patient_id', $patient_id],['episode_id', '<>',$episode_id]])->latest()->take(5)->get(['created_at', 'primary_diagnosis', 'other_diagnoses', 'created_by','episode_id','procedure_id']);
|
|
$diagnoses = DB::table('diagnoses')->whereNull('deleted_at')->orderBy('name', 'asc')->pluck("name", "id");
|
|
/* get treatment */
|
|
$treatments = Treatment::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'tta' => 0])->get();
|
|
/* get ordered procedures */
|
|
$ordered_procedures = OrderedProcedure::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
//check for ordered investigations,procedures and treatment
|
|
$ordered_investigations = OrderedInvestigation::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
/* get ordered sundries */
|
|
$ordered_sundries = OrderedSundry::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
//check for authenticated investigations
|
|
$investigation_results = InvestigationResults::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
$diagnoses_all = DB::table('diagnoses')->select('id', 'prompts', 'reference_areas', 'reference_names')->get();
|
|
$anc_vdrl_details = null;
|
|
$anc_vdrl_episode_records = AncVdrlHiv::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
if (count($anc_vdrl_episode_records) > 0) $anc_vdrl_details = $anc_vdrl_episode_records->first();
|
|
/* ======== added to cater for review episode =========*/
|
|
$is_episode_a_review = check_if_episode_is_a_followup($episode_id);
|
|
$parent_episode_treatments = [];
|
|
$parent_episode_ordered_procedures = [];
|
|
$parent_episode_ordered_investigations = [];
|
|
$parent_episode_ordered_sundries = [];
|
|
$parent_episode_investigation_results = [];
|
|
|
|
if ($is_episode_a_review) {
|
|
$parent_episode_details = PatientEpisode::find($episode->parent_episode_id);
|
|
|
|
$parent_episode_treatments = Treatment::where(['patient_id' => $patient_id, 'episode_id' => $parent_episode_details->id, 'tta' => 0])->get();
|
|
$parent_episode_ordered_procedures = OrderedProcedure::where(['patient_id' => $patient_id, 'episode_id' => $parent_episode_details->id])->get();
|
|
$parent_episode_ordered_investigations = OrderedInvestigation::where(['patient_id' => $patient_id, 'episode_id' => $parent_episode_details->id])->get();
|
|
/* get ordered sundries */
|
|
$parent_episode_ordered_sundries = OrderedSundry::where(['patient_id' => $patient_id, 'episode_id' => $parent_episode_details->id])->get();
|
|
//check for authenticated investigations
|
|
$parent_episode_investigation_results = InvestigationResults::where(['patient_id' => $patient_id, 'episode_id' => $parent_episode_details->id])->get();
|
|
}
|
|
/* ========end of varibales added to cater for review episodes ========*/
|
|
|
|
return view('antenatal::ante_natal_clinic.show_pregnancy', compact('patient', 'previous_consultations', 'previous_medical_conditions', 'previous_surgeries', 'chronic_results', 'diagnoses', 'patient_id','blood_groups','episode_id', 'referrals','accuracies','anc_vdrl_details','gender_based_violence','categories','mother_history','caesarian_sections','uterus_operations', 'marital_statuses', 'drug_categories', 'family_planning_methods','documents', 'known_patient_alerts', 'known_patient_allergies', 'anc_outcomes', 'triage', 'anc_registration_details', 'obstetric_history_details', 'anc_blood_transfusion_details_collection', 'dispensed_treatment', 'ordered_procedures', 'anc_vdrl_hiv_details', 'hiv_statuses', 'last_five_pregnancies', 'drug_categories_array', 'episode', 'ordered_procedures', 'ordered_investigations', 'investigation_results', 'treatments', 'ordered_sundries', 'parent_episode_treatments', 'parent_episode_ordered_procedures', 'parent_episode_ordered_sundries', 'parent_episode_ordered_investigations', 'parent_episode_investigation_results'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
$existing_anc_registration = AnteNatalClinicRegistration::find($id);
|
|
$patient_id = $existing_anc_registration->patient_id;
|
|
$episode_id = $existing_anc_registration->episode_id;
|
|
|
|
$patient = Patient::where(['id' => $patient_id])->first();
|
|
$anc_blood_transfusion_details = AnteNatalClinicBloodTransfusion::where([['patient_id', $patient_id],['episode_id', $episode_id]])->get();
|
|
$anc_vdrl_details = null;
|
|
$previous_medical_conditions = AnteNatalMotherHistory::where([['patient_id', $patient_id],['episode_id', '<>', $episode_id]])->latest()->first(['medical_presentations']);
|
|
$anc_vdrl_details = AncVdrlHiv::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'registration_id' => $id])->latest()->first();
|
|
$categories = DB::table('patient_categories')->pluck("name", "id");
|
|
$marital_statuses = DB::table('marital_statuses')->pluck("name", "id");
|
|
$drug_categories = DB::table('drug_categories')->get();
|
|
$documents = PatientDocument::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$known_patient_allergies = Allergy::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$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');
|
|
$family_planning_methods = FamilyPlanningMethod::orderBy('name', 'asc')->pluck("name", "id")->prepend('- Select -', '');
|
|
$gender_based_violence = GenderViolence::orderBy('name', 'asc')->pluck("name", "id")->prepend('- Select -', '');
|
|
$uterus_operations = Procedure::where('hmis_category_inpatient', 10046)->orderBy('name', 'asc')->pluck("name", "id")->prepend('- Select -', '');
|
|
$caesarian_sections = CaesarianSection::orderBy('name', 'asc')->pluck("name", "id")->prepend('- Select -', '');
|
|
$mother_history = AntenatalMotherHistory::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'registration_id' =>$id])->first();
|
|
$triage_id = get_name($episode_id, "id", "triage_id", "patient_episodes");
|
|
$triage = Triage::find($triage_id);
|
|
$last_five_pregnancies = AnteNatalClinicRegistration::where([['patient_id', $patient_id],['episode_id', '<>', $episode_id]])->latest()->take(5)->get();
|
|
$previous_surgeries = Surgery::where([['patient_id', $patient_id],['episode_id', '<>',$episode_id]])->latest()->take(5)->get(['created_at', 'primary_diagnosis', 'other_diagnoses', 'created_by','episode_id','procedure_id']);
|
|
$diagnoses = DB::table('diagnoses')->whereNull('deleted_at')->orderBy('name', 'asc')->pluck("name", "id")->prepend('- select -', '');
|
|
//select treatment
|
|
$treatment = Treatment::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'tta' => 0])->first();
|
|
$blood_groups = DB::table('blood_groups')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
$referrals = DB::table('referral_hospitals')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
$accuracies = DB::table('ante_natal_clinic_accuracies')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
$anc_outcomes = DB::table('ante_natal_clinic_outcomes')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
$obstetric_history_details = ObstetricHistory::where(['patient_id' => $patient_id])->orderBy('obstetric_date', 'desc')->get();
|
|
$hiv_statuses = ['' => '-- Select --', '0' => 'Negative', '1' => 'Positive', '3' => 'Unknown'];
|
|
// collect chronic drug ids as array
|
|
$chronic_drugs_array = ChronicPatient::where('patient_id', $patient_id)->whereNotNull('drug_id')->get(['drug_id']);
|
|
$chronic_results = Drug::whereIn('id', $chronic_drugs_array)->get(['id', 'name']);
|
|
$previous_consultations = Consultation::leftJoin('patient_episodes as p','p.id','consultations.episode_id')->where([['consultations.patient_id', $patient_id],['episode_id', '<>',$episode_id]])->latest()->take(5)->get(['consultations.created_at','p.clinic_id', 'primary_diagnosis', 'other_diagnoses', 'consultations.created_by','episode_id','consultations.id']);
|
|
/* episode details */
|
|
$episode = PatientEpisode::find($episode_id);
|
|
/* get treatment */
|
|
$treatments = Treatment::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'tta' => 0])->get();
|
|
/* get ordered procedures */
|
|
$ordered_procedures = OrderedProcedure::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
//check for ordered investigations,procedures and treatment
|
|
$ordered_investigations = OrderedInvestigation::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
/* get ordered sundries */
|
|
$ordered_sundries = OrderedSundry::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
//check for authenticated investigations
|
|
$investigation_results = InvestigationResults::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
$diagnoses_all = DB::table('diagnoses')->select('id', 'prompts', 'reference_areas', 'reference_names')->get();
|
|
|
|
/* ======== added to cater for review episode =========*/
|
|
$is_episode_a_review = check_if_episode_is_a_followup($episode->id);
|
|
$parent_episode_treatments = [];
|
|
$parent_episode_ordered_procedures = [];
|
|
$parent_episode_ordered_investigations = [];
|
|
$parent_episode_ordered_sundries = [];
|
|
$parent_episode_investigation_results = [];
|
|
|
|
if ($is_episode_a_review) {
|
|
$parent_episode_details = PatientEpisode::find($episode->parent_episode_id);
|
|
|
|
$parent_episode_treatments = Treatment::where(['patient_id' => $patient_id, 'episode_id' => $parent_episode_details->id, 'tta' => 0])->get();
|
|
$parent_episode_ordered_procedures = OrderedProcedure::where(['patient_id' => $patient_id, 'episode_id' => $parent_episode_details->id])->get();
|
|
$parent_episode_ordered_investigations = OrderedInvestigation::where(['patient_id' => $patient_id, 'episode_id' => $parent_episode_details->id])->get();
|
|
/* get ordered sundries */
|
|
$parent_episode_ordered_sundries = OrderedSundry::where(['patient_id' => $patient_id, 'episode_id' => $parent_episode_details->id])->get();
|
|
//check for authenticated investigations
|
|
$parent_episode_investigation_results = InvestigationResults::where(['patient_id' => $patient_id, 'episode_id' => $parent_episode_details->id])->get();
|
|
}
|
|
$employees = DB::table('users')->whereNull('deleted_at')->orderBy('first_name', 'asc')->get();
|
|
/* ========end of varibales added to cater for review episodes ========*/
|
|
|
|
return view('antenatal::ante_natal_clinic.edit', compact('existing_anc_registration', 'diagnoses', 'previous_medical_conditions', 'last_five_pregnancies','previous_surgeries','employees','previous_consultations','uterus_operations', 'patient', 'patient_id', 'mother_history', 'episode_id', 'triage', 'treatment', 'categories', 'marital_statuses', 'family_planning_methods', 'gender_based_violence', 'gender_based_violence', 'caesarian_sections','drug_categories', 'documents', 'blood_groups', 'hiv_statuses', 'accuracies', 'referrals', 'anc_outcomes', 'known_patient_allergies', 'known_patient_alerts', 'drug_categories_array', 'obstetric_history_details', 'anc_blood_transfusion_details', 'anc_vdrl_details', 'episode', 'ordered_procedures', 'ordered_investigations', 'investigation_results', 'treatments', 'ordered_sundries', 'parent_episode_treatments', 'parent_episode_ordered_procedures', 'parent_episode_ordered_sundries', 'parent_episode_ordered_investigations', 'parent_episode_investigation_results','chronic_results'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
$url = "";
|
|
$anc_registration = AnteNatalClinicRegistration::find($id);
|
|
|
|
/* try to perform this set of db transactions and if any fails, rollback everything */
|
|
DB::transaction(function () use ($request, $anc_registration) {
|
|
$patient_id = session()->get('patient_id');
|
|
$episode_id = session()->get('episode_id');
|
|
$gravida = $request->gravida;
|
|
$para = $request->para;
|
|
$abortion = $request->abortion;
|
|
$postpartum = $request->postpartum;
|
|
$previous_pph = $request->previous_pph;
|
|
$pph_details = $request->pph_details;
|
|
$previous_scar = $request->previous_scar;
|
|
$scar_number = $request->scar_number;
|
|
$scar_indication = $request->scar_indication;
|
|
$other_comments = $request->other_comments;
|
|
// Blood Transfusion
|
|
$blood_group = $request->blood_group;
|
|
$transfusion_date_array = $transfusion_date_array = (!empty($request->transfusion_date[0]) && (!empty($request->no_of_units[0]) || !empty($request->transfusion_comment[0])))? $request->transfusion_date:[];
|
|
$number_of_units_array = $request->no_of_units;
|
|
$transfusion_comment_array = $request->transfusion_comment;
|
|
// VDRL/Hiv
|
|
$hiv_result = $request->hiv_result;
|
|
$vdrl_result = $request->vdrl_result;
|
|
$vdrl_date = (isset($request->vdrl_date) && !empty($vdrl_result)) ? Carbon::createFromFormat('d/m/Y', $request->vdrl_date)->toDateString() : null;
|
|
$hiv_date = (isset($request->hiv_date) && isset($hiv_result)) ? Carbon::createFromFormat('d/m/Y', $request->hiv_date)->toDateString() : null;
|
|
$vdrl_location = $request->vdrl_location;
|
|
$hiv_location = $request->hiv_location;
|
|
//physique
|
|
$height = $request->height;
|
|
$weight = $request->weight;
|
|
$bmi = $request->bmi;
|
|
// This pregnancy
|
|
$lmp = isset($request->lmp) ? Carbon::createFromFormat('d/m/Y', $request->lmp)->toDateString() : null;
|
|
$accuracy = $request->accuracy;
|
|
$edd = isset($request->edd) ? Carbon::createFromFormat('d/m/Y', $request->edd)->toDateString() : null;
|
|
$referral = $request->refferal;
|
|
$general_comments = $request->comments;
|
|
//clinic
|
|
$clinic_id = get_name('ante_natal', 'slug', 'id', 'clinics'); //get the id for antenatal clinic from clinics table
|
|
//$triage_details = Triage::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
|
|
//$clinic_id = $triage_details->clinic_allocation;
|
|
// ART
|
|
$art_treatment_center = $request->art_treatment_center;
|
|
$art_treatment_number = $request->art_treatment_number;
|
|
|
|
$anc_registration->patient_id = $patient_id;
|
|
$anc_registration->episode_id = $episode_id;
|
|
$anc_registration->gravida = $gravida;
|
|
$anc_registration->para = $para;
|
|
$anc_registration->abortion = $abortion;
|
|
$anc_registration->ectopic_pregnancies = $request->ectopic_pregnancies;
|
|
//$anc_registration->postpartum = $postpartum;
|
|
$anc_registration->other_facility_visited_name = $request->other_facility_visited_name;
|
|
$anc_registration->other_facility_visit_date = isset($request->other_facility_visit_date)? Carbon::createFromFormat('d/m/Y',$request->other_facility_visit_date)->toDateString():null;
|
|
$anc_registration->previous_pph = $previous_pph;
|
|
$anc_registration->previous_pph_details = $pph_details;
|
|
$anc_registration->previous_scar = $previous_scar;
|
|
$anc_registration->previous_scar_number = $scar_number;
|
|
$anc_registration->previous_scar_indication = $scar_indication;
|
|
$anc_registration->other_comments = $other_comments;
|
|
$anc_registration->height = $height;
|
|
$anc_registration->weight = $weight;
|
|
$anc_registration->bmi = $bmi;
|
|
$anc_registration->lmp = $lmp;
|
|
$anc_registration->woa_weeks = $request->woa_weeks;
|
|
$anc_registration->accuracy = $accuracy;
|
|
$anc_registration->edd = $edd;
|
|
$anc_registration->referral_from = $referral;
|
|
$anc_registration->general_comments = $general_comments;
|
|
$anc_registration->updated_by = auth()->user()->id;
|
|
if ($request->get('submit-btn') == 'complete') {
|
|
$anc_registration->completed = 1;
|
|
$anc_registration->save();
|
|
} else {
|
|
$anc_registration->save();
|
|
}
|
|
|
|
$registration_id = $anc_registration->id; //get the registration id
|
|
|
|
$anc_vdrl_hiv_data_records = AncVdrlHiv::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'registration_id' => $registration_id])->get();
|
|
$anc_vdrl_hiv_data = count($anc_vdrl_hiv_data_records) > 0 ? $anc_vdrl_hiv_data_records->first() : new AncVdrlHiv;
|
|
$anc_vdrl_hiv_data->patient_id = $patient_id;
|
|
$anc_vdrl_hiv_data->episode_id = $episode_id;
|
|
$anc_vdrl_hiv_data->registration_id = $registration_id;
|
|
$anc_vdrl_hiv_data->vdrl_result = $vdrl_result;
|
|
$anc_vdrl_hiv_data->vdrl_date = $vdrl_date;
|
|
$anc_vdrl_hiv_data->vdrl_location = $vdrl_location;
|
|
$anc_vdrl_hiv_data->hiv_result = $hiv_result;
|
|
$anc_vdrl_hiv_data->hiv_date = $hiv_date;
|
|
$anc_vdrl_hiv_data->hiv_location = $hiv_location;
|
|
$anc_vdrl_hiv_data->art_treatment_center = $art_treatment_center;
|
|
$anc_vdrl_hiv_data->art_treatment_number = $art_treatment_number;
|
|
count($anc_vdrl_hiv_data_records) > 0 ? $anc_vdrl_hiv_data->updated_by = auth()->user()->id :$anc_vdrl_hiv_data->created_by = auth()->user()->id;
|
|
$anc_vdrl_hiv_data->save();
|
|
|
|
//store antenatal blood transfusions
|
|
for ($i = 0; $i < count($transfusion_date_array); $i++) {
|
|
|
|
$transfuz_date = !empty($transfusion_date_array[$i]) ? Carbon::createFromFormat('d/m/Y', $transfusion_date_array[$i])->toDateString() : null;
|
|
|
|
$anc_blood_transfusion_records = AnteNatalClinicBloodTransfusion::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->whereDate('transfusion_date', $transfuz_date)->get();
|
|
|
|
$anc_blood_transfusion = count($anc_blood_transfusion_records) > 0 ? $anc_blood_transfusion_records->first() : new AnteNatalClinicBloodTransfusion;
|
|
|
|
$anc_blood_transfusion->patient_id = $patient_id;
|
|
$anc_blood_transfusion->episode_id = $episode_id;
|
|
$anc_blood_transfusion->registration_id = $registration_id;
|
|
$anc_blood_transfusion->blood_group_id = $blood_group;
|
|
$anc_blood_transfusion->transfusion_date = isset($transfusion_date_array[$i]) ? Carbon::createFromFormat('d/m/Y', $transfusion_date_array[$i])->toDateString() : null;
|
|
$anc_blood_transfusion->number_of_units = $number_of_units_array[$i];
|
|
$anc_blood_transfusion->comments = $transfusion_comment_array[$i];
|
|
count($anc_blood_transfusion_records) > 0 ? $anc_blood_transfusion->updated_by = auth()->user()->id : $anc_blood_transfusion->created_by = auth()->user()->id;
|
|
$anc_blood_transfusion->save();
|
|
}
|
|
|
|
//store obstetric history data
|
|
for ($k = 1; $k <= $request->pregnancy_number; $k++) {
|
|
$pregnancy = 'pregnancy_'.$k;
|
|
$obs_date = $pregnancy.'_obstetric_date';
|
|
$gestation = $pregnancy.'_gestation';
|
|
$outcome = $pregnancy.'_obstetric_outcome';
|
|
$abortion_outcome = $pregnancy.'_abortion_outcome';
|
|
$stillbirth_type = $pregnancy.'_stillbirth_type';
|
|
$delivery_type = $pregnancy.'_delivery_type';
|
|
$classification = $pregnancy.'_classification';
|
|
$puerperium = $pregnancy.'_puerperium';
|
|
$pregnancy_complication = $pregnancy.'_pregnancy_complication';
|
|
$child_name = $pregnancy.'_child_name';
|
|
$child_gender = $pregnancy.'_child_gender';
|
|
$child_patient_number = $pregnancy.'_child_patient_number';
|
|
$child_birth_weight = $pregnancy.'_child_birth_weight';
|
|
$child_immunisation_status = $pregnancy.'_child_immunisation_status';
|
|
$child_health_condition = $pregnancy.'_child_health_condition';
|
|
$stored_pregnancy = $pregnancy.'_id';
|
|
$deleted_pregnancy = 'delete_'.$pregnancy.'_id';
|
|
$child_counter = !empty($request->$child_name[0]) ? count($request->$child_name) : 0;
|
|
$children = [];
|
|
if ($child_counter > 0) {
|
|
for ($t = 0; $t < $child_counter; $t++) {
|
|
$children[] = [
|
|
'health_condition' => $request->$child_health_condition[$t], 'immunisation_status' => $request->$child_immunisation_status[$t], 'birth_weight' => $request->$child_birth_weight[$t],
|
|
'patient_number' => $request->$child_patient_number[$t], 'gender' => $request->$child_gender[$t], 'name' => $request->$child_name[$t]
|
|
];
|
|
}
|
|
}
|
|
if(!empty($request->$deleted_pregnancy)){
|
|
$delete_pregnancy = ObstetricHistory::find($request->$deleted_pregnancy);
|
|
$delete_pregnancy->delete();
|
|
} elseif (!empty($request->$stored_pregnancy) && empty($request->$deleted_pregnancy)) {
|
|
$update_obstetric_history = ObstetricHistory::find($request->$stored_pregnancy);
|
|
$update_obstetric_history->patient_id = $patient_id;
|
|
$update_obstetric_history->episode_id = $episode_id;
|
|
$update_obstetric_history->obstetric_date = isset($request->$obs_date) ? Carbon::createFromFormat('d/m/Y', $request->$obs_date)->toDateString() : null;
|
|
$update_obstetric_history->gestation = $request->$gestation;
|
|
$update_obstetric_history->outcome = $request->$outcome;
|
|
$update_obstetric_history->clinic_id = $clinic_id;
|
|
$update_obstetric_history->abortion_outcome = $request->$abortion_outcome;
|
|
$update_obstetric_history->stillbirth_type = $request->$stillbirth_type;
|
|
$update_obstetric_history->delivery_type = $request->$delivery_type;
|
|
$update_obstetric_history->classification = $request->$classification;
|
|
$update_obstetric_history->puerperium = $request->$puerperium;
|
|
$update_obstetric_history->pregnancy_complication = $request->$pregnancy_complication;
|
|
$update_obstetric_history->children = !empty($children)? json_encode($children) : null;
|
|
$update_obstetric_history->updated_by = auth()->user()->id;
|
|
$update_obstetric_history->save();
|
|
} else{
|
|
$obstetric_history = new ObstetricHistory;
|
|
$obstetric_history->patient_id = $patient_id;
|
|
$obstetric_history->episode_id = $episode_id;
|
|
$obstetric_history->obstetric_date = isset($request->$obs_date) ? Carbon::createFromFormat('d/m/Y', $request->$obs_date)->toDateString() : null;
|
|
$obstetric_history->gestation = $request->$gestation;
|
|
$obstetric_history->outcome = $request->$outcome;
|
|
$obstetric_history->stillbirth_type = $request->$stillbirth_type;
|
|
$obstetric_history->clinic_id = $clinic_id;
|
|
$obstetric_history->abortion_outcome = $request->$abortion_outcome;
|
|
$obstetric_history->delivery_type = $request->$delivery_type;
|
|
$obstetric_history->classification = $request->$classification;
|
|
$obstetric_history->puerperium = $request->$puerperium;
|
|
$obstetric_history->pregnancy_complication = $request->$pregnancy_complication;
|
|
$obstetric_history->children = !empty($children)? json_encode($children) : null;
|
|
$obstetric_history->created_by = auth()->user()->id;
|
|
$obstetric_history->save();
|
|
}
|
|
}
|
|
|
|
//Store Mother's History
|
|
if (!empty($request->mother_obs_history_id)) {
|
|
$mother_history = AntenatalMotherHistory::find($request->mother_obs_history_id);
|
|
$mother_history->updated_by =auth()->user()->id;
|
|
} else {
|
|
$mother_history = new AntenatalMotherHistory();
|
|
$mother_history->created_by =auth()->user()->id;
|
|
}
|
|
$mother_history->patient_id = $patient_id;
|
|
$mother_history->episode_id = $episode_id;
|
|
$mother_history->registration_id = $registration_id;
|
|
$mother_history->menses_length =$request->menses_length;
|
|
$mother_history->cycle_time =$request->cycle_time;
|
|
$mother_history->menses_amount =$request->menses_amount;
|
|
$mother_history->family_planning = $request->family_planning?? null;
|
|
$mother_history->date_discontinued =$request->date_discontinued;
|
|
$mother_history->why_stop_family_planning =$request->why_stop_family_planning;
|
|
$mother_history->any_medications =!empty($request->any_medications)? implode(',', $request->any_medications): null;
|
|
$mother_history->other_any_medications =$request->any_medications_others_input;
|
|
$mother_history->medical_presentations_others_input = $request->medical_presentations_others_input;
|
|
$mother_history->medical_presentations = !empty($request->medical_presentations)? implode(',', $request->medical_presentations) : null;
|
|
$mother_history->surgical_history = !empty($request->surgical_history)? implode(',', $request->surgical_history):null;
|
|
$mother_history->surgical_history_operations =$request->surgical_history_operations_input;
|
|
$mother_history->surgical_history_blood_transfusion =$request->surgical_history_blood_transfusion_input;
|
|
$mother_history->obs_gyn =!empty($request->obs_gyn)? implode(',', $request->obs_gyn): null;
|
|
$mother_history->caesarian_section =$request->caesarian_section;
|
|
$mother_history->uterus_operations =$request->uterus_operations;
|
|
foreach($request->uterus_operations_name as $key => $operation){
|
|
if(!empty($operation)) $uterine_operations[] =['name'=>$operation, 'date'=>$request->uterus_operations_date[$key], 'facility_name'=>$request->uterus_operations_facility_name[$key]];
|
|
}
|
|
foreach($request->other_operations_name as $key => $operation){
|
|
if(!empty($operation)) $other_surgeries[] =['name'=>$operation, 'date'=>$request->other_operations_date[$key], 'facility_name'=>$request->other_operations_facility_name[$key]];
|
|
}
|
|
$mother_history->uterine_surgeries = !empty($uterine_operations)? json_encode($uterine_operations):null;
|
|
$mother_history->other_surgeries = !empty($other_surgeries)?json_encode($other_surgeries):null;
|
|
$mother_history->family_history =!empty($request->family_history)? implode(',', $request->family_history): null;
|
|
$mother_history->sgbv =$request->sgbv;
|
|
$mother_history->sgbv_risk =!empty($request->sgbv_sgbv_risk_input)? implode(',', $request->sgbv_sgbv_risk_input): null;
|
|
$mother_history->fractures =!empty($request->fractures)? implode(',', $request->fractures): null;
|
|
$fractures[] = ['date'=>$request->fractures_pelvis_date?? null, 'details'=>$request->fractures_pelvis_input?? null];
|
|
$fractures[] = ['date'=>$request->fractures_spine_date?? null, 'details'=>$request->fractures_spine_input?? null];
|
|
$fractures[] = ['date'=>$request->fractures_femur_date?? null, 'details'=>$request->fractures_femur_input?? null];
|
|
$mother_history->fracture_details = json_encode($fractures);
|
|
$mother_history->husband_health =$request->husband_health;
|
|
$mother_history->save();
|
|
});
|
|
// performing an ordered procedure.
|
|
if (!empty($request->perform_selected)) {
|
|
foreach ($request->perform_selected as $procedure_array_id) {
|
|
$arr = explode(",", get_name($request->procedure_order_perform[$procedure_array_id], 'id', 'performed', 'ordered_procedures'));
|
|
$arr_id = explode(",", get_name($request->procedure_order_perform[$procedure_array_id], 'id', 'performed_id', 'ordered_procedures'));
|
|
|
|
$performed_id = record_staff_that_has_performed_the_service(
|
|
session()->get('patient_id'),
|
|
session()->get('episode_id'),
|
|
1,
|
|
$request->perform[$procedure_array_id],
|
|
0,
|
|
$request->procedure_performed_by[$procedure_array_id]
|
|
);
|
|
|
|
if (isset($arr[$request->procedure_performed_position[$procedure_array_id]])) {
|
|
$arr[$request->procedure_performed_position[$procedure_array_id]] = 1;
|
|
$arr_id[$request->procedure_performed_position[$procedure_array_id]] = $performed_id;
|
|
$update = DB::table('ordered_procedures')->where('id', $request->procedure_order_perform[$procedure_array_id])
|
|
->update(['performed' => implode(",", $arr), 'performed_id' => implode(",", $arr_id)]);
|
|
}
|
|
}
|
|
}
|
|
// redirect according to what button has been clicked
|
|
switch ($request->get('submit-btn')):
|
|
case 'investigation':
|
|
$url = 'investigations/investigations_review';
|
|
break;
|
|
|
|
case 'treatment':
|
|
$url = 'prescriptions/create';
|
|
break;
|
|
|
|
case 'procedures':
|
|
$url = 'order_procedures';
|
|
break;
|
|
|
|
case 'sundries':
|
|
$url = 'order_sundries';
|
|
break;
|
|
|
|
case 'complete':
|
|
$url = '/ante_natal_clinic/'.$anc_registration->id;
|
|
break;
|
|
|
|
case 'save_consultation':
|
|
$url = '/patient_flow_monitoring/index';
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
endswitch;
|
|
|
|
flash('AnteNatal clinic registration has been updated successfully')->success();
|
|
return redirect($url);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/*
|
|
Display Ante Natal Clinic menu
|
|
*/
|
|
public function menu()
|
|
{
|
|
$patient_id = session()->get('patient_id');
|
|
$episode_id = session()->get('episode_id');
|
|
$patient = Patient::where(['id' => $patient_id])->first();
|
|
$categories = DB::table('patient_categories')->pluck("name", "id");
|
|
$marital_statuses = DB::table('marital_statuses')->pluck("name", "id");
|
|
$drug_categories = DB::table('drug_categories')->get();
|
|
$documents = \Streamline\Models\PatientDocument::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$known_patient_allergies = \Streamline\Models\Allergy::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$known_patient_alerts = \Streamline\Models\Alert::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$drug_categories_array = DB::table('drug_categories')->pluck('name', 'id');
|
|
return view('antenatal::ante_natal_clinic.menu', compact('patient_id', 'episode_id', 'patient', 'documents', 'known_patient_alerts', 'known_patient_allergies', 'categories', 'marital_statuses', 'drug_categories', 'drug_categories_array'));
|
|
}
|
|
|
|
/*view details of the last ante natal clinic visit */
|
|
public function view_antenatal_visit($id)
|
|
{
|
|
$episode_id = $id;
|
|
$patient_id = session()->get('patient_id');
|
|
$patient = Patient::find($patient_id);
|
|
|
|
//used by the allergies partial
|
|
$categories = DB::table('patient_categories')->pluck("name", "id");
|
|
$marital_statuses = DB::table('marital_statuses')->pluck("name", "id");
|
|
$drug_categories = DB::table('drug_categories')->get();
|
|
$triage_id = get_name($episode_id, "id", "triage_id", "patient_episodes");
|
|
$triage = Triage::where(['id' => $triage_id])->first();
|
|
$symptoms = DB::table('symptoms')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
$treatment = Treatment::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'tta' => 0])->first();
|
|
$documents = \Streamline\Models\PatientDocument::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$known_patient_allergies = \Streamline\Models\Allergy::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$known_patient_alerts = \Streamline\Models\Alert::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$drug_categories_array = DB::table('drug_categories')->pluck('name', 'id');
|
|
|
|
$last_anc_followup_record = AnteNatalClinicFollowup::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->orderBy('created_at', 'desc')->first();
|
|
$anc_followup_records = AnteNatalClinicFollowup::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->orderBy('created_at', 'desc')->paginate(50);
|
|
//if there is no previous record of the anc follow up go back to ANC menu
|
|
if (is_null($last_anc_followup_record)) {
|
|
flash('No previous records for this patient')->error();
|
|
return redirect()->back();
|
|
}
|
|
$checklist = json_decode($last_anc_followup_record->checklist, true);
|
|
|
|
return view('antenatal::ante_natal_clinic.last_antenatal_visit_details', compact('patient_id', 'episode_id', 'patient', 'categories', 'marital_statuses', 'drug_categories', 'documents', 'known_patient_alerts', 'known_patient_allergies', 'drug_categories_array', 'triage', 'symptoms', 'treatment', 'last_anc_followup_record', 'checklist', 'anc_followup_records'));
|
|
}
|
|
|
|
/* create anc follow up form */
|
|
public function antenatal_visit()
|
|
{
|
|
|
|
$data = $this->getAncVisitData();
|
|
$data['resume'] = FALSE;
|
|
|
|
$data['resume_anc_followup'] = AnteNatalClinicFollowup::where(['patient_id' => $data['patient_id'], 'episode_id' => $data['episode_id'], 'completion_status' => 0])->first();
|
|
|
|
|
|
$data['visit_number'] = !empty($data['anc_visit_records'])? count($data['anc_visit_records']) + 1:1;
|
|
|
|
/*if the anc_followup exists then try to resume */
|
|
if (!is_null($data['resume_anc_followup'])) {
|
|
$data['resume'] = TRUE;
|
|
$data['visit_number'] = $data['resume_anc_followup']->ante_natal_clinic_visit_number;
|
|
|
|
return redirect('anc_visits/' . $data['resume_anc_followup']->id . '/edit');
|
|
}
|
|
|
|
|
|
|
|
$data['previous_anc_visits'] = AnteNatalClinicFollowup::where(['patient_id' => $data['patient_id']])->orderBy('created_at', 'desc')->take(5)->get()->groupBy('ante_natal_clinic_registration_id');
|
|
return view('antenatal::ante_natal_clinic.antenatal_visit', $data);
|
|
}
|
|
|
|
/* store anc template form details */
|
|
public function store_anc_template(Request $request)
|
|
{
|
|
|
|
$episode_id = session()->get('episode_id');
|
|
$patient_id = session()->get('patient_id');
|
|
$physical_exam = [];
|
|
// $existing_anc_followup_record = AnteNatalClinicFollowup::where(['episode_id' => $episode_id])->first();
|
|
|
|
/* instantiate a new eloquent model or get the existing one for updating */
|
|
$anc_followup_record = new AnteNatalClinicFollowup;
|
|
$anc_followup_record->patient_id = $patient_id;
|
|
$anc_followup_record->episode_id = $episode_id;
|
|
$anc_followup_record->ante_natal_clinic_date = Carbon::today()->toDateString();
|
|
$anc_followup_record->ante_natal_clinic_registration_id = $request->anc_registration_id;
|
|
$anc_followup_record->ante_natal_clinic_visit_number = $request->anc_visit_number;
|
|
$anc_followup_record->fundal_height = $request->fundal_height;
|
|
$anc_followup_record->lie = $request->lie;
|
|
$anc_followup_record->other_physicals = !empty($request->other_physicals)? implode(',', $request->other_physicals):null;
|
|
$anc_followup_record->presentation = $request->presentation;
|
|
$anc_followup_record->engagement = $request->engagement;
|
|
$anc_followup_record->position = $request->position;
|
|
$anc_followup_record->foetal_heart_rate = $request->foetal_heart_rate;
|
|
$anc_followup_record->foetal_heart_regularity = $request->foetal_heart_regularity;
|
|
$anc_followup_record->aph = $request->history_of_aph;
|
|
$anc_followup_record->aph_details = $request->aph_details;
|
|
$anc_followup_record->fits = $request->histoy_of_fits;
|
|
$anc_followup_record->fits_details = $request->fits_details;
|
|
$physical_exam['height'] =$request->height;
|
|
$physical_exam['weight'] =$request->weight;
|
|
$physical_exam['bmi'] =$request->bmi;
|
|
$physical_exam['muac'] =$request->muac;
|
|
$physical_exam['nut_status'] =$request->nut_status;
|
|
$physical_exam['temperature'] =$request->temperature;
|
|
$physical_exam['bp'] =$request->bp;
|
|
$physical_exam['pulse'] =$request->pulse;
|
|
$physical_exam['gait'] =$request->gait;
|
|
$physical_exam['oral'] =$request->oral;
|
|
$physical_exam['teeth'] =$request->teeth;
|
|
$physical_exam['neck'] =$request->neck;
|
|
$physical_exam['breasts'] =$request->breasts;
|
|
$physical_exam['legs'] =$request->legs;
|
|
$physical_exam['deformities'] =$request->deformities;
|
|
$physical_exam['lymph'] =$request->lymph;
|
|
$physical_exam['herpes'] =$request->herpes;
|
|
$physical_exam['anaemia'] =$request->anaemia;
|
|
$physical_exam['eyes'] =$request->eyes;
|
|
$physical_exam['nails'] =$request->nails;
|
|
$physical_exam['palms'] =$request->palms;
|
|
$physical_exam['jaundice'] =$request->jaundice;
|
|
$physical_exam['heart'] =$request->heart;
|
|
$physical_exam['lungs'] =$request->lungs;
|
|
$physical_exam['vulva'] =$request->vulva;
|
|
$physical_exam['vagina'] =$request->vagina;
|
|
$physical_exam['cervix'] =$request->cervix;
|
|
$physical_exam['vaginal_discharge'] =$request->vaginal_discharge;
|
|
$anc_followup_record->physical_exam = json_encode($physical_exam);
|
|
$symptoms_array = $request->symptoms;
|
|
$duration_array = $request->duration;
|
|
$time_array = $request->time;
|
|
|
|
// Build symptoms and duration variables
|
|
$symptoms = '';
|
|
$durations = '';
|
|
for ($x = 0; $x < count($symptoms_array); $x++) {
|
|
if ($x == (count($symptoms_array) - 1)) {
|
|
$symptoms .= $symptoms_array[$x];
|
|
$durations .= $duration_array[$x] . " " . $time_array[$x];
|
|
} else {
|
|
$symptoms .= $symptoms_array[$x] . ",";
|
|
$durations .= $duration_array[$x] . " " . $time_array[$x] . ",";
|
|
}
|
|
}
|
|
$anc_followup_record->symptoms = $symptoms;
|
|
$anc_followup_record->symptom_duration = $durations;
|
|
|
|
// $anc_followup_record->bp = $request->bp;
|
|
$anc_followup_record->scan_edd = is_null($request->scan_edd) ? null : Carbon::createFromFormat('d/m/Y', $request->scan_edd)->toDateString();
|
|
$anc_followup_record->gestation_from_edd = $request->gestation_from_edd;
|
|
$anc_followup_record->gestation_from_scan = $request->gestation_from_scan;
|
|
$anc_followup_record->gestation_from_fundal = $request->gestation_from_fundal_height;
|
|
//checklist items
|
|
$first_dose_ipt = isset($request->first_dose_ipt) ? $request->first_dose_ipt : '';
|
|
$second_dose_ipt = isset($request->second_dose_ipt) ? $request->second_dose_ipt : '';
|
|
$third_dose_ipt = isset($request->third_dose_ipt) ? $request->third_dose_ipt : '';
|
|
$fourth_dose_ipt = isset($request->fourth_dose_ipt) ? $request->fourth_dose_ipt : '';
|
|
$hiv_status = isset($request->hiv_status) ? $request->hiv_status : '';
|
|
$bed_net = isset($request->bed_net) ? $request->bed_net : '';
|
|
$iron_folic = isset($request->iron_folic) ? $request->iron_folic : '';
|
|
$vdrl = isset($request->vdrl) ? $request->vdrl : '';
|
|
$health_education = isset($request->health_education) ? $request->health_education : '';
|
|
$tetanus_toxoid = isset($request->tetanus_toxoid) ? $request->tetanus_toxoid : '';
|
|
|
|
$checklist = array($first_dose_ipt, $second_dose_ipt, $third_dose_ipt, $fourth_dose_ipt, $hiv_status, $bed_net, $iron_folic, $vdrl, $health_education, $tetanus_toxoid);
|
|
$anc_followup_record->checklist = json_encode($checklist);
|
|
$anc_followup_record->comments = $request->comments;
|
|
$anc_followup_record->history_comments = $request->history_comments;
|
|
$anc_followup_record->clinic_examination_comments = $request->clinic_examination_comments;
|
|
$anc_followup_record->investigation_and_management_plan_comments = $request->investigation_and_management_plan_comments;
|
|
$anc_followup_record->primary_diagnosis = $request->primary_diagnosis ?? NULL;
|
|
$anc_followup_record->other_diagnoses = $request->other_diagnosis ? implode(',', $request->other_diagnosis) : null;
|
|
/* check if any submit_btn(investigations,treatment,procedures,ultra_scan) button is clicked and set completion status to 0 i.s false */
|
|
$completed = isset($request->complete_btn) ? 1 : 0;
|
|
$anc_followup_record->completion_status = $completed;
|
|
$anc_followup_record->outcome_id = $request->outcome;
|
|
|
|
switch ($request->outcome):
|
|
case 1: //Admitted
|
|
$inpatient = new InpatientInfo;
|
|
$inpatient->patient_id = $patient_id;
|
|
$inpatient->episode_id = $episode_id;
|
|
$inpatient->admitted_on = !empty($request->admitted_on)? Carbon::createFromFormat('d/m/Y', $request->admitted_on)->toDateString() : date('Y-m-d');
|
|
$inpatient->ward_id = $request->ward_id;
|
|
$inpatient->primary_diagnosis = $request->primary_diagnosis;
|
|
$inpatient->other_diagnoses = serialize($request->other_diagnosis);
|
|
$inpatient->comments = $request->comments;
|
|
$inpatient->created_by = auth()->user()->id;
|
|
$inpatient->save();
|
|
|
|
|
|
|
|
$anc_followup_record->ward_id = $request->ward_id;
|
|
$anc_followup_record->admitted_on = !is_null($request->admitted_on) ? Carbon::createFromFormat('d/m/Y', $request->admitted_on)->toDateString() : null;
|
|
break;
|
|
case 3: // Home with followup
|
|
$anc_followup_record->followup_where = "Hospital";
|
|
$anc_followup_record->followup_when = !is_null($request->followup_when) ? Carbon::createFromFormat('d/m/Y', $request->followup_when)->toDateString() : null;
|
|
|
|
// save information to the follow-up table
|
|
$appointment = new \Streamline\Models\PatientAppointment();
|
|
$appointment->patient_id = $patient_id;
|
|
$appointment->incharge_id = $request->followup_in_charge;
|
|
$appointment->clinic_allocation = $request->followup_clinic_allocation;
|
|
$appointment->episode_id = $episode_id;
|
|
$appointment->appointment_date = !is_null($request->followup_when) ? Carbon::createFromFormat('d/m/Y', $request->followup_when)->toDateString() : null;
|
|
$appointment->appointment_time = $request->followup_in_time;
|
|
$appointment->created_from = "Antenatal";
|
|
$appointment->created_by = auth()->user()->id;
|
|
$appointment->save();
|
|
break;
|
|
case 4: // Referred
|
|
$anc_followup_record->referred_to = $request->referral_id;
|
|
break;
|
|
default:
|
|
break;
|
|
endswitch;
|
|
|
|
$anc_followup_record->created_by = auth()->user()->id;
|
|
/* if $resume is set and also equal to true, then update the record else insert a new one */
|
|
$save_or_update = isset($request->resume) ? $anc_followup_record->update() : $anc_followup_record->save();
|
|
$url = '';
|
|
//Store Delivery Plan details
|
|
if(!empty($request->delivery_plan_id)) {
|
|
$delivery_plan_record = AncDeliveryPlan::find($request->delivery_plan_id);
|
|
$delivery_plan_record->updated_by = auth()->user()->id;
|
|
}
|
|
else {
|
|
$delivery_plan_record = new AncDeliveryPlan();
|
|
$delivery_plan_record->created_by = auth()->user()->id;
|
|
}
|
|
$delivery_plan_record->patient_id = $patient_id;
|
|
$delivery_plan_record->episode_id = $episode_id;
|
|
$delivery_plan_record->registration_id = $request->anc_registration_id;
|
|
$delivery_plan_record->live_in_support = $request->live_in_support;
|
|
$delivery_plan_record->emergency_support = $request->emergency_support;
|
|
$delivery_plan_record->facility_stay = $request->facility_stay;
|
|
$delivery_plan_record->transport_means = $request->transport_means;
|
|
$delivery_plan_record->home_keeper = $request->home_keeper;
|
|
$delivery_plan_record->delivery_method = $request->delivery_method;
|
|
$delivery_plan_record->family_planning_method = $request->family_planning_method;
|
|
$delivery_plan_record->health_screening = !empty($request->health_screening)? implode(',', $request->health_screening):null;
|
|
$delivery_plan_record->disposal = $request->disposal;
|
|
$delivery_plan_record->save();
|
|
|
|
if(empty($request->complete_btn)) session()->put('anc_visit_redirect','anc_visits/'.$anc_followup_record->id.'/edit');
|
|
else {
|
|
if($save_or_update) flash('ANC record saved successfully')->success();
|
|
return self::view_anc_visit_details($anc_followup_record->id);
|
|
}
|
|
|
|
if ($save_or_update) {
|
|
/* redirect to the appropriate url after saving or updating the record depending on the clicked button */
|
|
switch ($request->submit_btn) {
|
|
case 'investigation':
|
|
$url = 'investigations/investigations_review';
|
|
break;
|
|
case 'treatment':
|
|
$url = 'prescriptions/create/';
|
|
break;
|
|
case 'procedures':
|
|
$url = 'order_procedures';
|
|
break;
|
|
case 'order_ultrasound':
|
|
$url = 'investigations/investigations_review_ultrasound_obstetric';
|
|
break;
|
|
default:
|
|
$url = 'patient_episodes';
|
|
break;
|
|
}
|
|
|
|
flash('ANC record saved successfully')->success();
|
|
return redirect($url);
|
|
}
|
|
|
|
flash('Error occured in trying to save the anc record')->error();
|
|
return redirect()->back()->withInput();
|
|
}
|
|
|
|
public function edit_anc_visit($id)
|
|
{
|
|
|
|
$data = $this->getAncVisitData();
|
|
$data['resume'] = TRUE;
|
|
$data['resume_anc_followup'] = AnteNatalClinicFollowup::find($id);
|
|
$data['visit_number'] = $data['resume_anc_followup']->ante_natal_clinic_visit_number;
|
|
$data['previous_anc_visits'] = AnteNatalClinicFollowup::where('patient_id', $data['patient_id'])->where('id','<>', $id)->orderBy('created_at', 'desc')->take(5)->get()->groupBy('ante_natal_clinic_registration_id');
|
|
|
|
return view('antenatal::ante_natal_clinic.antenatal_visit_edit', $data);
|
|
}
|
|
|
|
/* update an edited ANC visit a.k.a ANC followup */
|
|
public function update_anc_template(Request $request, $id)
|
|
{
|
|
$episode_id = session()->get('episode_id');
|
|
$patient_id = session()->get('patient_id');
|
|
$anc_followup_record = AnteNatalClinicFollowup::findOrFail($id);
|
|
$physical_exam = [];
|
|
$anc_followup_record->patient_id = $patient_id;
|
|
$anc_followup_record->episode_id = $episode_id;
|
|
$anc_followup_record->ante_natal_clinic_registration_id = $request->anc_registration_id;
|
|
$anc_followup_record->ante_natal_clinic_visit_number = $request->anc_visit_number;
|
|
$anc_followup_record->fundal_height = $request->fundal_height;
|
|
$anc_followup_record->lie = $request->lie;
|
|
$anc_followup_record->other_physicals = !empty($request->other_physicals)? implode(',', $request->other_physicals):null;
|
|
$anc_followup_record->presentation = $request->presentation;
|
|
$anc_followup_record->engagement = $request->engagement;
|
|
$anc_followup_record->position = $request->position;
|
|
$anc_followup_record->foetal_heart_rate = $request->foetal_heart_rate;
|
|
$anc_followup_record->foetal_heart_regularity = $request->foetal_heart_regularity;
|
|
$anc_followup_record->aph = $request->history_of_aph;
|
|
$anc_followup_record->aph_details = $request->aph_details;
|
|
$anc_followup_record->fits = $request->histoy_of_fits;
|
|
$anc_followup_record->fits_details = $request->fits_details;
|
|
$physical_exam['height'] =$request->height;
|
|
$physical_exam['weight'] =$request->weight;
|
|
$physical_exam['bmi'] =$request->bmi;
|
|
$physical_exam['muac'] =$request->muac;
|
|
$physical_exam['nut_status'] =$request->nut_status;
|
|
$physical_exam['temperature'] =$request->temperature;
|
|
$physical_exam['bp'] =$request->bp;
|
|
$physical_exam['pulse'] =$request->pulse;
|
|
$physical_exam['gait'] =$request->gait;
|
|
$physical_exam['oral'] =$request->oral;
|
|
$physical_exam['teeth'] =$request->teeth;
|
|
$physical_exam['neck'] =$request->neck;
|
|
$physical_exam['breasts'] =$request->breasts;
|
|
$physical_exam['legs'] =$request->legs;
|
|
$physical_exam['deformities'] =$request->deformities;
|
|
$physical_exam['lymph'] =$request->lymph;
|
|
$physical_exam['herpes'] =$request->herpes;
|
|
$physical_exam['anaemia'] =$request->anaemia;
|
|
$physical_exam['eyes'] =$request->eyes;
|
|
$physical_exam['nails'] =$request->nails;
|
|
$physical_exam['palms'] =$request->palms;
|
|
$physical_exam['jaundice'] =$request->jaundice;
|
|
$physical_exam['heart'] =$request->heart;
|
|
$physical_exam['lungs'] =$request->lungs;
|
|
$physical_exam['vulva'] =$request->vulva;
|
|
$physical_exam['vagina'] =$request->vagina;
|
|
$physical_exam['cervix'] =$request->cervix;
|
|
$physical_exam['vaginal_discharge'] =$request->vaginal_discharge;
|
|
$anc_followup_record->physical_exam = json_encode($physical_exam);
|
|
|
|
$symptoms_array = $request->symptoms;
|
|
$duration_array = $request->duration;
|
|
$time_array = $request->time;
|
|
// Build symptoms and duration variables as copied from Triage Controller
|
|
$symptoms = '';
|
|
$durations = '';
|
|
for ($x = 0; $x < count($symptoms_array); $x++) {
|
|
if ($x == (count($symptoms_array) - 1)) {
|
|
$symptoms .= $symptoms_array[$x];
|
|
$durations .= $duration_array[$x] . " " . $time_array[$x];
|
|
} else {
|
|
$symptoms .= $symptoms_array[$x] . ",";
|
|
$durations .= $duration_array[$x] . " " . $time_array[$x] . ",";
|
|
}
|
|
}
|
|
$anc_followup_record->symptoms = $symptoms;
|
|
$anc_followup_record->symptom_duration = $durations;
|
|
|
|
// $anc_followup_record->bp = $request->bp;
|
|
$anc_followup_record->scan_edd = is_null($request->scan_edd) ? null : Carbon::createFromFormat('d/m/Y', $request->scan_edd)->toDateString();
|
|
$anc_followup_record->gestation_from_edd = $request->gestation_from_edd;
|
|
$anc_followup_record->gestation_from_scan = $request->gestation_from_scan;
|
|
$anc_followup_record->gestation_from_fundal = $request->gestation_from_fundal_height;
|
|
//checklist items
|
|
$first_dose_ipt = isset($request->first_dose_ipt) ? $request->first_dose_ipt : '';
|
|
$second_dose_ipt = isset($request->second_dose_ipt) ? $request->second_dose_ipt : '';
|
|
$third_dose_ipt = isset($request->third_dose_ipt) ? $request->third_dose_ipt : '';
|
|
$fourth_dose_ipt = isset($request->fourth_dose_ipt) ? $request->fourth_dose_ipt : '';
|
|
$hiv_status = isset($request->hiv_status) ? $request->hiv_status : '';
|
|
$bed_net = isset($request->bed_net) ? $request->bed_net : '';
|
|
$iron_folic = isset($request->iron_folic) ? $request->iron_folic : '';
|
|
$vdrl = isset($request->vdrl) ? $request->vdrl : '';
|
|
$health_education = isset($request->health_education) ? $request->health_education : '';
|
|
$tetanus_toxoid = isset($request->tetanus_toxoid) ? $request->tetanus_toxoid : '';
|
|
|
|
$checklist = array($first_dose_ipt, $second_dose_ipt, $third_dose_ipt, $fourth_dose_ipt, $hiv_status, $bed_net, $iron_folic, $vdrl, $health_education, $tetanus_toxoid);
|
|
$anc_followup_record->checklist = json_encode($checklist);
|
|
$anc_followup_record->comments = $request->comments;
|
|
$anc_followup_record->history_comments = $request->history_comments;
|
|
$anc_followup_record->clinic_examination_comments = $request->clinic_examination_comments;
|
|
$anc_followup_record->investigation_and_management_plan_comments = $request->investigation_and_management_plan_comments;
|
|
$anc_followup_record->primary_diagnosis = $request->primary_diagnosis;
|
|
$anc_followup_record->other_diagnoses = (!empty($request->other_diagnosis[0])) ? implode(',', $request->other_diagnosis) : null;
|
|
/* check if any submit_btn(investigations,treatment,procedures,ultra_scan) button is clicked and set completion status to 0 i.s false */
|
|
$completed = isset($request->complete_btn) ? 1 : 0;
|
|
$anc_followup_record->completion_status = $completed;
|
|
|
|
$anc_followup_record->outcome_id = $request->outcome;
|
|
|
|
switch ($request->outcome):
|
|
case 1: //Admitted
|
|
$inpatient_info = InpatientInfo::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'discharged' => 0])->orderBy('created_at', 'desc')->first();
|
|
if ($inpatient_info) {
|
|
$inpatient_info->ward_id = $request->ward_id;
|
|
$inpatient_info->updated_by = auth()->user()->id;
|
|
$inpatient_info->save();
|
|
} else {
|
|
$inpatient = new InpatientInfo;
|
|
$inpatient->patient_id = $patient_id;
|
|
$inpatient->episode_id = $episode_id;
|
|
$inpatient->admitted_on = !empty($request->admitted_on)? Carbon::createFromFormat('d/m/Y', $request->admitted_on)->toDateString() : date('Y-m-d');
|
|
$inpatient->ward_id = $request->ward_id;
|
|
$inpatient->primary_diagnosis = $request->primary_diagnosis;
|
|
$inpatient->other_diagnoses = serialize($request->other_diagnosis);
|
|
$inpatient->comments = $request->comments;
|
|
$inpatient->created_by = auth()->user()->id;
|
|
$inpatient->save();
|
|
}
|
|
|
|
$anc_followup_record->ward_id = $request->ward_id;
|
|
$anc_followup_record->admitted_on = !is_null($request->admitted_on) ? Carbon::createFromFormat('d/m/Y', $request->admitted_on)->toDateString() : null;
|
|
break;
|
|
case 3: // Home with followup
|
|
/*$anc_followup_record->followup_where = $request->followup_where;
|
|
$anc_followup_record->followup_when = !is_null($request->followup_when) ? Carbon::createFromFormat('d/m/Y',$request->followup_when)->toDateString() : null;*/
|
|
$anc_followup_record->followup_where = "Hospital";
|
|
$anc_followup_record->followup_when = !is_null($request->followup_when) ? Carbon::createFromFormat('Y-m-d', $request->followup_when)->toDateString() : null;
|
|
|
|
// save information to the follow-up table
|
|
$patient_appointment = \Streamline\Models\PatientAppointment::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
|
|
$appointment = $patient_appointment ? $patient_appointment : new \Streamline\Models\PatientAppointment();
|
|
$appointment->patient_id = $patient_id;
|
|
$appointment->incharge_id = $request->followup_in_charge;
|
|
$appointment->clinic_allocation = $request->followup_clinic_allocation;
|
|
$appointment->episode_id = $episode_id;
|
|
$appointment->appointment_date = !is_null($request->followup_when) ? Carbon::createFromFormat('Y-m-d', $request->followup_when)->toDateString() : null;
|
|
$appointment->appointment_time = $request->followup_in_time;
|
|
$appointment->created_from = "Antenatal";
|
|
$appointment->created_by = auth()->user()->id;
|
|
$appointment->updated_by = auth()->user()->id;
|
|
$appointment->save();
|
|
break;
|
|
case 4: // Referred
|
|
$anc_followup_record->referred_to = $request->referral_id;
|
|
break;
|
|
default:
|
|
break;
|
|
endswitch;
|
|
|
|
$anc_followup_record->updated_by = auth()->user()->id;
|
|
$save_or_update = $anc_followup_record->save();
|
|
$url = '';
|
|
//Store Delivery Plan details
|
|
if(!empty($request->delivery_plan_id)) {
|
|
$delivery_plan_record = AncDeliveryPlan::find($request->delivery_plan_id);
|
|
$delivery_plan_record->updated_by = auth()->user()->id;
|
|
}
|
|
else {
|
|
$delivery_plan_record = new AncDeliveryPlan();
|
|
$delivery_plan_record->created_by = auth()->user()->id;
|
|
$delivery_plan_record->patient_id = $patient_id;
|
|
$delivery_plan_record->episode_id = $episode_id;
|
|
$delivery_plan_record->registration_id = $request->anc_registration_id;
|
|
}
|
|
$delivery_plan_record->live_in_support = $request->live_in_support;
|
|
$delivery_plan_record->emergency_support = $request->emergency_support;
|
|
$delivery_plan_record->facility_stay = $request->facility_stay;
|
|
$delivery_plan_record->transport_means = $request->transport_means;
|
|
$delivery_plan_record->home_keeper = $request->home_keeper;
|
|
$delivery_plan_record->delivery_method = $request->delivery_method;
|
|
$delivery_plan_record->family_planning_method = $request->family_planning_method;
|
|
$delivery_plan_record->health_screening = !empty($request->health_screening)? implode(',', $request->health_screening):null;
|
|
$delivery_plan_record->disposal = $request->disposal;
|
|
$delivery_plan_record->save();
|
|
|
|
if(empty($request->complete_btn)) session()->put('anc_visit_redirect','anc_visits/'.$anc_followup_record->id.'/edit');
|
|
else {
|
|
if($save_or_update) flash('ANC record saved successfully')->success();
|
|
return self::view_anc_visit_details($anc_followup_record->id);
|
|
}
|
|
|
|
if ($save_or_update) {
|
|
/* redirect to the appropriate url after saving or updating the record depending on the clicked button */
|
|
switch ($request->submit_btn) {
|
|
case 'investigation':
|
|
$url = 'investigations/investigations_review';
|
|
break;
|
|
case 'treatment':
|
|
$url = 'prescriptions/create/';
|
|
break;
|
|
case 'procedures':
|
|
$url = 'order_procedures';
|
|
break;
|
|
case 'order_ultrasound':
|
|
$url = 'investigations/investigations_review_ultrasound_obstetric';
|
|
break;
|
|
default:
|
|
$url = 'patient_episodes';
|
|
break;
|
|
}
|
|
|
|
flash('ANC record saved successfully')->success();
|
|
return redirect($url);
|
|
}
|
|
|
|
flash('Error occured in trying to save the anc record')->error();
|
|
return redirect()->back()->withInput();
|
|
}
|
|
|
|
/* check if a pregnancy for that antenatal episode is registered. To record an Antenatal visit, thats epsiode
|
|
* must have a record in the the ANC registration table
|
|
*/
|
|
public function check_anc_registration()
|
|
{
|
|
$patient_id = session()->get('patient_id');
|
|
$anc_registration_record = AnteNatalClinicRegistration::where('patient_id', $patient_id)->latest()->first();
|
|
if (!empty($anc_registration_record)) {
|
|
$edd = Carbon::parse($anc_registration_record->edd);
|
|
$date_latest = $edd->addWeeks(6);
|
|
if (Carbon::now() < $date_latest) return "true";
|
|
else return "false";
|
|
}
|
|
else return "false";
|
|
}
|
|
|
|
public function view_anc_visit_details($id)
|
|
{
|
|
$patient_id = session()->get('patient_id');
|
|
$episode_id = session()->get('episode_id');
|
|
|
|
$visit_record_details = AnteNatalClinicFollowup::findOrFail($id);
|
|
|
|
$patient = Patient::find($patient_id);
|
|
$diagnoses = DB::table('diagnoses')->whereNull('deleted_at')->orderBy('name', 'asc')->pluck("name", "id");
|
|
$outcomes = DB::table('outcomes')->whereNull('deleted_at')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
|
|
$anc_lies = AnteNatalClinicLie::pluck('name', 'id');
|
|
$anc_presentations = AnteNatalClinicPresentation::pluck('name', 'id');
|
|
$anc_positions = AnteNatalClinicPosition::pluck('name', 'id');
|
|
$anc_engagements = AnteNatalClinicEngagement::pluck('name', 'id');
|
|
$anc_registration = AnteNatalClinicRegistration::where(['patient_id' => $patient_id])->latest()->first();
|
|
$delivery_plan = AncDeliveryPlan::where(['patient_id' => $patient_id, 'episode_id' => $anc_registration->episode_id])->first();
|
|
return view('antenatal::ante_natal_clinic.antenatal_visit_details', compact('patient_id', 'episode_id', 'delivery_plan', 'anc_lies', 'anc_presentations', 'anc_positions', 'anc_engagements', 'visit_record_details', 'outcomes', 'patient', 'diagnoses'));
|
|
}
|
|
|
|
public function route()
|
|
{
|
|
/*
|
|
* Check if a consultation is pending and then route it to edit page
|
|
* If a consultation is completed, route to the view page
|
|
*/
|
|
|
|
$patient_id = session()->get('patient_id');
|
|
$episode_id = session()->get('episode_id');
|
|
|
|
$existing_anc_registration = AnteNatalClinicRegistration::where(['patient_id' => $patient_id])->latest()->first();
|
|
session()->put('previous_action', 'anc_consultation_page');
|
|
if ($existing_anc_registration) {
|
|
$edd = Carbon::parse($existing_anc_registration->edd);
|
|
$date_latest = $edd->addMonths(6);
|
|
if (Carbon::now() > $date_latest) return self::create();
|
|
else {
|
|
switch ($existing_anc_registration->completed) {
|
|
case '0': // Pending
|
|
return self::edit($existing_anc_registration->id);
|
|
break;
|
|
case '1': // Completed
|
|
return self::show($existing_anc_registration->id);
|
|
break;
|
|
default: // Not created yet
|
|
return self::create();
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
return self::create();
|
|
}
|
|
}
|
|
|
|
public function calculate_edd_from_lmp(Request $request)
|
|
{
|
|
$lmp_date = $request->lmp_date;
|
|
$lmp_date = Carbon::createFromFormat('d/m/Y', $request->lmp_date);
|
|
$edd = $lmp_date->addDays(280);
|
|
$edd = $edd->toDateString();
|
|
|
|
$date = date("d/m/Y", strtotime($edd));
|
|
|
|
return response()->json($date);
|
|
}
|
|
|
|
public function calculate_woa_weeks_from_lmp(Request $request){
|
|
$lmp_date = Carbon::createFromFormat('d/m/Y', $request->lmp_date);
|
|
$now = Carbon::now();
|
|
$days = $lmp_date->diffInDays($now);
|
|
$weeks = floor($days / 7);
|
|
$dayRemainder = $days % 7;
|
|
$woa_weeks = $weeks.'<sup>'.$dayRemainder.'</sup>';
|
|
return response()->json($woa_weeks);
|
|
}
|
|
|
|
public function add_uterus_operation(Request $request)
|
|
{
|
|
|
|
$referral_hospital = new UterusOperation;
|
|
$referral_hospital->name = $request->name;
|
|
$referral_hospital->created_by = Auth()->user()->id;
|
|
|
|
if ($referral_hospital->save()) return $referral_hospital->id;
|
|
else return 0;
|
|
}
|
|
|
|
public function add_family_planning_method(Request $request)
|
|
{
|
|
|
|
$method = new FamilyPlanningMethod;
|
|
$method->name = $request->name;
|
|
$method->created_by = Auth()->user()->id;
|
|
|
|
if ($method->save()) return $method->id;
|
|
else return 0;
|
|
}
|
|
|
|
public function add_gender_based_violence(Request $request)
|
|
{
|
|
|
|
$referral_hospital = new GenderViolence;
|
|
$referral_hospital->name = $request->name;
|
|
$referral_hospital->created_by = Auth()->user()->id;
|
|
|
|
if ($referral_hospital->save()) return $referral_hospital->id;
|
|
else return 0;
|
|
}
|
|
|
|
public function add_caesarian_section(Request $request)
|
|
{
|
|
|
|
$referral_hospital = new CaesarianSection();
|
|
$referral_hospital->name = $request->name;
|
|
$referral_hospital->created_by = Auth()->user()->id;
|
|
|
|
if ($referral_hospital->save()) return $referral_hospital->id;
|
|
else return 0;
|
|
}
|
|
|
|
/**
|
|
* Display a listing of all ante natal visits.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function previously_registered_pregnancy_anc_visits(Request $request)
|
|
{
|
|
$episode_id = session()->get('episode_id');
|
|
$patient_id = session()->get('patient_id');
|
|
$patient = Patient::find($patient_id);
|
|
$pregnancy_ids=unserialize($request->visits);
|
|
$categories = DB::table('patient_categories')->pluck("name", "id");
|
|
$marital_statuses = DB::table('marital_statuses')->pluck("name", "id");
|
|
$drug_categories = DB::table('drug_categories')->get();
|
|
$documents = PatientDocument::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$known_patient_allergies = Allergy::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$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');
|
|
|
|
$anc_followup_records = AnteNatalClinicFollowup::whereIn('id', $pregnancy_ids)->orderBy('created_at', 'desc')->get()->groupBy('ante_natal_clinic_registration_id');
|
|
return view('antenatal::ante_natal_clinic.index_visits', compact('patient_id', 'patient', 'anc_followup_records', 'categories', 'marital_statuses', 'drug_categories', 'documents', 'known_patient_allergies', 'known_patient_alerts', 'drug_categories_array'));
|
|
}
|
|
|
|
public function antenatal_card(){
|
|
$episode_id = session()->get('episode_id');// Get episode id from session
|
|
$patient_id = session()->get('patient_id');// Get patient id from session
|
|
$anc_registration_details = AnteNatalClinicRegistration::where([['patient_id', $patient_id], ['episode_id', $episode_id]])->first();
|
|
if(empty($anc_registration_details)) {
|
|
flash('No Pregnancy Registered for this episode.')->error();
|
|
return redirect()->back();
|
|
}
|
|
$patient = Patient::where('patients.id',$patient_id)->leftJoin('districts','districts.id','district_id')->leftJoin('subcounties','subcounties.id','subcounty_id')->leftJoin('parishes','parishes.id','parish_id')->leftJoin('villages','villages.id','village_id')
|
|
->leftJoin('occupations','occupations.id','occupation_id')->leftJoin('family_relations','family_relations.id','next_of_kin_relationship')->leftJoin('marital_statuses','marital_statuses.id','marital_status')->leftJoin('religions','religions.id','religion_id')
|
|
->first(['villages.name as village','districts.name as district','subcounties.name as subcounty','parishes.name as parish','occupations.name as occupation', 'family_relations.name as family_relation','marital_statuses.name as marital_status','religions.name as religion',
|
|
'first_name', 'last_name', 'national_id','phone','date_of_birth','next_of_kin','phone_of_next_of_kin']);
|
|
$mother_history = AntenatalMotherHistory::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
|
|
$family_planning_methods = FamilyPlanningMethod::orderBy('name', 'asc')->pluck("name", "id");
|
|
$gender_based_violence = GenderViolence::orderBy('name', 'asc')->pluck("name", "id");
|
|
$triage = Triage::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
|
|
$obstetric_history_details = ObstetricHistory::where(['patient_id' => $patient_id])->orderBy('obstetric_date', 'desc')->get();
|
|
$hospitalInfo = DB::table('hospital_information')->find(1);
|
|
$anc_visits = AnteNatalClinicFollowup::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
$latest_anc_visit = $anc_visits->last();
|
|
$anc_presentations = AnteNatalClinicPresentation::pluck('name', 'id');
|
|
$anc_lies = AnteNatalClinicLie::pluck('name', 'id');
|
|
$anc_positions = AnteNatalClinicPosition::pluck('name', 'id');
|
|
$users = DB::table('users')->pluck(DB::raw("CONCAT(first_name,' ',last_name) AS name"), 'id');
|
|
$obs_scan_results = InvestigationResults::leftJoin('obstetric_ultrasound_reports as o','o.order_id','investigation_results.order_id')
|
|
->where(['patient_id'=>$patient_id, 'episode_id'=>$episode_id,'result_type'=>'Ultrasound_Obstetric', 'all_authenticated'=>1])
|
|
->select('o.*')->get();
|
|
$treatments = Treatment::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'tta' => 0])->get();
|
|
$dosage_frequencies = DB::table('dosage_frequencies')->pluck('name', 'id');
|
|
$drugs =Drug::pluck('name', 'id');
|
|
$malaria_investigations =Investigation::whereIn('hmis_002_slug', [2,3])->pluck('id')->toArray();
|
|
$malaria_ids = $malaria_inv_result = '';
|
|
foreach($malaria_investigations as $key => $malaria_investigation) {
|
|
if($key == 0) $malaria_ids .= 'FIND_IN_SET('.$malaria_investigation.',investigation_id)';
|
|
else $malaria_ids .= 'OR FIND_IN_SET('.$malaria_investigation.',investigation_id)';
|
|
}
|
|
if(!empty( $malaria_ids)){
|
|
$query = 'SELECT `id`, `investigation_id`, `value` FROM `investigation_results` WHERE `patient_id` = '.$patient_id.' AND `episode_id` = '.$episode_id.' AND `all_authenticated`= 1 AND `deleted_at` IS NULL AND ('.$malaria_ids.') ORDER BY `id` DESC LIMIT 1';
|
|
$results = DB::select($query);
|
|
if(!empty($results[0])){
|
|
$ids = explode(',', $results[0]->investigation_id);
|
|
$values = explode(',', $results[0]->value);
|
|
$id = array_search($malaria_investigation, $ids);
|
|
$malaria_inv_result = strtolower($values[$id]);
|
|
}
|
|
}
|
|
$results = InvestigationResults::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->latest()->first();
|
|
$data = ['patient', 'anc_registration_details', 'mother_history', 'family_planning_methods', 'gender_based_violence', 'triage',
|
|
'obstetric_history_details', 'hospitalInfo', 'anc_visits', 'latest_anc_visit', 'anc_presentations', 'anc_lies', 'anc_positions',
|
|
'users', 'obs_scan_results', 'treatments', 'dosage_frequencies', 'drugs', 'malaria_inv_result'];
|
|
|
|
// return view('antenatal::ante_natal_clinic.anc_card', compact($data));
|
|
|
|
$pdf = SnappyPDF::loadView('antenatal::ante_natal_clinic.anc_card', compact($data))
|
|
->setOrientation('portrait')
|
|
->setPaper('a4')
|
|
->setOption('margin-bottom', 5)
|
|
->setOption('margin-top', 5)
|
|
->setOption('footer-html', '<i>'.config('app.name').' - Printed On ' . streamline_date(date('Y-m-d')) . ' By ' . auth()->user()->first_name . " " . auth()->user()->last_name . '</i>');
|
|
return $pdf->inline('ANC Card' . date(" d-m-y h:ia") . '.pdf');
|
|
|
|
|
|
}
|
|
|
|
private function getAncVisitData(){
|
|
$episode_id = session()->get('episode_id');
|
|
$patient_id = session()->get('patient_id');
|
|
$patient = Patient::findOrFail($patient_id);
|
|
$dob = new Carbon($patient->date_of_birth);
|
|
$age_diff_months = $dob->diffInMonths(Carbon::now());
|
|
$categories = DB::table('patient_categories')->pluck("name", "id");
|
|
$diagnoses = DB::table('diagnoses')->whereNull('deleted_at')->orderBy('name', 'asc')->pluck("name", "id")->prepend('- select -', '');
|
|
$marital_statuses = DB::table('marital_statuses')->pluck("name", "id");
|
|
$drug_categories = DB::table('drug_categories')->get();
|
|
$symptoms = DB::table('symptoms')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
//select treatment
|
|
$treatment = Treatment::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'tta' => 0])->first();
|
|
$documents = PatientDocument::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$known_patient_allergies = Allergy::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$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');
|
|
$wards = DB::table('wards')->whereNull('deleted_at')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
$referrals = DB::table('referral_hospitals')->whereNull('deleted_at')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
//drop down values
|
|
$anc_lies = AnteNatalClinicLie::pluck('name', 'id')->prepend('- select -', '');
|
|
$anc_presentations = AnteNatalClinicPresentation::pluck('name', 'id')->prepend('- select -', '');
|
|
$anc_positions = AnteNatalClinicPosition::pluck('name', 'id')->prepend('- select -', '');
|
|
$anc_engagements = AnteNatalClinicEngagement::pluck('name', 'id')->prepend('- select -', '');
|
|
$heart_regularity = HeartRegularity::pluck('name', 'id')->prepend('- select -', '');
|
|
$symptoms = DB::table('symptoms')->orderBy('name')->pluck("name", "id")->toArray();
|
|
$symptoms = ['' => '- select -'] + $symptoms;
|
|
$outcomes = DB::table('outcomes')->whereNull('deleted_at')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
$anc_registration = AnteNatalClinicRegistration::where(['patient_id' => $patient_id])->orderBy('id', 'desc')->first();
|
|
$delivery_plan = AncDeliveryPlan::where(['patient_id' => $patient_id, 'episode_id' => $anc_registration->episode_id])->first();
|
|
$triage = Triage::where(['patient_id' => $patient_id, 'episode_id' => $anc_registration->episode_id])->first();
|
|
$obs_scan_results = InvestigationResults::leftJoin('obstetric_ultrasound_reports as o','o.order_id','investigation_results.order_id')
|
|
->where(['patient_id'=>$patient_id, 'episode_id'=>$anc_registration->episode_id,'result_type'=>'Ultrasound_Obstetric', 'all_authenticated'=>1])
|
|
->latest('o.created_at')->first(['expected_delivery_date', 'average_gestational_age', 'o.id']);
|
|
|
|
//check if there exists anc visit records of this episode already
|
|
$anc_visit_records = AnteNatalClinicFollowup::where(['episode_id' => $episode_id, 'completion_status' => 1])->get();
|
|
$obstetric_history_details = ObstetricHistory::where(['patient_id' => $patient_id])->orderBy('obstetric_date', 'desc')->get();
|
|
|
|
$clinics = Clinic::orderBy('name')->pluck("name", "id")->toArray();
|
|
$clinics = ['0' => "Don't assign clinic"] + $clinics;
|
|
$users = \Streamline\Models\User::orderBy('first_name')->select("id", "first_name", "last_name")->get();
|
|
|
|
/* episode details */
|
|
$episode = PatientEpisode::where('id', $episode_id)->first();
|
|
/* get treatment */
|
|
$treatments = Treatment::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'tta' => 0])->get();
|
|
/* get ordered procedures */
|
|
$ordered_procedures = OrderedProcedure::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
//check for ordered investigations,procedures and treatment
|
|
$ordered_investigations = OrderedInvestigation::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
/* get ordered sundries */
|
|
$ordered_sundries = OrderedSundry::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
//check for authenticated investigations
|
|
$investigation_results = InvestigationResults::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
$diagnoses_all = DB::table('diagnoses')->select('id', 'prompts', 'reference_areas', 'reference_names')->get();
|
|
$hmis_categories = DB::table('hmis_categories')->orderBy('title', 'asc')->pluck('title', 'id')->toArray();
|
|
$hmis_categories = ['' => '- select -'] + $hmis_categories;
|
|
|
|
$inpatient_info = InpatientInfo::where('patient_id', $patient_id)->where('discharged', 0)->count();
|
|
$visit_data = [
|
|
'episode_id' => $episode_id,
|
|
'patient_id' => $patient_id,
|
|
'patient' => $patient,
|
|
'age_diff_months' => $age_diff_months,
|
|
'categories' => $categories,
|
|
'diagnoses' => $diagnoses,
|
|
'marital_statuses' => $marital_statuses,
|
|
'drug_categories' => $drug_categories,
|
|
'symptoms' => $symptoms,
|
|
'outcomes' => $outcomes,
|
|
'anc_registration' => $anc_registration,
|
|
'delivery_plan' => $delivery_plan,
|
|
'triage' => $triage,
|
|
'obs_scan_results' => $obs_scan_results,
|
|
'known_patient_allergies' => $known_patient_allergies,
|
|
'known_patient_alerts' => $known_patient_alerts,
|
|
'drug_categories_array' => $drug_categories_array,
|
|
'wards' => $wards,
|
|
'referrals' => $referrals,
|
|
'anc_lies' => $anc_lies,
|
|
'anc_presentations' => $anc_presentations,
|
|
'anc_positions' => $anc_positions,
|
|
'anc_engagements' => $anc_engagements,
|
|
'heart_regularity' => $heart_regularity,
|
|
'diagnoses_all' => $diagnoses_all,
|
|
'hmis_categories' => $hmis_categories,
|
|
'inpatient_info' => $inpatient_info,
|
|
'treatment' => $treatment,
|
|
'documents' => $documents,
|
|
'ordered_procedures' => $ordered_procedures,
|
|
'ordered_investigations' => $ordered_investigations,
|
|
'ordered_sundries' => $ordered_sundries,
|
|
'investigation_results' => $investigation_results,
|
|
'clinics' => $clinics,
|
|
'users' => $users,
|
|
'episode' => $episode,
|
|
'treatments' => $treatments,
|
|
'anc_visit_records' => $anc_visit_records,
|
|
'obstetric_history_details' => $obstetric_history_details,
|
|
'outcomes' => $outcomes,
|
|
|
|
];
|
|
|
|
return $visit_data;
|
|
}
|
|
}
|