Skip to content

Commit

Permalink
map users to facilities
Browse files Browse the repository at this point in the history
  • Loading branch information
muokid3 committed Oct 26, 2020
1 parent 863466e commit e322f07
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 24 deletions.
27 changes: 11 additions & 16 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions app/Http/Controllers/API/ActionsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace App\Http\Controllers\API;

use App\HealthCareWorker;
use App\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ActionsController extends Controller
{
public function complete_profiles(Request $request)
{
$request->validate([
'msisdns' => 'required',
'facility_id' => 'required',
'facility_department_id' => 'required',
'cadre_id' => 'required',
],[
// 'facility_id.required' => 'Please select your facility',
// 'facility_department_id.required' => 'Please select your department',
// 'cadre_id.required' => 'Please select your cadre'
]);


$msisdnArray = explode(',', $request->msisdns);

$savedHcws = 0;

foreach ($msisdnArray as $msisdn) {
$user = User::where('msisdn',$msisdn)->first();

if (!is_null($user)){
$hcw = HealthCareWorker::where('user_id', $user->id)->first();
if (is_null($hcw)){
$newHcw = new HealthCareWorker();
$newHcw->user_id = $user->id;
$newHcw->facility_id = $request->facility_id;
$newHcw->facility_department_id = $request->facility_department_id;
$newHcw->cadre_id = $request->cadre_id;
$newHcw->saveOrFail();

$savedHcws++;
}
}

}
return response()->json([
'success' => true,
'message' => $savedHcws.' HCWs have been mapped to facilities'
], 201);


}

}
30 changes: 22 additions & 8 deletions app/Http/Controllers/API/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,28 @@ public function complete_profile(Request $request)

$user = \auth()->user();

$hcw = new HealthCareWorker();
$hcw->user_id = $user->id;
$hcw->facility_id = $request->facility_id;
$hcw->facility_department_id = $request->facility_department_id;
$hcw->cadre_id = $request->cadre_id;
$hcw->dob = $request->dob;
$hcw->id_no = $request->id_no;
$hcw->saveOrFail();
$hcw = HealthCareWorker::where('user_id',$user->id)->first();

if (is_null($hcw)){
$hcw = new HealthCareWorker();
$hcw->user_id = $user->id;
$hcw->facility_id = $request->facility_id;
$hcw->facility_department_id = $request->facility_department_id;
$hcw->cadre_id = $request->cadre_id;
$hcw->dob = $request->dob;
$hcw->id_no = $request->id_no;
$hcw->saveOrFail();
}else{

$hcw->facility_id = $request->facility_id;
$hcw->facility_department_id = $request->facility_department_id;
$hcw->cadre_id = $request->cadre_id;
$hcw->dob = $request->dob;
$hcw->id_no = $request->id_no;
$hcw->update();
}



$user->profile_complete = 1;
$user->update();
Expand Down
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,6 @@


Route::post('broadcasts/nascop/create', 'API\BroadcastsController@create_nascop_broadcast');
Route::post('profiles/complete', 'API\ActionsController@complete_profiles');


0 comments on commit e322f07

Please sign in to comment.