self_drug_api_congtroller.go 27KB

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