self_drug_api_congtroller.go 26KB

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