patientInfo.js
1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const mongoose = require('mongoose');
const moment = require('moment');
const Schema = mongoose.Schema;
const PatientInfoSchema = new Schema({
patientId : { type : String, required : true, ref : 'User', },
doctorId : { type : String, required : true, ref : 'User', },
info : { type : String, required : true, },
useYn : { type : String, required : true, default : 'W', },
});
PatientInfoSchema.statics.findAllByPatientIdAndUseYn = function(patientId, useYn) {
return this.find({ patientId, useYn });
};
PatientInfoSchema.statics.findAllByDoctorIdAndUseYn = function(doctorId, useYn) {
return this.find({ doctorId, useYn });
};
PatientInfoSchema.statics.findByPatientIdAndDoctorId = function(patientId, doctorId) {
return this.findOne({ patientId, doctorId });
};
PatientInfoSchema.statics.findByPatientIdAndDoctorIdAndUseYn = function(patientId, doctorId, useYn) {
return this.findOne({ patientId, doctorId, useYn });
};
PatientInfoSchema.methods.getInfo = function() {
return this.info;
};
PatientInfoSchema.methods.setUseYn = function(useYn) {
this.useYn = useYn;
};
PatientInfoSchema.methods.updateInfo = function(info) {
const date = moment(new Date()).format('YYYY-MM-DD hh:mm');
if(this.info.length)
this.info = this.info.concat('\n\n', `${date} => ${info}`);
else
this.info = `${date} => ${info}`;
};
module.exports = mongoose.model('PatientInfo', PatientInfoSchema);