public function addMedicalRecordCreate()
 {
     $validator = Validator::make(Input::all(), array('HN' => 'min:8|hn_exist|have_appointment_with_me|already_addmedicalrecord'), array('HN.min' => 'ท่านกรอก HN ของผู้ป่วยไม่ครบ', 'HN.hn_exist' => 'HN ที่ท่านกรอกไม่ตรงกับผู้ป่วยใดของโรงพยาบาล', 'HN.have_appointment_with_me' => 'ผู้ป่วยคนนี้ไม่ได้นัดกับท่านไว้ในช่วงเวลานี้', 'HN.already_addmedicalrecord' => 'ท่านได้ทำการบันทึกการรักษาผู้ป่วยคนนี้ไปแล้ว'));
     if ($validator->passes()) {
         $n = Input::get('ICD10');
         $diseases = DB::table('ICD10_Disease')->get();
         $i = 0;
         foreach ($diseases as $disease) {
             if ($i++ == $n) {
                 $ICD10 = $disease->ICD10;
                 break;
             }
         }
         date_default_timezone_set('Asia/Bangkok');
         $date = date("Y-m-d", time());
         $time = date("H:i:s", time());
         $morning = 1;
         if ((int) date("H", time()) < 12) {
             $morning = 0;
         }
         DB::table('appointments')->where('HN', Input::get('HN'))->where('appointmentDate', $date)->where('morning', $morning)->update(array('addMedicalRecordTime' => $time));
         $addMedicalRecord = new MedicalRecord();
         $addMedicalRecord->HN = Input::get('HN');
         $addMedicalRecord->doctorEmpID = Session::get('username');
         date_default_timezone_set('Asia/Bangkok');
         $addMedicalRecord->date = $date;
         $addMedicalRecord->time = $time;
         $addMedicalRecord->symptom = Input::get('symptom');
         $addMedicalRecord->ICD10 = $ICD10;
         $addMedicalRecord->save();
         return Redirect::to('doctor/addMedicalRecord')->with('flash_notice', 'ดำเนินการบันทึกการรักษาสำเร็จ');
     } else {
         return Redirect::to('doctor/addMedicalRecord')->withErrors($validator)->withInput();
     }
 }
 public function createMedicalRecord(Request $request)
 {
     try {
         $strStatus;
         $medicalRecord = new MedicalRecord();
         $medicalRecord->patientIdFK = $request->patientId_diagnosis;
         $medicalRecord->txtDiagnosis = $request->txtDiagnosis;
         $strStatus = $medicalRecord->createMedicalRecord();
     } catch (Exception $e) {
         dd($e);
         $strStatus = "error";
     }
     if ($strStatus === "success") {
         return redirect()->action('PatientController@getAllPatient');
     }
 }
 public function update(Request $request, $id)
 {
     $member = Member::find($id);
     $medicalrecord = MedicalRecord::firstOrCreate(['member_id' => $member->id]);
     $medicalrecord->fill($request->all());
     $medicalrecord->member()->associate($member);
     $medicalrecord->save();
     Flash::success("<b>¡Se ha actualizado la ficha medica de " . $member->first_name . " de manera exitosa!</b>");
     return redirect()->route('admin.member.show', $member->id);
 }
 public static function getAllMedicalRecord($id)
 {
     return MedicalRecord::where('patientIdFK', $id)->get();
 }
 public function viewMedicalHistory(Request $request)
 {
     $patient = Patient::getPatient($request->patientId);
     $medicalRecords = MedicalRecord::getAllMedicalRecord($patient->patientId);
     return response()->json($medicalRecords);
 }
 public function addMedicalRecordAndPrescribeCreate()
 {
     date_default_timezone_set('Asia/Bangkok');
     $date = date("Y-m-d", time());
     $time = date("H:i:s", time());
     $morning = 1;
     if ((int) date("H", time()) < 12) {
         $morning = 0;
     }
     $Drugs = Input::get('D');
     if (count($Drugs) > 0) {
         foreach ($Drugs as $Drug) {
             $i = 0;
             foreach ($Drug as $D) {
                 $i++;
                 if ($i == 1) {
                     $HN = $D;
                 } else {
                     if ($i == 6) {
                         $drugName = $D;
                     } else {
                         if ($i == 7) {
                             $quantity = $D;
                         } else {
                             if ($i == 8) {
                                 $description = $D;
                             }
                         }
                     }
                 }
             }
             $addPrescribedDrug = new PrescribedDrug();
             $addPrescribedDrug->HN = $HN;
             $addPrescribedDrug->doctorEmpID = Session::get('username');
             $addPrescribedDrug->date = $date;
             $addPrescribedDrug->time = $time;
             $addPrescribedDrug->drugName = $drugName;
             $addPrescribedDrug->quantity = $quantity;
             $addPrescribedDrug->description = $description;
             $addPrescribedDrug->save();
         }
     }
     $pharmacists = DB::table('pharmacistQueue')->get();
     $prev = 0;
     foreach ($pharmacists as $pharmacist) {
         $firstPharmacist = $pharmacist->pharmacistEmpID;
         break;
     }
     foreach ($pharmacists as $pharmacist) {
         if ($prev == 1) {
             $pharmacistEmpID = $pharmacist->pharmacistEmpID;
             $prev = 0;
             break;
         }
         $prev = $pharmacist->queue;
     }
     if ($prev == 1) {
         $pharmacistEmpID = $firstPharmacist;
     }
     DB::table('pharmacistQueue')->where('queue', 1)->update(array('queue' => 0));
     DB::table('pharmacistQueue')->where('pharmacistEmpID', $pharmacistEmpID)->update(array('queue' => 1));
     DB::table('appointments')->where('HN', Input::get("patientHN"))->where('doctorEmpID', Session::get('username'))->where('appointmentDate', $date)->where('morning', $morning)->update(array('addMedicalRecordTime' => $time, 'prescribedTime' => $time, 'pharmacistEmpID' => $pharmacistEmpID));
     $addMedicalRecord = new MedicalRecord();
     $addMedicalRecord->HN = Input::get("patientHN");
     $addMedicalRecord->doctorEmpID = Session::get('username');
     $addMedicalRecord->date = $date;
     $addMedicalRecord->time = $time;
     $addMedicalRecord->symptom = Input::get('symptom');
     $addMedicalRecord->ICD10 = substr(Input::get('ICD10'), 0, strpos(Input::get('ICD10'), " "));
     $addMedicalRecord->save();
     return Redirect::to('doctor/addMedicalRecordAndPrescribe')->with('flash_notice', 'ดำเนินการบันทึกการรักษาและสั่งยาสำเร็จ');
 }