박권수

feat. bottlemedicine : use Yn add

...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
19 "dependencies": { 19 "dependencies": {
20 "@koa/cors": "^3.1.0", 20 "@koa/cors": "^3.1.0",
21 "moment": "^2.29.1", 21 "moment": "^2.29.1",
22 - "mqtt": "^4.2.6" 22 + "mqtt": "^4.2.6",
23 + "node-cron": "^3.0.0"
23 }, 24 },
24 "devDependencies": { 25 "devDependencies": {
25 "eslint": "^7.32.0" 26 "eslint": "^7.32.0"
......
...@@ -143,14 +143,11 @@ exports.getBottleInfo = async(ctx) => { ...@@ -143,14 +143,11 @@ exports.getBottleInfo = async(ctx) => {
143 const message = 'req'; 143 const message = 'req';
144 await Mqtt.mqttPublishMessage(client, { topic, message }); 144 await Mqtt.mqttPublishMessage(client, { topic, message });
145 145
146 - const bottleMedicine = await BottleMedicine.find({ bottleId }) 146 + const bottleMedicine = await BottleMedicine.findOne({ bottleId, useYn : 'Y' });
147 - .sort({ regDtm : 'desc' })
148 - .limit(1);
149 147
150 - if(bottleMedicine.length) { 148 + if(bottleMedicine) {
151 -
152 const takeMedicineHist = await TakeMedicineHist 149 const takeMedicineHist = await TakeMedicineHist
153 - .find({ bmId : bottleMedicine[0]._id }) 150 + .find({ bmId : bottleMedicine._id })
154 .sort({ takeDate : 'desc' }) 151 .sort({ takeDate : 'desc' })
155 .populate('bmId'); 152 .populate('bmId');
156 153
...@@ -208,12 +205,10 @@ exports.getBottleFeedback = async ctx => { ...@@ -208,12 +205,10 @@ exports.getBottleFeedback = async ctx => {
208 return; 205 return;
209 } 206 }
210 207
211 - const bottleMedicine = await BottleMedicine.find({ bottleId }) 208 + const bottleMedicine = await BottleMedicine.findOne({ bottleId, useYn : 'Y' });
212 - .sort({ regDtm : 'desc' })
213 - .limit(1);
214 209
215 - if(bottleMedicine.length) { 210 + if(bottleMedicine) {
216 - const feedbackList = await Feedback.find({ bmId : bottleMedicine[0]._id }) 211 + const feedbackList = await Feedback.find({ bmId : bottleMedicine._id })
217 .sort({ fdbDtm : 'desc' }) 212 .sort({ fdbDtm : 'desc' })
218 .populate('bmId'); 213 .populate('bmId');
219 214
...@@ -294,6 +289,7 @@ exports.setMedicine = async(ctx) => { ...@@ -294,6 +289,7 @@ exports.setMedicine = async(ctx) => {
294 bottleMedicine.setDoctorId(doctorId); 289 bottleMedicine.setDoctorId(doctorId);
295 } 290 }
296 291
292 + await BottleMedicine.updateMany({ bottleId }, { useYn : 'N '});
297 293
298 bottleMedicine.save(); 294 bottleMedicine.save();
299 295
......
...@@ -145,11 +145,12 @@ exports.getPatientDetail = async ctx => { ...@@ -145,11 +145,12 @@ exports.getPatientDetail = async ctx => {
145 145
146 const reqUserBmList = []; 146 const reqUserBmList = [];
147 await Promise.all(reqUserBottleList.map(async bottle => { 147 await Promise.all(reqUserBottleList.map(async bottle => {
148 - const bmList = await BottleMedicine.find({ 148 + const bm = await BottleMedicine.findOne({
149 doctorId : userId, 149 doctorId : userId,
150 bottleId : bottle.bottleId, 150 bottleId : bottle.bottleId,
151 - }).sort({ regDtm : 'desc' }).limit(1); 151 + useYn : 'Y',
152 - reqUserBmList.push(...bmList); 152 + });
153 + reqUserBmList.push(bm);
153 })); 154 }));
154 155
155 const bottleList = await Promise.all(reqUserBmList.map(async bottleMedicine => { 156 const bottleList = await Promise.all(reqUserBmList.map(async bottleMedicine => {
...@@ -207,7 +208,7 @@ exports.getBottleDetail = async ctx => { ...@@ -207,7 +208,7 @@ exports.getBottleDetail = async ctx => {
207 return; 208 return;
208 } 209 }
209 210
210 - const bottleMedicine = await BottleMedicine.findOne({ bottleId, doctorId : userId }); 211 + const bottleMedicine = await BottleMedicine.findOne({ bottleId, doctorId : userId, useYn : 'Y' });
211 if(!bottleMedicine) { 212 if(!bottleMedicine) {
212 ctx.status = 403; 213 ctx.status = 403;
213 ctx.body = { 214 ctx.body = {
...@@ -318,11 +319,9 @@ exports.writeReqBottleFeedback = async ctx => { ...@@ -318,11 +319,9 @@ exports.writeReqBottleFeedback = async ctx => {
318 return; 319 return;
319 } 320 }
320 321
321 - const bottleMedicine = await BottleMedicine.find({ bottleId, doctorId : userId }) 322 + const bottleMedicine = await BottleMedicine.findOne({ bottleId, doctorId : userId, useYn : 'Y' });
322 - .sort({ regDtm : 'desc' })
323 - .limit(1);
324 323
325 - if(!bottleMedicine.length) { 324 + if(!bottleMedicine) {
326 ctx.status = 403; 325 ctx.status = 403;
327 ctx.body = { 326 ctx.body = {
328 error : '약병에 대한 권한 없음' 327 error : '약병에 대한 권한 없음'
...@@ -332,7 +331,7 @@ exports.writeReqBottleFeedback = async ctx => { ...@@ -332,7 +331,7 @@ exports.writeReqBottleFeedback = async ctx => {
332 331
333 const newFeedback = new Feedback({ 332 const newFeedback = new Feedback({
334 fdbType, 333 fdbType,
335 - bmId : bottleMedicine[0]._id, 334 + bmId : bottleMedicine._id,
336 doctorId : userId, 335 doctorId : userId,
337 feedback, 336 feedback,
338 }); 337 });
......
...@@ -63,7 +63,7 @@ const bottleInfoUpdate = async(data) => { ...@@ -63,7 +63,7 @@ const bottleInfoUpdate = async(data) => {
63 humidity = parseFloat(humidity); 63 humidity = parseFloat(humidity);
64 balance = parseInt(balance); 64 balance = parseInt(balance);
65 65
66 - const bottleMedicine = await BottleMedicine.find({ bottleId }).sort((a, b) => a.regDtm < b.regDtm)[0]; 66 + const bottleMedicine = await BottleMedicine.findOne({ bottleId, useYn : 'Y' });
67 67
68 if(bottleMedicine) { 68 if(bottleMedicine) {
69 if(isOpen) { 69 if(isOpen) {
...@@ -83,7 +83,7 @@ const bottleInfoUpdate = async(data) => { ...@@ -83,7 +83,7 @@ const bottleInfoUpdate = async(data) => {
83 const transPublishingTopicAndMessage = async(bottleId) => { 83 const transPublishingTopicAndMessage = async(bottleId) => {
84 const topic = 'bottle/' + bottleId + '/stb'; 84 const topic = 'bottle/' + bottleId + '/stb';
85 85
86 - const bottleMedicine = await BottleMedicine.find({ bottleId }).sort((a, b) => a.regDtm < b.regDtm)[0]; 86 + const bottleMedicine = await BottleMedicine.findOne({ bottleId, useYn : 'Y' });
87 const takeMedicineHist = await TakeMedicineHist.find({ 87 const takeMedicineHist = await TakeMedicineHist.find({
88 bmId : bottleMedicine._id 88 bmId : bottleMedicine._id
89 }).sort((a, b) => a.takeDate < b.takeDate)[0]; 89 }).sort((a, b) => a.takeDate < b.takeDate)[0];
......
...@@ -28,11 +28,20 @@ const BottleMedicineSchema = new Schema({ ...@@ -28,11 +28,20 @@ const BottleMedicineSchema = new Schema({
28 required : true, 28 required : true,
29 default : Date.now, 29 default : Date.now,
30 }, 30 },
31 + useYn : {
32 + type : String,
33 + required : true,
34 + default : 'Y',
35 + },
31 }); 36 });
32 37
33 BottleMedicineSchema.methods.setDoctorId = function(doctorId) { 38 BottleMedicineSchema.methods.setDoctorId = function(doctorId) {
34 this.doctorId = doctorId; 39 this.doctorId = doctorId;
35 }; 40 };
36 41
42 +BottleMedicineSchema.methods.setUseYn = function(useYn) {
43 + this.useYn = useYn;
44 +};
45 +
37 46
38 module.exports = mongoose.model('BottleMedicine', BottleMedicineSchema); 47 module.exports = mongoose.model('BottleMedicine', BottleMedicineSchema);
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -725,7 +725,14 @@ minimist@^1.1.0, minimist@^1.2.5: ...@@ -725,7 +725,14 @@ minimist@^1.1.0, minimist@^1.2.5:
725 resolved "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz" 725 resolved "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz"
726 integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw== 726 integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
727 727
728 -moment@^2.29.1: 728 +moment-timezone@^0.5.31:
729 + version "0.5.33"
730 + resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.33.tgz#b252fd6bb57f341c9b59a5ab61a8e51a73bbd22c"
731 + integrity sha512-PTc2vcT8K9J5/9rDEPe5czSIKgLoGsH8UNpA4qZTVw0Vd/Uz19geE9abbIOQKaAQFcnQ3v5YEXrbSc5BpshH+w==
732 + dependencies:
733 + moment ">= 2.9.0"
734 +
735 +"moment@>= 2.9.0", moment@^2.29.1:
729 version "2.29.1" 736 version "2.29.1"
730 resolved "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz" 737 resolved "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz"
731 integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ== 738 integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==
...@@ -768,6 +775,13 @@ natural-compare@^1.4.0: ...@@ -768,6 +775,13 @@ natural-compare@^1.4.0:
768 resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz" 775 resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz"
769 integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc= 776 integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
770 777
778 +node-cron@^3.0.0:
779 + version "3.0.0"
780 + resolved "https://registry.yarnpkg.com/node-cron/-/node-cron-3.0.0.tgz#b33252803e430f9cd8590cf85738efa1497a9522"
781 + integrity sha512-DDwIvvuCwrNiaU7HEivFDULcaQualDv7KoNlB/UU1wPW0n1tDEmBJKhEIE6DlF2FuoOHcNbLJ8ITL2Iv/3AWmA==
782 + dependencies:
783 + moment-timezone "^0.5.31"
784 +
771 once@^1.3.0, once@^1.3.1, once@^1.4.0: 785 once@^1.3.0, once@^1.3.1, once@^1.4.0:
772 version "1.4.0" 786 version "1.4.0"
773 resolved "https://registry.npmjs.org/once/-/once-1.4.0.tgz" 787 resolved "https://registry.npmjs.org/once/-/once-1.4.0.tgz"
......