Skip to content

Commit 3389d26

Browse files
committed
Address update, Toast message feature. Ondelete cascades on migration.
1 parent 31cd2c9 commit 3389d26

17 files changed

+105
-25
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ Homestead.yaml
1111
npm-debug.log
1212
yarn-error.log
1313
.idea
14+
.DB_Store
15+
/public/.DB_Store

app/Http/Controllers/CreditController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function show(Credit $credit)
116116
*/
117117
public function edit(Credit $credit)
118118
{
119-
dd('edit credit here', $credit);
119+
// We do not edit credit
120120
}
121121

122122
/**
@@ -128,7 +128,7 @@ public function edit(Credit $credit)
128128
*/
129129
public function update(Request $request, Credit $credit)
130130
{
131-
dd('update credit here', $credit, $request);
131+
// dd('update credit here', $credit, $request);
132132
}
133133

134134
/**
@@ -139,7 +139,7 @@ public function update(Request $request, Credit $credit)
139139
*/
140140
public function destroy(Credit $credit)
141141
{
142-
dd('delete credit here', $credit->attributesToArray());
142+
// dd('delete credit here', $credit->attributesToArray());
143143
}
144144

145145
public function clear_credit(Request $request) {

app/Http/Controllers/NextOfKinController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,13 @@ public function update(Request $request, NextOfKin $nok)
123123
* Remove the specified resource from storage.
124124
*
125125
* @param \App\NextOfKin $nok
126-
* @return \Illuminate\Http\Response
126+
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Routing\Redirector
127127
*/
128128
public function destroy(NextOfKin $nok)
129129
{
130-
dd('delete nok here', $nok->attributesToArray());
130+
$nok->delete();
131+
Session::flash('success', 'Next of Kin Deleted');
132+
return redirect(route('noks'));
131133
}
132134

133135
public function associate_patient(NextOfKin $nok)

app/Http/Controllers/PatientController.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public function store(Request $request)
7272
$request['dob'] = date_create($request['dob']);
7373
$nok_id = $request['p_nok_id'];
7474
$patient = Patient::create($request->all());
75-
Session::flash('success', 'Patient created');
7675
if (str_replace(' ','', $nok_id) !='') {
7776
$nok = NextOfKin::where('id_number', $nok_id)->first();
7877
if ($nok) {
@@ -82,15 +81,20 @@ public function store(Request $request)
8281
'created_by' => $patient->created_by,
8382
'is_primary' => true
8483
]);
85-
} else
84+
Session::flash('success', "Patient $patient->full_name Created successfully.");
85+
86+
}
87+
else {
88+
8689
// redirect to creating nok with this id number
8790
$nok_context = [
8891
'patient' => $patient,
8992
'nok_id' => $nok_id,
9093
'is_primary'=>true
9194
];
92-
return redirect(route('create_nok', $nok_context));
93-
}
95+
Session::flash('message', "Patient Created successfully, now create primary next of kin for $patient->full_name");
96+
return redirect(route('create_nok', $nok_context));
97+
}}
9498
return redirect(route('patients'));
9599
}
96100

@@ -165,11 +169,17 @@ public function update(Request $request, Patient $patient)
165169
* Remove the specified resource from storage.
166170
*
167171
* @param \App\Patient $patient
168-
* @return \Illuminate\Http\Response
172+
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Routing\Redirector
169173
*/
170174
public function destroy(Patient $patient)
171175
{
172-
dd('delete patient here', $patient->attributesToArray());
176+
if ($patient->credits->count()> 0){
177+
Session::flash('error', 'Cannot delete patient with credit records.');
178+
return redirect()->back();
179+
}
180+
$patient->delete();
181+
Session::flash('success', 'Patient Deleted.');
182+
return redirect(route('patients'));
173183
}
174184

175185
public function associate_nok(Patient $patient)

app/Http/Controllers/UserController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,16 @@ public function update(Request $request, User $user)
102102
* Remove the specified resource from storage.
103103
*
104104
* @param \App\User $user
105-
* @return \Illuminate\Http\Response
105+
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Routing\Redirector
106106
*/
107107
public function destroy(User $user)
108108
{
109-
dd('delete user here', $user->attributesToArray());
109+
if($user->creations_count > 0){
110+
Session::flash('error', 'Cannot delete user that has created records.');
111+
return redirect()->back();
112+
}
113+
$user->delete();
114+
Session::flash('success', 'User Deleted.');
115+
return redirect(route('users'));
110116
}
111117
}

app/User.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,9 @@ public function getCreationsAttribute()
4747
'credits' => $credits,
4848
'noks' => $noks];
4949
}
50+
51+
public function getCreationsCountAttribute() {
52+
$creations = $this->creations;
53+
return $creations['patients']->count() + $creations['credits']->count()+$creations['noks']->count();
54+
}
5055
}

database/migrations/2020_12_26_114958_create_credits_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function up()
2424
$table->unsignedBigInteger('cleared_by')->nullable();
2525
$table->timestamps();
2626

27-
$table->foreign('patient_id')->references('id')->on('patients');
27+
$table->foreign('patient_id')->references('id')->on('patients')->onDelete('cascade');
2828
$table->foreign('created_by')->references('id')->on('users');
2929
$table->foreign('cleared_by')->references('id')->on('users');
3030

database/migrations/2020_12_26_115013_create_patient_noks_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public function up()
2121
$table->boolean('is_primary')->default(false);
2222
$table->timestamps();
2323

24-
$table->foreign('patient_id')->references('id')->on('patients');
25-
$table->foreign('nok_id')->references('id')->on('next_of_kin');
24+
$table->foreign('patient_id')->references('id')->on('patients')->onDelete('cascade');
25+
$table->foreign('nok_id')->references('id')->on('next_of_kin')->onDelete('cascade');
2626
$table->foreign('created_by')->references('id')->on('users');
2727
});
2828
}

public/.DS_Store

6 KB
Binary file not shown.

0 commit comments

Comments
 (0)