def getPatientFile(patientId): userId = None if session.has_key('userId'): userId = session['userId'] if userId is None: return redirect(LOGIN_URL) if patientId is None or patientId < 0: return jsonify(FAILURE) patient = Patient.get_patient_by_id(patientId) if patient is None or patient.userID != string.atoi(userId): return jsonify(FAILURE) pathologs = Pathology.getByPatientId(patientId) files = [] if pathologs and len(pathologs) > 0: for patholog in pathologs: files.extend(File.getFilebypathologyId(patholog.id), constant.FileType.FileAboutDiagnose) fileResults = None if len(files) > 0: fileResults = dataChangeService.getFilesResult(files) resultStatus = rs.ResultStatus(rs.SUCCESS.status, rs.SUCCESS.msg, fileResults) return jsonify(resultStatus.__dict__)
def get_pathology(): if 'pathologyId' in request.args.keys(): new_pathology = Pathology.getById(request.args['pathologyId']) if new_pathology is not None: pathologyDict = dataChangeService.get_pathology(new_pathology) result = rs.ResultStatus(rs.SUCCESS.status, rs.SUCCESS.msg, pathologyDict) return jsonify(result.__dict__, ensure_ascii=False) return jsonify(rs.SUCCESS.__dict__, ensure_ascii=False)
def pathlogy_list(): if 'patientId' in request.args.keys(): patientId = request.args['patientId'] pathlogys = Pathology.getByPatientId(patientId) if pathlogys is None or len(pathlogys) < 1: return jsonify(rs.SUCCESS.__dict__, ensure_ascii=False) pathlogysDict = dataChangeService.get_pathology_list(pathlogys) resultStatus = rs.ResultStatus(rs.SUCCESS.status, rs.SUCCESS.msg, pathlogysDict) return jsonify(resultStatus.__dict__, ensure_ascii=False) return jsonify(SUCCESS.__dict__)
def getPatientFile(patientId): userId=None if session.has_key('userId'): userId=session['userId'] if userId is None: redirect(LOGIN_URL) if patientId is None or patientId<0 : return jsonify(FAILURE) patient=Patient.get_patient_by_id(patientId) if patient is None or patient.userID!=string.atoi(userId): return jsonify(FAILURE) pathologs=Pathology.getByPatientId(patientId) files=[] if pathologs and len(pathologs)>0: for patholog in pathologs: files.extend(File.getFilebypathologyId(patholog.id),constant.FileType.FileAboutDiagnose) fileResults=None if len(files)>0: fileResults=dataChangeService.getFilesResult(files) resultStatus = rs.ResultStatus(rs.SUCCESS.status, rs.SUCCESS.msg, fileResults) return jsonify(resultStatus.__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__)