-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocDetail.js
102 lines (96 loc) · 3.34 KB
/
docDetail.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const getparams = () => {
const param = new URLSearchParams(window.location.search).get("docId");
loadTime(param);
fetch(`https://testing-8az5.onrender.com/doctor/list/${param}`)
.then((res) => res.json())
.then((data) => displayDetails(data));
fetch(`https://testing-8az5.onrender.com/doctor/review/?doctor_id=${param}`)
.then((res) => res.json())
.then((data) => doctorReview(data));
};
const displayDetails = (doctor) => {
const parent = document.getElementById("doctor-details");
const div = document.createElement("div");
div.classList.add("doc-details-container");
div.innerHTML = `
<img src="${doctor.image}" alt="">
<div>
<h3>${doctor.full_name}</h3>
${doctor.specialization.map((item) => {
return `<p class="btn btn-primary btn-sm">${item}</p>`;
})}
<h4>${doctor.designation}</h4>
<p>Doctor reviews provide valuable insights into the experiences of patients who have visited a particular healthcare provider.</p>
<h3>Fees: ${doctor.fee} BDT</h3>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">Take an appoinment</button>
</div>
`;
parent.appendChild(div);
};
const doctorReview = (reviews) => {
const parent = document.getElementById("doctor-review");
reviews.forEach((review) => {
const div = document.createElement("div");
div.classList.add("review");
div.innerHTML = `
<img src="./images/girl.png" alt="">
<h3>${review.doctor}</h3>
<h4>${review.reviewer}</h4>
<h4>${review.rating}</h4>
<p>${review.body.slice(0, 200)}</p>
<p>Created Time: ${review.created}</p>
`;
parent.appendChild(div);
});
};
const loadTime = (id) => {
fetch(`https://testing-8az5.onrender.com/doctor/availabletime/?doctor_id=${id}`)
.then((res) => res.json())
.then((data) => {
data.forEach((item) => {
const parent = document.getElementById("doctor-time");
const option = document.createElement("option");
option.value = item.id;
option.innerText = item.name;
parent.appendChild(option);
});
});
};
const handleAppoinment = () => {
const param = new URLSearchParams(window.location.search).get("docId");
const status = document.getElementsByName("status");
const selected = Array.from(status).find((button) => button.checked);
const symptom = document.getElementById("symptom").value;
const time = document.getElementById("doctor-time");
const selectedTime = time.options[time.selectedIndex];
const patient_id = localStorage.getItem("patient_id");
const info = {
appointment_type: selected.value,
appointment_status: "Pending",
time: selectedTime.value,
symptom: symptom,
cancel: false,
patient: patient_id,
doctor: param,
};
fetch("https://testing-8az5.onrender.com/appointment/", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(info),
})
.then((res) => res.json())
.then((data) => {
console.log(data);
});
};
const loadPatientId = () => {
const user_id = localStorage.getItem("user_id");
fetch(`https://testing-8az5.onrender.com/patient/list/?user_id=${user_id}`)
.then((res) => res.json())
.then((data) => {
localStorage.setItem("patient_id", data[0].id);
});
};
loadPatientId();
loadTime();
getparams();