pharmacy_controller.go 44KB

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