Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
RIT_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박권수
2021-10-09 18:31:46 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
4e9bd5d6f6fd128212f8932857340cc833e0a75c
4e9bd5d6
2 parents
af71d7e1
be191115
Merge branch 'server' into web
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
407 additions
and
124 deletions
.vscode/launch.json
server/src/api/auth/auth.ctrl.js
server/src/api/auth/index.js
server/src/api/bottle/bottle.ctrl.js
server/src/api/bottle/index.js
server/src/api/doctor/doctor.ctrl.js
server/src/api/doctor/index.js
server/src/api/hub/hub.ctrl.js
server/src/api/manage/manage.ctrl.js
server/src/api/user/index.js
server/src/api/user/user.ctrl.js
server/src/models/bottleMedicine.js
server/src/models/prescribeInfo.js
server/src/models/profile.js
server/src/models/takeMedicineHistory.js
server/src/util/DataProcess.js
server/src/util/GoogleCloudStorage.js
server/src/util/MqttModule.js
server/src/util/QrCodeUtil.js
.vscode/launch.json
View file @
4e9bd5d
...
...
@@ -5,10 +5,20 @@
"version"
:
"0.2.0"
,
"configurations"
:
[
{
"name"
:
"flutter_application_1"
,
"cwd"
:
"frontend
\\
flutter_application_1"
,
"request"
:
"launch"
,
"type"
:
"dart"
}
"name"
:
"Attach"
,
"port"
:
9229
,
"request"
:
"attach"
,
"skipFiles"
:
[
"<node_internals>/**"
],
"type"
:
"pwa-node"
},
{
"name"
:
"Attach to Chrome"
,
"port"
:
9222
,
"request"
:
"attach"
,
"type"
:
"pwa-chrome"
,
"webRoot"
:
"${workspaceFolder}"
},
]
}
\ No newline at end of file
...
...
server/src/api/auth/auth.ctrl.js
View file @
4e9bd5d
/* eslint-disable no-undef */
//회원가입, 로그인 및 로그아웃에 관한 api
const
User
=
require
(
'../../models/user'
);
const
Profile
=
require
(
'../../models/profile'
);
const
DoctorInfo
=
require
(
'../../models/doctorInfo'
);
const
Hub
=
require
(
'../../models/hub'
);
const
Bottle
=
require
(
'../../models/bottle'
);
const
BottleMedicine
=
require
(
'../../models/bottleMedicine'
);
const
PatientInfo
=
require
(
'../../models/patientInfo'
);
const
{
uploadDoctorLicense
}
=
require
(
'../../util/GoogleCloudStorage'
);
const
Joi
=
require
(
'joi'
);
const
jwt
=
require
(
'jsonwebtoken'
);
...
...
@@ -48,6 +51,15 @@ exports.register = async(ctx) => {
return
;
}
const
existContact
=
await
Profile
.
findOne
({
contact
,
useYn
:
'Y'
});
if
(
existContact
)
{
ctx
.
status
=
409
;
ctx
.
body
=
{
error
:
'이미 가입된 번호입니다.'
,
};
return
;
}
const
user
=
new
User
({
userId
,
userTypeCd
:
'NORMAL'
,
...
...
@@ -80,6 +92,7 @@ exports.searchHospital = async ctx => {
const
pageSlice
=
5
;
const
url
=
'http://apis.data.go.kr/B551182/hospInfoService1/getHospBasisList1'
;
// eslint-disable-next-line no-undef
let
queryParams
=
'?'
+
encodeURIComponent
(
'ServiceKey'
)
+
'='
+
process
.
env
.
SERVICE_KEY
;
queryParams
+=
'&'
+
encodeURIComponent
(
'pageNo'
)
+
'='
+
encodeURIComponent
(
page
);
queryParams
+=
'&'
+
encodeURIComponent
(
'numOfRows'
)
+
'='
+
encodeURIComponent
(
pageSlice
);
...
...
@@ -188,14 +201,19 @@ exports.doctorRegister = async ctx => {
useYn
:
'W'
,
});
doctor
.
save
();
doctorInfo
.
save
();
await
doctor
.
save
();
await
doctorInfo
.
save
();
ctx
.
status
=
201
;
}
//로컬 로그인
/**
* 로컬 로그인
* @param {*} ctx
* @returns token
* http methods : POST
*/
exports
.
login
=
async
(
ctx
)
=>
{
const
{
userId
,
password
,
deviceToken
}
=
ctx
.
request
.
body
;
...
...
@@ -276,8 +294,8 @@ exports.socialRegister = async ctx => {
return
{
userId
:
result
.
email
,
userNm
:
result
.
name
,
contact
:
null
,
birth
:
null
,
contact
:
`
${
result
.
email
}
_등록되지않은 번호`
,
birth
:
'등록되지않음'
,
};
}
:
socialType
.
toUpperCase
()
===
'NAVER'
?
async
()
=>
{
...
...
@@ -333,6 +351,16 @@ exports.socialRegister = async ctx => {
return
;
}
const
existContact
=
await
Profile
.
findOne
({
contact
,
useYn
:
'Y'
});
if
(
existContact
)
{
ctx
.
status
=
409
;
ctx
.
body
=
{
error
:
'이미 가입된 번호'
,
};
return
;
}
const
user
=
new
User
({
userId
,
hashedPassword
:
'unnecessary'
,
...
...
@@ -437,6 +465,11 @@ exports.socialLogin = async ctx => {
};
/**
* 로그아웃
* @param {*} ctx
* httm methods : POST
*/
exports
.
logout
=
async
(
ctx
)
=>
{
ctx
.
cookies
.
set
(
'access_token'
,
null
,
{
httpOnly
:
true
,
...
...
@@ -446,6 +479,87 @@ exports.logout = async(ctx) => {
ctx
.
status
=
204
;
};
/**
* 회원 탈퇴
* @param {*} ctx
* http methods : delete
*/
exports
.
secession
=
async
ctx
=>
{
const
token
=
ctx
.
req
.
headers
.
authorization
;
if
(
!
token
||
!
token
.
length
)
{
ctx
.
status
=
401
;
return
;
}
// eslint-disable-next-line no-undef
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
);
const
user
=
await
User
.
findByUserId
(
userId
);
if
(
!
user
||
user
.
useYn
!==
'Y'
)
{
ctx
.
status
=
403
;
return
;
}
const
{
password
}
=
ctx
.
query
;
const
isPasswordTrue
=
await
user
.
checkPassword
(
password
);
if
(
!
isPasswordTrue
)
{
ctx
.
status
=
401
;
ctx
.
body
=
{
error
:
'비밀번호가 틀렸습니다.'
,
};
return
;
}
if
(
user
.
userTypeCd
===
'NORMAL'
)
{
const
profile
=
await
Profile
.
findOne
({
userId
});
//프로필 삭제
await
profile
.
setUseYn
(
'N'
);
await
profile
.
save
();
//유저에 등록된 허브, 약병, 약병정보 전부 삭제
const
hubList
=
await
Hub
.
find
({
userId
});
await
Promise
.
all
(
hubList
.
map
(
async
hub
=>
{
const
bottleList
=
await
Bottle
.
find
({
hubId
:
hub
.
hubId
});
await
Promise
.
all
(
bottleList
.
map
(
async
bottle
=>
{
const
bottleMedicine
=
await
BottleMedicine
.
findOne
({
bottleId
:
bottle
.
bottleId
});
await
bottleMedicine
.
setUseYn
(
'N'
);
await
bottleMedicine
.
save
();
}));
await
Bottle
.
deleteMany
({
hubId
:
hub
.
hubId
});
}));
await
Hub
.
deleteMany
({
userId
});
//환자 정보 삭제
const
patientInfoList
=
await
PatientInfo
.
find
({
patientId
:
userId
,
useYn
:
'Y'
});
await
Promise
.
all
(
patientInfoList
.
map
(
async
patientInfo
=>
{
await
patientInfo
.
setUseYn
(
'N'
);
await
patientInfo
.
save
();
}));
//유저 삭제
await
user
.
setUseYn
(
'N'
);
await
user
.
save
();
}
else
if
(
user
.
userTypeCd
===
'DOCTOR'
)
{
const
doctorInfo
=
await
DoctorInfo
.
findOne
({
doctorId
:
userId
});
await
doctorInfo
.
setUseYn
(
'WS'
);
await
doctorInfo
.
save
();
await
user
.
setUseYn
(
'WS'
);
await
user
.
save
();
}
ctx
.
status
=
200
;
};
exports
.
verifyToken
=
async
(
ctx
)
=>
{
const
token
=
ctx
.
req
.
headers
.
authorization
;
if
(
!
token
||
!
token
.
length
)
{
...
...
@@ -458,6 +572,7 @@ exports.verifyToken = async(ctx) => {
return
;
}
// eslint-disable-next-line no-undef
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
,
(
err
,
decoded
)
=>
{
if
(
err
)
{
ctx
.
status
=
400
;
...
...
server/src/api/auth/index.js
View file @
4e9bd5d
...
...
@@ -26,7 +26,7 @@ auth.get('/hospital', authCtrl.searchHospital);
* request parameter : userId, password, passwordCheck, doctorInfo(File)
* return : null
*/
auth
.
post
(
'/register/doctor'
,
KoaBody
,
authCtrl
.
doctorRegister
)
auth
.
post
(
'/register/doctor'
,
KoaBody
,
authCtrl
.
doctorRegister
)
/**
* 로컬 로그인 (email type)
...
...
@@ -58,7 +58,15 @@ auth.post('/login/social/:socialType', authCtrl.socialLogin);
* request parameter : null
* return : null
*/
auth
.
post
(
'/logout'
,
authCtrl
.
logout
)
auth
.
post
(
'/logout'
,
authCtrl
.
logout
);
/**
* 회원 탈퇴
* url : http://localhost:4000/api/auth
* request parameter : password
* return : null
*/
auth
.
delete
(
'/'
,
authCtrl
.
secession
);
/**
* 토큰이 유효한지 확인
...
...
server/src/api/bottle/bottle.ctrl.js
View file @
4e9bd5d
/* eslint-disable no-undef */
//어플에서 약병 등록 및, 약병에 관한 정보 조회 = 여기서 mqtt통신으로 broker에 데이터를 요청한다.
const
Bottle
=
require
(
'../../models/bottle'
);
const
Hub
=
require
(
'../../models/hub'
);
const
Medicine
=
require
(
'../../models/medicine'
);
const
User
=
require
(
'../../models/user'
);
const
DoctorInfo
=
require
(
'../../models/doctorInfo'
);
const
PatientInfo
=
require
(
'../../models/patientInfo'
);
const
TakeMedicineHist
=
require
(
'../../models/takeMedicineHistory'
);
const
BottleMedicine
=
require
(
'../../models/bottleMedicine'
);
...
...
@@ -19,6 +19,7 @@ exports.bottleConnect = async(ctx) => {
return
;
}
// eslint-disable-next-line no-undef
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
);
const
user
=
await
User
.
findByUserId
(
userId
);
if
(
!
user
||
!
user
.
userTypeCd
||
user
.
useYn
!==
'Y'
)
{
...
...
@@ -73,6 +74,7 @@ exports.bottleDisconnect = async(ctx) => {
return
;
}
// eslint-disable-next-line no-undef
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
);
const
user
=
await
User
.
findByUserId
(
userId
);
if
(
!
user
||
!
user
.
userTypeCd
||
user
.
useYn
!==
'Y'
)
{
...
...
@@ -114,6 +116,7 @@ exports.getBottleInfo = async(ctx) => {
return
;
}
// eslint-disable-next-line no-undef
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
);
const
user
=
await
User
.
findByUserId
(
userId
);
if
(
!
user
||
!
user
.
userTypeCd
||
user
.
useYn
!==
'Y'
)
{
...
...
@@ -146,21 +149,29 @@ exports.getBottleInfo = async(ctx) => {
const
bottleMedicine
=
await
BottleMedicine
.
findOne
({
bottleId
,
useYn
:
'Y'
});
if
(
bottleMedicine
)
{
const
medicine
=
await
Medicine
.
findOne
({
medicineId
:
bottleMedicine
.
medicineId
});
const
doctorInfo
=
await
DoctorInfo
.
findOne
({
doctorId
:
bottleMedicine
.
doctorId
});
const
takeMedicineHist
=
await
TakeMedicineHist
.
find
({
bmId
:
bottleMedicine
.
_id
})
.
sort
({
takeDate
:
'desc'
})
.
populate
(
'bmId'
);
.
sort
({
takeDate
:
'desc'
});
ctx
.
status
=
200
;
ctx
.
body
=
{
bottle
,
medicine
,
doctorInfo
,
dailyDosage
:
bottleMedicine
.
dailyDosage
,
totalDosage
:
bottleMedicine
.
totalDosage
,
takeMedicineHist
,
};
}
else
{
ctx
.
status
=
200
;
ctx
.
body
=
{
bottle
,
medicine
:
null
,
doctorInfo
:
null
,
dailyDosage
:
null
,
totalDosage
:
null
,
takeMedicineHist
:
[],
}
}
...
...
@@ -175,6 +186,7 @@ exports.getBottleFeedback = async ctx => {
return
;
}
// eslint-disable-next-line no-undef
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
);
const
user
=
await
User
.
findByUserId
(
userId
);
if
(
!
user
||
!
user
.
userTypeCd
||
user
.
useYn
!==
'Y'
)
{
...
...
@@ -213,7 +225,9 @@ exports.getBottleFeedback = async ctx => {
.
populate
(
'bmId'
);
ctx
.
status
=
200
;
ctx
.
body
=
feedbackList
;
ctx
.
body
=
{
feedbackList
};
}
else
{
ctx
.
status
=
404
;
ctx
.
body
=
{
...
...
@@ -231,6 +245,7 @@ exports.setMedicine = async(ctx) => {
return
;
}
// eslint-disable-next-line no-undef
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
);
const
user
=
await
User
.
findByUserId
(
userId
);
if
(
!
user
||
!
user
.
userTypeCd
||
user
.
useYn
!==
'Y'
)
{
...
...
@@ -239,7 +254,7 @@ exports.setMedicine = async(ctx) => {
}
const
{
bottleId
}
=
ctx
.
params
;
const
{
medicineId
,
do
sage
,
doctorId
}
=
ctx
.
request
.
body
;
const
{
medicineId
,
do
ctorId
,
dailyDosage
,
totalDosage
,
}
=
ctx
.
request
.
body
;
const
bottle
=
await
Bottle
.
findByBottleId
(
bottleId
);
if
(
!
bottle
)
{
...
...
@@ -273,7 +288,8 @@ exports.setMedicine = async(ctx) => {
let
bottleMedicine
=
new
BottleMedicine
({
bottleId
,
medicineId
,
dosage
,
dailyDosage
,
totalDosage
,
});
if
(
doctorId
!==
undefined
&&
doctorId
!==
null
&&
doctorId
!==
''
)
{
...
...
@@ -286,14 +302,63 @@ exports.setMedicine = async(ctx) => {
return
;
}
bottleMedicine
.
setDoctorId
(
doctorId
);
await
bottleMedicine
.
setDoctorId
(
doctorId
);
}
await
BottleMedicine
.
updateMany
({
bottleId
},
{
useYn
:
'N '
});
bottleMedicine
.
save
();
await
bottleMedicine
.
save
();
ctx
.
status
=
200
;
};
//약 무게 세팅
exports
.
setMedicineWeight
=
async
ctx
=>
{
const
token
=
ctx
.
req
.
headers
.
authorization
;
if
(
!
token
||
!
token
.
length
)
{
ctx
.
status
=
401
;
return
;
}
// eslint-disable-next-line no-undef
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
);
const
user
=
await
User
.
findByUserId
(
userId
);
if
(
!
user
||
!
user
.
userTypeCd
||
user
.
useYn
!==
'Y'
)
{
ctx
.
status
=
403
;
return
;
}
const
{
bottleId
}
=
ctx
.
params
;
const
bottle
=
await
Bottle
.
findByBottleId
(
bottleId
);
if
(
!
bottle
)
{
ctx
.
status
=
404
;
ctx
.
body
=
{
error
:
'약병 찾을 수 없음.'
,
}
return
;
}
const
hub
=
await
Hub
.
findByHubId
(
bottle
.
getHubId
());
if
(
hub
.
getHub_UserId
()
!==
userId
)
{
ctx
.
status
=
403
;
ctx
.
body
=
{
error
:
'해당 허브 권한 없음'
,
}
return
;
}
//toDo : 약병에서 가져온 무게 데이터를 이용하여, bottleMedicine값을 갱신.
const
bottleMedicine
=
await
BottleMedicine
.
findOne
({
bottleId
,
useYn
:
'Y'
});
const
{
totalWeight
,
totalDosage
}
=
bottleMedicine
;
ctx
.
status
=
200
;
};
// //비어있는 약병에 의사를 등록한다.
...
...
@@ -344,6 +409,7 @@ exports.getHubsBottleList = async(ctx) => {
return
;
}
// eslint-disable-next-line no-undef
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
);
const
user
=
await
User
.
findByUserId
(
userId
);
if
(
!
user
||
!
user
.
userTypeCd
||
user
.
useYn
!==
'Y'
)
{
...
...
@@ -385,6 +451,7 @@ exports.getAllBottleList = async ctx => {
return
;
}
// eslint-disable-next-line no-undef
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
);
const
user
=
await
User
.
findByUserId
(
userId
);
if
(
!
user
||
!
user
.
userTypeCd
||
user
.
useYn
!==
'Y'
)
{
...
...
@@ -402,7 +469,7 @@ exports.getAllBottleList = async ctx => {
ctx
.
status
=
200
;
ctx
.
body
=
{
bottleList
bottleList
,
};
};
\ No newline at end of file
...
...
server/src/api/bottle/index.js
View file @
4e9bd5d
...
...
@@ -44,6 +44,14 @@ bottle.get('/feedback/:bottleId', bottleCtrl.getBottleFeedback);
bottle
.
patch
(
'/:bottleId'
,
bottleCtrl
.
setMedicine
);
/**
* 약병에 등록된 약의 무게 갱신
* request parameter : bottleid
* url : http://localhost:4000/api/bottle/weight/:bottleId
* return : null
*/
bottle
.
patch
(
'/weight/:bottleId'
,
bottleCtrl
.
setMedicineWeight
);
/**
* 비어있는 약병에 전담의 등록
* request parameter : bottleId, doctorId
* url : http://localhost:4000/api/bottle/doctor/:bottleId
...
...
server/src/api/doctor/doctor.ctrl.js
View file @
4e9bd5d
...
...
@@ -13,7 +13,7 @@ const PrescribeInfo = require('../../models/prescribeInfo');
const
jwt
=
require
(
'jsonwebtoken'
);
const
{
uploadQrCode
,
viewQrCode
}
=
require
(
'../../util/GoogleCloudStorage'
);
const
{
uploadQrCode
,
getQrCodeUrl
}
=
require
(
'../../util/GoogleCloudStorage'
);
const
QrCodeUtil
=
require
(
'../../util/QrCodeUtil'
);
const
{
sendPushMessage
}
=
require
(
'../../util/FCM'
);
...
...
@@ -287,7 +287,7 @@ exports.writeReqPatientReport = async ctx => {
}
await
patientInfo
.
updateInfo
(
info
);
patientInfo
.
save
();
await
patientInfo
.
save
();
ctx
.
status
=
200
;
...
...
@@ -365,7 +365,7 @@ exports.writeReqBottleFeedback = async ctx => {
* @param {*} ctx
* @returns
*/
exports
.
searchPatientBy
Id
=
async
ctx
=>
{
exports
.
searchPatientBy
Contact
=
async
ctx
=>
{
const
token
=
ctx
.
req
.
headers
.
authorization
;
if
(
!
token
||
!
token
.
length
)
{
ctx
.
status
=
401
;
...
...
@@ -383,22 +383,19 @@ exports.searchPatientById = async ctx => {
return
;
}
const
{
patientId
}
=
ctx
.
params
;
const
patient
=
await
User
.
findByUserId
(
patientId
);
if
(
!
patient
||
patient
.
useYn
!==
'Y'
)
{
ctx
.
status
=
404
;
ctx
.
body
=
{
error
:
'존재하지 않는 회원'
,
};
return
;
}
const
{
contact
}
=
ctx
.
params
;
const
patientProfile
=
await
Profile
.
findOne
({
contact
,
useYn
:
'Y'
});
const
patientProfile
=
await
Profile
.
findOne
({
userId
:
patientId
});
const
patientInfo
=
{
userId
:
patientProfile
.
userId
,
userNm
:
patientProfile
.
userNm
,
birth
:
patientProfile
.
birth
,
contact
:
patientProfile
.
contact
,
};
ctx
.
status
=
200
;
ctx
.
body
=
{
patientNm
:
patientProfile
.
userNm
,
patientId
,
patientInfo
,
};
};
...
...
@@ -451,8 +448,8 @@ exports.registerNewPatient = async ctx => {
useYn
:
'W'
,
});
patientInfo
.
updateInfo
(
'환자 등록 요청'
);
patientInfo
.
save
();
await
patientInfo
.
updateInfo
(
'환자 등록 요청'
);
await
patientInfo
.
save
();
ctx
.
status
=
200
;
...
...
@@ -501,7 +498,7 @@ exports.removeReqPatient = async ctx => {
}
await
patientInfo
.
setUseYn
(
'N'
)
patientInfo
.
save
();
await
patientInfo
.
save
();
ctx
.
status
=
200
;
...
...
@@ -534,7 +531,8 @@ exports.prescribeMedicine = async ctx => {
const
{
patientId
,
medicineId
,
dosage
,
dailyDosage
,
totalDosage
,
}
=
ctx
.
request
.
body
;
...
...
@@ -551,9 +549,7 @@ exports.prescribeMedicine = async ctx => {
return
;
}
const
medicine
=
await
Medicine
.
findOne
({
medicineId
});
const
medicine
=
await
Medicine
.
findOne
({
medicineId
});
if
(
!
medicine
)
{
ctx
.
status
=
404
;
ctx
.
body
=
{
...
...
@@ -565,7 +561,8 @@ exports.prescribeMedicine = async ctx => {
const
qrCodeResult
=
await
QrCodeUtil
.
generateQrCode_prescribe
({
medicine
,
dosage
,
dailyDosage
,
totalDosage
,
patientId
,
doctorId
:
userId
,
});
...
...
@@ -589,19 +586,20 @@ exports.prescribeMedicine = async ctx => {
const
prescribeInfo
=
new
PrescribeInfo
({
doctorId
:
userId
,
patientId
,
dosage
,
dailyDosage
,
totalDosage
,
medicineId
,
qrCodeUrl
,
});
await
prescribeInfo
.
save
();
//특이사항에 처방기록 저장
patientInfo
.
updateInfo
(
`
${
medicine
.
name
}
, 하루
${
dosage
}
알
처방`
);
await
patientInfo
.
updateInfo
(
`
${
medicine
.
name
}
, 하루
${
dailyDosage
}
회분 처방, 총
${
totalDosage
}
회분
처방`
);
await
patientInfo
.
save
();
const
{
qrCodeFileName
}
=
qrCodeResult
;
const
qrCode
=
await
viewQrCode
({
qrCodeFileName
});
const
qrCode
=
await
getQrCodeUrl
({
qrCodeFileName
});
ctx
.
status
=
200
;
ctx
.
body
=
{
...
...
server/src/api/doctor/index.js
View file @
4e9bd5d
...
...
@@ -58,7 +58,7 @@ doctor.post('/bottle', doctorCtrl.writeReqBottleFeedback);
* url : http://localhost:4000/api/api/doctor/patient/search/:patientId
* return : patient Info(simple)
*/
doctor
.
get
(
'/patient/search/:
patientId'
,
doctorCtrl
.
searchPatientById
);
doctor
.
get
(
'/patient/search/:
contact'
,
doctorCtrl
.
searchPatientByContact
);
/**
* 현재 로그인한 유저(의사)의 관리 환자를 등록함.
...
...
server/src/api/hub/hub.ctrl.js
View file @
4e9bd5d
//허브(Mqtt Broker)등록 및 삭제
const
Hub
=
require
(
'../../models/hub'
);
const
Bottle
=
require
(
'../../models/bottle'
);
const
User
=
require
(
'../../models/user'
);
const
Mqtt
=
require
(
'../../util/MqttModule'
);
const
DataProcess
=
require
(
'../../util/DataProcess'
);
...
...
@@ -20,7 +21,7 @@ exports.hubConnect = async (ctx) => {
return
;
}
const
{
hubId
,
host
,
port
}
=
ctx
.
request
.
body
;
const
{
hubId
,
host
}
=
ctx
.
request
.
body
;
const
isExistHub
=
await
Hub
.
findByHubId
(
hubId
);
if
(
isExistHub
)
{
...
...
@@ -30,7 +31,7 @@ exports.hubConnect = async (ctx) => {
const
hosting
=
{
host
,
port
port
:
"1883"
,
};
Mqtt
.
mqttOn
(
hosting
,
DataProcess
.
dataPublish
);
...
...
@@ -104,6 +105,7 @@ exports.hubDisconnect = async(ctx) => {
const
hosting
=
await
hub
.
getHubHost
();
Mqtt
.
mqttOff
(
hosting
);
await
Bottle
.
deleteMany
({
hubId
});
await
Hub
.
deleteOne
({
hubId
});
ctx
.
status
=
204
;
...
...
server/src/api/manage/manage.ctrl.js
View file @
4e9bd5d
...
...
@@ -206,12 +206,12 @@ exports.acceptDoctorRegReq = async ctx => {
useYn
:
'W'
,
});
doctor
.
setUseYn
(
'Y'
);
doctor
.
save
();
await
doctor
.
setUseYn
(
'Y'
);
await
doctor
.
save
();
doctorInfo
.
setUseYn
(
'Y'
);
doctorInfo
.
setValidateDoctorLicense
(
validateDoctorLicense
);
doctorInfo
.
save
();
await
doctorInfo
.
setUseYn
(
'Y'
);
await
doctorInfo
.
setValidateDoctorLicense
(
validateDoctorLicense
);
await
doctorInfo
.
save
();
ctx
.
status
=
200
;
...
...
@@ -280,10 +280,10 @@ exports.acceptDoctorRegReq = async ctx => {
useYn
:
'W'
,
});
doctor
.
setUseYn
(
'N'
);
doctor
.
save
();
doctorInfo
.
setUseYn
(
'N'
);
doctorInfo
.
save
();
await
doctor
.
setUseYn
(
'N'
);
await
doctor
.
save
();
await
doctorInfo
.
setUseYn
(
'N'
);
await
doctorInfo
.
save
();
ctx
.
status
=
200
;
...
...
server/src/api/user/index.js
View file @
4e9bd5d
...
...
@@ -11,9 +11,18 @@ const user = new Router();
*/
user
.
get
(
'/'
,
userCtrl
.
getMyDetail
);
/**
* 현재
로그인한 유저에 등록된 의사 목록 가져옴
* 현재
유저 정보 수정
* request parameter : token
* url : http://localhost:4000/api/user
* return : Object User
*/
user
.
patch
(
'/'
,
userCtrl
.
updateMyDetail
);
/**
* 현재 로그인한 유저에 등록된 의사 목록 가져옴
* request parameter : userNm, birth, contact, password, passwordCheck
* url : http://localhost:4000/api/user/doctor
* return : Doctor List
*/
...
...
server/src/api/user/user.ctrl.js
View file @
4e9bd5d
...
...
@@ -38,10 +38,66 @@ exports.getMyDetail = async ctx => {
/**
* 내 정보를 업데이트한다.
* @param {*} ctx
* http methods : p
ost
* http methods : p
atch
*/
exports
.
updateMyInfo
=
async
ctx
=>
{
exports
.
updateMyDetail
=
async
ctx
=>
{
const
token
=
ctx
.
req
.
headers
.
authorization
;
if
(
!
token
||
!
token
.
length
)
{
ctx
.
status
=
401
;
return
;
}
// eslint-disable-next-line no-undef
const
{
userId
}
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
);
const
user
=
await
User
.
findByUserId
(
userId
);
if
(
!
user
||
user
.
useYn
!==
'Y'
||
user
.
userTypeCd
!==
'NORMAL'
)
{
ctx
.
status
=
403
;
return
;
}
const
profile
=
await
Profile
.
findByUserId
(
userId
);
if
(
!
profile
||
profile
.
useYn
!==
'Y'
)
{
ctx
.
status
=
403
;
return
;
}
const
{
userNm
,
birth
,
contact
,
password
,
passwordCheck
,
}
=
ctx
.
request
.
body
;
const
existContact
=
await
Profile
.
findOne
({
contact
,
useYn
:
'Y'
});
if
(
existContact
)
{
ctx
.
status
=
409
;
ctx
.
body
=
{
error
:
'이미 가입된 번호'
,
};
return
;
}
//passwordCheck가 있고 로컬 회원이라면 비밀번호 변경함
if
(
passwordCheck
&&
user
.
authTypeCd
===
'NORMAL'
)
{
//passwordCheck와 password가 같아야함
if
(
passwordCheck
!==
password
)
{
ctx
.
status
=
401
;
ctx
.
body
=
{
error
:
'비밀번호가 일치하지 않습니다.'
,
};
return
;
}
await
user
.
setPassword
(
password
);
await
user
.
save
();
}
await
profile
.
updateProfileInfo
({
userNm
,
birth
,
contact
,
});
await
profile
.
save
();
ctx
.
status
=
200
;
};
/**
...
...
@@ -76,7 +132,7 @@ exports.getMyDoctorList = async ctx => {
useYn
:
'Y'
,
});
return
doctorInfo
.
info
;
return
doctorInfo
?
doctorInfo
.
info
:
null
;
}));
ctx
.
status
=
200
;
...
...
@@ -156,9 +212,9 @@ exports.acceptDoctorRegister = async ctx => {
return
;
}
patientInfo
.
updateInfo
(
'환자 등록 요청 수락'
);
patientInfo
.
setUseYn
(
'Y'
);
patientInfo
.
save
();
await
patientInfo
.
updateInfo
(
'환자 등록 요청 수락'
);
await
patientInfo
.
setUseYn
(
'Y'
);
await
patientInfo
.
save
();
ctx
.
status
=
200
;
...
...
server/src/models/bottleMedicine.js
View file @
4e9bd5d
...
...
@@ -16,17 +16,26 @@ const BottleMedicineSchema = new Schema({
doctorId
:
{
type
:
String
,
ref
:
'User'
,
required
:
true
,
lowercase
:
true
,
},
dosage
:
{
dailyDosage
:
{
type
:
Number
,
default
:
1
,
},
totalDosage
:
{
type
:
Number
,
default
:
1
,
},
eachWeight
:
{
type
:
Number
,
default
:
0
,
},
totalWeight
:
{
type
:
Number
,
required
:
true
,
default
:
0
,
},
regDtm
:
{
type
:
Date
,
required
:
true
,
default
:
Date
.
now
,
},
useYn
:
{
...
...
@@ -40,6 +49,14 @@ BottleMedicineSchema.methods.setDoctorId = function(doctorId) {
this
.
doctorId
=
doctorId
;
};
BottleMedicineSchema
.
methods
.
setEachWeight
=
function
(
eachWeight
)
{
this
.
eachWeight
=
eachWeight
;
};
BottleMedicineSchema
.
methods
.
setTotalWeight
=
function
(
totalWeight
)
{
this
.
totalWeight
=
totalWeight
;
};
BottleMedicineSchema
.
methods
.
setUseYn
=
function
(
useYn
)
{
this
.
useYn
=
useYn
;
};
...
...
server/src/models/prescribeInfo.js
View file @
4e9bd5d
...
...
@@ -6,7 +6,8 @@ const PrescribeInfoSchema = new Schema({
doctorId
:
{
type
:
String
,
require
:
true
,
},
patientId
:
{
type
:
String
,
require
:
true
,
},
medicineId
:
{
type
:
Number
,
require
:
true
,
},
dosage
:
{
type
:
Number
,
require
:
true
,
},
dailyDosage
:
{
type
:
Number
,
require
:
true
,
},
totalDosage
:
{
type
:
Number
,
require
:
true
,
},
qrCodeUrl
:
{
type
:
String
,
require
:
true
,
},
});
...
...
server/src/models/profile.js
View file @
4e9bd5d
...
...
@@ -7,6 +7,7 @@ const ProfileSchema = new Schema({
userNm
:
{
type
:
String
,
required
:
true
,
},
birth
:
{
type
:
String
,
required
:
true
,
},
contact
:
{
type
:
String
,
required
:
true
,
},
useYn
:
{
type
:
String
,
default
:
'Y'
,
},
deviceToken
:
{
type
:
String
,
default
:
null
,
},
});
...
...
@@ -14,8 +15,14 @@ ProfileSchema.statics.findByUserId = function(userId) {
return
this
.
findOne
({
userId
});
};
ProfileSchema
.
methods
.
updateUserContact
=
function
(
contact
)
{
this
.
contact
=
contact
;
ProfileSchema
.
methods
.
setUseYn
=
function
(
useYn
)
{
this
.
useYn
=
useYn
;
};
ProfileSchema
.
methods
.
updateProfileInfo
=
function
({
userNm
,
birth
,
contact
})
{
if
(
userNm
)
{
this
.
userNm
=
userNm
}
if
(
birth
)
{
this
.
birth
=
birth
}
if
(
contact
)
{
this
.
contact
=
contact
}
};
ProfileSchema
.
methods
.
updateDeviceToken
=
function
(
deviceToken
)
{
...
...
server/src/models/takeMedicineHistory.js
View file @
4e9bd5d
...
...
@@ -5,7 +5,6 @@ const Schema = mongoose.Schema;
const
TakeMedicineHistorySchema
=
new
Schema
({
takeDate
:
{
type
:
Date
,
required
:
true
,
default
:
Date
.
now
,
},
bmId
:
{
...
...
@@ -15,7 +14,7 @@ const TakeMedicineHistorySchema = new Schema ({
},
temperature
:
{
type
:
Number
,
default
:
0
},
humidity
:
{
type
:
Number
,
default
:
0
},
balanc
e
:
{
type
:
Number
,
default
:
0
},
dosag
e
:
{
type
:
Number
,
default
:
0
},
});
...
...
server/src/util/DataProcess.js
View file @
4e9bd5d
...
...
@@ -16,66 +16,52 @@ exports.dataPublish = async (topic, message) => {
};
//Hub topic : bottle/bottleId
//Hub로부터 받은 message : 개폐여부/온도/습도/
초음파
센서
//Hub로부터 받은 message : 개폐여부/온도/습도/
무게
센서
const
factoring
=
async
(
topic
,
message
)
=>
{
const
bottleId
=
parseInt
(
topic
.
split
(
'/'
)[
1
]);
const
data
=
message
.
split
(
'/'
);
let
[
isOpen
,
temperature
,
humidity
,
balanc
e
]
=
data
;
const
[
isOpen
,
humidity
,
totalWeight
,
temperatur
e
]
=
data
;
if
(
isOpen
===
'1'
)
balance
=
await
balanceFactoring
(
balance
);
else
balance
=
'-1'
;
return
{
bottleId
,
isOpen
,
openDate
:
new
Date
(),
temperature
,
temperature
,
humidity
,
balance
totalWeight
,
};
}
const
balanceFactoring
=
(
balance
)
=>
{
const
max
=
10
;
//Digital Lead Sensor Maximum Value
const
slicingBalance
=
max
/
5
;
if
(
parseInt
(
balance
)
<
slicingBalance
||
parseInt
(
balance
)
>
max
*
2
)
return
'80'
;
else
if
(
parseInt
(
balance
)
<
slicingBalance
*
2
)
return
'60'
;
else
if
(
parseInt
(
balance
)
<
slicingBalance
*
3
)
return
'40'
;
else
if
(
parseInt
(
balance
)
<
slicingBalance
*
4
)
return
'20'
;
else
return
'0'
;
}
//bottleId가 포함된 data를 받아서 해당 약병의 data를 업데이트한다.
const
bottleInfoUpdate
=
async
(
data
)
=>
{
let
{
bottleId
,
isOpen
,
openDate
,
temperature
,
humidity
,
balance
}
=
data
;
let
{
bottleId
,
isOpen
,
temperature
,
humidity
,
totalWeight
}
=
data
;
bottleId
=
parseInt
(
bottleId
);
isOpen
=
parseInt
(
isOpen
);
temperature
=
parseFloat
(
temperature
);
humidity
=
parseFloat
(
humidity
);
balance
=
parseInt
(
balance
);
totalWeight
=
parseFloat
(
totalWeight
);
const
bottleMedicine
=
await
BottleMedicine
.
findOne
({
bottleId
,
useYn
:
'Y'
});
if
(
bottleMedicine
)
{
const
lastTotalWeight
=
parseFloat
(
bottleMedicine
.
totalWeight
);
if
(
isOpen
)
{
const
{
eachWeight
}
=
bottleMedicine
;
const
dosage
=
Math
.
round
((
lastTotalWeight
-
totalWeight
)
/
parseFloat
(
eachWeight
));
const
takeMedicineHist
=
new
TakeMedicineHist
({
takeDate
:
openDate
,
bmId
:
bottleMedicine
.
_id
,
temperature
,
humidity
,
balanc
e
,
dosag
e
,
});
await
takeMedicineHist
.
save
();
}
await
bottleMedicine
.
setTotalWeight
(
totalWeight
);
await
bottleMedicine
.
save
();
}
}
...
...
@@ -86,9 +72,9 @@ const transPublishingTopicAndMessage = async(bottleId) => {
const
bottleMedicine
=
await
BottleMedicine
.
findOne
({
bottleId
,
useYn
:
'Y'
});
const
takeMedicineHistList
=
await
TakeMedicineHist
.
find
({
bmId
:
bottleMedicine
.
_id
}).
sort
({
takeDate
:
'asc'
});
}).
sort
({
takeDate
:
'asc'
})
.
limit
(
1
)
;
const
message
=
'res/'
+
await
transDate
(
takeMedicineHistList
[
0
].
takeDate
)
+
'/'
+
bottleMedicine
.
dosage
;
const
message
=
'res/'
+
await
transDate
(
takeMedicineHistList
[
0
].
takeDate
)
+
'/'
+
takeMedicineHistList
[
0
]
.
dosage
;
return
{
topic
,
...
...
server/src/util/GoogleCloudStorage.js
View file @
4e9bd5d
...
...
@@ -57,7 +57,7 @@ exports.uploadQrCode = async ({ directory, qrCodeFileName }) => {
};
//생성된 QR코드의 signedUrl을 가져옴
exports
.
viewQrCode
=
async
({
qrCodeFileName
})
=>
{
exports
.
getQrCodeUrl
=
async
({
qrCodeFileName
})
=>
{
const
fileName
=
qrCodeFileName
;
const
file
=
storage
.
bucket
(
'prescribe-medicine-qrcode'
).
file
(
fileName
);
const
option
=
{
...
...
server/src/util/MqttModule.js
View file @
4e9bd5d
...
...
@@ -9,23 +9,23 @@ exports.mqttOn = async (hosting, foo) => {
})
if
(
filterIndex
===
-
1
)
{
const
client
=
mqtt
.
connect
(
hosting
)
clientList
.
push
(
client
)
const
client
=
mqtt
.
connect
(
hosting
)
;
clientList
.
push
(
client
)
;
client
.
on
(
'connect'
,
()
=>
{
console
.
log
(
'Hub connected: '
,
client
.
connected
)
})
})
;
client
.
on
(
'message'
,
async
(
topic
,
message
)
=>
{
const
result
=
await
foo
(
topic
,
message
.
toString
())
const
result
=
await
foo
(
topic
,
message
.
toString
())
;
console
.
log
(
'\x1b[1;32msubscribe : topic'
,
topic
,
'message : '
,
message
.
toString
(),
'\x1b[0m'
)
this
.
mqttPublishMessage
(
client
,
result
)
})
this
.
mqttPublishMessage
(
client
,
result
)
;
})
;
return
client
return
client
;
}
return
clientList
[
filterIndex
]
return
clientList
[
filterIndex
]
;
}
exports
.
mqttSubscribe
=
(
client
,
topic
)
=>
{
...
...
@@ -49,10 +49,10 @@ exports.mqttOff = (hosting) => {
return
(
client
.
options
.
clientId
===
hosting
.
clientId
&&
client
.
options
.
host
===
hosting
.
host
&&
client
.
options
.
port
===
hosting
.
port
)
})
})
;
if
(
filterIndex
!==
-
1
)
{
clientList
[
filterIndex
].
end
()
clientList
.
splice
(
filterIndex
,
1
)
clientList
[
filterIndex
].
end
()
;
clientList
.
splice
(
filterIndex
,
1
)
;
}
}
\ No newline at end of file
...
...
server/src/util/QrCodeUtil.js
View file @
4e9bd5d
...
...
@@ -2,17 +2,17 @@ const QrCode = require('qrcode');
const
moment
=
require
(
'moment'
);
exports
.
generateQrCode_prescribe
=
async
({
medicine
,
dosage
,
patientId
,
doctorId
})
=>
{
exports
.
generateQrCode_prescribe
=
async
({
medicine
,
d
ailyDosage
,
totalD
osage
,
patientId
,
doctorId
})
=>
{
// eslint-disable-next-line no-undef
const
directory
=
process
.
env
.
QR_DIR
;
const
now
=
moment
().
format
(
'YYYY-MM-DD_HH:mm'
);
const
qrCodeFileName
=
`
${
now
}
_
${
doctorId
}
_
${
patientId
}
_
${
medicine
.
medicineId
}
_
${
dosage
}
.png`
;
const
qrCodeFileName
=
`
${
now
}
_
${
doctorId
}
_
${
patientId
}
_
${
medicine
.
medicineId
}
_
${
d
ailyDosage
}
_
${
totalD
osage
}
.png`
;
try
{
await
QrCode
.
toFile
(
directory
+
'/'
+
qrCodeFileName
,
`
${
medicine
.
name
}
/
${
medicine
.
medicineId
}
/
${
dosage
}
/
${
patientId
}
/
${
doctorId
}
`
,
`
${
medicine
.
name
}
/
${
medicine
.
medicineId
}
/
${
d
ailyDosage
}
/
${
totalD
osage
}
/
${
patientId
}
/
${
doctorId
}
`
,
{
color
:
{
dark
:
'#337DFF'
,
...
...
Please
register
or
login
to post a comment