def test_addKefu(self): user=User('kefu','77777777777','123456') user.sex=0 user.status=0 user.email='*****@*****.**' user.address='四川省 通江县' user.phone = '77777777777' user.type = UserStatus.doctor user.name = "客服人员" User.save(user) new_userrole2 = UserRole(user.id, RoleId.Kefu) UserRole.save(new_userrole2)
def test_addFenzhen(self): user=User('fenzhen','13426026573','123456') user.sex=0 user.status=0 user.email='*****@*****.**' user.address='四川省 通江县' user.phone = '13426026573' user.type = UserStatus.doctor user.name = "分诊医生" User.save(user) new_userrole2 = UserRole(user.id, RoleId.Admin) UserRole.save(new_userrole2)
def test_addPatient(self): user=User('liclu','15210892443','123456') user.sex=0 user.status=0 user.email='*****@*****.**' user.address='四川省 通江县' user.phone = '15210892443' User.save(user) patient=Patient() patient.gender=0 patient.Name='程成' patient.status=0 patient.userID=user.id Patient.save(patient) new_userrole = UserRole(user.id, RoleId.Patient) UserRole.save(new_userrole)
def test_addSuperUser(self): user=User('zhoufan','13426026573','123456') user.sex=0 user.status=0 user.email='*****@*****.**' user.address='四川省 通江县' user.phone = '13426026573' user.type = UserStatus.doctor user.name = "张西" User.save(user) patient=Patient() patient.gender=0 patient.Name='zf' patient.status=0 patient.userID=user.id Patient.save(patient) new_userrole = UserRole(user.id, RoleId.Patient) UserRole.save(new_userrole) new_doctor_1 = Doctor(user.id) new_doctor_1.identityPhone = "029-12345567" new_doctor_1.username = "******" new_doctor_1.diagnoseCount = 10 new_doctor_1.feedbackCount = 5 new_doctor_1.goodFeedbackCount = 5 new_doctor_1.hospitalId = 1 new_doctor_1.departmentId = 1 new_doctor_1.title = "副主任医师" new_doctor_1.status = 0 Doctor.save(new_doctor_1) new_doctor2skill_1_1 = Doctor2Skill(new_doctor_1.id,1) Doctor2Skill.save(new_doctor2skill_1_1) new_userrole1 = UserRole(user.id, RoleId.Doctor) UserRole.save(new_userrole1) new_userrole2 = UserRole(user.id, RoleId.Admin) UserRole.save(new_userrole2)
def register_doctor(): form = RegisterFormDoctor(request.form) form_result = form.validate() if form_result.status == rs.SUCCESS.status: new_user = User(form.real_name, form.username, form.password) new_user.email = form.email new_user.phone = form.cellphone new_user.type = UserStatus.doctor new_user.status = ModelStatus.Draft User.save(new_user) new_doctor = Doctor(new_user.id) new_doctor.username = form.real_name new_doctor.identityPhone = form.identity_phone Doctor.save(new_doctor) new_doctor2skill = Doctor2Skill(new_doctor.id, 1) Doctor2Skill.save(new_doctor2skill) new_userrole = UserRole(new_user.id, RoleId.Doctor) UserRole.save(new_userrole) return jsonify(form_result.__dict__)
def applyDiagnoseForm(formid): if (int(formid) == 1) : form = DiagnoseForm3(request.form) form_result = form.validate() if form_result.status == rs.SUCCESS.status: if(form.diagnoseId): new_diagnose = Diagnose.getDiagnoseById(form.diagnoseId) else: new_diagnose = Diagnose.getNewDiagnoseByStatus(DiagnoseStatus.Draft, session['userId']) if(new_diagnose is None): new_diagnose = Diagnose() new_diagnose.status = DiagnoseStatus.Draft new_diagnose.doctorId = form.doctorId new_diagnose.uploadUserId = session['userId'] Diagnose.save(new_diagnose) form_result.data = {'formId': 2, 'diagnoseId': new_diagnose.id} return jsonify(form_result.__dict__) elif (int(formid) == 2) : form = DiagnoseForm1(request.form) form_result = form.validate() if form_result.status == rs.SUCCESS.status: if form.diagnoseId is not None: new_diagnose = Diagnose.getDiagnoseById(form.diagnoseId) else: new_diagnose = Diagnose.getNewDiagnoseByStatus(DiagnoseStatus.Draft, int(session['userId'])) if(new_diagnose is not None): # 去拿没有draft的用户 if(form.exist): new_patient = Patient.get_patient_by_id(form.patientid) else: new_patient = Patient.get_patient_draft(new_diagnose.patientId) if new_patient is None: new_patient = Patient() new_patient.type = PatientStatus.diagnose new_patient.userID = session['userId'] new_patient.realname = form.patientname new_patient.gender = form.patientsex new_patient.birthDate = datetime.strptime(form.birthdate, "%Y-%m-%d") new_patient.identityCode = form.identitynumber new_patient.locationId = form.locationId new_patient.identityPhone = form.phonenumber new_patient.status = ModelStatus.Draft # new_patient.locationId = form.location Patient.save(new_patient) new_diagnose.patientId = new_patient.id Diagnose.save(new_diagnose) # Hospital User 注册用户 if(form.isHospitalUser): new_user = User(form.phonenumber, random.sample('zyxwvutsrqponmlkjihgfedcba1234567890',6), False) new_user.type = UserStatus.patent new_user.status = ModelStatus.Draft User.save(new_user) new_patient.userID = new_user.id Patient.save(new_patient) new_userrole = UserRole(new_user.id, RoleId.Patient) UserRole.save(new_userrole) form_result.data = {'formId': 3, } else: form_result = ResultStatus(FAILURE.status, "找不到第一步草稿") return jsonify(form_result.__dict__) elif (int(formid) == 3): form = DiagnoseForm2(request.form) form_result = form.validate() if form_result.status == rs.SUCCESS.status: if form.diagnoseId is not None: new_diagnose = Diagnose.getDiagnoseById(form.diagnoseId) else: new_diagnose = Diagnose.getNewDiagnoseByStatus(DiagnoseStatus.Draft, int(session['userId'])) if new_diagnose is not None: if form.exist: new_pathology = Pathology.getById(form.pathologyId) elif new_diagnose.pathologyId: new_pathology = Pathology.getById(new_diagnose.pathologyId) else: new_pathology = Pathology.getByPatientStatus(session['userId'], ModelStatus.Draft) if new_pathology is None: new_pathology = Pathology(new_diagnose.patientId) new_pathology.diagnoseMethod = form.dicomtype new_pathology.status = ModelStatus.Draft new_pathology.save(new_pathology) PathologyPostion.deleteByPathologyId(new_pathology.id) for position in form.patientlocation: new_position_id = PathologyPostion(new_pathology.id, position) PathologyPostion.save(new_position_id) File.cleanDirtyFile(form.fileurl, new_pathology.id, FileType.Dicom) for fileurl in form.fileurl: new_file = File.getFilebyId(int(fileurl)) new_file.pathologyId = new_pathology.id File.save(new_file) new_diagnose.pathologyId = new_pathology.id Diagnose.save(new_diagnose) form_result.data = {'formId': 4} else: form_result = ResultStatus(FAILURE.status, "找不到上步的草稿") return jsonify(form_result.__dict__) elif (int(formid) == 4): form = DiagnoseForm4(request.form) form_result = form.validate() if form_result.status == rs.SUCCESS.status: if form.diagnoseId is not None: new_diagnose = Diagnose.getDiagnoseById(form.diagnoseId) else: new_diagnose = Diagnose.getNewDiagnoseByStatus(DiagnoseStatus.Draft, int(session['userId'])) if(new_diagnose is not None): new_pathology = Pathology.getById(new_diagnose.pathologyId) if(new_pathology is not None): new_pathology.caseHistory = form.illnessHistory new_pathology.hospitalId = form.hospitalId new_pathology.status = ModelStatus.Normal Pathology.save(new_pathology) File.cleanDirtyFile(form.fileurl, new_pathology.id, FileType.FileAboutDiagnose) for fileurl in form.fileurl: new_file = File.getFilebyId(int(fileurl)) new_file.pathologyId = new_pathology.id File.save(new_file) new_patient = Patient.get_patient_by_id(new_diagnose.patientId) new_patient.status = PatientStatus.diagnose new_diagnose.status = DiagnoseStatus.NeedPay Diagnose.save(new_diagnose) new_diagnoselog = DiagnoseLog(new_diagnose.uploadUserId, new_diagnose.id, DiagnoseLogAction.NewDiagnoseAction) DiagnoseLog.save(db_session, new_diagnoselog) else: form_result = ResultStatus(FAILURE.status, "找不到上步的草稿1") else: form_result = ResultStatus(FAILURE.status, "找不到上步的草稿2") form_result.data = {'isFinal': True} return jsonify(form_result.__dict__) else: return jsonify(ResultStatus(FAILURE.status, "错误的表单号").__dict__)
def applyDiagnoseForm(formid): if (int(formid) == 1): form = DiagnoseForm3(request.form) form_result = form.validate() if form_result.status == rs.SUCCESS.status: if (form.diagnoseId): new_diagnose = Diagnose.getDiagnoseById(form.diagnoseId) else: new_diagnose = Diagnose.getNewDiagnoseByStatus( DiagnoseStatus.Draft, session['userId']) if (new_diagnose is None): new_diagnose = Diagnose() new_diagnose.status = DiagnoseStatus.Draft new_diagnose.doctorId = form.doctorId new_diagnose.uploadUserId = session['userId'] Diagnose.save(new_diagnose) form_result.data = {'formId': 2, 'diagnoseId': new_diagnose.id} return jsonify(form_result.__dict__) elif (int(formid) == 2): form = DiagnoseForm1(request.form) form_result = form.validate() if form_result.status == rs.SUCCESS.status: if form.diagnoseId is not None: new_diagnose = Diagnose.getDiagnoseById(form.diagnoseId) else: new_diagnose = Diagnose.getNewDiagnoseByStatus( DiagnoseStatus.Draft, int(session['userId'])) if (new_diagnose is not None): needcreateNewUserByHospitalUser = True # 去拿没有draft的用户 if (form.exist): #select exist patient , from list, when modify exist diagnose new_patient = Patient.get_patient_by_id(form.patientid) else: #update draft patient when modify exist diagnose new_patient = Patient.getPatientDraftByPatienId( new_diagnose.patientId) if new_patient: new_patient.realname = form.patientname new_patient.gender = form.patientsex new_patient.birthDate = datetime.strptime( form.birthdate, "%Y-%m-%d") new_patient.identityCode = form.identitynumber new_patient.locationId = form.locationId new_patient.identityPhone = form.phonenumber Patient.save(new_patient) needcreateNewUserByHospitalUser = False #create a new patient if new_patient is None: new_patient = Patient() new_patient.type = PatientStatus.diagnose new_patient.userID = session['userId'] new_patient.realname = form.patientname new_patient.gender = form.patientsex new_patient.birthDate = datetime.strptime( form.birthdate, "%Y-%m-%d") new_patient.identityCode = form.identitynumber new_patient.locationId = form.locationId new_patient.identityPhone = form.phonenumber new_patient.status = ModelStatus.Draft # new_patient.locationId = form.location Patient.save(new_patient) new_diagnose.patientId = new_patient.id Diagnose.save(new_diagnose) # Hospital User 注册用户 if form.isHospitalUser and ( not form.exist) and needcreateNewUserByHospitalUser: userQuery = User.getByPhone(form.phonenumber) if userQuery.count() <= 0: passwd = random.sample( 'zyxwvutsrqponmlkjihgfedcba1234567890', 6) passwd = ''.join(passwd) new_user = User(form.patientname, form.phonenumber, passwd, True) new_user.type = UserStatus.patent new_user.status = ModelStatus.Normal User.save(new_user) new_patient.userID = new_user.id Patient.save(new_patient) new_userrole = UserRole(new_user.id, RoleId.Patient) UserRole.save(new_userrole) sendRegisterMobileMessage(session.get('userId'), new_diagnose, new_user.phone, passwd) else: new_patient.userID = userQuery.first().id Patient.save(new_patient) form_result.data = { 'formId': 3, } else: form_result = ResultStatus(FAILURE.status, "找不到第一步草稿") return jsonify(form_result.__dict__) elif (int(formid) == 3): form = DiagnoseForm2(request.form) form_result = form.validate() if form_result.status == rs.SUCCESS.status: if form.diagnoseId is not None: new_diagnose = Diagnose.getDiagnoseById(form.diagnoseId) else: new_diagnose = Diagnose.getNewDiagnoseByStatus( DiagnoseStatus.Draft, int(session['userId'])) if new_diagnose is not None: #直接选择的病例,不是新建或者更改 isExistingPathology = False if form.exist: new_pathology = Pathology.getById(form.pathologyId) isExistingPathology = True elif new_diagnose.pathologyId: new_pathology = Pathology.getById(new_diagnose.pathologyId) else: new_pathology = Pathology.getByPatientStatus( session['userId'], ModelStatus.Draft) if new_pathology is None: new_pathology = Pathology(new_diagnose.patientId) if not isExistingPathology: new_pathology.diagnoseMethod = form.dicomtype new_pathology.status = ModelStatus.Draft new_pathology.save(new_pathology) PathologyPostion.deleteByPathologyId(new_pathology.id) for position in form.patientlocation: new_position_id = PathologyPostion( new_pathology.id, position) PathologyPostion.save(new_position_id) File.cleanDirtyFile(form.fileurl, new_pathology.id, FileType.Dicom) if form.fileurl and len(form.fileurl) > 0: for fileurl in form.fileurl: new_file = File.getFilebyId(int(fileurl)) new_file.pathologyId = new_pathology.id File.save(new_file) new_diagnose.pathologyId = new_pathology.id Diagnose.save(new_diagnose) form_result.data = {'formId': 4} else: form_result = ResultStatus(FAILURE.status, "找不到上步的草稿") return jsonify(form_result.__dict__) elif (int(formid) == 4): form = DiagnoseForm4(request.form) form_result = form.validate() if form_result.status == rs.SUCCESS.status: if form.diagnoseId is not None: new_diagnose = Diagnose.getDiagnoseById(form.diagnoseId) else: new_diagnose = Diagnose.getNewDiagnoseByStatus( DiagnoseStatus.Draft, int(session['userId'])) if (new_diagnose is not None): new_pathology = Pathology.getById(new_diagnose.pathologyId) if (new_pathology is not None): new_pathology.caseHistory = form.illnessHistory new_pathology.hospitalId = form.hospitalId new_pathology.status = ModelStatus.Normal Pathology.save(new_pathology) File.cleanDirtyFile(form.fileurl, new_pathology.id, FileType.FileAboutDiagnose) if form.fileurl and len(form.fileurl) > 0: for fileurl in form.fileurl: new_file = File.getFilebyId(int(fileurl)) new_file.pathologyId = new_pathology.id File.save(new_file) new_patient = Patient.get_patient_by_id( new_diagnose.patientId) new_patient.status = PatientStatus.diagnose #add for need update scenario if new_diagnose.status == constant.DiagnoseStatus.NeedUpdate: new_diagnoselog = DiagnoseLog( new_diagnose.uploadUserId, new_diagnose.id, DiagnoseLogAction.DiagnoseNeedUpateRecommitAction) DiagnoseLog.save(db_session, new_diagnoselog) new_diagnose.status = DiagnoseStatus.Triaging Diagnose.save(new_diagnose) #hospitalUser type=1 else: if form.type == '1' and not checkFilesExisting( new_diagnose): new_diagnoselog = DiagnoseLog( new_diagnose.uploadUserId, new_diagnose.id, DiagnoseLogAction.NewDiagnoseAction) DiagnoseLog.save(db_session, new_diagnoselog) #update by lichuan , save diagnose and change to needPay new_diagnose.status = DiagnoseStatus.HospitalUserDiagnoseNeedCommit Diagnose.save(new_diagnose) #end update else: #产生alipay,发送短消息 userId = session.get('userId') new_diagnose.ossUploaded = constant.DiagnoseUploaed.Uploaded new_diagnose.status = DiagnoseStatus.NeedPay Diagnose.save(new_diagnose) sendAllMessage(userId, new_diagnose) else: form_result = ResultStatus(FAILURE.status, "找不到上步的草稿1") else: form_result = ResultStatus(FAILURE.status, "找不到上步的草稿2") form_result.data = {'isFinal': True} return jsonify(form_result.__dict__) else: return jsonify(ResultStatus(FAILURE.status, "错误的表单号").__dict__)