feat. search by patient Id -> simple response / update get bottle list of patient
Showing
3 changed files
with
64 additions
and
4 deletions
1 | +/* eslint-disable no-undef */ | ||
1 | //회원가입, 로그인 및 로그아웃에 관한 api | 2 | //회원가입, 로그인 및 로그아웃에 관한 api |
2 | const User = require('../../models/user'); | 3 | const User = require('../../models/user'); |
3 | const Profile = require('../../models/profile'); | 4 | const Profile = require('../../models/profile'); |
... | @@ -175,8 +176,8 @@ exports.verifyToken = async(ctx) => { | ... | @@ -175,8 +176,8 @@ exports.verifyToken = async(ctx) => { |
175 | return; | 176 | return; |
176 | } | 177 | } |
177 | 178 | ||
178 | - await jwt.verify(token, process.env.JWT_SECRET, (err, decoded) => { | 179 | + jwt.verify(token, process.env.JWT_SECRET, (err, decoded) => { |
179 | - if(err) { | 180 | + if (err) { |
180 | ctx.status = 400; | 181 | ctx.status = 400; |
181 | ctx.body = err; | 182 | ctx.body = err; |
182 | return; | 183 | return; | ... | ... |
... | @@ -127,10 +127,29 @@ exports.getPatientDetail = async ctx => { | ... | @@ -127,10 +127,29 @@ exports.getPatientDetail = async ctx => { |
127 | reqUserBottleList.push(...bottleList); | 127 | reqUserBottleList.push(...bottleList); |
128 | })); | 128 | })); |
129 | 129 | ||
130 | + const reqUserBmList = []; | ||
131 | + await Promise.all(reqUserBottleList.map(async bottle => { | ||
132 | + const bmList = await BottleMedicine.find({ | ||
133 | + doctorId : userId, | ||
134 | + bottleId : bottle.bottleId, | ||
135 | + }).sort({ regDtm : 'desc '}).limit(1); | ||
136 | + reqUserBmList.push(...bmList); | ||
137 | + })); | ||
138 | + | ||
139 | + const bottleList = await Promise.all(reqUserBmList.map(async bottleMedicine => { | ||
140 | + const { dosage, regDtm, medicineId } = bottleMedicine; | ||
141 | + const medicine = await Medicine.findOne({ medicineId }); | ||
142 | + return { | ||
143 | + dosage, | ||
144 | + regDtm, | ||
145 | + medicine, | ||
146 | + }; | ||
147 | + })); | ||
148 | + | ||
130 | const result = { | 149 | const result = { |
131 | profile, | 150 | profile, |
132 | info : isDoctorsPatient.getInfo(), | 151 | info : isDoctorsPatient.getInfo(), |
133 | - bottleList : reqUserBottleList, | 152 | + bottleList, |
134 | }; | 153 | }; |
135 | 154 | ||
136 | ctx.status = 200; | 155 | ctx.status = 200; |
... | @@ -296,6 +315,37 @@ exports.writeReqBottleFeedback = async ctx => { | ... | @@ -296,6 +315,37 @@ exports.writeReqBottleFeedback = async ctx => { |
296 | 315 | ||
297 | }; | 316 | }; |
298 | 317 | ||
318 | +exports.searchPatientById = async ctx => { | ||
319 | + const token = ctx.req.headers.authorization; | ||
320 | + if (!token || !token.length) { | ||
321 | + ctx.status = 401; | ||
322 | + return; | ||
323 | + } | ||
324 | + | ||
325 | + // eslint-disable-next-line no-undef | ||
326 | + const { userId } = jwt.verify(token, process.env.JWT_SECRET); | ||
327 | + const user = await User.findByUserId(userId); | ||
328 | + if(!user || user.userTypeCd !== 'DOCTOR') { | ||
329 | + ctx.status = 403; | ||
330 | + return; | ||
331 | + } | ||
332 | + | ||
333 | + const { patientId } = ctx.params; | ||
334 | + const patient = await User.findByUserId(patientId); | ||
335 | + if(!patient || patient.useYn !== 'Y') { | ||
336 | + ctx.status = 404; | ||
337 | + return; | ||
338 | + } | ||
339 | + | ||
340 | + const patientProfile = await Profile.findOne({ userId : patientId }); | ||
341 | + | ||
342 | + ctx.status = 200; | ||
343 | + ctx.body = { | ||
344 | + patientNm : patientProfile.userNm, | ||
345 | + patientId, | ||
346 | + }; | ||
347 | +}; | ||
348 | + | ||
299 | /** | 349 | /** |
300 | * 새로운 환자를 등록한다. | 350 | * 새로운 환자를 등록한다. |
301 | * @param {*} ctx | 351 | * @param {*} ctx | ... | ... |
... | @@ -53,9 +53,18 @@ doctor.patch('/patient', doctorCtrl.writeReqPatientReport); | ... | @@ -53,9 +53,18 @@ doctor.patch('/patient', doctorCtrl.writeReqPatientReport); |
53 | */ | 53 | */ |
54 | doctor.post('/bottle', doctorCtrl.writeReqBottleFeedback); | 54 | doctor.post('/bottle', doctorCtrl.writeReqBottleFeedback); |
55 | 55 | ||
56 | + | ||
57 | +/** | ||
58 | + * 현재 로그인한 유저(의사)가 이메일로 유저를 검색함 | ||
59 | + * request parameter : patientId | ||
60 | + * url : http://localhost:4000/api/doctor/patient/search/:patientId | ||
61 | + * return : patient Info(simple) | ||
62 | + */ | ||
63 | +doctor.get('/patient/search/:patientId', doctorCtrl.searchPatientById); | ||
64 | + | ||
56 | /** | 65 | /** |
57 | * 현재 로그인한 유저(의사)의 관리 환자를 등록함. | 66 | * 현재 로그인한 유저(의사)의 관리 환자를 등록함. |
58 | - * request parameter : reqUserId | 67 | + * request parameter : patientId |
59 | * url : http://localhost:4000/doctor/patient | 68 | * url : http://localhost:4000/doctor/patient |
60 | * return : null | 69 | * return : null |
61 | */ | 70 | */ | ... | ... |
-
Please register or login to post a comment