pharmacy_controller.go 44KB

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