|
@@ -11,66 +11,80 @@ class Client extends Model
|
|
|
{
|
|
|
protected $table = 'client';
|
|
|
|
|
|
- public function displayName() {
|
|
|
- return $this->name_last . ', '. $this->name_first;
|
|
|
+ public function displayName()
|
|
|
+ {
|
|
|
+ return $this->name_last . ', ' . $this->name_first;
|
|
|
}
|
|
|
|
|
|
- public function mcp() {
|
|
|
+ public function mcp()
|
|
|
+ {
|
|
|
return $this->hasOne(Pro::class, 'id', 'mcp_pro_id');
|
|
|
}
|
|
|
|
|
|
- public function pcp() {
|
|
|
+ public function pcp()
|
|
|
+ {
|
|
|
return $this->hasOne(Pro::class, 'id', 'physician_pro_id');
|
|
|
}
|
|
|
|
|
|
- public function cm() {
|
|
|
+ public function cm()
|
|
|
+ {
|
|
|
return $this->hasOne(Pro::class, 'id', 'cm_pro_id');
|
|
|
}
|
|
|
|
|
|
- public function rmm() {
|
|
|
+ public function rmm()
|
|
|
+ {
|
|
|
return $this->hasOne(Pro::class, 'id', 'rmm_pro_id');
|
|
|
}
|
|
|
|
|
|
- public function rme() {
|
|
|
+ public function rme()
|
|
|
+ {
|
|
|
return $this->hasOne(Pro::class, 'id', 'rme_pro_id');
|
|
|
}
|
|
|
|
|
|
- public function rms() {
|
|
|
+ public function rms()
|
|
|
+ {
|
|
|
return $this->hasOne(Pro::class, 'id', 'rms_pro_id');
|
|
|
}
|
|
|
|
|
|
- public function rmg() {
|
|
|
+ public function rmg()
|
|
|
+ {
|
|
|
return $this->hasOne(Pro::class, 'id', 'rmg_pro_id');
|
|
|
}
|
|
|
|
|
|
- public function prosInMeetingWith() {
|
|
|
+ public function prosInMeetingWith()
|
|
|
+ {
|
|
|
return Pro::where('in_meeting_with_client_id', $this->id)->get();
|
|
|
}
|
|
|
|
|
|
- public function notes() {
|
|
|
+ public function notes()
|
|
|
+ {
|
|
|
return $this->hasMany(Note::class, 'client_id', 'id')
|
|
|
->orderBy('effective_dateest', 'desc');
|
|
|
}
|
|
|
|
|
|
- public function activeNotes() {
|
|
|
+ public function activeNotes()
|
|
|
+ {
|
|
|
return $this->hasMany(Note::class, 'client_id', 'id')
|
|
|
->where('is_cancelled', false)
|
|
|
->orderBy('effective_dateest', 'desc');
|
|
|
}
|
|
|
|
|
|
- public function cancelledNotes() {
|
|
|
+ public function cancelledNotes()
|
|
|
+ {
|
|
|
return $this->hasMany(Note::class, 'client_id', 'id')
|
|
|
->where('is_cancelled', true)
|
|
|
->orderBy('effective_dateest', 'desc');
|
|
|
}
|
|
|
|
|
|
- public function sections() {
|
|
|
+ public function sections()
|
|
|
+ {
|
|
|
return $this->hasMany(Section::class, 'client_id', 'id')
|
|
|
->where('is_active', true)
|
|
|
->orderBy('created_at', 'asc');
|
|
|
}
|
|
|
|
|
|
- public function handouts() {
|
|
|
+ public function handouts()
|
|
|
+ {
|
|
|
$mappings = HandoutClient::where('client_id', $this->id)->get();
|
|
|
$handouts = new Collection();
|
|
|
foreach ($mappings as $mapping) {
|
|
@@ -82,28 +96,33 @@ class Client extends Model
|
|
|
return $handouts;
|
|
|
}
|
|
|
|
|
|
- public function duplicateOf() {
|
|
|
+ public function duplicateOf()
|
|
|
+ {
|
|
|
return $this->hasOne(Client::class, 'id', 'duplicate_of_client_id');
|
|
|
}
|
|
|
|
|
|
- public function actionItems () {
|
|
|
+ public function actionItems()
|
|
|
+ {
|
|
|
return $this->hasMany(ActionItem::class, 'client_id', 'id')
|
|
|
->orderBy('action_item_category', 'asc')
|
|
|
->orderBy('created_at', 'desc');
|
|
|
}
|
|
|
|
|
|
- public function infoLines() {
|
|
|
- return $this->hasMany(ClientInfoLine::class, 'client_id', 'id')->orderBy('created_at', 'desc');
|
|
|
+ public function infoLines()
|
|
|
+ {
|
|
|
+ return $this->hasMany(ClientInfoLine::class, 'client_id', 'id')->orderBy('created_at', 'desc');
|
|
|
}
|
|
|
|
|
|
- public function measurements() {
|
|
|
+ public function measurements()
|
|
|
+ {
|
|
|
return $this->hasMany(Measurement::class, 'client_id', 'id')
|
|
|
/*->distinct('label')*/
|
|
|
->where('is_removed', false)
|
|
|
->orderBy('effective_date', 'desc');
|
|
|
}
|
|
|
|
|
|
- public function currentCareMonth() {
|
|
|
+ public function currentCareMonth()
|
|
|
+ {
|
|
|
$cmStartDate = strtotime(date('Y-m-d'));
|
|
|
$month = date("n", $cmStartDate);
|
|
|
$year = date("Y", $cmStartDate);
|
|
@@ -114,7 +133,8 @@ class Client extends Model
|
|
|
->first();
|
|
|
}
|
|
|
|
|
|
- public function measurementsInCareMonth(CareMonth $careMonth) {
|
|
|
+ public function measurementsInCareMonth(CareMonth $careMonth)
|
|
|
+ {
|
|
|
$cmStartDate = strtotime($careMonth->start_date);
|
|
|
$month = date("n", $cmStartDate);
|
|
|
$year = date("Y", $cmStartDate);
|
|
@@ -128,7 +148,8 @@ class Client extends Model
|
|
|
return $measurements;
|
|
|
}
|
|
|
|
|
|
- public function allMeasurements() {
|
|
|
+ public function allMeasurements()
|
|
|
+ {
|
|
|
return $this->hasMany(Measurement::class, 'client_id', 'id')
|
|
|
->where('is_removed', false)
|
|
|
->whereNull('parent_measurement_id')
|
|
@@ -136,12 +157,14 @@ class Client extends Model
|
|
|
->orderBy('effective_date', 'desc');
|
|
|
}
|
|
|
|
|
|
- public function smses() {
|
|
|
+ public function smses()
|
|
|
+ {
|
|
|
return $this->hasMany(ClientSMS::class, 'client_id', 'id')
|
|
|
->orderBy('created_at', 'desc');
|
|
|
}
|
|
|
|
|
|
- public function documents() {
|
|
|
+ public function documents()
|
|
|
+ {
|
|
|
return $this->hasMany(ClientDocument::class, 'client_id', 'id')
|
|
|
->orderBy('created_at', 'desc');
|
|
|
}
|
|
@@ -156,8 +179,9 @@ class Client extends Model
|
|
|
->orderBy('created_at', 'desc');
|
|
|
}
|
|
|
|
|
|
- public function nextMcpAppointment() {
|
|
|
- if($this->mcp) {
|
|
|
+ public function nextMcpAppointment()
|
|
|
+ {
|
|
|
+ if ($this->mcp) {
|
|
|
return Appointment::where('client_id', $this->id)
|
|
|
->where('pro_id', $this->mcp->id)
|
|
|
->where('start_time', '>=', date('Y-m-d'))
|
|
@@ -167,31 +191,36 @@ class Client extends Model
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- public function appointments() {
|
|
|
+ public function appointments()
|
|
|
+ {
|
|
|
return $this->hasMany(Appointment::class, 'client_id', 'id')
|
|
|
->orderBy('start_time', 'desc');
|
|
|
}
|
|
|
|
|
|
- public function upcomingAppointments() {
|
|
|
+ public function upcomingAppointments()
|
|
|
+ {
|
|
|
return $this->hasMany(Appointment::class, 'client_id', 'id')
|
|
|
- // ->where('raw_start_time', '>', date('Y-m-d H:i:s'))
|
|
|
+ // ->where('raw_start_time', '>', date('Y-m-d H:i:s'))
|
|
|
->whereIn('status', ['CREATED', 'CONFIRMED'])
|
|
|
->orderBy('start_time', 'desc');
|
|
|
}
|
|
|
|
|
|
- public function memos() {
|
|
|
+ public function memos()
|
|
|
+ {
|
|
|
return $this->hasMany(ClientMemo::class, 'client_id', 'id')
|
|
|
->where('is_cancelled', false)
|
|
|
->orderBy('created_at', 'desc');
|
|
|
}
|
|
|
|
|
|
- public function devices() {
|
|
|
+ public function devices()
|
|
|
+ {
|
|
|
return $this->hasMany(ClientBDTDevice::class, 'client_id', 'id')
|
|
|
->where('is_active', true)
|
|
|
->orderBy('created_at', 'desc');
|
|
|
}
|
|
|
|
|
|
- public function hasDevice($_device) {
|
|
|
+ public function hasDevice($_device)
|
|
|
+ {
|
|
|
$count = ClientBDTDevice::where('client_id', $this->id)
|
|
|
->where('device_id', $_device->id)
|
|
|
->where('is_active', true)
|
|
@@ -199,27 +228,82 @@ class Client extends Model
|
|
|
return !!$count;
|
|
|
}
|
|
|
|
|
|
- public function deviceMeasurements() {
|
|
|
+ public function deviceMeasurements()
|
|
|
+ {
|
|
|
return $this->hasMany(ClientBDTMeasurement::class, 'client_id', 'id')
|
|
|
->orderBy('created_at', 'desc');
|
|
|
}
|
|
|
|
|
|
- public function activeMcpRequest() {
|
|
|
+ public function activeMcpRequest()
|
|
|
+ {
|
|
|
return $this->hasOne(McpRequest::class, 'id', 'active_mcp_request_id');
|
|
|
}
|
|
|
|
|
|
- public function clientPrograms() {
|
|
|
+ public function clientPrograms()
|
|
|
+ {
|
|
|
return $this->hasMany(ClientProgram::class, 'client_id', 'id')
|
|
|
->where('is_active', true)
|
|
|
->orderBy('title', 'desc');
|
|
|
}
|
|
|
|
|
|
- public function tickets() {
|
|
|
+ public function tickets()
|
|
|
+ {
|
|
|
return $this->hasMany(Ticket::class, 'client_id', 'id')
|
|
|
->orderBy('created_at', 'desc');
|
|
|
}
|
|
|
|
|
|
- public function prosWithAccess() {
|
|
|
+ public function mcpDisplayName()
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public function rmeDisplayName()
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public function firstCellularBPDevice()
|
|
|
+ {
|
|
|
+ $devices = $this->devices();
|
|
|
+ $x = null;
|
|
|
+ foreach($devices as $device){
|
|
|
+ if($device->device->category == 'BP'){
|
|
|
+ $x = $device;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $x;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getFirstCellularBPMeasurementAt()
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getLatestCellularBPMeasurementAt()
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getTotalCellularBPMeasurements()
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public function firstCellularWeightDevice()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getFirstCellularWeightMeasurementAt()
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getLatestCellularWeightMeasurementAt()
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getTotalCellularWeightMeasurements()
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public function prosWithAccess()
|
|
|
+ {
|
|
|
|
|
|
$pros = [];
|
|
|
|
|
@@ -238,28 +322,28 @@ class Client extends Model
|
|
|
// via client pro access
|
|
|
$cpAccesses = ClientProAccess::where('client_id', $this->id)->where('is_active', true)->get();
|
|
|
foreach ($cpAccesses as $cpAccess) {
|
|
|
- if(!$cpAccess->pro) continue;
|
|
|
+ if (!$cpAccess->pro) continue;
|
|
|
$pros[] = ["pro" => $cpAccess->pro->displayName(), "association" => 'Via Client-Pro Access'];
|
|
|
}
|
|
|
|
|
|
// via appointments
|
|
|
$appointments = Appointment::where('client_id', $this->id)->get();
|
|
|
foreach ($appointments as $appointment) {
|
|
|
- if(!$appointment->pro) continue;
|
|
|
+ if (!$appointment->pro) continue;
|
|
|
$pros[] = ["pro" => $appointment->pro->displayName(), "association" => 'Via Appointment: ' . $appointment->raw_date];
|
|
|
}
|
|
|
|
|
|
// via client program
|
|
|
$clientPrograms = ClientProgram::where('client_id', $this->id)->where('is_active', true)->get();
|
|
|
foreach ($clientPrograms as $clientProgram) {
|
|
|
- if($clientProgram->mcp)
|
|
|
+ if ($clientProgram->mcp)
|
|
|
$pros[] = ["pro" => $clientProgram->mcp->displayName(), "association" => 'Program MCP: ' . $clientProgram->title];
|
|
|
- if($clientProgram->manager)
|
|
|
+ if ($clientProgram->manager)
|
|
|
$pros[] = ["pro" => $clientProgram->manager->displayName(), "association" => 'Program Manager: ' . $clientProgram->title];
|
|
|
}
|
|
|
|
|
|
// sort by pro name
|
|
|
- $name = array_column($pros, 'pro');
|
|
|
+ $name = array_column($pros, 'pro');
|
|
|
array_multisort($name, SORT_ASC, $pros);
|
|
|
|
|
|
return $pros;
|