コード例 #1
0
ファイル: diagnose.py プロジェクト: LichuanLu/blueberry
def fetchDiagnoseByAdmin():

    diagnoseId=request.form.get('diagnoseId')
    userId=session['userId']


    # if diagnoseId is None :
    #     return  json.dumps(rs.PARAM_ERROR.__dict__,ensure_ascii=False)
    #
    # user=User.getById(userId)
    # if user is None:
    #     return  json.dumps(rs.NO_DATA.__dict__,ensure_ascii=False)
    #
    # from database import db_session
    # if UserRole.checkRole(db_session,userId,constant.RoleId.Admin):
    #     result=Diagnose.addAdminIdAndChangeStatus(diagnoseId,userId)
    #     #诊断日志
    #     diagoseLog=DiagnoseLog(userId,diagnoseId,constant.DiagnoseLogAction.FetchDiagnoseAction)
    #     DiagnoseLog.save(db_session,diagoseLog)
    #
    #     return json.dumps(rs.SUCCESS.__dict__,ensure_ascii=False)
    # else:
    #     return json.dumps(rs.PERMISSION_DENY.__dict__,ensure_ascii=False)



    result=Diagnose.addAdminIdAndChangeStatus(diagnoseId,userId)
    #诊断日志
    if result:
        diagoseLog=DiagnoseLog(userId,diagnoseId,constant.DiagnoseLogAction.FetchDiagnoseAction)
        DiagnoseLog.save(db_session,diagoseLog)

        return json.dumps(rs.SUCCESS.__dict__,ensure_ascii=False)
    return json.dumps(rs.FAILURE.__dict__,ensure_ascii=False)
コード例 #2
0
ファイル: diagnose.py プロジェクト: LichuanLu/redberry
def evaluateDiagnose(diagnoseId):
    userId = session['uesrId']
    if userId is None:
        return json.dumps(rs.NO_LOGIN.__dict__, ensure_ascii=False)
    userId = string.atoi(userId)

    score = request.args.get('score')
    description = request.args.get('description')
    if score:
        score = string.atoi(score)
    else:
        return json.dumps(rs.PARAM_ERROR.__dict__, ensure_ascii=False)

    diagnose = Diagnose.getDiagnoseById(diagnoseId)
    if diagnose is None:
        return json.dumps(rs.NO_DATA.__dict__, ensure_ascii=False)
    if hasattr(
            diagnose, 'patient'
    ) and diagnose.patient and diagnose.patient.userID and diagnose.patient.userID == userId:
        diagnose.status = constant.DiagnoseStatus.Diagnosed
        diagnose.score = score
        Diagnose.save(diagnose)

        diagoseLog = DiagnoseLog(userId, diagnoseId,
                                 constant.DiagnoseLogAction.DiagnoseFinished)
        diagoseLog.description = description
        DiagnoseLog.save(db_session, diagoseLog)
        return json.dumps(rs.SUCCESS.__dict__, ensure_ascii=False)
    else:
        return json.dumps(rs.PERMISSION_DENY.__dict__, ensure_ascii=False)
コード例 #3
0
ファイル: diagnose.py プロジェクト: LichuanLu/blueberry
def rollbackDiagnose(diagnoseId):
    userId=session['userId']
    if userId is None:
        return json.dumps(rs.NO_LOGIN.__dict__,ensure_ascii=False)
    userId=string.atoi(userId)

    status=request.form.get('status')
    comments=request.form.get('comments')
    if status:
        status=string.atoi(status)
    diagnose=Diagnose.getDiagnoseById(diagnoseId)
    if diagnose is None:
        return  json.dumps(rs.NO_DATA.__dict__,ensure_ascii=False)
    if hasattr(diagnose,'adminId') and diagnose.adminId and  diagnose.adminId==userId:
        if status is None:
            status=constant.DiagnoseStatus.Draft
        diagnose.status=status
        Diagnose.save(diagnose)

        diagoseLog=DiagnoseLog(userId,diagnoseId,constant.DiagnoseLogAction.DiagnoseNeedUpateAction)
        diagoseLog.description=comments
        DiagnoseLog.save(db_session,diagoseLog)

        if hasattr(diagnose,'patient') and diagnose.patient.userID:
            content=dataChangeService.getPatienDiagnoseMessageContent(diagnose)

            #诊断通知
            message=Message(constant.DefaultSystemAdminUserId,diagnose.patient.userID,'诊断通知',content,constant.MessageType.Diagnose)
            Message.save(message)

        return  json.dumps(rs.SUCCESS.__dict__,ensure_ascii=False)
    else:
        return  json.dumps(rs.PERMISSION_DENY.__dict__,ensure_ascii=False)
コード例 #4
0
ファイル: diagnose.py プロジェクト: LichuanLu/redberry
def fetchDiagnoseByAdmin():

    diagnoseId = request.form.get('diagnoseId')
    userId = session['userId']

    # if diagnoseId is None :
    #     return  json.dumps(rs.PARAM_ERROR.__dict__,ensure_ascii=False)
    #
    # user=User.getById(userId)
    # if user is None:
    #     return  json.dumps(rs.NO_DATA.__dict__,ensure_ascii=False)
    #
    # from database import db_session
    # if UserRole.checkRole(db_session,userId,constant.RoleId.Admin):
    #     result=Diagnose.addAdminIdAndChangeStatus(diagnoseId,userId)
    #     #诊断日志
    #     diagoseLog=DiagnoseLog(userId,diagnoseId,constant.DiagnoseLogAction.FetchDiagnoseAction)
    #     DiagnoseLog.save(db_session,diagoseLog)
    #
    #     return json.dumps(rs.SUCCESS.__dict__,ensure_ascii=False)
    # else:
    #     return json.dumps(rs.PERMISSION_DENY.__dict__,ensure_ascii=False)

    result = Diagnose.addAdminIdAndChangeStatus(diagnoseId, userId)
    #诊断日志
    if result:
        diagoseLog = DiagnoseLog(
            userId, diagnoseId, constant.DiagnoseLogAction.FetchDiagnoseAction)
        DiagnoseLog.save(db_session, diagoseLog)

        return json.dumps(rs.SUCCESS.__dict__, ensure_ascii=False)
    return json.dumps(rs.FAILURE.__dict__, ensure_ascii=False)
コード例 #5
0
ファイル: diagnose.py プロジェクト: LichuanLu/blueberry
def evaluateDiagnose(diagnoseId):
    userId=session['uesrId']
    if userId is None:
        return json.dumps(rs.NO_LOGIN.__dict__,ensure_ascii=False)
    userId=string.atoi(userId)

    score=request.args.get('score')
    description=request.args.get('description')
    if score:
        score=string.atoi(score)
    else:
        return  json.dumps(rs.PARAM_ERROR.__dict__,ensure_ascii=False)

    diagnose=Diagnose.getDiagnoseById(diagnoseId)
    if diagnose is None:
        return  json.dumps(rs.NO_DATA.__dict__,ensure_ascii=False)
    if hasattr(diagnose,'patient') and diagnose.patient and diagnose.patient.userID and  diagnose.patient.userID==userId:
        diagnose.status=constant.DiagnoseStatus.Diagnosed
        diagnose.score=score
        Diagnose.save(diagnose)

        diagoseLog=DiagnoseLog(userId,diagnoseId,constant.DiagnoseLogAction.DiagnoseFinished)
        diagoseLog.description=description
        DiagnoseLog.save(db_session,diagoseLog)
        return  json.dumps(rs.SUCCESS.__dict__,ensure_ascii=False)
    else:
        return  json.dumps(rs.PERMISSION_DENY.__dict__,ensure_ascii=False)
コード例 #6
0
ファイル: diagnose.py プロジェクト: LichuanLu/blueberry
def sendMessageAndRecordLog(diagnose,userId):
    if diagnose and hasattr(diagnose,'patient') and diagnose.patient.userID:
        userId=diagnose.patient.userID
        content=dataChangeService.getPatienDiagnoseMessageContent(diagnose)
        message=Message(constant.DefaultSystemAdminUserId,diagnose.patient.userID,'诊断通知',content,constant.MessageType.Diagnose)
        Message.save(message)

    diagnoseLog=DiagnoseLog(userId,diagnose.id,constant.DiagnoseLogAction.DiagnoseFinished)
    DiagnoseLog.save(db_session,diagnoseLog)
コード例 #7
0
ファイル: front.py プロジェクト: LichuanLu/redberry
def sendRegisterMobileMessage(userId, diagnose, phoneNumber, passwd):
    if userId and diagnose:
        new_diagnoselog = DiagnoseLog(userId, diagnose.id,
                                      DiagnoseLogAction.SendMessageToUser)
        DiagnoseLog.save(db_session, new_diagnoselog)
    if phoneNumber:
        smsRc = sms_utils.RandCode()
        template_param = {'param1': passwd}
        smsRc.send_emp_sms(phoneNumber, smsRc.TEMPLATE_REGISTER,
                           json.dumps(template_param))
コード例 #8
0
ファイル: diagnose.py プロジェクト: LichuanLu/blueberry
def addOrUpdateReport():

    userId=session['userId']
    user=User.getById(userId)


    if user is None  :
        return  json.dumps(rs.NO_DATA.__dict__,ensure_ascii=False)
    #权限查看
    if  UserRole.checkRole(db_session,userId,constant.RoleId.Admin) == False:
        return  json.dumps(rs.PERMISSION_DENY.__dict__,ensure_ascii=False)

    form =  ReportForm(request.form)
    formResult=form.validate()
    if formResult.status==rs.SUCCESS.status:
        diagnose=Diagnose.getDiagnoseById(form.diagnoseId)
        if diagnose is None:
            return  json.dumps(rs.NO_DATA.__dict__,ensure_ascii=False)
        #session['remember_me'] = form.remember_me.data
        # login and validate the user...
        report = None
        if form.reportId:
            report=Report.getReportById(form.reportId)
            if report.type==constant.ReportType.Doctor:
                return  json.dumps(rs.PERMISSION_DENY.__dict__,ensure_ascii=False)
            Report.update(form.reportId,None,form.status,None,form.techDesc,form.imageDesc,form.diagnoseDesc)
        else:
            report=Report(form.techDesc,form.imageDesc,form.diagnoseDesc,form.fileUrl,ReportType.Admin,form.status)
            Report.save(report)

            diagnose.reportId=report.id
            Diagnose.save(diagnose)
        #flash('成功添加诊断评论')
        if form.status and form.status == constant.ReportStatus.Commited:
            diagnose=Diagnose.getDiagnoseById(form.diagnoseId)
            if diagnose:
                Diagnose.changeDiagnoseStatus(diagnose.id,constant.DiagnoseStatus.NeedDiagnose)
            if form.reportId is None and report:
                form.reportId = report.id
            Report.update(form.reportId,constant.ReportType.Doctor,status=constant.ReportStatus.Draft)
            if diagnose and hasattr(diagnose,'doctor'):
                doctor=diagnose.doctor
                if doctor and doctor.userId:
                    content=dataChangeService.getDoctorNeedDiagnoseMessageContent(diagnose,doctor)

                    #诊断通知
                    message=Message(constant.DefaultSystemAdminUserId,doctor.userId,'诊断通知',content,constant.MessageType.Diagnose)
                    Message.save(message)

                    #诊断日志
                    diagoseLog=DiagnoseLog(userId,form.diagnoseId,constant.DiagnoseLogAction.FetchDiagnoseEndAction)
                    DiagnoseLog.save(db_session,diagoseLog)

            return json.dumps(formResult.__dict__,ensure_ascii=False)
    return json.dumps(formResult.__dict__,ensure_ascii=False)
コード例 #9
0
ファイル: diagnose.py プロジェクト: LichuanLu/redberry
def rollbackDiagnose(diagnoseId):
    userId=session['userId']
    if userId is None:
        return json.dumps(rs.NO_LOGIN.__dict__,ensure_ascii=False)
    userId=string.atoi(userId)

    status=request.form.get('status')
    comments=request.form.get('comments')
    if status:
        status=string.atoi(status)
    diagnose=Diagnose.getDiagnoseById(diagnoseId)
    if diagnose is None:
        return  json.dumps(rs.NO_DATA.__dict__,ensure_ascii=False)
    if (hasattr(diagnose,'adminId') and diagnose.adminId and  diagnose.adminId==userId) or (hasattr(diagnose,'doctorId') and diagnose.doctorId and  diagnose.doctor.userId == userId):
        if status is None:
            status=constant.DiagnoseStatus.Draft
        diagnose.status=status
        Diagnose.save(diagnose)

        diagoseLog=DiagnoseLog(userId,diagnoseId,constant.DiagnoseLogAction.DiagnoseNeedUpateAction)
        diagoseLog.description=comments
        DiagnoseLog.save(db_session,diagoseLog)

        if hasattr(diagnose,'patient') and diagnose.patient.userID:
            content=dataChangeService.getPatienDiagnoseMessageContent(diagnose)

            #诊断通知
            message=Message(constant.DefaultSystemAdminUserId,diagnose.patient.userID,'诊断通知',content,constant.MessageType.Diagnose)
            Message.save(message)

        if(hasattr(diagnose,'doctorId') and diagnose.doctorId and  diagnose.doctor.userId == userId):
            reportDiagnoseRelations = ReportDiagnoseRelation.getReportsByDiagnoseId(diagnose.id)
            for reportDiagnoseRelation in reportDiagnoseRelations:
                if reportDiagnoseRelation.report.status != constant.ReportStatus.Del:
                    if reportDiagnoseRelation.report.type == constant.ReportType.Doctor:
                        print 'doctor report'
                        #delete doctor report if exist
                        # reportDiagnoseRelation.report.status = constant.ModelStatus.Del
                        Report.update(reportDiagnoseRelation.report.id,status=constant.ReportStatus.Del)
                        ReportDiagnoseRelation.update(reportDiagnoseRelation.id,status=constant.ModelStatus.Del)
                    elif reportDiagnoseRelation.report.type == constant.ReportType.Admin:
                        print 'admin report'
                        #set diagnose report to admin report

                        diagnose.reportId = reportDiagnoseRelation.report.id
                        Diagnose.update(diagnose)





        return  json.dumps(rs.SUCCESS.__dict__,ensure_ascii=False)
    else:
        return  json.dumps(rs.PERMISSION_DENY.__dict__,ensure_ascii=False)
コード例 #10
0
ファイル: diagnose.py プロジェクト: LichuanLu/redberry
def sendMessageAndRecordLog(diagnose, userId):
    if diagnose and hasattr(diagnose, 'patient') and diagnose.patient.userID:
        userId = diagnose.patient.userID
        content = dataChangeService.getPatienDiagnoseMessageContent(diagnose)
        message = Message(constant.DefaultSystemAdminUserId,
                          diagnose.patient.userID, '诊断通知', content,
                          constant.MessageType.Diagnose)
        Message.save(message)

    diagnoseLog = DiagnoseLog(userId, diagnose.id,
                              constant.DiagnoseLogAction.DiagnoseFinished)
    DiagnoseLog.save(db_session, diagnoseLog)
コード例 #11
0
def applyRefund(diagnoseId):
    userId = session['user_id']
    diagoseLog=DiagnoseLog(userId,diagnoseId,constant.DiagnoseLogAction.DiagnoseRefund)
    DiagnoseLog.save(session,diagoseLog)

    diagnose = Diagnose.getDiagnoseById(diagnoseId)
    if diagnose.status == constant.DiagnoseStatus.Diagnosed:
        diagnosePayStats = DiagnosePayStats.getPayStatsByDiagnoseId(diagnoseId)
        for payStats in diagnosePayStats:
            payStats.status = constant.DiagnosePayStatsConstant.Refund
        DiagnosePayStats.updatePayStats(diagnosePayStats)

    return json.dumps(rs.SUCCESS.__dict__,ensure_ascii=False)
コード例 #12
0
def applyRefund(diagnoseId):
    userId = session['user_id']
    diagoseLog = DiagnoseLog(userId, diagnoseId,
                             constant.DiagnoseLogAction.DiagnoseRefund)
    DiagnoseLog.save(session, diagoseLog)

    diagnose = Diagnose.getDiagnoseById(diagnoseId)
    if diagnose.status == constant.DiagnoseStatus.Diagnosed:
        diagnosePayStats = DiagnosePayStats.getPayStatsByDiagnoseId(diagnoseId)
        for payStats in diagnosePayStats:
            payStats.status = constant.DiagnosePayStatsConstant.Refund
        DiagnosePayStats.updatePayStats(diagnosePayStats)

    return json.dumps(rs.SUCCESS.__dict__, ensure_ascii=False)
コード例 #13
0
ファイル: front.py プロジェクト: LichuanLu/redberry
def sendAllMessage(userId, diagnose):
    new_diagnoselog = DiagnoseLog(diagnose.uploadUserId, diagnose.id,
                                  DiagnoseLogAction.NewDiagnoseAction)
    DiagnoseLog.save(db_session, new_diagnoselog)
    payUrl = generateAliPay(userId, diagnose.id, diagnose)
    if payUrl:
        sendMobileMessage(userId, diagnose.id, diagnose, payUrl)
        #诊断通知
        content = dataChangeService.getPatienDiagnoseMessageContent(
            diagnose, "您好系统中有一个诊断需要支付才能继续进行,请先支付")
        message = Message(constant.DefaultSystemAdminUserId, userId, '诊断通知',
                          content, constant.MessageType.Diagnose)
        message.url = payUrl
        Message.save(message)
コード例 #14
0
ファイル: diagnose.py プロジェクト: LichuanLu/redberry
def changeDiagnoseToNeedPay(diagnoseId):
    try:
        loginUserId = session.get('userId')
        if loginUserId is None:
            return

        fileIds = request.form.getlist('fileIds')

        loginUserId = string.atoi(loginUserId)
        diagnose = Diagnose.getDiagnoseById(diagnoseId)
        if diagnose is None or (not hasattr(
                diagnose, "patient")) or diagnose.patient is None:
            return
        userID = diagnose.patient.userID
        if userID == loginUserId or diagnose.uploadUserId == loginUserId:
            # diagnose=Diagnose()
            # diagnose.id=diagnoseId
            #update by lichuan
            # diagnose.status= constant.DiagnoseStatus.NeedPay
            # Diagnose.update(diagnose)
            from DoctorSpring.views.front import sendAllMessage, checkFilesExisting
            from DoctorSpring.models.diagnoseDocument import File
            if (checkFilesExisting(diagnose)):
                # newDiagnose= Diagnose()
                # newDiagnose.id=diagnoseId
                if diagnose.status == constant.DiagnoseStatus.NeedUpdate:
                    new_diagnoselog = DiagnoseLog(
                        diagnose.uploadUserId, diagnose.id,
                        DiagnoseLogAction.DiagnoseNeedUpateRecommitAction)
                    DiagnoseLog.save(db_session, new_diagnoselog)
                    diagnose.status = constant.DiagnoseStatus.Triaging
                    Diagnose.update(diagnose)
                    pathologyId = diagnose.pathologyId
                    File.cleanAllDirtyFile(fileIds, pathologyId)
                else:
                    diagnose.status = constant.DiagnoseStatus.NeedPay
                    Diagnose.update(diagnose)
                    #清除以前的无用文件
                    pathologyId = diagnose.pathologyId
                    File.cleanAllDirtyFile(fileIds, pathologyId)
                    sendAllMessage(userID, diagnose)

            else:
                return json.dumps(rs.FAILURE.__dict__, "需要上传DICOM文件和诊断文件")

            #end update

    except Exception, e:
        LOG.error(e.message)
        return json.dumps(rs.FAILURE.__dict__, ensure_ascii=False)
コード例 #15
0
ファイル: diagnose.py プロジェクト: LichuanLu/redberry
def changeDiagnoseToNeedPay(diagnoseId):
    try:
        loginUserId=session.get('userId')
        if loginUserId is None:
            return

        fileIds = request.form.getlist('fileIds')

        loginUserId=string.atoi(loginUserId)
        diagnose=Diagnose.getDiagnoseById(diagnoseId)
        if diagnose is None or (not hasattr(diagnose,"patient")) or  diagnose.patient is None:
            return
        userID=diagnose.patient.userID
        if userID==loginUserId or diagnose.uploadUserId==loginUserId:
            # diagnose=Diagnose()
            # diagnose.id=diagnoseId
            #update by lichuan
            # diagnose.status= constant.DiagnoseStatus.NeedPay
            # Diagnose.update(diagnose)
            from DoctorSpring.views.front import sendAllMessage,checkFilesExisting
            from DoctorSpring.models.diagnoseDocument import File
            if(checkFilesExisting(diagnose)):
                # newDiagnose= Diagnose()
                # newDiagnose.id=diagnoseId
                if diagnose.status == constant.DiagnoseStatus.NeedUpdate:
                    new_diagnoselog = DiagnoseLog(diagnose.uploadUserId, diagnose.id, DiagnoseLogAction.DiagnoseNeedUpateRecommitAction)
                    DiagnoseLog.save(db_session, new_diagnoselog)
                    diagnose.status = constant.DiagnoseStatus.Triaging
                    Diagnose.update(diagnose)
                    pathologyId = diagnose.pathologyId
                    File.cleanAllDirtyFile(fileIds, pathologyId)
                else:
                    diagnose.status = constant.DiagnoseStatus.NeedPay
                    Diagnose.update(diagnose)
                    #清除以前的无用文件
                    pathologyId = diagnose.pathologyId
                    File.cleanAllDirtyFile(fileIds, pathologyId)
                    sendAllMessage(userID,diagnose)


            else:
                return json.dumps(rs.FAILURE.__dict__,"需要上传DICOM文件和诊断文件")

            #end update

    except Exception,e:
        LOG.error(e.message)
        return json.dumps(rs.FAILURE.__dict__,ensure_ascii=False)
コード例 #16
0
ファイル: diagnose.py プロジェクト: LichuanLu/blueberry
def cancleDiagnose(diagnoseId):
    userId=session['userId']
    if userId is None:
        return json.dumps(rs.NO_LOGIN.__dict__,ensure_ascii=False)
    userId=string.atoi(userId)
    diagnose=Diagnose.getDiagnoseById(diagnoseId)
    if diagnose is None:
        return  json.dumps(rs.NO_DATA.__dict__,ensure_ascii=False)
    if (hasattr(diagnose,'patient') and diagnose.patient and diagnose.patient.userID and diagnose.patient.userID==userId) or (hasattr(diagnose,'uploadUser') and diagnose.uploadUserId and  diagnose.uploadUserId==userId):
         diagnose.status=constant.DiagnoseStatus.Del
         Diagnose.save(diagnose)

         diagoseLog=DiagnoseLog(userId,diagnoseId,constant.DiagnoseLogAction.CancleDiagnose)
         DiagnoseLog.save(db_session,diagoseLog)
         return  json.dumps(rs.SUCCESS.__dict__,ensure_ascii=False)
    else:
         return  json.dumps(rs.PERMISSION_DENY.__dict__,ensure_ascii=False)
コード例 #17
0
ファイル: diagnose.py プロジェクト: LichuanLu/redberry
def cancleDiagnose(diagnoseId):
    userId = session['userId']
    if userId is None:
        return json.dumps(rs.NO_LOGIN.__dict__, ensure_ascii=False)
    userId = string.atoi(userId)
    diagnose = Diagnose.getDiagnoseById(diagnoseId)
    if diagnose is None:
        return json.dumps(rs.NO_DATA.__dict__, ensure_ascii=False)
    if (hasattr(diagnose, 'patient') and diagnose.patient
            and diagnose.patient.userID and diagnose.patient.userID
            == userId) or (hasattr(diagnose, 'uploadUser')
                           and diagnose.uploadUserId
                           and diagnose.uploadUserId == userId):
        diagnose.status = constant.DiagnoseStatus.Del
        Diagnose.save(diagnose)

        diagoseLog = DiagnoseLog(userId, diagnoseId,
                                 constant.DiagnoseLogAction.CancleDiagnose)
        DiagnoseLog.save(db_session, diagoseLog)
        return json.dumps(rs.SUCCESS.__dict__, ensure_ascii=False)
    else:
        return json.dumps(rs.PERMISSION_DENY.__dict__, ensure_ascii=False)
コード例 #18
0
ファイル: diagnose.py プロジェクト: LichuanLu/blueberry
def recordDiagnoseLog(diagnose,userId):
    diagnoseLog=DiagnoseLog(userId,diagnose.id,constant.DiagnoseLogAction.UpateDiagnoseAction)
    DiagnoseLog.save(db_session,diagnoseLog)
コード例 #19
0
ファイル: front.py プロジェクト: houzx910/blueberry
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__)
コード例 #20
0
def getDiagnoseDetailInfoByPatient(session, diagnose):
    if diagnose is None:
        return
    diagDict = {}
    diagDict["id"] = diagnose.id
    if hasattr(diagnose, "patient") and diagnose.patient:
        if diagnose.patient.realname:
            diagDict["patientName"] = diagnose.patient.realname
        if diagnose.patient.gender:
            diagDict["gender"] = constant.Gender[diagnose.patient.gender]
        if diagnose.patient.birthDate:
            diagDict["birthDate"] = diagnose.patient.birthDate.strftime("%Y-%m-%d")
    if diagnose.diagnoseSeriesNumber:
        diagDict["diagnosenumber"] = diagnose.diagnoseSeriesNumber
    # diagDict['type']=diagnose.type
    if hasattr(diagnose, "doctor") and diagnose.doctor and diagnose.doctor.username:
        diagDict["doctorName"] = diagnose.doctor.username
    if diagnose.createDate:
        diagDict["applyTime"] = diagnose.createDate.strftime("%Y-%m-%d")
    if diagnose.status:
        diagDict["diagnoseStatus"] = diagnose.status
    # if hasattr(diagnose,"hospital") and diagnose.hospital:
    #     diagDict['hospitalHistory']=diagnose.hospital.name
    #     diagDict['hospitalId']=diagnose.hospitalId

    if diagnose.pathologyId:
        diagDict["dicomUrl"] = File.getDicomFileUrl(diagnose.pathologyId)

    if diagnose.pathologyId:
        diagDict["docUrl"] = File.getFilesUrl(diagnose.pathologyId)

    if hasattr(diagnose, "pathology") and diagnose.pathology:
        pathology = diagnose.pathology
        diagDict["caseHistory"] = pathology.caseHistory
        diagDict["diagnoseType"] = pathology.diagnoseMethod
        if hasattr(pathology, "pathologyPostions") and pathology.pathologyPostions:
            pathologyPositons = pathology.pathologyPostions
            if pathologyPositons and len(pathologyPositons) > 0:
                positions = u""
                for pathologyPositon in pathologyPositons:
                    position = pathologyPositon.position
                    positions += u" " + position.name
                diagDict["positionName"] = positions

        if hasattr(pathology, "hospital") and pathology.hospital:
            diagDict["hospitalHistory"] = pathology.hospital.name
            diagDict["hospitalId"] = pathology.hospitalId

    if hasattr(diagnose, "report") and diagnose.report:
        diagDict["reportId"] = diagnose.reportId
        # diagDict['techDes']=diagnose.report.techDesc
        # diagDict['imageDes']=diagnose.report.imageDesc
        # diagDict['diagnoseResult']=diagnose.report.diagnoseDesc

    diagnoseLogs = DiagnoseLog.getDiagnoseLogByDiagnoseId(session, diagnose.id)
    diagnoseLogsDict = getDiagnoseLogsDict(diagnoseLogs)
    if diagnoseLogs and len(diagnoseLogs) > 0:
        diagDict["actions"] = diagnoseLogsDict
    isFeedback = Comment.existCommentBydiagnose(diagnose.id, type=constant.CommentType.DiagnoseComment)
    diagDict["isFeedback"] = str(isFeedback)

    return diagDict
コード例 #21
0
ファイル: front.py プロジェクト: LichuanLu/redberry
def fileUpload():
    userId = session.get('userId')
    if userId is None:
        return redirect(LOGIN_URL)
    userId = string.atoi(userId)
    type = request.form.get('type')
    diagnoseId = request.form.get("diagnoseId")
    if diagnoseId is None:
        return jsonify({'code': 1, 'message': "error", 'data': ''})
    diagnoseId = string.atoi(diagnoseId)
    if type:
        type = string.atoi(type)
    else:
        type = constant.FileType.Dicom
    try:
        diagnose = Diagnose.getDiagnoseById(diagnoseId)
        if diagnose and diagnose.pathologyId:
            file_infos = []
            files = request.files
            for key, file in files.iteritems():
                if file and allowed_file(file.filename):
                    filename = file.filename
                    extension = getFileExtension(filename)
                    # file_url = oss_util.uploadFile(diagnoseId, filename)
                    from DoctorSpring.util.oss_util import uploadFileFromFileStorage, size, getFileName
                    fileurl = uploadFileFromFileStorage(
                        diagnoseId, filename, file, '', {}, extension)

                    newFileName = getFileName(diagnoseId, filename, extension)
                    size = size(newFileName)
                    new_file = File(type, filename, size, fileurl,
                                    diagnose.pathologyId)
                    File.save(new_file)

                    if type == FileType.Dicom:
                        filesAboutDiagnose = File.getFiles(
                            diagnose.pathologyId, FileType.FileAboutDiagnose)
                        if filesAboutDiagnose and len(filesAboutDiagnose) > 0:
                            diagnoseChange = Diagnose()
                            diagnoseChange.id = diagnoseId
                            diagnoseChange.ossUploaded = constant.DiagnoseUploaed.Uploaded
                            #diagnoseChange.status=constant.DiagnoseStatus.NeedPay
                            diagnose.uploadUserId = userId
                            Diagnose.update(diagnoseChange)
                            #sendAllMessage(userId,diagnose)需要提交了才能发信息h
                            new_diagnoselog = DiagnoseLog(
                                diagnose.uploadUserId, diagnose.id,
                                DiagnoseLogAction.NewDiagnoseAction)
                            DiagnoseLog.save(db_session, new_diagnoselog)
                    if type == FileType.FileAboutDiagnose:
                        filesAboutDiagnose = File.getFiles(
                            diagnose.pathologyId, FileType.Dicom)
                        if filesAboutDiagnose and len(filesAboutDiagnose) > 0:
                            diagnoseChange = Diagnose()
                            diagnoseChange.id = diagnoseId
                            diagnoseChange.ossUploaded = constant.DiagnoseUploaed.Uploaded
                            #diagnoseChange.status=constant.DiagnoseStatus.NeedPay
                            diagnose.uploadUserId = userId
                            Diagnose.update(diagnoseChange)
                            #sendAllMessage(userId,diagnose)
                            new_diagnoselog = DiagnoseLog(
                                diagnose.uploadUserId, diagnose.id,
                                DiagnoseLogAction.NewDiagnoseAction)
                            DiagnoseLog.save(db_session, new_diagnoselog)

                    file_infos.append(
                        dict(id=new_file.id,
                             name=filename,
                             size=size,
                             url=fileurl))
                else:
                    return jsonify({'code': 1, 'message': "error", 'data': ''})
            return jsonify(files=file_infos)
    except Exception, e:
        LOG.error(e.message)
        return jsonify({'code': 1, 'message': "上传出错", 'data': ''})
コード例 #22
0
ファイル: diagnose.py プロジェクト: LichuanLu/redberry
def recordDiagnoseLog(diagnose, userId):
    diagnoseLog = DiagnoseLog(userId, diagnose.id,
                              constant.DiagnoseLogAction.UpateDiagnoseAction)
    DiagnoseLog.save(db_session, diagnoseLog)
コード例 #23
0
ファイル: diagnose.py プロジェクト: LichuanLu/redberry
def addOrUpdateReport():

    userId = session['userId']
    user = User.getById(userId)

    if user is None:
        return json.dumps(rs.NO_DATA.__dict__, ensure_ascii=False)
    #权限查看
    if UserRole.checkRole(db_session, userId, constant.RoleId.Admin) == False:
        return json.dumps(rs.PERMISSION_DENY.__dict__, ensure_ascii=False)

    form = ReportForm(request.form)
    formResult = form.validate()
    if formResult.status == rs.SUCCESS.status:
        diagnose = Diagnose.getDiagnoseById(form.diagnoseId)
        if diagnose is None:
            return json.dumps(rs.NO_DATA.__dict__, ensure_ascii=False)
        #session['remember_me'] = form.remember_me.data
        # login and validate the user...
        report = None
        if form.reportId:
            report = Report.getReportById(form.reportId)
            if report.type == constant.ReportType.Doctor:
                return json.dumps(rs.PERMISSION_DENY.__dict__,
                                  ensure_ascii=False)
            Report.update(form.reportId, None, form.status, None,
                          form.techDesc, form.imageDesc, form.diagnoseDesc)
        else:
            report = Report(form.techDesc, form.imageDesc, form.diagnoseDesc,
                            form.fileUrl, ReportType.Admin, form.status)
            Report.save(report)

            diagnose.reportId = report.id
            Diagnose.save(diagnose)

            #add report and diagnose to relation table
            reportDiagnoseRelation = ReportDiagnoseRelation(
                report.id, diagnose.id)
            ReportDiagnoseRelation.save(reportDiagnoseRelation)

        #flash('成功添加诊断评论')
        if form.status and form.status == constant.ReportStatus.Commited:
            diagnose = Diagnose.getDiagnoseById(form.diagnoseId)
            if diagnose:
                Diagnose.changeDiagnoseStatus(
                    diagnose.id, constant.DiagnoseStatus.NeedDiagnose)
            if form.reportId is None and report:
                form.reportId = report.id
            #copy a report and add to relation table
            newReport = Report(form.techDesc, form.imageDesc,
                               form.diagnoseDesc, form.fileUrl,
                               ReportType.Doctor, constant.ReportStatus.Draft)
            Report.save(newReport)

            reportDiagnoseRelation = ReportDiagnoseRelation(
                newReport.id, diagnose.id)
            ReportDiagnoseRelation.save(reportDiagnoseRelation)

            diagnose.reportId = newReport.id
            Diagnose.save(diagnose)
            #end copy

            if diagnose and hasattr(diagnose, 'doctor'):
                doctor = diagnose.doctor
                if doctor and doctor.userId:
                    content = dataChangeService.getDoctorNeedDiagnoseMessageContent(
                        diagnose, doctor)

                    #诊断通知
                    message = Message(constant.DefaultSystemAdminUserId,
                                      doctor.userId, '诊断通知', content,
                                      constant.MessageType.Diagnose)
                    Message.save(message)

                    #诊断日志
                    diagoseLog = DiagnoseLog(
                        userId, form.diagnoseId,
                        constant.DiagnoseLogAction.FetchDiagnoseEndAction)
                    DiagnoseLog.save(db_session, diagoseLog)

            return json.dumps(formResult.__dict__, ensure_ascii=False)
    return json.dumps(formResult.__dict__, ensure_ascii=False)
コード例 #24
0
ファイル: diagnose.py プロジェクト: LichuanLu/redberry
def rollbackDiagnose(diagnoseId):
    userId = session['userId']
    if userId is None:
        return json.dumps(rs.NO_LOGIN.__dict__, ensure_ascii=False)
    userId = string.atoi(userId)

    status = request.form.get('status')
    comments = request.form.get('comments')
    if status:
        status = string.atoi(status)
    diagnose = Diagnose.getDiagnoseById(diagnoseId)
    if diagnose is None:
        return json.dumps(rs.NO_DATA.__dict__, ensure_ascii=False)
    if (hasattr(diagnose, 'adminId') and diagnose.adminId and diagnose.adminId
            == userId) or (hasattr(diagnose, 'doctorId') and diagnose.doctorId
                           and diagnose.doctor.userId == userId):
        if status is None:
            status = constant.DiagnoseStatus.Draft
        diagnose.status = status
        Diagnose.save(diagnose)

        diagoseLog = DiagnoseLog(
            userId, diagnoseId,
            constant.DiagnoseLogAction.DiagnoseNeedUpateAction)
        diagoseLog.description = comments
        DiagnoseLog.save(db_session, diagoseLog)

        if hasattr(diagnose, 'patient') and diagnose.patient.userID:
            content = dataChangeService.getPatienDiagnoseMessageContent(
                diagnose)

            #诊断通知
            message = Message(constant.DefaultSystemAdminUserId,
                              diagnose.patient.userID, '诊断通知', content,
                              constant.MessageType.Diagnose)
            Message.save(message)

        if (hasattr(diagnose, 'doctorId') and diagnose.doctorId
                and diagnose.doctor.userId == userId):
            reportDiagnoseRelations = ReportDiagnoseRelation.getReportsByDiagnoseId(
                diagnose.id)
            for reportDiagnoseRelation in reportDiagnoseRelations:
                if reportDiagnoseRelation.report.status != constant.ReportStatus.Del:
                    if reportDiagnoseRelation.report.type == constant.ReportType.Doctor:
                        print 'doctor report'
                        #delete doctor report if exist
                        # reportDiagnoseRelation.report.status = constant.ModelStatus.Del
                        Report.update(reportDiagnoseRelation.report.id,
                                      status=constant.ReportStatus.Del)
                        ReportDiagnoseRelation.update(
                            reportDiagnoseRelation.id,
                            status=constant.ModelStatus.Del)
                    elif reportDiagnoseRelation.report.type == constant.ReportType.Admin:
                        print 'admin report'
                        #set diagnose report to admin report

                        diagnose.reportId = reportDiagnoseRelation.report.id
                        Diagnose.update(diagnose)

        return json.dumps(rs.SUCCESS.__dict__, ensure_ascii=False)
    else:
        return json.dumps(rs.PERMISSION_DENY.__dict__, ensure_ascii=False)
コード例 #25
0
def getDiagnoseDetailInfoByPatient(session, diagnose):
    if diagnose is None:
        return
    diagDict = {}
    diagDict['id'] = diagnose.id
    if hasattr(diagnose, "patient") and diagnose.patient:
        if diagnose.patient.realname:
            diagDict['patientName'] = diagnose.patient.realname
        if diagnose.patient.gender:
            diagDict['gender'] = constant.Gender[diagnose.patient.gender]
        if diagnose.patient.birthDate:
            diagDict['birthDate'] = diagnose.patient.birthDate.strftime(
                '%Y-%m-%d')
    if diagnose.diagnoseSeriesNumber:
        diagDict['diagnosenumber'] = diagnose.diagnoseSeriesNumber
    #diagDict['type']=diagnose.type
    if hasattr(diagnose,
               "doctor") and diagnose.doctor and diagnose.doctor.username:
        diagDict['doctorName'] = diagnose.doctor.username
        diagDict['doctorUserId'] = diagnose.doctor.userId
    if diagnose.createDate:
        diagDict["applyTime"] = diagnose.createDate.strftime('%Y-%m-%d')
    if diagnose.status:
        diagDict['diagnoseStatus'] = diagnose.status
    # if hasattr(diagnose,"hospital") and diagnose.hospital:
    #     diagDict['hospitalHistory']=diagnose.hospital.name
    #     diagDict['hospitalId']=diagnose.hospitalId

    if diagnose.pathologyId:
        diagDict['dicomUrl'] = File.getDicomFileUrl(diagnose.pathologyId)

    if diagnose.pathologyId:
        diagDict['docUrl'] = File.getFilesUrl(diagnose.pathologyId)

    if hasattr(diagnose, "pathology") and diagnose.pathology:
        pathology = diagnose.pathology
        diagDict['caseHistory'] = pathology.caseHistory
        diagDict['diagnoseType'] = pathology.diagnoseMethod
        if hasattr(pathology,
                   "pathologyPostions") and pathology.pathologyPostions:
            pathologyPositons = pathology.pathologyPostions
            if pathologyPositons and len(pathologyPositons) > 0:
                positions = u''
                for pathologyPositon in pathologyPositons:
                    position = pathologyPositon.position
                    positions += (u' ' + position.name)
                diagDict['positionName'] = positions

        if hasattr(pathology, "hospital") and pathology.hospital:
            diagDict['hospitalHistory'] = pathology.hospital.name
            diagDict['hospitalId'] = pathology.hospitalId

    if hasattr(diagnose,
               'report') and diagnose.report and diagnose.report.fileUrl:
        diagDict['reportId'] = diagnose.reportId
        diagDict['reportUrl'] = diagnose.report.fileUrl
        # diagDict['techDes']=diagnose.report.techDesc
        # diagDict['imageDes']=diagnose.report.imageDesc
        # diagDict['diagnoseResult']=diagnose.report.diagnoseDesc

    diagnoseLogs = DiagnoseLog.getDiagnoseLogByDiagnoseId(session, diagnose.id)
    diagnoseLogsDict = getDiagnoseLogsDict(diagnoseLogs)
    if diagnoseLogs and len(diagnoseLogs) > 0:
        diagDict['actions'] = diagnoseLogsDict
    isFeedback = Comment.existCommentBydiagnose(
        diagnose.id, type=constant.CommentType.DiagnoseComment)
    diagDict['isFeedback'] = str(isFeedback)

    return diagDict
コード例 #26
0
ファイル: front.py プロジェクト: LichuanLu/redberry
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__)