def applyDiagnose(): if session.has_key('userId'): userId = session['userId'] if userId is None: return redirect('/loginPage') data = {} hospitals = Hospital.getAllHospitals(db_session) hospitalsDict = object2dict.objects2dicts(hospitals) data['hospitals'] = hospitalsDict positions = Position.getPositions() positionsDict = object2dict.objects2dicts(positions) data['positions'] = positionsDict locations = Location.getAllLocations(db_session) locationsDict = object2dict.objects2dicts(locations) data['locations'] = locationsDict #hospital user if 'type' in request.args.keys(): data['type'] = int(request.args.get('type')) if 'edit' in request.args.keys() and 'diagnoseid' in request.args.keys(): new_diagnose = Diagnose.getDiagnoseById(request.args['diagnoseid']) data['edit'] = 1 else: new_diagnose = Diagnose.getNewDiagnoseByStatus(ModelStatus.Draft, session['userId']) if new_diagnose is not None: data['doctor'] = new_diagnose.doctor data['patient'] = new_diagnose.patient data['pathology'] = new_diagnose.pathology new_file = File.getFiles(new_diagnose.pathologyId, constant.FileType.Dicom) data['dicomfile'] = new_file new_files = File.getFiles(new_diagnose.pathologyId, constant.FileType.FileAboutDiagnose) data['fileAboutDiagnose'] = new_files pathologyPositions = [] if hasattr(new_diagnose, 'pathology') and hasattr( new_diagnose.pathology, 'pathologyPostions'): pathologyPositions = object2dict.objects2dicts( new_diagnose.pathology.pathologyPostions) data['pathologyPositions'] = pathologyPositions patients = Patient.get_patient_by_user(session['userId']) if patients is None or len(patients) < 1: patientdict = [] else: patientdict = object2dict.objects2dicts(patients) data['patientdict'] = patientdict return render_template("applyDiagnose.html", result=data)
def applyDiagnose(): if session.has_key('userId'): userId=session['userId'] if userId is None: return redirect('/loginPage') data = {} hospitals = Hospital.getAllHospitals(db_session) hospitalsDict = object2dict.objects2dicts(hospitals) data['hospitals'] = hospitalsDict positions = Position.getPositions() positionsDict = object2dict.objects2dicts(positions) data['positions'] = positionsDict locations = Location.getAllLocations(db_session) locationsDict = object2dict.objects2dicts(locations) data['locations'] = locationsDict if 'edit' in request.args.keys() and 'diagnoseid' in request.args.keys(): new_diagnose = Diagnose.getDiagnoseById(request.args['diagnoseid']) data['edit'] = 1 else: new_diagnose = Diagnose.getNewDiagnoseByStatus(ModelStatus.Draft, session['userId']) if new_diagnose is not None: data['doctor'] = new_diagnose.doctor data['patient'] = new_diagnose.patient data['pathology'] = new_diagnose.pathology new_file = File.getFiles(new_diagnose.pathologyId, constant.FileType.Dicom) data['dicomfile'] = new_file new_files = File.getFiles(new_diagnose.pathologyId, constant.FileType.FileAboutDiagnose) data['fileAboutDiagnose'] = new_files pathologyPositions = [] if hasattr(new_diagnose, 'pathology') and hasattr(new_diagnose.pathology, 'pathologyPostions'): pathologyPositions = object2dict.objects2dicts(new_diagnose.pathology.pathologyPostions) data['pathologyPositions'] = pathologyPositions patients = Patient.get_patient_by_user(session['userId']) if patients is None or len(patients) < 1: patientdict = [] else: patientdict = object2dict.objects2dicts(patients) data['patientdict'] = patientdict return render_template("applyDiagnose.html", result=data)
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__)