12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442 |
- package controllers
-
- import (
- "fmt"
- "math"
- "strconv"
- "strings"
- "time"
-
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "github.com/astaxie/beego"
- )
-
- 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") //获取当前机构的给药途径
-
- beego.Router("/api/pharmacy/getgoodinventorylist", &PharmacyController{}, "Get:GetGoodInventoryList")
- beego.Router("/api/pharmacy/getgoodinventorybygoodid", &PharmacyController{}, "Get:GetGoodInventoryByGoodId")
- beego.Router("/api/pharmacy/updateInventoryWarehouseInfo", &PharmacyController{}, "Get:UpdateInventoryWarehouseInfo")
-
- beego.Router("/api/pharmacy/getdrugnewinventoryList", &PharmacyController{}, "Get:GetDrugInventoryList")
-
- beego.Router("/api/pharmacy/getdruginventorybydrugid", &PharmacyController{}, "Get:GetDrugInventoryByDrugId")
-
- beego.Router("/api/pharmacy/updatedruginventorywarehouseinfo", &PharmacyController{}, "Get:UpdateDrugInventoryWarehouseInfo")
-
- beego.Router("/api/pharmacy/changedrugcode", &PharmacyController{}, "Get:ChangeDrugCode")
-
- beego.Router("/api/pharmacy/changeZeroFlag", &PharmacyController{}, "Get:ChangeZeroFlag")
-
- }
-
- // 测试
- 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
- //}
-
- var wtotal int
- var itotal int
- //查找出库数量
- wtotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 1)
-
- itotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 0)
-
- drug, _ := service.GetAllBaseDrugList(orgid)
-
- config, _ := service.GetDrugCodeConfig(orgid)
- this.ServeSuccessJSON(map[string]interface{}{
- "wtotal": wtotal,
- "itotal": itotal,
- "drug": drug,
- "config": config,
- })
- 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", "")
- fmt.Println(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
- }
-
- var patientsId []int64
-
- patient, _ := service.GetPatientKeyWord(keyword, orgid)
- if len(patient) > 0 {
- for _, item := range patient {
- patientsId = append(patientsId, item.ID)
- }
- }
-
- //获取排班班次
- schedule, _ := service.GetSchedulePatientId(stime, etime, orgid, shift, partition, patientsId)
-
- 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)
- }
- }
-
- listTwo, _ := service.GetTodayAdviceCountTwo(stime, etime, orgid, 1)
-
- var vlist []*models.HisDoctorAdviceInfo
- if len(listTwo) > 0 {
- for _, item := range listTwo {
- //查询该患者是否有排班
- scheduleList, _ := service.GetPatientAdviceScheduleByPatient(item.PatientId, item.UserOrgId, item.AdviceDate)
- if len(scheduleList) == 0 {
- vlist = append(vlist, item)
- }
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": flist,
- "listTwo": vlist,
- })
-
- //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
- }
-
- var patientsId []int64
-
- patient, _ := service.GetPatientKeyWord(keyword, orgid)
-
- if len(patient) > 0 {
- for _, item := range patient {
- patientsId = append(patientsId, item.ID)
- }
- }
-
- //当未发药的人数
- //获取排班班次
- schedule, _ := service.GetSchedulePatientId(stime, etime, orgid, shift, partition, patientsId)
- var ids []int64
- for _, item := range schedule {
- ids = append(ids, item.PatientId)
- }
-
- list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 0, ids)
-
- listTwo, _ := service.GetTodayAdviceCountTwo(stime, etime, orgid, 0)
-
- var vlist []*models.HisDoctorAdviceInfo
- if len(listTwo) > 0 {
- for _, item := range listTwo {
- //查询该患者是否有排班
- scheduleList, _ := service.GetPatientAdviceScheduleByPatient(item.PatientId, item.UserOrgId, item.AdviceDate)
- if len(scheduleList) == 0 {
- vlist = append(vlist, item)
- }
- }
- }
-
- patientList, _ := service.GetAllpatient(orgid)
-
- 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,
- "listTwo": vlist,
- "patientList": patientList,
- })
- 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)
-
- patients, _ := service.GetPatientByIDOne(orgid, patient_id)
- order, _ := service.GetMobiledialysiOrder(orgid, patient_id, stime)
- numberList, _ := service.GetAllBedNumberList(orgid)
- zoneList, _ := service.GetAllZoneByList(orgid)
-
- appId := this.GetAdminUserInfo().CurrentAppId
- adminUserES, _ := service.GetAllAdminUserES(orgid, appId)
- allDoctor, _ := service.GetAllDoctor(orgid, appId)
-
- prescriptionListByToDay, _ := service.GetPrescriptionListByToDay(orgid, patient_id, stime)
-
- diagnose, _ := service.FindAllDiagnose(orgid)
-
- config, _ := service.GetDrugCodeConfig(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
- return_value["patients"] = patients
- return_value["order"] = order
- return_value["numberList"] = numberList
- return_value["zoneList"] = zoneList
- return_value["adminUserES"] = adminUserES
- return_value["doctors"] = allDoctor
- return_value["prescription"] = prescriptionListByToDay
- return_value["diagnose"] = diagnose
- return_value["config"] = config
- //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
- }
- tmp_bool := service.IsPharmacyConfig(orgid)
- codeConfig, _ := service.GetDrugCodeConfig(orgid)
- if tmp_bool == true {
- advicelist, _ := service.FindeHisAdviceDocAdvice(orgid, patient_id, stime, etime)
- if len(advicelist) > 0 {
-
- var total int64
- var prescribing_number_total int64
- for _, item := range advicelist {
-
- if codeConfig.IsOpen == 1 {
- if item.DrugCode == "" || len(item.DrugCode) == 0 {
- err := fmt.Errorf(service.FindDrugsName(item.DrugId) + "药品追溯码不能为空")
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
- return
- }
- }
- }
-
- //查询改药品信息
- 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 && orgid != 10217 && orgid != 10164 && orgid != 10666 {
- //发药
- 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 || orgid == 10217 || orgid == 10164 || orgid == 10666 {
- //发药逻辑
-
- 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
- }
-
- func (this *PharmacyController) GetGoodInventoryList() {
-
- keyword := this.GetString("keywords")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- list, _ := service.GetGoodInventoryList(keyword, orgId)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "manufacturerList": manufacturerList,
- })
- return
- }
-
- func (this *PharmacyController) GetGoodInventoryByGoodId() {
-
- id, _ := this.GetInt64("id")
-
- infoList, _ := service.GetGoodInventoryByGoodId(id)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "infoList": infoList,
- })
- }
-
- func (this *PharmacyController) UpdateInventoryWarehouseInfo() {
-
- id, _ := this.GetInt64("id")
-
- stock_count, _ := this.GetInt64("stock_count")
-
- last_stock_count, _ := this.GetInt64("last_stock_count")
-
- good_id, _ := this.GetInt64("good_id")
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- storehouse_id, _ := this.GetInt64("storehouse_id")
-
- is_type, _ := this.GetInt64("is_type")
-
- warehouseInfo, _ := service.GetInventoryWarehouseInfo(id)
- goodInfo, _ := service.GetGoodInformationByGoodIdThirty(good_id)
-
- manufacturer, _ := service.GetManufactureById(warehouseInfo.Manufacturer)
-
- //更新库存
- service.UpdateWarehouseInfoById(last_stock_count, id)
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- goodListOne, _ := service.GetSumGoodList(orgId, storehouse_id, good_id)
- var flush_count int64
- for _, it := range goodListOne {
- flush_count += it.StockCount
- }
- //盘盈
- if last_stock_count > stock_count {
- var total_count int64
- total_count = last_stock_count - stock_count
- creater := this.GetAdminUserInfo().AdminUser.Id
- inventory := models.XtStockInventory{
- GoodName: goodInfo.GoodName,
- SpecificationName: goodInfo.SpecificationName,
- WarehousingUnit: goodInfo.PackingUnit,
- Count: total_count,
- BuyPrice: goodInfo.BuyPrice,
- PackingPrice: goodInfo.PackingPrice,
- NewPrice: 0,
- Manufacturer: manufacturer.ManufacturerName,
- Dealer: "",
- Remark: "",
- GoodId: good_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: warehouseInfo.WarehousingOrder,
- LicenseNumber: warehouseInfo.LicenseNumber,
- StartTime: time.Now().Unix(),
- Creater: creater,
- Checker: 0,
- CheckerStatus: 0,
- CheckerTime: 0,
- Total: 0,
- Number: warehouseInfo.Number,
- WarehousingInfoId: id,
- ExpireDate: warehouseInfo.ExpiryDate,
- ProductDate: warehouseInfo.ProductDate,
- GoodOriginPlace: "",
- Type: 10,
- InventoryType: is_type,
- LastStockCount: last_stock_count,
- StockCount: stock_count,
- StorehouseId: storehouse_id,
- RecordDate: recordDate.Unix(),
- }
- service.CreateInentory(inventory)
-
- stockFlow := models.VmStockFlow{
- WarehousingId: 0,
- GoodId: good_id,
- Number: warehouseInfo.Number,
- LicenseNumber: "",
- Count: total_count,
- UserOrgId: orgId,
- PatientId: 0,
- SystemTime: recordDate.Unix(),
- ConsumableType: 10,
- IsSys: 0,
- WarehousingOrder: warehouseInfo.WarehousingOrder,
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: 0,
- CancelOrderNumber: "",
- Manufacturer: warehouseInfo.Manufacturer,
- Dealer: 0,
- Creator: creater,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: warehouseInfo.Price,
- WarehousingDetailId: 0,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ProductDate: warehouseInfo.ProductDate,
- ExpireDate: warehouseInfo.ExpiryDate,
- ReturnCount: 0,
- StorehouseId: storehouse_id,
- OverCount: flush_count,
- }
- service.CreateStockFlowOne(stockFlow)
-
- service.ReduceSumOutCount(good_id, total_count, storehouse_id, orgId)
- }
-
- //盘亏
- if last_stock_count < stock_count {
- var total_count int64
- total_count = stock_count - last_stock_count
- creater := this.GetAdminUserInfo().AdminUser.Id
- inventory := models.XtStockInventory{
- GoodName: goodInfo.GoodName,
- SpecificationName: goodInfo.SpecificationName,
- WarehousingUnit: goodInfo.PackingUnit,
- Count: total_count,
- BuyPrice: goodInfo.BuyPrice,
- PackingPrice: goodInfo.PackingPrice,
- NewPrice: 0,
- Manufacturer: manufacturer.ManufacturerName,
- Dealer: "",
- Remark: "",
- GoodId: good_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: warehouseInfo.WarehousingOrder,
- LicenseNumber: warehouseInfo.LicenseNumber,
- StartTime: time.Now().Unix(),
- Creater: creater,
- Checker: 0,
- CheckerStatus: 0,
- CheckerTime: 0,
- Total: 0,
- Number: warehouseInfo.Number,
- WarehousingInfoId: id,
- ExpireDate: warehouseInfo.ExpiryDate,
- ProductDate: warehouseInfo.ProductDate,
- GoodOriginPlace: "",
- Type: 10,
- InventoryType: is_type,
- LastStockCount: last_stock_count,
- StockCount: stock_count,
- StorehouseId: storehouse_id,
- RecordDate: recordDate.Unix(),
- }
- service.CreateInentory(inventory)
-
- stockFlow := models.VmStockFlow{
- WarehousingId: 0,
- GoodId: good_id,
- Number: warehouseInfo.Number,
- LicenseNumber: "",
- Count: total_count,
- UserOrgId: orgId,
- PatientId: 0,
- SystemTime: recordDate.Unix(),
- ConsumableType: 11,
- IsSys: 0,
- WarehousingOrder: warehouseInfo.WarehousingOrder,
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: 0,
- CancelOrderNumber: "",
- Manufacturer: warehouseInfo.Manufacturer,
- Dealer: 0,
- Creator: creater,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: warehouseInfo.Price,
- WarehousingDetailId: 0,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ProductDate: warehouseInfo.ProductDate,
- ExpireDate: warehouseInfo.ExpiryDate,
- ReturnCount: 0,
- StorehouseId: storehouse_id,
- OverCount: flush_count,
- }
- service.CreateStockFlowOne(stockFlow)
- service.ReduceSumInCount(good_id, total_count, storehouse_id, orgId)
- }
-
- //查询已审核单据的剩余库存
- goodList, _ := service.GetGoodSumCountByStoreId(storehouse_id, good_id, orgId)
- var sum_count int64
- var sum_in_count int64
- for _, item := range goodList {
- sum_count += item.StockCount
- sum_in_count += item.WarehousingCount
- }
- service.UpdateGoodByGoodId(good_id, sum_count, sum_in_count, orgId)
-
- service.UpdateSumGood(orgId, storehouse_id, good_id, flush_count)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "msg",
- })
-
- }
-
- func (this *PharmacyController) GetDrugInventoryList() {
-
- keywords := this.GetString("keywords")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- drugList, _ := service.GetDrugNewInventoryList(orgId, keywords)
- manufacturerList, _ := service.GetAllManufacturerList(orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "drugList": drugList,
- "manufacturerList": manufacturerList,
- })
- }
-
- func (this *PharmacyController) GetDrugInventoryByDrugId() {
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- id, _ := this.GetInt64("id")
-
- infoList, _ := service.GetDrugInvetoryByDrugId(orgId, id)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "infoList": infoList,
- })
- }
-
- func (this *PharmacyController) UpdateDrugInventoryWarehouseInfo() {
-
- id, _ := this.GetInt64("id")
- stock_max_number, _ := this.GetInt64("stock_max_number")
- stock_min_number, _ := this.GetInt64("stock_min_number")
- last_stock_max_number, _ := this.GetInt64("last_stock_max_number")
- last_stock_min_number, _ := this.GetInt64("last_stock_min_number")
-
- drug_id, _ := this.GetInt64("drug_id")
- storehouse_id, _ := this.GetInt64("storehouse_id")
- is_type, _ := this.GetInt64("is_type")
-
- specification_name := this.GetString("specification_name")
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- base, _ := service.GetBasedrugByIdOne(drug_id, orgId)
-
- var ord_total int64
- var new_total int64
- var consumable_count int64
-
- ord_total = stock_max_number*base.MinNumber + stock_min_number
- new_total = last_stock_max_number*base.MinNumber + last_stock_min_number
-
- //更新入库单
- service.UpdateNewDrugWarehouseInfoById(id, last_stock_max_number, last_stock_min_number)
-
- //查询默认仓库
- houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- //查询默认仓库剩余多少库存
- list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, drug_id)
- var sum_count int64
- for _, it := range list {
- baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
- if it.MaxUnit == baseDrug.MaxUnit {
- it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
- it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
- }
- sum_count += it.StockMaxNumber + it.StockMinNumber
-
- }
- //更新剩余库存
- service.UpdateMedicalSumCountOne(drug_id, sum_count, orgId)
-
- //更新剩余库存
- service.UpdateDrugStockCount(drug_id, orgId, houseConfig.DrugStorehouseOut, sum_count)
-
- drugWarehouseInfoOne, _ := service.GetDrugWarehouseInfoOne(id)
-
- manufacturer, _ := service.GetManufactureById(drugWarehouseInfoOne.Manufacturer)
-
- recordDateStr := time.Now().Format("2006-01-02")
-
- recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
-
- //盘亏
- if ord_total > new_total {
-
- consumable_count = ord_total - new_total
-
- inventory := models.XtDrugInventory{
- DrugName: base.DrugName,
- SpecificationName: specification_name,
- WarehousingUnit: drugWarehouseInfoOne.MaxUnit,
- Count: consumable_count,
- LastPrice: drugWarehouseInfoOne.Price,
- RetailPrice: drugWarehouseInfoOne.RetailPrice,
- NewPrice: 0,
- Manufacturer: manufacturer.ManufacturerName,
- Dealer: "",
- Remark: "",
- DrugId: drug_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: drugWarehouseInfoOne.WarehousingOrder,
- LicenseNumber: "",
- StartTime: recordDate.Unix(),
- Creater: this.GetAdminUserInfo().AdminUser.Id,
- Checker: 0,
- CheckerStatus: 0,
- CheckerTime: 0,
- ExpiryDate: drugWarehouseInfoOne.ExpiryDate,
- ProductDate: drugWarehouseInfoOne.ProductDate,
- Number: "",
- BatchNumber: drugWarehouseInfoOne.BatchNumber,
- Total: "",
- DrugOriginPlace: "",
- WarehouseInfoId: id,
- ProofCount: 0,
- StockMaxNumber: stock_max_number,
- StockMinNumber: stock_min_number,
- MinCount: 0,
- MinUnit: drugWarehouseInfoOne.MinUnit,
- LastStockMaxNumber: last_stock_max_number,
- LastStockMinNumber: last_stock_min_number,
- InventoryType: 11,
- Type: is_type,
- StorehouseId: storehouse_id,
- RecordDate: recordDate.Unix(),
- }
-
- service.CreateDrugInventory(inventory)
-
- flow := models.DrugFlow{
- WarehousingId: id,
- DrugId: drug_id,
- Number: "",
- BatchNumber: drugWarehouseInfoOne.BatchNumber,
- Count: consumable_count,
- UserOrgId: orgId,
- PatientId: 0,
- SystemTime: recordDate.Unix(),
- ConsumableType: 11,
- IsSys: 1,
- WarehousingOrder: drugWarehouseInfoOne.WarehousingOrder,
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: 0,
- CancelOrderNumber: "",
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: this.GetAdminUserInfo().AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: drugWarehouseInfoOne.Price,
- WarehousingDetailId: id,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ExpireDate: drugWarehouseInfoOne.ExpiryDate,
- ProductDate: 0,
- MaxUnit: drugWarehouseInfoOne.MaxUnit,
- MinUnit: drugWarehouseInfoOne.MinUnit,
- StorehouseId: storehouse_id,
- OverCount: sum_count,
- }
- service.CreateDrugFlowOne(flow)
-
- //添加出库数据
- service.AddDrugWarehouseOut(drug_id, consumable_count, storehouse_id, orgId)
-
- }
-
- //盘盈
- if ord_total < new_total {
-
- consumable_count = new_total - ord_total
-
- inventory := models.XtDrugInventory{
- DrugName: base.DrugName,
- SpecificationName: specification_name,
- WarehousingUnit: drugWarehouseInfoOne.MaxUnit,
- Count: consumable_count,
- LastPrice: drugWarehouseInfoOne.Price,
- RetailPrice: drugWarehouseInfoOne.RetailPrice,
- NewPrice: 0,
- Manufacturer: manufacturer.ManufacturerName,
- Dealer: "",
- Remark: "",
- DrugId: drug_id,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- WarehousingOrder: drugWarehouseInfoOne.WarehousingOrder,
- LicenseNumber: "",
- StartTime: recordDate.Unix(),
- Creater: this.GetAdminUserInfo().AdminUser.Id,
- Checker: 0,
- CheckerStatus: 0,
- CheckerTime: 0,
- ExpiryDate: drugWarehouseInfoOne.ExpiryDate,
- ProductDate: drugWarehouseInfoOne.ProductDate,
- Number: "",
- BatchNumber: drugWarehouseInfoOne.BatchNumber,
- Total: "",
- DrugOriginPlace: "",
- WarehouseInfoId: id,
- ProofCount: 0,
- StockMaxNumber: stock_max_number,
- StockMinNumber: stock_min_number,
- MinCount: 0,
- MinUnit: drugWarehouseInfoOne.MinUnit,
- LastStockMaxNumber: last_stock_max_number,
- LastStockMinNumber: last_stock_min_number,
- InventoryType: 10,
- Type: is_type,
- StorehouseId: storehouse_id,
- RecordDate: recordDate.Unix(),
- }
-
- service.CreateDrugInventory(inventory)
-
- flow := models.DrugFlow{
- WarehousingId: id,
- DrugId: drug_id,
- Number: "",
- BatchNumber: drugWarehouseInfoOne.BatchNumber,
- Count: consumable_count,
- UserOrgId: orgId,
- PatientId: 0,
- SystemTime: recordDate.Unix(),
- ConsumableType: 10,
- IsSys: 1,
- WarehousingOrder: drugWarehouseInfoOne.WarehousingOrder,
- WarehouseOutId: 0,
- WarehouseOutOrderNumber: "",
- IsEdit: 0,
- CancelStockId: 0,
- CancelOrderNumber: "",
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: this.GetAdminUserInfo().AdminUser.Id,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: drugWarehouseInfoOne.Price,
- WarehousingDetailId: id,
- WarehouseOutDetailId: 0,
- CancelOutDetailId: 0,
- ExpireDate: drugWarehouseInfoOne.ExpiryDate,
- ProductDate: 0,
- MaxUnit: drugWarehouseInfoOne.MaxUnit,
- MinUnit: drugWarehouseInfoOne.MinUnit,
- StorehouseId: storehouse_id,
- OverCount: sum_count,
- }
- service.CreateDrugFlowOne(flow)
-
- //减少出库数据
- service.ReduceDrugWarehouseOut(drug_id, consumable_count, storehouse_id, orgId)
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "msg",
- })
- }
-
- func (this *PharmacyController) ChangeDrugCode() {
-
- id, _ := this.GetInt64("id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- data_source, _ := this.GetInt64("data_source")
- drug_code := this.GetString("drug_code")
- str := strings.Replace(drug_code, " ", "", -1)
- // 去除换行符
- str = strings.Replace(str, "\n", "", -1)
- if data_source == 1 {
- service.ChangeHisDrugCode(id, str, orgId)
- }
- if data_source == 2 {
- service.ChangeAdivceDrugCode(id, str, orgId)
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "msg",
- })
- }
-
- func (this *PharmacyController) ChangeZeroFlag() {
- id, _ := this.GetInt64("id")
- orgId := this.GetAdminUserInfo().CurrentOrgId
- zero_flag, _ := this.GetInt64("zero_flag")
- fmt.Println(id)
- fmt.Println(zero_flag)
- service.ChangeAdivceZeroFlag(id, zero_flag, orgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "msg",
- })
-
- }
|