|
1 | 1 | import { pool } from '../../db'; |
2 | 2 | import { randomUUID } from 'crypto'; |
3 | | -import axios from 'axios'; |
4 | 3 |
|
5 | 4 | class BedsService { |
6 | 5 | async createWard(name: string, description?: string) { |
@@ -69,26 +68,32 @@ class BedsService { |
69 | 68 | try { |
70 | 69 | // 1. Fetch names and current admissions from patient-service |
71 | 70 | const [patientsRes, admissionsRes] = await Promise.all([ |
72 | | - axios.post(`${process.env.PATIENT_SERVICE_URL}/patients/bulk-info`, { |
73 | | - ids: activePatientIds, |
| 71 | + fetch(`${process.env.PATIENT_SERVICE_URL}/patients/bulk-info`, { |
| 72 | + method: 'POST', |
| 73 | + headers: { 'Content-Type': 'application/json' }, |
| 74 | + body: JSON.stringify({ ids: activePatientIds }), |
| 75 | + }), |
| 76 | + fetch(`${process.env.PATIENT_SERVICE_URL}/admissions/bulk-current`, { |
| 77 | + method: 'POST', |
| 78 | + headers: { 'Content-Type': 'application/json' }, |
| 79 | + body: JSON.stringify({ patientIds: activePatientIds }), |
74 | 80 | }), |
75 | | - axios.post( |
76 | | - `${process.env.PATIENT_SERVICE_URL}/admissions/bulk-current`, |
77 | | - { |
78 | | - patientIds: activePatientIds, |
79 | | - } |
80 | | - ), |
81 | 81 | ]); |
82 | 82 |
|
83 | | - const patientMap = new Map( |
84 | | - patientsRes.data.map((p: any) => [p.id, p.name]) |
85 | | - ); |
| 83 | + if (!patientsRes.ok || !admissionsRes.ok) { |
| 84 | + throw new Error('Failed to fetch patient or admission info'); |
| 85 | + } |
| 86 | + |
| 87 | + const patientsData = await patientsRes.json(); |
| 88 | + const admissionsData = await admissionsRes.json(); |
| 89 | + |
| 90 | + const patientMap = new Map(patientsData.map((p: any) => [p.id, p.name])); |
86 | 91 | const admissionMap = new Map( |
87 | | - admissionsRes.data.map((a: any) => [a.patient_id, a.doctor_id]) |
| 92 | + admissionsData.map((a: any) => [a.patient_id, a.doctor_id]) |
88 | 93 | ); |
89 | 94 |
|
90 | 95 | const doctorIds = Array.from( |
91 | | - new Set(admissionsRes.data.map((a: any) => a.doctor_id)) as Set<string> |
| 96 | + new Set(admissionsData.map((a: any) => a.doctor_id)) as Set<string> |
92 | 97 | ); |
93 | 98 |
|
94 | 99 | // 2. Fetch doctor names from local staff table |
@@ -146,8 +151,9 @@ class BedsService { |
146 | 151 | ); |
147 | 152 |
|
148 | 153 | // 🔁 Notify patient-service admission is complete |
149 | | - await axios.post( |
150 | | - `${process.env.PATIENT_SERVICE_URL}/admissions/${admissionId}/admit` |
| 154 | + await fetch( |
| 155 | + `${process.env.PATIENT_SERVICE_URL}/admissions/${admissionId}/admit`, |
| 156 | + { method: 'POST' } |
151 | 157 | ); |
152 | 158 |
|
153 | 159 | return assignment.rows[0]; |
@@ -188,8 +194,9 @@ class BedsService { |
188 | 194 | [bedId] |
189 | 195 | ); |
190 | 196 |
|
191 | | - await axios.post( |
192 | | - `${process.env.PATIENT_SERVICE_URL}/admissions/${admissionId}/discharged` |
| 197 | + await fetch( |
| 198 | + `${process.env.PATIENT_SERVICE_URL}/admissions/${admissionId}/discharged`, |
| 199 | + { method: 'POST' } |
193 | 200 | ); |
194 | 201 | } |
195 | 202 |
|
|
0 commit comments