/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(RelationshipsRequest $request) { $relationship = Relationship::where('id', $request['relationshipID'])->first(); $relationship->name = $request['name']; $relationship->updated_by = \Auth::user()->id; $relationship->save(); \Session::flash('success', $request['name'] . ' has been successfully updated!'); return redirect()->back(); }
public function removeCampaignMembership() { $relationship = Relationship::where(function ($query) { $query->where('source_type', $this->referenceClass); $query->where('source_id', $this->id); $query->where('sibling_type', 'App\\Campaign'); $query->where('sibling_id', \Session::get('campaign')->id); })->orWhere(function ($query) { $query->where('sibling_type', $this->referenceClass); $query->where('sibling_id', $this->id); $query->where('source_type', 'App\\Campaign'); $query->where('source_id', \Session::get('campaign')->id); })->first(); try { $relationship->delete(); } catch (Exception $e) { \Log::error('Could not remove reference for ' . $this->referenceClass . ':' . $this->id . ' from campaign ' . \Session::get('campaign')->id); } }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(Request $request) { // try { $relationship_debug = "None"; if ($request->ajax()) { DB::beginTransaction(); $Person_id = Input::get('person_id'); // keep the doctor profile $Doctor_id = DB::table('doctors')->where('doctor_id', Input::get('doctor_id'))->update(['doctor_name' => Input::get('doctor_name'), 'doctor_mobile_phone' => Input::get('doctor_mobilephonenumber'), 'doctor_phone' => Input::get('doctor_phonenumber'), 'hospital' => Input::get('hospital_name'), 'doctor_care_date' => Input::get('doctor_care_date'), 'email' => Input::get('doctor_email')]); // insert information record $symptom_checkbox_10 = Input::get('10_symptom_checkbox'); DB::table('disease_1')->where('questions_id', Input::get('question_id'))->update(['symptom_1_1' => Input::get('1_1_symptom'), 'symptom_1_2' => Input::get('1_2_symptom'), 'symptom_1_3' => Input::get('1_3_symptom'), 'symptom_2' => Input::get('2_symptom_age'), 'symptom_3' => Input::get('3_symptom_age'), 'symptom_4_1' => Input::get('4_1_symptom'), 'symptom_4_2' => Input::get('4_2_symptom'), 'symptom_4_3' => Input::get('4_2_symptom'), 'symptom_4_4' => Input::get('4_4_symptom'), 'symptom_5' => Input::get('5_symptom'), 'symptom_5_date' => Input::get('5_2_symptom_add_on_result_date'), 'symptom_5_result' => Input::get('5_2_symptom_add_on_result'), 'symptom_6' => Input::get('6_symptom'), 'symptom_6_date' => Input::get('6_2_symptom_add_on_result_date'), 'symptom_6_result' => Input::get('6_2_symptom_add_on_result'), 'symptom_7_1' => Input::get('7_1_symptom'), 'symptom_7_1_result' => Input::get('7_1_symptom_result'), 'symptom_7_2' => Input::get('7_2_symptom'), 'symptom_7_2_result' => Input::get('7_2_symptom_result'), 'symptom_7_3' => Input::get('7_3_symptom'), 'symptom_7_3_result' => Input::get('7_3_symptom_result'), 'symptom_8' => Input::get('8_1_symptom'), 'symptom_9_male' => Input::get('9_male_number'), 'symptom_9_female' => Input::get('9_female_number'), 'symptom_10_2_male' => Input::get('10_2_male_number'), 'symptom_10_2_female' => Input::get('10_2_female_number'), 'symptom_10_1' => Input::get('10_symptom'), 'symptom_10_1_number' => Input::get('10_symptom_number'), 'symptom_10_1_check' => $symptom_checkbox_10]); $sym_10_name = json_decode(stripslashes(Input::get('vpb_item_name'))); $sym_10_age = json_decode(stripslashes(Input::get('vpb_item_ages'))); $sym_10_citizen_number = json_decode(stripslashes(Input::get('vpb_item_ids'))); $sym_10_roles = json_decode(stripslashes(Input::get('vpb_item_roles'))); if ($symptom_checkbox_10 != "ไม่รู้" || $symptom_checkbox_10 == null || !isset($symptom_checkbox_10)) { $relationship_debug = "เข้ามาเเล้ส"; for ($i = 0; $i < sizeof($sym_10_name); $i++) { $relationship_debug = "เข้ามาเเล้ส 1"; if ($sym_10_name[$i] != ' ' && $sym_10_name[$i] != null) { $name = explode(" ", $sym_10_name[$i]); $user = Persons::firstOrNew(array('person_first_name' => $name[0], 'person_last_name' => $name[1])); $user->person_first_name = $name[0]; $user->person_last_name = $name[1]; $user->person_age = $sym_10_age[$i]; $user->person_citizenID = $sym_10_citizen_number[$i]; $user->person_sex = 'male'; $user->save(); $relative_person_id = $user->person_id; /*$relative_person_id = DB::table('persons')->insertGetId( ['person_first_name' => $name[0], 'person_last_name' => $name[1], 'person_age' => $sym_10_age[$i],'person_citizenID' => $sym_10_citizen_number[$i], 'person_sex' => 'male' ]);*/ $relationship = Relationship::where('person_1_id', '=', $Person_id)->where('person_2_id', '=', $relative_person_id)->first(); if ($relationship->exists) { $relationship_debug = "เข้ามาเเล้ส 2"; $relationship->role_1_id = $this->check_my_role($sym_10_roles[$i], $Person_id); $relationship->role_2_id = $this->check_role($sym_10_roles[$i]); $relationship->relationship_type_id = $this->check_my_relationship($sym_10_roles[$i]); $relationship->save(); } else { $relationship = Relationship::where('person_2_id', '=', $Person_id)->where('person_1_id', '=', $relative_person_id)->first(); if ($relationship->exists) { $relationship_debug = "เข้ามาเเล้ส 3"; $relationship->role_2_id = $this->check_my_role($sym_10_roles[$i], $Person_id); $relationship->role_1_id = $this->check_role($sym_10_roles[$i]); $relationship->relationship_type_id = $this->check_my_relationship($sym_10_roles[$i]); $relationship->save(); } else { $relationship_debug = "เข้ามาเเล้ส 4"; //add data into patient, doctor , and question table $relative_doctor_id = DB::table('doctors')->insertGetId(['doctor_name' => "ไม่ทราบ", 'doctor_mobile_phone' => "ไม่ทราบ", 'doctor_phone' => "ไม่ทราบ", 'hospital' => "ไม่ทราบ", 'doctor_care_date' => "", 'email' => "ไม่ทราบ"]); $relative_patient_id = DB::table('patients')->insertGetId(['doctor_id' => $relative_doctor_id, 'person_id' => $relative_person_id, 'registration_date' => date('Y-m-d')]); //In future, if our system support many disease types , we need to change where on disease_type_name_en to id $relative_disease_types = DB::table('disease_types')->where('disease_type_name_en', StaticArray::$diseases['DMD'])->first(); // register disease type with question table $relative_disease_form_id = DB::table('disease_forms')->insertGetId(['disease_type_id' => $relative_disease_types->disease_type_id]); DB::table('patients_disease_forms')->insert(['patient_id' => $relative_patient_id, 'question_id' => $relative_disease_form_id, 'registration_date' => date('Y-m-d')]); DB::table('disease_1')->insert(['questions_id' => $relative_disease_form_id]); DB::table('relationship')->insert(['person_1_id' => $Person_id, 'person_2_id' => $relative_person_id, 'role_1_id' => $this->check_my_role($sym_10_roles[$i], $Person_id), 'role_2_id' => $this->check_role($sym_10_roles[$i]), 'relationship_type_id' => $this->check_my_relationship($sym_10_roles[$i])]); } } } } } DB::commit(); return response()->json(array('status' => 'Complete', 'message' => 'บันทึกสำเร็จ '), 200); } return response()->json(array('status' => 'Error', 'message' => 'มาได้ยังไง '), 200); } catch (Exception $e) { DB::rollback(); if ($e->getCode() == 23000) { $result['status'] = "Error"; $result['message'] = "Duplicate Record"; return response()->json($result, 200); } else { $result['status'] = 2; $result['message'] = $e->getMessage(); return response()->json($result, 200); } } }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $patient = Patient::find($id); $dataToSave = $patient->company_id; if ($patient->type === "Carga") { $relation = Relationship::where('burden', $id)->first(); $dataToSave = $relation->incumbent; } return view('patients.edit', compact('patient', 'dataToSave')); }