pharmacy_controller.go 44KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  1. package controllers
  2. import (
  3. "fmt"
  4. "math"
  5. "strconv"
  6. "strings"
  7. "time"
  8. "XT_New/enums"
  9. "XT_New/models"
  10. "XT_New/service"
  11. "XT_New/utils"
  12. "github.com/astaxie/beego"
  13. )
  14. type PharmacyController struct {
  15. BaseAuthAPIController
  16. }
  17. func PharmacyApiRegistRouters() {
  18. beego.Router("/api/pharmacy/ceshili", &PharmacyController{}, "get:Tlili")
  19. beego.Router("/api/pharmacy/todaynumber", &PharmacyController{}, "get:TodayNumber") //查询今天的待发药,已发药人数(
  20. beego.Router("/api/pharmacy/waitingdrug", &PharmacyController{}, "get:WaitingDrug") //获取当天待发药的所有患者(
  21. beego.Router("/api/pharmacy/issueddrugs", &PharmacyController{}, "get:IssuedDrug") //获取当天已发药的所有患者(
  22. beego.Router("/api/pharmacy/getpharmacycontent", &PharmacyController{}, "get:GetPharmacyContent") //获取当天该患者的所有信息(
  23. beego.Router("/api/pharmacy/dispensingmedicine", &PharmacyController{}, "get:DispensingMedicine") //患者发药按钮点击(
  24. beego.Router("/api/pharmacy/drugwithdrawal", &PharmacyController{}, "get:DrugWithdrawal") //退药按钮点击
  25. beego.Router("/api/pharmacy/dispensingdetails", &PharmacyController{}, "get:DispensingDetails") //获取发药明细的患者列表(
  26. beego.Router("/api/pharmacy/prescriptiondetails", &PharmacyController{}, "get:PrescriptionDetails") //发药明细-详情(
  27. beego.Router("/api/pharmacy/dispensemedicine", &PharmacyController{}, "get:DispenseMedicine") //获取当天已发药的药品(
  28. beego.Router("/api/pharmacy/waitingmedicine", &PharmacyController{}, "get:WaitingMedicine") //获取当天待发药的药品(
  29. beego.Router("/api/pharmacy/getpatientswithdrugs", &PharmacyController{}, "get:GetPatientsWithDrugs") //获取当天该药品的所有患者(
  30. beego.Router("/api/pharmacy/medicinedeparture", &PharmacyController{}, "get:MedicineDeparture") //药品发药按钮点击(
  31. beego.Router("/api/pharmacy/getcurrentname", &PharmacyController{}, "get:GetCurrentName") //获取当前登录账号的名字(
  32. beego.Router("/api/pharmacy/getpartitionlist", &PharmacyController{}, "get:GetPartitionList") //获取当前机构的分区列表
  33. beego.Router("/api/pharmacy/routeofadministration", &PharmacyController{}, "get:RouteOfAdministration") //获取当前机构的给药途径
  34. beego.Router("/api/pharmacy/getgoodinventorylist", &PharmacyController{}, "Get:GetGoodInventoryList")
  35. beego.Router("/api/pharmacy/getgoodinventorybygoodid", &PharmacyController{}, "Get:GetGoodInventoryByGoodId")
  36. beego.Router("/api/pharmacy/updateInventoryWarehouseInfo", &PharmacyController{}, "Get:UpdateInventoryWarehouseInfo")
  37. beego.Router("/api/pharmacy/getdrugnewinventoryList", &PharmacyController{}, "Get:GetDrugInventoryList")
  38. beego.Router("/api/pharmacy/getdruginventorybydrugid", &PharmacyController{}, "Get:GetDrugInventoryByDrugId")
  39. beego.Router("/api/pharmacy/updatedruginventorywarehouseinfo", &PharmacyController{}, "Get:UpdateDrugInventoryWarehouseInfo")
  40. beego.Router("/api/pharmacy/changedrugcode", &PharmacyController{}, "Get:ChangeDrugCode")
  41. }
  42. // 测试
  43. func (this *PharmacyController) Tlili() {
  44. var err error
  45. defer func() {
  46. if rec := recover(); rec != nil {
  47. err = fmt.Errorf("程序异常:%v", rec)
  48. }
  49. if err != nil {
  50. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  51. }
  52. }()
  53. var list2 []*models.ReplacementDrugs
  54. list2, err = service.ReplacementDrugs(9675, false)
  55. if err != nil {
  56. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  57. return
  58. }
  59. this.ServeSuccessJSON(map[string]interface{}{
  60. "list": list2,
  61. })
  62. return
  63. }
  64. func (this *PharmacyController) GetCurrentName() {
  65. create := this.GetAdminUserInfo().AdminUser.Id
  66. this.ServeSuccessJSON(map[string]interface{}{
  67. "list": create,
  68. })
  69. return
  70. }
  71. // 查询今天的待发药,已发药人数
  72. func (this *PharmacyController) TodayNumber() {
  73. var err error
  74. defer func() {
  75. if rec := recover(); rec != nil {
  76. err = fmt.Errorf("程序异常:%v", rec)
  77. }
  78. if err != nil {
  79. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  80. }
  81. }()
  82. orgid := this.GetAdminUserInfo().CurrentOrgId
  83. times := this.GetString("time", "")
  84. timeLayout := "2006-01-02"
  85. loc, _ := time.LoadLocation("Local")
  86. var stime, etime int64
  87. if times == "" {
  88. stime, etime = service.GetNowTime()
  89. } else {
  90. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  91. stime = stmp.Unix()
  92. etime = stime + 86399
  93. }
  94. //if orgid != 9671 && orgid != 10188 && orgid != 10217 && orgid != 3877 && orgid != 10164 && orgid != 10480 {
  95. // //查询表里当天的数据
  96. // var wtotal int
  97. // wtotal, err = service.GetTodayPharmacy(stime, etime, orgid, 1)
  98. //
  99. // if err != nil {
  100. // utils.ErrorLog(err.Error())
  101. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  102. // return
  103. // }
  104. //
  105. // var itotal int
  106. // itotal, err = service.GetTodayPharmacy(stime, etime, orgid, 0)
  107. //
  108. // drug, _ := service.GetAllBaseDrugList(orgid)
  109. // if err != nil {
  110. // utils.ErrorLog(err.Error())
  111. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  112. // return
  113. // }
  114. // this.ServeSuccessJSON(map[string]interface{}{
  115. // "wtotal": wtotal,
  116. // "itotal": itotal,
  117. // "drug": drug,
  118. // })
  119. // return
  120. //}
  121. var wtotal int
  122. var itotal int
  123. //查找出库数量
  124. wtotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 1)
  125. itotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 0)
  126. drug, _ := service.GetAllBaseDrugList(orgid)
  127. config, _ := service.GetDrugCodeConfig(orgid)
  128. this.ServeSuccessJSON(map[string]interface{}{
  129. "wtotal": wtotal,
  130. "itotal": itotal,
  131. "drug": drug,
  132. "config": config,
  133. })
  134. return
  135. }
  136. func (this *PharmacyController) IssuedDrug() {
  137. var err error
  138. defer func() {
  139. if rec := recover(); rec != nil {
  140. err = fmt.Errorf("程序异常:%v", rec)
  141. }
  142. if err != nil {
  143. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  144. }
  145. }()
  146. keyword := this.GetString("keyword", "")
  147. fmt.Println(keyword)
  148. times := this.GetString("time", "")
  149. orgid := this.GetAdminUserInfo().CurrentOrgId
  150. shift, err := this.GetInt64("shift", 0) //班次
  151. if err != nil {
  152. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  153. return
  154. }
  155. partition, err := this.GetInt64("partition", 0) //分区
  156. if err != nil {
  157. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  158. return
  159. }
  160. timeLayout := "2006-01-02"
  161. loc, _ := time.LoadLocation("Local")
  162. var stime, etime int64
  163. if times == "" {
  164. stime, etime = service.GetNowTime()
  165. } else {
  166. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  167. stime = stmp.Unix()
  168. etime = stime + 86399
  169. }
  170. var patientsId []int64
  171. patient, _ := service.GetPatientKeyWord(keyword, orgid)
  172. if len(patient) > 0 {
  173. for _, item := range patient {
  174. patientsId = append(patientsId, item.ID)
  175. }
  176. }
  177. //获取排班班次
  178. schedule, _ := service.GetSchedulePatientId(stime, etime, orgid, shift, partition, patientsId)
  179. var ids []int64
  180. for _, item := range schedule {
  181. ids = append(ids, item.PatientId)
  182. }
  183. list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 1, ids)
  184. var flist []models.TmpPatientOne
  185. if len(list) > 0 {
  186. for _, item := range list {
  187. patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
  188. flist = append(flist, patientlist)
  189. }
  190. }
  191. listTwo, _ := service.GetTodayAdviceCountTwo(stime, etime, orgid, 1)
  192. var vlist []*models.HisDoctorAdviceInfo
  193. if len(listTwo) > 0 {
  194. for _, item := range listTwo {
  195. //查询该患者是否有排班
  196. scheduleList, _ := service.GetPatientAdviceScheduleByPatient(item.PatientId, item.UserOrgId, item.AdviceDate)
  197. if len(scheduleList) == 0 {
  198. vlist = append(vlist, item)
  199. }
  200. }
  201. }
  202. this.ServeSuccessJSON(map[string]interface{}{
  203. "list": flist,
  204. "listTwo": vlist,
  205. })
  206. //if orgid != 10164 && orgid == 3877 && orgid != 10188 && orgid != 10217 && orgid != 9671 && orgid != 10387 && orgid != 10375 && orgid != 10480 && orgid == 10344 {
  207. // //查询表里当天的数据
  208. // var flist []*models.TmpPatient
  209. // flist, err = service.GetTodayDrug(stime, etime, orgid, 1, keyword)
  210. // if err != nil {
  211. // utils.ErrorLog(err.Error())
  212. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  213. // return
  214. // }
  215. // listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
  216. // if err != nil {
  217. // utils.ErrorLog(err.Error())
  218. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  219. // return
  220. // }
  221. // this.ServeSuccessJSON(map[string]interface{}{
  222. // "list": listt,
  223. // })
  224. // return
  225. //}
  226. }
  227. func (this *PharmacyController) WaitingDrug() {
  228. var err error
  229. defer func() {
  230. if rec := recover(); rec != nil {
  231. err = fmt.Errorf("程序异常:%v", rec)
  232. }
  233. if err != nil {
  234. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  235. }
  236. }()
  237. keyword := this.GetString("keyword", "")
  238. times := this.GetString("time", "")
  239. shift, err := this.GetInt64("shift", 0) //班次
  240. if err != nil {
  241. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  242. return
  243. }
  244. partition, err := this.GetInt64("partition", 0) //分区
  245. if err != nil {
  246. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  247. return
  248. }
  249. orgid := this.GetAdminUserInfo().CurrentOrgId
  250. timeLayout := "2006-01-02"
  251. loc, _ := time.LoadLocation("Local")
  252. var stime, etime int64
  253. if times == "" {
  254. stime, etime = service.GetNowTime()
  255. } else {
  256. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  257. stime = stmp.Unix()
  258. etime = stime + 86399
  259. }
  260. var patientsId []int64
  261. patient, _ := service.GetPatientKeyWord(keyword, orgid)
  262. if len(patient) > 0 {
  263. for _, item := range patient {
  264. patientsId = append(patientsId, item.ID)
  265. }
  266. }
  267. //当未发药的人数
  268. //获取排班班次
  269. schedule, _ := service.GetSchedulePatientId(stime, etime, orgid, shift, partition, patientsId)
  270. var ids []int64
  271. for _, item := range schedule {
  272. ids = append(ids, item.PatientId)
  273. }
  274. list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 0, ids)
  275. listTwo, _ := service.GetTodayAdviceCountTwo(stime, etime, orgid, 0)
  276. var vlist []*models.HisDoctorAdviceInfo
  277. if len(listTwo) > 0 {
  278. for _, item := range listTwo {
  279. //查询该患者是否有排班
  280. scheduleList, _ := service.GetPatientAdviceScheduleByPatient(item.PatientId, item.UserOrgId, item.AdviceDate)
  281. if len(scheduleList) == 0 {
  282. vlist = append(vlist, item)
  283. }
  284. }
  285. }
  286. patientList, _ := service.GetAllpatient(orgid)
  287. var flist []models.TmpPatientOne
  288. if len(list) > 0 {
  289. for _, item := range list {
  290. patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
  291. flist = append(flist, patientlist)
  292. }
  293. }
  294. baseList, _ := service.GetAllBaseDrugListTwo(orgid)
  295. this.ServeSuccessJSON(map[string]interface{}{
  296. "list": flist,
  297. "baseList": baseList,
  298. "listTwo": vlist,
  299. "patientList": patientList,
  300. })
  301. return
  302. }
  303. func (this *PharmacyController) GetPharmacyContent() {
  304. var err error
  305. defer func() {
  306. if rec := recover(); rec != nil {
  307. err = fmt.Errorf("程序异常:%v", rec)
  308. }
  309. if err != nil {
  310. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  311. }
  312. }()
  313. patient_id, _ := this.GetInt64("patient_id", 0)
  314. is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
  315. times := this.GetString("time", "")
  316. orgid := this.GetAdminUserInfo().CurrentOrgId
  317. timeLayout := "2006-01-02"
  318. loc, _ := time.LoadLocation("Local")
  319. var stime, etime int64
  320. if times == "" {
  321. stime, etime = service.GetNowTime()
  322. } else {
  323. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  324. stime = stmp.Unix()
  325. etime = stime + 86399
  326. }
  327. var list []*models.PharmacyContent
  328. list, err = service.GetPatientMedication(orgid, patient_id, stime, etime, is_medicine)
  329. baseList, _ := service.GetAllBaseDrugListTwo(orgid)
  330. patients, _ := service.GetPatientByIDOne(orgid, patient_id)
  331. order, _ := service.GetMobiledialysiOrder(orgid, patient_id, stime)
  332. numberList, _ := service.GetAllBedNumberList(orgid)
  333. zoneList, _ := service.GetAllZoneByList(orgid)
  334. appId := this.GetAdminUserInfo().CurrentAppId
  335. adminUserES, _ := service.GetAllAdminUserES(orgid, appId)
  336. allDoctor, _ := service.GetAllDoctor(orgid, appId)
  337. prescriptionListByToDay, _ := service.GetPrescriptionListByToDay(orgid, patient_id, stime)
  338. diagnose, _ := service.FindAllDiagnose(orgid)
  339. config, _ := service.GetDrugCodeConfig(orgid)
  340. if err != nil {
  341. utils.ErrorLog(err.Error())
  342. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  343. return
  344. }
  345. return_value := make(map[string]interface{})
  346. return_value["list"] = list
  347. return_value["baseList"] = baseList
  348. return_value["patients"] = patients
  349. return_value["order"] = order
  350. return_value["numberList"] = numberList
  351. return_value["zoneList"] = zoneList
  352. return_value["adminUserES"] = adminUserES
  353. return_value["doctors"] = allDoctor
  354. return_value["prescription"] = prescriptionListByToDay
  355. return_value["diagnose"] = diagnose
  356. return_value["config"] = config
  357. //if is_medicine == 1{发药时间先不展示
  358. // return_value["time"] = time
  359. //}
  360. this.ServeSuccessJSON(return_value)
  361. return
  362. }
  363. // 发药按钮点击
  364. func (this *PharmacyController) DispensingMedicine() {
  365. var err error
  366. defer func() {
  367. if rec := recover(); rec != nil {
  368. err = fmt.Errorf("程序异常:%v", rec)
  369. }
  370. if err != nil {
  371. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  372. }
  373. }()
  374. patient_id, _ := this.GetInt64("patient_id", 0)
  375. times := this.GetString("time", "")
  376. orgid := this.GetAdminUserInfo().CurrentOrgId
  377. creater := this.GetAdminUserInfo().AdminUser.Id
  378. timeLayout := "2006-01-02"
  379. loc, _ := time.LoadLocation("Local")
  380. var stime, etime int64
  381. if times == "" {
  382. stime, etime = service.GetNowTime()
  383. } else {
  384. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  385. stime = stmp.Unix()
  386. etime = stime + 86399
  387. }
  388. tmp_bool := service.IsPharmacyConfig(orgid)
  389. codeConfig, _ := service.GetDrugCodeConfig(orgid)
  390. if tmp_bool == true {
  391. advicelist, _ := service.FindeHisAdviceDocAdvice(orgid, patient_id, stime, etime)
  392. if len(advicelist) > 0 {
  393. var total int64
  394. var prescribing_number_total int64
  395. for _, item := range advicelist {
  396. if codeConfig.IsOpen == 1 {
  397. if item.DrugCode == "" || len(item.DrugCode) == 0 {
  398. err := fmt.Errorf(service.FindDrugsName(item.DrugId) + "药品追溯码不能为空")
  399. if err != nil {
  400. utils.ErrorLog(err.Error())
  401. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  402. return
  403. }
  404. }
  405. }
  406. //查询改药品信息
  407. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  408. //如果是药房发药的方式
  409. if medical.IsPharmacy == 1 {
  410. houseConfig, _ := service.GetAllStoreHouseConfig(orgid)
  411. //查询该药品是否有库存
  412. list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  413. //判断单位是否相等
  414. if medical.MaxUnit == item.PrescribingNumberUnit {
  415. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  416. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  417. //转化为最小单位
  418. total = list.Count*medical.MinNumber + list.StockMinNumber
  419. prescribing_number_total = count * medical.MinNumber
  420. }
  421. if medical.MinUnit == item.PrescribingNumberUnit {
  422. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  423. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  424. total = list.Count*medical.MinNumber + list.StockMinNumber
  425. prescribing_number_total = count
  426. }
  427. if medical.IsUse != 1 {
  428. //如果出库数量大于库存数量
  429. if prescribing_number_total > total {
  430. err := fmt.Errorf(service.FindDrugsName(item.DrugId) + "库存不足")
  431. if err != nil {
  432. utils.ErrorLog(err.Error())
  433. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  434. return
  435. }
  436. }
  437. }
  438. }
  439. }
  440. }
  441. }
  442. if orgid != 10480 && orgid != 10188 && orgid != 10217 && orgid != 10164 && orgid != 10666 {
  443. //发药
  444. err = service.DispensingMedicine(orgid, patient_id, stime, etime, creater)
  445. if err != nil {
  446. utils.ErrorLog(err.Error())
  447. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  448. return
  449. }
  450. this.ServeSuccessJSON(map[string]interface{}{
  451. "list": "操作成功",
  452. })
  453. return
  454. }
  455. if orgid == 10480 || orgid == 10188 || orgid == 10217 || orgid == 10164 || orgid == 10666 {
  456. //发药逻辑
  457. service.DispensingMedicineOne(orgid, patient_id, stime, etime, creater)
  458. //针对桑植盛康
  459. if orgid == 10387 || orgid == 3877 {
  460. advicelist, _ := service.FindeHisAdviceDocAdvice(orgid, patient_id, stime, etime)
  461. if len(advicelist) > 0 {
  462. for _, item := range advicelist {
  463. //查询改药品信息
  464. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  465. if medical.IsPharmacy == 1 {
  466. flow, _ := service.GetFlow(item.DrugId, item.AdviceDate, orgid, item.PatientId)
  467. if len(flow) > 0 {
  468. service.UpdateAdviceFlow(item.ID)
  469. }
  470. }
  471. }
  472. }
  473. }
  474. if err != nil {
  475. utils.ErrorLog(err.Error())
  476. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  477. return
  478. }
  479. this.ServeSuccessJSON(map[string]interface{}{
  480. "list": "操作成功",
  481. })
  482. return
  483. }
  484. }
  485. // 退药按钮点击
  486. func (this *PharmacyController) DrugWithdrawal() {
  487. var err error
  488. defer func() {
  489. if rec := recover(); rec != nil {
  490. err = fmt.Errorf("程序异常:%v", rec)
  491. }
  492. if err != nil {
  493. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  494. }
  495. }()
  496. patient_id, _ := this.GetInt64("patient_id", 0)
  497. times := this.GetString("time", "")
  498. orgid := this.GetAdminUserInfo().CurrentOrgId
  499. creater := this.GetAdminUserInfo().AdminUser.Id
  500. timeLayout := "2006-01-02"
  501. loc, _ := time.LoadLocation("Local")
  502. var stime, etime int64
  503. if times == "" {
  504. stime, etime = service.GetNowTime()
  505. } else {
  506. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  507. stime = stmp.Unix()
  508. etime = stime + 86399
  509. }
  510. err = service.DrugWithdrawal(orgid, patient_id, stime, etime, creater)
  511. if err != nil {
  512. utils.ErrorLog(err.Error())
  513. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  514. return
  515. }
  516. this.ServeSuccessJSON(map[string]interface{}{
  517. "list": "操作成功",
  518. })
  519. return
  520. }
  521. // 发药明细列表
  522. func (this *PharmacyController) DispensingDetails() {
  523. var err error
  524. defer func() {
  525. if rec := recover(); rec != nil {
  526. err = fmt.Errorf("程序异常:%v", rec)
  527. }
  528. if err != nil {
  529. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  530. }
  531. }()
  532. keyword := this.GetString("keyword", "") //患者名称
  533. start_time := this.GetString("start_time", "") //开始时间
  534. end_time := this.GetString("end_time", "") //结束时间
  535. page, _ := this.GetInt64("page", 1) //页码
  536. limit, _ := this.GetInt64("limit", 10) //每一页查出来的条数
  537. orgid := this.GetAdminUserInfo().CurrentOrgId
  538. timeLayout := "2006-01-02"
  539. loc, _ := time.LoadLocation("Local")
  540. var stime, etime int64
  541. if start_time == "" {
  542. stime = 1
  543. } else {
  544. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  545. stime = stmp.Unix()
  546. }
  547. if end_time == "" {
  548. _, etime = service.GetNowTime()
  549. } else {
  550. etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  551. etime = etmp.Unix()
  552. }
  553. var dislist []*models.DispensingList
  554. var total int64
  555. dislist, total, err = service.DispensingDetailsList(stime, etime, orgid, page, limit, keyword)
  556. if err != nil {
  557. utils.ErrorLog(err.Error())
  558. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  559. return
  560. }
  561. this.ServeSuccessJSON(map[string]interface{}{
  562. "list": dislist,
  563. "total": total,
  564. })
  565. return
  566. }
  567. // 处方详情
  568. func (this *PharmacyController) PrescriptionDetails() {
  569. var err error
  570. defer func() {
  571. if rec := recover(); rec != nil {
  572. err = fmt.Errorf("程序异常:%v", rec)
  573. }
  574. if err != nil {
  575. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  576. }
  577. }()
  578. //患者姓名
  579. patient_id, _ := this.GetInt64("patient_id", 0)
  580. //发药时间
  581. record_date, _ := this.GetInt64("record_date", 0)
  582. orgid := this.GetAdminUserInfo().CurrentOrgId
  583. if record_date == 0 || patient_id == 0 {
  584. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数不足")
  585. return
  586. }
  587. var list []*models.PrescripDetails
  588. list, err = service.PrescriptionDetails(patient_id, record_date, orgid)
  589. if err != nil {
  590. utils.ErrorLog(err.Error())
  591. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  592. return
  593. }
  594. this.ServeSuccessJSON(map[string]interface{}{
  595. "list": list,
  596. })
  597. return
  598. }
  599. // 已发药品的信息
  600. func (this *PharmacyController) DispenseMedicine() {
  601. var err error
  602. defer func() {
  603. if rec := recover(); rec != nil {
  604. err = fmt.Errorf("程序异常:%v", rec)
  605. }
  606. if err != nil {
  607. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  608. }
  609. }()
  610. keyword := this.GetString("keyword", "")
  611. times := this.GetString("time", "")
  612. orgid := this.GetAdminUserInfo().CurrentOrgId
  613. timeLayout := "2006-01-02"
  614. loc, _ := time.LoadLocation("Local")
  615. deliveryway := this.GetString("deliveryway", "")
  616. var stime, etime int64
  617. if times == "" {
  618. stime, etime = service.GetNowTime()
  619. } else {
  620. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  621. stime = stmp.Unix()
  622. etime = stime + 86399
  623. }
  624. //查询表里当天的数据
  625. var flist []*models.ListOfDrugs
  626. flist, err = service.GetTodayMedicine(stime, etime, orgid, 1, keyword)
  627. if err != nil {
  628. utils.ErrorLog(err.Error())
  629. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  630. return
  631. }
  632. llist, err := service.Administration(deliveryway, orgid, flist)
  633. if err != nil {
  634. utils.ErrorLog(err.Error())
  635. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  636. return
  637. }
  638. this.ServeSuccessJSON(map[string]interface{}{
  639. "list": llist,
  640. })
  641. return
  642. }
  643. // 待发药的药品信息
  644. func (this *PharmacyController) WaitingMedicine() {
  645. var err error
  646. defer func() {
  647. if rec := recover(); rec != nil {
  648. err = fmt.Errorf("程序异常:%v", rec)
  649. }
  650. if err != nil {
  651. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  652. }
  653. }()
  654. keyword := this.GetString("keyword", "")
  655. times := this.GetString("time", "")
  656. orgid := this.GetAdminUserInfo().CurrentOrgId
  657. timeLayout := "2006-01-02"
  658. loc, _ := time.LoadLocation("Local")
  659. deliveryway := this.GetString("deliveryway", "")
  660. var stime, etime int64
  661. if times == "" {
  662. stime, etime = service.GetNowTime()
  663. } else {
  664. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  665. stime = stmp.Unix()
  666. etime = stime + 86399
  667. }
  668. //查询表里当天的数据
  669. var flist []*models.ListOfDrugs
  670. flist, err = service.GetTodayMedicine(stime, etime, orgid, 0, keyword)
  671. if err != nil {
  672. utils.ErrorLog(err.Error())
  673. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  674. return
  675. }
  676. llist, err := service.Administration(deliveryway, orgid, flist)
  677. if err != nil {
  678. utils.ErrorLog(err.Error())
  679. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  680. return
  681. }
  682. this.ServeSuccessJSON(map[string]interface{}{
  683. "list": llist,
  684. })
  685. return
  686. }
  687. // 获取药品的所有患者信息
  688. func (this *PharmacyController) GetPatientsWithDrugs() {
  689. var err error
  690. defer func() {
  691. if rec := recover(); rec != nil {
  692. err = fmt.Errorf("程序异常:%v", rec)
  693. }
  694. if err != nil {
  695. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  696. }
  697. }()
  698. drug_id, _ := this.GetInt64("drug_id", 0)
  699. is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
  700. times := this.GetString("time", "")
  701. orgid := this.GetAdminUserInfo().CurrentOrgId
  702. deliveryway := this.GetString("deliveryway", "")
  703. if deliveryway == "" {
  704. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  705. return
  706. }
  707. shift, err := this.GetInt64("shift", 0) //班次
  708. if err != nil {
  709. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  710. return
  711. }
  712. partition, err := this.GetInt64("partition", 0) //分区
  713. if err != nil {
  714. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  715. return
  716. }
  717. timeLayout := "2006-01-02"
  718. loc, _ := time.LoadLocation("Local")
  719. var stime, etime int64
  720. if times == "" {
  721. stime, etime = service.GetNowTime()
  722. } else {
  723. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  724. stime = stmp.Unix()
  725. etime = stime + 86399
  726. }
  727. var list []*models.PatientInformation
  728. list, err = service.FindMedicationList(orgid, drug_id, stime, etime, is_medicine)
  729. if err != nil {
  730. utils.ErrorLog(err.Error())
  731. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  732. return
  733. }
  734. listll, err := service.PartitionAndLayoutDrug(deliveryway, stime, etime, orgid, shift, partition, list)
  735. if err != nil {
  736. utils.ErrorLog(err.Error())
  737. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  738. return
  739. }
  740. total, err := service.CalculateTheTotalAmount(listll, drug_id)
  741. if err != nil {
  742. utils.ErrorLog(err.Error())
  743. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  744. return
  745. }
  746. this.ServeSuccessJSON(map[string]interface{}{
  747. "list": listll,
  748. "total": total,
  749. })
  750. return
  751. }
  752. // 药品管理发药按钮点击
  753. func (this *PharmacyController) MedicineDeparture() {
  754. var err error
  755. defer func() {
  756. if rec := recover(); rec != nil {
  757. err = fmt.Errorf("程序异常:%v", rec)
  758. }
  759. if err != nil {
  760. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  761. }
  762. }()
  763. creater, _ := this.GetInt64("creater", 0) //领药人
  764. ids := this.GetString("ids", "") //发药的数据
  765. orgid := this.GetAdminUserInfo().CurrentOrgId
  766. if ids == "" {
  767. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数不足")
  768. return
  769. }
  770. err = service.MedicineDeparture(ids, creater, orgid)
  771. if err != nil {
  772. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  773. return
  774. }
  775. this.ServeSuccessJSON(map[string]interface{}{
  776. "list": "修改成功",
  777. })
  778. return
  779. }
  780. func (this *PharmacyController) GetPartitionList() {
  781. var err error
  782. defer func() {
  783. if rec := recover(); rec != nil {
  784. err = fmt.Errorf("程序异常:%v", rec)
  785. }
  786. if err != nil {
  787. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  788. }
  789. }()
  790. orgid := this.GetAdminUserInfo().CurrentOrgId
  791. tmp := []*models.DeviceZone{{ID: 0, Name: "全部分区"}}
  792. list, err := service.GetAllValidDeviceZones02(orgid)
  793. if err != nil {
  794. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  795. return
  796. }
  797. this.ServeSuccessJSON(map[string]interface{}{
  798. "list": append(tmp, list...),
  799. })
  800. return
  801. }
  802. func (this *PharmacyController) RouteOfAdministration() {
  803. var err error
  804. defer func() {
  805. if rec := recover(); rec != nil {
  806. err = fmt.Errorf("程序异常:%v", rec)
  807. }
  808. if err != nil {
  809. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  810. }
  811. }()
  812. orgid := this.GetAdminUserInfo().CurrentOrgId
  813. tmp := []*models.DrugwayDic{{ID: 0, Name: "全部"}}
  814. list, _, err := service.GetDrugWayDics(orgid)
  815. if err != nil {
  816. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  817. return
  818. }
  819. this.ServeSuccessJSON(map[string]interface{}{
  820. "list": append(tmp, list...),
  821. })
  822. return
  823. }
  824. func (this *PharmacyController) GetGoodInventoryList() {
  825. keyword := this.GetString("keywords")
  826. orgId := this.GetAdminUserInfo().CurrentOrgId
  827. list, _ := service.GetGoodInventoryList(keyword, orgId)
  828. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  829. this.ServeSuccessJSON(map[string]interface{}{
  830. "list": list,
  831. "manufacturerList": manufacturerList,
  832. })
  833. return
  834. }
  835. func (this *PharmacyController) GetGoodInventoryByGoodId() {
  836. id, _ := this.GetInt64("id")
  837. infoList, _ := service.GetGoodInventoryByGoodId(id)
  838. this.ServeSuccessJSON(map[string]interface{}{
  839. "infoList": infoList,
  840. })
  841. }
  842. func (this *PharmacyController) UpdateInventoryWarehouseInfo() {
  843. id, _ := this.GetInt64("id")
  844. stock_count, _ := this.GetInt64("stock_count")
  845. last_stock_count, _ := this.GetInt64("last_stock_count")
  846. good_id, _ := this.GetInt64("good_id")
  847. orgId := this.GetAdminUserInfo().CurrentOrgId
  848. storehouse_id, _ := this.GetInt64("storehouse_id")
  849. is_type, _ := this.GetInt64("is_type")
  850. warehouseInfo, _ := service.GetInventoryWarehouseInfo(id)
  851. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(good_id)
  852. manufacturer, _ := service.GetManufactureById(warehouseInfo.Manufacturer)
  853. //更新库存
  854. service.UpdateWarehouseInfoById(last_stock_count, id)
  855. recordDateStr := time.Now().Format("2006-01-02")
  856. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  857. goodListOne, _ := service.GetSumGoodList(orgId, storehouse_id, good_id)
  858. var flush_count int64
  859. for _, it := range goodListOne {
  860. flush_count += it.StockCount
  861. }
  862. //盘盈
  863. if last_stock_count > stock_count {
  864. var total_count int64
  865. total_count = last_stock_count - stock_count
  866. creater := this.GetAdminUserInfo().AdminUser.Id
  867. inventory := models.XtStockInventory{
  868. GoodName: goodInfo.GoodName,
  869. SpecificationName: goodInfo.SpecificationName,
  870. WarehousingUnit: goodInfo.PackingUnit,
  871. Count: total_count,
  872. BuyPrice: goodInfo.BuyPrice,
  873. PackingPrice: goodInfo.PackingPrice,
  874. NewPrice: 0,
  875. Manufacturer: manufacturer.ManufacturerName,
  876. Dealer: "",
  877. Remark: "",
  878. GoodId: good_id,
  879. UserOrgId: orgId,
  880. Ctime: time.Now().Unix(),
  881. Mtime: 0,
  882. Status: 1,
  883. WarehousingOrder: warehouseInfo.WarehousingOrder,
  884. LicenseNumber: warehouseInfo.LicenseNumber,
  885. StartTime: time.Now().Unix(),
  886. Creater: creater,
  887. Checker: 0,
  888. CheckerStatus: 0,
  889. CheckerTime: 0,
  890. Total: 0,
  891. Number: warehouseInfo.Number,
  892. WarehousingInfoId: id,
  893. ExpireDate: warehouseInfo.ExpiryDate,
  894. ProductDate: warehouseInfo.ProductDate,
  895. GoodOriginPlace: "",
  896. Type: 10,
  897. InventoryType: is_type,
  898. LastStockCount: last_stock_count,
  899. StockCount: stock_count,
  900. StorehouseId: storehouse_id,
  901. RecordDate: recordDate.Unix(),
  902. }
  903. service.CreateInentory(inventory)
  904. stockFlow := models.VmStockFlow{
  905. WarehousingId: 0,
  906. GoodId: good_id,
  907. Number: warehouseInfo.Number,
  908. LicenseNumber: "",
  909. Count: total_count,
  910. UserOrgId: orgId,
  911. PatientId: 0,
  912. SystemTime: recordDate.Unix(),
  913. ConsumableType: 10,
  914. IsSys: 0,
  915. WarehousingOrder: warehouseInfo.WarehousingOrder,
  916. WarehouseOutId: 0,
  917. WarehouseOutOrderNumber: "",
  918. IsEdit: 0,
  919. CancelStockId: 0,
  920. CancelOrderNumber: "",
  921. Manufacturer: warehouseInfo.Manufacturer,
  922. Dealer: 0,
  923. Creator: creater,
  924. UpdateCreator: 0,
  925. Status: 1,
  926. Ctime: time.Now().Unix(),
  927. Mtime: 0,
  928. Price: warehouseInfo.Price,
  929. WarehousingDetailId: 0,
  930. WarehouseOutDetailId: 0,
  931. CancelOutDetailId: 0,
  932. ProductDate: warehouseInfo.ProductDate,
  933. ExpireDate: warehouseInfo.ExpiryDate,
  934. ReturnCount: 0,
  935. StorehouseId: storehouse_id,
  936. OverCount: flush_count,
  937. }
  938. service.CreateStockFlowOne(stockFlow)
  939. service.ReduceSumOutCount(good_id, total_count, storehouse_id, orgId)
  940. }
  941. //盘亏
  942. if last_stock_count < stock_count {
  943. var total_count int64
  944. total_count = stock_count - last_stock_count
  945. creater := this.GetAdminUserInfo().AdminUser.Id
  946. inventory := models.XtStockInventory{
  947. GoodName: goodInfo.GoodName,
  948. SpecificationName: goodInfo.SpecificationName,
  949. WarehousingUnit: goodInfo.PackingUnit,
  950. Count: total_count,
  951. BuyPrice: goodInfo.BuyPrice,
  952. PackingPrice: goodInfo.PackingPrice,
  953. NewPrice: 0,
  954. Manufacturer: manufacturer.ManufacturerName,
  955. Dealer: "",
  956. Remark: "",
  957. GoodId: good_id,
  958. UserOrgId: orgId,
  959. Ctime: time.Now().Unix(),
  960. Mtime: 0,
  961. Status: 1,
  962. WarehousingOrder: warehouseInfo.WarehousingOrder,
  963. LicenseNumber: warehouseInfo.LicenseNumber,
  964. StartTime: time.Now().Unix(),
  965. Creater: creater,
  966. Checker: 0,
  967. CheckerStatus: 0,
  968. CheckerTime: 0,
  969. Total: 0,
  970. Number: warehouseInfo.Number,
  971. WarehousingInfoId: id,
  972. ExpireDate: warehouseInfo.ExpiryDate,
  973. ProductDate: warehouseInfo.ProductDate,
  974. GoodOriginPlace: "",
  975. Type: 10,
  976. InventoryType: is_type,
  977. LastStockCount: last_stock_count,
  978. StockCount: stock_count,
  979. StorehouseId: storehouse_id,
  980. RecordDate: recordDate.Unix(),
  981. }
  982. service.CreateInentory(inventory)
  983. stockFlow := models.VmStockFlow{
  984. WarehousingId: 0,
  985. GoodId: good_id,
  986. Number: warehouseInfo.Number,
  987. LicenseNumber: "",
  988. Count: total_count,
  989. UserOrgId: orgId,
  990. PatientId: 0,
  991. SystemTime: recordDate.Unix(),
  992. ConsumableType: 11,
  993. IsSys: 0,
  994. WarehousingOrder: warehouseInfo.WarehousingOrder,
  995. WarehouseOutId: 0,
  996. WarehouseOutOrderNumber: "",
  997. IsEdit: 0,
  998. CancelStockId: 0,
  999. CancelOrderNumber: "",
  1000. Manufacturer: warehouseInfo.Manufacturer,
  1001. Dealer: 0,
  1002. Creator: creater,
  1003. UpdateCreator: 0,
  1004. Status: 1,
  1005. Ctime: time.Now().Unix(),
  1006. Mtime: 0,
  1007. Price: warehouseInfo.Price,
  1008. WarehousingDetailId: 0,
  1009. WarehouseOutDetailId: 0,
  1010. CancelOutDetailId: 0,
  1011. ProductDate: warehouseInfo.ProductDate,
  1012. ExpireDate: warehouseInfo.ExpiryDate,
  1013. ReturnCount: 0,
  1014. StorehouseId: storehouse_id,
  1015. OverCount: flush_count,
  1016. }
  1017. service.CreateStockFlowOne(stockFlow)
  1018. service.ReduceSumInCount(good_id, total_count, storehouse_id, orgId)
  1019. }
  1020. //查询已审核单据的剩余库存
  1021. goodList, _ := service.GetGoodSumCountByStoreId(storehouse_id, good_id, orgId)
  1022. var sum_count int64
  1023. var sum_in_count int64
  1024. for _, item := range goodList {
  1025. sum_count += item.StockCount
  1026. sum_in_count += item.WarehousingCount
  1027. }
  1028. service.UpdateGoodByGoodId(good_id, sum_count, sum_in_count, orgId)
  1029. service.UpdateSumGood(orgId, storehouse_id, good_id, flush_count)
  1030. this.ServeSuccessJSON(map[string]interface{}{
  1031. "msg": "msg",
  1032. })
  1033. }
  1034. func (this *PharmacyController) GetDrugInventoryList() {
  1035. keywords := this.GetString("keywords")
  1036. orgId := this.GetAdminUserInfo().CurrentOrgId
  1037. drugList, _ := service.GetDrugNewInventoryList(orgId, keywords)
  1038. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1039. this.ServeSuccessJSON(map[string]interface{}{
  1040. "drugList": drugList,
  1041. "manufacturerList": manufacturerList,
  1042. })
  1043. }
  1044. func (this *PharmacyController) GetDrugInventoryByDrugId() {
  1045. orgId := this.GetAdminUserInfo().CurrentOrgId
  1046. id, _ := this.GetInt64("id")
  1047. infoList, _ := service.GetDrugInvetoryByDrugId(orgId, id)
  1048. this.ServeSuccessJSON(map[string]interface{}{
  1049. "infoList": infoList,
  1050. })
  1051. }
  1052. func (this *PharmacyController) UpdateDrugInventoryWarehouseInfo() {
  1053. id, _ := this.GetInt64("id")
  1054. stock_max_number, _ := this.GetInt64("stock_max_number")
  1055. stock_min_number, _ := this.GetInt64("stock_min_number")
  1056. last_stock_max_number, _ := this.GetInt64("last_stock_max_number")
  1057. last_stock_min_number, _ := this.GetInt64("last_stock_min_number")
  1058. drug_id, _ := this.GetInt64("drug_id")
  1059. storehouse_id, _ := this.GetInt64("storehouse_id")
  1060. is_type, _ := this.GetInt64("is_type")
  1061. specification_name := this.GetString("specification_name")
  1062. orgId := this.GetAdminUserInfo().CurrentOrgId
  1063. base, _ := service.GetBasedrugByIdOne(drug_id, orgId)
  1064. var ord_total int64
  1065. var new_total int64
  1066. var consumable_count int64
  1067. ord_total = stock_max_number*base.MinNumber + stock_min_number
  1068. new_total = last_stock_max_number*base.MinNumber + last_stock_min_number
  1069. //更新入库单
  1070. service.UpdateNewDrugWarehouseInfoById(id, last_stock_max_number, last_stock_min_number)
  1071. //查询默认仓库
  1072. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1073. //查询默认仓库剩余多少库存
  1074. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, drug_id)
  1075. var sum_count int64
  1076. for _, it := range list {
  1077. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  1078. if it.MaxUnit == baseDrug.MaxUnit {
  1079. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  1080. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  1081. }
  1082. sum_count += it.StockMaxNumber + it.StockMinNumber
  1083. }
  1084. //更新剩余库存
  1085. service.UpdateMedicalSumCountOne(drug_id, sum_count, orgId)
  1086. //更新剩余库存
  1087. service.UpdateDrugStockCount(drug_id, orgId, houseConfig.DrugStorehouseOut, sum_count)
  1088. drugWarehouseInfoOne, _ := service.GetDrugWarehouseInfoOne(id)
  1089. manufacturer, _ := service.GetManufactureById(drugWarehouseInfoOne.Manufacturer)
  1090. recordDateStr := time.Now().Format("2006-01-02")
  1091. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1092. //盘亏
  1093. if ord_total > new_total {
  1094. consumable_count = ord_total - new_total
  1095. inventory := models.XtDrugInventory{
  1096. DrugName: base.DrugName,
  1097. SpecificationName: specification_name,
  1098. WarehousingUnit: drugWarehouseInfoOne.MaxUnit,
  1099. Count: consumable_count,
  1100. LastPrice: drugWarehouseInfoOne.Price,
  1101. RetailPrice: drugWarehouseInfoOne.RetailPrice,
  1102. NewPrice: 0,
  1103. Manufacturer: manufacturer.ManufacturerName,
  1104. Dealer: "",
  1105. Remark: "",
  1106. DrugId: drug_id,
  1107. UserOrgId: orgId,
  1108. Ctime: time.Now().Unix(),
  1109. Mtime: 0,
  1110. Status: 1,
  1111. WarehousingOrder: drugWarehouseInfoOne.WarehousingOrder,
  1112. LicenseNumber: "",
  1113. StartTime: recordDate.Unix(),
  1114. Creater: this.GetAdminUserInfo().AdminUser.Id,
  1115. Checker: 0,
  1116. CheckerStatus: 0,
  1117. CheckerTime: 0,
  1118. ExpiryDate: drugWarehouseInfoOne.ExpiryDate,
  1119. ProductDate: drugWarehouseInfoOne.ProductDate,
  1120. Number: "",
  1121. BatchNumber: drugWarehouseInfoOne.BatchNumber,
  1122. Total: "",
  1123. DrugOriginPlace: "",
  1124. WarehouseInfoId: id,
  1125. ProofCount: 0,
  1126. StockMaxNumber: stock_max_number,
  1127. StockMinNumber: stock_min_number,
  1128. MinCount: 0,
  1129. MinUnit: drugWarehouseInfoOne.MinUnit,
  1130. LastStockMaxNumber: last_stock_max_number,
  1131. LastStockMinNumber: last_stock_min_number,
  1132. InventoryType: 11,
  1133. Type: is_type,
  1134. StorehouseId: storehouse_id,
  1135. RecordDate: recordDate.Unix(),
  1136. }
  1137. service.CreateDrugInventory(inventory)
  1138. flow := models.DrugFlow{
  1139. WarehousingId: id,
  1140. DrugId: drug_id,
  1141. Number: "",
  1142. BatchNumber: drugWarehouseInfoOne.BatchNumber,
  1143. Count: consumable_count,
  1144. UserOrgId: orgId,
  1145. PatientId: 0,
  1146. SystemTime: recordDate.Unix(),
  1147. ConsumableType: 11,
  1148. IsSys: 1,
  1149. WarehousingOrder: drugWarehouseInfoOne.WarehousingOrder,
  1150. WarehouseOutId: 0,
  1151. WarehouseOutOrderNumber: "",
  1152. IsEdit: 0,
  1153. CancelStockId: 0,
  1154. CancelOrderNumber: "",
  1155. Manufacturer: manufacturer.ID,
  1156. Dealer: 0,
  1157. Creator: this.GetAdminUserInfo().AdminUser.Id,
  1158. UpdateCreator: 0,
  1159. Status: 1,
  1160. Ctime: time.Now().Unix(),
  1161. Mtime: 0,
  1162. Price: drugWarehouseInfoOne.Price,
  1163. WarehousingDetailId: id,
  1164. WarehouseOutDetailId: 0,
  1165. CancelOutDetailId: 0,
  1166. ExpireDate: drugWarehouseInfoOne.ExpiryDate,
  1167. ProductDate: 0,
  1168. MaxUnit: drugWarehouseInfoOne.MaxUnit,
  1169. MinUnit: drugWarehouseInfoOne.MinUnit,
  1170. StorehouseId: storehouse_id,
  1171. OverCount: sum_count,
  1172. }
  1173. service.CreateDrugFlowOne(flow)
  1174. //添加出库数据
  1175. service.AddDrugWarehouseOut(drug_id, consumable_count, storehouse_id, orgId)
  1176. }
  1177. //盘盈
  1178. if ord_total < new_total {
  1179. consumable_count = new_total - ord_total
  1180. inventory := models.XtDrugInventory{
  1181. DrugName: base.DrugName,
  1182. SpecificationName: specification_name,
  1183. WarehousingUnit: drugWarehouseInfoOne.MaxUnit,
  1184. Count: consumable_count,
  1185. LastPrice: drugWarehouseInfoOne.Price,
  1186. RetailPrice: drugWarehouseInfoOne.RetailPrice,
  1187. NewPrice: 0,
  1188. Manufacturer: manufacturer.ManufacturerName,
  1189. Dealer: "",
  1190. Remark: "",
  1191. DrugId: drug_id,
  1192. UserOrgId: orgId,
  1193. Ctime: time.Now().Unix(),
  1194. Mtime: 0,
  1195. Status: 1,
  1196. WarehousingOrder: drugWarehouseInfoOne.WarehousingOrder,
  1197. LicenseNumber: "",
  1198. StartTime: recordDate.Unix(),
  1199. Creater: this.GetAdminUserInfo().AdminUser.Id,
  1200. Checker: 0,
  1201. CheckerStatus: 0,
  1202. CheckerTime: 0,
  1203. ExpiryDate: drugWarehouseInfoOne.ExpiryDate,
  1204. ProductDate: drugWarehouseInfoOne.ProductDate,
  1205. Number: "",
  1206. BatchNumber: drugWarehouseInfoOne.BatchNumber,
  1207. Total: "",
  1208. DrugOriginPlace: "",
  1209. WarehouseInfoId: id,
  1210. ProofCount: 0,
  1211. StockMaxNumber: stock_max_number,
  1212. StockMinNumber: stock_min_number,
  1213. MinCount: 0,
  1214. MinUnit: drugWarehouseInfoOne.MinUnit,
  1215. LastStockMaxNumber: last_stock_max_number,
  1216. LastStockMinNumber: last_stock_min_number,
  1217. InventoryType: 10,
  1218. Type: is_type,
  1219. StorehouseId: storehouse_id,
  1220. RecordDate: recordDate.Unix(),
  1221. }
  1222. service.CreateDrugInventory(inventory)
  1223. flow := models.DrugFlow{
  1224. WarehousingId: id,
  1225. DrugId: drug_id,
  1226. Number: "",
  1227. BatchNumber: drugWarehouseInfoOne.BatchNumber,
  1228. Count: consumable_count,
  1229. UserOrgId: orgId,
  1230. PatientId: 0,
  1231. SystemTime: recordDate.Unix(),
  1232. ConsumableType: 10,
  1233. IsSys: 1,
  1234. WarehousingOrder: drugWarehouseInfoOne.WarehousingOrder,
  1235. WarehouseOutId: 0,
  1236. WarehouseOutOrderNumber: "",
  1237. IsEdit: 0,
  1238. CancelStockId: 0,
  1239. CancelOrderNumber: "",
  1240. Manufacturer: manufacturer.ID,
  1241. Dealer: 0,
  1242. Creator: this.GetAdminUserInfo().AdminUser.Id,
  1243. UpdateCreator: 0,
  1244. Status: 1,
  1245. Ctime: time.Now().Unix(),
  1246. Mtime: 0,
  1247. Price: drugWarehouseInfoOne.Price,
  1248. WarehousingDetailId: id,
  1249. WarehouseOutDetailId: 0,
  1250. CancelOutDetailId: 0,
  1251. ExpireDate: drugWarehouseInfoOne.ExpiryDate,
  1252. ProductDate: 0,
  1253. MaxUnit: drugWarehouseInfoOne.MaxUnit,
  1254. MinUnit: drugWarehouseInfoOne.MinUnit,
  1255. StorehouseId: storehouse_id,
  1256. OverCount: sum_count,
  1257. }
  1258. service.CreateDrugFlowOne(flow)
  1259. //减少出库数据
  1260. service.ReduceDrugWarehouseOut(drug_id, consumable_count, storehouse_id, orgId)
  1261. }
  1262. this.ServeSuccessJSON(map[string]interface{}{
  1263. "msg": "msg",
  1264. })
  1265. }
  1266. func (this *PharmacyController) ChangeDrugCode() {
  1267. id, _ := this.GetInt64("id")
  1268. orgId := this.GetAdminUserInfo().CurrentOrgId
  1269. data_source, _ := this.GetInt64("data_source")
  1270. drug_code := this.GetString("drug_code")
  1271. str := strings.Replace(drug_code, " ", "", -1)
  1272. // 去除换行符
  1273. str = strings.Replace(str, "\n", "", -1)
  1274. if data_source == 1 {
  1275. service.ChangeHisDrugCode(id, str, orgId)
  1276. }
  1277. if data_source == 2 {
  1278. service.ChangeAdivceDrugCode(id, str, orgId)
  1279. }
  1280. this.ServeSuccessJSON(map[string]interface{}{
  1281. "msg": "msg",
  1282. })
  1283. }