Example #1
0
 public function post_user_soap(Request $request)
 {
     $uuid = Session::get('uuid');
     $uid = Auth::user()->id;
     $calendar_date = Session::get('calendar_date');
     $user_soap = UserSoap::where('hospital_no_uuid', '=', $uuid)->first();
     $user_id = Auth::User()->id;
     $bsugar = HospitalNo::find($uuid)->blood_sugar()->where('calendar_date', '=', $calendar_date)->first();
     DB::beginTransaction();
     try {
         if ($bsugar == null && $calendar_date != null) {
             $bsugar = new BloodSugar();
             $bsugar->calendar_date = $calendar_date;
             $bsugar->early_morning = null;
             $bsugar->morning = null;
             $bsugar->breakfast_before = null;
             $bsugar->breakfast_after = null;
             $bsugar->lunch_before = null;
             $bsugar->lunch_after = null;
             $bsugar->dinner_before = null;
             $bsugar->dinner_after = null;
             $bsugar->sleep_before = null;
             $bsugar->note = null;
             $bsugar->hospital_no_uuid = $uuid;
             $bsugar->user_id = $user_id;
             $bsugar->save();
         } else {
             if ($user_soap == null) {
                 $user_soap = new UserSoap();
             }
             $user_soap->hospital_no_uuid = $uuid;
             $user_soap->s_text = $request->s_text;
             $user_soap->o_text = $request->o_text;
             $user_soap->a_text = $request->a_text;
             $user_soap->p_text = $request->p_text;
             $user_soap->e_text = $request->e_text;
             $user_soap->r_text = $request->r_text;
             $user_soap->health_date = $request->health_date;
             $user_soap->soa_nurse_class_pks = $request->soa_nurse_class_pks;
             if (isset($request["confirm"]) && $request->confirm == "true") {
                 $user_soap->is_finished = true;
             } else {
                 $user_soap->is_finished = false;
             }
             $user_soap->save();
         }
         $user_soap_history = new UserSoapHistory();
         $user_soap_history->s_text = $request->s_text;
         $user_soap_history->o_text = $request->o_text;
         $user_soap_history->a_text = $request->a_text;
         $user_soap_history->p_text = $request->p_text;
         $user_soap_history->e_text = $request->e_text;
         $user_soap_history->r_text = $request->r_text;
         $user_soap_history->health_date = $request->health_date;
         $user_soap_history->user_id = Auth::user()->id;
         $user_soap_history->created_at = $user_soap->created_at;
         $user_soap_history->soa_nurse_class_pks = $request->soa_nurse_class_pks;
         if (isset($request["confirm"]) && $request->confirm == "true") {
             $user_soap_history->is_finished = true;
         } else {
             $user_soap_history->is_finished = false;
         }
         if ($user_soap != null) {
             $user_soap_history->user_soap_pk = $user_soap->user_soap_pk;
         }
         if ($bsugar != null) {
             $user_soap_history->blood_sugar_pk = $bsugar->blood_sugar_pk;
         }
         if (isset($request["history"])) {
             $history = $user_soap->history()->find($request["history"]);
             if ($history != null) {
                 $user_soap_history->old_pk = $history->user_soap_history_pk;
                 $history->is_visible = 0;
                 $history->save();
             }
         }
         $user_soap_history->save();
         if ($user_soap->is_finished == true) {
             // 完成
             $buildcase = Buildcase::where('hospital_no_uuid', '=', $uuid)->orderBy('build_at', 'desc')->first();
             if ($buildcase) {
                 $buildcase->soap_status = 1;
                 $buildcase->save();
             }
             $buildcase = Buildcase::where('hospital_no_uuid', '=', $uuid)->where('duty', '=', $uid)->first();
             if ($buildcase) {
                 $buildcase->duty_status = 2;
                 $buildcase->save();
             }
             $buildcase = Buildcase::where('hospital_no_uuid', '=', $uuid)->where('nurse', '=', $uid)->first();
             if ($buildcase) {
                 $buildcase->nurse_status = 2;
                 $buildcase->save();
             }
             $buildcase = Buildcase::where('hospital_no_uuid', '=', $uuid)->where('dietitian', '=', $uid)->first();
             if ($buildcase) {
                 $buildcase->dietitian_status = 2;
                 $buildcase->save();
             }
         } else {
             // 暫存
             $buildcase = Buildcase::where('hospital_no_uuid', '=', $uuid)->orderBy('build_at', 'desc')->first();
             if ($buildcase) {
                 $buildcase->soap_status = 0;
                 $buildcase->save();
             }
             $buildcase = Buildcase::where('hospital_no_uuid', '=', $uuid)->where('duty', '=', $uid)->first();
             if ($buildcase) {
                 $buildcase->duty_status = 1;
                 $buildcase->save();
             }
             $buildcase = Buildcase::where('hospital_no_uuid', '=', $uuid)->where('nurse', '=', $uid)->first();
             if ($buildcase) {
                 $buildcase->nurse_status = 1;
                 $buildcase->save();
             }
             $buildcase = Buildcase::where('hospital_no_uuid', '=', $uuid)->where('dietitian', '=', $uid)->first();
             if ($buildcase) {
                 $buildcase->dietitian_status = 1;
                 $buildcase->save();
             }
         }
         DB::commit();
         return "success /bdata/{$uuid}";
     } catch (\Exception $e) {
         DB::rollback();
         return "{$e}";
     }
 }