feat. new DataTable :Bottle -> TakeMedicineHistory / BottleMedicine, API Change, Test
Showing
30 changed files
with
488 additions
and
288 deletions
No preview for this file type
server/.eslintrc.js
0 → 100644
1 | +module.exports = { | ||
2 | + "env": { | ||
3 | + "browser": true, | ||
4 | + "commonjs": true, | ||
5 | + "es2021": true | ||
6 | + }, | ||
7 | + "extends": "eslint:recommended", | ||
8 | + "parserOptions": { | ||
9 | + "ecmaVersion": 12 | ||
10 | + }, | ||
11 | + "rules": { | ||
12 | + "no-unused-vars": ["warn", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }], | ||
13 | + | ||
14 | + } | ||
15 | +}; |
server/.eslintrc.json
deleted
100644 → 0
1 | -{ | ||
2 | - "extends": "eslint:recommended", | ||
3 | - "rules": { | ||
4 | - // "semi": ["warn", "never"], | ||
5 | - "quotes": ["warn", "single"], | ||
6 | - "no-console": ["off"], | ||
7 | - "no-unused-vars": ["warn", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }], | ||
8 | - "no-constant-condition" : ["off"] | ||
9 | - }, | ||
10 | - "parserOptions": { | ||
11 | - "ecmaVersion": 9 | ||
12 | - }, | ||
13 | - "env": { | ||
14 | - "es6": true, | ||
15 | - "node": true, | ||
16 | - "browser": true, | ||
17 | - "amd": true | ||
18 | - }, | ||
19 | - "globals": { | ||
20 | - "$": true, | ||
21 | - "require": true, | ||
22 | - "process": true | ||
23 | - }, | ||
24 | - "root": true | ||
25 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -8,6 +8,7 @@ const updateMedicineInfo = require('./src/lib/UpdatingMedicineInfo'); | ... | @@ -8,6 +8,7 @@ const updateMedicineInfo = require('./src/lib/UpdatingMedicineInfo'); |
8 | const MqttServer = require('./src/util/MqttServer'); | 8 | const MqttServer = require('./src/util/MqttServer'); |
9 | 9 | ||
10 | require('dotenv').config(); | 10 | require('dotenv').config(); |
11 | +// eslint-disable-next-line no-undef | ||
11 | const { SERVER_PORT, MONGO_URL } = process.env; | 12 | const { SERVER_PORT, MONGO_URL } = process.env; |
12 | 13 | ||
13 | const app = new Koa(); | 14 | const app = new Koa(); |
... | @@ -21,7 +22,7 @@ Mongoose.connect(MONGO_URL, { | ... | @@ -21,7 +22,7 @@ Mongoose.connect(MONGO_URL, { |
21 | useCreateIndex : true | 22 | useCreateIndex : true |
22 | }).then(() => { | 23 | }).then(() => { |
23 | console.log('\x1b[1;32mMongo DB is connected : ', MONGO_URL, '\x1b[0m'); | 24 | console.log('\x1b[1;32mMongo DB is connected : ', MONGO_URL, '\x1b[0m'); |
24 | - updateMedicineInfo.updateMedicineInfo(); | 25 | + // updateMedicineInfo.updateMedicineInfo(); |
25 | }).catch(e => { | 26 | }).catch(e => { |
26 | console.log(e); | 27 | console.log(e); |
27 | }) | 28 | }) | ... | ... |
This diff could not be displayed because it is too large.
... | @@ -20,7 +20,10 @@ exports.register = async(ctx) => { | ... | @@ -20,7 +20,10 @@ exports.register = async(ctx) => { |
20 | userId : Joi.string().email().max(50).required(), | 20 | userId : Joi.string().email().max(50).required(), |
21 | password : Joi.string().required(), | 21 | password : Joi.string().required(), |
22 | passwordCheck : Joi.string().required(), | 22 | passwordCheck : Joi.string().required(), |
23 | - }) | 23 | + userNm : Joi.string().required(), |
24 | + userAge : Joi.number().required(), | ||
25 | + contact : Joi.string().required(), | ||
26 | + }); | ||
24 | 27 | ||
25 | const result = schema.validate(ctx.request.body); | 28 | const result = schema.validate(ctx.request.body); |
26 | if(result.error || password !== passwordCheck) { | 29 | if(result.error || password !== passwordCheck) { |
... | @@ -41,7 +44,6 @@ exports.register = async(ctx) => { | ... | @@ -41,7 +44,6 @@ exports.register = async(ctx) => { |
41 | }); | 44 | }); |
42 | 45 | ||
43 | await user.setPassword(password); | 46 | await user.setPassword(password); |
44 | - await user.save(); | ||
45 | 47 | ||
46 | const profile = new Profile({ | 48 | const profile = new Profile({ |
47 | userId, | 49 | userId, |
... | @@ -50,6 +52,7 @@ exports.register = async(ctx) => { | ... | @@ -50,6 +52,7 @@ exports.register = async(ctx) => { |
50 | contact, | 52 | contact, |
51 | }); | 53 | }); |
52 | 54 | ||
55 | + await user.save(); | ||
53 | await profile.save(); | 56 | await profile.save(); |
54 | 57 | ||
55 | ctx.status = 201; | 58 | ctx.status = 201; |
... | @@ -68,6 +71,7 @@ exports.doctorRegister = async ctx => { | ... | @@ -68,6 +71,7 @@ exports.doctorRegister = async ctx => { |
68 | userId : Joi.string().email().max(50).required(), | 71 | userId : Joi.string().email().max(50).required(), |
69 | password : Joi.string().required(), | 72 | password : Joi.string().required(), |
70 | passwordCheck : Joi.string().required(), | 73 | passwordCheck : Joi.string().required(), |
74 | + info : Joi.object().required(), | ||
71 | }) | 75 | }) |
72 | 76 | ||
73 | const result = schema.validate(ctx.request.body); | 77 | const result = schema.validate(ctx.request.body); |
... | @@ -90,7 +94,6 @@ exports.doctorRegister = async ctx => { | ... | @@ -90,7 +94,6 @@ exports.doctorRegister = async ctx => { |
90 | }); | 94 | }); |
91 | 95 | ||
92 | await doctor.setPassword(password); | 96 | await doctor.setPassword(password); |
93 | - doctor.save(); | ||
94 | 97 | ||
95 | const doctorInfo = new DoctorInfo({ | 98 | const doctorInfo = new DoctorInfo({ |
96 | doctorId : userId, | 99 | doctorId : userId, |
... | @@ -98,6 +101,8 @@ exports.doctorRegister = async ctx => { | ... | @@ -98,6 +101,8 @@ exports.doctorRegister = async ctx => { |
98 | useYn : 'W', | 101 | useYn : 'W', |
99 | }); | 102 | }); |
100 | 103 | ||
104 | + | ||
105 | + doctor.save(); | ||
101 | doctorInfo.save(); | 106 | doctorInfo.save(); |
102 | 107 | ||
103 | ctx.status = 201; | 108 | ctx.status = 201; | ... | ... |
1 | +/* eslint-disable no-undef */ | ||
1 | //어플에서 약병 등록 및, 약병에 관한 정보 조회 = 여기서 mqtt통신으로 broker에 데이터를 요청한다. | 2 | //어플에서 약병 등록 및, 약병에 관한 정보 조회 = 여기서 mqtt통신으로 broker에 데이터를 요청한다. |
2 | const Bottle = require('../../models/bottle'); | 3 | const Bottle = require('../../models/bottle'); |
3 | const Hub = require('../../models/hub'); | 4 | const Hub = require('../../models/hub'); |
4 | const Medicine = require('../../models/medicine'); | 5 | const Medicine = require('../../models/medicine'); |
5 | const User = require('../../models/user'); | 6 | const User = require('../../models/user'); |
6 | -const History = require('../../models/history'); | 7 | +const PatientInfo = require('../../models/patientInfo'); |
8 | +const TakeMedicineHist = require('../../models/takeMedicineHistory'); | ||
9 | +const BottleMedicine = require('../../models/bottleMedicine'); | ||
10 | +const Feedback = require('../../models/feedback'); | ||
7 | const Mqtt = require('../../lib/MqttModule'); | 11 | const Mqtt = require('../../lib/MqttModule'); |
8 | const jwt = require('jsonwebtoken'); | 12 | const jwt = require('jsonwebtoken'); |
9 | 13 | ||
... | @@ -16,7 +20,7 @@ exports.bottleConnect = async(ctx) => { | ... | @@ -16,7 +20,7 @@ exports.bottleConnect = async(ctx) => { |
16 | } | 20 | } |
17 | 21 | ||
18 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); | 22 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); |
19 | - const user = await User.findById(userId); | 23 | + const user = await User.findByUserId(userId); |
20 | if(!user || !user.userTypeCd || user.useYn !== 'Y') { | 24 | if(!user || !user.userTypeCd || user.useYn !== 'Y') { |
21 | ctx.status = 403; | 25 | ctx.status = 403; |
22 | return; | 26 | return; |
... | @@ -70,7 +74,7 @@ exports.bottleDisconnect = async(ctx) => { | ... | @@ -70,7 +74,7 @@ exports.bottleDisconnect = async(ctx) => { |
70 | } | 74 | } |
71 | 75 | ||
72 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); | 76 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); |
73 | - const user = await User.findById(userId); | 77 | + const user = await User.findByUserId(userId); |
74 | if(!user || !user.userTypeCd || user.useYn !== 'Y') { | 78 | if(!user || !user.userTypeCd || user.useYn !== 'Y') { |
75 | ctx.status = 403; | 79 | ctx.status = 403; |
76 | return; | 80 | return; |
... | @@ -102,7 +106,7 @@ exports.bottleDisconnect = async(ctx) => { | ... | @@ -102,7 +106,7 @@ exports.bottleDisconnect = async(ctx) => { |
102 | 106 | ||
103 | }; | 107 | }; |
104 | 108 | ||
105 | -//약병 정보를 조회 -> 약병에 현재 데이터를 요청한다. message : req | 109 | +//약병 정보를 조회 -> 약병의 기록을 가져온다. message : req |
106 | exports.getBottleInfo = async(ctx) => { | 110 | exports.getBottleInfo = async(ctx) => { |
107 | const token = ctx.req.headers.authorization; | 111 | const token = ctx.req.headers.authorization; |
108 | if(!token || !token.length) { | 112 | if(!token || !token.length) { |
... | @@ -111,7 +115,7 @@ exports.getBottleInfo = async(ctx) => { | ... | @@ -111,7 +115,7 @@ exports.getBottleInfo = async(ctx) => { |
111 | } | 115 | } |
112 | 116 | ||
113 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); | 117 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); |
114 | - const user = await User.findById(userId); | 118 | + const user = await User.findByUserId(userId); |
115 | if(!user || !user.userTypeCd || user.useYn !== 'Y') { | 119 | if(!user || !user.userTypeCd || user.useYn !== 'Y') { |
116 | ctx.status = 403; | 120 | ctx.status = 403; |
117 | return; | 121 | return; |
... | @@ -126,12 +130,12 @@ exports.getBottleInfo = async(ctx) => { | ... | @@ -126,12 +130,12 @@ exports.getBottleInfo = async(ctx) => { |
126 | } | 130 | } |
127 | 131 | ||
128 | const hub = await Hub.findByHubId(bottle.getHubId()); | 132 | const hub = await Hub.findByHubId(bottle.getHubId()); |
129 | - if(hub.getHub_UserId() !== userId || user.userTypeCd !== 'DOCTOR') { | 133 | + if(hub.userId !== userId) { |
130 | ctx.status = 403; | 134 | ctx.status = 403; |
131 | return; | 135 | return; |
132 | } | 136 | } |
133 | 137 | ||
134 | - if(user.userTypeCd === 'NORMAL') { | 138 | + |
135 | const hosting = hub.getHubHost(); | 139 | const hosting = hub.getHubHost(); |
136 | //서버에서 bottle로 데이터를 요청한다. | 140 | //서버에서 bottle로 데이터를 요청한다. |
137 | const client = await Mqtt.mqttOn(hosting); | 141 | const client = await Mqtt.mqttOn(hosting); |
... | @@ -139,28 +143,88 @@ exports.getBottleInfo = async(ctx) => { | ... | @@ -139,28 +143,88 @@ exports.getBottleInfo = async(ctx) => { |
139 | const message = 'req'; | 143 | const message = 'req'; |
140 | await Mqtt.mqttPublishMessage(client, { topic, message }); | 144 | await Mqtt.mqttPublishMessage(client, { topic, message }); |
141 | 145 | ||
142 | - const bottle = await Bottle.findByBottleId(bottleId); | 146 | + const bottleMedicine = await BottleMedicine.find({ bottleId }) |
147 | + .sort({ regDtm : 'desc' }) | ||
148 | + .limit(1); | ||
149 | + | ||
150 | + if(bottleMedicine.length) { | ||
151 | + | ||
152 | + const takeMedicineHist = await TakeMedicineHist | ||
153 | + .find({ bmId : bottleMedicine[0]._id }) | ||
154 | + .sort({ takeDate : 'desc' }) | ||
155 | + .populate('bmId'); | ||
143 | 156 | ||
144 | ctx.status = 200; | 157 | ctx.status = 200; |
145 | - ctx.body = bottle; | 158 | + ctx.body = takeMedicineHist; |
159 | + | ||
160 | + } else { | ||
161 | + ctx.status = 404; | ||
162 | + ctx.body = { | ||
163 | + error : '정보가 등록되지 않은 약병' | ||
164 | + } | ||
165 | + } | ||
146 | 166 | ||
167 | +} | ||
168 | + | ||
169 | +//약병에 대한 피드백의 정보를 가져옴 | ||
170 | +exports.getBottleFeedback = async ctx => { | ||
171 | + const token = ctx.req.headers.authorization; | ||
172 | + if(!token || !token.length) { | ||
173 | + ctx.status = 401; | ||
147 | return; | 174 | return; |
148 | - } else if (user.userTypeCd === 'DOCTOR') { | 175 | + } |
149 | - let result = { | ||
150 | - bottle, | ||
151 | - history : [], | ||
152 | - }; | ||
153 | 176 | ||
154 | - result.historyList = History.findByBottleId(bottle.bottleId); | 177 | + const { userId } = jwt.verify(token, process.env.JWT_SECRET); |
178 | + const user = await User.findByUserId(userId); | ||
179 | + if(!user || !user.userTypeCd || user.useYn !== 'Y') { | ||
180 | + ctx.status = 403; | ||
181 | + ctx.body = { | ||
182 | + error : '권한 없는 사용자' | ||
183 | + } | ||
184 | + return; | ||
185 | + } | ||
155 | 186 | ||
156 | - ctx.status = 200; | 187 | + const { bottleId } = ctx.params; |
157 | - ctx.body = result; | ||
158 | 188 | ||
189 | + const bottle = await Bottle.findByBottleId(bottleId); | ||
190 | + if(!bottle) { | ||
191 | + ctx.status = 404; | ||
192 | + ctx.body = { | ||
193 | + error : '존재하지 않는 약병' | ||
194 | + } | ||
159 | return; | 195 | return; |
160 | } | 196 | } |
161 | -} | ||
162 | 197 | ||
163 | -//약병의 ID를 찾아서 약의 정보를 등록 : Post | 198 | + const hub = await Hub.findByHubId(bottle.getHubId()); |
199 | + if(hub.userId !== userId) { | ||
200 | + ctx.status = 403; | ||
201 | + ctx.body = { | ||
202 | + error : '약병에 대한 권한 없음' | ||
203 | + } | ||
204 | + return; | ||
205 | + } | ||
206 | + | ||
207 | + const bottleMedicine = await BottleMedicine.find({ bottleId }) | ||
208 | + .sort({ regDtm : 'desc' }) | ||
209 | + .limit(1); | ||
210 | + | ||
211 | + if(bottleMedicine.length) { | ||
212 | + const feedbackList = await Feedback.find({ bmId : bottleMedicine[0]._id }) | ||
213 | + .sort({ fdbDtm : 'desc' }) | ||
214 | + .populate('bmId'); | ||
215 | + | ||
216 | + ctx.status = 200; | ||
217 | + ctx.body = feedbackList; | ||
218 | + } else { | ||
219 | + ctx.status = 404; | ||
220 | + ctx.body = { | ||
221 | + error : '정보가 등록되지 않은 약병', | ||
222 | + }; | ||
223 | + } | ||
224 | + | ||
225 | +}; | ||
226 | + | ||
227 | +//약병의 ID를 찾아서 약의 정보와 처방의를 등록 : Post | ||
164 | exports.setMedicine = async(ctx) => { | 228 | exports.setMedicine = async(ctx) => { |
165 | const token = ctx.req.headers.authorization; | 229 | const token = ctx.req.headers.authorization; |
166 | if(!token || !token.length) { | 230 | if(!token || !token.length) { |
... | @@ -169,42 +233,103 @@ exports.setMedicine = async(ctx) => { | ... | @@ -169,42 +233,103 @@ exports.setMedicine = async(ctx) => { |
169 | } | 233 | } |
170 | 234 | ||
171 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); | 235 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); |
172 | - const user = await User.findById(userId); | 236 | + const user = await User.findByUserId(userId); |
173 | if(!user || !user.userTypeCd || user.useYn !== 'Y') { | 237 | if(!user || !user.userTypeCd || user.useYn !== 'Y') { |
174 | ctx.status = 403; | 238 | ctx.status = 403; |
175 | return; | 239 | return; |
176 | } | 240 | } |
177 | 241 | ||
178 | const { bottleId } = ctx.params; | 242 | const { bottleId } = ctx.params; |
179 | - const { medicineId, dosage } = ctx.request.body; | 243 | + const { medicineId, dosage, doctorId } = ctx.request.body; |
180 | 244 | ||
181 | const bottle = await Bottle.findByBottleId(bottleId); | 245 | const bottle = await Bottle.findByBottleId(bottleId); |
182 | if(!bottle) { | 246 | if(!bottle) { |
183 | ctx.status = 404; | 247 | ctx.status = 404; |
248 | + ctx.body = { | ||
249 | + error : '약병 찾을 수 없음.', | ||
250 | + } | ||
184 | return; | 251 | return; |
185 | } | 252 | } |
186 | 253 | ||
187 | const hub = await Hub.findByHubId(bottle.getHubId()); | 254 | const hub = await Hub.findByHubId(bottle.getHubId()); |
188 | if(hub.getHub_UserId() !== userId) { | 255 | if(hub.getHub_UserId() !== userId) { |
189 | ctx.status = 403; | 256 | ctx.status = 403; |
257 | + ctx.body = { | ||
258 | + error : '해당 허브 권한 없음', | ||
259 | + } | ||
190 | return; | 260 | return; |
191 | } | 261 | } |
192 | 262 | ||
193 | const medicine = await Medicine.findByMedicineId(medicineId); | 263 | const medicine = await Medicine.findByMedicineId(medicineId); |
194 | if(!medicine) { | 264 | if(!medicine) { |
195 | ctx.status = 404; | 265 | ctx.status = 404; |
266 | + ctx.body = { | ||
267 | + error : '해당 약 존재하지 않음', | ||
268 | + } | ||
269 | + return; | ||
270 | + } | ||
271 | + | ||
272 | + if(doctorId !== undefined && doctorId !== null && doctorId !== '') { | ||
273 | + const patientInfo = await PatientInfo.findByPatientIdAndDoctorIdAndUseYn(userId, doctorId, 'Y'); | ||
274 | + if(!patientInfo) { | ||
275 | + ctx.status = 403; | ||
276 | + ctx.body = { | ||
277 | + error : '담당의가 아님', | ||
278 | + }; | ||
196 | return; | 279 | return; |
197 | } | 280 | } |
281 | + } | ||
198 | 282 | ||
199 | - await Bottle.findOneAndUpdate({ | 283 | + const bottleMedicine = new BottleMedicine({ |
200 | - bottleId | 284 | + bottleId, |
201 | - }, { | ||
202 | medicineId, | 285 | medicineId, |
203 | - dosage : parseInt(dosage) | 286 | + doctorId, |
287 | + dosage, | ||
204 | }); | 288 | }); |
289 | + bottleMedicine.save(); | ||
205 | 290 | ||
206 | ctx.status = 200; | 291 | ctx.status = 200; |
207 | -} | 292 | +}; |
293 | + | ||
294 | +// //비어있는 약병에 의사를 등록한다. | ||
295 | +// exports.registerDoctorToBottle = async ctx => { | ||
296 | +// const token = ctx.req.headers.authorization; | ||
297 | +// if(!token || !token.length) { | ||
298 | +// ctx.status = 401; | ||
299 | +// return; | ||
300 | +// } | ||
301 | + | ||
302 | +// const { userId } = jwt.verify(token, process.env.JWT_SECRET); | ||
303 | +// const user = await User.findByUserId(userId); | ||
304 | +// if(!user || !user.userTypeCd || user.useYn !== 'Y') { | ||
305 | +// ctx.status = 403; | ||
306 | +// return; | ||
307 | +// } | ||
308 | + | ||
309 | +// const { bottleId } = ctx.params; | ||
310 | +// const { doctorId } = ctx.request.body; | ||
311 | +// const bottle = await Bottle.findByBottleId(bottleId); | ||
312 | +// if(!bottle) { | ||
313 | +// ctx.status = 404; | ||
314 | +// return; | ||
315 | +// } | ||
316 | +// if(bottle.getDoctorId()) { | ||
317 | +// ctx.status = 403; | ||
318 | +// return; | ||
319 | +// } | ||
320 | + | ||
321 | +// const patinetInfo = await PatientInfo.findByPatientIdAndDoctorIdAndUseYn(userId, doctorId, 'Y'); | ||
322 | +// if(!patinetInfo) { | ||
323 | +// ctx.status = 404; | ||
324 | +// return; | ||
325 | +// } | ||
326 | + | ||
327 | +// bottle.setDoctorId(doctorId); | ||
328 | +// bottle.save(); | ||
329 | + | ||
330 | +// ctx.status = 200; | ||
331 | + | ||
332 | +// }; | ||
208 | 333 | ||
209 | //로그인한 유저의 약병 리스트 가져오기 | 334 | //로그인한 유저의 약병 리스트 가져오기 |
210 | exports.getBottleList = async(ctx) => { | 335 | exports.getBottleList = async(ctx) => { |
... | @@ -215,7 +340,7 @@ exports.getBottleList = async(ctx) => { | ... | @@ -215,7 +340,7 @@ exports.getBottleList = async(ctx) => { |
215 | } | 340 | } |
216 | 341 | ||
217 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); | 342 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); |
218 | - const user = await User.findById(userId); | 343 | + const user = await User.findByUserId(userId); |
219 | if(!user || !user.userTypeCd || user.useYn !== 'Y') { | 344 | if(!user || !user.userTypeCd || user.useYn !== 'Y') { |
220 | ctx.status = 403; | 345 | ctx.status = 403; |
221 | return; | 346 | return; |
... | @@ -243,4 +368,4 @@ exports.getBottleList = async(ctx) => { | ... | @@ -243,4 +368,4 @@ exports.getBottleList = async(ctx) => { |
243 | ctx.status = 200; | 368 | ctx.status = 200; |
244 | ctx.body = bottleList; | 369 | ctx.body = bottleList; |
245 | 370 | ||
246 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
371 | +}; | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -28,6 +28,14 @@ bottle.delete('/:bottleId', bottleCtrl.bottleDisconnect); | ... | @@ -28,6 +28,14 @@ bottle.delete('/:bottleId', bottleCtrl.bottleDisconnect); |
28 | bottle.get('/:bottleId', bottleCtrl.getBottleInfo); | 28 | bottle.get('/:bottleId', bottleCtrl.getBottleInfo); |
29 | 29 | ||
30 | /** | 30 | /** |
31 | + * 약병에 대한 피드백 확인 | ||
32 | + * request parameter : bottleId | ||
33 | + * url : http://localhost:4000/api/bottle/feedback/:bottleId | ||
34 | + * return : feedback List | ||
35 | + */ | ||
36 | +bottle.get('/feedback/:bottleId', bottleCtrl.getBottleFeedback); | ||
37 | + | ||
38 | +/** | ||
31 | * 약병에 약 등록 = 약 검색 후 약 ID(medicineId)와 복용 정보 보고 사용자가 약 복용량(dosage) 입력 | 39 | * 약병에 약 등록 = 약 검색 후 약 ID(medicineId)와 복용 정보 보고 사용자가 약 복용량(dosage) 입력 |
32 | * request parameter : medicineId, dosage | 40 | * request parameter : medicineId, dosage |
33 | * url : http://localhost:4000/api/bottle/:bottleId | 41 | * url : http://localhost:4000/api/bottle/:bottleId |
... | @@ -36,6 +44,14 @@ bottle.get('/:bottleId', bottleCtrl.getBottleInfo); | ... | @@ -36,6 +44,14 @@ bottle.get('/:bottleId', bottleCtrl.getBottleInfo); |
36 | bottle.patch('/:bottleId', bottleCtrl.setMedicine); | 44 | bottle.patch('/:bottleId', bottleCtrl.setMedicine); |
37 | 45 | ||
38 | /** | 46 | /** |
47 | + * 비어있는 약병에 전담의 등록 | ||
48 | + * request parameter : bottleId, doctorId | ||
49 | + * url : http://localhost:4000/api/bottle/doctor/:bottleId | ||
50 | + * return null; | ||
51 | + */ | ||
52 | +// bottle.patch('/doctor/:bottleId', bottleCtrl.registerDoctorToBottle); | ||
53 | + | ||
54 | +/** | ||
39 | * 현재 로그인한 유저의 허브 중, 해당 허브에 등록된 약병 리스트를 가져옴 | 55 | * 현재 로그인한 유저의 허브 중, 해당 허브에 등록된 약병 리스트를 가져옴 |
40 | * request parameter : x | 56 | * request parameter : x |
41 | * url : http://localhost:4000/api/bottle/hub/:hubId | 57 | * url : http://localhost:4000/api/bottle/hub/:hubId | ... | ... |
... | @@ -3,7 +3,8 @@ const User = require('../../models/user'); | ... | @@ -3,7 +3,8 @@ const User = require('../../models/user'); |
3 | const Profile = require('../../models/profile'); | 3 | const Profile = require('../../models/profile'); |
4 | const Bottle = require('../../models/bottle'); | 4 | const Bottle = require('../../models/bottle'); |
5 | const Medicine = require('../../models/medicine'); | 5 | const Medicine = require('../../models/medicine'); |
6 | -const History = require('../../models/history'); | 6 | +const BottleMedicine = require('../../models/bottleMedicine'); |
7 | +const TakeMedicineHist = require('../../models/takeMedicineHistory'); | ||
7 | const Feedback = require('../../models/feedback'); | 8 | const Feedback = require('../../models/feedback'); |
8 | const Hub = require('../../models/hub'); | 9 | const Hub = require('../../models/hub'); |
9 | const PatientInfo = require('../../models/patientInfo'); | 10 | const PatientInfo = require('../../models/patientInfo'); |
... | @@ -21,19 +22,21 @@ exports.getPatientList = async ctx => { | ... | @@ -21,19 +22,21 @@ exports.getPatientList = async ctx => { |
21 | return; | 22 | return; |
22 | } | 23 | } |
23 | 24 | ||
25 | + // eslint-disable-next-line no-undef | ||
24 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); | 26 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); |
25 | - const user = await User.findById(userId); | 27 | + const user = await User.findByUserId(userId); |
26 | if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') { | 28 | if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') { |
27 | ctx.status = 403; | 29 | ctx.status = 403; |
28 | return; | 30 | return; |
29 | } | 31 | } |
30 | 32 | ||
31 | - const managePatientIdList = await PatientInfo.findAllByDoctorId(userId); | 33 | + const managePatientIdList = await PatientInfo.findAllByDoctorIdAndUseYn(userId, 'Y'); |
32 | 34 | ||
33 | - const result = managePatientIdList.map(async patientId => { | 35 | + const result = []; |
34 | - const patient = await User.findByUserId(patientId); | 36 | + await Promise.all(managePatientIdList.map(async patient => { |
35 | - return patient; | 37 | + const patientProfile = await Profile.findByUserId(patient.patientId); |
36 | - }); | 38 | + result.push(patientProfile); |
39 | + })); | ||
37 | 40 | ||
38 | ctx.status = 200; | 41 | ctx.status = 200; |
39 | ctx.body = result; | 42 | ctx.body = result; |
... | @@ -52,21 +55,22 @@ exports.getPatientDetail = async ctx => { | ... | @@ -52,21 +55,22 @@ exports.getPatientDetail = async ctx => { |
52 | return; | 55 | return; |
53 | } | 56 | } |
54 | 57 | ||
58 | + // eslint-disable-next-line no-undef | ||
55 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); | 59 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); |
56 | - const user = await User.findById(userId); | 60 | + const user = await User.findByUserId(userId); |
57 | if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') { | 61 | if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') { |
58 | ctx.status = 403; | 62 | ctx.status = 403; |
59 | return; | 63 | return; |
60 | } | 64 | } |
61 | 65 | ||
62 | - const { patientId } = ctx.params; | 66 | + const { patientId } = ctx.request.body; |
63 | const patient = await User.findByUserId(patientId); | 67 | const patient = await User.findByUserId(patientId); |
64 | if(!patient || patient.useYn !== 'Y') { | 68 | if(!patient || patient.useYn !== 'Y') { |
65 | ctx.status = 404; | 69 | ctx.status = 404; |
66 | return; | 70 | return; |
67 | } | 71 | } |
68 | 72 | ||
69 | - const isDoctorsPatient = await PatientInfo.findByPatientIdAndDoctorId(patientId, userId); | 73 | + const isDoctorsPatient = await PatientInfo.findByPatientIdAndDoctorIdAndUseYn(patientId, userId, 'Y'); |
70 | if(!isDoctorsPatient) { | 74 | if(!isDoctorsPatient) { |
71 | ctx.status = 403; | 75 | ctx.status = 403; |
72 | return; | 76 | return; |
... | @@ -78,12 +82,12 @@ exports.getPatientDetail = async ctx => { | ... | @@ -78,12 +82,12 @@ exports.getPatientDetail = async ctx => { |
78 | const reqUserHubList = await Hub.findAllByUserId(patientId); | 82 | const reqUserHubList = await Hub.findAllByUserId(patientId); |
79 | const reqUserBottleList = []; | 83 | const reqUserBottleList = []; |
80 | await Promise.all(reqUserHubList.map(async hub => { | 84 | await Promise.all(reqUserHubList.map(async hub => { |
81 | - const bottleList = await Bottle.findAllByHubId(hub.hubId); | 85 | + const bottleList = await Bottle.findAllByHubId(hub.hubId, userId); |
82 | reqUserBottleList.push(...bottleList); | 86 | reqUserBottleList.push(...bottleList); |
83 | })); | 87 | })); |
84 | 88 | ||
85 | const result = { | 89 | const result = { |
86 | - ...profile, | 90 | + profile, |
87 | info : isDoctorsPatient.getInfo(), | 91 | info : isDoctorsPatient.getInfo(), |
88 | bottleList : reqUserBottleList, | 92 | bottleList : reqUserBottleList, |
89 | }; | 93 | }; |
... | @@ -105,10 +109,14 @@ exports.getBottleDetail = async ctx => { | ... | @@ -105,10 +109,14 @@ exports.getBottleDetail = async ctx => { |
105 | return; | 109 | return; |
106 | } | 110 | } |
107 | 111 | ||
112 | + // eslint-disable-next-line no-undef | ||
108 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); | 113 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); |
109 | - const user = await User.findById(userId); | 114 | + const user = await User.findByUserId(userId); |
110 | if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') { | 115 | if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') { |
111 | ctx.status = 403; | 116 | ctx.status = 403; |
117 | + ctx.body = { | ||
118 | + error : '권한 없는 사용자', | ||
119 | + } | ||
112 | return; | 120 | return; |
113 | } | 121 | } |
114 | 122 | ||
... | @@ -116,29 +124,29 @@ exports.getBottleDetail = async ctx => { | ... | @@ -116,29 +124,29 @@ exports.getBottleDetail = async ctx => { |
116 | const bottle = await Bottle.findByBottleId(bottleId); | 124 | const bottle = await Bottle.findByBottleId(bottleId); |
117 | if(!bottle) { | 125 | if(!bottle) { |
118 | ctx.status = 404; | 126 | ctx.status = 404; |
127 | + ctx.body = { | ||
128 | + error : '존재하지 않는 약병', | ||
129 | + } | ||
119 | return; | 130 | return; |
120 | } | 131 | } |
121 | - if(bottle.getDoctorId() !== userId) { | 132 | + |
133 | + const bottleMedicine = await BottleMedicine.findOne({ bottleId, doctorId : userId }); | ||
134 | + if(!bottleMedicine) { | ||
122 | ctx.status = 403; | 135 | ctx.status = 403; |
136 | + ctx.body = { | ||
137 | + error : '약병에 대한 권한 없음', | ||
138 | + } | ||
123 | return; | 139 | return; |
124 | } | 140 | } |
125 | 141 | ||
126 | - | 142 | + const medicine = await Medicine.findOne({ medicineId : bottleMedicine.medicineId }); |
127 | - //약병에 들어있는 약 정보와 복용 내역을 가져온다. | 143 | + const takeMedicineHist = await TakeMedicineHist.find({ |
128 | - const bottleInfo = { | 144 | + bmId : bottleMedicine._id, |
129 | - temperature : bottle.temperature, | 145 | + }).sort({ takeDate : 'desc' }); |
130 | - humidity : bottle.humidity, | ||
131 | - dosage : bottle.dosage, | ||
132 | - balance : bottle.balance, | ||
133 | - }; | ||
134 | - | ||
135 | - const medicine = await Medicine.findByMedicineId(bottle.getMedicineId()); | ||
136 | - const takeHistory = await History.findByBottleIdAndMedicineId(bottleId, bottle.getMedicineId()); | ||
137 | 146 | ||
138 | const result = { | 147 | const result = { |
139 | - bottleInfo, | ||
140 | medicine, | 148 | medicine, |
141 | - takeHistory, | 149 | + takeMedicineHist, |
142 | }; | 150 | }; |
143 | 151 | ||
144 | ctx.status = 200; | 152 | ctx.status = 200; |
... | @@ -158,21 +166,22 @@ exports.writeReqPatientReport = async ctx => { | ... | @@ -158,21 +166,22 @@ exports.writeReqPatientReport = async ctx => { |
158 | return; | 166 | return; |
159 | } | 167 | } |
160 | 168 | ||
169 | + // eslint-disable-next-line no-undef | ||
161 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); | 170 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); |
162 | - const user = await User.findById(userId); | 171 | + const user = await User.findByUserId(userId); |
163 | if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') { | 172 | if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') { |
164 | ctx.status = 403; | 173 | ctx.status = 403; |
165 | return; | 174 | return; |
166 | } | 175 | } |
167 | 176 | ||
168 | - const { reqUserId, info } = ctx.request.body; | 177 | + const { patientId, info } = ctx.request.body; |
169 | - const patient = await User.findByUserId(reqUserId); | 178 | + const patient = await User.findByUserId(patientId); |
170 | if(!patient || patient.useYn !== 'Y') { | 179 | if(!patient || patient.useYn !== 'Y') { |
171 | ctx.status = 404; | 180 | ctx.status = 404; |
172 | return; | 181 | return; |
173 | } | 182 | } |
174 | 183 | ||
175 | - const patientInfo = await PatientInfo.findByPatientIdAndDoctorId(reqUserId, userId); | 184 | + const patientInfo = await PatientInfo.findByPatientIdAndDoctorIdAndUseYn(patientId, userId, 'Y'); |
176 | if(!patientInfo) { | 185 | if(!patientInfo) { |
177 | ctx.status = 404; | 186 | ctx.status = 404; |
178 | return; | 187 | return; |
... | @@ -197,10 +206,14 @@ exports.writeReqBottleFeedback = async ctx => { | ... | @@ -197,10 +206,14 @@ exports.writeReqBottleFeedback = async ctx => { |
197 | return; | 206 | return; |
198 | } | 207 | } |
199 | 208 | ||
209 | + // eslint-disable-next-line no-undef | ||
200 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); | 210 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); |
201 | - const user = await User.findById(userId); | 211 | + const user = await User.findByUserId(userId); |
202 | if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') { | 212 | if(!user || user.userTypeCd !== 'DOCTOR' || user.useYn !== 'Y') { |
203 | ctx.status = 403; | 213 | ctx.status = 403; |
214 | + ctx.body = { | ||
215 | + error : '권한 없는 사용자', | ||
216 | + } | ||
204 | return; | 217 | return; |
205 | } | 218 | } |
206 | 219 | ||
... | @@ -208,17 +221,27 @@ exports.writeReqBottleFeedback = async ctx => { | ... | @@ -208,17 +221,27 @@ exports.writeReqBottleFeedback = async ctx => { |
208 | const bottle = await Bottle.findByBottleId(bottleId); | 221 | const bottle = await Bottle.findByBottleId(bottleId); |
209 | if(!bottle) { | 222 | if(!bottle) { |
210 | ctx.status = 404; | 223 | ctx.status = 404; |
224 | + ctx.body = { | ||
225 | + error : '존재하지 않는 약병' | ||
226 | + } | ||
211 | return; | 227 | return; |
212 | } | 228 | } |
213 | - if(bottle.getDoctorId() !== userId) { | 229 | + |
230 | + const bottleMedicine = await BottleMedicine.find({ bottleId, doctorId : userId }) | ||
231 | + .sort({ regDtm : 'desc' }) | ||
232 | + .limit(1); | ||
233 | + | ||
234 | + if(!bottleMedicine.length) { | ||
214 | ctx.status = 403; | 235 | ctx.status = 403; |
236 | + ctx.body = { | ||
237 | + error : '약병에 대한 권한 없음' | ||
238 | + } | ||
215 | return; | 239 | return; |
216 | } | 240 | } |
217 | 241 | ||
218 | const newFeedback = new Feedback({ | 242 | const newFeedback = new Feedback({ |
219 | - fdbDtm : new Date(), | ||
220 | fdbType, | 243 | fdbType, |
221 | - bottleId, | 244 | + bmId : bottleMedicine[0]._id, |
222 | doctorId : userId, | 245 | doctorId : userId, |
223 | feedback, | 246 | feedback, |
224 | }); | 247 | }); |
... | @@ -240,27 +263,35 @@ exports.registerNewPatient = async ctx => { | ... | @@ -240,27 +263,35 @@ exports.registerNewPatient = async ctx => { |
240 | return; | 263 | return; |
241 | } | 264 | } |
242 | 265 | ||
266 | + // eslint-disable-next-line no-undef | ||
243 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); | 267 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); |
244 | - const user = await User.findById(userId); | 268 | + const user = await User.findByUserId(userId); |
245 | if(!user || user.userTypeCd !== 'DOCTOR') { | 269 | if(!user || user.userTypeCd !== 'DOCTOR') { |
246 | ctx.status = 403; | 270 | ctx.status = 403; |
247 | return; | 271 | return; |
248 | } | 272 | } |
249 | 273 | ||
250 | - const { reqUserId } = ctx.request.body; | 274 | + const { patientId } = ctx.request.body; |
251 | - const patient = await User.findByUserId(reqUserId); | 275 | + const patient = await User.findByUserId(patientId); |
252 | if(!patient || patient.useYn !== 'Y') { | 276 | if(!patient || patient.useYn !== 'Y') { |
253 | ctx.status = 404; | 277 | ctx.status = 404; |
254 | return; | 278 | return; |
255 | } | 279 | } |
256 | 280 | ||
281 | + const isExistPatientInfo = await PatientInfo.findByPatientIdAndDoctorId(patientId, userId); | ||
282 | + if(isExistPatientInfo) { | ||
283 | + ctx.status = 403; | ||
284 | + return; | ||
285 | + } | ||
286 | + | ||
257 | const patientInfo = new PatientInfo({ | 287 | const patientInfo = new PatientInfo({ |
258 | - patientId : reqUserId, | 288 | + patientId, |
259 | doctorId : userId, | 289 | doctorId : userId, |
260 | info : '', | 290 | info : '', |
291 | + useYn : 'W', | ||
261 | }); | 292 | }); |
262 | 293 | ||
263 | - patientInfo.updateInfo('환자 등록'); | 294 | + patientInfo.updateInfo('환자 등록 요청'); |
264 | patientInfo.save(); | 295 | patientInfo.save(); |
265 | 296 | ||
266 | ctx.status = 200; | 297 | ctx.status = 200; |
... | @@ -279,8 +310,9 @@ exports.removeReqPatient = async ctx => { | ... | @@ -279,8 +310,9 @@ exports.removeReqPatient = async ctx => { |
279 | return; | 310 | return; |
280 | } | 311 | } |
281 | 312 | ||
313 | + // eslint-disable-next-line no-undef | ||
282 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); | 314 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); |
283 | - const user = await User.findById(userId); | 315 | + const user = await User.findByUserId(userId); |
284 | if(!user || user.userTypeCd !== 'DOCTOR') { | 316 | if(!user || user.userTypeCd !== 'DOCTOR') { |
285 | ctx.status = 403; | 317 | ctx.status = 403; |
286 | return; | 318 | return; |
... | @@ -293,16 +325,14 @@ exports.removeReqPatient = async ctx => { | ... | @@ -293,16 +325,14 @@ exports.removeReqPatient = async ctx => { |
293 | return; | 325 | return; |
294 | } | 326 | } |
295 | 327 | ||
296 | - const patientInfo = await PatientInfo.findByPatientIdAndDoctorId(patientId, userId); | 328 | + const patientInfo = await PatientInfo.findByPatientIdAndDoctorIdAndUseYn(patientId, userId, 'Y'); |
297 | if(!patientInfo) { | 329 | if(!patientInfo) { |
298 | ctx.status = 404; | 330 | ctx.status = 404; |
299 | return; | 331 | return; |
300 | } | 332 | } |
301 | 333 | ||
302 | - await PatientInfo.deleteOne({ | 334 | + await patientInfo.setUseYn('N') |
303 | - patientId, | 335 | + patientInfo.save(); |
304 | - doctorId : userId, | ||
305 | - }); | ||
306 | 336 | ||
307 | ctx.status = 200; | 337 | ctx.status = 200; |
308 | 338 | ... | ... |
... | @@ -17,7 +17,7 @@ doctor.get('/patient', doctorCtrl.getPatientList); | ... | @@ -17,7 +17,7 @@ doctor.get('/patient', doctorCtrl.getPatientList); |
17 | * url : http://localhost:4000/doctor/patient/:patientId | 17 | * url : http://localhost:4000/doctor/patient/:patientId |
18 | * return : patient Detail | 18 | * return : patient Detail |
19 | */ | 19 | */ |
20 | -doctor.get('/patient/:patientId', doctorCtrl.getPatientDetail); | 20 | +doctor.get('/patient/detail', doctorCtrl.getPatientDetail); |
21 | 21 | ||
22 | /** | 22 | /** |
23 | * 현재 로그인한 유저(의사)의 관리 약병 상세 정보를 가져옴 | 23 | * 현재 로그인한 유저(의사)의 관리 약병 상세 정보를 가져옴 |
... | @@ -37,7 +37,7 @@ doctor.get('/bottle/:bottleId', doctorCtrl.getBottleDetail); | ... | @@ -37,7 +37,7 @@ doctor.get('/bottle/:bottleId', doctorCtrl.getBottleDetail); |
37 | doctor.patch('/patient', doctorCtrl.writeReqPatientReport); | 37 | doctor.patch('/patient', doctorCtrl.writeReqPatientReport); |
38 | 38 | ||
39 | /** | 39 | /** |
40 | - * 현재 로그인한 유저(의사)의 특정 관리 환자의 약병의 피드백을 기록함 | 40 | + * 현재 로그인한 유저(의사)의 특정 관리 환자의 약병의 피드백을 등록함. |
41 | * request parameter : bottleId, fdbType, feedback | 41 | * request parameter : bottleId, fdbType, feedback |
42 | * url : http://localhost:4000/doctor/bottle | 42 | * url : http://localhost:4000/doctor/bottle |
43 | * return : null | 43 | * return : null | ... | ... |
... | @@ -12,8 +12,9 @@ exports.hubConnect = async (ctx) => { | ... | @@ -12,8 +12,9 @@ exports.hubConnect = async (ctx) => { |
12 | return; | 12 | return; |
13 | } | 13 | } |
14 | 14 | ||
15 | + // eslint-disable-next-line no-undef | ||
15 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); | 16 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); |
16 | - const user = await User.findById(userId); | 17 | + const user = await User.findByUserId(userId); |
17 | if(!user || !user.userTypeCd || user.useYn !== 'Y') { | 18 | if(!user || !user.userTypeCd || user.useYn !== 'Y') { |
18 | ctx.status = 403; | 19 | ctx.status = 403; |
19 | return; | 20 | return; |
... | @@ -53,8 +54,9 @@ exports.getHubList = async(ctx) => { | ... | @@ -53,8 +54,9 @@ exports.getHubList = async(ctx) => { |
53 | return; | 54 | return; |
54 | } | 55 | } |
55 | 56 | ||
57 | + // eslint-disable-next-line no-undef | ||
56 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); | 58 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); |
57 | - const user = await User.findById(userId); | 59 | + const user = await User.findByUserId(userId); |
58 | if(!user || !user.userTypeCd || user.useYn !== 'Y') { | 60 | if(!user || !user.userTypeCd || user.useYn !== 'Y') { |
59 | ctx.status = 403; | 61 | ctx.status = 403; |
60 | return; | 62 | return; |
... | @@ -77,8 +79,9 @@ exports.hubDisconnect = async(ctx) => { | ... | @@ -77,8 +79,9 @@ exports.hubDisconnect = async(ctx) => { |
77 | return; | 79 | return; |
78 | } | 80 | } |
79 | 81 | ||
82 | + // eslint-disable-next-line no-undef | ||
80 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); | 83 | const { userId } = jwt.verify(token, process.env.JWT_SECRET); |
81 | - const user = await User.findById(userId); | 84 | + const user = await User.findByUserId(userId); |
82 | if(!user || !user.userTypeCd || user.useYn !== 'Y') { | 85 | if(!user || !user.userTypeCd || user.useYn !== 'Y') { |
83 | ctx.status = 403; | 86 | ctx.status = 403; |
84 | return; | 87 | return; | ... | ... |
1 | -const Router = require('koa-router') | 1 | +const Router = require('koa-router'); |
2 | -const auth = require('./auth') | 2 | + |
3 | -const user = require('./user') | 3 | +const auth = require('./auth'); |
4 | -const bottle = require('./bottle') | 4 | +const user = require('./user'); |
5 | -const hub = require('./hub') | 5 | +const bottle = require('./bottle'); |
6 | -const medicine = require('./medicine') | 6 | +const hub = require('./hub'); |
7 | +const medicine = require('./medicine'); | ||
7 | const doctor = require('./doctor'); | 8 | const doctor = require('./doctor'); |
9 | +const manage = require('./manage'); | ||
8 | 10 | ||
9 | const api = new Router(); | 11 | const api = new Router(); |
10 | 12 | ||
11 | -api.use('/auth', auth.routes()) | 13 | +api.use('/auth', auth.routes()); |
12 | -api.use('/user', user.routes()) | 14 | +api.use('/user', user.routes()); |
13 | -api.use('/bottle', bottle.routes()) | 15 | +api.use('/bottle', bottle.routes()); |
14 | -api.use('/hub', hub.routes()) | 16 | +api.use('/hub', hub.routes()); |
15 | -api.use('/medicine', medicine.routes()) | 17 | +api.use('/medicine', medicine.routes()); |
16 | api.use('/doctor', doctor.routes()); | 18 | api.use('/doctor', doctor.routes()); |
19 | +api.use('/manage', manage.routes()); | ||
17 | 20 | ||
18 | module.exports = api; | 21 | module.exports = api; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
server/src/api/manage/index.js
0 → 100644
... | @@ -8,23 +8,9 @@ exports.medicineSearch = async(ctx) => { | ... | @@ -8,23 +8,9 @@ exports.medicineSearch = async(ctx) => { |
8 | return; | 8 | return; |
9 | } | 9 | } |
10 | 10 | ||
11 | - const { name, company, target } = ctx.request.body; | 11 | + const { keyword } = ctx.request.body; |
12 | 12 | ||
13 | - let result = []; | 13 | + const result = await Medicine.findByKeyword(keyword); |
14 | - | ||
15 | - if (name && name !== '' && name !== undefined) | ||
16 | - result = await medicineSearch_ByName(name); | ||
17 | - | ||
18 | - else if (company && company !== '' && company !== undefined) | ||
19 | - result = await medicineSearch_ByCompany(company); | ||
20 | - | ||
21 | - else if (target && target !== '' && target !== undefined) | ||
22 | - result = await medicineSearch_ByTarget(target); | ||
23 | - | ||
24 | - if(!result.length) { | ||
25 | - ctx.status = 404; | ||
26 | - return; | ||
27 | - } | ||
28 | 14 | ||
29 | ctx.status = 200; | 15 | ctx.status = 200; |
30 | ctx.body = result; | 16 | ctx.body = result; |
... | @@ -48,21 +34,3 @@ exports.medicineGet = async(ctx) => { | ... | @@ -48,21 +34,3 @@ exports.medicineGet = async(ctx) => { |
48 | ctx.body = medicine; | 34 | ctx.body = medicine; |
49 | 35 | ||
50 | } | 36 | } |
... | \ No newline at end of file | ... | \ No newline at end of file |
51 | - | ||
52 | -//이름으로 약 검색 | ||
53 | -const medicineSearch_ByName = async(name) => { | ||
54 | - const result = await Medicine.findByName(name); | ||
55 | - return result; | ||
56 | -} | ||
57 | - | ||
58 | -//제조사명으로 약 검색 | ||
59 | -const medicineSearch_ByCompany = async(company) => { | ||
60 | - const result = await Medicine.findByCompany(company); | ||
61 | - return result; | ||
62 | -} | ||
63 | - | ||
64 | -//타겟 병명으로 약 검색 | ||
65 | -const medicineSearch_ByTarget = async(target) => { | ||
66 | - const result = await Medicine.findByTarget(target); | ||
67 | - return result; | ||
68 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -11,4 +11,22 @@ const user = new Router(); | ... | @@ -11,4 +11,22 @@ const user = new Router(); |
11 | */ | 11 | */ |
12 | user.get('/', userCtrl.getMyDetail); | 12 | user.get('/', userCtrl.getMyDetail); |
13 | 13 | ||
14 | +/** | ||
15 | + * 유저를 등록하려는 의사의 요청을 전부 보여준다 | ||
16 | + * request parameter : token, | ||
17 | + * url : http://localhost:4000/api/user/doctorrequest | ||
18 | + * return : List | ||
19 | + */ | ||
20 | +user.get('/doctorrequest', userCtrl.viewAllDoctorRegister); | ||
21 | + | ||
22 | + | ||
23 | +/** | ||
24 | + * 유저를 등록하려는 의사의 요청을 수락한다. | ||
25 | + * request parameter : token, doctorId, | ||
26 | + * url : http://localhost:4000/api/user/doctorrequest/:doctorId | ||
27 | + * return : null | ||
28 | + */ | ||
29 | +user.post('/doctorrequest/accept', userCtrl.acceptDoctorRegister); | ||
30 | + | ||
31 | + | ||
14 | module.exports = user; | 32 | module.exports = user; | ... | ... |
1 | //유저에 관련된 Api | 1 | //유저에 관련된 Api |
2 | const User = require('../../models/user'); | 2 | const User = require('../../models/user'); |
3 | const Profile = require('../../models/profile'); | 3 | const Profile = require('../../models/profile'); |
4 | +const PatientInfo = require('../../models/patientInfo'); | ||
4 | const jwt = require('jsonwebtoken'); | 5 | const jwt = require('jsonwebtoken'); |
5 | 6 | ||
6 | 7 | ||
8 | +/** | ||
9 | + * 내 정보를 확인한다. | ||
10 | + * @param {*} ctx | ||
11 | + * http methods : get | ||
12 | + */ | ||
7 | exports.getMyDetail = async ctx => { | 13 | exports.getMyDetail = async ctx => { |
8 | const token = ctx.req.headers.authorization | 14 | const token = ctx.req.headers.authorization |
9 | if (!token || !token.length) { | 15 | if (!token || !token.length) { |
... | @@ -12,7 +18,7 @@ exports.getMyDetail = async ctx => { | ... | @@ -12,7 +18,7 @@ exports.getMyDetail = async ctx => { |
12 | } | 18 | } |
13 | 19 | ||
14 | const { userId } = jwt.verify(token, process.env.JWT_SECRET) | 20 | const { userId } = jwt.verify(token, process.env.JWT_SECRET) |
15 | - const user = await User.findById(userId) | 21 | + const user = await User.findByUserId(userId) |
16 | if(!user || !user.userTypeCd || user.useYn !== 'Y') { | 22 | if(!user || !user.userTypeCd || user.useYn !== 'Y') { |
17 | ctx.status = 403; | 23 | ctx.status = 403; |
18 | return; | 24 | return; |
... | @@ -25,7 +31,71 @@ exports.getMyDetail = async ctx => { | ... | @@ -25,7 +31,71 @@ exports.getMyDetail = async ctx => { |
25 | 31 | ||
26 | } | 32 | } |
27 | 33 | ||
28 | -//toDo | 34 | +/** |
35 | + * 내 정보를 업데이트한다. | ||
36 | + * @param {*} ctx | ||
37 | + * http methods : post | ||
38 | + */ | ||
29 | exports.updateMyInfo = async ctx => { | 39 | exports.updateMyInfo = async ctx => { |
30 | 40 | ||
31 | -} | 41 | +}; |
42 | + | ||
43 | +/** | ||
44 | + * 의사가 요청한 환자 등록을 확인한다. | ||
45 | + * @param {*} ctx | ||
46 | + * http methods : get | ||
47 | + */ | ||
48 | +exports.viewAllDoctorRegister = async ctx => { | ||
49 | + const token = ctx.req.headers.authorization | ||
50 | + if (!token || !token.length) { | ||
51 | + ctx.status = 401 | ||
52 | + return | ||
53 | + } | ||
54 | + | ||
55 | + const { userId } = jwt.verify(token, process.env.JWT_SECRET) | ||
56 | + const user = await User.findByUserId(userId) | ||
57 | + if(!user || !user.userTypeCd || user.userTypeCd !== 'NORMAL' || user.useYn !== 'Y') { | ||
58 | + ctx.status = 403; | ||
59 | + return; | ||
60 | + } | ||
61 | + | ||
62 | + const patientInfoList = await PatientInfo.findAllByPatientIdAndUseYn(userId, 'W'); | ||
63 | + | ||
64 | + ctx.status = 200; | ||
65 | + ctx.body = patientInfoList; | ||
66 | + | ||
67 | +}; | ||
68 | + | ||
69 | +/** | ||
70 | + * 의사가 요청한 환자 등록을 수락한다/ | ||
71 | + * @param {*} ctx | ||
72 | + * http methods : post | ||
73 | + */ | ||
74 | +exports.acceptDoctorRegister = async ctx => { | ||
75 | + const token = ctx.req.headers.authorization | ||
76 | + if (!token || !token.length) { | ||
77 | + ctx.status = 401 | ||
78 | + return | ||
79 | + } | ||
80 | + | ||
81 | + const { userId } = jwt.verify(token, process.env.JWT_SECRET) | ||
82 | + const user = await User.findByUserId(userId) | ||
83 | + if(!user || !user.userTypeCd || user.userTypeCd !== 'NORMAL' || user.useYn !== 'Y') { | ||
84 | + ctx.status = 403; | ||
85 | + return; | ||
86 | + } | ||
87 | + | ||
88 | + const { doctorId } = ctx.request.body; | ||
89 | + const patientInfo = await PatientInfo.findByPatientIdAndDoctorIdAndUseYn(userId, doctorId, 'W'); | ||
90 | + if(!patientInfo) { | ||
91 | + ctx.status = 404; | ||
92 | + return; | ||
93 | + } | ||
94 | + | ||
95 | + patientInfo.updateInfo('환자 등록 요청 수락'); | ||
96 | + patientInfo.setUseYn('Y'); | ||
97 | + patientInfo.save(); | ||
98 | + | ||
99 | + ctx.status = 200; | ||
100 | + | ||
101 | +}; | ... | ... |
1 | const Bottle = require('../models/bottle'); | 1 | const Bottle = require('../models/bottle'); |
2 | -const History = require('../models/history'); | 2 | +const BottleMedicine = require('../models/bottleMedicine'); |
3 | +const TakeMedicineHist = require('../models/takeMedicineHistory'); | ||
3 | 4 | ||
4 | //message subscribe 후 message를 가공한 이후 해당 데이터를 보낼 topic과 message를 리턴하는 함수 | 5 | //message subscribe 후 message를 가공한 이후 해당 데이터를 보낼 topic과 message를 리턴하는 함수 |
5 | exports.dataPublish = async (topic, message) => { | 6 | exports.dataPublish = async (topic, message) => { |
6 | //client가 subscribe를 하면 메시지를 보낸 약병의 topic과 message를 가공 및 보낸 약병의 bottleId를 가져옴 | 7 | //client가 subscribe를 하면 메시지를 보낸 약병의 topic과 message를 가공 및 보낸 약병의 bottleId를 가져옴 |
7 | const data = await factoring(topic, message); | 8 | const data = await factoring(topic, message); |
8 | - const { bottleId } = data; | ||
9 | - | ||
10 | //가공된 데이터를 bottleId의 약병에 업데이트 | 9 | //가공된 데이터를 bottleId의 약병에 업데이트 |
11 | await bottleInfoUpdate(data); | 10 | await bottleInfoUpdate(data); |
12 | //가공된 데이터를 메시지로 만들어 topic과 message 리턴 | 11 | //가공된 데이터를 메시지로 만들어 topic과 message 리턴 |
13 | - const result = await transPublishingTopicAndMessage(bottleId); | 12 | + const result = await transPublishingTopicAndMessage(data.bottleId); |
14 | 13 | ||
15 | return result; | 14 | return result; |
16 | 15 | ||
... | @@ -27,12 +26,10 @@ const factoring = async (topic, message) => { | ... | @@ -27,12 +26,10 @@ const factoring = async (topic, message) => { |
27 | balance = await balanceFactoring(balance); | 26 | balance = await balanceFactoring(balance); |
28 | else balance = '-1'; | 27 | else balance = '-1'; |
29 | 28 | ||
30 | - const openDate = new Date(); | ||
31 | - | ||
32 | return { | 29 | return { |
33 | bottleId, | 30 | bottleId, |
34 | isOpen, | 31 | isOpen, |
35 | - openDate, | 32 | + openDate : new Date(), |
36 | temperature, | 33 | temperature, |
37 | humidity, | 34 | humidity, |
38 | balance | 35 | balance |
... | @@ -66,27 +63,19 @@ const bottleInfoUpdate = async(data) => { | ... | @@ -66,27 +63,19 @@ const bottleInfoUpdate = async(data) => { |
66 | humidity = parseFloat(humidity); | 63 | humidity = parseFloat(humidity); |
67 | balance = parseInt(balance); | 64 | balance = parseInt(balance); |
68 | 65 | ||
69 | - const bottle = await Bottle.findByBottleId(bottleId); | 66 | + const bottleMedicine = await BottleMedicine.find({ bottleId }).sort((a, b) => a.regDtm < b.regDtm)[0]; |
70 | 67 | ||
71 | - if(bottle) { | 68 | + if(bottleMedicine) { |
72 | if(isOpen) { | 69 | if(isOpen) { |
73 | - const history = new History({ | 70 | + const takeMedicineHist = new TakeMedicineHist({ |
74 | - takeDate : new Date(openDate), | 71 | + takeDate : openDate, |
75 | - bottleId, | 72 | + bmId : bottleMedicine._id, |
76 | - medicineId : bottle.getMedicineId(), | 73 | + temperature, |
74 | + humidity, | ||
75 | + balance, | ||
77 | }); | 76 | }); |
78 | - history.save(); | 77 | + takeMedicineHist.save(); |
79 | - } | ||
80 | - | ||
81 | - if(balance !== -1) { | ||
82 | - await Bottle.findOneAndUpdate({ | ||
83 | - bottleId | ||
84 | - }, { balance }) | ||
85 | } | 78 | } |
86 | - | ||
87 | - bottle.updateTemperature(temperature); | ||
88 | - bottle.updateHumidity(humidity); | ||
89 | - bottle.save(); | ||
90 | } | 79 | } |
91 | } | 80 | } |
92 | 81 | ||
... | @@ -94,11 +83,12 @@ const bottleInfoUpdate = async(data) => { | ... | @@ -94,11 +83,12 @@ const bottleInfoUpdate = async(data) => { |
94 | const transPublishingTopicAndMessage = async(bottleId) => { | 83 | const transPublishingTopicAndMessage = async(bottleId) => { |
95 | const topic = 'bottle/' + bottleId + '/stb'; | 84 | const topic = 'bottle/' + bottleId + '/stb'; |
96 | 85 | ||
97 | - const bottle = await Bottle.findByBottleId(bottleId); | 86 | + const bottleMedicine = await BottleMedicine.find({ bottleId }).sort((a, b) => a.regDtm < b.regDtm)[0]; |
98 | - const recentOpen = bottle.getRecentOpenDate(); | 87 | + const takeMedicineHist = await TakeMedicineHist.find({ |
99 | - const dosage = bottle.getDosage(); | 88 | + bmId : bottleMedicine._id |
89 | + }).sort((a, b) => a.takeDate < b.takeDate)[0]; | ||
100 | 90 | ||
101 | - const message = 'res/' + await transDate(recentOpen) + '/' + dosage; | 91 | + const message = 'res/' + await transDate(takeMedicineHist.takeDate) + '/' + bottleMedicine.dosage; |
102 | 92 | ||
103 | return { | 93 | return { |
104 | topic, | 94 | topic, | ... | ... |
1 | const mqtt = require('mqtt') | 1 | const mqtt = require('mqtt') |
2 | const clientList = [] | 2 | const clientList = [] |
3 | 3 | ||
4 | -exports.mqttOn = async (hosting, func) => { | 4 | +exports.mqttOn = async (hosting, foo) => { |
5 | const filterIndex = clientList.findIndex(client => { | 5 | const filterIndex = clientList.findIndex(client => { |
6 | return (client.options.clientId === hosting.clientId | 6 | return (client.options.clientId === hosting.clientId |
7 | && client.options.host === hosting.host | 7 | && client.options.host === hosting.host |
... | @@ -17,7 +17,7 @@ exports.mqttOn = async (hosting, func) => { | ... | @@ -17,7 +17,7 @@ exports.mqttOn = async (hosting, func) => { |
17 | }) | 17 | }) |
18 | 18 | ||
19 | client.on('message', async (topic, message) => { | 19 | client.on('message', async (topic, message) => { |
20 | - const result = await func(topic, message.toString()) | 20 | + const result = await foo(topic, message.toString()) |
21 | console.log('\x1b[1;32msubscribe : topic', topic, 'message : ', message.toString(), '\x1b[0m') | 21 | console.log('\x1b[1;32msubscribe : topic', topic, 'message : ', message.toString(), '\x1b[0m') |
22 | this.mqttPublishMessage(client, result) | 22 | this.mqttPublishMessage(client, result) |
23 | }) | 23 | }) | ... | ... |
... | @@ -15,7 +15,7 @@ const jwtMiddleware = async (ctx, next) => { | ... | @@ -15,7 +15,7 @@ const jwtMiddleware = async (ctx, next) => { |
15 | }; | 15 | }; |
16 | const now = Math.floor(Date.now() / 1000); | 16 | const now = Math.floor(Date.now() / 1000); |
17 | if (decoded.exp - now < 60 * 60 * 24 * 7) { | 17 | if (decoded.exp - now < 60 * 60 * 24 * 7) { |
18 | - const user = await User.findById(decoded._id); | 18 | + const user = await User.findByUserId(decoded._id); |
19 | const token = user.generateToken(); | 19 | const token = user.generateToken(); |
20 | 20 | ||
21 | ctx.cookies.set('access_token', token, { | 21 | ctx.cookies.set('access_token', token, { | ... | ... |
... | @@ -4,13 +4,7 @@ const Schema = mongoose.Schema; | ... | @@ -4,13 +4,7 @@ const Schema = mongoose.Schema; |
4 | 4 | ||
5 | const BottleSchema = new Schema ({ | 5 | const BottleSchema = new Schema ({ |
6 | bottleId : { type : Number, required : true, unique : true }, | 6 | bottleId : { type : Number, required : true, unique : true }, |
7 | - temperature : { type : Number, default : 0 }, | 7 | + hubId : { type : Number, required : true, ref : 'Hub', }, |
8 | - humidity : { type : Number, default : 0 }, | ||
9 | - balance : { type : Number, default : 0 }, | ||
10 | - medicineId : { type : Number, }, | ||
11 | - dosage : { type : Number, default : 0 }, | ||
12 | - hubId : { type : Number, required : true, }, | ||
13 | - doctorId : { type : String, default : null, }, | ||
14 | }); | 8 | }); |
15 | 9 | ||
16 | BottleSchema.statics.findByBottleId = function(bottleId) { | 10 | BottleSchema.statics.findByBottleId = function(bottleId) { |
... | @@ -21,56 +15,13 @@ BottleSchema.statics.findAllByHubId = function(hubId) { | ... | @@ -21,56 +15,13 @@ BottleSchema.statics.findAllByHubId = function(hubId) { |
21 | return this.find({ hubId }); | 15 | return this.find({ hubId }); |
22 | }; | 16 | }; |
23 | 17 | ||
24 | -BottleSchema.statics.findAllByDoctorId = function(doctorId) { | ||
25 | - return this.find({ doctorId }); | ||
26 | -} | ||
27 | - | ||
28 | BottleSchema.methods.getBottleId = function() { | 18 | BottleSchema.methods.getBottleId = function() { |
29 | return this.bottleId; | 19 | return this.bottleId; |
30 | }; | 20 | }; |
31 | 21 | ||
32 | -BottleSchema.methods.getTemperature = function() { | ||
33 | - return this.temperature; | ||
34 | -}; | ||
35 | - | ||
36 | -BottleSchema.methods.getHumidity = function() { | ||
37 | - return this.humidity; | ||
38 | -}; | ||
39 | - | ||
40 | -BottleSchema.methods.getBalance = function() { | ||
41 | - return this.balance; | ||
42 | -}; | ||
43 | - | ||
44 | -BottleSchema.methods.getDosage = function() { | ||
45 | - return this.dosage; | ||
46 | -}; | ||
47 | - | ||
48 | -BottleSchema.methods.getMedicineId = function() { | ||
49 | - return this.medicineId; | ||
50 | -}; | ||
51 | - | ||
52 | BottleSchema.methods.getHubId = function() { | 22 | BottleSchema.methods.getHubId = function() { |
53 | return this.hubId; | 23 | return this.hubId; |
54 | }; | 24 | }; |
55 | 25 | ||
56 | -BottleSchema.methods.getDoctorId = function() { | ||
57 | - return this.doctorId; | ||
58 | -}; | ||
59 | - | ||
60 | -BottleSchema.methods.setMedicineId = function(medicineId) { | ||
61 | - this.medicineId = medicineId; | ||
62 | -}; | ||
63 | - | ||
64 | -BottleSchema.methods.setDosage = function(dosage) { | ||
65 | - this.dosage = dosage; | ||
66 | -}; | ||
67 | - | ||
68 | -BottleSchema.methods.updateTemperature = function (temperature) { | ||
69 | - this.temperature = temperature; | ||
70 | -}; | ||
71 | - | ||
72 | -BottleSchema.methods.updateHumidity = function (humidity) { | ||
73 | - this.humidity = humidity; | ||
74 | -}; | ||
75 | 26 | ||
76 | module.exports = mongoose.model('Bottle', BottleSchema); | 27 | module.exports = mongoose.model('Bottle', BottleSchema); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -2,31 +2,33 @@ const mongoose = require('mongoose'); | ... | @@ -2,31 +2,33 @@ const mongoose = require('mongoose'); |
2 | 2 | ||
3 | const Schema = mongoose.Schema; | 3 | const Schema = mongoose.Schema; |
4 | 4 | ||
5 | -const TakeMedicineHistorySchema = new Schema ({ | 5 | +const BottleMedicineSchema = new Schema({ |
6 | - takeDate : { | 6 | + bottleId : { |
7 | - type : Date, | 7 | + type : Number, |
8 | + ref : 'Bottle', | ||
8 | required : true, | 9 | required : true, |
9 | - default : Date.now, | ||
10 | }, | 10 | }, |
11 | medicineId : { | 11 | medicineId : { |
12 | type : Number, | 12 | type : Number, |
13 | ref : 'Medicine', | 13 | ref : 'Medicine', |
14 | required : true, | 14 | required : true, |
15 | }, | 15 | }, |
16 | - bottleId : { | 16 | + doctorId : { |
17 | + type : String, | ||
18 | + ref : 'User', | ||
19 | + required : true, | ||
20 | + }, | ||
21 | + dosage : { | ||
17 | type : Number, | 22 | type : Number, |
18 | - ref : 'Bottle', | ||
19 | required : true, | 23 | required : true, |
24 | + default : 0, | ||
20 | }, | 25 | }, |
26 | + regDtm : { | ||
27 | + type : Date, | ||
28 | + required : true, | ||
29 | + default : Date.now, | ||
30 | + } | ||
21 | }); | 31 | }); |
22 | 32 | ||
23 | -TakeMedicineHistorySchema.statics.findByBottleId = async function(bottleId) { | ||
24 | - return this.find({ bottleId }); | ||
25 | -}; | ||
26 | - | ||
27 | -TakeMedicineHistorySchema.statics.findByBottleIdAndMedicineId = async function(bottleId, medicineId) { | ||
28 | - return this.find({ bottleId, medicineId }); | ||
29 | -}; | ||
30 | - | ||
31 | 33 | ||
32 | -module.export = mongoose.model("TakeMedicineHist", TakeMedicineHistorySchema); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
34 | +module.exports = mongoose.model('BottleMedicine', BottleMedicineSchema); | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -7,7 +7,7 @@ const DoctorInfoSchema = new Schema({ | ... | @@ -7,7 +7,7 @@ const DoctorInfoSchema = new Schema({ |
7 | info : { | 7 | info : { |
8 | doctorLicense : { type : String, required : true, }, | 8 | doctorLicense : { type : String, required : true, }, |
9 | hospitalNm : { type : String, default : null, }, | 9 | hospitalNm : { type : String, default : null, }, |
10 | - hosptialAddr : { type : String, default : null, }, | 10 | + hospitalAddr : { type : String, default : null, }, |
11 | contact : { type : String, required : true, }, | 11 | contact : { type : String, required : true, }, |
12 | }, | 12 | }, |
13 | useYn : { type : String, default : 'W', required : true, }, | 13 | useYn : { type : String, default : 'W', required : true, }, | ... | ... |
... | @@ -5,8 +5,12 @@ const Schema = mongoose.Schema; | ... | @@ -5,8 +5,12 @@ const Schema = mongoose.Schema; |
5 | const FeedbackSchema = new Schema({ | 5 | const FeedbackSchema = new Schema({ |
6 | fdbDtm : { type : Date, default : Date.now, required : true, }, | 6 | fdbDtm : { type : Date, default : Date.now, required : true, }, |
7 | fdbType : { type : String, required : true, }, | 7 | fdbType : { type : String, required : true, }, |
8 | - bottleId : { type : Number, required : true, }, | 8 | + bmId : { |
9 | - doctorId : { type : String, required : true, }, | 9 | + type : Schema.Types.ObjectId, |
10 | + required : true, | ||
11 | + ref : 'BottleMedicine', | ||
12 | + }, | ||
13 | + doctorId : { type : String, required : true, ref : 'User', }, | ||
10 | feedback : { type : String, required : true, }, | 14 | feedback : { type : String, required : true, }, |
11 | }); | 15 | }); |
12 | 16 | ... | ... |
... | @@ -12,31 +12,14 @@ const MedicineSchema = new Schema ({ | ... | @@ -12,31 +12,14 @@ const MedicineSchema = new Schema ({ |
12 | antiEffect : { type : String, required : true } | 12 | antiEffect : { type : String, required : true } |
13 | }) | 13 | }) |
14 | 14 | ||
15 | -MedicineSchema.statics.findByName = async function(name) { | 15 | +MedicineSchema.statics.findByKeyword = function(keyword) { |
16 | - const all = await this.find().exec(); | 16 | + return this.find({ |
17 | - const result = all.filter(item => { | 17 | + $or : [ |
18 | - return item.name.includes(name) | 18 | + { name : { $regex : keyword }}, |
19 | - }); | 19 | + { company : { $regex : keyword }}, |
20 | - | 20 | + { target : { $regex : keyword }}, |
21 | - return result; | 21 | + ] |
22 | -}; | 22 | + }) |
23 | - | ||
24 | -MedicineSchema.statics.findByCompany = async function(company) { | ||
25 | - const all = await this.find().exec(); | ||
26 | - const result = all.filter(item => { | ||
27 | - return item.company.includes(company) | ||
28 | - }); | ||
29 | - | ||
30 | - return result; | ||
31 | -}; | ||
32 | - | ||
33 | -MedicineSchema.statics.findByTarget = async function(target) { | ||
34 | - const all = await this.find().exec(); | ||
35 | - const result = all.filter(item => { | ||
36 | - return item.target.includes(target) | ||
37 | - }); | ||
38 | - | ||
39 | - return result; | ||
40 | }; | 23 | }; |
41 | 24 | ||
42 | MedicineSchema.statics.findByMedicineId = function(medicineId) { | 25 | MedicineSchema.statics.findByMedicineId = function(medicineId) { | ... | ... |
... | @@ -4,27 +4,36 @@ const moment = require('moment'); | ... | @@ -4,27 +4,36 @@ const moment = require('moment'); |
4 | const Schema = mongoose.Schema; | 4 | const Schema = mongoose.Schema; |
5 | 5 | ||
6 | const PatientInfoSchema = new Schema({ | 6 | const PatientInfoSchema = new Schema({ |
7 | - patientId : { type : String, required : true, }, | 7 | + patientId : { type : String, required : true, ref : 'User', }, |
8 | - doctorId : { type : String, required : true, }, | 8 | + doctorId : { type : String, required : true, ref : 'User', }, |
9 | info : { type : String, required : true, }, | 9 | info : { type : String, required : true, }, |
10 | + useYn : { type : String, required : true, default : 'W', }, | ||
10 | }); | 11 | }); |
11 | 12 | ||
12 | -PatientInfoSchema.statics.findAllByPatientId = function(patientId) { | 13 | +PatientInfoSchema.statics.findAllByPatientIdAndUseYn = function(patientId, useYn) { |
13 | - return this.find({ patientId }); | 14 | + return this.find({ patientId, useYn }); |
14 | }; | 15 | }; |
15 | 16 | ||
16 | -PatientInfoSchema.statics.findAllByDoctorId = function(doctorId) { | 17 | +PatientInfoSchema.statics.findAllByDoctorIdAndUseYn = function(doctorId, useYn) { |
17 | - return this.find({ doctorId }); | 18 | + return this.find({ doctorId, useYn }); |
18 | }; | 19 | }; |
19 | 20 | ||
20 | PatientInfoSchema.statics.findByPatientIdAndDoctorId = function(patientId, doctorId) { | 21 | PatientInfoSchema.statics.findByPatientIdAndDoctorId = function(patientId, doctorId) { |
21 | return this.findOne({ patientId, doctorId }); | 22 | return this.findOne({ patientId, doctorId }); |
22 | }; | 23 | }; |
23 | 24 | ||
25 | +PatientInfoSchema.statics.findByPatientIdAndDoctorIdAndUseYn = function(patientId, doctorId, useYn) { | ||
26 | + return this.findOne({ patientId, doctorId, useYn }); | ||
27 | +}; | ||
28 | + | ||
24 | PatientInfoSchema.methods.getInfo = function() { | 29 | PatientInfoSchema.methods.getInfo = function() { |
25 | return this.info; | 30 | return this.info; |
26 | }; | 31 | }; |
27 | 32 | ||
33 | +PatientInfoSchema.methods.setUseYn = function(useYn) { | ||
34 | + this.useYn = useYn; | ||
35 | +}; | ||
36 | + | ||
28 | PatientInfoSchema.methods.updateInfo = function(info) { | 37 | PatientInfoSchema.methods.updateInfo = function(info) { |
29 | const date = moment(new Date()).format('YYYY-MM-DD hh:mm'); | 38 | const date = moment(new Date()).format('YYYY-MM-DD hh:mm'); |
30 | if(this.info.length) | 39 | if(this.info.length) | ... | ... |
... | @@ -3,7 +3,7 @@ const mongoose = require('mongoose'); | ... | @@ -3,7 +3,7 @@ const mongoose = require('mongoose'); |
3 | const Schema = mongoose.Schema; | 3 | const Schema = mongoose.Schema; |
4 | 4 | ||
5 | const ProfileSchema = new Schema({ | 5 | const ProfileSchema = new Schema({ |
6 | - userId : { type : String, required : true, }, | 6 | + userId : { type : String, required : true, ref : 'User', }, |
7 | userNm : { type : String, required : true, }, | 7 | userNm : { type : String, required : true, }, |
8 | userAge : { type : Number, required : true, }, | 8 | userAge : { type : Number, required : true, }, |
9 | contact : { type : String, required : true, }, | 9 | contact : { type : String, required : true, }, | ... | ... |
server/src/models/takeMedicineHistory.js
0 → 100644
1 | +const mongoose = require('mongoose'); | ||
2 | + | ||
3 | +const Schema = mongoose.Schema; | ||
4 | + | ||
5 | +const TakeMedicineHistorySchema = new Schema ({ | ||
6 | + takeDate : { | ||
7 | + type : Date, | ||
8 | + required : true, | ||
9 | + default : Date.now, | ||
10 | + }, | ||
11 | + bmId : { | ||
12 | + type : Schema.Types.ObjectId, | ||
13 | + ref : 'BottleMedicine', | ||
14 | + required : true, | ||
15 | + }, | ||
16 | + temperature : { type : Number, default : 0 }, | ||
17 | + humidity : { type : Number, default : 0 }, | ||
18 | + balance : { type : Number, default : 0 }, | ||
19 | +}); | ||
20 | + | ||
21 | + | ||
22 | +module.exports = mongoose.model('TakeMedicineHist', TakeMedicineHistorySchema); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -5,7 +5,7 @@ const jwt = require('jsonwebtoken'); | ... | @@ -5,7 +5,7 @@ const jwt = require('jsonwebtoken'); |
5 | const Schema = mongoose.Schema; | 5 | const Schema = mongoose.Schema; |
6 | 6 | ||
7 | const UserSchema = new Schema ({ | 7 | const UserSchema = new Schema ({ |
8 | - userId : { type: String, required : true, unique : true, lowercase : true }, | 8 | + userId : { type: String, required : true, unique : true, lowercase : true, }, |
9 | hashedPassword : { type : String, required : true }, | 9 | hashedPassword : { type : String, required : true }, |
10 | userTypeCd : { type : String, required : true, default : 'NORMAL' }, | 10 | userTypeCd : { type : String, required : true, default : 'NORMAL' }, |
11 | useYn : { type : String, default : 'W', required : true, }, | 11 | useYn : { type : String, default : 'W', required : true, }, |
... | @@ -39,6 +39,7 @@ UserSchema.methods.generateToken = function() { | ... | @@ -39,6 +39,7 @@ UserSchema.methods.generateToken = function() { |
39 | _id : this._id, | 39 | _id : this._id, |
40 | userId : this.userId | 40 | userId : this.userId |
41 | }, | 41 | }, |
42 | + // eslint-disable-next-line no-undef | ||
42 | process.env.JWT_SECRET, | 43 | process.env.JWT_SECRET, |
43 | { expiresIn : '30d' } | 44 | { expiresIn : '30d' } |
44 | ); | 45 | ); | ... | ... |
server/yarn.lock
0 → 100644
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment