self_drug_api_congtroller.go 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/astaxie/beego"
  9. "github.com/jinzhu/gorm"
  10. "strconv"
  11. "strings"
  12. "time"
  13. )
  14. type SelfDrugApiController struct {
  15. BaseAuthAPIController
  16. }
  17. func SelfDrugRouters() {
  18. beego.Router("/api/drug/getcurrentpatient", &SelfDrugApiController{}, "Get:GetCurrentPatient")
  19. beego.Router("/api/drug/getalldrugname", &SelfDrugApiController{}, "Get:GetAllDrugName")
  20. beego.Router("/api/drug/savedrugname", &SelfDrugApiController{}, "Get:SaveDrugName")
  21. beego.Router("/api/drug/getdrugnamelist", &SelfDrugApiController{}, "Get:GetDrugNameList")
  22. beego.Router("/api/drug/getrullename", &SelfDrugApiController{}, "Get:GetRulleName")
  23. beego.Router("/api/drug/getunitbybaseid", &SelfDrugApiController{}, "Get:GetUnitByBaseId")
  24. beego.Router("/api/drug/saverullename", &SelfDrugApiController{}, "Get:SaveRulleName")
  25. beego.Router("/api/drug/editrullername", &SelfDrugApiController{}, "Get:EditRullerName")
  26. beego.Router("/api/drug/updatedrullername", &SelfDrugApiController{}, "Get:UpdatedRullerName")
  27. beego.Router("/api/drug/getalldrugnamelist", &SelfDrugApiController{}, "Get:GetAllDrugNameList")
  28. beego.Router("/api/drug/getrulllistbydrugname", &SelfDrugApiController{}, "Get:GetRullerListByDrugName")
  29. beego.Router("/api/drug/saveselfmedicines", &SelfDrugApiController{}, "Post:SaveSelfMedicines")
  30. beego.Router("/api/drug/getcurrentorgallstaff", &SelfDrugApiController{}, "Get:GetCurrentOrgAllStaff")
  31. beego.Router("/api/drug/savestock", &SelfDrugApiController{}, "Post:SaveStock")
  32. beego.Router("/api/drug/saveoutstock", &SelfDrugApiController{}, "Post:SaveOutStock")
  33. beego.Router("/api/drug/deletedrugbyid", &SelfDrugApiController{}, "Get:DeleteDrugById")
  34. beego.Router("/api/drug/saveradio", &SelfDrugApiController{}, "Get:SaveRadio")
  35. beego.Router("/api/drug/deletedrugstand", &SelfDrugApiController{}, "Get:DeleteDrugStand")
  36. beego.Router("/api/drug/getstocklist", &SelfDrugApiController{}, "Get:GetStockList")
  37. beego.Router("/api/drug/deletedrugname", &SelfDrugApiController{}, "Get:DeleteDrugName")
  38. beego.Router("/api/drug/getdrugdetail", &SelfDrugApiController{}, "Get:GetDrugDetail")
  39. beego.Router("/api/drug/getallpatientstocklist", &SelfDrugApiController{}, "Get:GetAllPatientStockList")
  40. beego.Router("/api/drug/getdrugdatabypatientid", &SelfDrugApiController{}, "Get:GetDrugDataByPatientId")
  41. beego.Router("/api/drug/getselfmedicallist", &SelfDrugApiController{}, "Get:GetSelfMedicalList")
  42. beego.Router("/api/drug/getdrugdescbydrugname", &SelfDrugApiController{}, "Get:GetDrugDescByDrugName")
  43. beego.Router("/api/drug/getdrugset", &SelfDrugApiController{}, "Get:GetDrugSet")
  44. }
  45. func (this *SelfDrugApiController) GetCurrentPatient() {
  46. adminUserInfo := this.GetAdminUserInfo()
  47. orgId := adminUserInfo.CurrentOrgId
  48. patient, err := service.GetCurrentPatient(orgId)
  49. if err != nil {
  50. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  51. return
  52. }
  53. this.ServeSuccessJSON(map[string]interface{}{
  54. "patient": patient,
  55. })
  56. }
  57. func (this *SelfDrugApiController) GetAllDrugName() {
  58. adminUserInfo := this.GetAdminUserInfo()
  59. orgId := adminUserInfo.CurrentOrgId
  60. //查询药品库是否开启
  61. //configStock, _ := service.GetDrugStockConfig(orgId)
  62. //if configStock.IsOpen == 1 {
  63. //
  64. //}
  65. drugName, err := service.GetAllDrugName(orgId)
  66. if err != nil {
  67. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查寻成功")
  68. return
  69. }
  70. this.ServeSuccessJSON(map[string]interface{}{
  71. "drugName": drugName,
  72. })
  73. }
  74. func (this *SelfDrugApiController) SaveDrugName() {
  75. adminUserInfo := this.GetAdminUserInfo()
  76. orgId := adminUserInfo.CurrentOrgId
  77. drug_name := this.GetString("drug_name")
  78. //fmt.Println("drug_name", drug_name)
  79. drugName := models.XtDrugName{
  80. UserOrgId: orgId,
  81. DrugName: drug_name,
  82. Status: 1,
  83. CreatedTime: time.Now().Unix(),
  84. }
  85. _, errcode := service.GetDrugName(drug_name, orgId)
  86. if errcode == gorm.ErrRecordNotFound {
  87. err := service.SaveDrugName(&drugName)
  88. if err != nil {
  89. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  90. return
  91. }
  92. this.ServeSuccessJSON(map[string]interface{}{
  93. "drugName": drugName,
  94. })
  95. } else {
  96. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  97. return
  98. }
  99. }
  100. func (this *SelfDrugApiController) GetDrugNameList() {
  101. adminUserInfo := this.GetAdminUserInfo()
  102. orgId := adminUserInfo.CurrentOrgId
  103. list, err := service.GetDrugNameList(orgId)
  104. if err != nil {
  105. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  106. return
  107. }
  108. this.ServeSuccessJSON(map[string]interface{}{
  109. "list": list,
  110. })
  111. }
  112. func (this *SelfDrugApiController) GetRulleName() {
  113. adminUserInfo := this.GetAdminUserInfo()
  114. orgId := adminUserInfo.CurrentOrgId
  115. name := this.GetString("name")
  116. rulleName, err := service.GetRulleName(orgId, name)
  117. rullerList, err := service.GetRulleList(orgId, name)
  118. if err != nil {
  119. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  120. return
  121. }
  122. this.ServeSuccessJSON(map[string]interface{}{
  123. "rulleName": rulleName,
  124. "rullerList": rullerList,
  125. })
  126. }
  127. func (this *SelfDrugApiController) GetUnitByBaseId() {
  128. id, _ := this.GetInt64("id")
  129. baseList, err := service.GetUnitByBaseId(id)
  130. if err != nil {
  131. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  132. return
  133. }
  134. this.ServeSuccessJSON(map[string]interface{}{
  135. "baseList": baseList,
  136. })
  137. }
  138. func (this *SelfDrugApiController) SaveRulleName() {
  139. drug_name := this.GetString("drug_name")
  140. drug_spec := this.GetString("drug_spec")
  141. drug_stock_limit := this.GetString("drug_stock_limit")
  142. drug_name_id, _ := this.GetInt64("drug_name_id")
  143. price, _ := this.GetInt64("price")
  144. prices := strconv.FormatInt(price, 10)
  145. durg_price, _ := strconv.ParseFloat(prices, 64)
  146. unit := this.GetString("unit")
  147. adminUserInfo := this.GetAdminUserInfo()
  148. orgId := adminUserInfo.CurrentOrgId
  149. fmt.Println(drug_name, drug_stock_limit, unit, price, drug_spec, orgId)
  150. drugSpecName := models.XtStandName{
  151. DrugName: drug_name,
  152. DrugSpec: drug_spec,
  153. DrugStockLimit: drug_stock_limit,
  154. DrugNameId: drug_name_id,
  155. Price: durg_price,
  156. MinUnit: unit,
  157. UserOrgId: orgId,
  158. Status: 1,
  159. CreatedTime: time.Now().Unix(),
  160. }
  161. err := service.SaveRulleName(&drugSpecName)
  162. if err != nil {
  163. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  164. return
  165. }
  166. this.ServeSuccessJSON(map[string]interface{}{
  167. "RullerName": drugSpecName,
  168. })
  169. }
  170. func (this *SelfDrugApiController) EditRullerName() {
  171. id, _ := this.GetInt64("id")
  172. rullerDetail, err := service.GetRullerNameDetail(id)
  173. if err != nil {
  174. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  175. return
  176. }
  177. this.ServeSuccessJSON(map[string]interface{}{
  178. "rullerDetail": rullerDetail,
  179. })
  180. }
  181. func (this *SelfDrugApiController) UpdatedRullerName() {
  182. id, _ := this.GetInt64("id")
  183. drug_name := this.GetString("drug_name")
  184. drug_stock_limit := this.GetString("drug_stock_limit")
  185. price, _ := this.GetInt64("price")
  186. prices := strconv.FormatInt(price, 10)
  187. durg_price, _ := strconv.ParseFloat(prices, 64)
  188. drug_spec := this.GetString("drug_spec")
  189. unit := this.GetString("unit")
  190. drug_name_id, _ := this.GetInt64("drug_name_id")
  191. RullerName := models.XtStandName{
  192. DrugName: drug_name,
  193. DrugStockLimit: drug_stock_limit,
  194. Price: durg_price,
  195. DrugSpec: drug_spec,
  196. MinUnit: unit,
  197. DrugNameId: drug_name_id,
  198. }
  199. err := service.UpdatedRullerName(id, &RullerName)
  200. if err != nil {
  201. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  202. return
  203. }
  204. this.ServeSuccessJSON(map[string]interface{}{
  205. "RullerName": RullerName,
  206. })
  207. }
  208. func (this *SelfDrugApiController) GetAllDrugNameList() {
  209. adminUserInfo := this.GetAdminUserInfo()
  210. orgId := adminUserInfo.CurrentOrgId
  211. rullerName, err := service.GetAllDrugNameList(orgId)
  212. if err != nil {
  213. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  214. return
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "rullerName": rullerName,
  218. })
  219. }
  220. func (this *SelfDrugApiController) GetRullerListByDrugName() {
  221. drug_name := this.GetString("drug_name")
  222. fmt.Println(drug_name)
  223. adminUserInfo := this.GetAdminUserInfo()
  224. orgId := adminUserInfo.CurrentOrgId
  225. fmt.Println("orgid", orgId)
  226. drugName, err := service.GetRullerListByDrugName(drug_name, orgId)
  227. if err != nil {
  228. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  229. return
  230. }
  231. this.ServeSuccessJSON(map[string]interface{}{
  232. "drugName": drugName,
  233. })
  234. }
  235. func (this *SelfDrugApiController) SaveSelfMedicines() {
  236. dataBody := make(map[string]interface{}, 0)
  237. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  238. fmt.Println(err)
  239. patient_id := int64(dataBody["patient_id"].(float64))
  240. medicineData, _ := dataBody["medicineData"].([]interface{})
  241. adminUserInfo := this.GetAdminUserInfo()
  242. orgId := adminUserInfo.CurrentOrgId
  243. for _, item := range medicineData {
  244. items := item.(map[string]interface{})
  245. drug_name := items["drug_name"].(string)
  246. id := int64(items["id"].(float64))
  247. drug_spec := items["drug_spec"].(string)
  248. min_unit := items["min_unit"].(string)
  249. medical := models.XtSelfMedical{
  250. DrugName: drug_name,
  251. DrugNameId: id,
  252. DrugSpec: drug_spec,
  253. CreatedTime: time.Now().Unix(),
  254. Status: 1,
  255. UserOrgId: orgId,
  256. PatientId: patient_id,
  257. MinUnit: min_unit,
  258. }
  259. //查询同个病人同个药品同个规格是否已存在
  260. _, errcode := service.GetSelfMedicalByDrugName(drug_name, drug_spec, patient_id)
  261. if errcode == gorm.ErrRecordNotFound {
  262. err := service.CreateSelfMedical(&medical)
  263. fmt.Println(err)
  264. } else if errcode == nil {
  265. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  266. return
  267. }
  268. }
  269. returnData := make(map[string]interface{}, 0)
  270. returnData["msg"] = "ok"
  271. this.ServeSuccessJSON(returnData)
  272. return
  273. }
  274. func (this *SelfDrugApiController) GetCurrentOrgAllStaff() {
  275. adminUserInfo := this.GetAdminUserInfo()
  276. orgid := adminUserInfo.CurrentOrgId
  277. //fmt.Println(orgid)
  278. appId := adminUserInfo.CurrentAppId
  279. staff, err := service.GetCurrentOrgAllStaff(orgid, appId)
  280. if err != nil {
  281. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  282. return
  283. }
  284. this.ServeSuccessJSON(map[string]interface{}{
  285. "staff": staff,
  286. })
  287. }
  288. func (this *SelfDrugApiController) SaveStock() {
  289. timeLayout := "2006-01-02"
  290. loc, _ := time.LoadLocation("Local")
  291. start_time := this.GetString("start_time")
  292. fmt.Println("start_time", start_time)
  293. admin_user_id, _ := this.GetInt64("admin_user_id")
  294. fmt.Println("admin_user_id", admin_user_id)
  295. patient_id, _ := this.GetInt64("patient_id")
  296. dataBody := make(map[string]interface{}, 0)
  297. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  298. fmt.Println(err)
  299. stocks, _ := dataBody["stocks"].([]interface{})
  300. adminUserInfo := this.GetAdminUserInfo()
  301. orgId := adminUserInfo.CurrentOrgId
  302. for _, item := range stocks {
  303. items := item.(map[string]interface{})
  304. drug_name := items["drug_name"].(string)
  305. fmt.Println("drug_name", drug_name)
  306. drug_name_id := int64(items["drug_name_id"].(float64))
  307. fmt.Println("parient_id", drug_name_id)
  308. drug_spec := items["drug_spec"].(string)
  309. store_number := items["store_number"].(string)
  310. fmt.Println("store_number", store_number)
  311. storeNumber, _ := strconv.ParseInt(store_number, 10, 64)
  312. remarks := items["remarks"].(string)
  313. min_unit := items["min_unit"].(string)
  314. medic_id := int64(items["id"].(float64))
  315. timeStr := time.Now().Format("2006-01-02")
  316. timeArr := strings.Split(timeStr, "-")
  317. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  318. total = total + 1
  319. warehousing_in_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  320. number, _ := strconv.ParseInt(warehousing_in_order, 10, 64)
  321. number = number + total
  322. warehousing_in_order = "RKD" + strconv.FormatInt(number, 10)
  323. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  324. stock := models.XtSelfStock{
  325. DrugName: drug_name,
  326. DrugNameId: drug_name_id,
  327. DrugSpec: drug_spec,
  328. StoreNumber: storeNumber,
  329. Remarks: remarks,
  330. AdminUserId: admin_user_id,
  331. StorckTime: theTime.Unix(),
  332. CreatedTime: time.Now().Unix(),
  333. Status: 1,
  334. UserOrgId: orgId,
  335. StockInNumber: warehousing_in_order,
  336. PatientId: patient_id,
  337. MinUnit: min_unit,
  338. StorageMode: 1,
  339. MedicId: medic_id,
  340. }
  341. err := service.CreateStock(&stock)
  342. fmt.Println("err", err)
  343. }
  344. returnData := make(map[string]interface{}, 0)
  345. returnData["msg"] = "ok"
  346. this.ServeSuccessJSON(returnData)
  347. return
  348. }
  349. func (this *SelfDrugApiController) SaveOutStock() {
  350. timeLayout := "2006-01-02"
  351. loc, _ := time.LoadLocation("Local")
  352. start_time := this.GetString("start_time")
  353. admin_user_id, _ := this.GetInt64("admin_user_id")
  354. patient_id, _ := this.GetInt64("patient_id")
  355. dataBody := make(map[string]interface{}, 0)
  356. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  357. fmt.Println(err)
  358. outStocks, _ := dataBody["outStocks"].([]interface{})
  359. adminUserInfo := this.GetAdminUserInfo()
  360. orgId := adminUserInfo.CurrentOrgId
  361. for _, item := range outStocks {
  362. items := item.(map[string]interface{})
  363. drug_name := items["drug_name"].(string)
  364. drug_name_id := int64(items["drug_name_id"].(float64))
  365. drug_spec := items["drug_spec"].(string)
  366. outstore_number := items["outstore_number"].(string)
  367. outStoreNumber, _ := strconv.ParseInt(outstore_number, 10, 64)
  368. remarks := items["remarks"].(string)
  369. medic_id := int64(items["id"].(float64))
  370. timeStr := time.Now().Format("2006-01-02")
  371. timeArr := strings.Split(timeStr, "-")
  372. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  373. total = total + 1
  374. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  375. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  376. number = number + total
  377. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  378. fmt.Println(remarks)
  379. fmt.Println(items)
  380. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  381. stock := models.XtSelfOutStock{
  382. DrugName: drug_name,
  383. DrugNameId: drug_name_id,
  384. DrugSpec: drug_spec,
  385. OutstoreNumber: outStoreNumber,
  386. Remarks: remarks,
  387. AdminUserId: admin_user_id,
  388. StorckTime: theTime.Unix(),
  389. CreatedTime: time.Now().Unix(),
  390. Status: 1,
  391. UserOrgId: orgId,
  392. StockOutNumber: warehousing_out_order,
  393. PatientId: patient_id,
  394. ExitMode: 1,
  395. MedicId: medic_id,
  396. }
  397. err := service.CreateOutStock(&stock)
  398. fmt.Println("err", err)
  399. }
  400. returnData := make(map[string]interface{}, 0)
  401. returnData["msg"] = "ok"
  402. this.ServeSuccessJSON(returnData)
  403. return
  404. }
  405. func (this *SelfDrugApiController) DeleteDrugById() {
  406. id, _ := this.GetInt64("id")
  407. drug_name := this.GetString("drug_name")
  408. fmt.Println("drug_name", drug_name)
  409. adminUserInfo := this.GetAdminUserInfo()
  410. orgId := adminUserInfo.CurrentOrgId
  411. _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
  412. fmt.Println("errcode", errcode)
  413. if errcode == gorm.ErrRecordNotFound {
  414. service.DeleteDrugName(id)
  415. returnData := make(map[string]interface{}, 0)
  416. returnData["msg"] = "ok"
  417. this.ServeSuccessJSON(returnData)
  418. } else if errcode == nil {
  419. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  420. return
  421. }
  422. }
  423. func (this *SelfDrugApiController) SaveRadio() {
  424. radio, _ := this.GetInt64("radio")
  425. adminUserInfo := this.GetAdminUserInfo()
  426. orgId := adminUserInfo.CurrentOrgId
  427. drugSet := models.XtDrugSet{
  428. DrugStart: radio,
  429. UserOrgId: orgId,
  430. Status: 1,
  431. CreatedTime: time.Now().Unix(),
  432. }
  433. _, errcode := service.GetDrugSetByUserOrgId(orgId)
  434. if errcode == gorm.ErrRecordNotFound {
  435. err := service.SaveRadio(&drugSet)
  436. if err != nil {
  437. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  438. return
  439. }
  440. this.ServeSuccessJSON(map[string]interface{}{
  441. "drugSet": drugSet,
  442. })
  443. } else if errcode == nil {
  444. err := service.UpdateDrugSet(&drugSet, orgId)
  445. if err != nil {
  446. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  447. return
  448. }
  449. this.ServeSuccessJSON(map[string]interface{}{
  450. "drugSet": drugSet,
  451. })
  452. }
  453. }
  454. func (this *SelfDrugApiController) DeleteDrugStand() {
  455. id, _ := this.GetInt64("id")
  456. err := service.DeleteDrugStand(id)
  457. fmt.Println(err)
  458. returnData := make(map[string]interface{}, 0)
  459. returnData["msg"] = "ok"
  460. this.ServeSuccessJSON(returnData)
  461. }
  462. func (this *SelfDrugApiController) GetStockList() {
  463. patientid, _ := this.GetInt64("id")
  464. start_time := this.GetString("start_time")
  465. fmt.Println("开始时间", start_time)
  466. timeLayout := "2006-01-02"
  467. loc, _ := time.LoadLocation("Local")
  468. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  469. startimeUnix := theTime.Unix()
  470. keyword := this.GetString("keyword")
  471. fmt.Println("keyword", keyword)
  472. adminUserInfo := this.GetAdminUserInfo()
  473. orgId := adminUserInfo.CurrentOrgId
  474. //获取
  475. medicalList, _ := service.GetMedicalList(patientid, orgId, keyword)
  476. //统计总数量
  477. stocklist, err := service.GetStockList(patientid, startimeUnix, keyword, orgId)
  478. //统计出库数量
  479. outStocklist, err := service.GetOutStockList(patientid, startimeUnix, keyword, orgId)
  480. if err != nil {
  481. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  482. return
  483. }
  484. this.ServeSuccessJSON(map[string]interface{}{
  485. "medicalList": medicalList,
  486. "stocklist": stocklist,
  487. "outStocklist": outStocklist,
  488. })
  489. }
  490. func (this *SelfDrugApiController) DeleteDrugName() {
  491. drug_name := this.GetString("drugname")
  492. patient_id, _ := this.GetInt64("patientid")
  493. //查询该药品是否出库
  494. stocklist, _ := service.GetStockOutDetail(drug_name, patient_id)
  495. if len(stocklist) == 0 {
  496. //删除该药品
  497. service.DeleteDrugStockNumber(drug_name, patient_id)
  498. returnData := make(map[string]interface{}, 0)
  499. returnData["msg"] = "ok"
  500. this.ServeSuccessJSON(returnData)
  501. } else {
  502. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  503. return
  504. }
  505. }
  506. func (this *SelfDrugApiController) GetDrugDetail() {
  507. timeLayout := "2006-01-02"
  508. loc, _ := time.LoadLocation("Local")
  509. drug_name := this.GetString("drug_name")
  510. drug_spec := this.GetString("drug_spec")
  511. start_time := this.GetString("start_time")
  512. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  513. end_time := this.GetString("end_time")
  514. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  515. patient_id, _ := this.GetInt64("patient_id")
  516. adminUserInfo := this.GetAdminUserInfo()
  517. orgId := adminUserInfo.CurrentOrgId
  518. //查询入库明细
  519. stockDetail, err := service.GetStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
  520. //查询出库明细
  521. outStockDetail, err := service.GetOutStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
  522. if err != nil {
  523. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  524. return
  525. }
  526. this.ServeSuccessJSON(map[string]interface{}{
  527. "stockDetail": stockDetail,
  528. "outStockDetail": outStockDetail,
  529. })
  530. }
  531. func (this *SelfDrugApiController) GetAllPatientStockList() {
  532. timeLayout := "2006-01-02"
  533. loc, _ := time.LoadLocation("Local")
  534. drug_name := this.GetString("drug_name")
  535. drug_spec := this.GetString("drug_spec")
  536. start_time := this.GetString("start_time")
  537. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  538. startUnix := theTime.Unix()
  539. end_time := this.GetString("end_time")
  540. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  541. endTimeUnix := endTimes.Unix()
  542. keywords := this.GetString("search_input")
  543. adminUserInfo := this.GetAdminUserInfo()
  544. orgId := adminUserInfo.CurrentOrgId
  545. //入库
  546. stocklist, err := service.GetAllPatientStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
  547. //出库
  548. outStockList, err := service.GetAllPatientOutStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
  549. if err != nil {
  550. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  551. return
  552. }
  553. this.ServeSuccessJSON(map[string]interface{}{
  554. "stocklist": stocklist,
  555. "outStockList": outStockList,
  556. })
  557. }
  558. func (this *SelfDrugApiController) GetDrugDataByPatientId() {
  559. patient_id, _ := this.GetInt64("patient_id")
  560. fmt.Println("patient_id", patient_id)
  561. medicalList, err := service.GetDrugDataByPatientId(patient_id)
  562. if err != nil {
  563. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  564. return
  565. }
  566. this.ServeSuccessJSON(map[string]interface{}{
  567. "medicalList": medicalList,
  568. })
  569. }
  570. func (this *SelfDrugApiController) GetSelfMedicalList() {
  571. patient_id, _ := this.GetInt64("patient_id")
  572. adminUserInfo := this.GetAdminUserInfo()
  573. orgId := adminUserInfo.CurrentOrgId
  574. //查询该机构是否开启自备药
  575. medical, _ := service.GetSetSelfMedical(orgId)
  576. //查询该机构下的药品库
  577. drugName, _ := service.GetAllDrugName(orgId)
  578. //开启
  579. if medical.DrugStart == 1 {
  580. list, err := service.GetSelfMedicalList(patient_id)
  581. if err != nil {
  582. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  583. return
  584. }
  585. this.ServeSuccessJSON(map[string]interface{}{
  586. "medicalList": list,
  587. "drugName": drugName,
  588. })
  589. } else {
  590. this.ServeSuccessJSON(map[string]interface{}{
  591. "drugName": drugName,
  592. })
  593. }
  594. }
  595. func (this *SelfDrugApiController) GetDrugDescByDrugName() {
  596. drug_name := this.GetString("drug_name")
  597. patient_id, _ := this.GetInt64("patient_id")
  598. way, _ := this.GetInt64("way")
  599. adminUserInfo := this.GetAdminUserInfo()
  600. orgId := adminUserInfo.CurrentOrgId
  601. drug_id, _ := this.GetInt64("id")
  602. //从基础库查询
  603. if way == 1 {
  604. //查询基础库数据
  605. medcal, err := service.GetBaseMedcal(drug_name, orgId)
  606. //统计入库数量
  607. countInfo, err := service.GetTotalBaseMedicalCount(drug_id, orgId)
  608. //统计出库数量
  609. countout, err := service.GetTotalBaseMedicalCountOut(drug_id, orgId)
  610. if err != nil {
  611. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  612. return
  613. }
  614. this.ServeSuccessJSON(map[string]interface{}{
  615. "drugspec": medcal,
  616. "countInfo": countInfo,
  617. "countout": countout,
  618. })
  619. }
  620. //从自备药库查询
  621. if way == 2 {
  622. drugspec, err := service.GetDrugDescByDrugName(drug_name, patient_id, orgId)
  623. if err != nil {
  624. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  625. return
  626. }
  627. this.ServeSuccessJSON(map[string]interface{}{
  628. "drugspec": drugspec,
  629. })
  630. }
  631. }
  632. func (this *SelfDrugApiController) GetDrugSet() {
  633. adminUserInfo := this.GetAdminUserInfo()
  634. orgId := adminUserInfo.CurrentOrgId
  635. drugSet, err := service.GetDrugSet(orgId)
  636. if err != nil {
  637. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  638. return
  639. }
  640. this.ServeSuccessJSON(map[string]interface{}{
  641. "drugSet": drugSet,
  642. })
  643. }