From d0dac925e9e9647432134810f5d75e2bb0ce76b5 Mon Sep 17 00:00:00 2001 From: Abhay Date: Mon, 6 Jan 2025 11:52:09 +0530 Subject: [PATCH 1/2] Fix typos, bugs --- components/PrescriptionCreator/MedicineForm.tsx | 2 +- components/PrescriptionCreator/PatientForm.tsx | 2 +- components/PrescriptionCreator/index.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/PrescriptionCreator/MedicineForm.tsx b/components/PrescriptionCreator/MedicineForm.tsx index 683d246..47e7bf3 100644 --- a/components/PrescriptionCreator/MedicineForm.tsx +++ b/components/PrescriptionCreator/MedicineForm.tsx @@ -85,7 +85,7 @@ export const MedicineForm: React.FC = ({ handleTextChange('directions', text)} /> diff --git a/components/PrescriptionCreator/PatientForm.tsx b/components/PrescriptionCreator/PatientForm.tsx index 2bb5bc8..1e87a72 100644 --- a/components/PrescriptionCreator/PatientForm.tsx +++ b/components/PrescriptionCreator/PatientForm.tsx @@ -62,7 +62,7 @@ export const PatientForm: React.FC = ({ modal mode={'date'} open={openDate} - date={new Date(form.date_of_birth || '01-01-1999')} + date={new Date(form.date_of_birth || '1990-01-01')} onCancel={() => setOpenDate(false)} onConfirm={(date: Date) => { handleTextChange('date_of_birth', date.toDateString()); diff --git a/components/PrescriptionCreator/index.tsx b/components/PrescriptionCreator/index.tsx index 1f808a8..58f6e1c 100644 --- a/components/PrescriptionCreator/index.tsx +++ b/components/PrescriptionCreator/index.tsx @@ -176,7 +176,7 @@ export const PrescriptionCreator = () => {
-
+
From 85ef6310e222e4c234c696464808b3e22ad1b2d4 Mon Sep 17 00:00:00 2001 From: Abhay Date: Mon, 6 Jan 2025 12:07:39 +0530 Subject: [PATCH 2/2] Fix State Initialization --- components/PrescriptionCreator/AddressForm.tsx | 7 +++++-- components/PrescriptionCreator/MedicineForm.tsx | 8 ++++++-- components/PrescriptionCreator/PatientForm.tsx | 10 ++++++++-- components/PrescriptionCreator/index.tsx | 15 ++++++++++++--- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/components/PrescriptionCreator/AddressForm.tsx b/components/PrescriptionCreator/AddressForm.tsx index 73b06b5..cd03c96 100644 --- a/components/PrescriptionCreator/AddressForm.tsx +++ b/components/PrescriptionCreator/AddressForm.tsx @@ -13,18 +13,21 @@ interface AddressForm { interface AddressFormProps { nestedFormCallback: (tag: string, form: Object) => void; + initForm: {[key: string]: any}; } +const ADDRESS_KEY = 'Address'; export const AddressForm: React.FC = ({ nestedFormCallback, + initForm, }) => { - const [form, setForm] = useState({}); + const [form, setForm] = useState(initForm[ADDRESS_KEY] || {}); const handleTextChange = (tag: keyof AddressForm, text: string) => { let newForm = {...form}; newForm[tag] = text; setForm(newForm); - nestedFormCallback('Address', newForm); + nestedFormCallback(ADDRESS_KEY, newForm); }; return ( diff --git a/components/PrescriptionCreator/MedicineForm.tsx b/components/PrescriptionCreator/MedicineForm.tsx index 47e7bf3..9cb559d 100644 --- a/components/PrescriptionCreator/MedicineForm.tsx +++ b/components/PrescriptionCreator/MedicineForm.tsx @@ -12,20 +12,24 @@ interface MedicineForm { directions?: string; } +const MEDICINE_KEY = 'MedicationPrescribed'; + interface MedicineFormProps { nestedFormCallback: (tag: string, form: Object) => void; + initForm: {[key: string]: any}; } export const MedicineForm: React.FC = ({ nestedFormCallback, + initForm, }) => { - const [form, setForm] = useState({}); + const [form, setForm] = useState(initForm[MEDICINE_KEY] || {}); const handleTextChange = (tag: keyof MedicineForm, text: string) => { let newForm = {...form}; newForm[tag] = text; setForm(newForm); - nestedFormCallback('MedicationPrescribed', newForm); + nestedFormCallback(MEDICINE_KEY, newForm); }; return ( diff --git a/components/PrescriptionCreator/PatientForm.tsx b/components/PrescriptionCreator/PatientForm.tsx index 1e87a72..bb2c502 100644 --- a/components/PrescriptionCreator/PatientForm.tsx +++ b/components/PrescriptionCreator/PatientForm.tsx @@ -11,19 +11,25 @@ interface PatientForm { interface PatientFormProps { nestedFormCallback: (tag: string, form: Object) => void; + initForm: {[key: string]: any}; } +const PATIENT_KEY = 'patient'; + export const PatientForm: React.FC = ({ nestedFormCallback, + initForm, }) => { - const [form, setForm] = useState({}); + const [form, setForm] = useState( + initForm[PATIENT_KEY]?.['human_patient'] || {}, + ); const [openDate, setOpenDate] = useState(false); const handleTextChange = (tag: 'name' | 'date_of_birth', text: string) => { let newForm = {...form}; newForm[tag] = text; setForm(newForm); - nestedFormCallback('patient', {human_patient: newForm}); + nestedFormCallback(PATIENT_KEY, {human_patient: newForm}); }; return ( diff --git a/components/PrescriptionCreator/index.tsx b/components/PrescriptionCreator/index.tsx index 58f6e1c..3ee9dfe 100644 --- a/components/PrescriptionCreator/index.tsx +++ b/components/PrescriptionCreator/index.tsx @@ -171,13 +171,22 @@ export const PrescriptionCreator = () => {
{' '} - +
- +
- +