Skip to content

Commit

Permalink
Merge pull request #1419 from tidepool-org/WEB-3068-default-device-se…
Browse files Browse the repository at this point in the history
…lection

[WEB-3068] Skip device selection if only one pump and cgm option available
  • Loading branch information
clintonium-119 authored Aug 16, 2024
2 parents 5a6bb7a + b1272ac commit 61493ec
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 16 deletions.
22 changes: 17 additions & 5 deletions app/pages/prescription/PrescriptionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import * as actions from '../../redux/actions';
import { components as vizComponents } from '@tidepool/viz';

import {
cgmDeviceOptions,
defaultUnits,
deviceIdMap,
prescriptionStateOptions,
Expand Down Expand Up @@ -335,7 +336,7 @@ export const PrescriptionForm = props => {
const [singleStepEditValues, setSingleStepEditValues] = useState(values);
const isSingleStepEdit = !!pendingStep.length;
const validationFields = [ ...stepValidationFields ];
const isLastStep = activeStep === validationFields.length - 1;
const isLastStep = () => activeStep === validationFields.length - 1;
const isNewPrescription = isEmpty(get(values, 'id'));

const handlers = {
Expand Down Expand Up @@ -379,7 +380,7 @@ export const PrescriptionForm = props => {
// We can't simply delete all future steps, as the clinician may have returned to the current
// step via 'Back' button navigation and we don't want to lose existing data previously
// entered in the later steps.
if (!isLastStep) {
if (!isLastStep()) {
const emptyFieldsInFutureSteps = remove(
flattenDeep(slice(validationFields, activeStep + 1)),
fieldPath => {
Expand Down Expand Up @@ -415,7 +416,7 @@ export const PrescriptionForm = props => {
prescriptionAttributes.createdUserId = loggedInUserId;
prescriptionAttributes.prescriberTermsAccepted = isPrescriber && get(values, 'therapySettingsReviewed');

if (isLastStep) prescriptionAttributes.state = isPrescriber ? 'submitted' : 'pending';
if (isLastStep()) prescriptionAttributes.state = isPrescriber ? 'submitted' : 'pending';
setFieldValue('state', prescriptionAttributes.state);

prescriptionAttributes.revisionHash = await sha512(
Expand Down Expand Up @@ -480,8 +481,19 @@ export const PrescriptionForm = props => {
},
];

// Remove calculator step if selected pump, or all available pump options are set to skip aace calculator
const pumpDevices = pumpDeviceOptions(devices);
const cgmDevices = cgmDeviceOptions(devices);

// Skip device selection substep and set default pump and cgm IDs if there aren't multiple choices available
const skipDeviceSelection = cgmDevices.length === 1 && pumpDevices.length === 1;
if (skipDeviceSelection) {
if (!values.initialSettings?.cgmId) setFieldValue('initialSettings.cgmId', cgmDevices[0].value);
if (!values.initialSettings?.pumpId) setFieldValue('initialSettings.pumpId', pumpDevices[0].value);
validationFields[1].splice(2, 1);
steps[1].subSteps.splice(3, 1);
}

// Skip calculator step if selected pump, or all available pump options are set to skip aace calculator
const skipCalculator = !!(pumpDevices.length && every(pumpDevices, { skipCalculator: true })) || !!find(devices, { value: pumpId })?.skipCalculator;
if (skipCalculator) {
validationFields.splice(2, 1);
Expand Down Expand Up @@ -552,7 +564,7 @@ export const PrescriptionForm = props => {
if (!isFirstRender && !inProgress) {
if (completed) {
setStepAsyncState(asyncStates.completed);
if (isLastStep) {
if (isLastStep()) {

let messageAction = isRevision ? t('updated') : t('created');
if (isPrescriber) messageAction = t('finalized and sent');
Expand Down
6 changes: 3 additions & 3 deletions app/pages/prescription/accountFormSteps.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const AccountType = withTranslation()(props => {
const formikContext = useFormikContext();

return (
<Box {...fieldsetStyles}>
<Box id="account-type-step" {...fieldsetStyles}>
<Headline mb={4}>{t('Who are you creating an account for?')}</Headline>
<FastField
as={RadioGroup}
Expand Down Expand Up @@ -55,7 +55,7 @@ export const PatientInfo = withTranslation()(props => {
const maskFormat = dateInputFormat.replace(/[A-Z]/g, '9');

return (
<Box {...fieldsetStyles}>
<Box id="patient-info-step" {...fieldsetStyles}>
<Headline mb={4}>{t('Please enter the patient\'s name and birthdate')}</Headline>
<FastField
as={TextInput}
Expand Down Expand Up @@ -138,7 +138,7 @@ export const PatientEmail = withTranslation()(props => {
}, []);

return (
<Box {...fieldsetStyles}>
<Box id="patient-email-step" {...fieldsetStyles}>
<Headline mb={4}>{headline}</Headline>
{isCaregiverAccount && (
<FastField
Expand Down
8 changes: 4 additions & 4 deletions app/pages/prescription/profileFormSteps.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const PatientPhone = withTranslation()(props => {
const initialFocusedInputRef = useInitialFocusedInput();

return (
<Box {...fieldsetStyles}>
<Box id='patient-phone-step' {...fieldsetStyles}>
<Headline mb={4}>{t('What is the mobile phone number {{patientName}} will use with Tidepool Loop?', { patientName })}</Headline>
<FastField
as={({ innerRef }) => (
Expand Down Expand Up @@ -90,7 +90,7 @@ export const PatientMRN = withTranslation()(props => {
const initialFocusedInputRef = useInitialFocusedInput();

return (
<Box {...fieldsetStyles}>
<Box id='patient-mrn-step' {...fieldsetStyles}>
<Headline mb={4}>{t('What is {{patientName}}\'s Medical Record Number?', { patientName })}</Headline>
<FastField
as={TextInput}
Expand All @@ -113,7 +113,7 @@ export const PatientGender = withTranslation()(props => {
const initialFocusedInputRef = useInitialFocusedInput();

return (
<Box {...fieldsetStyles}>
<Box id='patient-gender-step' {...fieldsetStyles}>
<Headline mb={4}>{t('What is {{patientName}}\'s gender?', { patientName })}</Headline>
<FastField
as={RadioGroup}
Expand Down Expand Up @@ -144,7 +144,7 @@ export const PatientDevices = withTranslation()(props => {
const [hasInitialFocus, setHasInitialFocus] = React.useState(true);

return (
<Box {...fieldsetStyles}>
<Box id='patient-devices-step' {...fieldsetStyles}>
<Headline mb={4}>{t('Does {{patientName}} have the necessary prescriptions for Tidepool Loop compatible devices?', { patientName })}</Headline>
<Flex {...checkboxGroupStyles}>
{map(pumpDeviceOptions(devices), device => (
Expand Down
1 change: 1 addition & 0 deletions app/pages/prescription/reviewFormStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ export const PrescriptionReview = withTranslation()(props => {

return (
<Flex
id="prescription-review-step"
sx={{
flexWrap: 'wrap',
margin: 'auto',
Expand Down
4 changes: 2 additions & 2 deletions app/pages/prescription/settingsCalculatorFormSteps.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const CalculatorMethod = withTranslation()(props => {
}, [method]);

return (
<Box {...fieldsetStyles}>
<Box id="calculator-method-step" {...fieldsetStyles}>
<Headline mb={4}>{t('Optional Therapy Settings Calculator')}</Headline>
<Box mb={4}>
<Paragraph1>
Expand Down Expand Up @@ -97,7 +97,7 @@ export const CalculatorInputs = withTranslation()(props => {
const showWeight = includes(['weight', 'totalDailyDoseAndWeight'], method);

return (
<Box {...fieldsetStyles}>
<Box id="calculator-inputs-step" {...fieldsetStyles}>
<Headline mb={4}>{t('Optional Therapy Settings Calculator')}</Headline>

<Box mb={4}>
Expand Down
2 changes: 1 addition & 1 deletion app/pages/prescription/therapySettingsFormStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ export const TherapySettings = withTranslation()(props => {
});

return (
<Box>
<Box id="therapy-settings-step">
<PatientInfo mb={4} {...props} />
{hasCalculatorResults(values) && <DefaultCalculatorSettings mt={0} mb={4} {...props} />}
<PatientTraining mt={0} mb={4} {...props} />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"node": "20.8.0"
},
"packageManager": "[email protected]",
"version": "1.81.0-web-3020-disable-ace-calculator-palmtree.1",
"version": "1.81.0-web-3068-default-device-selection.1",
"private": true,
"scripts": {
"test": "TZ=UTC NODE_ENV=test NODE_OPTIONS='--max-old-space-size=4096' yarn karma start",
Expand Down

0 comments on commit 61493ec

Please sign in to comment.