public function delete_food($calendar_date) { $uuid = Session::get('uuid'); $user_food = HospitalNo::find($uuid)->food_record()->where('calendar_date', '=', $calendar_date)->first(); DB::beginTransaction(); try { if ($user_food != null) { $details = $user_food->food_detail; foreach ($details as $detail) { $detail->delete(); } $user_food->delete(); } DB::commit(); return "success"; } catch (\Exception $e) { DB::rollback(); return "fail"; } }
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}"; } }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { // validate $this->validate($request, ['account' => 'required|alpha_num|size:18|unique:users,account']); $this->validate($request, Patientprofile::rules()); $this->validate($request, CaseCare::rules()); DB::beginTransaction(); try { // users $user = new User(); $user->account = trim($request->account); $user->name = $request->pp_name; $user->password = Hash::make($user->account); $user->pid = $request->pp_patientid; $user->position = '患者'; $user->phone = $request->pp_mobile1; $user->email = $request->pp_email; $user->save(); // patientprofile1 $patientprofile = new Patientprofile(); $patientprofile->user_id = $user->id; $patientprofile->pp_patientid = trim($request->pp_patientid); $patientprofile->pp_birthday = $request->pp_birthday; $patientprofile->pp_age = $request->pp_age; $patientprofile->pp_sex = $request->pp_sex; $patientprofile->pp_height = $request->pp_height; $patientprofile->pp_weight = $request->pp_weight; $patientprofile->pp_tel1 = $request->pp_tel1; $patientprofile->pp_tel2 = $request->pp_tel2; $patientprofile->pp_mobile1 = $request->pp_mobile1; $patientprofile->pp_mobile2 = $request->pp_mobile2; $patientprofile->pp_area = $request->pp_area; $patientprofile->pp_area_other = $request->pp_area_other; $patientprofile->pp_doctor = $request->pp_doctor; $patientprofile->pp_remark = $request->pp_remark; $patientprofile->pp_source = $request->pp_source; $patientprofile->pp_source_other = $request->pp_source_other; $patientprofile->pp_occupation = $request->pp_occupation; $patientprofile->pp_occupation_other = $request->pp_occupation_other; $patientprofile->pp_address = $request->pp_address; $patientprofile->pp_email = $request->pp_email; $patientprofile->educator = Auth::user()->id; $patientprofile->save(); // casecare $casecare = new CaseCare(); $casecare->patientprofile1_id = $patientprofile->id; $casecare->cc_patientid = trim($request->pp_patientid); $casecare->cc_contactor = $request->cc_contactor; $casecare->cc_contactor = $request->cc_contactor; $casecare->cc_contactor_tel = $request->cc_contactor_tel; $casecare->cc_language = $request->cc_language; $casecare->cc_mdate = $request->cc_mdate; $casecare->cc_mdatem = $request->cc_mdatem; $casecare->cc_type = $request->cc_type; $casecare->cc_type_other = $request->cc_type_other; $casecare->cc_ibw = $request->cc_ibw; $casecare->cc_bmi = $request->cc_bmi; $casecare->cc_waist = $request->cc_waist; $casecare->cc_butt = $request->cc_butt; if ($request->cc_status) { $casecare->cc_status = ($request->cc_status_c1 ? "1" : "0") . ($request->cc_status_c2 ? "1" : "0") . ($request->cc_status_c3 ? "1" : "0") . ($request->cc_status_c4 ? "1" : "0") . ($request->cc_status_c5 ? "1" : "0"); $casecare->cc_status_other = $request->cc_status_other; } else { $casecare->cc_status = ""; $casecare->cc_status_other = ""; } $casecare->cc_drink = $request->cc_drink; $casecare->cc_wine = $request->cc_wine; $casecare->cc_wineq = $request->cc_wineq; $casecare->cc_smoke = $request->cc_smoke == 1 && $request->cc_smoke_time > 0 ? $request->cc_smoke_time : $request->cc_smoke; $casecare->cc_mh = $request->cc_mh; $casecare->cc_fh = $request->cc_fh; $casecare->cc_fh_desc = $request->cc_fh_desc; $casecare->cc_drug_allergy = $request->cc_drug_allergy; $casecare->cc_drug_allergy_name = $request->cc_drug_allergy_name; $casecare->cc_activity = $request->cc_activity; $casecare->cc_medicaretype = $request->cc_medicaretype; $casecare->cc_jobtime = $request->cc_jobtime; if ($request->cc_current_use) { $casecare->cc_current_use = ($request->cc_current_use1 ? "1" : "0") . ($request->cc_current_use2 ? "1" : "0") . ($request->cc_current_use3 ? "1" : "0") . ($request->cc_current_use4 ? "1" : "0") . ($request->cc_current_use5 ? "1" : "0"); $casecare->cc_starty = $request->cc_starty; $casecare->cc_startm = $request->cc_startm; } else { $casecare->cc_current_use = ""; $casecare->cc_starty = -1; $casecare->cc_startm = -1; } if ($request->cc_hinder) { $casecare->cc_hinder = ($request->cc_hinder_1 ? "1" : "0") . ($request->cc_hinder_2 ? "1" : "0") . ($request->cc_hinder_3 ? "1" : "0") . ($request->cc_hinder_4 ? "1" : "0") . ($request->cc_hinder_5 ? "1" : "0") . ($request->cc_hinder_6 ? "1" : "0") . ($request->cc_hinder_7 ? "1" : "0") . ($request->cc_hinder_8 ? "1" : "0") . ($request->cc_hinder_9 ? "1" : "0"); $casecare->cc_hinder_desc = $request->cc_hinder_desc; } else { $casecare->cc_hinder = ""; $casecare->cc_hinder_desc = ""; } $casecare->cc_act_time = $request->cc_act_time; $casecare->cc_act_times = $request->cc_act_times; $casecare->cc_act_kind = $request->cc_act_kind; $casecare->cc_act_other = $request->cc_act_other; $casecare->cc_edu = $request->cc_edu; $casecare->cc_careself = $request->cc_careself; $casecare->cc_careself_name = $request->cc_careself_name; $casecare->cc_careman = $request->cc_careman; $casecare->cc_careman_tel = $request->cc_careman_tel; if ($request->cc_usebsm) { $casecare->cc_usebsm = $request->cc_usebsm_name; } $casecare->cc_usebsm_frq = $request->cc_usebsm_frq; if ($request->cc_usebsm_frq) { // by month $casecare->cc_usebsm_unit = $request->cc_usebsm_frq_month; } else { // by week $casecare->cc_usebsm_unit = $request->cc_usebsm_frq_week; } $casecare->cc_g6pd = $request->cc_g6pd; $casecare->cc_deathdate = $request->cc_deathdate; $casecare->cc_deathdatem = $request->cc_deathdatem; $casecare->cc_smartphone = $request->cc_smartphone; $casecare->cc_wifi3g = $request->cc_wifi3g; $casecare->cc_smartphone_family = $request->cc_smartphone_family; $casecare->cc_familyupload = $request->cc_familyupload; $casecare->cc_uploadtodm = $request->cc_uploadtodm; $casecare->cc_appexp = $request->cc_appexp; $casecare->cc_lastexam = $request->cc_lastexam; $casecare->save(); // bsm 血糖仪新增 if ($request->cc_usebsm && $request->cc_usebsm_name == 0 && $request->cc_otherbsm) { $bsm = new BSM(); $bsm->bm_name = $request->cc_otherbsm; $bsm->bm_model = $request->cc_otherbsm; $bsm->save(); $casecare = CaseCare::where('patientprofile1_id', '=', $patientprofile->id)->firstOrFail(); $casecare->cc_usebsm = $bsm->id; $casecare->save(); } //create the hospital_no while (1) { $uuid = uniqid('cn_'); if (HospitalNo::find($uuid) == null) { break; } } $hospital_no = new HospitalNo(); $hospital_no->hospital_no_uuid = $uuid; $hospital_no->patient_profile_id = $patientprofile->id; $hospital_no->patient_user_id = $patientprofile->user_id; $hospital_no->nurse_user_id = Auth::user()->id; $hospital_no->hospital_no_displayname = substr($request->input("pp_patientid"), 0, -6) . 'xxxxxx'; $hospital_no->save(); //enable feature // $featurs_id = Feature::where('href', '=', '/bdata') -> first() -> id; // $hasfeatures = new Hasfeature(); // $hasfeatures -> user_id = $patientprofile -> user_id; // $hasfeatures -> feature_id = $featurs_id; // $hasfeatures -> save(); $msg = '项目成功创建。'; DB::commit(); EventController::SaveEvent('patientprofile', 'store(保存)'); } catch (\Exception $e) { $msg = '项目创建失败。'; DB::rollback(); } return redirect()->route('patient.index')->with('message', $msg); }