pharmacy_controller.go 43KB

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