From f90c3c398b40d50e501573bfde2cdc66d0aeeb70 Mon Sep 17 00:00:00 2001 From: Savy011 <106910589+Savy011@users.noreply.github.com> Date: Thu, 1 Jun 2023 11:31:27 +0530 Subject: [PATCH] Finished Ex 9.28 --- .../components/AddEntryModal/AddEntryForm.tsx | 216 +++++++++++++++--- Part_9/patientor/frontend/src/types.ts | 2 +- 2 files changed, 189 insertions(+), 29 deletions(-) diff --git a/Part_9/patientor/frontend/src/components/AddEntryModal/AddEntryForm.tsx b/Part_9/patientor/frontend/src/components/AddEntryModal/AddEntryForm.tsx index 60bd2f3..d11431b 100644 --- a/Part_9/patientor/frontend/src/components/AddEntryModal/AddEntryForm.tsx +++ b/Part_9/patientor/frontend/src/components/AddEntryModal/AddEntryForm.tsx @@ -7,6 +7,133 @@ interface Props { onSubmit: (values: EntryFormValues) => void } +const OccupationalHealthcareForm = ({ + style, + employerName, + startDate, + endDate, + setEmployerName, + setStartDate, + setEndDate, +}: { + style: React.CSSProperties + employerName: string, + startDate: string, + endDate: string, + setEmployerName: React.Dispatch>, + setStartDate: React.Dispatch> + setEndDate: React.Dispatch> +}) => { + return ( + <> + +
+ setEmployerName(e.target.value)} + /> +
+ Sick Leave +
+ setStartDate(e.target.value)} + /> +
+
+ setEndDate(e.target.value)} + /> +
+
+ + ) +} + +const HealthCheckForm = ({ + style, + radioValue, + setRadioValue +}: { + style: React.CSSProperties, + radioValue: string, + setRadioValue: React.Dispatch> +}) => { + return ( + <> + + Health Check Rating + setRadioValue(e.target.value)} + > + } + label="Healthy" + /> + } + label="Low Risk" + /> + } + label="High Risk" + /> + } + label="Critical Risk" + /> + + + + ) +} + +const HospitalForm = ({ + style, + dischargeDate, + dischargeCriteria, + setDischargeDate, + setDischargeCriteria +}: { + style: React.CSSProperties, + dischargeDate: string, + dischargeCriteria: string, + setDischargeDate: React.Dispatch>, + setDischargeCriteria: React.Dispatch> +}) => { + return ( + + Discharge +
+ setDischargeDate(e.target.value)} + /> +
+
+ setDischargeCriteria(e.target.value)} + /> +
+
+ ) +} + const AddPatientForm = ({ onClose, onSubmit }: Props) => { const [date, setDate] = useState('') const [description, setDescription] = useState('') @@ -14,6 +141,12 @@ const AddPatientForm = ({ onClose, onSubmit }: Props) => { const [diagnosisCodes, setDiagnosisCodes] = useState('') const [entryType, setEntryType] = useState('') const [radioValue, setRadioValue] = useState('') + const [dischargeDate, setDischargeDate] = useState('') + const [dischargeCriteria, setDischargeCriteria] = useState('') + const [employerName, setEmployerName] = useState('') + const [startDate, setStartDate] = useState('') + const [endDate, setEndDate] = useState('') + const style: React.CSSProperties = { margin: 10 @@ -30,6 +163,36 @@ const AddPatientForm = ({ onClose, onSubmit }: Props) => { type: entryType, healthCheckRating: Number(radioValue), } + console.log(object) + onSubmit(object) + } else if (entryType === EntryType.Hospital) { + const object = { + date, + description, + specialist, + diagnosisCodes, + type: entryType, + discharge: { + date: dischargeDate, + criteria: dischargeCriteria + } + } + console.log(object) + onSubmit(object) + } else if (entryType === EntryType.OccupationalHealthcare) { + const object = { + date, + description, + specialist, + diagnosisCodes, + type: entryType, + employerName, + sickLeave: { + startDate, + endDate + } + } + console.log(object) onSubmit(object) } @@ -83,37 +246,34 @@ const AddPatientForm = ({ onClose, onSubmit }: Props) => { Health Check Occupational Healthcare +
{entryType === EntryType.HealthCheck - ? ( - Health Check Rating - setRadioValue(e.target.value)} - > - } - label="Healthy" - /> - } - label="Low Risk" - /> - } - label="High Risk" - /> - } - label="Critical Risk" - /> - - ) + ? () + : entryType === EntryType.Hospital + ? () + : entryType === EntryType.OccupationalHealthcare + ? () : null } +
diff --git a/Part_9/patientor/frontend/src/types.ts b/Part_9/patientor/frontend/src/types.ts index 4011abe..0534e4e 100644 --- a/Part_9/patientor/frontend/src/types.ts +++ b/Part_9/patientor/frontend/src/types.ts @@ -59,7 +59,6 @@ export interface OccupationalHealthcareEntry extends BaseEntry { export type Entry = HospitalEntry | HealthCheckEntry | OccupationalHealthcareEntry - export interface Patient { id: string; name: string; @@ -83,6 +82,7 @@ export type EntryFormValues = { date: string; criteria: string; }; + employerName?: string; sickLeave?: { startDate: string; endDate: string; -- 2.51.2