Skip to content

Commit

Permalink
Merge pull request #10 from moevm/link-patient-api
Browse files Browse the repository at this point in the history
Linked patients' front and back
  • Loading branch information
10023r authored Dec 23, 2023
2 parents 16bfc35 + 7f52c05 commit da90861
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 49 deletions.
1 change: 1 addition & 0 deletions backend/src/controllers/DoctorController.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore
import express from "express";
import { doctorsService } from "../services/DoctorsService";

Expand Down
2 changes: 1 addition & 1 deletion backend/src/init_data/init_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DataInitializer {
const doctorId = new Types.ObjectId(String(doctorUser?._id))

const testData: DoctorDto[] = [
{ _id: doctorId, name: "Ашыр", surname: "Мыратгилдиев", email: "[email protected]", contact: "123456789", experience: "5 years" },
{ _id: doctorId, name: "Ашыр", surname: "Мыратгелдиев", email: "[email protected]", contact: "123456789", experience: "5 years" },
];

await DoctorMongoCollection.insertMany(testData);
Expand Down
18 changes: 9 additions & 9 deletions backend/src/services/PatientsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ class PatientService {
const objId = new mongoose.Types.ObjectId(id)
const patient = await PatientsMongoCollection.findById(objId)

const appoitments = await AppoitmentMongoCollection.find({patient_id: objId})
const appointments = await AppoitmentMongoCollection.find({patient_id: objId})

let myAppoitments: { [key: string]: any }[] = [];
let myAppointments: { [key: string]: any }[] = [];

for(const appoitment of appoitments) {
const procedure = await ProceduresMongoCollection.findOne({_id: appoitment?.procedure_id})
const doctor = await DoctorMongoCollection.findOne({_id: appoitment?.doctor_id})
const date = appoitment?.date
for(const appointment of appointments) {
const procedure = await ProceduresMongoCollection.findOne({_id: appointment?.procedure_id})
const doctor = await DoctorMongoCollection.findOne({_id: appointment?.doctor_id})
const date = appointment?.date
const appointmentDetails = {
"date": date,
"procedure": procedure?.name,
"doctor": doctor?.name + " " + doctor?.surname
};
console.log(appointmentDetails);

myAppoitments.push(appointmentDetails);
myAppointments.push(appointmentDetails);
}
console.log({ "name": patient?.name, "surname": patient?.surname, "appoitments": myAppoitments});
console.log({ "name": patient?.name, "surname": patient?.surname, "appointments": myAppointments});

return { "name": patient?.name, "surname": patient?.surname, "appoitments": myAppoitments}
return { "name": patient?.name, "surname": patient?.surname, "appointments": myAppointments}
}

public async getAllPatients() {
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/Pages/DoctorPage/DoctorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {useNavigate} from "react-router-dom";


function DoctorPage() {
const [info, setInfo] = useState({})
let tmp: any = {}
const [info, setInfo] = useState(tmp)
const navigate = useNavigate()
const id = useSelector((state: any) => state.id)
const [appointments, setAppointments] = useState([])
Expand All @@ -31,7 +32,7 @@ function DoctorPage() {
const onChange = (event: any) => {
const target = event.target
const comparators: {[index: string]: any} = {
'date': (x: any) => x.date.includes(new Date(target.value).toLocaleString('ru-RU', timeRepresentationOptions)),
'date': (x: any) => x.date == (new Date(target.value).toLocaleString('ru-RU', timeRepresentationOptions)),
'procedure': (x: any) => x.procedure.includes(target.value),
'patient': (x: any) => x.patient.includes(target.value)
}
Expand Down Expand Up @@ -71,7 +72,7 @@ function DoctorPage() {
<h4>Patient</h4>
</div>
<ul className="w-full">
{appointments.map((currentValue, idx) =>
{appointments.map((currentValue: any, idx) =>
<div key={idx} className={`${gridCol3} text-lg font-medium mb-7`}>
<li>{currentValue.date}</li>
<li>{currentValue.procedure}</li>
Expand Down
65 changes: 30 additions & 35 deletions frontend/src/Pages/PatientPage/PatientPage.tsx
Original file line number Diff line number Diff line change
@@ -1,61 +1,56 @@
import Header from "../../Widgets/Header/Header.tsx";
import ProfileButton from "../../Components/ProfileButton/ProfileButton.tsx";
import SignOutButton from "../../Components/SignOutButton/SignOutButton.tsx";
import FormInput from "../../Components/FormInput/FormInput.tsx";
import {useState} from "react";
import {useEffect, useState} from "react";
import FilterCard from "../../Widgets/FilterCard/FilterCard.tsx";
import RecordsStand from "../../Widgets/RecordsStand/RecordsStand.tsx";
import {useNavigate} from "react-router-dom";
import {useSelector} from "react-redux";
import {getPatientById} from "../../api/requests.ts";
import {timeRepresentationOptions} from "../../Config/timeRepresentationConfig.ts";


const person = {
name: "Patient1",
appointments: [
{
id: 1,
date: "22.12.2023, 15:54",
doctor: "Doctor Doolittle",
procedure: "Procedure 1"
},
{
id: 2,
date: "20.12.2012, 11:00",
doctor: "Doctor Aybolit",
procedure: "Procedure 2"
},
{
id: 3,
date: "20.12.2022, 06:00",
doctor: "Doctor A",
procedure: "Procedure 2"
}
]
}

function PatientPage() {
const gridCol3 = "w-full grid grid-cols-3 justify-items-center"

const [records, setRecords] = useState(person.appointments)
let tmp: any = {}
const [info, setInfo] = useState(tmp)
const navigate = useNavigate()
const id = useSelector((state: any) => state.id)
const [appointments, setAppointments] = useState([])
useEffect(() => {
if (!id) navigate("/")
getPatientById(id)
.then(res => {
console.log(id, res)
setInfo(res.data)
setAppointments(res.data.appointments)
})
.catch(err => {
console.log(err.message)
navigate("/welcome")
})
}, []);

const onChange = (event: any) => {
const target = event.target
const comparators: {[index: string]: any} = {
'date': (x: any) => x.date.includes(new Date(target.value).toLocaleString('ru-RU', timeRepresentationOptions)),
'date': (x: any) => x.date == (new Date(target.value).toLocaleString('ru-RU', timeRepresentationOptions)),
'procedure': (x: any) => x.procedure.includes(target.value),
'doctor': (x: any) => x.doctor.includes(target.value)
}
setRecords(records.filter(comparators[target.name]))
setAppointments(appointments.filter(comparators[target.name]))
}

const dropFilter = () => {
setRecords(person.appointments)
setAppointments(info.appointments)
}

const gridCol3 = "w-full grid grid-cols-3 justify-items-center"

return (
<>
<Header profileButton={<ProfileButton/>} signOutButton={<SignOutButton/>} />
<Header signOutButton={<SignOutButton/>} />
<div className="px-14 font-bold min-w-fit">
<h3 className="text-2xl my-7">Hello, <span className="text-base1">{person.name}</span>!</h3>
<h3 className="text-2xl my-7">Hello, <span className="text-base1">{info.name}</span>!</h3>
<FilterCard theme="primary" onChange={onChange} dropFilter={dropFilter}>
<div>
<label htmlFor="" className="block ml-3">Date</label>
Expand All @@ -77,7 +72,7 @@ function PatientPage() {
<h4>Doctor</h4>
</div>
<ul className="w-full">
{records.map((currentValue, idx) =>
{appointments.map((currentValue: any, idx) =>
<div key={idx} className={`${gridCol3} text-lg font-medium mb-7`}>
<li>{currentValue.date}</li>
<li>{currentValue.procedure}</li>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/api/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

export enum Endpoints {
LOGIN = "login",
GET_DOCTOR_BY_ID = "doctors"
GET_DOCTOR_BY_ID = "doctors",
GET_PATIENTS = "patients"
}
7 changes: 7 additions & 0 deletions frontend/src/api/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ export const getDoctorById = (id: string) => {
url: API_URL + Endpoints.GET_DOCTOR_BY_ID + "/" + id,
method: 'GET',
})
}

export const getPatientById = (id: string) => {
return axios({
url: API_URL + Endpoints.GET_PATIENTS + "/" + id,
method: "GET"
})
}

0 comments on commit da90861

Please sign in to comment.