Add clinical device registry, browser wedge scan, and local agent API.
Deploy Ladill Care / deploy (push) Successful in 1m39s
Deploy Ladill Care / deploy (push) Successful in 1m39s
Branch-scoped Care devices with hashed agent tokens, patient barcode lookup/labels, and provenance-aware vitals from a minimal device agent (Pro for agent hardware; wedge free). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BelongsToOwner;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Device extends Model
|
||||
{
|
||||
use BelongsToOwner, SoftDeletes;
|
||||
|
||||
public const STATUS_ACTIVE = 'active';
|
||||
|
||||
public const STATUS_OFFLINE = 'offline';
|
||||
|
||||
public const STATUS_DISABLED = 'disabled';
|
||||
|
||||
public const MODE_BROWSER_WEDGE = 'browser_wedge';
|
||||
|
||||
public const MODE_AGENT = 'agent';
|
||||
|
||||
public const MODE_WEB_BLUETOOTH = 'web_bluetooth';
|
||||
|
||||
public const MODE_MANUAL = 'manual';
|
||||
|
||||
protected $table = 'care_devices';
|
||||
|
||||
protected $fillable = [
|
||||
'owner_ref', 'organization_id', 'branch_id', 'name', 'type',
|
||||
'status', 'connection_mode', 'device_token_hash', 'last_seen_at', 'metadata',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'device_token_hash',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'metadata' => 'array',
|
||||
'last_seen_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function organization(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Organization::class, 'organization_id');
|
||||
}
|
||||
|
||||
public function branch(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Branch::class, 'branch_id');
|
||||
}
|
||||
|
||||
public function vitalSigns(): HasMany
|
||||
{
|
||||
return $this->hasMany(VitalSign::class, 'device_id');
|
||||
}
|
||||
|
||||
public function isOnline(int $staleMinutes = 10): bool
|
||||
{
|
||||
return $this->status === self::STATUS_ACTIVE
|
||||
&& $this->last_seen_at
|
||||
&& $this->last_seen_at->gte(now()->subMinutes($staleMinutes));
|
||||
}
|
||||
|
||||
public function requiresAgent(): bool
|
||||
{
|
||||
return $this->connection_mode === self::MODE_AGENT
|
||||
|| in_array($this->type, config('care.device_agent_types', []), true);
|
||||
}
|
||||
|
||||
public function hasToken(): bool
|
||||
{
|
||||
return filled($this->device_token_hash);
|
||||
}
|
||||
}
|
||||
@@ -12,10 +12,16 @@ class VitalSign extends Model
|
||||
|
||||
protected $table = 'care_vital_signs';
|
||||
|
||||
public const SOURCE_MANUAL = 'manual';
|
||||
|
||||
public const SOURCE_DEVICE = 'device';
|
||||
|
||||
public const SOURCE_IMPORT = 'import';
|
||||
|
||||
protected $fillable = [
|
||||
'owner_ref', 'consultation_id', 'bp_systolic', 'bp_diastolic', 'pulse',
|
||||
'temperature', 'weight_kg', 'height_cm', 'spo2', 'respiratory_rate',
|
||||
'recorded_by', 'recorded_at',
|
||||
'recorded_by', 'recorded_at', 'source', 'device_id', 'raw_payload',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
@@ -25,6 +31,7 @@ class VitalSign extends Model
|
||||
'weight_kg' => 'decimal:2',
|
||||
'height_cm' => 'decimal:1',
|
||||
'recorded_at' => 'datetime',
|
||||
'raw_payload' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -32,4 +39,9 @@ class VitalSign extends Model
|
||||
{
|
||||
return $this->belongsTo(Consultation::class, 'consultation_id');
|
||||
}
|
||||
|
||||
public function device(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Device::class, 'device_id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user