import type { Task } from 'fhir/r4'; /** What an unnamed custom task is called, on create and on edit alike. */ export const customTaskCodeText = (title?: string): string => title?.trim() || 'Custom task'; export interface CustomTaskEdit { title?: string; instructions: string; priority?: Task['priority']; extension: Task['extension']; basedOn?: Task['basedOn']; restriction?: Task['restriction']; lastModified: string; } // The stored task with the edit applied; its identity, patient and codings stay as they were. export const applyCustomTaskEdit = (task: Task, edit: CustomTaskEdit): Task => ({ ...task, code: { ...task.code, text: customTaskCodeText(edit.title) }, description: edit.instructions.trim(), priority: edit.priority ?? task.priority, extension: edit.extension, basedOn: edit.basedOn, focus: task.focus?.reference?.startsWith('Appointment/') ? undefined : task.focus, restriction: edit.restriction, lastModified: edit.lastModified, });