feat(assessments): layered clinical assessment engine end-to-end
Deploy Ladill Care / deploy (push) Successful in 1m26s
Deploy Ladill Care / deploy (push) Successful in 1m26s
Add a template-driven assessment system with universal intake, clinical pathways, disease instruments (stroke MVP + extended, diabetes, and ten specialty packs), scoring, patient outcome trends, REST/API + FHIR export, and Enterprise org-level assessment analytics. Seed packs and design/licensing docs ship for deploy and pre-GA review.
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* PR 1 — Assessment engine schema (templates, questions, assessments, answers).
|
||||
* Scores: PR 4. Pathways: PR 5.
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('care_assessment_templates', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->uuid('uuid')->unique();
|
||||
// v1 always NULL (system catalog). Reserved for future org forks.
|
||||
$table->foreignId('organization_id')->nullable()->constrained('care_organizations')->nullOnDelete();
|
||||
$table->string('code');
|
||||
$table->string('name');
|
||||
$table->string('category'); // universal, disease, outcome, screening
|
||||
$table->text('description')->nullable();
|
||||
$table->unsignedInteger('version')->default(1);
|
||||
$table->boolean('is_current')->default(true);
|
||||
$table->string('scoring_strategy')->nullable(); // sum_items, single_value, custom:Handler
|
||||
$table->json('meta')->nullable();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
// Valid for v1 (system-only rows). Org clones out of scope.
|
||||
$table->unique(['code', 'version']);
|
||||
$table->index(['category', 'is_current', 'is_active']);
|
||||
$table->index(['code', 'is_current']);
|
||||
});
|
||||
|
||||
Schema::create('care_assessment_questions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('template_id')->constrained('care_assessment_templates')->cascadeOnDelete();
|
||||
$table->string('code');
|
||||
$table->string('section')->nullable();
|
||||
$table->string('label');
|
||||
$table->text('help_text')->nullable();
|
||||
$table->string('answer_type'); // text, number, boolean, date, single_choice, multi_choice, score_item, calculated
|
||||
$table->json('options')->nullable();
|
||||
$table->boolean('is_required')->default(false);
|
||||
$table->unsignedInteger('sort_order')->default(0);
|
||||
$table->string('score_key')->nullable();
|
||||
$table->json('validation')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['template_id', 'code']);
|
||||
$table->index(['template_id', 'sort_order']);
|
||||
});
|
||||
|
||||
Schema::create('care_assessments', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->uuid('uuid')->unique();
|
||||
$table->string('owner_ref')->index();
|
||||
$table->foreignId('organization_id')->constrained('care_organizations')->cascadeOnDelete();
|
||||
$table->foreignId('branch_id')->nullable()->constrained('care_branches')->nullOnDelete();
|
||||
$table->foreignId('patient_id')->constrained('care_patients')->cascadeOnDelete();
|
||||
// Frozen template version for historical integrity.
|
||||
$table->foreignId('template_id')->constrained('care_assessment_templates')->restrictOnDelete();
|
||||
$table->foreignId('consultation_id')->nullable()->constrained('care_consultations')->nullOnDelete();
|
||||
$table->foreignId('visit_id')->nullable()->constrained('care_visits')->nullOnDelete();
|
||||
// patient_pathway_id added in PR 5 when pathway tables exist.
|
||||
$table->foreignId('practitioner_id')->nullable()->constrained('care_practitioners')->nullOnDelete();
|
||||
$table->string('status')->default('draft'); // draft, completed, cancelled
|
||||
$table->timestamp('assessed_at')->nullable();
|
||||
$table->timestamp('completed_at')->nullable();
|
||||
$table->string('completed_by')->nullable();
|
||||
$table->string('started_by')->nullable();
|
||||
$table->text('notes')->nullable();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index(['patient_id', 'assessed_at']);
|
||||
$table->index(['consultation_id']);
|
||||
$table->index(['owner_ref', 'status']);
|
||||
$table->index(['template_id', 'status']);
|
||||
$table->index(['patient_id', 'template_id', 'status']);
|
||||
});
|
||||
|
||||
Schema::create('care_assessment_answers', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('owner_ref')->index();
|
||||
$table->foreignId('assessment_id')->constrained('care_assessments')->cascadeOnDelete();
|
||||
$table->foreignId('question_id')->constrained('care_assessment_questions')->restrictOnDelete();
|
||||
$table->text('value_text')->nullable();
|
||||
$table->decimal('value_number', 12, 4)->nullable();
|
||||
$table->boolean('value_boolean')->nullable();
|
||||
$table->dateTime('value_date')->nullable();
|
||||
$table->json('value_json')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['assessment_id', 'question_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('care_assessment_answers');
|
||||
Schema::dropIfExists('care_assessments');
|
||||
Schema::dropIfExists('care_assessment_questions');
|
||||
Schema::dropIfExists('care_assessment_templates');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/** PR 4 — materialize instrument scores on assessment complete. */
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('care_assessment_scores', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('owner_ref')->index();
|
||||
$table->foreignId('assessment_id')->constrained('care_assessments')->cascadeOnDelete();
|
||||
$table->string('template_code')->index();
|
||||
$table->decimal('total_score', 12, 4)->nullable();
|
||||
$table->decimal('max_score', 12, 4)->nullable();
|
||||
$table->json('subscores')->nullable();
|
||||
$table->string('severity_label')->nullable();
|
||||
$table->timestamp('computed_at');
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique('assessment_id');
|
||||
$table->index(['owner_ref', 'template_code', 'computed_at']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('care_assessment_scores');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* PR 5 — clinical pathway catalog + patient pathway activation.
|
||||
* Pathway bindings use template_code only (no template_id FK).
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('care_clinical_pathways', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->uuid('uuid')->unique();
|
||||
$table->string('code')->unique();
|
||||
$table->string('name');
|
||||
$table->text('description')->nullable();
|
||||
$table->json('match_rules')->nullable();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->unsignedInteger('sort_order')->default(0);
|
||||
$table->json('meta')->nullable();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
$table->index(['is_active', 'sort_order']);
|
||||
});
|
||||
|
||||
Schema::create('care_pathway_templates', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('pathway_id')->constrained('care_clinical_pathways')->cascadeOnDelete();
|
||||
$table->string('template_code');
|
||||
$table->boolean('is_required_on_activation')->default(false);
|
||||
$table->string('phase')->default('any'); // acute, follow_up, any
|
||||
$table->unsignedInteger('sort_order')->default(0);
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['pathway_id', 'template_code']);
|
||||
$table->index(['template_code']);
|
||||
});
|
||||
|
||||
Schema::create('care_patient_pathways', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->uuid('uuid')->unique();
|
||||
$table->string('owner_ref')->index();
|
||||
$table->foreignId('organization_id')->constrained('care_organizations')->cascadeOnDelete();
|
||||
$table->foreignId('patient_id')->constrained('care_patients')->cascadeOnDelete();
|
||||
$table->foreignId('pathway_id')->constrained('care_clinical_pathways')->restrictOnDelete();
|
||||
$table->string('status')->default('active'); // active, resolved, inactive
|
||||
$table->timestamp('activated_at');
|
||||
$table->string('activated_by')->nullable();
|
||||
$table->foreignId('activation_consultation_id')->nullable()->constrained('care_consultations')->nullOnDelete();
|
||||
$table->string('activation_diagnosis_text')->nullable();
|
||||
$table->timestamp('resolved_at')->nullable();
|
||||
$table->text('notes')->nullable();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index(['patient_id', 'status']);
|
||||
$table->index(['patient_id', 'pathway_id', 'status']);
|
||||
});
|
||||
|
||||
Schema::table('care_assessments', function (Blueprint $table) {
|
||||
$table->foreignId('patient_pathway_id')
|
||||
->nullable()
|
||||
->after('visit_id')
|
||||
->constrained('care_patient_pathways')
|
||||
->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('care_assessments', function (Blueprint $table) {
|
||||
$table->dropConstrainedForeignId('patient_pathway_id');
|
||||
});
|
||||
Schema::dropIfExists('care_patient_pathways');
|
||||
Schema::dropIfExists('care_pathway_templates');
|
||||
Schema::dropIfExists('care_clinical_pathways');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user