Refactored handle form submission function for first section
This commit is contained in:
parent
2e403624a8
commit
8419e26a4e
14
src/Components/Interface/Patient.tsx
Normal file
14
src/Components/Interface/Patient.tsx
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
export interface Patient {
|
||||||
|
fullName: string;
|
||||||
|
homePhone: string;
|
||||||
|
cellPhone: string;
|
||||||
|
email: string;
|
||||||
|
age: number | string;
|
||||||
|
dateOfBirth: string;
|
||||||
|
socialSecurityNumber: string;
|
||||||
|
mailingAddress: string;
|
||||||
|
city: string;
|
||||||
|
state: string;
|
||||||
|
zipCode: string;
|
||||||
|
gender: string;
|
||||||
|
}
|
||||||
@ -36,6 +36,7 @@ import ViewPatientImageMarker from '../ImageMarker/ViewPatientImageMarker';
|
|||||||
import AlertDialog from '../Helper/AlertDialogBox';
|
import AlertDialog from '../Helper/AlertDialogBox';
|
||||||
import SignatureComponent from '../Helper/SignatureComponent';
|
import SignatureComponent from '../Helper/SignatureComponent';
|
||||||
import { Link, useLocation } from 'react-router-dom';
|
import { Link, useLocation } from 'react-router-dom';
|
||||||
|
import { Patient } from '../Interface/Patient';
|
||||||
|
|
||||||
const Accordion = styled((props: AccordionProps) => (
|
const Accordion = styled((props: AccordionProps) => (
|
||||||
<MuiAccordion disableGutters elevation={0} square {...props} />
|
<MuiAccordion disableGutters elevation={0} square {...props} />
|
||||||
@ -91,36 +92,11 @@ export default function PatientForm({ type }: Props) {
|
|||||||
const [section7Data, setSection7Data] = React.useState<any>({});
|
const [section7Data, setSection7Data] = React.useState<any>({});
|
||||||
const [section8Data, setSection8Data] = React.useState<any>({});
|
const [section8Data, setSection8Data] = React.useState<any>({});
|
||||||
const [allPatientData, setAllPatientData] = React.useState<any>([]);
|
const [allPatientData, setAllPatientData] = React.useState<any>([]);
|
||||||
const [patientDetailsButtonFlag, setPatientDetailsButtonFlag ] = React.useState<boolean>(false)
|
const [patientDetailsButtonFlag, setPatientDetailsButtonFlag] =
|
||||||
|
React.useState<boolean>(false);
|
||||||
|
|
||||||
const handleFormSection1Data = (
|
const handleFormSection1Data = (patient: Patient) => {
|
||||||
fullName?: string | undefined,
|
setSection1Data(patient);
|
||||||
homePhone?: string | undefined,
|
|
||||||
cellPhone?: string | undefined,
|
|
||||||
email?: string | undefined,
|
|
||||||
age?: number | undefined | string,
|
|
||||||
dateOfBirth?: string | undefined,
|
|
||||||
socialSecurityNumber?: string | undefined,
|
|
||||||
mailingAddress?: string | undefined,
|
|
||||||
city?: string | undefined,
|
|
||||||
state?: string | undefined,
|
|
||||||
zipCode?: string | undefined,
|
|
||||||
gender?: string | undefined
|
|
||||||
) => {
|
|
||||||
setSection1Data({
|
|
||||||
fullName,
|
|
||||||
homePhone,
|
|
||||||
cellPhone,
|
|
||||||
email,
|
|
||||||
age,
|
|
||||||
dateOfBirth,
|
|
||||||
socialSecurityNumber,
|
|
||||||
mailingAddress,
|
|
||||||
city,
|
|
||||||
state,
|
|
||||||
zipCode,
|
|
||||||
gender,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleFormSection2Data = (
|
const handleFormSection2Data = (
|
||||||
@ -375,7 +351,7 @@ export default function PatientForm({ type }: Props) {
|
|||||||
section1Data.mailingAddress !== ''
|
section1Data.mailingAddress !== ''
|
||||||
) {
|
) {
|
||||||
TextFile();
|
TextFile();
|
||||||
setPatientDetailsButtonFlag(true)
|
setPatientDetailsButtonFlag(true);
|
||||||
setAlertProps({
|
setAlertProps({
|
||||||
open: true,
|
open: true,
|
||||||
severity: 'success',
|
severity: 'success',
|
||||||
@ -659,10 +635,15 @@ export default function PatientForm({ type }: Props) {
|
|||||||
<Grid container spacing={2} flexDirection={'row'}>
|
<Grid container spacing={2} flexDirection={'row'}>
|
||||||
{type !== 'display' ? (
|
{type !== 'display' ? (
|
||||||
<>
|
<>
|
||||||
|
|
||||||
<Grid item className='collapsable-form-style'>
|
<Grid item className='collapsable-form-style'>
|
||||||
<FormLabel sx={{marginLeft:'10px'}}> Signature:</FormLabel>
|
<FormLabel sx={{ marginLeft: '10px' }}>
|
||||||
<SignatureComponent signature={signature} setSignature={setSignature} />
|
{' '}
|
||||||
|
Signature:
|
||||||
|
</FormLabel>
|
||||||
|
<SignatureComponent
|
||||||
|
signature={signature}
|
||||||
|
setSignature={setSignature}
|
||||||
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Grid item>
|
<Grid item>
|
||||||
@ -708,37 +689,35 @@ export default function PatientForm({ type }: Props) {
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid container flexDirection={'row-reverse'}>
|
<Grid container flexDirection={'row-reverse'}>
|
||||||
{patientDetailsButtonFlag && type!=='display'?
|
{patientDetailsButtonFlag && type !== 'display' ? (
|
||||||
<Grid item>
|
<Grid item>
|
||||||
<Button
|
<Button
|
||||||
variant='contained'
|
variant='contained'
|
||||||
color='primary'
|
color='primary'
|
||||||
sx={{ margin: 5, width: '200px' }}
|
sx={{ margin: 5, width: '200px' }}
|
||||||
onClick={(e)=>{
|
onClick={(e) => {}}
|
||||||
|
|
||||||
}}
|
|
||||||
component={Link}
|
component={Link}
|
||||||
to='/view-details'
|
to='/view-details'
|
||||||
>
|
>
|
||||||
View Patient Details
|
View Patient Details
|
||||||
</Button>
|
</Button>
|
||||||
</Grid>:null}
|
</Grid>
|
||||||
|
) : null}
|
||||||
|
|
||||||
{type=='display'?
|
{type == 'display' ? (
|
||||||
<Grid item>
|
<Grid item>
|
||||||
<Button
|
<Button
|
||||||
variant='contained'
|
variant='contained'
|
||||||
color='primary'
|
color='primary'
|
||||||
sx={{ margin: 5, width: '200px' }}
|
sx={{ margin: 5, width: '200px' }}
|
||||||
onClick={(e)=>{
|
onClick={(e) => {}}
|
||||||
|
|
||||||
}}
|
|
||||||
component={Link}
|
component={Link}
|
||||||
to='/'
|
to='/'
|
||||||
>
|
>
|
||||||
New Patient Form
|
New Patient Form
|
||||||
</Button>
|
</Button>
|
||||||
</Grid>:null}
|
</Grid>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<Grid item>
|
<Grid item>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@ -13,37 +13,10 @@ import {
|
|||||||
import { LocalizationProvider, DatePicker } from '@mui/x-date-pickers';
|
import { LocalizationProvider, DatePicker } from '@mui/x-date-pickers';
|
||||||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
|
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
|
import { Patient } from '../Interface/Patient';
|
||||||
interface Patient {
|
|
||||||
fullName: string;
|
|
||||||
homePhone: string;
|
|
||||||
cellPhone: string;
|
|
||||||
email: string;
|
|
||||||
age: number | string;
|
|
||||||
dateOfBirth: string;
|
|
||||||
socialSecurityNumber: string;
|
|
||||||
mailingAddress: string;
|
|
||||||
city: string;
|
|
||||||
state: string;
|
|
||||||
zipCode: string;
|
|
||||||
gender: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
handleFormSection1Data: (
|
handleFormSection1Data: (patient: Patient) => void;
|
||||||
fullName?: string | undefined,
|
|
||||||
homePhone?: string | undefined,
|
|
||||||
cellPhone?: string | undefined,
|
|
||||||
email?: string | undefined,
|
|
||||||
age?: number | undefined | string,
|
|
||||||
dateOfBirth?: string | undefined,
|
|
||||||
socialSecurityNumber?: string | undefined,
|
|
||||||
mailingAddress?: string | undefined,
|
|
||||||
city?: string | undefined,
|
|
||||||
state?: string | undefined,
|
|
||||||
zipCode?: string | undefined,
|
|
||||||
gender?: string | undefined
|
|
||||||
) => void;
|
|
||||||
patientDataDiplay: any;
|
patientDataDiplay: any;
|
||||||
type: string;
|
type: string;
|
||||||
};
|
};
|
||||||
@ -54,41 +27,31 @@ export default function PersonalSection({
|
|||||||
type,
|
type,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const [birthDateValue, setBirthDateValue] = React.useState<any>();
|
const [birthDateValue, setBirthDateValue] = React.useState<any>();
|
||||||
const [patient, setPatient] = React.useState<any>({
|
const [patient, setPatient] = React.useState<Patient>({
|
||||||
fullName: '',
|
fullName: '',
|
||||||
fullNameError: false,
|
|
||||||
homePhone: '',
|
homePhone: '',
|
||||||
cellPhone: '',
|
cellPhone: '',
|
||||||
cellPhoneError: false,
|
|
||||||
email: '',
|
email: '',
|
||||||
emailError: false,
|
|
||||||
age: '',
|
age: '',
|
||||||
ageError: false,
|
|
||||||
dateOfBirth: birthDateValue,
|
dateOfBirth: birthDateValue,
|
||||||
socialSecurityNumber: '',
|
socialSecurityNumber: '',
|
||||||
mailingAddress: '',
|
mailingAddress: '',
|
||||||
mailingAddressFalse: false,
|
|
||||||
city: '',
|
city: '',
|
||||||
state: '',
|
state: '',
|
||||||
zipCode: '',
|
zipCode: '',
|
||||||
gender: 'male',
|
gender: 'male',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [errors, setErrors] = React.useState<any>({
|
||||||
|
fullNameError: false,
|
||||||
|
cellPhoneError: false,
|
||||||
|
emailError: false,
|
||||||
|
ageError: false,
|
||||||
|
mailingAddressFalse: false,
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handleFormSection1Data(
|
handleFormSection1Data(patient);
|
||||||
patient.fullName,
|
|
||||||
patient.homePhone,
|
|
||||||
patient.cellPhone,
|
|
||||||
patient.email,
|
|
||||||
patient.age,
|
|
||||||
birthDateValue,
|
|
||||||
patient.socialSecurityNumber,
|
|
||||||
patient.mailingAddress,
|
|
||||||
patient.city,
|
|
||||||
patient.state,
|
|
||||||
patient.zipCode,
|
|
||||||
patient.gender
|
|
||||||
);
|
|
||||||
}, [patient]);
|
}, [patient]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -109,7 +72,9 @@ export default function PersonalSection({
|
|||||||
name='fullName'
|
name='fullName'
|
||||||
placeholder='Please enter your name'
|
placeholder='Please enter your name'
|
||||||
value={
|
value={
|
||||||
type == 'display' ? patientDataDiplay && patientDataDiplay.fullName : patient.fullName
|
type == 'display'
|
||||||
|
? patientDataDiplay && patientDataDiplay.fullName
|
||||||
|
: patient.fullName
|
||||||
}
|
}
|
||||||
disabled={type == 'display'}
|
disabled={type == 'display'}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
@ -120,20 +85,20 @@ export default function PersonalSection({
|
|||||||
}}
|
}}
|
||||||
onBlur={(e) => {
|
onBlur={(e) => {
|
||||||
if (e.target.value === '') {
|
if (e.target.value === '') {
|
||||||
setPatient((prevValues: any) => ({
|
setErrors((prevValues: any) => ({
|
||||||
...prevValues,
|
...prevValues,
|
||||||
fullNameError: true,
|
fullNameError: true,
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
setPatient((prevValues: any) => ({
|
setErrors((prevValues: any) => ({
|
||||||
...prevValues,
|
...prevValues,
|
||||||
fullNameError: false,
|
fullNameError: false,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
required
|
required
|
||||||
error={patient.fullNameError}
|
error={errors.fullNameError}
|
||||||
helperText={patient.fullNameError ? 'Please enter your name' : ''}
|
helperText={errors.fullNameError ? 'Please enter your name' : ''}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
@ -171,20 +136,20 @@ export default function PersonalSection({
|
|||||||
}}
|
}}
|
||||||
onBlur={(e) => {
|
onBlur={(e) => {
|
||||||
if (!/^\d{10}$/.test(e.target.value)) {
|
if (!/^\d{10}$/.test(e.target.value)) {
|
||||||
setPatient((prevValues: any) => ({
|
setErrors((prevValues: any) => ({
|
||||||
...prevValues,
|
...prevValues,
|
||||||
cellPhoneError: true,
|
cellPhoneError: true,
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
setPatient((prevValues: any) => ({
|
setErrors((prevValues: any) => ({
|
||||||
...prevValues,
|
...prevValues,
|
||||||
cellPhoneError: false,
|
cellPhoneError: false,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
error={patient.cellPhoneError}
|
error={errors.cellPhoneError}
|
||||||
helperText={
|
helperText={
|
||||||
patient.cellPhoneError
|
errors.cellPhoneError
|
||||||
? 'Please enter a valid 10-digit phone number'
|
? 'Please enter a valid 10-digit phone number'
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
@ -238,7 +203,11 @@ export default function PersonalSection({
|
|||||||
label='Email'
|
label='Email'
|
||||||
name='email'
|
name='email'
|
||||||
placeholder='Please enter your email'
|
placeholder='Please enter your email'
|
||||||
value={type == 'display' ? patientDataDiplay && patientDataDiplay.email : patient.email}
|
value={
|
||||||
|
type == 'display'
|
||||||
|
? patientDataDiplay && patientDataDiplay.email
|
||||||
|
: patient.email
|
||||||
|
}
|
||||||
disabled={type == 'display'}
|
disabled={type == 'display'}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setPatient((prevValues: any) => ({
|
setPatient((prevValues: any) => ({
|
||||||
@ -248,20 +217,20 @@ export default function PersonalSection({
|
|||||||
}}
|
}}
|
||||||
onBlur={(e) => {
|
onBlur={(e) => {
|
||||||
if (!/^\S+@\S+\.\S+$/.test(e.target.value)) {
|
if (!/^\S+@\S+\.\S+$/.test(e.target.value)) {
|
||||||
setPatient((prevValues: any) => ({
|
setErrors((prevValues: any) => ({
|
||||||
...prevValues,
|
...prevValues,
|
||||||
emailError: true,
|
emailError: true,
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
setPatient((prevValues: any) => ({
|
setErrors((prevValues: any) => ({
|
||||||
...prevValues,
|
...prevValues,
|
||||||
emailError: false,
|
emailError: false,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
error={patient.emailError}
|
error={errors.emailError}
|
||||||
helperText={
|
helperText={
|
||||||
patient.emailError ? 'Please enter a valid email address' : ''
|
errors.emailError ? 'Please enter a valid email address' : ''
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
@ -281,7 +250,11 @@ export default function PersonalSection({
|
|||||||
name='age'
|
name='age'
|
||||||
type='number'
|
type='number'
|
||||||
placeholder='Please enter your age'
|
placeholder='Please enter your age'
|
||||||
value={type == 'display' ? patientDataDiplay && patientDataDiplay.age : patient.age}
|
value={
|
||||||
|
type == 'display'
|
||||||
|
? patientDataDiplay && patientDataDiplay.age
|
||||||
|
: patient.age
|
||||||
|
}
|
||||||
disabled={type == 'display'}
|
disabled={type == 'display'}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setPatient((prevValues: any) => ({
|
setPatient((prevValues: any) => ({
|
||||||
@ -291,19 +264,19 @@ export default function PersonalSection({
|
|||||||
}}
|
}}
|
||||||
onBlur={(e) => {
|
onBlur={(e) => {
|
||||||
if (e.target.value === '') {
|
if (e.target.value === '') {
|
||||||
setPatient((prevValues: any) => ({
|
setErrors((prevValues: any) => ({
|
||||||
...prevValues,
|
...prevValues,
|
||||||
ageError: true,
|
ageError: true,
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
setPatient((prevValues: any) => ({
|
setErrors((prevValues: any) => ({
|
||||||
...prevValues,
|
...prevValues,
|
||||||
ageError: false,
|
ageError: false,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
error={patient.ageError}
|
error={errors.ageError}
|
||||||
helperText={patient.ageError ? 'Please enter your age' : ''}
|
helperText={errors.ageError ? 'Please enter your age' : ''}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
@ -396,20 +369,20 @@ export default function PersonalSection({
|
|||||||
}}
|
}}
|
||||||
onBlur={(e) => {
|
onBlur={(e) => {
|
||||||
if (e.target.value === '') {
|
if (e.target.value === '') {
|
||||||
setPatient((prevValues: any) => ({
|
setErrors((prevValues: any) => ({
|
||||||
...prevValues,
|
...prevValues,
|
||||||
mailingAddressError: true,
|
mailingAddressError: true,
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
setPatient((prevValues: any) => ({
|
setErrors((prevValues: any) => ({
|
||||||
...prevValues,
|
...prevValues,
|
||||||
mailingAddressError: false,
|
mailingAddressError: false,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
error={patient.mailingAddressError}
|
error={errors.mailingAddressError}
|
||||||
helperText={
|
helperText={
|
||||||
patient.mailingAddressError
|
errors.mailingAddressError
|
||||||
? 'Please enter your mailing address'
|
? 'Please enter your mailing address'
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
@ -429,7 +402,11 @@ export default function PersonalSection({
|
|||||||
variant='outlined'
|
variant='outlined'
|
||||||
label='State'
|
label='State'
|
||||||
name='state'
|
name='state'
|
||||||
value={type == 'display' ? patientDataDiplay && patientDataDiplay.state : patient.state}
|
value={
|
||||||
|
type == 'display'
|
||||||
|
? patientDataDiplay && patientDataDiplay.state
|
||||||
|
: patient.state
|
||||||
|
}
|
||||||
disabled={type == 'display'}
|
disabled={type == 'display'}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setPatient((prevValues: any) => ({
|
setPatient((prevValues: any) => ({
|
||||||
@ -453,7 +430,11 @@ export default function PersonalSection({
|
|||||||
variant='outlined'
|
variant='outlined'
|
||||||
label='City'
|
label='City'
|
||||||
name='city'
|
name='city'
|
||||||
value={type == 'display' ? patientDataDiplay && patientDataDiplay.city : patient.city}
|
value={
|
||||||
|
type == 'display'
|
||||||
|
? patientDataDiplay && patientDataDiplay.city
|
||||||
|
: patient.city
|
||||||
|
}
|
||||||
disabled={type == 'display'}
|
disabled={type == 'display'}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setPatient((prevValues: any) => ({
|
setPatient((prevValues: any) => ({
|
||||||
@ -478,7 +459,9 @@ export default function PersonalSection({
|
|||||||
label='Zip Code'
|
label='Zip Code'
|
||||||
name='zipCode'
|
name='zipCode'
|
||||||
value={
|
value={
|
||||||
type == 'display' ? patientDataDiplay && patientDataDiplay.zipCode : patient.zipCode
|
type == 'display'
|
||||||
|
? patientDataDiplay && patientDataDiplay.zipCode
|
||||||
|
: patient.zipCode
|
||||||
}
|
}
|
||||||
disabled={type == 'display'}
|
disabled={type == 'display'}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
@ -507,7 +490,9 @@ export default function PersonalSection({
|
|||||||
<RadioGroup
|
<RadioGroup
|
||||||
aria-labelledby='demo-radio-buttons-group-label'
|
aria-labelledby='demo-radio-buttons-group-label'
|
||||||
defaultValue={
|
defaultValue={
|
||||||
type == 'display' ? patientDataDiplay && patientDataDiplay.gender : patient.gender
|
type == 'display'
|
||||||
|
? patientDataDiplay && patientDataDiplay.gender
|
||||||
|
: patient.gender
|
||||||
}
|
}
|
||||||
name='radio-buttons-group'
|
name='radio-buttons-group'
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user