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 pathdrugOrderedTreatment.js
93 lines (88 loc) · 2.71 KB
/
drugOrderedTreatment.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
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
90
91
92
93
import { hasYesOrNo, checkValue } from 'models/validate'
import address from 'models/shared/locations/address'
import phone from 'models/shared/phone'
// import { drugTypes } from 'constants/enums/substanceOptions'
import { DEFAULT_LATEST } from 'constants/dateLimits'
const drugOrderedTreatment = {
DrugType: (value, attributes) => {
if (checkValue(attributes.ActionTaken, 'Yes')) {
return {
presence: true,
hasValue: { validator: { exclusion: ['Other'] } },
}
}
return {}
},
// 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 {}
},
*/
Explanation: { presence: true, hasValue: true },
ActionTaken: { presence: true, hasValue: { validator: hasYesOrNo } },
OrderedBy: (value) => {
const length = { minimum: 1 }
if (value && value.values && value.values.includes('None')) {
length.maximum = 1
}
return {
presence: true,
array: {
validator: { presence: true },
length,
},
}
},
TreatmentProvider: (value, attributes) => {
if (checkValue(attributes.ActionTaken, 'Yes')) {
return { presence: true, hasValue: true }
}
return {}
},
TreatmentProviderAddress: (value, attributes) => {
if (checkValue(attributes.ActionTaken, 'Yes')) {
return { presence: true, location: { validator: address } }
}
return {}
},
TreatmentProviderTelephone: (value, attributes) => {
if (checkValue(attributes.ActionTaken, 'Yes')) {
return { presence: true, model: { validator: phone, requireNumber: true } }
}
return {}
},
TreatmentDates: (value, attributes, attributeName, options = {}) => {
if (checkValue(attributes.ActionTaken, 'Yes')) {
const { applicantBirthdate } = options
return {
presence: true,
daterange: { earliest: applicantBirthdate, latest: DEFAULT_LATEST },
}
}
return {}
},
TreatmentCompleted: (value, attributes) => {
if (checkValue(attributes.ActionTaken, 'Yes')) {
return { presence: true, hasValue: { validator: hasYesOrNo } }
}
return {}
},
NoTreatmentExplanation: (value, attributes) => {
if (checkValue(attributes.TreatmentCompleted, 'No')) {
return { presence: true, hasValue: true }
}
return {}
},
NoActionTakenExplanation: (value, attributes) => {
if (checkValue(attributes.ActionTaken, 'No')) {
return { presence: true, hasValue: true }
}
return {}
},
}
export default drugOrderedTreatment