self_drug_api_congtroller.go 21KB

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