self_drug_api_congtroller.go 29KB

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