Skip to content

Commit

Permalink
bug fix in app protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
CynthiaKamau committed May 7, 2021
1 parent 9ba4e6e commit 7eb4af3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 14 additions & 0 deletions app/Http/Controllers/API/ResourcesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,20 @@ public function get_hcw_partner_protocols()
return new GenericCollection(FacilityProtocol::orderBy('id','desc')->where('facility_id',$hcw->facility_id)->paginate(20));
}

public function get_hcw_facility_protocols()
{
$user = auth()->user();

$hcw = HealthCareWorker::where('user_id', $user->id)->first();
if (is_null($hcw))
return response()->json([
'success' => false,
'message' => 'You do not belong to a facility. Please contact system admin'
], 200);


return new GenericCollection(FacilityProtocol::orderBy('id','desc')->where('facility_id',$hcw->facility_id)->paginate(20));
}


public function counties()
Expand Down
10 changes: 5 additions & 5 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public function role()
return $this->belongsTo('App\Role');
}

// public function partner()
// {
// return $this->hasMany('App\Partner','partner_users');
// }
public function partner()
{
return $this->hasMany('App\Partner');
}

public function hcw()
{
Expand All @@ -59,7 +59,7 @@ public function toArray() {
$data = parent::toArray();
$data['cadre'] = optional(optional($this->hcw)->cadre)->name;
$data['dob'] = optional($this->hcw)->dob;
$data['partner'] = optional($this->partner);
$data['partner'] = optional($this->partner)->name;
$data['county'] = optional(optional(optional($this->hcw)->facility)->county)->name;
$data['sub_county'] = optional(optional(optional($this->hcw)->facility)->sub_county)->name;
$data['role'] = $this->role;
Expand Down

0 comments on commit 7eb4af3

Please sign in to comment.