diff --git a/app/components/Notes.vue b/app/components/Notes.vue index f91ab5d..b3c7fb2 100644 --- a/app/components/Notes.vue +++ b/app/components/Notes.vue @@ -140,6 +140,7 @@ const selectedSessionNoteId = ref(null) const localPreviousNotes = ref([...props.previousNotes]) const localSessionNotes = ref([...props.sessionNotes]) + const showEditHistory = ref(false) const formEditPanelRef = ref<{ handleSave: () => void } | null>(null) @@ -253,6 +254,11 @@ async function selectSessionNote(sn: SessionNoteRow) { if (sn.status === 'DRAFT' && sn.appointmentId) { + selectedSessionNoteId.value = null + selectedPreviousNote.value = null + editingNoteId.value = null + editingSessionNoteId.value = null + isEditingPreviousPanel.value = false selectedAppointmentId.value = sn.appointmentId noteContent.value = sn.content currentNoteKind.value = sn.kind ?? 'PROGRESS' @@ -282,6 +288,7 @@ const noteContent = ref(props.currentNote.content || '') /** Kind for the current in-progress note; progress notes are the default. */ + watch(noteContent, (val) => console.log('noteContent changed:', val)) const currentNoteKind = ref('PROGRESS') /** Filter for the sidebar Notes tab: 'all' | 'PROGRESS' | 'PSYCHOTHERAPY'. */ const notesKindFilter = ref<'all' | NoteKind>('all') @@ -346,10 +353,6 @@ 'PCL-5': 'pcl', } - watch(sidebarTab, (t) => { - if (t !== 'forms') selectedForm.value = null - }) - const formPanelSubTab = ref<'answers' | 'history'>('answers') const CLINICAL_FORM_KEYS = new Set(['ace', 'gad', 'phq', 'pcl']) @@ -616,26 +619,64 @@ ) async function saveDraftNote() { - if (!noteContent.value.trim() || !selectedAppointmentId.value) return - saveStatus.value = 'saving' - try { - await $fetch(`/api/clients/${props.client.id}/notes`, { - method: 'POST', - body: { + if (!noteContent.value.trim() || !selectedAppointmentId.value) return + saveStatus.value = 'saving' + try { + const response = await $fetch(`/api/clients/${props.client.id}/notes`, { + method: 'POST', + body: { + content: noteContent.value, + appointmentId: selectedAppointmentId.value, + kind: currentNoteKind.value, + action: 'save-draft', + }, + }) as SessionNoteRow + + // Update or insert the saved note in the local list + const existingIdx = localSessionNotes.value.findIndex((n) => n.id === response.id) + const row: SessionNoteRow = { + id: response.id, + createdAt: response.createdAt, content: noteContent.value, - appointmentId: selectedAppointmentId.value, - kind: currentNoteKind.value, - action: 'draft', - }, - }) - localStorage.setItem(`note_draft_${props.client.id}`, noteContent.value) - lastSaved.value = new Date() - saveStatus.value = 'saved' - } catch (err) { - console.error('Draft save failed:', err) - saveStatus.value = 'error' + attendanceStatus: response.attendanceStatus ?? 'show', + sessionName: response.sessionName, + sessionNumber: response.sessionNumber, + appointmentId: response.appointmentId, + appointmentStartTime: selectedAppointment.value?.startTime ?? null, + kind: response.kind, + status: response.status, + } + if (existingIdx === -1) localSessionNotes.value.unshift(row) + else localSessionNotes.value[existingIdx] = row + + localStorage.setItem(`note_draft_${props.client.id}`, noteContent.value) + lastSaved.value = new Date() + saveStatus.value = 'saved' + } catch (err) { + console.error('Draft save failed:', err) + saveStatus.value = 'error' + } } - } +// if (!noteContent.value.trim() || !selectedAppointmentId.value) return +// saveStatus.value = 'saving' +// try { +// await $fetch(`/api/clients/${props.client.id}/notes`, { +// method: 'POST', +// body: { +// content: noteContent.value, +// appointmentId: selectedAppointmentId.value, +// kind: currentNoteKind.value, +// action: 'save-draft', +// }, +// }) +// localStorage.setItem(`note_draft_${props.client.id}`, noteContent.value) +// lastSaved.value = new Date() +// saveStatus.value = 'saved' +// } catch (err) { +// console.error('Draft save failed:', err) +// saveStatus.value = 'error' +// } +// } function startEditPrevious() { const sd = selectedNoteData.value @@ -698,6 +739,8 @@ showEditJustificationModal.value = false } + const showAttendanceWarningModal = ref(false) + const isSavingPrevious = ref(false) const didApplyInitialFocus = ref(false) @@ -857,6 +900,11 @@ async function saveNote() { if (!noteContent.value.trim()) return + if (!attendanceStatus.value) { + showAttendanceWarningModal.value = true + return + } + showSaveModal.value = true } @@ -1424,12 +1472,12 @@ class="flex min-h-0 flex-1 flex-col divide-y divide-gray-200 overflow-hidden border-l border-gray-200 md:flex-row md:divide-x md:divide-y-0 dark:divide-gray-800 dark:border-gray-800 min-w-0" >
@@ -1503,15 +1551,14 @@
-
-
-
+
+
+
+
+
+
+
+

+ Edited {{ new Date(edit.editedAt).toLocaleString('en-US') }} +

+

Reason: {{ edit.reason }}

+
-
+
@@ -1647,6 +1704,7 @@ @@ -1690,7 +1748,7 @@ !isEditingPreviousPanel && (!selectedAppointmentId || !canEditCurrentNote || !canMarkAttendance) " - @click="showSaveModal = true" + @click="saveNote" class="w-auto" />
@@ -1707,7 +1765,7 @@
-
+
@@ -1932,6 +1990,30 @@
+ + +
+
+

+ Please mark whether the client attended this session before submitting the note. +

+
+ +
+
+
+
+ + emit('update:modelValue', val)) +watch(() => props.modelValue, (val) => { + if (val !== localContent.value) localContent.value = val +}) + const items: EditorToolbarItem[][] = [ [ {