This repository was archived by the owner on Sep 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathdrugInvolvement.js
56 lines (52 loc) · 2.12 KB
/
drugInvolvement.js
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
import { hasYesOrNo } from 'models/validate'
import { DEFAULT_LATEST } from 'constants/dateLimits'
// import { drugTypes } from 'constants/enums/substanceOptions'
const drugInvolvement = {
DrugType: { presence: true, hasValue: { validator: { exclusion: ['Other'] } } },
// TODO - add this back after fixing DrugType structure
/*
DrugType: { presence: true, hasValue: { validator: { inclusion: drugTypes } } },
DrugTypeExplanation: (value, attributes) => {
if (attributes.DrugType && attributes.DrugType.value === 'Other') {
return { presence: true, hasValue: true }
}
return {}
},
*/
FirstInvolvement: (value, attributes, attributeName, options = {}) => {
const { applicantBirthdate } = options
return {
presence: true,
date: { requireDay: false, earliest: applicantBirthdate, latest: DEFAULT_LATEST },
}
},
RecentInvolvement: (value, attributes) => {
const dateLimits = { latest: DEFAULT_LATEST }
if (attributes.FirstInvolvement) {
dateLimits.earliest = attributes.FirstInvolvement
}
return { presence: true, date: { requireDay: false, ...dateLimits } }
},
NatureOfInvolvement: { presence: true, hasValue: true },
Reasons: { presence: true, hasValue: true },
InvolvementWhileEmployed: (value, attributes, attributeName, options) => {
if (options && options.requireInvolvementWhileEmployed === false) return {}
return { presence: true, hasValue: { validator: hasYesOrNo } }
},
InvolvementWithClearance: (value, attributes, attributeName, options) => {
if (options && options.requireInvolvementWithClearance === false) return {}
return { presence: true, hasValue: { validator: hasYesOrNo } }
},
InvolvementInFuture: (value, attributes, attributeName, options) => {
if (options && options.requireInvolvementInFuture === false) return {}
return { presence: true, hasValue: { validator: hasYesOrNo } }
},
Explanation: (value, attributes) => {
if (attributes.InvolvementInFuture
&& attributes.InvolvementInFuture.value === 'Yes') {
return { presence: true, hasValue: true }
}
return {}
},
}
export default drugInvolvement