diff --git a/.env.local.example b/.env.local.example index f9cf1d76..0522a552 100644 --- a/.env.local.example +++ b/.env.local.example @@ -5,5 +5,4 @@ AUTH0_ISSUER_BASE_URL= AUTH0_CLIENT_ID= AUTH0_CLIENT_SECRET= AUTH0_AUDIENCE= -NEXT_PUBLIC_API_URL='http://localhost:8000' -SHORTENED_PROD_URL= \ No newline at end of file +NEXT_PUBLIC_API_URL='http://localhost:8000' \ No newline at end of file diff --git a/components/SideMenu.js b/components/SideMenu.js index d39dc251..f39beb03 100644 --- a/components/SideMenu.js +++ b/components/SideMenu.js @@ -13,7 +13,6 @@ import { OFFLINE } from '@/utils/constants'; import VenueOptionsDropdown from '@/components/VenueOptionsDropdown'; import { VillageContext } from '@/context/VillageContext'; -// const SHORTENED_PROD_URL = process.env.NEXT_PUBLIC_SHORTENED_PROD_URL; const navigation = [ { name: 'Registration', diff --git a/pages/records/patient-record/index.js b/pages/records/patient-record/index.js index 0ea81939..39836f6c 100644 --- a/pages/records/patient-record/index.js +++ b/pages/records/patient-record/index.js @@ -17,6 +17,7 @@ import toast from 'react-hot-toast'; import { urltoFile } from '@/utils/helpers'; import withAuth from '@/utils/auth'; import useWithLoading from '@/utils/loading'; +import { submitNewVisit } from '@/pages/registration'; const PatientRecord = () => { const [noRecords, setNoRecords] = useState(true); @@ -59,7 +60,7 @@ const PatientRecord = () => { if (visits.length > 0) { const visitID = visits[0].id; - loadVisitDetails(visitID); + await loadVisitDetails(visitID); } } catch (error) { toast.error(`Error loading patient data: ${error.message}`); @@ -161,6 +162,10 @@ const PatientRecord = () => { setPatientEdit(newPatientDetails); }; + const handleNewVisit = useWithLoading(async () => + submitNewVisit(patient).then(r => onRefresh()) + ); + function LeftColumn() { if (typeof vitals === 'undefined') { return ( @@ -210,10 +215,17 @@ const PatientRecord = () => { if (noRecords) { return ( -
+

This patient has no records currently

+

+

); } diff --git a/pages/registration/index.js b/pages/registration/index.js index ba8aefae..5b24a218 100644 --- a/pages/registration/index.js +++ b/pages/registration/index.js @@ -18,6 +18,21 @@ import { PageTitle } from '@/components/TextComponents'; import { REGISTRATION_FORM_FIELDS } from '@/utils/constants'; import { VillageContext } from '@/context/VillageContext'; +export const submitNewVisit = async patient => { + try { + const payload = { + patient: patient.pk, + status: 'started', + visit_date: moment().format('DD MMMM YYYY HH:mm'), + }; + await axiosInstance.post('/visits', payload); + toast.success('New visit created for patient!'); + } catch (error) { + toast.error(`Error creating new visit: ${error.message}`); + console.error('Error creating new visit:', error); + } +}; + const Registration = () => { const [patientsList, setPatientsList] = useState([]); @@ -155,7 +170,7 @@ const Registration = () => { onRefresh(); setPatientModalOpen(false); - submitNewVisit(response); + handleNewVisit(response); setFormDetails(REGISTRATION_FORM_FIELDS); } catch (error) { toast.error(`Error creating new patient: ${error.message}`); @@ -197,7 +212,7 @@ const Registration = () => { } }); - const submitNewVisit = useWithLoading(async patient => { + const handleNewVisit = useWithLoading(async patient => { try { const { data: patient_visits } = await axiosInstance.get( `/visits?patient=${patient.pk}` @@ -232,18 +247,7 @@ const Registration = () => { console.error('Error fetching patient vists:', error); } - try { - const payload = { - patient: patient.pk, - status: 'started', - visit_date: moment().format('DD MMMM YYYY HH:mm'), - }; - await axiosInstance.post('/visits', payload); - toast.success('New visit created for patient!'); - } catch (error) { - toast.error(`Error creating new visit: ${error.message}`); - console.error('Error creating new visit:', error); - } + submitNewVisit(patient); }); return ( @@ -304,7 +308,7 @@ const Registration = () => {
submitNewVisit(patient)} + submitNewVisit={() => handleNewVisit(patient)} />