Skip to content

Commit a56bb0e

Browse files
Refactor pinned notes
1 parent ba2a63f commit a56bb0e

6 files changed

Lines changed: 16 additions & 16 deletions

File tree

app/controllers/patient-session.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
AuditEventType,
32
ConsentOutcome,
43
ConsentWindow,
54
InstructionOutcome,
@@ -20,7 +19,6 @@ import {
2019
Vaccination
2120
} from '../models.js'
2221
import { today } from '../utils/date.js'
23-
import { stringToBoolean } from '../utils/string.js'
2422

2523
export const patientSessionController = {
2624
read(request, response, next, nhsn) {
@@ -378,15 +376,13 @@ export const patientSessionController = {
378376

379377
note(request, response) {
380378
const { account } = request.app.locals
381-
let { note, pinned } = request.body
379+
const { note, pinned } = request.body
382380
const { data } = request.session
383381
const { __, back, patientSession } = response.locals
384382

385-
pinned = stringToBoolean(pinned)
386-
387383
patientSession.saveNote({
388-
name: pinned ? AuditEventType.Pinned : AuditEventType.SessionNote,
389384
note,
385+
pinned,
390386
createdBy_uid: account.uid
391387
})
392388

app/controllers/patient.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import _ from 'lodash'
22

33
import {
44
ArchiveRecordReason,
5-
AuditEventType,
65
PatientStatus,
76
ProgrammeType,
87
SessionPresetName,
@@ -401,7 +400,6 @@ export const patientController = {
401400
const { __, patient } = response.locals
402401

403402
patient.saveNote({
404-
name: AuditEventType.RecordNote,
405403
note,
406404
createdBy_uid: account.uid
407405
})

app/enums.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ export const ArchiveRecordReason = {
5151
*/
5252
export const AuditEventType = {
5353
Notice: 'Notice',
54-
Pinned: 'Pinned session note',
5554
Reminder: 'Reminder',
5655
Record: 'Change to child record',
57-
RecordNote: 'Note added to child record',
56+
RecordNote: 'Child record note',
5857
SessionNote: 'Session note'
5958
}
6059

app/models/audit-event.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { getScreenOutcomeStatus } from '../utils/status.js'
1111
import {
1212
formatTag,
1313
formatMarkdown,
14-
formatWithSecondaryText
14+
formatWithSecondaryText,
15+
stringToBoolean
1516
} from '../utils/string.js'
1617

1718
/**
@@ -23,6 +24,7 @@ import {
2324
* @property {string} [createdBy_uid] - User who created event
2425
* @property {string} name - Name
2526
* @property {string} [note] - Note
27+
* @property {boolean} [pinned] - Pinned
2628
* @property {AuditEventType} [type] - Audit event type
2729
* @property {string} [outcome] - Outcome for activity type
2830
* @property {Date} [outcomeAt] - Date outcome invalidates
@@ -36,6 +38,7 @@ export class AuditEvent {
3638
this.createdBy_uid = options?.createdBy_uid
3739
this.name = options.name
3840
this.note = options.note
41+
this.pinned = stringToBoolean(options?.pinned)
3942
this.type = options?.type
4043
this.outcome = options?.outcome
4144
this.outcomeAt = options?.outcomeAt && new Date(options.outcomeAt)

app/models/patient-session.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class PatientSession {
180180
get pinnedNotes() {
181181
return this.auditEvents
182182
.filter(({ programme_ids }) => programme_ids.includes(this.programme_id))
183-
.filter(({ name }) => name === AuditEventType.Pinned)
183+
.filter(({ pinned }) => pinned)
184184
.sort((a, b) => getDateValueDifference(b.createdAt, a.createdAt))
185185
}
186186

@@ -1029,8 +1029,10 @@ export class PatientSession {
10291029
*/
10301030
saveNote(event) {
10311031
this.patient.addEvent({
1032-
name: event.name,
1032+
type: AuditEventType.SessionNote,
1033+
name: `${AuditEventType.SessionNote} added`,
10331034
note: event.note,
1035+
pinned: event.pinned,
10341036
createdBy_uid: event.createdBy_uid,
10351037
programme_ids: this.session.programme_ids
10361038
})

app/models/patient.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@ export class Patient extends Child {
234234

235235
return events
236236
.map((auditEvent) => new AuditEvent(auditEvent, this.context))
237-
.filter(({ type }) => type === AuditEventType.Record)
237+
.filter(({ type }) =>
238+
[AuditEventType.Record, AuditEventType.RecordNote].includes(type)
239+
)
238240
}
239241

240242
/**
@@ -686,8 +688,8 @@ export class Patient extends Child {
686688
*/
687689
saveNote(event) {
688690
this.addEvent({
689-
type: AuditEventType.Record,
690-
name: event.name,
691+
type: AuditEventType.RecordNote,
692+
name: `${AuditEventType.RecordNote} added`,
691693
note: event.note,
692694
createdBy_uid: event.createdBy_uid
693695
})

0 commit comments

Comments
 (0)