diff --git a/app/components/clinic/PatientForm.js b/app/components/clinic/PatientForm.js index c1bd83c799..366c6d8cb6 100644 --- a/app/components/clinic/PatientForm.js +++ b/app/components/clinic/PatientForm.js @@ -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; @@ -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', ''), }; } @@ -149,6 +153,25 @@ export const PatientForm = (props) => { {t('If you want your patients to upload their data from home, you must include their email address.')} + + {!patient?.id && ( + + + + )} ); }; diff --git a/app/core/clinicUtils.js b/app/core/clinicUtils.js index f1515c1e91..b6f38e5be5 100644 --- a/app/core/clinicUtils.js +++ b/app/core/clinicUtils.js @@ -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'; @@ -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) => { @@ -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)), + }), }); diff --git a/package.json b/package.json index 155735921f..e93b923a26 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/unit/app/core/clinicUtils.test.js b/test/unit/app/core/clinicUtils.test.js index a676d3f5cd..b855b31fd0 100644 --- a/test/unit/app/core/clinicUtils.test.js +++ b/test/unit/app/core/clinicUtils.test.js @@ -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', ]); }); diff --git a/test/unit/pages/ClinicPatients.test.js b/test/unit/pages/ClinicPatients.test.js index 8cc9e9d290..acee05a68b 100644 --- a/test/unit/pages/ClinicPatients.test.js +++ b/test/unit/pages/ClinicPatients.test.js @@ -402,6 +402,10 @@ describe('ClinicPatients', () => { patientForm().find('input[name="email"]').simulate('change', { persist: noop, target: { name: 'email', value: 'patient@test.ca' } }); expect(patientForm().find('input[name="email"]').prop('value')).to.equal('patient@test.ca'); + 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'); @@ -469,6 +473,10 @@ describe('ClinicPatients', () => { patientForm().find('input[name="email"]').simulate('change', { persist: noop, target: { name: 'email', value: 'patient@test.ca' } }); expect(patientForm().find('input[name="email"]').prop('value')).to.equal('patient@test.ca'); + 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' } }); diff --git a/test/unit/pages/ClinicianPatients.test.js b/test/unit/pages/ClinicianPatients.test.js index 235edeb5e6..5c86df65e2 100644 --- a/test/unit/pages/ClinicianPatients.test.js +++ b/test/unit/pages/ClinicianPatients.test.js @@ -196,6 +196,10 @@ describe('ClinicianPatients', () => { patientForm().find('input[name="email"]').simulate('change', { persist: noop, target: { name: 'email', value: 'patient@test.ca' } }); expect(patientForm().find('input[name="email"]').prop('value')).to.equal('patient@test.ca'); + 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'); @@ -260,6 +264,10 @@ describe('ClinicianPatients', () => { patientForm().find('input[name="email"]').simulate('change', { persist: noop, target: { name: 'email', value: 'patient@test.ca' } }); expect(patientForm().find('input[name="email"]').prop('value')).to.equal('patient@test.ca'); + 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' } });