Add specialty clinical records on the shared shell (Phase 3).
Deploy Ladill Care / deploy (push) Failing after 1m2s
Deploy Ladill Care / deploy (push) Failing after 1m2s
Visit-scoped structured forms for Emergency triage, Blood Bank requests, and Dentistry odontogram with derived alerts, document upload, and KPI counts. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -6,9 +6,11 @@ use App\Http\Controllers\Care\Concerns\ScopesToAccount;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Appointment;
|
||||
use App\Models\Department;
|
||||
use App\Models\PatientAttachment;
|
||||
use App\Models\Visit;
|
||||
use App\Services\Care\CareQueueBridge;
|
||||
use App\Services\Care\OrganizationResolver;
|
||||
use App\Services\Care\SpecialtyClinicalRecordService;
|
||||
use App\Services\Care\SpecialtyModuleService;
|
||||
use App\Services\Care\SpecialtyShellService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
@@ -105,6 +107,102 @@ class SpecialtyModuleController extends Controller
|
||||
return back()->with('success', 'Added to invoice '.$bill->invoice_number.'.');
|
||||
}
|
||||
|
||||
public function saveClinical(
|
||||
Request $request,
|
||||
string $module,
|
||||
Visit $visit,
|
||||
SpecialtyModuleService $modules,
|
||||
SpecialtyClinicalRecordService $clinical,
|
||||
): RedirectResponse {
|
||||
$definition = $modules->definition($module);
|
||||
abort_unless($definition, 404);
|
||||
|
||||
$organization = $this->organization($request);
|
||||
$member = $this->member($request);
|
||||
abort_unless($modules->memberCanAccess($organization, $member, $module), 403);
|
||||
abort_unless($visit->organization_id === $organization->id, 404);
|
||||
|
||||
$tab = (string) $request->input('tab', '');
|
||||
$recordType = $clinical->recordTypeForTab($module, $tab);
|
||||
abort_unless($recordType, 422);
|
||||
|
||||
// Normalize checkbox booleans before validation.
|
||||
$payload = (array) $request->input('payload', []);
|
||||
foreach ($clinical->fieldsFor($module, $recordType) as $field) {
|
||||
if (($field['type'] ?? '') === 'boolean') {
|
||||
$payload[$field['name']] = $request->boolean('payload.'.$field['name']);
|
||||
}
|
||||
}
|
||||
$request->merge(['payload' => $payload]);
|
||||
|
||||
$validated = $request->validate(array_merge([
|
||||
'tab' => ['required', 'string'],
|
||||
'stage_code' => ['nullable', 'string', 'max:64'],
|
||||
'status' => ['nullable', 'in:draft,active,completed'],
|
||||
], $clinical->validationRules($module, $recordType)));
|
||||
|
||||
$record = $clinical->upsert(
|
||||
$organization,
|
||||
$visit,
|
||||
$module,
|
||||
$recordType,
|
||||
$clinical->payloadFromRequest($validated),
|
||||
$this->ownerRef($request),
|
||||
$this->ownerRef($request),
|
||||
$validated['stage_code'] ?? null,
|
||||
$validated['status'] ?? \App\Models\SpecialtyClinicalRecord::STATUS_ACTIVE,
|
||||
);
|
||||
|
||||
return redirect()
|
||||
->route('care.specialty.workspace', [
|
||||
'module' => $module,
|
||||
'visit' => $visit,
|
||||
'tab' => $tab,
|
||||
])
|
||||
->with('success', 'Saved '.$record->record_type.' record.');
|
||||
}
|
||||
|
||||
public function uploadDocument(
|
||||
Request $request,
|
||||
string $module,
|
||||
Visit $visit,
|
||||
SpecialtyModuleService $modules,
|
||||
): RedirectResponse {
|
||||
$definition = $modules->definition($module);
|
||||
abort_unless($definition, 404);
|
||||
|
||||
$organization = $this->organization($request);
|
||||
$member = $this->member($request);
|
||||
abort_unless($modules->memberCanAccess($organization, $member, $module), 403);
|
||||
abort_unless($visit->organization_id === $organization->id, 404);
|
||||
abort_unless($visit->patient_id, 422);
|
||||
|
||||
$validated = $request->validate([
|
||||
'attachment' => ['required', 'file', 'max:10240', 'mimes:pdf,jpeg,jpg,png,webp'],
|
||||
]);
|
||||
|
||||
$file = $validated['attachment'];
|
||||
$path = $file->store("care/patients/{$visit->patient_id}/attachments", 'public');
|
||||
|
||||
PatientAttachment::create([
|
||||
'owner_ref' => $this->ownerRef($request),
|
||||
'patient_id' => $visit->patient_id,
|
||||
'file_path' => $path,
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'mime_type' => $file->getMimeType(),
|
||||
'document_type' => 'specialty_'.$module,
|
||||
'uploaded_by' => $this->ownerRef($request),
|
||||
]);
|
||||
|
||||
return redirect()
|
||||
->route('care.specialty.workspace', [
|
||||
'module' => $module,
|
||||
'visit' => $visit,
|
||||
'tab' => 'documents',
|
||||
])
|
||||
->with('success', 'Document uploaded.');
|
||||
}
|
||||
|
||||
public function callNext(
|
||||
Request $request,
|
||||
string $module,
|
||||
@@ -215,11 +313,23 @@ class SpecialtyModuleController extends Controller
|
||||
$workspaceVisit = null;
|
||||
$patientHeader = null;
|
||||
$timeline = [];
|
||||
$clinicalRecord = null;
|
||||
$clinicalFields = [];
|
||||
$clinicalAlerts = [];
|
||||
$visitDocuments = collect();
|
||||
$activeTab = (string) $request->query('tab', array_key_first($shell->workspaceTabs($module)) ?: 'overview');
|
||||
$clinical = app(SpecialtyClinicalRecordService::class);
|
||||
|
||||
if ($visit) {
|
||||
abort_unless($visit->organization_id === $organization->id, 404);
|
||||
$visit->load(['patient.allergies', 'patient.emergencyContacts', 'appointment.practitioner', 'bill.lineItems']);
|
||||
$visit->load([
|
||||
'patient.allergies',
|
||||
'patient.emergencyContacts',
|
||||
'patient.attachments',
|
||||
'appointment.practitioner',
|
||||
'bill.lineItems',
|
||||
'consultations',
|
||||
]);
|
||||
$workspaceVisit = $visit;
|
||||
if ($visit->patient) {
|
||||
$patientHeader = array_merge(
|
||||
@@ -231,6 +341,14 @@ class SpecialtyModuleController extends Controller
|
||||
} elseif ($section === 'workspace') {
|
||||
$first = $openVisits->first();
|
||||
if ($first?->patient) {
|
||||
$first->load([
|
||||
'patient.allergies',
|
||||
'patient.emergencyContacts',
|
||||
'patient.attachments',
|
||||
'appointment.practitioner',
|
||||
'bill.lineItems',
|
||||
'consultations',
|
||||
]);
|
||||
$workspaceVisit = $first;
|
||||
$patientHeader = array_merge(
|
||||
['patient' => $first->patient, 'visit' => $first, 'appointment' => $first->appointment],
|
||||
@@ -240,6 +358,29 @@ class SpecialtyModuleController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
if ($workspaceVisit && $section === 'workspace') {
|
||||
$recordType = $clinical->recordTypeForTab($module, $activeTab);
|
||||
if ($recordType) {
|
||||
$clinicalRecord = $clinical->findForVisit($workspaceVisit, $module, $recordType);
|
||||
$clinicalFields = $clinical->fieldsFor($module, $recordType);
|
||||
}
|
||||
$clinicalAlerts = $clinical->alertsForVisit($workspaceVisit, $module);
|
||||
if ($patientHeader !== null) {
|
||||
$patientHeader['clinical_alerts'] = $clinicalAlerts;
|
||||
}
|
||||
$visitDocuments = $workspaceVisit->patient
|
||||
? $workspaceVisit->patient->attachments()
|
||||
->where(function ($q) use ($module) {
|
||||
$q->where('document_type', 'specialty_'.$module)
|
||||
->orWhere('document_type', 'other')
|
||||
->orWhereNull('document_type');
|
||||
})
|
||||
->orderByDesc('id')
|
||||
->limit(20)
|
||||
->get()
|
||||
: collect();
|
||||
}
|
||||
|
||||
return view('care.specialty.shell', [
|
||||
'organization' => $organization,
|
||||
'moduleKey' => $module,
|
||||
@@ -259,6 +400,10 @@ class SpecialtyModuleController extends Controller
|
||||
'workspaceVisit' => $workspaceVisit,
|
||||
'patientHeader' => $patientHeader,
|
||||
'timeline' => $timeline,
|
||||
'clinicalRecord' => $clinicalRecord,
|
||||
'clinicalFields' => $clinicalFields,
|
||||
'clinicalAlerts' => $clinicalAlerts,
|
||||
'visitDocuments' => $visitDocuments,
|
||||
'queueStubs' => $modules->queueStubsFor($organization, $module),
|
||||
'branchId' => $branchId,
|
||||
'queueIntegration' => $branchId
|
||||
|
||||
Reference in New Issue
Block a user