self_drug_api_congtroller.go 27KB

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