self_drug_api_congtroller.go 28KB

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