package controllers import ( "XT_New/enums" "XT_New/models" "XT_New/service" "fmt" "github.com/astaxie/beego" "math/rand" "strconv" "strings" "time" ) type HisHospitalApiController struct { BaseAuthAPIController } func HisHospitalManagerApiRegistRouters() { beego.Router("/api/hishospitalpatient/list", &HisHospitalApiController{}, "get:GetHisHospitalPatientList") beego.Router("/api/hospitalcharge/list", &HisHospitalApiController{}, "get:GetHisHospitalChargePatientList") beego.Router("/api/hospotalcharge/info", &HisHospitalApiController{}, "get:GetHisHospitalChargePatientInfo") beego.Router("/api/hospitalprescription/list", &HisHospitalApiController{}, "get:GetHisHospitalPrescriptionList") beego.Router("/api/hospital/inhopitalcheck/get", &HisHospitalApiController{}, "get:GetZHInHospitalCheck") beego.Router("/api/hospital/outhopitalcheck/get", &HisHospitalApiController{}, "get:GetZHOutHospitalCheck") beego.Router("/api/hospital/settle/get", &HisHospitalApiController{}, "get:GetSettleInfo") beego.Router("/api/hospital/inthopitaluncheck/get", &HisHospitalApiController{}, "get:GetZHInHospitalUnCheck") beego.Router("/api/hospital/outhopitaluncheck/get", &HisHospitalApiController{}, "get:GetZHOutHospitalUnCheck") beego.Router("/api/hospital/refund", &HisHospitalApiController{}, "get:ZHRefund") } func (c *HisHospitalApiController) GetHisHospitalPatientList() { record_date := c.GetString("record_date") types, _ := c.GetInt64("type", 0) sch_type, _ := c.GetInt64("sch_type", 0) timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordDateTime := theTime.Unix() adminInfo := c.GetAdminUserInfo() //var patients []*service.HospitalPatient tempPatients, _ := service.GetHisHospitalPatientList(adminInfo.CurrentOrgId, recordDateTime) tempPatients_two, _ := service.GetHisHospitalSchPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type) //当天有登记住院的和排班同时存在的话,删除掉排班的记录 for _, item := range tempPatients { for index, subItem := range tempPatients_two { if item.ID == subItem.ID { tempPatients_two = append(tempPatients_two[:index], tempPatients_two[index+1:]...) } } } tempPatients = append(tempPatients, tempPatients_two...) var total_one int64 var total_two int64 for _, item := range tempPatients { if item.VMHisPrescriptionInfo.ID == 0 { total_one = total_one + 1 } if item.VMHisPrescriptionInfo.ID > 0 { total_two = total_two + 1 } } adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id) doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId) department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId) if types == 0 { c.ServeSuccessJSON(map[string]interface{}{ "list": tempPatients, "total_one": total_one, "total_two": total_two, "info": adminUserInfo, "doctors": doctors, "department": department, }) } else if types == 1 { //未就诊 var patientsOne []*service.HospitalPatient for _, item := range tempPatients { if item.VMHisPrescriptionInfo.ID == 0 { patientsOne = append(patientsOne, item) } } c.ServeSuccessJSON(map[string]interface{}{ "list": patientsOne, "total_one": total_one, "total_two": total_two, "info": adminUserInfo, "doctors": doctors, "department": department, }) } else if types == 2 { //已就诊 var patientsTwo []*service.HospitalPatient for _, item := range tempPatients { if item.VMHisPrescriptionInfo.ID > 0 { patientsTwo = append(patientsTwo, item) } } c.ServeSuccessJSON(map[string]interface{}{ "list": patientsTwo, "total_one": total_one, "total_two": total_two, "info": adminUserInfo, "doctors": doctors, "department": department, }) } } func (c *HisHospitalApiController) GetHisHospitalChargePatientList() { record_date := c.GetString("record_date") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordDateTime := theTime.Unix() adminInfo := c.GetAdminUserInfo() //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime) orders, _ := service.GetNewAllChargeHisHospitalPatientList(adminInfo.CurrentOrgId, recordDateTime) tempPatients, _ := service.GetNewAllUnChargeHisHospitalPatientList(adminInfo.CurrentOrgId, recordDateTime) var patients []*models.HisHospitalCheckRecord for _, item := range tempPatients { fmt.Println(item.ID) if item.ID > 0 && item.InHospitalStatus == 1 && item.HisHospitalOrder.OrderStatus != 2 { patients = append(patients, item) } } c.ServeSuccessJSON(map[string]interface{}{ "list": patients, "list_two": patients, "charge_list": orders, }) } func (c *HisHospitalApiController) GetHisHospitalChargePatientInfo() { patient_id, _ := c.GetInt64("patient_id") his_patient_id, _ := c.GetInt64("his_patient_id") record_date := c.GetString("record_date") start_time := c.GetString("start_time") end_time := c.GetString("end_time") order_status, _ := c.GetInt64("type", 0) p_type, _ := c.GetInt64("p_type", 0) timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordDateTime := theTime.Unix() startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc) if err != nil { } startRecordDateTime := startTime.Unix() endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc) if err != nil { } endRecordDateTime := endTime.Unix() admin := c.GetAdminUserInfo() his_patient_info, _ := service.GetNewHisHospitalPatientInfo(his_patient_id) xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id) var prescriptions []*models.HisPrescription if order_status == 1 || order_status == 0 { prescriptions, _ = service.GetUnChargeHisHospitalPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime) } else if order_status == 2 { prescriptions, _ = service.GetChargeHisHospitalPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime) } var monthPrescriptions []*models.HisPrescription if order_status == 1 || order_status == 0 { monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type) } else if order_status == 2 { monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFour(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type) } case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime) patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type) order, _ := service.GetNewHisOrder(admin.CurrentOrgId, his_patient_info.Number, patient_id) doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId) //获取所有科室信息 department, _ := service.GetAllDepartMent(admin.CurrentOrgId) c.ServeSuccessJSON(map[string]interface{}{ "his_info": his_patient_info, "xt_info": xt_patient_info, "prescription": prescriptions, "case_history": case_history, "info": patientPrescriptionInfo, "month_prescriptions": monthPrescriptions, "order": order, "doctors": doctors, "department": department, }) return } func (c *HisHospitalApiController) GetHisHospitalrescriptionList() { record_date := c.GetString("record_date") keywords := c.GetString("keywords") page, _ := c.GetInt64("page") limit, _ := c.GetInt64("limit") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordDateTime := theTime.Unix() adminInfo := c.GetAdminUserInfo() prescriptionOrder, err, total := service.GetHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit) //adminInfo := c.GetAdminUserInfo() //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId) //fmt.Println(prescriptionOrder) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "order": prescriptionOrder, "total": total, }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } func (c *HisHospitalApiController) GetHisHospitalPrescriptionList() { record_date := c.GetString("record_date") keywords := c.GetString("keywords") page, _ := c.GetInt64("page") limit, _ := c.GetInt64("limit") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordDateTime := theTime.Unix() adminInfo := c.GetAdminUserInfo() prescriptionOrder, err, total := service.GetHisHospitalPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "order": prescriptionOrder, "total": total, }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } func (c *HisHospitalApiController) GetZHInHospitalCheck() { id, _ := c.GetInt64("id") record_time := c.GetString("record_time") name := c.GetString("name") phone := c.GetString("phone") id_card_type, _ := c.GetInt64("id_card_type") certificates, _ := c.GetInt64("certificates") id_card_no := c.GetString("id_card_no") doctor, _ := c.GetInt64("doctor") admin_user_id, _ := c.GetInt64("admin_user_id") department, _ := c.GetInt64("department") adm_bed, _ := c.GetInt64("adm_bed") diagnosis_ids := c.GetString("diagnosis") sick_type, _ := c.GetInt64("sick_type") start_time := c.GetString("start_time") balance_accounts_type, _ := c.GetInt64("balance_accounts_type") med_type, _ := c.GetInt64("med_type") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordDateTime := theTime.Unix() adminInfo := c.GetAdminUserInfo() record, _ := service.GetLastHospitalRecord(id, adminInfo.CurrentOrgId) if record.ID != 0 { if record.InHospitalStatus == 1 && record.OutHospitalStatus != 1 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalExistDataException) return } } timestamp := time.Now().Unix() tempTime := time.Unix(timestamp, 0) timeFormat := tempTime.Format("20060102150405") chrgBchno := rand.Intn(100000) + 10000 ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(id, 10) timeStr := time.Now().Format("2006-01-02 15:04:05") fmt.Println(timeStr) timeArr := strings.Split(timeStr, " ") fmt.Println(timeArr) timeArrTwo := strings.Split(timeArr[0], "-") timeArrThree := strings.Split(timeArr[1], ":") var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(id, 10) inHospital := &models.HisHospitalCheckRecord{ PatientId: id, Name: name, MedicalTreatmentType: med_type, RecordDate: recordDateTime, IdCardNo: id_card_no, AdminUserId: admin_user_id, Departments: department, UserOrgId: adminInfo.CurrentOrgId, Status: 1, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Number: str, Doctor: doctor, Certno: id_card_no, MedType: med_type, IptOtpNo: ipt_otp_no, AdmBed: adm_bed, IdCardType: id_card_type, Diagnosis: diagnosis_ids, SickType: sick_type, MdtrtCertType: "02", InHosptialTime: start_time, OutHosptialTime: "", InHospitalStatus: 1, Certificates: certificates, Phone: phone, BalanceAccountsType: balance_accounts_type, } service.CreateHospitalRecord(inHospital) c.ServeSuccessJSON(map[string]interface{}{ "msg": "办理入院成功", "info": inHospital, }) } func (this *HisHospitalApiController) GetZHOutHospitalCheck() { id, _ := this.GetInt64("id") record, _ := service.GetInHospitalRecord(id) if record.ID == 0 { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException) return } timestamp := time.Now().Unix() tempTime := time.Unix(timestamp, 0) timeFormatOne := tempTime.Format("2006-01-02 15:04:05") record.OutHospitalStatus = 1 record.OutHosptialTime = timeFormatOne record.OutWay = 1 service.CreateHospitalRecord(&record) this.ServeSuccessJSON(map[string]interface{}{ "msg": "出院成功", }) } func (c *HisHospitalApiController) GetSettleInfo() { id, _ := c.GetInt64("id") record_time := c.GetString("record_time") in_hospital_id, _ := c.GetInt64("in_hospital_id") settle_accounts_type, _ := c.GetInt64("settle_accounts_type") patient_id, _ := c.GetInt64("patient_id") pay_way, _ := c.GetInt64("pay_way") pay_price, _ := c.GetFloat("pay_price") pay_card_no := c.GetString("pay_card_no") discount_price, _ := c.GetFloat("discount_price") preferential_price, _ := c.GetFloat("preferential_price") reality_price, _ := c.GetFloat("reality_price") found_price, _ := c.GetFloat("found_price") medical_insurance_price, _ := c.GetFloat("medical_insurance_price") private_price, _ := c.GetFloat("private_price") fapiao_code := c.GetString("fapiao_code") fapiao_number := c.GetString("fapiao_number") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordDateTime := theTime.Unix() adminUser := c.GetAdminUserInfo() var prescriptions []*models.HisPrescription var start_time int64 var end_time int64 if settle_accounts_type == 1 { //日结 //prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime) } else { //月结 start_time_str := c.GetString("start_time") end_time_str := c.GetString("end_time") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordStartTime := theStartTime.Unix() start_time = recordStartTime theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordEndTime := theEndTime.Unix() end_time = recordEndTime prescriptions, _ = service.GetHospitalMonthHisPrescription(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime) } record, _ := service.GetInHospitalRecord(in_hospital_id) if record.ID == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } timestamp := time.Now().Unix() tempTime := time.Unix(timestamp, 0) timeFormat := tempTime.Format("20060102150405") chrgBchno := rand.Intn(100000) + 10000 chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10) var ids []int64 fmt.Println(prescriptions) for _, item := range prescriptions { ids = append(ids, item.ID) } var total float64 fmt.Println(prescriptions) for _, item := range prescriptions { fmt.Println(item) if item.Type == 1 { //药品 for _, subItem := range item.HisDoctorAdviceInfo { total = total + (subItem.Price * subItem.PrescribingNumber) } } if item.Type == 2 { //项目 for _, subItem := range item.HisPrescriptionProject { total = total + (subItem.Price * float64(subItem.Count)) } } for _, subItem := range item.HisAdditionalCharge { total = total + (subItem.Price * float64(subItem.Count)) } } allTotal := fmt.Sprintf("%.2f", total) totals, _ := strconv.ParseFloat(allTotal, 64) order := &models.HisOrder{ UserOrgId: adminUser.CurrentOrgId, HisPatientId: record.ID, PatientId: patient_id, SettleAccountsDate: recordDateTime, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Status: 1, OrderStatus: 2, MdtrtId: record.Number, Number: chrg_bchno, MedfeeSumamt: totals, SettleEndTime: end_time, SettleStartTime: start_time, SettleType: settle_accounts_type, PType: 1, Creator: c.GetAdminUserInfo().AdminUser.Id, } order.DiscountPrice = discount_price order.MedicalInsurancePrice = medical_insurance_price order.FaPiaoNumber = fapiao_number order.FaPiaoCode = fapiao_code order.PayWay = pay_way order.PayPrice = pay_price order.PayCardNo = pay_card_no order.PreferentialPrice = preferential_price order.RealityPrice = reality_price order.FoundPrice = found_price order.PrivatePrice = private_price err = service.CreateOrder(order) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException) return } var customs []*Custom for _, item := range prescriptions { if item.Type == 1 { //药品 for _, subItem := range item.HisDoctorAdviceInfo { cus := &Custom{ AdviceId: subItem.ID, ProjectId: 0, DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber), Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber), FeedetlSn: subItem.FeedetlSn, Price: fmt.Sprintf("%.2f", subItem.Price), MedListCodg: subItem.MedListCodg, Type: 1, } customs = append(customs, cus) } } if item.Type == 2 { //项目 for _, subItem := range item.HisPrescriptionProject { cus := &Custom{ AdviceId: 0, ProjectId: subItem.ID, DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), Cut: fmt.Sprintf("%.2f", float64(subItem.Count)), FeedetlSn: subItem.FeedetlSn, Price: fmt.Sprintf("%.2f", float64(subItem.Price)), MedListCodg: subItem.MedListCodg, Type: 2, } customs = append(customs, cus) } } for _, item := range item.HisAdditionalCharge { cus := &Custom{ ItemId: item.ID, AdviceId: 0, ProjectId: 0, DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price), Cut: fmt.Sprintf("%.2f", float64(item.Count)), FeedetlSn: item.FeedetlSn, Price: fmt.Sprintf("%.2f", float64(item.Price)), MedListCodg: item.XtHisAddtionConfig.Code, Type: 3, } customs = append(customs, cus) } } for _, item := range customs { var advice_id int64 = 0 var project_id int64 = 0 var item_id int64 = 0 var types int64 = 0 if item.Type == 1 { advice_id = item.AdviceId project_id = 0 item_id = 0 } else if item.Type == 2 { advice_id = 0 item_id = 0 project_id = item.ProjectId } else if item.Type == 3 { advice_id = 0 item_id = item.ItemId project_id = 0 } detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32) cut, _ := strconv.ParseFloat(item.Cut, 32) pric, _ := strconv.ParseFloat(item.Price, 32) info := &models.HisOrderInfo{ OrderNumber: order.Number, UploadDate: time.Now().Unix(), AdviceId: advice_id, DetItemFeeSumamt: detItemFeeSumamt, Cnt: cut, Pric: pric, PatientId: id, Status: 1, Mtime: time.Now().Unix(), Ctime: time.Now().Unix(), UserOrgId: adminUser.CurrentOrgId, HisPatientId: record.ID, OrderId: order.ID, ProjectId: project_id, Type: types, ItemId: item_id, } service.CreateOrderInfo(info) } err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno) err = service.UpDateHospitalHisPrescriptionInfoNumber(adminUser.CurrentOrgId, chrg_bchno, start_time, end_time) err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "结算成功", }) } } func (c *HisHospitalApiController) ZHRefund() { order_id, _ := c.GetInt64("order_id") adminUser := c.GetAdminUserInfo() var order models.HisOrder order, _ = service.GetHisOrderByID(order_id) err := service.UpdataHospitalOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "") if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "退费成功", }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } func (this *HisHospitalApiController) GetZHOutHospitalUnCheck() { id, _ := this.GetInt64("id") record, _ := service.GetInHospitalRecord(id) if record.ID == 0 { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException) return } record.OutHospitalStatus = 0 service.CreateHospitalRecord(&record) this.ServeSuccessJSON(map[string]interface{}{ "msg": "撤销出院成功", }) } func (this *HisHospitalApiController) GetZHInHospitalUnCheck() { id, _ := this.GetInt64("id") record, _ := service.GetInHospitalRecord(id) if record.ID == 0 { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException) return } record.Status = 0 service.CreateHospitalRecord(&record) this.ServeSuccessJSON(map[string]interface{}{ "msg": "撤销入院成功", }) }