60 lines
2.1 KiB
JavaScript
60 lines
2.1 KiB
JavaScript
// Global prompts only. No private templates, Memories, or credential settings.
|
|
exports.up = pgm => {
|
|
pgm.sql(`
|
|
CREATE TABLE prompt_revisions (
|
|
id SERIAL PRIMARY KEY,
|
|
prompt_key TEXT NOT NULL CHECK (prompt_key IN (
|
|
'prompt.hpiEncounter',
|
|
'prompt.hpiDictation',
|
|
'prompt.hpiInpatient',
|
|
'prompt.hospitalCourseShort',
|
|
'prompt.hospitalCourseLong',
|
|
'prompt.hospitalCourseICU',
|
|
'prompt.hospitalCoursePsych',
|
|
'prompt.chartReviewOutpatient',
|
|
'prompt.chartReviewSubspecialty',
|
|
'prompt.chartReviewED',
|
|
'prompt.soapFull',
|
|
'prompt.soapSubjective',
|
|
'prompt.milestoneNarrative',
|
|
'prompt.milestoneList',
|
|
'prompt.milestoneSummary',
|
|
'prompt.peGuideNarrative',
|
|
'prompt.peGuideList',
|
|
'prompt.refine',
|
|
'prompt.shortenDocument',
|
|
'prompt.askClarification',
|
|
'prompt.shadessAssessment',
|
|
'prompt.wellVisitNote',
|
|
'prompt.wellVisitShort',
|
|
'prompt.sickVisitNote',
|
|
'prompt.edEncounterStaged',
|
|
'prompt.edConsolidate',
|
|
'prompt.edFinalize',
|
|
'prompt.dontMissTooltip',
|
|
'prompt.patientEducation',
|
|
'clinical_assistant.system_behavior',
|
|
'clinical_assistant.image_behavior'
|
|
)),
|
|
value TEXT NOT NULL,
|
|
was_default BOOLEAN NOT NULL,
|
|
created_by INTEGER,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
restored_from INTEGER,
|
|
UNIQUE (prompt_key, id),
|
|
FOREIGN KEY (prompt_key, restored_from) REFERENCES prompt_revisions (prompt_key, id)
|
|
);
|
|
-- Actor is a historical id, not a FK that user deletion could rewrite.
|
|
CREATE FUNCTION reject_prompt_revision_mutation() RETURNS trigger LANGUAGE plpgsql AS $$
|
|
BEGIN
|
|
RAISE EXCEPTION 'Prompt revisions are append-only';
|
|
END;
|
|
$$;
|
|
CREATE TRIGGER prompt_revisions_immutable BEFORE UPDATE OR DELETE ON prompt_revisions
|
|
FOR EACH ROW EXECUTE FUNCTION reject_prompt_revision_mutation();
|
|
`);
|
|
};
|
|
|
|
exports.down = pgm => {
|
|
pgm.sql('DROP TABLE prompt_revisions; DROP FUNCTION reject_prompt_revision_mutation();');
|
|
};
|