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:
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
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()
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
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
patient_medical.set("medical", medical) patient_medical.set("region_id", region_id) patient_medical.set("category", medical_category if medical_category else u"未分类") patient_medical.set("rank", medical_rank) patient_medical.set("medical_name", medical_name) patient_medical.set("finish", False) processes_list = [] processes = Query(MedicalProcess).equal_to("parent", medical).equal_to("is_delete", False).ascending("sort").find() for process in processes: p_dic = { "process_id": process.id, "head": "" } processes_list.append(p_dic) patient_medical.set("processes_json", json.dumps(processes_list)) patient_medical.save() if creater_id.startswith("doctor-") and creater_id != "doctor-100000": doctor_id = int(creater_id[7:]) 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() patient_medical.set("first_create", True) app.logger.debug(u"创建成功,患者病历id为%s" % patient_medical.id) return patient_medical class PatientMedicalApi(Resource): @marshal_with(PatientMedicalDetailsFields.resource_fields)