-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconsent.js
More file actions
89 lines (82 loc) · 1.79 KB
/
consent.js
File metadata and controls
89 lines (82 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { Reply } from '../models.js'
import { countAnswersNeedingTriage } from '../utils/reply.js'
import { formatLinkWithSecondaryText } from '../utils/string.js'
/**
* @class Consent
* @augments Reply
*/
export class Consent extends Reply {
/**
* Answers in this consent response need triage
*
* @returns {boolean} Has answers needing triage
*/
get hasAnswersNeedingTriage() {
return countAnswersNeedingTriage(this.healthAnswers) > 0
}
/**
* Get formatted links
*
* @returns {object} Formatted links
*/
get link() {
return {
summary: formatLinkWithSecondaryText(
this.uri,
this.parent.fullNameAndRelationship,
`for ${this.child.fullName}`
)
}
}
/**
* Get namespace
*
* @returns {string} Namespace
*/
get ns() {
return 'consent'
}
/**
* Get URI
*
* @returns {string} URI
*/
get uri() {
return `/consents/${this.uuid}`
}
/**
* Find all
*
* @param {object} context - Context
* @returns {Array<Consent>|undefined} Consents
* @static
*/
static findAll(context) {
return Object.values(context.replies)
.map((reply) => new Consent(reply, context))
.filter((consent) => !consent.invalid)
.filter((consent) => !consent.patient_uuid)
}
/**
* Find one
*
* @param {string} uuid - Reply UUID
* @param {object} context - Context
* @returns {Consent|undefined} Consent
* @static
*/
static findOne(uuid, context) {
if (context?.replies?.[uuid]) {
return new Consent(context.replies[uuid], context)
}
}
/**
* Link consent with patient record
*
* @param {import('./patient.js').Patient} patient - Patient
*/
linkToPatient(patient) {
this.patient_uuid = patient.uuid
patient.addReply(this)
}
}