예제 #1
0
 def post(self, patient_medical_id):
     """
     提交病历标签
     :param patient_medical_id:
     :return:
     """
     data = request.jsondata
     symptom = data.get("symptom")  # 症状
     follow_symptom = data.get("follow_symptom")  # 伴随症状
     disease_time = data.get("disease_time")  # 发病时间
     stage = data.get("stage")  # 分期
     pathology = data.get("pathology")  # 病理分型
     check_item = data.get("check_item")  # 检查项目
     medical_history = data.get("medical_history")  # 相关病史
     operation = data.get("operation")  # 手术
     treatment = data.get("treatment")  # 治疗
     complication = data.get("complication")  # 合并症
     patient_medical = Query(PatientMedical).get(patient_medical_id)
     try:
         label = Query(PatientMedicalLabel).equal_to("patient_medical", patient_medical).first()
     except LeanCloudError, e:
         if e.code == 101:
             label = PatientMedicalLabel()
             label.set("patient_medical", patient_medical)
         else:
             raise e
 def post(self):
     data = request.jsondata
     username = data.get('username')
     password = data.get('password')
     try:
         User().login(username, password)
     except LeanCloudError:
         abort(403, message=u"认证失败")
     else:
         user = Query(User).equal_to("username", username).first()
         try:
             token = Query(AuthToken).equal_to("user", user).greater_than("expires_time", datetime.datetime.now()).first()
         except LeanCloudError, e:
             if e.code == 101:  # 服务端对应的 Class 还没创建
                 expires_date = datetime.datetime.now() + datetime.timedelta(hours=8)
                 token = AuthToken()
                 token.set("user", user)
                 token.set("expires_time", expires_date)
                 token.set("access_token", str(uuid.uuid1()))
                 token.save()
                 return {
                     "access_token": token.access_token,
                     "expires_time": token.expires_time.isoformat()
                 }
             else:
                 raise e
         else:
예제 #3
0
 def get(self, patient_id):
     """
     获取患者最危重的病历并且填过病历标签的标签
     :return:
     """
     medical_label = None
     try:
         patient_medicals = Query(PatientMedical).equal_to("patient_id", patient_id).find()
         if not patient_medicals:
             return {}
         for patient_medical in patient_medicals:
             patient_medical.medical.fetch()
         # 填写过的病历重新排序,严重的在前边
         patient_medicals.sort(key=lambda rank: patient_medical.medical.rank, reverse=True)
         for patient_medical in patient_medicals:
             try:
                 medical_label = Query(PatientMedicalLabel).equal_to("patient_medical", patient_medical).first()
             except LeanCloudError, e:
                 if e.code == 101:
                     pass
             if medical_label:
                 break
     except LeanCloudError, e:
         if e.code == 101:
             return {}
예제 #4
0
    def get(self):
        severe = int(request.args.get("severe", 0))  # 如果是1,则取出由患者创建,并且没有医生接收的病历
        query = Query(PatientMedical)
        if severe == 1:
            query.startswith("creater_id", "patient").equal_to("receive_doctor_id", -1)

        patient_medicals = query.find()
        if not patient_medicals:
            patient_medicals = []
        return patient_medicals
예제 #5
0
 def get(self, patient_medical_id):
     """
     根据创建的患者的病历id获取病历
     :param patient_medical_id:
     :return:
     """
     patient_medical = Query(PatientMedical).get(patient_medical_id)
     patient_medical.get("medical").fetch()
     comments = Query(PatientMedicalComment).equal_to("patient_medical", patient_medical).ascending("created_at").limit(2).find()
     return {"patient_medical": patient_medical, "comments": comments}
예제 #6
0
 def delete(self, doctor_id, patient_medical_id):
     """
     取消接收
     :param patient_medical_id:
     :return:
     """
     patient_medical = Query(PatientMedical).get(patient_medical_id)
     doctor_medical = Query(DoctorMedicalRelation).equal_to("doctor_id", doctor_id).equal_to("patient_medical",
                                                                                             patient_medical).first()
     doctor_medical.set("is_cancel", True)
     doctor_medical.save()
     return patient_medical
예제 #7
0
    def send_to_followers(self):
        current_user = User.get_current()
        if not current_user:
            raise ValueError("Please sign in an user")

        query = Query("_Follower").select("follower").equal_to("user", current_user)
        self.send(query)
예제 #8
0
    def send_to_followers(self):
        current_user = User.get_current()
        if not current_user:
            raise ValueError('Please sign in an user')

        query = Query('_Follower').select('follower').equal_to(
            'user', current_user)
        self.send(query)
예제 #9
0
 def post(self, patient_medical_id):
     """
     我要患者-接收患者
     :return:
     """
     doctor_id = request.jsondata.get("doctor_id")
     patient_medical = Query(PatientMedical).get(patient_medical_id)
     try:
         doctor_medical = Query(DoctorMedicalRelation).equal_to("doctor_id", doctor_id).equal_to("patient_medical",
                                                                                                 patient_medical).first()
     except LeanCloudError, e:
         if e.code == 101:
             doctor_medical = DoctorMedicalRelation()
             doctor_medical.set("doctor_id", doctor_id)
             doctor_medical.set("patient_medical", patient_medical)
             doctor_medical.set("is_cancel", False)
             doctor_medical.save()
예제 #10
0
def load_user_from_request(request):
    access_token = request.headers.get('Authorization')
    if access_token:
        if access_token == "Panmax":
            user = Query(User).equal_to("username", "jiapan").first()
            admin = Query(Admin).equal_to("user", user).first()
            return admin
        try:
            token = Query(AuthToken).equal_to("access_token", access_token).greater_than("expires_time", datetime.now()).first()
        except LeanCloudError:
            return None
        else:
            user = token.get('user')
            user.fetch()
            admin = Query(Admin).equal_to("user", user).first()
            return admin
    return None
예제 #11
0
 def save(self, *args, **kwargs):
     """
     重写保存
     """
     # 保存的时候检查有没有leancloud的conversation,没有则创建
     if not self.channel_leancloud_id:
         cl_c = _Conversation()
         cl_c.set("n", self.name)
         cl_c.set("sys", True)
         cl_c.save()
         self.channel_leancloud_id = cl_c.id
     else:
         qs = Query(_Conversation)
         cl_c = qs.get(self.channel_leancloud_id)
         if cl_c.get("name") != self.name:
             cl_c.set("name", self.name)
             cl_c.save()
         # 更新 update_time
         self.update_time = TimeZone.utc_now()
     super(Channel, self).save(*args, **kwargs)
예제 #12
0
    def send_private_status(self, target):
        current_user = User.get_current()
        if not current_user:
            raise ValueError('Please sign in an user')

        if not isinstance(target, User):
            raise TypeError('target must be a leancloud.User')

        query = Query('User').equal_to('objectId', target.id)
        self.inbox_type = 'private'
        self.send(query)
예제 #13
0
    def send_private_status(self, target):
        current_user = User.get_current()
        if not current_user:
            raise ValueError("Please sign in an user")

        if not isinstance(target, User):
            raise TypeError("target must be a leancloud.User")

        query = Query("User").equal_to("objectId", target.id)
        self.inbox_type = "private"
        self.send(query)
예제 #14
0
 def logic(self, client_ids):
     if len(client_ids)<=1:
         self.resp_error(content="At least two client_id is required.")
         return
     try_same = None
     for i in client_ids:
         if not i or try_same==i:
             self.resp_args_error()
             return
         try_same = i
     qs = Query(_Conversation)
     try:
         obj = qs.contains_all("m", client_ids).first() # FIXME 当前只是包含, 如果今后出现了群聊,此处务必修改
         the_id = obj.id
     except LeanCloudError:
         conv_obj = _Conversation()
         conv_obj.set("m", client_ids)
         conv_obj.set("sys", False)
         conv_obj.save()
         the_id = conv_obj.id
     return the_id
예제 #15
0
    def get(self):
        """
        我要患者首页
        :return:
        """
        page = int(request.args.get("page", 1))
        size = int(request.args.get("size", 20))
        region_id = int(request.args.get("region_id", -1))
        keyword = request.args.get("keyword")
        rank = int(request.args.get("rank", 0))
        category = request.args.get("category")
        skip = (page-1) * size

        patient_medicals = []
        try:
            query = Query(PatientMedical).equal_to("finish", True)
            if region_id and region_id != -1:
                query = query.equal_to("region_id", region_id)
            elif keyword:
                query = query.contains("medical_name", keyword)
            elif category:
                query = query.equal_to("category", category)
                if rank != 0:
                    query = query.equal_to("rank", rank)
            patient_medicals = query.skip(skip).limit(size).find()
        except LeanCloudError, e:
            if e.code == 101:
                patient_medicals = []
예제 #16
0
    def get(self, patient_medical_id):
        """
        通过创建好的病历id,获取创建时候的过程,同时带着病历模板信息
        :param patient_medical_id: 病历id
        :return:
        """
        app.logger.debug(u"获取病历过程,患者病历id:%s" % patient_medical_id)

        patient_medical = Query(PatientMedical).get(patient_medical_id)
        processes_list = json.loads(patient_medical.get("processes_json"))
        processes = []
        for _process in processes_list:
            try:
                process = Query(MedicalProcess).get(_process['process_id'])
            except LeanCloudError, e:
                if e.code == 101:
                    continue
            process.set("fill", True if _process['head'] else False)
            process.set("base_url", "http://m.ihaoyisheng.com/medical/processes/%s?patient_medical_id=%s" % (process.id, patient_medical_id))
            processes.append(process)
예제 #17
0
 def post(self, patient_id):
     """
     提交患者个人信息
     :param patient_id:
     :return:
     """
     data = request.jsondata
     name = data.get("name")
     sex = data.get("sex")
     birth = datetime.datetime.strptime(data.get("birth"), "%Y-%m-%d")
     height = data.get("height")
     weight = data.get("weight")
     try:
         patient_info = Query(PatientInfo).equal_to("patient_id", patient_id).first()
     except LeanCloudError, e:
         if e.code == 101:
             patient_info = PatientInfo()
             patient_info.set("patient_id", patient_id)
             patient_info.save()
         else:
             raise e
예제 #18
0
    def post(self, patient_medical_id):
        """
        创建病历过程
        :param patient_id: 病历id
        :return:
        """
        data = request.jsondata
        result_json = data.get("result_json")
        creater_id = data.get("creater_id")
        process_id = data.get("process_id")
        if not (creater_id.startswith("doctor-") or creater_id.startswith("patient-")):
            abort(400, message=u"创建者id不正确")
        patient_medical = Query(PatientMedical).get(patient_medical_id)

        process = Query(MedicalProcess).get(process_id)
        patient_process = PatientMedicalProcess()
        patient_process.set("process", process)
        patient_process.set("result_json", result_json)
        patient_process.set("patient_id", patient_medical.patient_id)
        patient_process.set("creater_id", creater_id)
        patient_process.save()

        # update medical record head
        processes_list = json.loads(patient_medical.get("processes_json"))
        for _process in processes_list:
            if _process['process_id'] == process_id:
                _process['head'] = patient_process.id
                break
        else:
            abort(400, message=u'更新过程head失败')

        patient_medical.set("processes_json", json.dumps(processes_list))

        if processes_list[0].get("head") and processes_list[1].get("head"):
            patient_medical.set("finish", True)
            patient_medical.save()
        else:
            patient_medical.set("finish", False)
            patient_medical.save()

        patient_medical.save()

        return patient_process
예제 #19
0
 if creater_id.startswith("doctor-") and creater_id != "doctor-100000":
     try:
         patient_medicals = Query(PatientMedical).equal_to("creater_id", creater_id).find()
         not_finish_count = 0
         for patient_medical in patient_medicals:
             if not patient_medical.finish:
                 not_finish_count += 1
         if not_finish_count >= 3:
             abort(401, message=u"创建失败,未完成病历不能超过3个。")
     except LeanCloudError, e:
         if e.code == 101:
             pass
         else:
             raise e
 try:
     patient_medical = Query(PatientMedical).equal_to("medical", medical).equal_to("patient_id", patient_id).first()
     if patient_medical:
         if creater_id.startswith("doctor-"):
             if not (patient_medical.get("creater_id") == creater_id or creater_id == "doctor-100000"):
                 abort(401, message=u"该患者病历已被其他医生创建")
         elif creater_id.startswith("patient-"):
             if patient_medical.get("patient_id") != patient_id:
                 abort(401, message=u"患者只能给自己创建病历")
         patient_medical.set("first_create", False)
         return patient_medical
 except LeanCloudError, e:
     if e.code == 101:
         pass
     else:
         raise e
 patient_medical = PatientMedical()