package mobile_api_controllers import ( "encoding/json" "fmt" "github.com/jinzhu/gorm" "reflect" "strconv" "strings" "time" "XT_New/enums" "XT_New/models" "XT_New/service" "XT_New/utils" "github.com/astaxie/beego" "math" "net/http" "net/url" ) // type DialysisTestAPIController struct { // MobileBaseAPIController // } // [get]/m/api/test // func (this *DialysisTestAPIController) Test() { // orgID := int64(3907) // now := time.Now() // nextWeek := now.AddDate(0, 0, 7) // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek) // nextTwoWeek := now.AddDate(0, 0, 14) // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek) // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix()) // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix()) // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil { // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return // } // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs) // if exchangeErr != nil { // this.ErrorLog("%v", exchangeErr) // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return // } // this.ServeSuccessJSON(map[string]interface{}{ // // "now": now, // // "next_week": nextWeek,f // // "next_week_mon": nextWeekMon, // // "next_week_sun": nextWeekSun, // // "next_two_week_mon": nextTwoWeekMon, // // "next_two_week_sun": nextTwoWeekSun, // "next_week_schs": nextWeekSchs, // "next_two_week_schs": nextTwoWeekSchs, // }) // } type DialysisAPIController struct { MobileBaseAPIAuthController } // /m/api/scheduals [get] // @param type:int // @param date:string func (this *DialysisAPIController) Scheduals() { schedualType, _ := this.GetInt64("type") schedualDate := this.GetString("date") if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 { schedualType = 0 } date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate) if parseDateErr != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminInfo := this.GetMobileAdminUserInfo() orgID := adminInfo.Org.Id redis := service.RedisClient() defer redis.Close() // cur_date := time.Now().Format("2006-01-02") key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10) scheduals_json_str, _ := redis.Get(key).Result() if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType) if err != nil { this.ErrorLog("获取排班信息失败:%v", err) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) } else { if len(scheduals) > 0 { //缓存数据 scheduals_json, err := json.Marshal(scheduals) if err == nil { redis.Set(key, scheduals_json, time.Second*30) } } this.ServeSuccessJSON(map[string]interface{}{ "scheduals": scheduals, }) } } else { //缓存数据了数据,将redis缓存的json字符串转为map var dat []map[string]interface{} if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil { } else { } this.ServeSuccessJSON(map[string]interface{}{ "scheduals": dat, "redis": "true", "date": schedualDate, }) } } // /m/api/waiting_scheduals [get] // @param date:string func (this *DialysisAPIController) WaitingScheduals() { schedualDate := this.GetString("date") date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate) if parseDateErr != nil && len(schedualDate) != 0 { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminInfo := this.GetMobileAdminUserInfo() orgID := adminInfo.Org.Id redis := service.RedisClient() defer redis.Close() // cur_date := time.Now().Format("2006-01-02") key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10) wait_scheduals, _ := redis.Get(key).Result() if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix()) if err != nil { this.ErrorLog("获取排班信息失败:%v", err) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) } else { returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals)) for _, s := range scheduals { returnScheduals = append(returnScheduals, s) } if len(returnScheduals) > 0 { //缓存数据 wait_scheduals_json, err := json.Marshal(scheduals) if err == nil { redis.Set(key, wait_scheduals_json, time.Second*30) } } this.ServeSuccessJSON(map[string]interface{}{ "scheduals": scheduals, }) } } else { //缓存数据了数据,将redis缓存的json字符串转为map var dat []map[string]interface{} if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil { } else { } this.ServeSuccessJSON(map[string]interface{}{ "scheduals": dat, "redis": "true", "date": schedualDate, }) } } //else{ // fmt.Println("33333333") // // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix()) // if err != nil { // this.ErrorLog("获取排班信息失败:%v", err) // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // } else { // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals)) // for _, s := range scheduals { // // returnScheduals = append(returnScheduals, s) // } // // this.ServeSuccessJSON(map[string]interface{}{ // "scheduals": returnScheduals, // }) // } // // } //if err == nil{ // // // // // //}else{ //} // /m/api/dialysis/record [get] // @param patient_id:int // @param date:string (yyyy-MM-dd) func (this *DialysisAPIController) DialysisRecord() { patientID, _ := this.GetInt64("patient_id") recordDateStr := this.GetString("date") if patientID <= 0 { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } if len(recordDateStr) == 0 { recordDateStr = time.Now().Format("2006-01-02") } date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr) if parseDateErr != nil { this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminInfo := this.GetMobileAdminUserInfo() patient, getPatientErr := service.MobileGetPatientDetail(adminInfo.Org.Id, patientID) if getPatientErr != nil { this.ErrorLog("获取患者信息失败:%v", getPatientErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } else if patient == nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist) return } schedual, getSchedualErr := service.MobileGetSchedualDetail(adminInfo.Org.Id, patientID, date.Unix()) if getSchedualErr != nil { this.ErrorLog("获取患者排班信息失败:%v", getSchedualErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix()) if getRTARErr != nil { this.ErrorLog("获取接诊评估失败:%v", getRTARErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix()) if getPEErr != nil { this.ErrorLog("获取透前评估失败:%v", getPEErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix()) if getLPEErr != nil { this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix()) if getDoctorAdvicesErr != nil { this.ErrorLog("获取临时医嘱失败:%v", getDoctorAdvicesErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix()) if getDialysisOrderErr != nil { this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix()) if getDoubleCheckErr != nil { this.ErrorLog("获取双人核对记录失败:%v", getDoubleCheckErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix()) if getMonitorRecordsErr != nil { this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } var lastMonitorRecord *models.MonitoringRecord lastMonitorRecord, getLastErr := service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix()) if getLastErr != nil { this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix()) if getAADErr != nil { this.ErrorLog("获取透后评估失败:%v", getAADErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } lastAssessmentAfterDislysis, getLAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix()) if getLAADErr != nil { this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix()) if getTreatmentSummaryErr != nil { this.ErrorLog("获取治疗小结失败:%v", getTreatmentSummaryErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId) //if getDialysisPrescribeErr != nil { // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr) // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return //} dialysisSolution, _ := service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId) //if getDialysisSolutionErr != nil { // this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr) // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return //} lastDialysisPrescribe, _ := service.MobileGetLastDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, schedual.ModeId) //fmt.Println("上次透析处方",lastDialysisPrescribe.DialyzerPerfusionApparatus) //if getDialysisPrescribeErr != nil { // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr) // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return //} //获取系统透析处方模版 systemDialysisPrescribe, _ := service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId) //if getSystemDialysisPrescribeErr != nil { // this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr) // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return //} //dialysisSolution, getDialysisSolutionErr := service.MobileGetDialysisSolution(adminInfo.Org.Id, patientID) //operators, _ := service.GetAllAdminUserES(adminInfo.Org.Id, adminInfo.App.Id) _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id) stockType, _ := service.GetStockType(adminInfo.Org.Id) prepare, _ := service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID) var his_advices []*models.HisDoctorAdviceInfo if is_open_config.IsOpen == 1 { his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix()) } if getLPEErr != nil { this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } lastDryWeightDislysis, getDryErr := service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID) if getDryErr != nil { this.ErrorLog("获取最后一条干体重失败:%v", getDryErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } //headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.Org.Id, adminInfo.App.Id, models.SpecialPermissionTypeHeadNurse) _, gobalConfig := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id) //goodTypes, _ := service.FindAllGoodTypeByType(1) //查出所有库存配置的系统类型 //goodInfos, _ := service.FindAllGoodInfo(adminInfo.Org.Id) //查出所有库存配置的系统类型 operators, _ := service.GetAllStarfEs(adminInfo.Org.Id) //consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patientID, date.Unix()) //lastConsumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patientID, date.Unix()) returnData := map[string]interface{}{ "patient": patient, "schedual": schedual, "prescription": dialysisPrescribe, "solution": dialysisSolution, "last_prescription": lastDialysisPrescribe, "receiver_treatment_access": receiverTreatmentAccess, "predialysis_evaluation": predialysisEvaluation, "doctor_advices": doctorAdvices, "double_check": doubleCheck, "assessment_after_dislysis": assessmentAfterDislysis, "treatment_summary": treatmentSummary, "monitor_records": monitorRecords, "dialysis_order": dialysisOrder, "operators": operators, "last_predialysis_evaluation": lastPredialysisEvaluation, "last_assessment_after_dislysis": lastAssessmentAfterDislysis, "last_monitor_record": lastMonitorRecord, "config": gobalConfig, "dry_weight": lastDryWeightDislysis, "system_prescription": systemDialysisPrescribe, "his_advices": his_advices, "is_open_config": is_open_config, "stockType": stockType, "prepare": prepare, } this.ServeSuccessJSON(returnData) } func (c *DialysisAPIController) GetDialysisGlobalConfig() { adminInfo := c.GetMobileAdminUserInfo() adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id) devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0) device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id) returnData := map[string]interface{}{ "admin_users": adminUsers, "devices": devices, "device_numbers": device_numbers, } c.ServeSuccessJSON(returnData) } func (c *DialysisAPIController) PostAtreatmentInfo() { id, _ := c.GetInt64("patient", 0) recordDateStr := c.GetString("record_date") propagandaAndEducationContent := c.GetString("propagandaAndEducationContent") summaryContent := c.GetString("summaryContent") changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0) treatNurseId, _ := c.GetInt64("treatNurse", 0) checkStaffId, _ := c.GetInt64("checkStaff", 0) deboardNurseId, _ := c.GetInt64("deboardNurse", 0) treatDoctor, _ := c.GetInt64("treatDoctor", 0) nursingRecord := c.GetString("nursing_record") fmt.Println("护理记录", nursingRecord) specialRecord := c.GetString("special_record") fmt.Println("特殊记录", specialRecord) adminUserInfo := c.GetMobileAdminUserInfo() changeMedicalNurseId = adminUserInfo.AdminUser.Id checkStaffId = adminUserInfo.AdminUser.Id deboardNurseId = adminUserInfo.AdminUser.Id treatDoctor = adminUserInfo.AdminUser.Id if id <= 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id) if patient.ID == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist) return } if len(recordDateStr) == 0 { recordDateStr = time.Now().Format("2006-01-02") } recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr) if parseDateErr != nil { c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } //now := time.Now() //year, month, day := now.Date() //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local) //todayTimeStamp := today_time.Unix() summary := models.TreatmentSummary{ UserOrgId: adminUserInfo.Org.Id, PatientId: id, AssessmentDate: recordDate.Unix(), Mission: propagandaAndEducationContent, DialysisSummary: summaryContent, SjNurse: changeMedicalNurseId, ZlNurse: treatNurseId, HdNurse: checkStaffId, XjNurse: deboardNurseId, ZlDoctor: treatDoctor, CreatedTime: time.Now().Unix(), Status: 1, NursingRecord: nursingRecord, SpecialRecord: specialRecord, } _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id) if treatmentSummary.ID == 0 { //新增 summary.Creater = adminUserInfo.AdminUser.Id service.AddSigleSummaryRecord(&summary) c.ServeSuccessJSON(map[string]interface{}{ "summary": summary, }) } else { //修改 //if treatmentSummary.Creater != adminUserInfo.AdminUser.Id { // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse) // if getPermissionErr != nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return // } else if headNursePermission == nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify) // return // } //} summary.Creater = treatmentSummary.Creater summary.CreatedTime = treatmentSummary.CreatedTime summary.Modifier = adminUserInfo.AdminUser.Id summary.ID = treatmentSummary.ID service.UpdateSummeRecord(&summary) c.ServeSuccessJSON(map[string]interface{}{ "summary": summary, }) } } func (c *DialysisAPIController) PostDoubleCheck() { id, _ := c.GetInt64("patient", 0) recordDateStr := c.GetString("record_date") checkTimeStr := c.GetString("check_time") firstCheckTimeStr := c.GetString("first_check_time") creater, _ := c.GetInt64("creater", 0) modifier, _ := c.GetInt64("modifier", 0) dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0) dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0) vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0) pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0) dialysis_item_desc := c.GetString("dialysis_item_desc") dialysis_parameter_desc := c.GetString("dialysis_parameter_desc") vascular_access_desc := c.GetString("vascular_access_desc") pipeline_connection_desc := c.GetString("pipeline_connection_desc") collator, _ := c.GetInt64("collator", 0) if id <= 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminUserInfo := c.GetMobileAdminUserInfo() patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id) if patient.ID == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist) return } if len(recordDateStr) == 0 { recordDateStr = time.Now().Format("2006-01-02") } recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr) if parseDateErr != nil { c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } var checkDate int64 if len(checkTimeStr) == 0 { checkDate = 0 } else { checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr) checkDate = checkDateUnix.Unix() } var firstCheckDate int64 if len(firstCheckTimeStr) == 0 { firstCheckDate = 0 } else { firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr) firstCheckDate = firstCheckDateUnix.Unix() } //now := time.Now() //year, month, day := now.Date() //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local) //todayTimeStamp := today_time.Unix() doubleCheck := models.DoubleCheck{ UserOrgId: adminUserInfo.Org.Id, PatientId: id, DialysisItemCheck: dialysis_item_check, DialysisParameterCheck: dialysis_parameter_check, VascularAccessVerification: vascular_access_verification, PipelineConnectionCheck: pipeline_connection_check, DialysisItemDesc: dialysis_item_desc, DialysisParameterDesc: dialysis_parameter_desc, VascularAccessDesc: vascular_access_desc, PipelineConnectionDesc: pipeline_connection_desc, Collator: collator, Status: 1, CreatedTime: time.Now().Unix(), CheckDate: recordDate.Unix(), UpdatedTime: time.Now().Unix(), } _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id) if check.ID == 0 { //新增 doubleCheck.FirstCheckTime = firstCheckDate doubleCheck.CheckTime = checkDate doubleCheck.Creater = creater doubleCheck.Modifier = modifier err := service.AddSigleDoubleCheck(&doubleCheck) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "doubleCheck": &doubleCheck, }) } } else { //修改 doubleCheck.FirstCheckTime = firstCheckDate doubleCheck.CheckTime = checkDate doubleCheck.Creater = creater doubleCheck.Modifier = modifier doubleCheck.CreatedTime = check.CreatedTime doubleCheck.ID = check.ID err := service.UpdateDoubleCheck(&doubleCheck) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "doubleCheck": &doubleCheck, }) } } } func (c *DialysisAPIController) PostAcceptsAssessment() { id, _ := c.GetInt64("patient", 0) recordDateStr := c.GetString("record_date") way, _ := c.GetInt64("way", 0) consciousness, _ := c.GetInt64("consciousness", 0) appetite, _ := c.GetInt64("appetite", 0) condition, _ := c.GetInt64("condition", 0) posture, _ := c.GetInt64("posture") sick_condition, _ := c.GetInt64("sick_condition", 0) danger_level, _ := c.GetInt64("danger_level", 0) intake, _ := c.GetInt64("intake", 0) nutrition, _ := c.GetInt64("nutrition", 0) psychological_assessment, _ := c.GetInt64("psychological_assessment", 0) psychological_assessment_other := c.GetString("psychological_assessment_other") score := c.GetString("score") sick_condition_other := c.GetString("sick_condition_other") //precaution, _ := c.GetInt64("precaution", 0) precaution := c.GetString("precaution") precaution_other := c.GetString("precaution_other") psychological_other := c.GetString("psychological_other") admission_number := c.GetString("admission_number") if id <= 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminUserInfo := c.GetMobileAdminUserInfo() patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id) if patient.ID == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist) return } //now := time.Now() //year, month, day := now.Date() //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local) //todayTimeStamp := today_time.Unix() if len(recordDateStr) == 0 { recordDateStr = time.Now().Format("2006-01-02") } recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr) if parseDateErr != nil { c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id) receiveTreatmentAsses := models.ReceiveTreatmentAsses{ UserOrgId: adminUserInfo.Org.Id, PatientId: id, RecordDate: recordDate.Unix(), Way: way, Consciousness: consciousness, Appetite: appetite, Condition: condition, SickCondition: sick_condition, DangerLevel: danger_level, Intake: intake, Nutrition: nutrition, PsychologicalAssessment: psychological_assessment, PsychologicalAssessmentOther: psychological_assessment_other, SickConditionOther: sick_condition_other, Posture: posture, CreatedTime: time.Now().Unix(), UpdateTime: time.Now().Unix(), Status: 1, Score: score, Precaution: precaution, PrecautionOther: precaution_other, PsychologicalOther: psychological_other, AdmissionNumber: admission_number, } if receiveTreatment.ID == 0 { //新增 receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "receiveTreatmentAsses": receiveTreatmentAsses, }) } } else { //修改 //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id { // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse) // if getPermissionErr != nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return // } else if headNursePermission == nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify) // return // } //} receiveTreatmentAsses.Creater = receiveTreatment.Creater receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id receiveTreatmentAsses.ID = receiveTreatment.ID err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "receiveTreatmentAsses": receiveTreatmentAsses, }) } } } func (c *DialysisAPIController) PostAssessmentAfterDislysis() { id, _ := c.GetInt64("patient", 0) recordDateStr := c.GetString("record_date") weightAfter, _ := c.GetFloat("weight_after", 0) additionalWeight, _ := c.GetFloat("additional_weight", 0) weightReduce, _ := c.GetFloat("weight_loss", 0) temperature, _ := c.GetFloat("temperature", 0) pulse_frequency, _ := c.GetFloat("pulse_frequency", 0) breathing_rate, _ := c.GetFloat("breathing_rate", 0) systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0) diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0) actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0) actual_displacement, _ := c.GetFloat("actual_displacement", 0) actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0) actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0) cruor := c.GetString("cruor") symptomsAfterDialysi := c.GetString("symptom_after_dialysis") internalFistula := c.GetString("internal_fistula") catheter := c.GetString("catheter") complications := c.GetString("complication") remark := c.GetString("remark") dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0) dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0) blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0) blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0) puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0) puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0) internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0) patientGose, _ := c.GetInt64("patient_gose", 0) inpatientDepartment := c.GetString("inpatient_department") observationContent := c.GetString("observation_content") observationContentOther := c.GetString("observation_content_other") dialysis_process, _ := c.GetInt64("dialysis_process", 0) in_advance_minute, _ := c.GetFloat("in_advance_minute", 0) in_advance_reason := c.GetString("in_advance_reason") hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0) hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0) tremor_noise, _ := c.GetInt64("tremor_noise", 0) disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0) disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option") arterial_tube, _ := c.GetInt64("arterial_tube", 0) intravenous_tube, _ := c.GetInt64("intravenous_tube", 0) dialyzer, _ := c.GetInt64("dialyzer", 0) in_advance_reason_other := c.GetString("in_advance_reason_other") is_eat, _ := c.GetInt64("is_eat", 0) cvc_a, _ := c.GetFloat("cvc_a", 0) cvc_v, _ := c.GetFloat("cvc_v", 0) channels, _ := c.GetInt64("channel", 0) return_blood, _ := c.GetInt64("return_blood", 0) rehydration_volume, _ := c.GetInt64("rehydration_volume", 0) dialysis_during, _ := c.GetInt64("dialysis_during", 0) stroke_volume, _ := c.GetInt64("stroke_volume", 0) blood_flow, _ := c.GetInt64("blood_flow", 0) //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0) sealing_fluid_dispose := c.GetString("sealing_fluid_dispose") sealing_fluid_special := c.GetString("sealing_fluid_special") dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants") supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure") setting_pressure := c.GetString("setting_pressure") supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure") diastolic_pressure := c.GetString("diastolic_pressure") other_complication := c.GetString("other_complication") if id <= 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminUserInfo := c.GetMobileAdminUserInfo() patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id) if patient.ID == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist) return } if len(recordDateStr) == 0 { recordDateStr = time.Now().Format("2006-01-02") } recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr) if parseDateErr != nil { c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } //now := time.Now() //year, month, day := now.Date() //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local) //todayTimeStamp := today_time.Unix() //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id) assessmentAfterDislysis := models.AssessmentAfterDislysis{ UserOrgId: adminUserInfo.Org.Id, PatientId: id, AssessmentDate: recordDate.Unix(), Temperature: temperature, PulseFrequency: pulse_frequency, BreathingRate: breathing_rate, SystolicBloodPressure: systolic_blood_pressure, DiastolicBloodPressure: diastolic_blood_pressure, ActualUltrafiltration: actual_ultrafiltration, ActualDisplacement: actual_displacement, ActualTreatmentHour: actualtreatHour, ActualTreatmentMinute: actualtreatmin, WeightAfter: weightAfter, AdditionalWeight: additionalWeight, WeightLoss: weightReduce, Cruor: cruor, SymptomAfterDialysis: symptomsAfterDialysi, InternalFistula: internalFistula, Catheter: catheter, Complication: complications, DialysisIntakes: dialysateVolume, CreatedTime: time.Now().Unix(), Status: 1, Remark: remark, BloodAccessPartId: blood_access_part_id, BloodAccessPartOperaId: blood_access_part_opera_id, DialysisIntakesUnit: dialysis_intakes_unit, PuncturePointOozingBlood: puncturePointOozingBlood, PuncturePointHaematoma: puncturePointHaematoma, InternalFistulaTremorAc: internalFistulaTremorAc, PatientGose: patientGose, InpatientDepartment: inpatientDepartment, ObservationContent: observationContent, ObservationContentOther: observationContentOther, DialysisProcess: dialysis_process, InAdvanceMinute: in_advance_minute, InAdvanceReason: in_advance_reason, HemostasisMinute: hemostasis_minute, HemostasisOpera: hemostasis_opera, TremorNoise: tremor_noise, DisequilibriumSyndrome: disequilibrium_syndrome, DisequilibriumSyndromeOption: disequilibrium_syndrome_option, ArterialTube: arterial_tube, IntravenousTube: intravenous_tube, Dialyzer: dialyzer, InAdvanceReasonOther: in_advance_reason_other, IsEat: is_eat, CvcA: cvc_a, CvcV: cvc_v, Channel: channels, ReturnBlood: return_blood, RehydrationVolume: rehydration_volume, DialysisDuring: dialysis_during, StrokeVolume: stroke_volume, BloodFlow: blood_flow, SealingFluidDispose: sealing_fluid_dispose, SealingFluidSpecial: sealing_fluid_special, DosageOfAnticoagulants: dosage_of_anticoagulants, SupineDiastolicBloodPressure: supine_diastolic_blood_pressure, SupineSystolicBloodPressure: supine_systolic_blood_pressure, SettingPressure: setting_pressure, DiastolicPressure: diastolic_pressure, OtherComplication: other_complication, } appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id) _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id) if assessmentAfter.ID == 0 { //新增 if appRole.UserType == 2 || appRole.UserType == 1 { assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id assessmentAfterDislysis.AssessmentTime = time.Now().Unix() } else { assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id } err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "assessmentAfterDislysis": assessmentAfterDislysis, }) } } else { //修改 if appRole.UserType == 2 || appRole.UserType == 1 { assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id assessmentAfterDislysis.AssessmentTime = time.Now().Unix() } else { assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id if assessmentAfterDislysis.Creater == 0 { assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id } } assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime assessmentAfterDislysis.ID = assessmentAfter.ID err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "assessmentAfterDislysis": assessmentAfterDislysis, }) } } } func (c *DialysisAPIController) PostDialysisPrescription() { id, _ := c.GetInt64("patient", 0) recordDateStr := c.GetString("record_date") if id <= 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminUserInfo := c.GetMobileAdminUserInfo() patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id) if patient.ID == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist) return } if len(recordDateStr) == 0 { recordDateStr = time.Now().Format("2006-01-02") } recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr) if parseDateErr != nil { c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } mode_id, _ := c.GetInt64("mode_id", 0) dialysis_duration, _ := c.GetFloat("dialysis_duration", 0) dialyzer, _ := c.GetInt64("dialyzer", 0) perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0) blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0) dewater_amount, _ := c.GetFloat("dewater_amount", 0) displace_liqui, _ := c.GetFloat("displace_liqui", 0) replacement_total, _ := c.GetFloat("replacement_total", 0) replacement_way, _ := c.GetInt64("replacement_way", 0) anticoagulant, _ := c.GetInt64("anticoagulant", 0) anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0) anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0) anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0) anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng") anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang") dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus") kalium, _ := c.GetFloat("kalium", 0) sodium, _ := c.GetFloat("sodium", 0) calcium, _ := c.GetFloat("calcium", 0) bicarbonate, _ := c.GetFloat("bicarbonate", 0) glucose, _ := c.GetFloat("glucose", 0) // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0) // dry_weight, _ := c.GetFloat("dry_weight", 0) dialysate_flow, _ := c.GetFloat("dialysate_flow", 0) dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0) conductivity, _ := c.GetFloat("conductivity", 0) remark := c.GetString("remark") dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0) dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0) targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0) dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0) body_fluid, _ := c.GetInt64("body_fluid", 0) special_medicine, _ := c.GetInt64("special_medicine", 0) special_medicine_other := c.GetString("special_medicine_other") displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0) displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0) blood_access, _ := c.GetInt64("blood_access", 0) ultrafiltration, _ := c.GetFloat("ultrafiltration", 0) body_fluid_other := c.GetString("body_fluid_other") niprocart, _ := c.GetInt64("niprocart", 0) jms, _ := c.GetInt64("jms", 0) fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0) fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0) hemoperfusion, _ := c.GetInt64("hemoperfusion", 0) dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0) filtryzer, _ := c.GetInt64("filtryzer", 0) target_ktv, _ := c.GetFloat("target_ktv", 0) dialyzers, _ := c.GetInt64("dialyzers", 0) injector, _ := c.GetInt64("injector", 0) bloodlines, _ := c.GetInt64("bloodlines", 0) tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0) safe_package, _ := c.GetInt64("package", 0) a_liquid, _ := c.GetInt64("a_liquid", 0) pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0) fmt.Println("预冲量====", pre_impulse) anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0) anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0) blood := c.GetString("blood") dialysis_dialyszers := c.GetString("dialysis_dialyszers") dialysis_irrigation := c.GetString("dialysis_irrigation") antioxidant_commodity_name := c.GetString("antioxidant_commodity_name") appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id) //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id) // //if template.TemplateId == 2 || template.TemplateId == 6 { // if appRole.UserType == 3 { // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse) // if getPermissionErr != nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return // } else if headNursePermission == nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify) // return // } // } //} //TODO 需要根据角色去判断 prescription := models.DialysisPrescription{ UserOrgId: adminUserInfo.Org.Id, PatientId: id, RecordDate: recordDate.Unix(), ModeId: mode_id, DialysisDuration: dialysis_duration, Dialyzer: dialyzer, PerfusionApparatus: perfusion_apparatus, BloodFlowVolume: blood_flow_volume, DewaterAmount: dewater_amount, DisplaceLiqui: displace_liqui, ReplacementWay: replacement_way, Anticoagulant: anticoagulant, AnticoagulantShouji: anticoagulant_shouji, AnticoagulantWeichi: anticoagulant_weichi, AnticoagulantZongliang: anticoagulant_zongliang, AnticoagulantGaimingcheng: anticoagulant_gaimingcheng, AnticoagulantGaijiliang: anticoagulant_gaijiliang, Kalium: kalium, Sodium: sodium, Calcium: calcium, Bicarbonate: bicarbonate, Glucose: glucose, // DryWeight: dry_weight, DialysateFlow: dialysate_flow, DialysateTemperature: dialysate_temperature, // PrescriptionDoctor: prescription_doctor, ReplacementTotal: replacement_total, Conductivity: conductivity, Remark: remark, Status: 1, CreatedTime: time.Now().Unix(), UpdatedTime: time.Now().Unix(), DialysisDurationMinute: dialysisDurationMinute, DialysisDurationHour: dialysisDurationHour, TargetUltrafiltration: targetUltrafiltration, DialysateFormulation: dialysateFormulation, DialyzerPerfusionApparatus: dialyzerPerfusionApparatus, BodyFluid: body_fluid, SpecialMedicine: special_medicine, SpecialMedicineOther: special_medicine_other, DisplaceLiquiPart: displace_liqui_part, DisplaceLiquiValue: displace_liqui_value, BloodAccess: blood_access, Ultrafiltration: ultrafiltration, BodyFluidOther: body_fluid_other, Niprocart: niprocart, Jms: jms, FistulaNeedleSet: fistula_needle_set, FistulaNeedleSet16: fistula_needle_set_16, Hemoperfusion: hemoperfusion, DialyserSterilised: dialyser_sterilised, Filtryzer: filtryzer, Dialyzers: dialyzers, Injector: injector, Bloodlines: bloodlines, TubingHemodialysis: tubing_hemodialysis, Package: safe_package, ALiquid: a_liquid, TargetKtv: target_ktv, PreImpulse: pre_impulse, AnticoagulantStopTimeHour: anticoagulant_stop_time_hour, AnticoagulantStopTimeMin: anticoagulant_stop_time_min, Blood: blood, DialysisDialyszers: dialysis_dialyszers, DialysisIrrigation: dialysis_irrigation, AntioxidantCommodityName: antioxidant_commodity_name, } _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id) if dialysisPrescription.ID == 0 { //新增 //if mode_id > 0 { // //service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id) //} if appRole.UserType == 2 || appRole.UserType == 1 { prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id } prescription.Creater = adminUserInfo.AdminUser.Id err := service.AddSigleRecord(&prescription) if err == nil { updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id) if updateErr != nil { utils.ErrorLog("%v", updateErr) } c.ServeSuccessJSON(map[string]interface{}{ "prescription": prescription, }) } } else { //修改 //if mode_id > 0 { // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id) //} //if template.TemplateId == 1 { // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 { // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse) // if getPermissionErr != nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return // } else if headNursePermission == nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify) // return // } // } //} prescription.CreatedTime = dialysisPrescription.CreatedTime prescription.Modifier = adminUserInfo.AdminUser.Id if appRole.UserType == 2 || appRole.UserType == 1 { prescription_doctor := adminUserInfo.AdminUser.Id prescription.PrescriptionDoctor = prescription_doctor } else { prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor } if dialysisPrescription.Creater == 0 { //体重称 prescription.Creater = adminUserInfo.AdminUser.Id } else { prescription.Creater = dialysisPrescription.Creater } prescription.ID = dialysisPrescription.ID err := service.UpDateDialysisPrescription(&prescription) if err == nil { updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id) if updateErr != nil { utils.ErrorLog("%v", updateErr) } c.ServeSuccessJSON(map[string]interface{}{ "prescription": prescription, }) } } } func (c *DialysisAPIController) Finish() { id, _ := c.GetInt64("patient", 0) recordDateStr := c.GetString("record_date") nurseID, _ := c.GetInt64("nurse") end_time := c.GetString("end_time") if id <= 0 || nurseID <= 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminUserInfo := c.GetMobileAdminUserInfo() patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id) if patient.ID == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist) return } nurse, getNurseErr := service.GetAdminUserByUserID(nurseID) if getNurseErr != nil { c.ErrorLog("获取护士失败:%v", getNurseErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } else if nurse == nil { c.ErrorLog("护士不存在") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } if len(recordDateStr) == 0 { recordDateStr = time.Now().Format("2006-01-02") } recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr) if parseDateErr != nil { c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time) if parseEndDateErr != nil { c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } //now := time.Now() //year, month, day := now.Date() //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local) //todayTimeStamp := today_time.Unix() // 获取当天的第一条透析纪录 fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix()) if getMonitorRecordsErr != nil { c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } // 获取当前的最后一条透析纪录 endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.Org.Id, id, recordDate.Unix()) if getMonitorRecordsErr != nil { c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } fmt.Println(endmonitorRecords.UltrafiltrationVolume) assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix()) if getAADErr != nil { c.ErrorLog("获取透后评估失败:%v", getAADErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix()) _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix()) var tempassessmentAfterDislysis models.AssessmentAfterDislysis if assessmentAfterDislysis != nil { tempassessmentAfterDislysis = *assessmentAfterDislysis tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix() } else { tempassessmentAfterDislysis.CreatedTime = time.Now().Unix() tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix() tempassessmentAfterDislysis.Status = 1 tempassessmentAfterDislysis.PatientId = id tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id } if dialysisOrder.Stage == 1 { temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600 value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64) fmt.Println(value) a, b := math.Modf(value) c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64) hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64) minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64) fmt.Println(hour) fmt.Println(minute) tempassessmentAfterDislysis.ActualTreatmentHour = hour tempassessmentAfterDislysis.ActualTreatmentMinute = minute } if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 { //var num1 int64 //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime //fmt.Println(num1) //sub := float64(num1 / 3600) //fmt.Println(sub) //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub)) //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60) //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2)) tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity } if adminUserInfo.Org.Id == 9583 { //获取透析处方的最后一条数据 diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix()) if diaerr != nil { c.ErrorLog("获取透析处方失败:%v", diaerr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 { tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration } } if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 { tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume } if lastAssessmentAfterDislysis != nil { tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial } err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if dialysisOrder == nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart) return } if dialysisOrder.Stage == 2 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND) return } if dialysisOrder.Stage == 1 { err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id) //结束时候透析次数加1 service.UpdateSolutionByPatientId(id) dialysisOrder.Stage = 2 dialysisOrder.FinishNurse = nurseID dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id dialysisOrder.EndTime = endDate.Unix() go func() { ssoDomain := beego.AppConfig.String("call_domain") api := ssoDomain + "/index/downpatient" values := make(url.Values) values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10)) values.Set("admin_user_id", strconv.FormatInt(nurseID, 10)) values.Set("patient_id", strconv.FormatInt(id, 10)) http.PostForm(api, values) }() if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "dialysisOrder": dialysisOrder, "assessmentAfterDislysis": tempassessmentAfterDislysis, }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) } } } func (c *DialysisAPIController) GetAllZone() { adminUserInfo := c.GetMobileAdminUserInfo() err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "zone": zone, }) } } func (c *DialysisAPIController) GetSchedualPatientsList() { adminUserInfo := c.GetMobileAdminUserInfo() page, _ := c.GetInt64("page", 1) limit, _ := c.GetInt64("limit", 10) schedulType, _ := c.GetInt64("schedul_type", 0) startTime, _ := c.GetInt64("schedul_time", 0) partitionType, _ := c.GetInt64("partition_type", 0) keywords := c.GetString("keywords") dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "schedule": dialysisSchedule, }) } return } // /m/api/dialysis/start [post] // @param patient_id:int // @param record_date:string 排班时间 (yyyy-mm-dd) // @param nurse:int 上机护士 // @param bed:int 床位号 func (this *DialysisAPIController) StartDialysis() { patientID, _ := this.GetInt64("patient_id") recordDateStr := this.GetString("record_date") nurseID, _ := this.GetInt64("nurse") puncture_nurse, _ := this.GetInt64("puncture_nurse") blood_drawing, _ := this.GetInt64("blood_drawing") schedual_type, _ := this.GetInt64("schedual_type") bedID, _ := this.GetInt64("bed") start_time := this.GetString("start_time") washpipe_nurse, _ := this.GetInt64("washpipe_nurse") change_nurse, _ := this.GetInt64("change_nurse") difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse") new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse") if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time) if parseStartDateErr != nil { this.ErrorLog("时间解析失败:%v", parseStartDateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr) if parseErr != nil { this.ErrorLog("时间解析失败:%v", parseErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminUserInfo := this.GetMobileAdminUserInfo() patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID) if getPatientErr != nil { this.ErrorLog("获取患者信息失败:%v", getPatientErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } else if patient == nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist) return } nurse, getNurseErr := service.GetAdminUserByUserID(nurseID) if getNurseErr != nil { this.ErrorLog("获取护士失败:%v", getNurseErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } else if nurse == nil { this.ErrorLog("护士不存在") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse) if getNurseErr != nil { this.ErrorLog("获取护士失败:%v", getNurseErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } else if nurse == nil { this.ErrorLog("护士不存在") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID) if getDeviceNumberErr != nil { this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } else if deviceNumber == nil { this.ErrorLog("床位号不存在") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix()) if getRecordErr != nil { this.ErrorLog("获取透析记录失败:%v", getRecordErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } else if dialysisRecord != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart) return } scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00" scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59" timeLayout := "2006-01-02 15:04:05" loc, _ := time.LoadLocation("Local") theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc) theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc) schedulestartTime := theStartTime.Unix() scheduleendTime := theEndTime.Unix() template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id) //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机 schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type) //查询该床位是否有人用了 order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type) if err == gorm.ErrRecordNotFound { //空床位 // 修改了床位逻辑 daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID) if daySchedule.ID > 0 { daySchedule.PartitionId = deviceNumber.ZoneID daySchedule.BedId = bedID daySchedule.ScheduleType = schedual_type daySchedule.UpdatedTime = time.Now().Unix() err := service.UpdateSchedule(&daySchedule) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } } else if err == nil { if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录 if order_err == nil { if order.ID > 0 { //该机位被其他人占用了 this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed) return } else { daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID) if daySchedule.ID > 0 { daySchedule.PartitionId = deviceNumber.ZoneID daySchedule.BedId = bedID daySchedule.ScheduleType = schedual_type daySchedule.UpdatedTime = time.Now().Unix() err := service.UpdateSchedule(&daySchedule) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } } } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用 daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID) if daySchedule.ID > 0 { daySchedule.PartitionId = deviceNumber.ZoneID daySchedule.BedId = bedID daySchedule.ScheduleType = schedual_type daySchedule.UpdatedTime = time.Now().Unix() err := service.UpdateSchedule(&daySchedule) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } } } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录 this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed) return } } else if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } dialysisRecord = &models.DialysisOrder{ DialysisDate: recordDate.Unix(), UserOrgId: adminUserInfo.Org.Id, PatientId: patientID, Stage: 1, BedID: bedID, StartNurse: nurseID, Status: 1, StartTime: startDate.Unix(), CreatedTime: time.Now().Unix(), UpdatedTime: time.Now().Unix(), PunctureNurse: puncture_nurse, Creator: adminUserInfo.AdminUser.Id, Modifier: adminUserInfo.AdminUser.Id, SchedualType: schedual_type, WashpipeNurse: washpipe_nurse, ChangeNurse: change_nurse, DifficultPunctureNurse: difficult_puncture_nurse, NewFistulaNurse: new_fistula_nurse, } createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord) newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix()) var tempdispose string // 只针对中能建 if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 { tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min" } var ultrafiltration_rate float64 _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id) if prescription.ID > 0 { if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 { totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute if template.TemplateId == 6 || template.TemplateId == 32 { //adminUserInfo.Org.Id == 9538 ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000) } if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538 ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60) } // 只针对方济医院 if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 { value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6) ultrafiltration_rate = value } } } record := models.MonitoringRecord{ UserOrgId: adminUserInfo.Org.Id, PatientId: patientID, DialysisOrderId: dialysisRecord.ID, MonitoringDate: schedulestartTime, OperateTime: startDate.Unix(), // MonitoringTime: recordTime, MonitoringNurse: nurseID, Dispose: tempdispose, UltrafiltrationRate: ultrafiltration_rate, UltrafiltrationVolume: 0, Status: 1, CreatedTime: time.Now().Unix(), UpdatedTime: time.Now().Unix(), } //只针对广慈医院 if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 { // 查询病人是否有透前评估数据 befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix()) //如果有数据就插入 if errcode == nil { record.SystolicBloodPressure = befor.SystolicBloodPressure record.DiastolicBloodPressure = befor.DiastolicBloodPressure record.BreathingRate = befor.BreathingRate record.PulseFrequency = befor.PulseFrequency record.Temperature = befor.Temperature } } // 如果当天有插入数据,则不再往透析纪录里插入数据 if newdialysisRecord.ID > 0 { err := service.CreateMonitor(&record) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate) return } } go func() { ssoDomain := beego.AppConfig.String("call_domain") api := ssoDomain + "/index/uppatient" values := make(url.Values) values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10)) values.Set("admin_user_id", strconv.FormatInt(nurseID, 10)) values.Set("patient_id", strconv.FormatInt(patientID, 10)) values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10)) http.PostForm(api, values) }() if createErr != nil { this.ErrorLog("上机失败:%v", createErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } this.ServeSuccessJSON(map[string]interface{}{ "dialysis_order": newdialysisRecord, "monitor": record, }) } func (c *DialysisAPIController) PostSolution() { id, _ := c.GetInt64("patient", 0) recordDateStr := c.GetString("record_date") if id <= 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminUserInfo := c.GetMobileAdminUserInfo() patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id) if patient.ID == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist) return } if len(recordDateStr) == 0 { recordDateStr = time.Now().Format("2006-01-02") } recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr) if parseDateErr != nil { c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } mode_id, _ := c.GetInt64("mode_id", 0) dialysis_duration, _ := c.GetFloat("dialysis_duration", 0) dialyzer, _ := c.GetInt64("dialyzer", 0) perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0) blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0) dewater_amount, _ := c.GetFloat("dewater_amount", 0) displace_liqui, _ := c.GetFloat("displace_liqui", 0) replacement_way, _ := c.GetInt64("replacement_way", 0) anticoagulant, _ := c.GetInt64("anticoagulant", 0) anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0) anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0) anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0) anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng") anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang") kalium, _ := c.GetFloat("kalium", 0) sodium, _ := c.GetFloat("sodium", 0) calcium, _ := c.GetFloat("calcium", 0) bicarbonate, _ := c.GetFloat("bicarbonate", 0) prescription_doctor, _ := c.GetInt64("prescription_doctor", 0) dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus") glucose, _ := c.GetFloat("glucose", 0) // dry_weight, _ := c.GetFloat("dry_weight", 0) dialysate_flow, _ := c.GetFloat("dialysate_flow", 0) dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0) conductivity, _ := c.GetFloat("conductivity", 0) remark := c.GetString("remark") dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0) dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0) targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0) dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0) body_fluid, _ := c.GetInt64("body_fluid", 0) special_medicine, _ := c.GetInt64("special_medicine", 0) special_medicine_other := c.GetString("special_medicine_other") displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0) displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0) blood_access, _ := c.GetInt64("blood_access", 0) ultrafiltration, _ := c.GetFloat("ultrafiltration", 0) body_fluid_other := c.GetString("body_fluid_other") replacement_total, _ := c.GetFloat("replacement_total", 0) niprocart, _ := c.GetInt64("niprocart", 0) jms, _ := c.GetInt64("jms", 0) fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0) fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0) hemoperfusion, _ := c.GetInt64("hemoperfusion", 0) dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0) filtryzer, _ := c.GetInt64("filtryzer", 0) target_ktv, _ := c.GetFloat("target_ktv", 0) dialyzers, _ := c.GetInt64("dialyzers", 0) injector, _ := c.GetInt64("injector", 0) bloodlines, _ := c.GetInt64("bloodlines", 0) tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0) safe_package, _ := c.GetInt64("package", 0) a_liquid, _ := c.GetInt64("a_liquid", 0) anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0) anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0) blood := c.GetString("blood") dialysis_dialyszers := c.GetString("dialysis_dialyszers") dialysis_irrigation := c.GetString("dialysis_irrigation") antioxidant_commodity_name := c.GetString("antioxidant_commodity_name") if mode_id > 0 { service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id) } //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id) // //if template.TemplateId == 2 || template.TemplateId == 6 { // if appRole.UserType == 3 { // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse) // if getPermissionErr != nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return // } else if headNursePermission == nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify) // return // } // } //} prescription := models.DialysisPrescription{ UserOrgId: adminUserInfo.Org.Id, PatientId: id, RecordDate: recordDate.Unix(), ModeId: mode_id, DialysisDuration: dialysis_duration, Dialyzer: dialyzer, PerfusionApparatus: perfusion_apparatus, BloodFlowVolume: blood_flow_volume, DewaterAmount: dewater_amount, DisplaceLiqui: displace_liqui, ReplacementWay: replacement_way, Anticoagulant: anticoagulant, AnticoagulantShouji: anticoagulant_shouji, AnticoagulantWeichi: anticoagulant_weichi, AnticoagulantZongliang: anticoagulant_zongliang, AnticoagulantGaimingcheng: anticoagulant_gaimingcheng, AnticoagulantGaijiliang: anticoagulant_gaijiliang, Kalium: kalium, Sodium: sodium, Calcium: calcium, Bicarbonate: bicarbonate, Glucose: glucose, // DryWeight: dry_weight, DialysateFlow: dialysate_flow, DialysateTemperature: dialysate_temperature, Conductivity: conductivity, Remark: remark, Status: 1, CreatedTime: time.Now().Unix(), UpdatedTime: time.Now().Unix(), DialysisDurationMinute: dialysisDurationMinute, DialysisDurationHour: dialysisDurationHour, TargetUltrafiltration: targetUltrafiltration, DialysateFormulation: dialysateFormulation, DialyzerPerfusionApparatus: dialyzerPerfusionApparatus, BodyFluid: body_fluid, SpecialMedicine: special_medicine, SpecialMedicineOther: special_medicine_other, DisplaceLiquiPart: displace_liqui_part, DisplaceLiquiValue: displace_liqui_value, BloodAccess: blood_access, Ultrafiltration: ultrafiltration, BodyFluidOther: body_fluid_other, ReplacementTotal: replacement_total, Niprocart: niprocart, Jms: jms, FistulaNeedleSet: fistula_needle_set, FistulaNeedleSet16: fistula_needle_set_16, Hemoperfusion: hemoperfusion, DialyserSterilised: dialyser_sterilised, Filtryzer: filtryzer, TargetKtv: target_ktv, Dialyzers: dialyzers, Injector: injector, Bloodlines: bloodlines, TubingHemodialysis: tubing_hemodialysis, Package: safe_package, ALiquid: a_liquid, AnticoagulantStopTimeMin: anticoagulant_stop_time_min, AnticoagulantStopTimeHour: anticoagulant_stop_time_hour, Blood: blood, DialysisDialyszers: dialysis_dialyszers, DialysisIrrigation: dialysis_irrigation, AntioxidantCommodityName: antioxidant_commodity_name, } _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id) appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id) // if appRole.UserType == 2 || appRole.UserType == 1 { prescription_doctor = adminUserInfo.AdminUser.Id prescription.PrescriptionDoctor = prescription_doctor } if dialysisPrescription.ID == 0 { //新增 prescription.Creater = adminUserInfo.AdminUser.Id } else { //修改 if dialysisPrescription.Creater == 0 { prescription.Creater = adminUserInfo.AdminUser.Id } else { prescription.Creater = dialysisPrescription.Creater } //if/**/ //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id) //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 { // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse) // if getPermissionErr != nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return // } else if headNursePermission == nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify) // return // } //} //prescription.Creater = dialysisPrescription.Creater prescription.CreatedTime = dialysisPrescription.CreatedTime prescription.Modifier = adminUserInfo.AdminUser.Id prescription.ID = dialysisPrescription.ID } solution := models.DialysisSolution{ RegistrarsId: adminUserInfo.AdminUser.Id, UserOrgId: adminUserInfo.Org.Id, Doctor: prescription_doctor, PatientId: id, ModeId: mode_id, DialysisDuration: dialysis_duration, PerfusionApparatus: perfusion_apparatus, BloodFlowVolume: blood_flow_volume, Dewater: dewater_amount, DisplaceLiqui: displace_liqui, ReplacementWay: replacement_way, Anticoagulant: anticoagulant, AnticoagulantShouji: anticoagulant_shouji, AnticoagulantWeichi: anticoagulant_weichi, AnticoagulantZongliang: anticoagulant_zongliang, AnticoagulantGaimingcheng: anticoagulant_gaimingcheng, AnticoagulantGaijiliang: anticoagulant_gaijiliang, Kalium: kalium, Sodium: sodium, Calcium: calcium, Bicarbonate: bicarbonate, Glucose: glucose, // DryWeight: dry_weight, DialysateFlow: dialysate_flow, DialysateTemperature: dialysate_temperature, Conductivity: conductivity, Remark: remark, Status: 1, CreatedTime: time.Now().Unix(), UpdatedTime: time.Now().Unix(), DialysisDurationMinute: dialysisDurationMinute, DialysisDurationHour: dialysisDurationHour, TargetUltrafiltration: targetUltrafiltration, DialysateFormulation: dialysateFormulation, DialyzerPerfusionApparatus: dialyzerPerfusionApparatus, BodyFluid: body_fluid, SpecialMedicine: special_medicine, SpecialMedicineOther: special_medicine_other, DisplaceLiquiPart: displace_liqui_part, DisplaceLiquiValue: displace_liqui_value, BloodAccess: blood_access, Ultrafiltration: ultrafiltration, BodyFluidOther: body_fluid_other, ReplacementTotal: replacement_total, TargetKtv: target_ktv, } service.SavePrescriptionAndCreateSolution(&solution, &prescription) c.ServeSuccessJSON(map[string]interface{}{ "solution": &solution, "prescription": &prescription, }) } func (c *DialysisAPIController) GetAcceptsAssessment() { patient, _ := c.GetInt64("patient", 0) adminUserInfo := c.GetMobileAdminUserInfo() _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id) c.ServeSuccessJSON(map[string]interface{}{ "receiveTreatmentAsses": receiveTreatmentAsses, }) } func (this *DialysisAPIController) PostSignInfo() { patientID, _ := this.GetInt64("patient_id") recordDateStr := this.GetString("date") if patientID <= 0 { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } if len(recordDateStr) == 0 { recordDateStr = time.Now().Format("2006-01-02") } date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr) if parseDateErr != nil { this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminInfo := this.GetMobileAdminUserInfo() err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id) if err != nil { this.ErrorLog("签名失败:%v", err) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } this.ServeSuccessJSON(map[string]interface{}{ "doctor_id": adminInfo.AdminUser.Id, }) } func (this *DialysisAPIController) GetLastMonitorRecord() { patientID, _ := this.GetInt64("patient_id") adminInfo := this.GetMobileAdminUserInfo() record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id) this.ServeSuccessJSON(map[string]interface{}{ "monitor": record, }) } func (this *DialysisAPIController) GetLastMonitorRecordTody() { thisTime := time.Now() scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00" timeLayout := "2006-01-02 15:04:05" loc, _ := time.LoadLocation("Local") theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc) theAssessmentDateTime := theStartTime.Unix() patientID, _ := this.GetInt64("patient_id") monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime) adminInfo := this.GetMobileAdminUserInfo() record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate) fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate) template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id) var ultrafiltration_rate float64 _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id) if prescription.ID > 0 { if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 { totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute if template.TemplateId == 6 { ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000) record.UltrafiltrationRate = ultrafiltration_rate } if template.TemplateId == 32 || template.TemplateId == 34 { ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1) record.UltrafiltrationRate = ultrafiltration_rate } if template.TemplateId == 20 || template.TemplateId == 22 { ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60) record.UltrafiltrationRate = ultrafiltration_rate } // 只针对方济医院 if template.TemplateId == 1 && adminInfo.Org.Id != 9849 { value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6) ultrafiltration_rate = value record.UltrafiltrationRate = ultrafiltration_rate } } } // record.UltrafiltrationRate = ultrafiltration_rate record.UltrafiltrationVolume = 0 if template.TemplateId == 1 && adminInfo.Org.Id != 9849 { //adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535 if ultrafiltration_rate > 0 { value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6) record.UltrafiltrationVolume = value } } if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 { //adminInfo.Org.Id == 9538 if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 { ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate) record.UltrafiltrationVolume = ultrafiltration_volume } } this.ServeSuccessJSON(map[string]interface{}{ "monitor": record, }) } func (this *DialysisAPIController) ModifyStartDialysisOrder() { record_id, _ := this.GetInt64("id") nurseID, _ := this.GetInt64("nurse") puncture_nurse, _ := this.GetInt64("puncture_nurse") bedID, _ := this.GetInt64("bed") start_time := this.GetString("start_time") schedual_type, _ := this.GetInt64("schedual_type") washpipe_nurse, _ := this.GetInt64("washpipe_nurse") change_nurse, _ := this.GetInt64("change_nurse") difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse") new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse") if record_id == 0 { this.ErrorLog("id:%v", record_id) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time) if parseStartDateErr != nil { this.ErrorLog("时间解析失败:%v", parseStartDateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminUserInfo := this.GetMobileAdminUserInfo() nurse, getNurseErr := service.GetAdminUserByUserID(nurseID) if getNurseErr != nil { this.ErrorLog("获取护士失败:%v", getNurseErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } else if nurse == nil { this.ErrorLog("护士不存在") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse) if getNurseErr != nil { this.ErrorLog("获取护士失败:%v", getNurseErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } else if nurse == nil { this.ErrorLog("护士不存在") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID) if getDeviceNumberErr != nil { this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } else if deviceNumber == nil { this.ErrorLog("床位号不存在") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } _, tempDialysisRecord := service.FindDialysisOrderById(record_id) // //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id { // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse) // if getPermissionErr != nil { // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return // } else if headNursePermission == nil { // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify) // return // } //} scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00" scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59" timeLayout := "2006-01-02 15:04:05" loc, _ := time.LoadLocation("Local") theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc) theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc) schedulestartTime := theStartTime.Unix() scheduleendTime := theEndTime.Unix() //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机 schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type) daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId) if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type { if err == gorm.ErrRecordNotFound { //空床位 // 修改了床位逻辑 daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId) if daySchedule.ID > 0 { daySchedule.BedId = bedID daySchedule.PartitionId = deviceNumber.ZoneID daySchedule.ScheduleType = schedual_type daySchedule.UpdatedTime = time.Now().Unix() err := service.UpdateSchedule(&daySchedule) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } } else if err == nil { if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录 daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId) if daySchedule.ID > 0 { daySchedule.BedId = bedID daySchedule.PartitionId = deviceNumber.ZoneID daySchedule.ScheduleType = schedual_type daySchedule.UpdatedTime = time.Now().Unix() err := service.UpdateSchedule(&daySchedule) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录 this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed) return } } else if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } dialysisRecord := &models.DialysisOrder{ ID: record_id, UserOrgId: adminUserInfo.Org.Id, BedID: bedID, StartNurse: nurseID, StartTime: startDate.Unix(), PunctureNurse: puncture_nurse, Creator: adminUserInfo.AdminUser.Id, Modifier: adminUserInfo.AdminUser.Id, WashpipeNurse: washpipe_nurse, SchedualType: schedual_type, ChangeNurse: change_nurse, DifficultPunctureNurse: difficult_puncture_nurse, NewFistulaNurse: new_fistula_nurse, } updateErr := service.ModifyStartDialysisOrder(dialysisRecord) if updateErr != nil { this.ErrorLog("修改上机失败:%v", updateErr) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if updateErr == nil { if tempDialysisRecord.Stage == 2 { temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600 value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64) fmt.Println(value) a, b := math.Modf(value) tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64) hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64) minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64) updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute) if updateAssessmentErr != nil { utils.ErrorLog("%v", updateAssessmentErr) } } } _, dialysisRecords := service.FindDialysisOrderById(record_id) this.ServeSuccessJSON(map[string]interface{}{ "dialysis_order": dialysisRecords, }) } func (c *DialysisAPIController) ModifyFinishDialysisOrder() { record_id, _ := c.GetInt64("id") nurseID, _ := c.GetInt64("nurse") end_time := c.GetString("end_time") if record_id <= 0 || nurseID <= 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminUserInfo := c.GetMobileAdminUserInfo() nurse, getNurseErr := service.GetAdminUserByUserID(nurseID) if getNurseErr != nil { c.ErrorLog("获取护士失败:%v", getNurseErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } else if nurse == nil { c.ErrorLog("护士不存在") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time) if parseEndDateErr != nil { c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } _, tempDialysisRecords := service.FindDialysisOrderById(record_id) //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id { // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse) // if getPermissionErr != nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return // } else if headNursePermission == nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify) // return // } //} dialysisRecord := &models.DialysisOrder{ ID: record_id, UserOrgId: adminUserInfo.Org.Id, EndTime: endDate.Unix(), FinishNurse: nurseID, FinishModifier: adminUserInfo.AdminUser.Id, } updateErr := service.ModifyFinishDialysisOrder(dialysisRecord) if updateErr != nil { c.ErrorLog("修改下机失败:%v", updateErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if updateErr == nil { temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600 value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64) a, b := math.Modf(value) tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64) hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64) minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64) updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute) if updateAssessmentErr != nil { utils.ErrorLog("%v", updateAssessmentErr) } } _, dialysisRecords := service.FindDialysisOrderById(record_id) c.ServeSuccessJSON(map[string]interface{}{ "dialysis_order": dialysisRecords, }) } func (c *DialysisAPIController) GetLongAdvice() { patient_id, _ := c.GetInt64("id") adminUserInfo := c.GetMobileAdminUserInfo() _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id) //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id) if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理 c.ServeSuccessJSON(map[string]interface{}{ "status": "1", }) return } else { //开启推送提醒 //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送 var advice_three []*models.DoctorAdvice //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id) advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id) advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id) for _, advice := range advices { if advice.FrequencyType == 3 { t := time.Now() week := int(t.Weekday()) fmt.Println(t.Weekday()) fmt.Println(week) switch week { case 1: if strings.Index(advice.WeekDay, "周一") == -1 { advice_three = append(advice_three, advice) } break case 2: if strings.Index(advice.WeekDay, "周二") == -1 { advice_three = append(advice_three, advice) } break case 3: if strings.Index(advice.WeekDay, "周三") == -1 { advice_three = append(advice_three, advice) } break case 4: if strings.Index(advice.WeekDay, "周四") == -1 { advice_three = append(advice_three, advice) } break case 5: if strings.Index(advice.WeekDay, "周五") == -1 { advice_three = append(advice_three, advice) } break case 6: if strings.Index(advice.WeekDay, "周六") == -1 { advice_three = append(advice_three, advice) } break case 0: if strings.Index(advice.WeekDay, "周日") == -1 { advice_three = append(advice_three, advice) } break } } } for _, advice := range advices_two { p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02")) now := p.Unix() dayStr := strconv.FormatInt(advice.DayCount, 10) dayStr2 := "-" + dayStr count, _ := strconv.ParseInt(dayStr2, 10, 64) oldTime := time.Now().AddDate(0, 0, int(count)).Unix() advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId) for _, ad := range advices { advice_three = append(advice_three, ad) } } if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "status": "2", "advices": advices, "advices_two": RemoveRepeatedElement(advice_three), "is_open_remind": config.IsOpenRemind, }) } } } func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) { newArr = make([]*models.DoctorAdvice, 0) for i := 0; i < len(arr); i++ { repeat := false for j := i + 1; j < len(arr); j++ { if arr[i].ID == arr[j].ID { repeat = true break } } if !repeat { newArr = append(newArr, arr[i]) } } return } func (c *DialysisAPIController) CreateRemindDoctorAdvice() { patient, _ := c.GetInt64("id", 0) groupNo, _ := c.GetInt64("groupno", 0) if patient <= 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminUserInfo := c.GetMobileAdminUserInfo() dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody) if err != nil { utils.ErrorLog(err.Error()) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } utils.ErrorLog("%v", dataBody) timeLayout := "2006-01-02 15:04" loc, _ := time.LoadLocation("Local") timeLayout2 := "2006-01-02" loc2, _ := time.LoadLocation("Local") if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" { utils.ErrorLog("advice_type") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adviceType := int64(2) if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" { utils.ErrorLog("advice_date") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adviceDate, _ := dataBody["advice_date"].(string) theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2) AdviceDate := theTime.Unix() RecordDate := theTime.Unix() if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" { utils.ErrorLog("start_time") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } startTime, _ := dataBody["start_time"].(string) if len(startTime) == 0 { utils.ErrorLog("len(start_time) == 0") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } theTime, err = time.ParseInLocation(timeLayout, startTime, loc) if err != nil { utils.ErrorLog(err.Error()) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } StartTime := theTime.Unix() Remark := "" if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" { remark, _ := dataBody["remark"].(string) Remark = remark } var advices []*models.GroupAdvice if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" { utils.ErrorLog("advices") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adviceNames := dataBody["advices"].([]interface{}) for _, adviceNameMap := range adviceNames { adviceNameM := adviceNameMap.(map[string]interface{}) var advice models.GroupAdvice advice.Remark = Remark advice.AdviceType = adviceType advice.StartTime = StartTime advice.AdviceDate = AdviceDate advice.RecordDate = RecordDate advice.Status = 1 advice.CreatedTime = time.Now().Unix() advice.UpdatedTime = time.Now().Unix() advice.StopState = 2 advice.ExecutionState = 2 advice.UserOrgId = adminUserInfo.Org.Id advice.PatientId = patient advice.AdviceDoctor = adminUserInfo.AdminUser.Id if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" { utils.ErrorLog("advice_name") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adviceName, _ := adviceNameM["advice_name"].(string) if len(adviceName) == 0 { utils.ErrorLog("len(advice_name) == 0") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } advice.AdviceName = adviceName if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" { drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64) advice.DrugSpec = drugSpec } if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" { adviceDesc, _ := adviceNameM["advice_desc"].(string) advice.AdviceDesc = adviceDesc } if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" { drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string) advice.DrugSpecUnit = drugSpecUnit } //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" { // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64) // advice.SingleDose = singleDose //} if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" { //single_dose := int64(adviceNameM["single_dose"].(float64)) advice.SingleDose = adviceNameM["single_dose"].(float64) } if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" { singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string) advice.SingleDoseUnit = singleDoseUnit } //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" { // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64) // advice.PrescribingNumber = prescribingNumber //} if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" { //single_dose := int64(adviceNameM["single_dose"].(float64)) advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64) } if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" { prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string) advice.PrescribingNumberUnit = prescribingNumberUnit } if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" { deliveryWay, _ := adviceNameM["delivery_way"].(string) advice.DeliveryWay = deliveryWay } if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" { executionFrequency, _ := adviceNameM["execution_frequency"].(string) advice.ExecutionFrequency = executionFrequency } if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" { frequency_type := int64(adviceNameM["frequency_type"].(float64)) advice.FrequencyType = frequency_type } if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" { day_count := int64(adviceNameM["day_count"].(float64)) advice.DayCount = day_count } if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" { week_day, _ := adviceNameM["week_day"].(string) advice.WeekDay = week_day } if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" { way := int64(adviceNameM["way"].(float64)) advice.Way = way } if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" { drug_id := int64(adviceNameM["drug_id"].(float64)) advice.DrugId = drug_id } if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" { drug_name_id := int64(adviceNameM["drug_name_id"].(float64)) advice.DrugNameId = drug_name_id } if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" { template_id, _ := adviceNameM["template_id"].(string) advice.TemplateId = template_id } if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" { executionFrequency, _ := adviceNameM["execution_frequency"].(string) advice.ExecutionFrequency = executionFrequency } if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" { children := adviceNameM["child"].([]interface{}) if len(children) > 0 { for _, childrenMap := range children { childMap := childrenMap.(map[string]interface{}) var child models.GroupAdvice child.Remark = Remark child.AdviceType = adviceType child.StartTime = StartTime child.AdviceDate = AdviceDate child.RecordDate = RecordDate child.Status = 1 child.CreatedTime = time.Now().Unix() child.UpdatedTime = time.Now().Unix() child.StopState = 2 child.ExecutionState = 2 child.UserOrgId = adminUserInfo.Org.Id child.PatientId = patient child.AdviceDoctor = adminUserInfo.AdminUser.Id if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" { utils.ErrorLog("child advice_name") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } childAdviceName, _ := childMap["advice_name"].(string) if len(childAdviceName) == 0 { utils.ErrorLog("len(child advice_name) == 0") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } child.AdviceName = childAdviceName if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" { childAdviceDesc, _ := childMap["advice_desc"].(string) child.AdviceDesc = childAdviceDesc } if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" { childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64) child.DrugSpec = childDrugSpec } if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" { childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string) child.DrugSpecUnit = childDrugSpecUnit } if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" { child.SingleDose = childMap["single_dose"].(float64) } if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" { childSingleDoseUnit, _ := childMap["single_dose_unit"].(string) child.SingleDoseUnit = childSingleDoseUnit } if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" { child.PrescribingNumber = childMap["prescribing_number"].(float64) } if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" { childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string) child.PrescribingNumberUnit = childPrescribingNumberUnit } child.DeliveryWay = advice.DeliveryWay child.ExecutionFrequency = advice.ExecutionFrequency advice.Children = append(advice.Children, &child) } } } advices = append(advices, &advice) } list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail) return } c.ServeSuccessJSON(map[string]interface{}{ "msg": "ok", "advices": list, }) return } func (c *DialysisAPIController) UploadDryWeight() { patient_id, _ := c.GetInt64("id") dry_weight, _ := c.GetFloat("dry_weight") doctor_id, _ := c.GetInt64("doctor_id") remark := c.GetString("remark") adminUserInfo := c.GetMobileAdminUserInfo() weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id) if err == gorm.ErrRecordNotFound { dryWeight := &models.SgjPatientDryweight{ PatientId: patient_id, DryWeight: dry_weight, Remakes: remark, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Creator: doctor_id, Status: 1, UserOrgId: adminUserInfo.Org.Id, AdjustedValue: "/", UserId: adminUserInfo.AdminUser.Id, } createErr := service.CreatePatientWeightAdjust(dryWeight) if createErr == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "提交成功", "weight": dryWeight, }) } } else { dryWeight := &models.SgjPatientDryweight{ PatientId: patient_id, DryWeight: dry_weight, Remakes: remark, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Creator: doctor_id, Status: 1, UserOrgId: adminUserInfo.Org.Id, AdjustedValue: "/", UserId: adminUserInfo.AdminUser.Id, } var value float64 value = dry_weight - weightAdjust.DryWeight if value < 0 { dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)" } else if value == 0 { dryWeight.AdjustedValue = "/" } else if value > 0 { dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)" } createErr := service.CreatePatientWeightAdjust(dryWeight) if createErr == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "提交成功", "weight": dryWeight, }) } } } func (c *DialysisAPIController) GetSolution() { patient_id, _ := c.GetInt64("patient_id") mode_id, _ := c.GetInt64("mode_id") adminUserInfo := c.GetMobileAdminUserInfo() solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, patient_id, mode_id) prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient_id, mode_id) system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, mode_id) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } c.ServeSuccessJSON(map[string]interface{}{ "solution": solution, "prescription": prescription, "system_prescription": system_prescription, }) } func (c *DialysisAPIController) GetSchedule() { schedual_type, _ := c.GetInt64("schedual_type") adminUserInfo := c.GetMobileAdminUserInfo() timeLayout := "2006-01-02 15:04:05" date := time.Now().Format("2006-01-02") + " 00:00:00" loc, _ := time.LoadLocation("Local") theStartTime, _ := time.ParseInLocation(timeLayout, date, loc) scheduleTime := theStartTime.Unix() deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type) c.ServeSuccessJSON(map[string]interface{}{ "number": deviceNumber, }) } func (c *DialysisAPIController) GetPatientId() { id, _ := c.GetInt64("id") patientId, _ := service.GetPatientId(id) c.ServeSuccessJSON(map[string]interface{}{ "patient": patientId, }) } func (this *DialysisAPIController) GetDialysisSchedule() { schedualDate := this.GetString("date") date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate) if parseDateErr != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminInfo := this.GetMobileAdminUserInfo() orgID := adminInfo.Org.Id redis := service.RedisClient() defer redis.Close() key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10) scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0) if len(scheduals) > 0 { //缓存数据 scheduals_json, err := json.Marshal(scheduals) if err == nil { redis.Set(key, scheduals_json, time.Second*30) } } this.ServeSuccessJSON(map[string]interface{}{ "scheduals": scheduals, }) } func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() { change_type, _ := this.GetInt64("type", 0) record_date := this.GetString("record_time") patient_id, _ := this.GetInt64("patient_id", 0) timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc) record_time := theAdviceRecordTime.Unix() adminUserInfo := this.GetMobileAdminUserInfo() advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id) if err == nil { if len(advices) == 0 { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty) return } else { this.ServeSuccessJSON(map[string]interface{}{ "advices": advices, "schedule": sch, }) return } } else { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } } func (c *DialysisAPIController) CreateConsumables() { record_date := c.GetString("record_time") patient_id, _ := c.GetInt64("patient_id", 0) adminUser := c.GetMobileAdminUserInfo() timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc) record_time := theRecordTime.Unix() dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody) if err != nil { utils.ErrorLog(err.Error()) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } var beforePrepares []*models.DialysisBeforePrepare var updateBeforePrepares []*models.DialysisBeforePrepare if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" { goods, _ := dataBody["goods"].([]interface{}) if len(goods) > 0 { for _, item := range goods { items := item.(map[string]interface{}) if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" { utils.ErrorLog("good_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } good_id := int64(items["good_id"].(float64)) if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" { utils.ErrorLog("good_type_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } good_type_id := int64(items["good_type_id"].(float64)) if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" { utils.ErrorLog("count") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } count, _ := strconv.ParseInt(items["count"].(string), 10, 64) //commdity_code := items["commdity_code"].(string) //fmt.Println("新建22222222222222",commdity_code) adminUser := c.GetMobileAdminUserInfo() prepare := &models.DialysisBeforePrepare{ UserOrgId: adminUser.Org.Id, PatientId: patient_id, RecordDate: record_time, GoodId: good_id, GoodTypeId: good_type_id, Count: count, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Creater: adminUser.AdminUser.Id, Modifier: 0, //CommdityCode:commdity_code, } record_count := service.FindDialysisBeforePrepare(prepare.PatientId, prepare.GoodId, prepare.GoodTypeId, adminUser.Org.Id, record_time) if record_count == 0 { beforePrepares = append(beforePrepares, prepare) } } } } if len(beforePrepares) > 0 { service.CreateDialysisBeforePrepare(beforePrepares) } var errs error if dataBody["update_goods"] != nil && reflect.TypeOf(dataBody["update_goods"]).String() == "[]interface {}" { goods, _ := dataBody["update_goods"].([]interface{}) if len(goods) > 0 { for _, item := range goods { items := item.(map[string]interface{}) if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" { utils.ErrorLog("record_time") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } record_time := int64(items["record_time"].(float64)) if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" { utils.ErrorLog("id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } id := int64(items["id"].(float64)) if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" { utils.ErrorLog("patient_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } patient_id := int64(items["patient_id"].(float64)) if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" { utils.ErrorLog("creater") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } creater := int64(items["creater"].(float64)) if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" { utils.ErrorLog("good_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } good_id := int64(items["good_id"].(float64)) if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" { utils.ErrorLog("good_type_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } good_type_id := int64(items["good_type_id"].(float64)) if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" { utils.ErrorLog("count") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } count, _ := strconv.ParseInt(items["count"].(string), 10, 64) if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" { utils.ErrorLog("ctime") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } ctime := int64(items["ctime"].(float64)) //commdity_code := items["commdity_code"].(string) //fmt.Println("commdityecode22222222222222222222",commdity_code) prepare := &models.DialysisBeforePrepare{ ID: id, UserOrgId: adminUser.Org.Id, PatientId: patient_id, RecordDate: record_time, GoodId: good_id, GoodTypeId: good_type_id, Count: count, Ctime: ctime, Mtime: time.Now().Unix(), Creater: creater, Modifier: adminUser.AdminUser.Id, Status: 1, //CommdityCode: commdity_code, } updateBeforePrepares = append(updateBeforePrepares, prepare) } } //去重 updateBeforePrepares = RemoveRepeatedGood(updateBeforePrepares) if len(updateBeforePrepares) > 0 { for _, item := range updateBeforePrepares { errs = service.UpdateDialysisBeforePrepareTwo(item) } } } if errs == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "提交成功", }) return } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } } func (c *DialysisAPIController) CreateStockOutInfo() { patient_id, _ := c.GetInt64("patient_id", 0) record_date := c.GetString("record_time") if patient_id <= 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminInfo := c.GetMobileAdminUserInfo() timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc) record_time := theRecordTime.Unix() consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time) _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id) consumables = RemoveRepeatedGood(consumables) if record.IsOpen == 1 { out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time) if err == gorm.ErrRecordNotFound { //没有记录,则创建出库单 timeStr := time.Now().Format("2006-01-02") timeArr := strings.Split(timeStr, "-") total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id) total = total + 1 warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" number, _ := strconv.ParseInt(warehousing_out_order, 10, 64) number = number + total warehousing_out_order = "CKD" + strconv.FormatInt(number, 10) creater := adminInfo.AdminUser.Id warehouseOut := models.WarehouseOut{ WarehouseOutOrderNumber: warehousing_out_order, OperationTime: time.Now().Unix(), OrgId: adminInfo.Org.Id, Creater: creater, Ctime: time.Now().Unix(), Status: 1, WarehouseOutTime: record_time, Dealer: 0, Manufacturer: 0, Type: 1, IsSys: 1, } err := service.AddSigleWarehouseOut(&warehouseOut) if err != nil { utils.TraceLog("创建出库单失败 err = %v", err) } else { for _, item := range consumables { if item.Count > 0 { warehouseOutInfo := &models.WarehouseOutInfo{ WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber, WarehouseOutId: warehouseOut.ID, Status: 1, Ctime: time.Now().Unix(), Remark: "", OrgId: adminInfo.Org.Id, Type: 1, Manufacturer: 0, Dealer: 0, IsSys: 1, SysRecordTime: record_time, GoodTypeId: item.GoodTypeId, GoodId: item.GoodId, } warehouseOutInfo.Count = item.Count stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id) warehouseOutInfo.Price = stockInInfo.Price err := service.AddSigleWarehouseOutInfo(warehouseOutInfo) if err == nil { details := &models.AutomaticReduceDetail{ WarehouseOutId: warehouseOutInfo.ID, WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber, PatientId: patient_id, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Status: 1, RecordTime: record_time, OrgId: adminInfo.Org.Id, GoodId: item.GoodId, GoodTypeId: item.GoodTypeId, Count: item.Count, } service.AddSigleAutoReduceRecordInfo(details) } } } } } else if err == nil { for _, item := range consumables { outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber) if err == gorm.ErrRecordNotFound { warehouseOutInfo := &models.WarehouseOutInfo{ WarehouseOutOrderNumber: out.WarehouseOutOrderNumber, WarehouseOutId: out.ID, Status: 1, Ctime: time.Now().Unix(), Remark: "", OrgId: adminInfo.Org.Id, Type: 1, Manufacturer: 0, Dealer: 0, IsSys: 1, SysRecordTime: record_time, } stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id) warehouseOutInfo.Price = stockInInfo.Price warehouseOutInfo.GoodId = item.GoodId warehouseOutInfo.GoodTypeId = item.GoodTypeId warehouseOutInfo.Count = item.Count err := service.AddSigleWarehouseOutInfo(warehouseOutInfo) if err == nil { details := &models.AutomaticReduceDetail{ WarehouseOutId: warehouseOutInfo.ID, WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber, PatientId: patient_id, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Status: 1, RecordTime: record_time, OrgId: adminInfo.Org.Id, GoodId: item.GoodId, GoodTypeId: item.GoodTypeId, Count: item.Count, } service.AddSigleAutoReduceRecordInfo(details) } } else if err == nil { //记录存在,则将增加数量 if outInfo.ID > 0 { service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count) } count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id) if count == 0 { details := &models.AutomaticReduceDetail{ WarehouseOutId: outInfo.ID, WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber, PatientId: patient_id, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Status: 1, RecordTime: record_time, OrgId: adminInfo.Org.Id, GoodId: item.GoodId, GoodTypeId: item.GoodTypeId, Count: item.Count, } service.AddSigleAutoReduceRecordInfo(details) } else if count == 1 { service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo) } } } } c.ServeSuccessJSON(map[string]interface{}{ "msg": "提交成功", }) return } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong) return } } func (c *DialysisAPIController) EditConsumables() { patient_id, _ := c.GetInt64("patient_id", 0) record_date := c.GetString("record_time") if patient_id <= 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminInfo := c.GetMobileAdminUserInfo() timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc) record_time := theRecordTime.Unix() dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody) if err != nil { utils.ErrorLog(err.Error()) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } var beforePrepares []*models.DialysisBeforePrepare var newBeforePrepares []*models.DialysisBeforePrepare _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id) if record.IsOpen == 1 { if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" { goods, _ := dataBody["goods"].([]interface{}) if len(goods) > 0 { for _, item := range goods { items := item.(map[string]interface{}) if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" { utils.ErrorLog("record_time") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } record_time := int64(items["record_time"].(float64)) if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" { utils.ErrorLog("id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } id := int64(items["id"].(float64)) if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" { utils.ErrorLog("patient_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } patient_id := int64(items["patient_id"].(float64)) if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" { utils.ErrorLog("creater") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } creater := int64(items["creater"].(float64)) if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" { utils.ErrorLog("good_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } good_id := int64(items["good_id"].(float64)) if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" { utils.ErrorLog("good_type_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } good_type_id := int64(items["good_type_id"].(float64)) if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" { utils.ErrorLog("count") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } count, _ := strconv.ParseInt(items["count"].(string), 10, 64) if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" { utils.ErrorLog("ctime") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } ctime := int64(items["ctime"].(float64)) //commdity_code := items["commdity_code"].(string) //fmt.Println("commdityecode22222222222222222222",commdity_code) adminUser := c.GetMobileAdminUserInfo() prepare := &models.DialysisBeforePrepare{ ID: id, UserOrgId: adminUser.Org.Id, PatientId: patient_id, RecordDate: record_time, GoodId: good_id, GoodTypeId: good_type_id, Count: count, Ctime: ctime, Mtime: time.Now().Unix(), Creater: creater, Modifier: adminUser.AdminUser.Id, Status: 1, //CommdityCode: commdity_code, } beforePrepares = append(beforePrepares, prepare) } } } consumables_source, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time) if dataBody["new_goods"] != nil && reflect.TypeOf(dataBody["new_goods"]).String() == "[]interface {}" { goods, _ := dataBody["new_goods"].([]interface{}) if len(goods) > 0 { for _, item := range goods { items := item.(map[string]interface{}) if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" { utils.ErrorLog("good_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } good_id := int64(items["good_id"].(float64)) if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" { utils.ErrorLog("good_type_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } good_type_id := int64(items["good_type_id"].(float64)) if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" { utils.ErrorLog("count") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } count, _ := strconv.ParseInt(items["count"].(string), 10, 64) //commdity_code := items["commdity_code"].(string) //fmt.Println("commdityecode22222222222222222222",commdity_code) adminUser := c.GetMobileAdminUserInfo() prepare := &models.DialysisBeforePrepare{ UserOrgId: adminUser.Org.Id, PatientId: patient_id, RecordDate: record_time, GoodId: good_id, GoodTypeId: good_type_id, Count: count, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Creater: adminUser.AdminUser.Id, Modifier: 0, //CommdityCode:commdity_code, } newBeforePrepares = append(newBeforePrepares, prepare) } newBeforePrepares = RemoveRepeatedGood(newBeforePrepares) } service.CreateDialysisBeforePrepare(newBeforePrepares) } out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time) if err == gorm.ErrRecordNotFound { //没有记录,则创建出库单 timeStr := time.Now().Format("2006-01-02") timeArr := strings.Split(timeStr, "-") total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id) total = total + 1 warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" number, _ := strconv.ParseInt(warehousing_out_order, 10, 64) number = number + total warehousing_out_order = "CKD" + strconv.FormatInt(number, 10) creater := adminInfo.AdminUser.Id warehouseOut := models.WarehouseOut{ WarehouseOutOrderNumber: warehousing_out_order, OperationTime: time.Now().Unix(), OrgId: adminInfo.Org.Id, Creater: creater, Ctime: time.Now().Unix(), Status: 1, WarehouseOutTime: record_time, Dealer: 0, Manufacturer: 0, Type: 1, IsSys: 1, } err := service.AddSigleWarehouseOut(&warehouseOut) if err != nil { utils.TraceLog("创建出库单失败 err = %v", err) } else { for _, item := range beforePrepares { if item.Count > 0 { warehouseOutInfo := &models.WarehouseOutInfo{ WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber, WarehouseOutId: warehouseOut.ID, Count: 1, Status: 1, Ctime: time.Now().Unix(), Remark: "", OrgId: adminInfo.Org.Id, Type: 1, Manufacturer: 0, Dealer: 0, IsSys: 1, SysRecordTime: record_time, GoodTypeId: item.GoodTypeId, GoodId: item.GoodId, } stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id) warehouseOutInfo.Price = stockInInfo.Price err := service.AddSigleWarehouseOutInfo(warehouseOutInfo) if err == nil { details := &models.AutomaticReduceDetail{ WarehouseOutId: warehouseOutInfo.ID, WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber, PatientId: patient_id, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Status: 1, RecordTime: record_time, OrgId: adminInfo.Org.Id, GoodId: item.GoodId, GoodTypeId: item.GoodTypeId, } service.AddSigleAutoReduceRecordInfo(details) } } } } } else if err == nil { if len(newBeforePrepares) > 0 { //新增 for _, item := range newBeforePrepares { outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber) if err == gorm.ErrRecordNotFound { warehouseOutInfo := &models.WarehouseOutInfo{ WarehouseOutOrderNumber: out.WarehouseOutOrderNumber, WarehouseOutId: out.ID, Status: 1, Ctime: time.Now().Unix(), Remark: "", OrgId: adminInfo.Org.Id, Type: 1, Manufacturer: 0, Dealer: 0, IsSys: 1, SysRecordTime: record_time, } stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id) warehouseOutInfo.Price = stockInInfo.Price warehouseOutInfo.GoodId = item.GoodId warehouseOutInfo.GoodTypeId = item.GoodTypeId warehouseOutInfo.Count = item.Count err := service.AddSigleWarehouseOutInfo(warehouseOutInfo) if err == nil { count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id) if count == 0 { details := &models.AutomaticReduceDetail{ WarehouseOutId: warehouseOutInfo.ID, WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber, PatientId: patient_id, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Status: 1, RecordTime: record_time, OrgId: adminInfo.Org.Id, GoodId: item.GoodId, GoodTypeId: item.GoodTypeId, Count: item.Count, } service.AddSigleAutoReduceRecordInfo(details) } else if count == 1 { service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo) } } } else if err == nil { //记录存在,则将加数量 if outInfo.ID > 0 { service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count) } count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id) if count == 0 { details := &models.AutomaticReduceDetail{ WarehouseOutId: outInfo.ID, WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber, PatientId: patient_id, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Status: 1, RecordTime: record_time, OrgId: adminInfo.Org.Id, GoodId: item.GoodId, GoodTypeId: item.GoodTypeId, Count: item.Count, } service.AddSigleAutoReduceRecordInfo(details) } else if count == 1 { service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo) } //details := &models.AutomaticReduceDetail{ // WarehouseOutId: outInfo.ID, // WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber, // PatientId: patient_id, // Ctime: time.Now().Unix(), // Mtime: time.Now().Unix(), // Status: 1, // RecordTime: record_time, // OrgId: adminInfo.Org.Id, // GoodId: item.GoodId, // GoodTypeId: item.GoodTypeId, // Count: item.Count, //} //service.AddSigleAutoReduceRecordInfo(details) } } } if len(beforePrepares) > 0 { //修改 for _, consumable := range consumables_source { for _, before := range beforePrepares { if consumable.GoodId == before.GoodId { if consumable.Count != before.Count { _, out := service.FindStockOutOrderNumberByTime(record_time, adminInfo.Org.Id) //_, out := service.FindOldOrderInfoByGoodId(record_time, adminInfo.Org.Id) //判断前端更改后的商品id的出库记录在数据库中是否存在 err, newOut := service.FindOrderInfoByGoodId(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id) if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息 warehouseOutInfo := &models.WarehouseOutInfo{ WarehouseOutOrderNumber: out.WarehouseOutOrderNumber, WarehouseOutId: out.ID, Count: before.Count, Status: 1, Ctime: time.Now().Unix(), Remark: "", OrgId: adminInfo.Org.Id, Type: 1, Manufacturer: 0, Dealer: 0, IsSys: 1, SysRecordTime: record_time, } stockInInfo, _ := service.FindLastStockInInfoRecord(before.GoodId, adminInfo.Org.Id) warehouseOutInfo.Price = stockInInfo.Price warehouseOutInfo.GoodId = before.GoodId warehouseOutInfo.GoodTypeId = before.GoodTypeId err := service.AddSigleWarehouseOutInfo(warehouseOutInfo) if err == nil { //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在 user, err := service.FindGoodUserById(before.GoodTypeId, before.GoodId, patient_id, adminInfo.Org.Id, record_time) if err == gorm.ErrRecordNotFound { details := &models.AutomaticReduceDetail{ WarehouseOutId: warehouseOutInfo.ID, WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber, PatientId: patient_id, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Status: 1, RecordTime: record_time, OrgId: adminInfo.Org.Id, GoodId: consumable.GoodId, GoodTypeId: consumable.GoodTypeId, Count: before.Count, } service.AddSigleAutoReduceRecordInfo(details) } else if err == nil { if user.ID > 0 { //service.UpdateOrderInfoDetails( consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, a_liquid, warehouseOutInfo) service.UpdateUserInfoDetails(consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, before.Count, warehouseOutInfo) } } } } else if err == nil { //存在,则更改使用人商品信息 fmt.Println("333333333") //处理原来的数据 if newOut.ID > 0 { if consumable.Count > before.Count { // 减少 num := int64(0) if consumable.Count-before.Count > 0 { num = consumable.Count - before.Count } else { num = before.Count - consumable.Count } service.UpdateOrderCountSub(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id, num) } else if consumable.Count < before.Count { //增加 service.UpdateOrderCountAdd(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id, before.Count-consumable.Count) } user, err := service.FindGoodUserById(consumable.GoodTypeId, consumable.GoodId, patient_id, adminInfo.Org.Id, record_time) if err == gorm.ErrRecordNotFound { details := &models.AutomaticReduceDetail{ WarehouseOutId: newOut.ID, WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber, PatientId: patient_id, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Status: 1, RecordTime: record_time, OrgId: adminInfo.Org.Id, GoodId: consumable.GoodId, GoodTypeId: consumable.GoodTypeId, Count: before.Count, } service.AddSigleAutoReduceRecordInfo(details) } else if err == nil { if user.ID > 0 { service.UpdateUserInfoDetails(consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, before.Count, &newOut) } } } } fmt.Println("444444444") } } } } } } fmt.Println("655555555") var errs error if len(beforePrepares) > 0 { for _, item := range beforePrepares { errs = service.UpdateDialysisBeforePrepareTwo(item) } } if errs == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "修改成功", }) return } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } } else { if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" { goods, _ := dataBody["goods"].([]interface{}) if len(goods) > 0 { for _, item := range goods { items := item.(map[string]interface{}) if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" { utils.ErrorLog("record_time") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } record_time := int64(items["record_time"].(float64)) if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" { utils.ErrorLog("id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } id := int64(items["id"].(float64)) if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" { utils.ErrorLog("patient_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } patient_id := int64(items["patient_id"].(float64)) if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" { utils.ErrorLog("creater") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } creater := int64(items["creater"].(float64)) if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" { utils.ErrorLog("good_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } good_id := int64(items["good_id"].(float64)) if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" { utils.ErrorLog("good_type_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } good_type_id := int64(items["good_type_id"].(float64)) if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" { utils.ErrorLog("count") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } count, _ := strconv.ParseInt(items["count"].(string), 10, 64) if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" { utils.ErrorLog("ctime") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } ctime := int64(items["ctime"].(float64)) adminUser := c.GetMobileAdminUserInfo() prepare := &models.DialysisBeforePrepare{ ID: id, UserOrgId: adminUser.Org.Id, PatientId: patient_id, RecordDate: record_time, GoodId: good_id, GoodTypeId: good_type_id, Count: count, Ctime: ctime, Mtime: time.Now().Unix(), Creater: creater, Modifier: adminUser.AdminUser.Id, Status: 1, } beforePrepares = append(beforePrepares, prepare) } } } if dataBody["new_goods"] != nil && reflect.TypeOf(dataBody["new_goods"]).String() == "[]interface {}" { goods, _ := dataBody["new_goods"].([]interface{}) if len(goods) > 0 { for _, item := range goods { items := item.(map[string]interface{}) if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" { utils.ErrorLog("good_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } good_id := int64(items["good_id"].(float64)) if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" { utils.ErrorLog("good_type_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } good_type_id := int64(items["good_type_id"].(float64)) if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" { utils.ErrorLog("count") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } count, _ := strconv.ParseInt(items["count"].(string), 10, 64) adminUser := c.GetMobileAdminUserInfo() prepare := &models.DialysisBeforePrepare{ UserOrgId: adminUser.Org.Id, PatientId: patient_id, RecordDate: record_time, GoodId: good_id, GoodTypeId: good_type_id, Count: count, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Creater: adminUser.AdminUser.Id, Modifier: 0, } newBeforePrepares = append(newBeforePrepares, prepare) } } service.CreateDialysisBeforePrepare(newBeforePrepares) } var errs error if len(beforePrepares) > 0 { for _, item := range beforePrepares { errs = service.UpdateDialysisBeforePrepareTwo(item) } } if errs == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "修改成功", }) return } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } } } func (c *DialysisAPIController) GetDialysisGoods() { schedualDate := c.GetString("schedule_date") schedule_type, _ := c.GetInt64("schedule_type") partition_id, _ := c.GetInt64("partition_id") page, _ := c.GetInt("page") patient_id, _ := c.GetInt64("patient_id") schedualEndDate := int64(0) date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate) if parseDateErr != nil && len(schedualDate) != 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59") if parseDateErr != nil && len(schedualDate) != 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } schedualEndDate = endDate.Unix() adminUser := c.GetMobileAdminUserInfo() _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix()) goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id) if err == gorm.ErrRecordNotFound { dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate) if patient_id != 0 { for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况 goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix()) lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix()) item.LastAutomaticReduceDetail = goodUser item.LastDialysisBeforePrepare = lastGoodUserDetial } } c.ServeSuccessJSON(map[string]interface{}{ "dialysis_goods": dialysisGoods, "good_type": goodTypes, "total": total, }) return } else if err == nil { //获取当天排班的每个患者的库存使用情况 dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate) if patient_id != 0 { for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况 goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix()) lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix()) fmt.Println(goodUser) fmt.Println(lastGoodUserDetial) item.LastAutomaticReduceDetail = goodUser item.LastDialysisBeforePrepare = lastGoodUserDetial } } if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "dialysis_goods": dialysisGoods, "good_type": goodTypes, "total": total, }) return } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } } else if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } } func (c *DialysisAPIController) GetDialysisGoodsStatistics() { start_time := c.GetString("start_time") end_time := c.GetString("end_time") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") var theStartTime int64 if len(start_time) > 0 { theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc) if err != nil { utils.ErrorLog(err.Error()) } theStartTime = theTime.Unix() } var theEndtTime int64 if len(end_time) > 0 { theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc) if err != nil { utils.ErrorLog(err.Error()) } theEndtTime = theTime.Unix() } adminUser := c.GetMobileAdminUserInfo() outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime) stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "stock_out": outInfo, "stockCount": stockCount, }) return } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } } func (c *DialysisAPIController) GetStockInGoodInfo() { patient_id, _ := c.GetInt64("patient_id", 0) record_time := c.GetString("record_time") adminUser := c.GetMobileAdminUserInfo() date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time) if parseDateErr != nil && len(record_time) != 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id) good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id) goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix()) lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix()) c.ServeSuccessJSON(map[string]interface{}{ "good_type": goodTypes, "good_user": goodUser, "good_info": good_info, "last_good_user": lastGoodUserDetial, }) return } func (c *DialysisAPIController) CreateOtherStockOutInfo() { patient_id, _ := c.GetInt64("patient_id", 0) record_date := c.GetString("record_time") if patient_id <= 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminInfo := c.GetMobileAdminUserInfo() timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc) record_time := theRecordTime.Unix() dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody) if err != nil { utils.ErrorLog(err.Error()) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } var beforePrepares []*models.DialysisBeforePrepare if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" { goods, _ := dataBody["goods"].([]interface{}) if len(goods) > 0 { for _, item := range goods { items := item.(map[string]interface{}) if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" { utils.ErrorLog("good_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } good_id := int64(items["good_id"].(float64)) if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" { utils.ErrorLog("good_type_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } good_type_id := int64(items["good_type_id"].(float64)) if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" { utils.ErrorLog("count") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } count, _ := strconv.ParseInt(items["count"].(string), 10, 64) adminUser := c.GetMobileAdminUserInfo() prepare := &models.DialysisBeforePrepare{ UserOrgId: adminUser.Org.Id, PatientId: patient_id, RecordDate: record_time, GoodId: good_id, GoodTypeId: good_type_id, Count: count, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Creater: adminUser.AdminUser.Id, Modifier: 0, } record_count := service.FindDialysisBeforePrepare(prepare.PatientId, prepare.GoodId, prepare.GoodTypeId, adminUser.Org.Id, record_time) if record_count == 0 { beforePrepares = append(beforePrepares, prepare) } else if record_count == 1 { service.UpdateDialysisBeforePrepareTwo(prepare) } } } } beforePrepares = RemoveRepeatedGood(beforePrepares) if len(beforePrepares) > 0 { service.CreateDialysisBeforePrepare(beforePrepares) } consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time) //去重 consumables = RemoveRepeatedGood(consumables) _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id) if record.IsOpen == 1 { out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time) if err == gorm.ErrRecordNotFound { //没有记录,则创建出库单 timeStr := time.Now().Format("2006-01-02") timeArr := strings.Split(timeStr, "-") total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id) total = total + 1 warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" number, _ := strconv.ParseInt(warehousing_out_order, 10, 64) number = number + total warehousing_out_order = "CKD" + strconv.FormatInt(number, 10) creater := adminInfo.AdminUser.Id warehouseOut := models.WarehouseOut{ WarehouseOutOrderNumber: warehousing_out_order, OperationTime: time.Now().Unix(), OrgId: adminInfo.Org.Id, Creater: creater, Ctime: time.Now().Unix(), Status: 1, WarehouseOutTime: record_time, Dealer: 0, Manufacturer: 0, Type: 1, IsSys: 1, } err := service.AddSigleWarehouseOut(&warehouseOut) if err != nil { utils.TraceLog("创建出库单失败 err = %v", err) } else { for _, item := range consumables { if item.Count > 0 { warehouseOutInfo := &models.WarehouseOutInfo{ WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber, WarehouseOutId: warehouseOut.ID, Status: 1, Ctime: time.Now().Unix(), Remark: "", OrgId: adminInfo.Org.Id, Type: 1, Manufacturer: 0, Dealer: 0, IsSys: 1, SysRecordTime: record_time, GoodTypeId: item.GoodTypeId, GoodId: item.GoodId, } warehouseOutInfo.Count = item.Count stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id) warehouseOutInfo.Price = stockInInfo.Price err := service.AddSigleWarehouseOutInfo(warehouseOutInfo) if err == nil { details := &models.AutomaticReduceDetail{ WarehouseOutId: warehouseOutInfo.ID, WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber, PatientId: patient_id, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Status: 1, RecordTime: record_time, OrgId: adminInfo.Org.Id, GoodId: item.GoodId, GoodTypeId: item.GoodTypeId, Count: item.Count, } service.AddSigleAutoReduceRecordInfo(details) } } } } } else if err == nil { for _, item := range consumables { outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber) if err == gorm.ErrRecordNotFound { warehouseOutInfo := &models.WarehouseOutInfo{ WarehouseOutOrderNumber: out.WarehouseOutOrderNumber, WarehouseOutId: out.ID, Status: 1, Ctime: time.Now().Unix(), Remark: "", OrgId: adminInfo.Org.Id, Type: 1, Manufacturer: 0, Dealer: 0, IsSys: 1, SysRecordTime: record_time, } stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id) warehouseOutInfo.Price = stockInInfo.Price warehouseOutInfo.GoodId = item.GoodId warehouseOutInfo.GoodTypeId = item.GoodTypeId warehouseOutInfo.Count = item.Count err := service.AddSigleWarehouseOutInfo(warehouseOutInfo) if err == nil { details := &models.AutomaticReduceDetail{ WarehouseOutId: warehouseOutInfo.ID, WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber, PatientId: patient_id, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Status: 1, RecordTime: record_time, OrgId: adminInfo.Org.Id, GoodId: item.GoodId, GoodTypeId: item.GoodTypeId, Count: item.Count, } service.AddSigleAutoReduceRecordInfo(details) } } else if err == nil { //记录存在,则将增加数量 if outInfo.ID > 0 { service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count) } details := &models.AutomaticReduceDetail{ WarehouseOutId: outInfo.ID, WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber, PatientId: patient_id, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Status: 1, RecordTime: record_time, OrgId: adminInfo.Org.Id, GoodId: item.GoodId, GoodTypeId: item.GoodTypeId, Count: item.Count, } service.AddSigleAutoReduceRecordInfo(details) } } } c.ServeSuccessJSON(map[string]interface{}{ "msg": "提交成功", }) return } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong) return } } func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) { newArr = make([]*models.DialysisBeforePrepare, 0) for i := 0; i < len(arr); i++ { repeat := false for j := i + 1; j < len(arr); j++ { if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId { repeat = true break } } if !repeat { newArr = append(newArr, arr[i]) } } return } func (c *DialysisAPIController) GetAllDrug() { patient_id, _ := c.GetInt64("patient_id", 0) adminInfo := c.GetMobileAdminUserInfo() _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id) privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id) drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id) privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id) c.ServeSuccessJSON(map[string]interface{}{ "base_drug_config": drugStockConfig, "private_drug_config": privateDrugConfig, "base_drug_list": drugList, "private_drug_list": privateDrugList, }) } func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) { newArr = make([]*models.DialysisBeforePrepare, 0) for i := 0; i < len(arr); i++ { repeat := false for j := i + 1; j < len(arr); j++ { if arr[i].GoodId == arr[j].GoodId { repeat = true break } } if !repeat { newArr = append(newArr, arr[i]) } } return } func (c *DialysisAPIController) GetDepartment() { adminInfo := c.GetMobileAdminUserInfo() departments, err := service.GetAllDepartMent(adminInfo.Org.Id) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "departments": departments, }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } }