Skip to content

Commit

Permalink
Merge pull request #330 from NUS-Project-SaBai/nathan/fix-no-records
Browse files Browse the repository at this point in the history
Nathan/fix no records
  • Loading branch information
nathantew14 authored Dec 9, 2024
2 parents d3c312f + 5c6c7a2 commit 454bf78
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
3 changes: 1 addition & 2 deletions .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=
NEXT_PUBLIC_API_URL='http://localhost:8000'
1 change: 0 additions & 1 deletion components/SideMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
16 changes: 14 additions & 2 deletions pages/records/patient-record/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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}`);
Expand Down Expand Up @@ -161,6 +162,10 @@ const PatientRecord = () => {
setPatientEdit(newPatientDetails);
};

const handleNewVisit = useWithLoading(async () =>
submitNewVisit(patient).then(r => onRefresh())
);

function LeftColumn() {
if (typeof vitals === 'undefined') {
return (
Expand Down Expand Up @@ -210,10 +215,17 @@ const PatientRecord = () => {

if (noRecords) {
return (
<div className="flex justify-center items-center h-screen">
<div className="flex flex-col justify-center items-center h-screen gap-4">
<h2 className="text-black text-xl">
This patient has no records currently
</h2>
<p>
<Button
text="Create New Visit"
onClick={handleNewVisit}
colour="green"
/>
</p>
</div>
);
}
Expand Down
34 changes: 19 additions & 15 deletions pages/registration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);

Expand Down Expand Up @@ -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}`);
Expand Down Expand Up @@ -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}`
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -304,7 +308,7 @@ const Registration = () => {
</div>
<PatientInfo
patient={patient}
submitNewVisit={() => submitNewVisit(patient)}
submitNewVisit={() => handleNewVisit(patient)}
/>
</div>
</div>
Expand Down

0 comments on commit 454bf78

Please sign in to comment.