Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEB-1495] Require clinician attestation of obtained permissions for custodial account creation #1042

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
23 changes: 23 additions & 0 deletions app/components/clinic/PatientForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import { Box, BoxProps } from 'rebass/styled-components';

import * as actions from '../../redux/actions';
import TextInput from '../../components/elements/TextInput';
import Checkbox from '../../components/elements/Checkbox';
import { getCommonFormikFieldProps } from '../../core/forms';
import { dateRegex, patientSchema as validationSchema } from '../../core/clinicUtils';
import { accountInfoFromClinicPatient } from '../../core/personutils';
import { Body1 } from '../../components/elements/FontStyles';
import baseTheme from '../../themes/baseTheme';

export const PatientForm = (props) => {
const { t, api, onFormChange, patient, trackMetric, ...boxProps } = props;
Expand Down Expand Up @@ -69,9 +71,11 @@ export const PatientForm = (props) => {

function getFormValues(source) {
return {
attestationSubmitted: get(source, 'attestationSubmitted', false),
birthDate: get(source, 'birthDate', ''),
email: get(source, 'email', ''),
fullName: get(source, 'fullName', ''),
id: get(source, 'id'),
mrn: get(source, 'mrn', ''),
};
}
Expand Down Expand Up @@ -149,6 +153,25 @@ export const PatientForm = (props) => {
<Body1>
{t('If you want your patients to upload their data from home, you must include their email address.')}
</Body1>

{!patient?.id && (
<Box
p={2}
mt={3}
mb={2}
bg="lightestGrey"
sx={{
border: baseTheme.borders.default,
borderRadius: `${baseTheme.radii.default}px`,
}}
>
<Checkbox
{...getCommonFormikFieldProps('attestationSubmitted', formikContext, 'checked')}
label={t('I attest that I have obtained permission from the patient and/or the patient\'s legal guardian to use Tidepool\'s software to assist in the management of the patient\'s health care.')}
themeProps={{ bg: 'lightestGrey', lineHeight: 1.4 }}
/>
</Box>
)}
</Box>
);
};
Expand Down
7 changes: 7 additions & 0 deletions app/core/clinicUtils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as yup from 'yup';
import get from 'lodash/get';
import includes from 'lodash/includes';
import isEmpty from 'lodash/isEmpty';
import keys from 'lodash/keys';
import map from 'lodash/map';
import moment from 'moment';
Expand Down Expand Up @@ -137,6 +138,7 @@ export const clinicSchema = yup.object().shape({
});

export const patientSchema = yup.object().shape({
id: yup.string(),
fullName: yup.string().required(t('Please enter the patient\'s full name')),
birthDate: yup.date()
.transform((value, originalValue) => {
Expand All @@ -148,4 +150,9 @@ export const patientSchema = yup.object().shape({
.required(t('Patient\'s birthday is required')),
mrn: yup.string(),
email: yup.string().email(t('Please enter a valid email address')),
attestationSubmitted: yup.mixed().notRequired().when('id', {
is: id => isEmpty(id),
then: yup.boolean()
.test('isTrue', t('Please confirm that you have obtained this permission'), value => (value === true)),
}),
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blip",
"version": "1.53.1-web-1577-date-format.1",
"version": "1.53.0-web-1495-patient-form-attestation",
"private": true,
"scripts": {
"test": "TZ=UTC NODE_ENV=test ./node_modules/karma/bin/karma start",
Expand Down
6 changes: 4 additions & 2 deletions test/unit/app/core/clinicUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@ describe('clinicUtils', function() {
});

describe('patientSchema', () => {
it('should return a yup schema for clinic fields', () => {
it('should return a yup schema for clinic patient fields', () => {
expect(clinicUtils.patientSchema).to.be.an('object');

expect(clinicUtils.patientSchema._nodes).to.be.an('array').and.have.members([
'fullName',
'attestationSubmitted',
'birthDate',
'email',
'fullName',
'id',
'mrn',
]);
});
Expand Down
8 changes: 8 additions & 0 deletions test/unit/pages/ClinicPatients.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ describe('ClinicPatients', () => {
patientForm().find('input[name="email"]').simulate('change', { persist: noop, target: { name: 'email', value: '[email protected]' } });
expect(patientForm().find('input[name="email"]').prop('value')).to.equal('[email protected]');

expect(patientForm().find('input[name="attestationSubmitted"]').prop('checked')).to.be.false;
patientForm().find('input[name="attestationSubmitted"]').simulate('change', { persist: noop, target: { name: 'attestationSubmitted', value: true } });
expect(patientForm().find('input[name="attestationSubmitted"]').prop('checked')).to.be.true;

store.clearActions();
dialog().find('Button#addPatientConfirm').simulate('click');

Expand Down Expand Up @@ -469,6 +473,10 @@ describe('ClinicPatients', () => {
patientForm().find('input[name="email"]').simulate('change', { persist: noop, target: { name: 'email', value: '[email protected]' } });
expect(patientForm().find('input[name="email"]').prop('value')).to.equal('[email protected]');

expect(patientForm().find('input[name="attestationSubmitted"]').prop('checked')).to.be.false;
patientForm().find('input[name="attestationSubmitted"]').simulate('change', { persist: noop, target: { name: 'attestationSubmitted', value: true } });
expect(patientForm().find('input[name="attestationSubmitted"]').prop('checked')).to.be.true;

expect(dialog().find('Button#addPatientConfirm').prop('disabled')).to.be.true;

patientForm().find('input[name="birthDate"]').simulate('change', { persist: noop, target: { name: 'birthDate', value: '11/21/1999' } });
Expand Down
8 changes: 8 additions & 0 deletions test/unit/pages/ClinicianPatients.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ describe('ClinicianPatients', () => {
patientForm().find('input[name="email"]').simulate('change', { persist: noop, target: { name: 'email', value: '[email protected]' } });
expect(patientForm().find('input[name="email"]').prop('value')).to.equal('[email protected]');

expect(patientForm().find('input[name="attestationSubmitted"]').prop('checked')).to.be.false;
patientForm().find('input[name="attestationSubmitted"]').simulate('change', { persist: noop, target: { name: 'attestationSubmitted', value: true } });
expect(patientForm().find('input[name="attestationSubmitted"]').prop('checked')).to.be.true;

store.clearActions();
dialog().find('Button#addPatientConfirm').simulate('click');

Expand Down Expand Up @@ -260,6 +264,10 @@ describe('ClinicianPatients', () => {
patientForm().find('input[name="email"]').simulate('change', { persist: noop, target: { name: 'email', value: '[email protected]' } });
expect(patientForm().find('input[name="email"]').prop('value')).to.equal('[email protected]');

expect(patientForm().find('input[name="attestationSubmitted"]').prop('checked')).to.be.false;
patientForm().find('input[name="attestationSubmitted"]').simulate('change', { persist: noop, target: { name: 'attestationSubmitted', value: true } });
expect(patientForm().find('input[name="attestationSubmitted"]').prop('checked')).to.be.true;

expect(dialog().find('Button#addPatientConfirm').prop('disabled')).to.be.true;

patientForm().find('input[name="birthDate"]').simulate('change', { persist: noop, target: { name: 'birthDate', value: '11/21/1999' } });
Expand Down