123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "fmt"
- "github.com/astaxie/beego"
- "math"
- "strconv"
- "time"
- )
-
- type PharmacyController struct {
- BaseAuthAPIController
- }
-
- func PharmacyApiRegistRouters() {
- beego.Router("/api/pharmacy/ceshili", &PharmacyController{}, "get:Tlili")
- beego.Router("/api/pharmacy/todaynumber", &PharmacyController{}, "get:TodayNumber") //查询今天的待发药,已发药人数(
- beego.Router("/api/pharmacy/waitingdrug", &PharmacyController{}, "get:WaitingDrug") //获取当天待发药的所有患者(
- beego.Router("/api/pharmacy/issueddrugs", &PharmacyController{}, "get:IssuedDrug") //获取当天已发药的所有患者(
- beego.Router("/api/pharmacy/getpharmacycontent", &PharmacyController{}, "get:GetPharmacyContent") //获取当天该患者的所有信息(
- beego.Router("/api/pharmacy/dispensingmedicine", &PharmacyController{}, "get:DispensingMedicine") //患者发药按钮点击(
- beego.Router("/api/pharmacy/drugwithdrawal", &PharmacyController{}, "get:DrugWithdrawal") //退药按钮点击
- beego.Router("/api/pharmacy/dispensingdetails", &PharmacyController{}, "get:DispensingDetails") //获取发药明细的患者列表(
- beego.Router("/api/pharmacy/prescriptiondetails", &PharmacyController{}, "get:PrescriptionDetails") //发药明细-详情(
- beego.Router("/api/pharmacy/dispensemedicine", &PharmacyController{}, "get:DispenseMedicine") //获取当天已发药的药品(
- beego.Router("/api/pharmacy/waitingmedicine", &PharmacyController{}, "get:WaitingMedicine") //获取当天待发药的药品(
- beego.Router("/api/pharmacy/getpatientswithdrugs", &PharmacyController{}, "get:GetPatientsWithDrugs") //获取当天该药品的所有患者(
- beego.Router("/api/pharmacy/medicinedeparture", &PharmacyController{}, "get:MedicineDeparture") //药品发药按钮点击(
- beego.Router("/api/pharmacy/getcurrentname", &PharmacyController{}, "get:GetCurrentName") //获取当前登录账号的名字(
- beego.Router("/api/pharmacy/getpartitionlist", &PharmacyController{}, "get:GetPartitionList") //获取当前机构的分区列表
- beego.Router("/api/pharmacy/routeofadministration", &PharmacyController{}, "get:RouteOfAdministration") //获取当前机构的给药途径
- }
-
- // 测试
- func (this *PharmacyController) Tlili() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
- }
- }()
- var list2 []*models.ReplacementDrugs
- list2, err = service.ReplacementDrugs(9675, false)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list2,
- })
- return
- }
- func (this *PharmacyController) GetCurrentName() {
- create := this.GetAdminUserInfo().AdminUser.Id
- this.ServeSuccessJSON(map[string]interface{}{
- "list": create,
- })
- return
- }
-
- // 查询今天的待发药,已发药人数
- func (this *PharmacyController) TodayNumber() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
- }
- }()
- orgid := this.GetAdminUserInfo().CurrentOrgId
- times := this.GetString("time", "")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var stime, etime int64
- if times == "" {
- stime, etime = service.GetNowTime()
- } else {
- stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
- stime = stmp.Unix()
- etime = stime + 86399
- }
-
- if orgid != 9671 && orgid != 10188 && orgid != 10217 && orgid != 3877 && orgid != 10164 && orgid != 10480 {
- //查询表里当天的数据
- var wtotal int
- wtotal, err = service.GetTodayPharmacy(stime, etime, orgid, 1)
-
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var itotal int
- itotal, err = service.GetTodayPharmacy(stime, etime, orgid, 0)
-
- drug, _ := service.GetAllBaseDrugList(orgid)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "wtotal": wtotal,
- "itotal": itotal,
- "drug": drug,
- })
- return
- }
-
- if orgid == 9671 || orgid == 10188 || orgid == 10217 || orgid == 3877 || orgid == 10164 || orgid == 10480 {
- var wtotal int
- var itotal int
- //查找出库数量
- wtotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 1)
-
- itotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 0)
- drug, _ := service.GetAllBaseDrugList(orgid)
- this.ServeSuccessJSON(map[string]interface{}{
- "wtotal": wtotal,
- "itotal": itotal,
- "drug": drug,
- })
- return
- }
-
- }
- func (this *PharmacyController) IssuedDrug() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
- }
- }()
- keyword := this.GetString("keyword", "")
- times := this.GetString("time", "")
- orgid := this.GetAdminUserInfo().CurrentOrgId
- shift, err := this.GetInt64("shift", 0) //班次
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- partition, err := this.GetInt64("partition", 0) //分区
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var stime, etime int64
- if times == "" {
- stime, etime = service.GetNowTime()
- } else {
- stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
- stime = stmp.Unix()
- etime = stime + 86399
- }
-
- if orgid == 10164 || orgid == 3877 || orgid == 10188 || orgid == 10217 || orgid == 9671 || orgid == 10387 || orgid == 10375 || orgid == 10480 || orgid == 10344 {
-
- //获取排班班次
- schedule, _ := service.GetSchedulePatientId(stime, etime, orgid, shift, partition)
-
- var ids []int64
- for _, item := range schedule {
- ids = append(ids, item.PatientId)
- }
-
- list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 1, ids)
-
- var flist []models.TmpPatientOne
- if len(list) > 0 {
- for _, item := range list {
- patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
- flist = append(flist, patientlist)
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": flist,
- })
- }
-
- if orgid != 10164 && orgid == 3877 && orgid != 10188 && orgid != 10217 && orgid != 9671 && orgid != 10387 && orgid != 10375 && orgid != 10480 && orgid == 10344 {
- //查询表里当天的数据
- var flist []*models.TmpPatient
- flist, err = service.GetTodayDrug(stime, etime, orgid, 1, keyword)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": listt,
- })
- return
- }
-
- }
- func (this *PharmacyController) WaitingDrug() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
- }
- }()
- keyword := this.GetString("keyword", "")
- times := this.GetString("time", "")
- shift, err := this.GetInt64("shift", 0) //班次
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- partition, err := this.GetInt64("partition", 0) //分区
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- orgid := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var stime, etime int64
- if times == "" {
- stime, etime = service.GetNowTime()
- } else {
- stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
- stime = stmp.Unix()
- etime = stime + 86399
- }
-
- if orgid != 9671 && orgid != 10188 && orgid != 10217 && orgid != 3877 && orgid != 10164 && orgid != 10387 && orgid != 10375 && orgid != 10480 && orgid != 10344 {
- //查询表里当天的数据
- var flist []*models.TmpPatient
- flist, err = service.GetTodayDrug(stime, etime, orgid, 0, keyword)
-
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
-
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- baseList, _ := service.GetAllBaseDrugListTwo(orgid)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": listt,
- "baseList": baseList,
- })
- return
- }
-
- //当天已发药的人数
- if orgid == 9671 || orgid == 10188 || orgid == 10217 || orgid == 3877 || orgid == 10164 || orgid == 10387 || orgid == 10375 || orgid == 10480 || orgid == 10344 {
-
- //获取排班班次
- schedule, _ := service.GetSchedulePatientId(stime, etime, orgid, shift, partition)
- var ids []int64
- for _, item := range schedule {
- ids = append(ids, item.PatientId)
- }
-
- list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 0, ids)
-
- var flist []models.TmpPatientOne
- if len(list) > 0 {
- for _, item := range list {
- patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
- flist = append(flist, patientlist)
- }
- }
- baseList, _ := service.GetAllBaseDrugListTwo(orgid)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": flist,
- "baseList": baseList,
- })
- return
- }
-
- }
-
- func (this *PharmacyController) GetPharmacyContent() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
- }
- }()
- patient_id, _ := this.GetInt64("patient_id", 0)
- is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
- times := this.GetString("time", "")
- orgid := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var stime, etime int64
- if times == "" {
- stime, etime = service.GetNowTime()
- } else {
- stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
- stime = stmp.Unix()
- etime = stime + 86399
- }
- var list []*models.PharmacyContent
- list, err = service.GetPatientMedication(orgid, patient_id, stime, etime, is_medicine)
- baseList, _ := service.GetAllBaseDrugListTwo(orgid)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- return_value := make(map[string]interface{})
- return_value["list"] = list
- return_value["baseList"] = baseList
- //if is_medicine == 1{发药时间先不展示
- // return_value["time"] = time
- //}
- this.ServeSuccessJSON(return_value)
- return
-
- }
-
- // 发药按钮点击
- func (this *PharmacyController) DispensingMedicine() {
-
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
- }
- }()
- patient_id, _ := this.GetInt64("patient_id", 0)
- times := this.GetString("time", "")
- orgid := this.GetAdminUserInfo().CurrentOrgId
- creater := this.GetAdminUserInfo().AdminUser.Id
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var stime, etime int64
- if times == "" {
- stime, etime = service.GetNowTime()
- } else {
- stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
- stime = stmp.Unix()
- etime = stime + 86399
- }
-
- advicelist, _ := service.FindeHisAdviceDocAdvice(orgid, patient_id, stime, etime)
- if len(advicelist) > 0 {
- var total int64
- var prescribing_number_total int64
- for _, item := range advicelist {
- //查询改药品信息
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- //如果是药房发药的方式
- if medical.IsPharmacy == 1 {
- houseConfig, _ := service.GetAllStoreHouseConfig(orgid)
- //查询该药品是否有库存
- list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
-
- //判断单位是否相等
- if medical.MaxUnit == item.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- //转化为最小单位
- total = list.Count*medical.MinNumber + list.StockMinNumber
- prescribing_number_total = count * medical.MinNumber
- }
- if medical.MinUnit == item.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- total = list.Count*medical.MinNumber + list.StockMinNumber
- prescribing_number_total = count
- }
-
- if medical.IsUse != 1 {
- //如果出库数量大于库存数量
- if prescribing_number_total > total {
- err := fmt.Errorf(service.FindDrugsName(item.DrugId) + "库存不足")
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- }
- }
- }
-
- }
- }
-
- if orgid != 10480 && orgid != 10188 {
- //发药
- err = service.DispensingMedicine(orgid, patient_id, stime, etime, creater)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "操作成功",
- })
- return
- }
-
- if orgid == 10480 || orgid == 10188 {
- //发药逻辑
-
- service.DispensingMedicineOne(orgid, patient_id, stime, etime, creater)
-
- //针对桑植盛康
- if orgid == 10387 || orgid == 3877 {
- advicelist, _ := service.FindeHisAdviceDocAdvice(orgid, patient_id, stime, etime)
- if len(advicelist) > 0 {
- for _, item := range advicelist {
- //查询改药品信息
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- if medical.IsPharmacy == 1 {
- flow, _ := service.GetFlow(item.DrugId, item.AdviceDate, orgid, item.PatientId)
- if len(flow) > 0 {
- service.UpdateAdviceFlow(item.ID)
- }
- }
- }
-
- }
- }
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "操作成功",
- })
- return
- }
-
- }
-
- // 退药按钮点击
- func (this *PharmacyController) DrugWithdrawal() {
-
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
- }
- }()
- patient_id, _ := this.GetInt64("patient_id", 0)
- times := this.GetString("time", "")
- orgid := this.GetAdminUserInfo().CurrentOrgId
- creater := this.GetAdminUserInfo().AdminUser.Id
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var stime, etime int64
- if times == "" {
- stime, etime = service.GetNowTime()
- } else {
- stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
- stime = stmp.Unix()
- etime = stime + 86399
- }
- err = service.DrugWithdrawal(orgid, patient_id, stime, etime, creater)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "操作成功",
- })
- return
-
- }
-
- // 发药明细列表
- func (this *PharmacyController) DispensingDetails() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
- }
- }()
- keyword := this.GetString("keyword", "") //患者名称
- start_time := this.GetString("start_time", "") //开始时间
- end_time := this.GetString("end_time", "") //结束时间
- page, _ := this.GetInt64("page", 1) //页码
- limit, _ := this.GetInt64("limit", 10) //每一页查出来的条数
- orgid := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var stime, etime int64
- if start_time == "" {
- stime = 1
- } else {
- stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- stime = stmp.Unix()
- }
- if end_time == "" {
- _, etime = service.GetNowTime()
- } else {
- etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- etime = etmp.Unix()
- }
- var dislist []*models.DispensingList
- var total int64
- dislist, total, err = service.DispensingDetailsList(stime, etime, orgid, page, limit, keyword)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": dislist,
- "total": total,
- })
- return
- }
-
- // 处方详情
- func (this *PharmacyController) PrescriptionDetails() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
- }
- }()
- //患者姓名
- patient_id, _ := this.GetInt64("patient_id", 0)
- //发药时间
- record_date, _ := this.GetInt64("record_date", 0)
- orgid := this.GetAdminUserInfo().CurrentOrgId
- if record_date == 0 || patient_id == 0 {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数不足")
- return
- }
- var list []*models.PrescripDetails
- list, err = service.PrescriptionDetails(patient_id, record_date, orgid)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- }
-
- // 已发药品的信息
- func (this *PharmacyController) DispenseMedicine() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
- }
- }()
- keyword := this.GetString("keyword", "")
- times := this.GetString("time", "")
- orgid := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- deliveryway := this.GetString("deliveryway", "")
- var stime, etime int64
- if times == "" {
- stime, etime = service.GetNowTime()
- } else {
- stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
- stime = stmp.Unix()
- etime = stime + 86399
- }
- //查询表里当天的数据
- var flist []*models.ListOfDrugs
- flist, err = service.GetTodayMedicine(stime, etime, orgid, 1, keyword)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- llist, err := service.Administration(deliveryway, orgid, flist)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": llist,
- })
- return
- }
-
- // 待发药的药品信息
- func (this *PharmacyController) WaitingMedicine() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
- }
- }()
- keyword := this.GetString("keyword", "")
- times := this.GetString("time", "")
- orgid := this.GetAdminUserInfo().CurrentOrgId
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- deliveryway := this.GetString("deliveryway", "")
- var stime, etime int64
- if times == "" {
- stime, etime = service.GetNowTime()
- } else {
- stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
- stime = stmp.Unix()
- etime = stime + 86399
- }
- //查询表里当天的数据
- var flist []*models.ListOfDrugs
- flist, err = service.GetTodayMedicine(stime, etime, orgid, 0, keyword)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- llist, err := service.Administration(deliveryway, orgid, flist)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": llist,
- })
- return
- }
-
- // 获取药品的所有患者信息
- func (this *PharmacyController) GetPatientsWithDrugs() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
- }
- }()
- drug_id, _ := this.GetInt64("drug_id", 0)
- is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
- times := this.GetString("time", "")
- orgid := this.GetAdminUserInfo().CurrentOrgId
- deliveryway := this.GetString("deliveryway", "")
- if deliveryway == "" {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- shift, err := this.GetInt64("shift", 0) //班次
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- partition, err := this.GetInt64("partition", 0) //分区
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var stime, etime int64
- if times == "" {
- stime, etime = service.GetNowTime()
- } else {
- stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
- stime = stmp.Unix()
- etime = stime + 86399
- }
- var list []*models.PatientInformation
- list, err = service.FindMedicationList(orgid, drug_id, stime, etime, is_medicine)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- listll, err := service.PartitionAndLayoutDrug(deliveryway, stime, etime, orgid, shift, partition, list)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- total, err := service.CalculateTheTotalAmount(listll, drug_id)
-
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": listll,
- "total": total,
- })
- return
- }
-
- // 药品管理发药按钮点击
- func (this *PharmacyController) MedicineDeparture() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
- }
- }()
- creater, _ := this.GetInt64("creater", 0) //领药人
- ids := this.GetString("ids", "") //发药的数据
- orgid := this.GetAdminUserInfo().CurrentOrgId
- if ids == "" {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数不足")
- return
- }
- err = service.MedicineDeparture(ids, creater, orgid)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": "修改成功",
- })
- return
- }
-
- func (this *PharmacyController) GetPartitionList() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
- }
- }()
- orgid := this.GetAdminUserInfo().CurrentOrgId
- tmp := []*models.DeviceZone{{ID: 0, Name: "全部分区"}}
- list, err := service.GetAllValidDeviceZones02(orgid)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": append(tmp, list...),
- })
- return
- }
-
- func (this *PharmacyController) RouteOfAdministration() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
- }
- }()
- orgid := this.GetAdminUserInfo().CurrentOrgId
- tmp := []*models.DrugwayDic{{ID: 0, Name: "全部"}}
- list, _, err := service.GetDrugWayDics(orgid)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": append(tmp, list...),
- })
- return
- }
|