self_drug_api_congtroller.go 51KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "reflect"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. type SelfDrugApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func SelfDrugRouters() {
  20. beego.Router("/api/drug/getcurrentpatient", &SelfDrugApiController{}, "Get:GetCurrentPatient")
  21. beego.Router("/api/drug/getalldrugname", &SelfDrugApiController{}, "Get:GetAllDrugName")
  22. beego.Router("/api/drug/savedrugname", &SelfDrugApiController{}, "Get:SaveDrugName")
  23. beego.Router("/api/drug/getdrugnamelist", &SelfDrugApiController{}, "Get:GetDrugNameList")
  24. beego.Router("/api/drug/getrullename", &SelfDrugApiController{}, "Get:GetRulleName")
  25. beego.Router("/api/drug/getunitbybaseid", &SelfDrugApiController{}, "Get:GetUnitByBaseId")
  26. beego.Router("/api/drug/saverullename", &SelfDrugApiController{}, "Get:SaveRulleName")
  27. beego.Router("/api/drug/editrullername", &SelfDrugApiController{}, "Get:EditRullerName")
  28. beego.Router("/api/drug/updatedrullername", &SelfDrugApiController{}, "Get:UpdatedRullerName")
  29. beego.Router("/api/drug/getalldrugnamelist", &SelfDrugApiController{}, "Get:GetAllDrugNameList")
  30. beego.Router("/api/drug/getrulllistbydrugname", &SelfDrugApiController{}, "Get:GetRullerListByDrugName")
  31. beego.Router("/api/drug/saveselfmedicines", &SelfDrugApiController{}, "Post:SaveSelfMedicines")
  32. beego.Router("/api/drug/getcurrentorgallstaff", &SelfDrugApiController{}, "Get:GetCurrentOrgAllStaff")
  33. beego.Router("/api/drug/savestock", &SelfDrugApiController{}, "Post:SaveStock")
  34. beego.Router("/api/drug/saveoutstock", &SelfDrugApiController{}, "Post:SaveOutStock")
  35. beego.Router("/api/drug/deletedrugbyid", &SelfDrugApiController{}, "Get:DeleteDrugById")
  36. beego.Router("/api/drug/saveradio", &SelfDrugApiController{}, "Get:SaveRadio")
  37. beego.Router("/api/drug/deletedrugstand", &SelfDrugApiController{}, "Get:DeleteDrugStand")
  38. beego.Router("/api/drug/getstocklist", &SelfDrugApiController{}, "Get:GetStockList")
  39. beego.Router("/api/drug/deletedrugname", &SelfDrugApiController{}, "Get:DeleteDrugName")
  40. beego.Router("/api/drug/getdrugdetail", &SelfDrugApiController{}, "Get:GetDrugDetail")
  41. beego.Router("/api/drug/getallpatientstocklist", &SelfDrugApiController{}, "Get:GetAllPatientStockList")
  42. beego.Router("/api/drug/getdrugdatabypatientid", &SelfDrugApiController{}, "Get:GetDrugDataByPatientId")
  43. beego.Router("/api/drug/getselfmedicallist", &SelfDrugApiController{}, "Get:GetSelfMedicalList")
  44. beego.Router("/api/drug/getdrugdescbydrugname", &SelfDrugApiController{}, "Get:GetDrugDescByDrugName")
  45. beego.Router("/api/drug/getdrugset", &SelfDrugApiController{}, "Get:GetDrugSet")
  46. beego.Router("/api/drug/getallmedicallist", &SelfDrugApiController{}, "Get:GetAllMedicalList")
  47. beego.Router("/api/drug/getstandname", &SelfDrugApiController{}, "Get:GetStandName")
  48. beego.Router("/api/drug/getrullerlist", &SelfDrugApiController{}, "Get:GetRullerList")
  49. beego.Router("/api/drug/deleteDrugNamebyid", &SelfDrugApiController{}, "Get:DeleteDrugNameById")
  50. beego.Router("/api/drug/getpatientdetail", &SelfDrugApiController{}, "Get:GetPatientDetail")
  51. //beego.Router("/api/drug/getpatientdetail",&SelfDrugApiController{},"Get:ToPatientDetail")
  52. beego.Router("/api/drug/getselfstockquery", &SelfDrugApiController{}, "Get:GetSelfStockQuery")
  53. beego.Router("/api/drug/postsearchdrugwarehouselist", &SelfDrugApiController{}, "Get:PostSearchDrugWarehouseList")
  54. beego.Router("/api/drug/savedrugpriceone", &SelfDrugApiController{}, "Post:SaveDrugPrice")
  55. beego.Router("/api/drug/drugpricelist", &SelfDrugApiController{}, "Get:GetDrugPriceList")
  56. beego.Router("/api/drug/savecheckdrugprice", &SelfDrugApiController{}, "Get:SaveCheckDrugPrice")
  57. beego.Router("/api/drug/savedrugdamageone", &SelfDrugApiController{}, "Post:SaveDrugDamage")
  58. beego.Router("/api/drug/getdrugdamagelist", &SelfDrugApiController{}, "Get:GetDrugDamageList")
  59. beego.Router("/api/drug/savedrugdamageprice", &SelfDrugApiController{}, "Get:SaveDrugDamagePrice")
  60. beego.Router("/api/drug/getdrugmodifyprice", &SelfDrugApiController{}, "Get:GetDrugModifyPrice")
  61. beego.Router("/api/drug/modifydrugprice", &SelfDrugApiController{}, "Get:ModifyDrugPrice")
  62. beego.Router("/api/drug/getmodifypriceprint", &SelfDrugApiController{}, "Get:GetModifyPricePrint")
  63. beego.Router("/api/drug/getdrugdamagedetail", &SelfDrugApiController{}, "Get:GetDrugDamageDetail")
  64. beego.Router("/api/drug/modifydrugdamage", &SelfDrugApiController{}, "Get:ModifyDrugDamage")
  65. beego.Router("/api/drug/deletedrugdamage", &SelfDrugApiController{}, "Get:DeleteDrugDamage")
  66. beego.Router("/api/drug/getdrugdamageprint", &SelfDrugApiController{}, "Get:GetDrugDamagePrint")
  67. beego.Router("/api/drug/warehouseinfobyid", &SelfDrugApiController{}, "Get:GetWarehoseInfoById")
  68. }
  69. func (this *SelfDrugApiController) GetCurrentPatient() {
  70. adminUserInfo := this.GetAdminUserInfo()
  71. orgId := adminUserInfo.CurrentOrgId
  72. patient, err := service.GetCurrentPatient(orgId)
  73. if err != nil {
  74. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  75. return
  76. }
  77. this.ServeSuccessJSON(map[string]interface{}{
  78. "patient": patient,
  79. })
  80. }
  81. func (this *SelfDrugApiController) GetAllDrugName() {
  82. adminUserInfo := this.GetAdminUserInfo()
  83. orgId := adminUserInfo.CurrentOrgId
  84. //查询药品库是否开启
  85. //configStock, _ := service.GetDrugStockConfig(orgId)
  86. //if configStock.IsOpen == 1 {
  87. //
  88. //}
  89. drugName, err := service.GetAllDrugName(orgId)
  90. if err != nil {
  91. this.ServeFailJsonSend(enums.ErrorCodeDataException, "查寻成功")
  92. return
  93. }
  94. this.ServeSuccessJSON(map[string]interface{}{
  95. "drugName": drugName,
  96. })
  97. }
  98. func (this *SelfDrugApiController) SaveDrugName() {
  99. adminUserInfo := this.GetAdminUserInfo()
  100. orgId := adminUserInfo.CurrentOrgId
  101. drug_name := this.GetString("drug_name")
  102. id, _ := this.GetInt64("id")
  103. //fmt.Println("drug_name", drug_name)
  104. drugName := models.XtDrugName{
  105. UserOrgId: orgId,
  106. DrugName: drug_name,
  107. Status: 1,
  108. CreatedTime: time.Now().Unix(),
  109. DrugId: id,
  110. }
  111. _, errcode := service.GetDrugName(drug_name, orgId)
  112. if errcode == gorm.ErrRecordNotFound {
  113. err := service.SaveDrugName(&drugName)
  114. if err != nil {
  115. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  116. return
  117. }
  118. this.ServeSuccessJSON(map[string]interface{}{
  119. "drugName": drugName,
  120. })
  121. } else {
  122. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  123. return
  124. }
  125. }
  126. func (this *SelfDrugApiController) GetDrugNameList() {
  127. adminUserInfo := this.GetAdminUserInfo()
  128. orgId := adminUserInfo.CurrentOrgId
  129. list, err := service.GetDrugNameList(orgId)
  130. if err != nil {
  131. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  132. return
  133. }
  134. this.ServeSuccessJSON(map[string]interface{}{
  135. "list": list,
  136. })
  137. }
  138. func (this *SelfDrugApiController) GetRulleName() {
  139. adminUserInfo := this.GetAdminUserInfo()
  140. orgId := adminUserInfo.CurrentOrgId
  141. id, _ := this.GetInt64("id")
  142. drugId, _ := service.GetDrugId(id)
  143. rullerList, err := service.GetRulleList(orgId, drugId.DrugId)
  144. if err != nil {
  145. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  146. return
  147. }
  148. this.ServeSuccessJSON(map[string]interface{}{
  149. "rullerList": rullerList,
  150. })
  151. }
  152. func (this *SelfDrugApiController) GetUnitByBaseId() {
  153. id, _ := this.GetInt64("id")
  154. baseList, err := service.GetUnitByBaseId(id)
  155. if err != nil {
  156. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  157. return
  158. }
  159. this.ServeSuccessJSON(map[string]interface{}{
  160. "baseList": baseList,
  161. })
  162. }
  163. func (this *SelfDrugApiController) SaveRulleName() {
  164. drug_name := this.GetString("drug_name")
  165. drug_spec := this.GetString("drug_spec")
  166. drug_stock_limit := this.GetString("drug_stock_limit")
  167. drug_name_id, _ := this.GetInt64("drug_name_id")
  168. drug_id, _ := this.GetInt64("drug_id")
  169. price, _ := this.GetInt64("price")
  170. prices := strconv.FormatInt(price, 10)
  171. durg_price, _ := strconv.ParseFloat(prices, 64)
  172. unit := this.GetString("unit")
  173. adminUserInfo := this.GetAdminUserInfo()
  174. orgId := adminUserInfo.CurrentOrgId
  175. fmt.Println(drug_name, drug_stock_limit, unit, price, drug_spec, orgId)
  176. drugSpecName := models.XtStandName{
  177. DrugName: drug_name,
  178. DrugSpec: drug_spec,
  179. DrugStockLimit: drug_stock_limit,
  180. DrugNameId: drug_name_id,
  181. Price: durg_price,
  182. MinUnit: unit,
  183. UserOrgId: orgId,
  184. Status: 1,
  185. CreatedTime: time.Now().Unix(),
  186. DrugId: drug_id,
  187. }
  188. //查询该机构下药品规格名称是否存在
  189. _, errcode := service.IsExistStandName(drug_name, drug_spec, adminUserInfo.CurrentOrgId)
  190. if errcode == gorm.ErrRecordNotFound {
  191. err := service.SaveRulleName(&drugSpecName)
  192. if err != nil {
  193. this.ServeFailJsonSend(enums.ErrorCodeDataException, "创建规格失败")
  194. return
  195. }
  196. this.ServeSuccessJSON(map[string]interface{}{
  197. "RullerName": drugSpecName,
  198. })
  199. } else if errcode == nil {
  200. this.ServeFailJsonSend(enums.ErrorCodeDataException, "规格已存在")
  201. return
  202. }
  203. }
  204. func (this *SelfDrugApiController) EditRullerName() {
  205. id, _ := this.GetInt64("id")
  206. rullerDetail, err := service.GetRullerNameDetail(id)
  207. if err != nil {
  208. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  209. return
  210. }
  211. this.ServeSuccessJSON(map[string]interface{}{
  212. "rullerDetail": rullerDetail,
  213. })
  214. }
  215. func (this *SelfDrugApiController) UpdatedRullerName() {
  216. id, _ := this.GetInt64("id")
  217. drug_name := this.GetString("drug_name")
  218. drug_stock_limit := this.GetString("drug_stock_limit")
  219. price, _ := this.GetInt64("price")
  220. prices := strconv.FormatInt(price, 10)
  221. durg_price, _ := strconv.ParseFloat(prices, 64)
  222. drug_spec := this.GetString("drug_spec")
  223. unit := this.GetString("unit")
  224. drug_name_id, _ := this.GetInt64("drug_name_id")
  225. drug_id, _ := this.GetInt64("drug_id")
  226. RullerName := models.XtStandName{
  227. DrugName: drug_name,
  228. DrugStockLimit: drug_stock_limit,
  229. Price: durg_price,
  230. DrugSpec: drug_spec,
  231. MinUnit: unit,
  232. DrugNameId: drug_name_id,
  233. DrugId: drug_id,
  234. }
  235. _, errcode := service.GetIsExit(drug_name, drug_spec, id)
  236. if errcode == gorm.ErrRecordNotFound {
  237. err := service.UpdatedRullerName(id, &RullerName)
  238. if err != nil {
  239. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  240. return
  241. }
  242. this.ServeSuccessJSON(map[string]interface{}{
  243. "RullerName": RullerName,
  244. })
  245. } else if errcode == nil {
  246. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  247. return
  248. }
  249. }
  250. func (this *SelfDrugApiController) GetAllDrugNameList() {
  251. adminUserInfo := this.GetAdminUserInfo()
  252. orgId := adminUserInfo.CurrentOrgId
  253. rullerName, err := service.GetAllDrugNameList(orgId)
  254. list, err := service.GetMedicalDrugNameList(orgId)
  255. if err != nil {
  256. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  257. return
  258. }
  259. this.ServeSuccessJSON(map[string]interface{}{
  260. "rullerName": rullerName,
  261. "list": list,
  262. })
  263. }
  264. func (this *SelfDrugApiController) GetRullerListByDrugName() {
  265. id := this.GetString("id")
  266. adminUserInfo := this.GetAdminUserInfo()
  267. orgId := adminUserInfo.CurrentOrgId
  268. fmt.Println("orgid", orgId)
  269. drugName, err := service.GetRullerListByDrugName(id, orgId)
  270. if err != nil {
  271. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  272. return
  273. }
  274. this.ServeSuccessJSON(map[string]interface{}{
  275. "drugName": drugName,
  276. })
  277. }
  278. func (this *SelfDrugApiController) SaveSelfMedicines() {
  279. dataBody := make(map[string]interface{}, 0)
  280. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  281. fmt.Println(err)
  282. patient_id := int64(dataBody["patient_id"].(float64))
  283. medicineData, _ := dataBody["medicineData"].([]interface{})
  284. adminUserInfo := this.GetAdminUserInfo()
  285. orgId := adminUserInfo.CurrentOrgId
  286. for _, item := range medicineData {
  287. items := item.(map[string]interface{})
  288. drug_name := items["drug_name"].(string)
  289. drug_name_id := int64(items["drug_name_id"].(float64))
  290. drug_spec := items["drug_spec"].(string)
  291. min_unit := items["min_unit"].(string)
  292. drug_id := int64(items["drug_id"].(float64))
  293. //根据drug_id
  294. drugMedical, _ := service.GetBaseDrugMedical(drug_name_id)
  295. medical := models.XtSelfMedical{
  296. DrugName: drug_name,
  297. DrugNameId: drug_name_id,
  298. DrugSpec: drug_spec,
  299. CreatedTime: time.Now().Unix(),
  300. Status: 1,
  301. UserOrgId: orgId,
  302. PatientId: patient_id,
  303. MinUnit: min_unit,
  304. ExecutionFrequency: drugMedical.ExecutionFrequency,
  305. PrescribingNumber: drugMedical.PrescribingNumber,
  306. DeliveryWay: drugMedical.DeliveryWay,
  307. SingleDose: drugMedical.SingleDose,
  308. DrugId: drug_id,
  309. }
  310. //查询同个病人同个药品同个规格是否已存在
  311. _, errcode := service.GetSelfMedicalByDrugName(drug_name, drug_spec, patient_id)
  312. if errcode == gorm.ErrRecordNotFound {
  313. err := service.CreateSelfMedical(&medical)
  314. fmt.Println(err)
  315. } else if errcode == nil {
  316. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  317. return
  318. }
  319. }
  320. returnData := make(map[string]interface{}, 0)
  321. returnData["msg"] = "ok"
  322. this.ServeSuccessJSON(returnData)
  323. return
  324. }
  325. func (this *SelfDrugApiController) GetCurrentOrgAllStaff() {
  326. adminUserInfo := this.GetAdminUserInfo()
  327. orgid := adminUserInfo.CurrentOrgId
  328. //fmt.Println(orgid)
  329. appId := adminUserInfo.CurrentAppId
  330. staff, err := service.GetCurrentOrgAllStaff(orgid, appId)
  331. if err != nil {
  332. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  333. return
  334. }
  335. this.ServeSuccessJSON(map[string]interface{}{
  336. "staff": staff,
  337. })
  338. }
  339. func (this *SelfDrugApiController) SaveStock() {
  340. timeLayout := "2006-01-02"
  341. loc, _ := time.LoadLocation("Local")
  342. start_time := this.GetString("start_time")
  343. fmt.Println("start_time", start_time)
  344. admin_user_id, _ := this.GetInt64("admin_user_id")
  345. fmt.Println("admin_user_id", admin_user_id)
  346. patient_id, _ := this.GetInt64("patient_id")
  347. dataBody := make(map[string]interface{}, 0)
  348. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  349. fmt.Println(err)
  350. stocks, _ := dataBody["stocks"].([]interface{})
  351. adminUserInfo := this.GetAdminUserInfo()
  352. orgId := adminUserInfo.CurrentOrgId
  353. for _, item := range stocks {
  354. items := item.(map[string]interface{})
  355. drug_name := items["drug_name"].(string)
  356. fmt.Println("drug_name", drug_name)
  357. drug_name_id := int64(items["drug_name_id"].(float64))
  358. fmt.Println("parient_id", drug_name_id)
  359. drug_spec := items["drug_spec"].(string)
  360. store_number := items["store_number"].(string)
  361. fmt.Println("store_number", store_number)
  362. storeNumber, _ := strconv.ParseInt(store_number, 10, 64)
  363. remarks := items["remarks"].(string)
  364. min_unit := items["min_unit"].(string)
  365. medic_id := int64(items["id"].(float64))
  366. timeStr := time.Now().Format("2006-01-02")
  367. timeArr := strings.Split(timeStr, "-")
  368. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  369. total = total + 1
  370. warehousing_in_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  371. number, _ := strconv.ParseInt(warehousing_in_order, 10, 64)
  372. number = number + total
  373. warehousing_in_order = "RKD" + strconv.FormatInt(number, 10)
  374. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  375. stock := models.XtSelfStock{
  376. DrugName: drug_name,
  377. DrugNameId: drug_name_id,
  378. DrugSpec: drug_spec,
  379. StoreNumber: storeNumber,
  380. Remarks: remarks,
  381. AdminUserId: admin_user_id,
  382. StorckTime: theTime.Unix(),
  383. CreatedTime: time.Now().Unix(),
  384. Status: 1,
  385. UserOrgId: orgId,
  386. StockInNumber: warehousing_in_order,
  387. PatientId: patient_id,
  388. MinUnit: min_unit,
  389. StorageMode: 1,
  390. MedicId: medic_id,
  391. }
  392. err := service.CreateStock(&stock)
  393. fmt.Println("err", err)
  394. }
  395. returnData := make(map[string]interface{}, 0)
  396. returnData["msg"] = "ok"
  397. this.ServeSuccessJSON(returnData)
  398. return
  399. }
  400. func (this *SelfDrugApiController) SaveOutStock() {
  401. timeLayout := "2006-01-02"
  402. loc, _ := time.LoadLocation("Local")
  403. start_time := this.GetString("start_time")
  404. admin_user_id, _ := this.GetInt64("admin_user_id")
  405. patient_id, _ := this.GetInt64("patient_id")
  406. dataBody := make(map[string]interface{}, 0)
  407. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  408. fmt.Println(err)
  409. outStocks, _ := dataBody["outStocks"].([]interface{})
  410. adminUserInfo := this.GetAdminUserInfo()
  411. orgId := adminUserInfo.CurrentOrgId
  412. for _, item := range outStocks {
  413. items := item.(map[string]interface{})
  414. drug_name := items["drug_name"].(string)
  415. drug_name_id := int64(items["drug_name_id"].(float64))
  416. drug_spec := items["drug_spec"].(string)
  417. outstore_number := items["outstore_number"].(string)
  418. outStoreNumber, _ := strconv.ParseInt(outstore_number, 10, 64)
  419. remarks := items["remarks"].(string)
  420. medic_id := int64(items["id"].(float64))
  421. timeStr := time.Now().Format("2006-01-02")
  422. timeArr := strings.Split(timeStr, "-")
  423. total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
  424. total = total + 1
  425. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  426. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  427. number = number + total
  428. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  429. fmt.Println(remarks)
  430. fmt.Println(items)
  431. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  432. stock := models.XtSelfOutStock{
  433. DrugName: drug_name,
  434. DrugNameId: drug_name_id,
  435. DrugSpec: drug_spec,
  436. OutstoreNumber: outStoreNumber,
  437. Remarks: remarks,
  438. AdminUserId: admin_user_id,
  439. StorckTime: theTime.Unix(),
  440. CreatedTime: time.Now().Unix(),
  441. Status: 1,
  442. UserOrgId: orgId,
  443. StockOutNumber: warehousing_out_order,
  444. PatientId: patient_id,
  445. ExitMode: 1,
  446. MedicId: medic_id,
  447. }
  448. err := service.CreateOutStock(&stock)
  449. fmt.Println("err", err)
  450. }
  451. returnData := make(map[string]interface{}, 0)
  452. returnData["msg"] = "ok"
  453. this.ServeSuccessJSON(returnData)
  454. return
  455. }
  456. func (this *SelfDrugApiController) DeleteDrugById() {
  457. id, _ := this.GetInt64("id")
  458. drug_name := this.GetString("drug_name")
  459. adminUserInfo := this.GetAdminUserInfo()
  460. orgId := adminUserInfo.CurrentOrgId
  461. _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
  462. if errcode == gorm.ErrRecordNotFound {
  463. service.DeleteDrugName(id)
  464. returnData := make(map[string]interface{}, 0)
  465. returnData["msg"] = "ok"
  466. this.ServeSuccessJSON(returnData)
  467. } else if errcode == nil {
  468. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  469. return
  470. }
  471. }
  472. func (this *SelfDrugApiController) SaveRadio() {
  473. radio, _ := this.GetInt64("radio")
  474. adminUserInfo := this.GetAdminUserInfo()
  475. orgId := adminUserInfo.CurrentOrgId
  476. drugSet := models.XtDrugSet{
  477. DrugStart: radio,
  478. UserOrgId: orgId,
  479. Status: 1,
  480. CreatedTime: time.Now().Unix(),
  481. }
  482. _, errcode := service.GetDrugSetByUserOrgId(orgId)
  483. if errcode == gorm.ErrRecordNotFound {
  484. err := service.SaveRadio(&drugSet)
  485. if err != nil {
  486. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  487. return
  488. }
  489. this.ServeSuccessJSON(map[string]interface{}{
  490. "drugSet": drugSet,
  491. })
  492. } else if errcode == nil {
  493. err := service.UpdateDrugSet(&drugSet, orgId)
  494. if err != nil {
  495. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  496. return
  497. }
  498. this.ServeSuccessJSON(map[string]interface{}{
  499. "drugSet": drugSet,
  500. })
  501. }
  502. }
  503. func (this *SelfDrugApiController) DeleteDrugStand() {
  504. id, _ := this.GetInt64("id")
  505. name := this.GetString("name")
  506. adminUserInfo := this.GetAdminUserInfo()
  507. orgId := adminUserInfo.CurrentOrgId
  508. _, errcode := service.GetMedicalsByName(orgId, name)
  509. if errcode == gorm.ErrRecordNotFound {
  510. err := service.DeleteDrugStand(id)
  511. fmt.Println(err)
  512. returnData := make(map[string]interface{}, 0)
  513. returnData["msg"] = "ok"
  514. this.ServeSuccessJSON(returnData)
  515. } else if errcode == nil {
  516. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  517. return
  518. }
  519. }
  520. func (this *SelfDrugApiController) GetStockList() {
  521. patientid, _ := this.GetInt64("id")
  522. start_time := this.GetString("start_time")
  523. fmt.Println("开始时间", start_time)
  524. timeLayout := "2006-01-02"
  525. loc, _ := time.LoadLocation("Local")
  526. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  527. startimeUnix := theTime.Unix()
  528. keyword := this.GetString("keyword")
  529. fmt.Println("keyword", keyword)
  530. adminUserInfo := this.GetAdminUserInfo()
  531. orgId := adminUserInfo.CurrentOrgId
  532. //获取
  533. medicalList, _ := service.GetMedicalList(patientid, orgId, keyword)
  534. //统计总数量
  535. stocklist, err := service.GetStockList(patientid, startimeUnix, keyword, orgId)
  536. //统计出库数量
  537. outStocklist, err := service.GetOutStockList(patientid, startimeUnix, keyword, orgId)
  538. //统计该病人时间段内出库条数
  539. outList, err := service.GetTotalOutStockList(patientid, startimeUnix, keyword, orgId)
  540. if err != nil {
  541. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  542. return
  543. }
  544. this.ServeSuccessJSON(map[string]interface{}{
  545. "medicalList": medicalList,
  546. "stocklist": stocklist,
  547. "outStocklist": outStocklist,
  548. "outList": outList,
  549. })
  550. }
  551. func (this *SelfDrugApiController) DeleteDrugName() {
  552. drug_name := this.GetString("drugname")
  553. patient_id, _ := this.GetInt64("patientid")
  554. //查询该药品是否出库
  555. stocklist, _ := service.GetStockOutDetail(drug_name, patient_id)
  556. if len(stocklist) == 0 {
  557. //删除该药品
  558. service.DeleteDrugStockNumber(drug_name, patient_id)
  559. returnData := make(map[string]interface{}, 0)
  560. returnData["msg"] = "ok"
  561. this.ServeSuccessJSON(returnData)
  562. } else {
  563. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  564. return
  565. }
  566. }
  567. func (this *SelfDrugApiController) GetDrugDetail() {
  568. timeLayout := "2006-01-02"
  569. loc, _ := time.LoadLocation("Local")
  570. drug_name := this.GetString("drug_name")
  571. drug_spec := this.GetString("drug_spec")
  572. start_time := this.GetString("start_time")
  573. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  574. end_time := this.GetString("end_time")
  575. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  576. patient_id, _ := this.GetInt64("patient_id")
  577. adminUserInfo := this.GetAdminUserInfo()
  578. orgId := adminUserInfo.CurrentOrgId
  579. //查询入库明细
  580. stockDetail, err := service.GetStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
  581. //查询出库明细
  582. outStockDetail, err := service.GetOutStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
  583. if err != nil {
  584. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  585. return
  586. }
  587. this.ServeSuccessJSON(map[string]interface{}{
  588. "stockDetail": stockDetail,
  589. "outStockDetail": outStockDetail,
  590. })
  591. }
  592. func (this *SelfDrugApiController) GetAllPatientStockList() {
  593. timeLayout := "2006-01-02"
  594. loc, _ := time.LoadLocation("Local")
  595. drug_name := this.GetString("drug_name")
  596. drug_spec := this.GetString("drug_spec")
  597. start_time := this.GetString("start_time")
  598. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  599. startUnix := theTime.Unix()
  600. end_time := this.GetString("end_time")
  601. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  602. endTimeUnix := endTimes.Unix()
  603. keywords := this.GetString("search_input")
  604. adminUserInfo := this.GetAdminUserInfo()
  605. orgId := adminUserInfo.CurrentOrgId
  606. //入库
  607. stocklist, err := service.GetAllPatientStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
  608. //出库
  609. outStockList, err := service.GetAllPatientOutStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
  610. if err != nil {
  611. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  612. return
  613. }
  614. this.ServeSuccessJSON(map[string]interface{}{
  615. "stocklist": stocklist,
  616. "outStockList": outStockList,
  617. })
  618. }
  619. func (this *SelfDrugApiController) GetDrugDataByPatientId() {
  620. patient_id, _ := this.GetInt64("patient_id")
  621. fmt.Println("patient_id", patient_id)
  622. medicalList, err := service.GetDrugDataByPatientId(patient_id)
  623. if err != nil {
  624. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  625. return
  626. }
  627. this.ServeSuccessJSON(map[string]interface{}{
  628. "medicalList": medicalList,
  629. })
  630. }
  631. func (this *SelfDrugApiController) GetSelfMedicalList() {
  632. patient_id, _ := this.GetInt64("patient_id")
  633. adminUserInfo := this.GetAdminUserInfo()
  634. orgId := adminUserInfo.CurrentOrgId
  635. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  636. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(orgId)
  637. drugList, _ := service.GetAllBaseDrugLibList(orgId)
  638. privateDrugList, _ := service.GetPrivateDrugList(patient_id, orgId)
  639. this.ServeSuccessJSON(map[string]interface{}{
  640. "base_drug_config": drugStockConfig,
  641. "private_drug_config": privateDrugConfig,
  642. "base_drug_list": drugList,
  643. "private_drug_list": privateDrugList,
  644. })
  645. ////查询是否开启药品库
  646. //config, _ := service.GetDruckStockConfig(orgId)
  647. //
  648. //fmt.Println("--------------------------",config.IsOpen)
  649. ////开启
  650. //if config.IsOpen == 1 {
  651. // //查询该机构下的药品库
  652. // drugName, _ := service.GetAllDrugName(orgId)
  653. //
  654. // //查询该机构是否开启自备药
  655. // medical, _ := service.GetSetSelfMedical(orgId)
  656. // fmt.Println("medical+++++++++++++++++",medical.DrugStart)
  657. // //开启
  658. // if medical.DrugStart == 1 {
  659. // list, err := service.GetSelfMedicalList(patient_id)
  660. // if err != nil {
  661. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  662. // return
  663. // }
  664. // this.ServeSuccessJSON(map[string]interface{}{
  665. // "medicalList": list,
  666. // "drugName": drugName,
  667. // })
  668. // } else {
  669. // this.ServeSuccessJSON(map[string]interface{}{
  670. // "drugName": drugName,
  671. // })
  672. // }
  673. //}
  674. }
  675. func (this *SelfDrugApiController) GetDrugDescByDrugName() {
  676. drug_name := this.GetString("drug_name")
  677. patient_id, _ := this.GetInt64("patient_id")
  678. way, _ := this.GetInt64("way")
  679. adminUserInfo := this.GetAdminUserInfo()
  680. orgId := adminUserInfo.CurrentOrgId
  681. drug_id, _ := this.GetInt64("id")
  682. //从基础库查询
  683. if way == 1 {
  684. //查询基础库数据
  685. medcal, err := service.GetBaseMedcal(drug_name, orgId)
  686. //统计入库数量
  687. countInfo, err := service.GetTotalBaseMedicalCount(drug_id, orgId)
  688. //统计出库数量
  689. countout, err := service.GetTotalBaseMedicalCountOut(drug_id, orgId)
  690. if err != nil {
  691. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  692. return
  693. }
  694. this.ServeSuccessJSON(map[string]interface{}{
  695. "drugspec": medcal,
  696. "countInfo": countInfo,
  697. "countout": countout,
  698. })
  699. }
  700. //从自备药库查询
  701. if way == 2 {
  702. drugspec, err := service.GetDrugDescByDrugName(drug_name, patient_id, orgId)
  703. if err != nil {
  704. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  705. return
  706. }
  707. this.ServeSuccessJSON(map[string]interface{}{
  708. "drugspec": drugspec,
  709. })
  710. }
  711. }
  712. func (this *SelfDrugApiController) GetDrugSet() {
  713. adminUserInfo := this.GetAdminUserInfo()
  714. orgId := adminUserInfo.CurrentOrgId
  715. drugSet, err := service.GetDrugSet(orgId)
  716. if err != nil {
  717. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  718. return
  719. }
  720. this.ServeSuccessJSON(map[string]interface{}{
  721. "drugSet": drugSet,
  722. })
  723. }
  724. func (this *SelfDrugApiController) GetAllMedicalList() {
  725. adminUserInfo := this.GetAdminUserInfo()
  726. orgId := adminUserInfo.CurrentOrgId
  727. list, err := service.GetAllMedicalList(orgId)
  728. if err != nil {
  729. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  730. return
  731. }
  732. this.ServeSuccessJSON(map[string]interface{}{
  733. "drugName": list,
  734. })
  735. }
  736. func (this *SelfDrugApiController) GetStandName() {
  737. name := this.GetString("name")
  738. adminUserInfo := this.GetAdminUserInfo()
  739. orgId := adminUserInfo.CurrentOrgId
  740. rullerlist, err := service.GetRulleName(orgId, name)
  741. if err != nil {
  742. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  743. return
  744. }
  745. this.ServeSuccessJSON(map[string]interface{}{
  746. "rullerlist": rullerlist,
  747. })
  748. }
  749. func (this *SelfDrugApiController) GetRullerList() {
  750. id, _ := this.GetInt64("id")
  751. adminUserInfo := this.GetAdminUserInfo()
  752. orgId := adminUserInfo.CurrentOrgId
  753. rullerList, err := service.GetRulleList(orgId, id)
  754. if err != nil {
  755. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  756. return
  757. }
  758. this.ServeSuccessJSON(map[string]interface{}{
  759. "rullerlist": rullerList,
  760. })
  761. }
  762. func (this *SelfDrugApiController) DeleteDrugNameById() {
  763. id, _ := this.GetInt64("id")
  764. drug_name := this.GetString("drug_name")
  765. adminUserInfo := this.GetAdminUserInfo()
  766. orgId := adminUserInfo.CurrentOrgId
  767. _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
  768. if errcode == gorm.ErrRecordNotFound {
  769. service.DeleteDrugNameById(id)
  770. returnData := make(map[string]interface{}, 0)
  771. returnData["msg"] = "ok"
  772. this.ServeSuccessJSON(returnData)
  773. } else if errcode == nil {
  774. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  775. return
  776. }
  777. }
  778. func (this *SelfDrugApiController) GetPatientDetail() {
  779. id, _ := this.GetInt64("id")
  780. adminUserInfo := this.GetAdminUserInfo()
  781. patientDetail, err := service.GetPatientDetail(id, adminUserInfo.CurrentOrgId)
  782. if err != nil {
  783. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  784. return
  785. }
  786. this.ServeSuccessJSON(map[string]interface{}{
  787. "patientDetail": patientDetail,
  788. })
  789. }
  790. //func (this *SelfDrugApiController) ToPatientDetail() {
  791. //
  792. // keyword := this.GetString("keyword")
  793. // adminUser := this.GetAdminUserInfo()
  794. // orgId := adminUser.CurrentOrgId
  795. // patient, err := service.ToSeachPatient(keyword, orgId)
  796. // if err != nil {
  797. // this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  798. // return
  799. // }
  800. // this.ServeSuccessJSON(map[string]interface{}{
  801. // "patient": patient,
  802. // })
  803. //}
  804. func (this *SelfDrugApiController) GetSelfStockQuery() {
  805. adminUserInfo := this.GetAdminUserInfo()
  806. orgId := adminUserInfo.CurrentOrgId
  807. type_name, _ := this.GetInt64("type_name")
  808. keywords := this.GetString("keywords")
  809. timeLayout := "2006-01-02"
  810. loc, _ := time.LoadLocation("Local")
  811. start_time := this.GetString("start_time")
  812. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  813. startUnix := theTime.Unix()
  814. end_time := this.GetString("end_time")
  815. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  816. endTimeUnix := endTimes.Unix()
  817. page, _ := this.GetInt64("page")
  818. limit, _ := this.GetInt64("limit")
  819. //统计入库数量
  820. stockQuery, total, err := service.GetSelfStockQuery(type_name, keywords, startUnix, endTimeUnix, orgId, limit, page)
  821. //统计出库数量
  822. stockOutQuery, err := service.GetSelfOutStockQuery(startUnix, endTimeUnix, orgId)
  823. if err != nil {
  824. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  825. return
  826. }
  827. this.ServeSuccessJSON(map[string]interface{}{
  828. "stockQuery": stockQuery,
  829. "total": total,
  830. "stockOutQuery": stockOutQuery,
  831. })
  832. }
  833. func (this *SelfDrugApiController) PostSearchDrugWarehouseList() {
  834. keyword := this.GetString("keyword")
  835. orgId := this.GetAdminUserInfo().CurrentOrgId
  836. list, err := service.PostSearchDrugWarehouseList(keyword, orgId)
  837. manufacturerList, err := service.GetAllManufacturerList(orgId)
  838. dealerList, err := service.GetAllDealerList(orgId)
  839. if err != nil {
  840. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  841. return
  842. }
  843. this.ServeSuccessJSON(map[string]interface{}{
  844. "list": list,
  845. "manufacturerList": manufacturerList,
  846. "dealerList": dealerList,
  847. })
  848. }
  849. func (this *SelfDrugApiController) SaveDrugPrice() {
  850. fmt.Println("999999999999999999999")
  851. timeLayout := "2006-01-02"
  852. loc, _ := time.LoadLocation("Local")
  853. dataBody := make(map[string]interface{}, 0)
  854. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  855. fmt.Println(err)
  856. tableData, _ := dataBody["tableData"].([]interface{})
  857. fmt.Println("999939433443", tableData)
  858. if len(tableData) > 0 {
  859. for _, item := range tableData {
  860. items := item.(map[string]interface{})
  861. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  862. utils.ErrorLog("drug_name")
  863. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  864. return
  865. }
  866. drug_name := items["drug_name"].(string)
  867. fmt.Println("drug_aname23232323232", drug_name)
  868. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  869. utils.ErrorLog("drug_name")
  870. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  871. return
  872. }
  873. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  874. utils.ErrorLog("retail_price")
  875. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  876. return
  877. }
  878. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  879. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  880. utils.ErrorLog("warehousing_order")
  881. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  882. return
  883. }
  884. warehousing_order := items["warehousing_order"].(string)
  885. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  886. utils.ErrorLog("number")
  887. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  888. return
  889. }
  890. number := items["number"].(string)
  891. if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  892. utils.ErrorLog("dealer")
  893. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  894. return
  895. }
  896. dealer := items["dealer"].(string)
  897. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  898. utils.ErrorLog("manufacturer")
  899. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  900. return
  901. }
  902. manufacturer := items["manufacturer"].(string)
  903. //if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  904. // utils.ErrorLog("specification_name")
  905. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  906. // return
  907. //}
  908. //specification_name := items["specification_name"].(string)
  909. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  910. utils.ErrorLog("remark")
  911. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  912. return
  913. }
  914. remark := items["remark"].(string)
  915. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  916. utils.ErrorLog("warehousing_unit")
  917. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  918. return
  919. }
  920. warehousing_unit := items["warehousing_unit"].(string)
  921. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  922. utils.ErrorLog("last_price")
  923. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  924. return
  925. }
  926. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  927. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  928. utils.ErrorLog("count")
  929. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  930. return
  931. }
  932. count := int64(items["count"].(float64))
  933. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  934. utils.ErrorLog("new_price")
  935. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  936. return
  937. }
  938. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  939. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  940. utils.ErrorLog("drug_id")
  941. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  942. return
  943. }
  944. drug_id := int64(items["drug_id"].(float64))
  945. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  946. utils.ErrorLog("start_time")
  947. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  948. return
  949. }
  950. var startTime int64
  951. start_time := items["start_time"].(string)
  952. if len(start_time) > 0 {
  953. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  954. if err != nil {
  955. fmt.Println(err)
  956. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  957. return
  958. }
  959. startTime = theTime.Unix()
  960. }
  961. orgId := this.GetAdminUserInfo().CurrentOrgId
  962. Creater := this.GetAdminUserInfo().AdminUser.Id
  963. drugAdjust := models.XtDrugAdjustPrice{
  964. DrugName: drug_name,
  965. SpecificationName: "",
  966. WarehousingUnit: warehousing_unit,
  967. Count: count,
  968. LastPrice: last_price,
  969. RetailPrice: retail_price,
  970. NewPrice: new_price,
  971. Manufacturer: manufacturer,
  972. Dealer: dealer,
  973. Remark: remark,
  974. DrugId: drug_id,
  975. UserOrgId: orgId,
  976. Ctime: time.Now().Unix(),
  977. Mtime: 0,
  978. Status: 1,
  979. WarehousingOrder: warehousing_order,
  980. Number: number,
  981. StartTime: startTime,
  982. Creater: Creater,
  983. Checker: 0,
  984. CheckerStatus: 2,
  985. CheckerTime: 0,
  986. }
  987. err := service.CreateDrugPrice(drugAdjust)
  988. fmt.Println(err)
  989. }
  990. }
  991. returnData := make(map[string]interface{}, 0)
  992. returnData["msg"] = "ok"
  993. this.ServeSuccessJSON(returnData)
  994. return
  995. }
  996. func (this *SelfDrugApiController) GetDrugPriceList() {
  997. timeLayout := "2006-01-02"
  998. loc, _ := time.LoadLocation("Local")
  999. dataBody := make(map[string]interface{}, 0)
  1000. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1001. fmt.Println(err)
  1002. orgId := this.GetAdminUserInfo().CurrentOrgId
  1003. keyword := this.GetString("keyword")
  1004. start_time := this.GetString("start_time")
  1005. end_time := this.GetString("end_time")
  1006. var startTime int64
  1007. if len(start_time) > 0 {
  1008. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1009. if err != nil {
  1010. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1011. return
  1012. }
  1013. startTime = theTime.Unix()
  1014. }
  1015. var endTime int64
  1016. if len(end_time) > 0 {
  1017. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1018. if err != nil {
  1019. utils.ErrorLog(err.Error())
  1020. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1021. return
  1022. }
  1023. endTime = theTime.Unix()
  1024. }
  1025. limit, _ := this.GetInt64("limit")
  1026. page, _ := this.GetInt64("page")
  1027. list, total, err := service.GetDrugPriceList(startTime, endTime, orgId, keyword, limit, page)
  1028. doctorList, err := service.GetAllDoctorThree(orgId)
  1029. if err != nil {
  1030. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1031. return
  1032. }
  1033. this.ServeSuccessJSON(map[string]interface{}{
  1034. "total": total,
  1035. "list": list,
  1036. "doctorList": doctorList,
  1037. })
  1038. }
  1039. func (this *SelfDrugApiController) SaveCheckDrugPrice() {
  1040. timeLayout := "2006-01-02"
  1041. loc, _ := time.LoadLocation("Local")
  1042. dataBody := make(map[string]interface{}, 0)
  1043. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1044. fmt.Println(err)
  1045. idstr := this.GetString("ids")
  1046. ids := strings.Split(idstr, ",")
  1047. check_time := this.GetString("check_time")
  1048. var checkTime int64
  1049. if len(check_time) > 0 {
  1050. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1051. if err != nil {
  1052. fmt.Println(err)
  1053. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1054. return
  1055. }
  1056. checkTime = theTime.Unix()
  1057. }
  1058. checker, _ := this.GetInt64("checker")
  1059. adjustPrice := models.XtDrugAdjustPrice{
  1060. Checker: checker,
  1061. CheckerStatus: 1,
  1062. CheckerTime: checkTime,
  1063. }
  1064. err = service.UpdateDrugAdjuestPrice(ids, adjustPrice)
  1065. fmt.Println("err", err)
  1066. this.ServeSuccessJSON(map[string]interface{}{
  1067. "adjustPrice": adjustPrice,
  1068. })
  1069. }
  1070. func (this *SelfDrugApiController) SaveDrugDamage() {
  1071. fmt.Println("999999999999999999999")
  1072. timeLayout := "2006-01-02"
  1073. loc, _ := time.LoadLocation("Local")
  1074. dataBody := make(map[string]interface{}, 0)
  1075. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1076. fmt.Println(err)
  1077. tableData, _ := dataBody["tableData"].([]interface{})
  1078. fmt.Println("999939433443", tableData)
  1079. if len(tableData) > 0 {
  1080. for _, item := range tableData {
  1081. items := item.(map[string]interface{})
  1082. drug_name := items["drug_name"].(string)
  1083. fmt.Println("durg_nae232333223332232323323223232323", drug_name)
  1084. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  1085. utils.ErrorLog("drug_name")
  1086. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1087. return
  1088. }
  1089. if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
  1090. utils.ErrorLog("retail_price")
  1091. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1092. return
  1093. }
  1094. retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
  1095. if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
  1096. utils.ErrorLog("warehousing_order")
  1097. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1098. return
  1099. }
  1100. warehousing_order := items["warehousing_order"].(string)
  1101. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  1102. utils.ErrorLog("number")
  1103. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1104. return
  1105. }
  1106. number := items["number"].(string)
  1107. //if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "string" {
  1108. // utils.ErrorLog("dealer")
  1109. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1110. // return
  1111. //}
  1112. //dealer := items["dealer"].(string)
  1113. if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "string" {
  1114. utils.ErrorLog("manufacturer")
  1115. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1116. return
  1117. }
  1118. manufacturer := items["manufacturer"].(string)
  1119. //if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
  1120. // utils.ErrorLog("specification_name")
  1121. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1122. // return
  1123. //}
  1124. //specification_name := items["specification_name"].(string)
  1125. if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
  1126. utils.ErrorLog("remark")
  1127. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1128. return
  1129. }
  1130. remark := items["remark"].(string)
  1131. if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
  1132. utils.ErrorLog("warehousing_unit")
  1133. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1134. return
  1135. }
  1136. warehousing_unit := items["warehousing_unit"].(string)
  1137. if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
  1138. utils.ErrorLog("last_price")
  1139. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1140. return
  1141. }
  1142. last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
  1143. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
  1144. utils.ErrorLog("count")
  1145. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1146. return
  1147. }
  1148. count := int64(items["count"].(float64))
  1149. if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
  1150. utils.ErrorLog("new_price")
  1151. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1152. return
  1153. }
  1154. new_price, _ := strconv.ParseFloat(items["new_price"].(string), 64)
  1155. if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
  1156. utils.ErrorLog("drug_id")
  1157. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1158. return
  1159. }
  1160. drug_id := int64(items["drug_id"].(float64))
  1161. if items["start_time"] == nil || reflect.TypeOf(items["start_time"]).String() != "string" {
  1162. utils.ErrorLog("start_time")
  1163. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1164. return
  1165. }
  1166. var startTime int64
  1167. start_time := items["start_time"].(string)
  1168. if len(start_time) > 0 {
  1169. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1170. if err != nil {
  1171. fmt.Println(err)
  1172. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1173. return
  1174. }
  1175. startTime = theTime.Unix()
  1176. }
  1177. orgId := this.GetAdminUserInfo().CurrentOrgId
  1178. Creater := this.GetAdminUserInfo().AdminUser.Id
  1179. drugDamage := models.XtDrugDamage{
  1180. DrugName: drug_name,
  1181. SpecificationName: "",
  1182. WarehousingUnit: warehousing_unit,
  1183. Count: count,
  1184. LastPrice: last_price,
  1185. RetailPrice: retail_price,
  1186. NewPrice: new_price,
  1187. Manufacturer: manufacturer,
  1188. Dealer: "",
  1189. Remark: remark,
  1190. DrugId: drug_id,
  1191. UserOrgId: orgId,
  1192. Ctime: time.Now().Unix(),
  1193. Mtime: 0,
  1194. Status: 1,
  1195. WarehousingOrder: warehousing_order,
  1196. Number: number,
  1197. StartTime: startTime,
  1198. Creater: Creater,
  1199. Checker: 0,
  1200. CheckerStatus: 2,
  1201. CheckerTime: 0,
  1202. }
  1203. err := service.CreateDrugDamage(drugDamage)
  1204. fmt.Println(err)
  1205. }
  1206. }
  1207. returnData := make(map[string]interface{}, 0)
  1208. returnData["msg"] = "ok"
  1209. this.ServeSuccessJSON(returnData)
  1210. }
  1211. func (this *SelfDrugApiController) GetDrugDamageList() {
  1212. timeLayout := "2006-01-02"
  1213. loc, _ := time.LoadLocation("Local")
  1214. dataBody := make(map[string]interface{}, 0)
  1215. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1216. fmt.Println(err)
  1217. orgId := this.GetAdminUserInfo().CurrentOrgId
  1218. keyword := this.GetString("keyword")
  1219. fmt.Println("keywoer2r2r32rwrwr", keyword)
  1220. start_time := this.GetString("start_time")
  1221. end_time := this.GetString("end_time")
  1222. var startTime int64
  1223. if len(start_time) > 0 {
  1224. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1225. if err != nil {
  1226. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1227. return
  1228. }
  1229. startTime = theTime.Unix()
  1230. }
  1231. var endTime int64
  1232. if len(end_time) > 0 {
  1233. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1234. if err != nil {
  1235. utils.ErrorLog(err.Error())
  1236. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1237. return
  1238. }
  1239. endTime = theTime.Unix()
  1240. }
  1241. limit, _ := this.GetInt64("limit")
  1242. page, _ := this.GetInt64("page")
  1243. list, total, err := service.GetDrugDamageList(startTime, endTime, orgId, keyword, limit, page)
  1244. doctorList, err := service.GetAllDoctorThree(orgId)
  1245. if err != nil {
  1246. this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
  1247. return
  1248. }
  1249. fmt.Println("list232332", list)
  1250. fmt.Println("total", total)
  1251. this.ServeSuccessJSON(map[string]interface{}{
  1252. "total": total,
  1253. "list": list,
  1254. "doctorList": doctorList,
  1255. })
  1256. }
  1257. func (this *SelfDrugApiController) SaveDrugDamagePrice() {
  1258. timeLayout := "2006-01-02"
  1259. loc, _ := time.LoadLocation("Local")
  1260. dataBody := make(map[string]interface{}, 0)
  1261. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1262. fmt.Println(err)
  1263. idstr := this.GetString("ids")
  1264. ids := strings.Split(idstr, ",")
  1265. check_time := this.GetString("check_time")
  1266. var checkTime int64
  1267. if len(check_time) > 0 {
  1268. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", check_time+" 00:00:00", loc)
  1269. if err != nil {
  1270. fmt.Println(err)
  1271. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1272. return
  1273. }
  1274. checkTime = theTime.Unix()
  1275. }
  1276. checker, _ := this.GetInt64("checker")
  1277. damage := models.XtDrugDamage{
  1278. Checker: checker,
  1279. CheckerStatus: 1,
  1280. CheckerTime: checkTime,
  1281. }
  1282. err = service.UpdateDrugDamage(ids, damage)
  1283. fmt.Println(err)
  1284. this.ServeSuccessJSON(map[string]interface{}{
  1285. "damage": damage,
  1286. })
  1287. }
  1288. func (this *SelfDrugApiController) GetDrugModifyPrice() {
  1289. id, _ := this.GetInt64("id")
  1290. detail, err := service.GetDrugModifyPrice(id)
  1291. fmt.Println(err)
  1292. this.ServeSuccessJSON(map[string]interface{}{
  1293. "detail": detail,
  1294. })
  1295. }
  1296. func (this *SelfDrugApiController) ModifyDrugPrice() {
  1297. drug_name := this.GetString("drug_name")
  1298. retailPrice := this.GetString("retail_price")
  1299. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  1300. newPrice := this.GetString("new_price")
  1301. new_price, _ := strconv.ParseFloat(newPrice, 64)
  1302. count, _ := this.GetInt64("count")
  1303. remark := this.GetString("remark")
  1304. id, _ := this.GetInt64("id")
  1305. adjustPrice := models.XtDrugAdjustPrice{
  1306. DrugName: drug_name,
  1307. Count: count,
  1308. RetailPrice: retail_price,
  1309. NewPrice: new_price,
  1310. Remark: remark,
  1311. }
  1312. err := service.ModifyDrugPrice(id, adjustPrice)
  1313. fmt.Println(err)
  1314. this.ServeSuccessJSON(map[string]interface{}{
  1315. "adjustPrice": adjustPrice,
  1316. })
  1317. }
  1318. func (this *SelfDrugApiController) GetModifyPricePrint() {
  1319. ids := this.GetString("ids")
  1320. idsSplit := strings.Split(ids, ",")
  1321. list, err := service.GetModifyPricePrint(idsSplit)
  1322. fmt.Println(err)
  1323. this.ServeSuccessJSON(map[string]interface{}{
  1324. "list": list,
  1325. })
  1326. }
  1327. func (this *SelfDrugApiController) GetDrugDamageDetail() {
  1328. id, _ := this.GetInt64("id")
  1329. detail, _ := service.GetDrugDamageDetail(id)
  1330. this.ServeSuccessJSON(map[string]interface{}{
  1331. "detail": detail,
  1332. })
  1333. }
  1334. func (this *SelfDrugApiController) ModifyDrugDamage() {
  1335. id, _ := this.GetInt64("id")
  1336. drug_id, _ := this.GetInt64("drug_id")
  1337. drug_name := this.GetString("drug_name")
  1338. //drug_origin_place := this.GetString("drug_origin_place")
  1339. lastPrice := this.GetString("last_price")
  1340. last_price, _ := strconv.ParseFloat(lastPrice, 64)
  1341. newPrice := this.GetString("new_price")
  1342. new_price, _ := strconv.ParseFloat(newPrice, 64)
  1343. manufacturer := this.GetString("manufacturer")
  1344. number := this.GetString("number")
  1345. retailPrice := this.GetString("retail_price")
  1346. retail_price, _ := strconv.ParseFloat(retailPrice, 64)
  1347. remark := this.GetString("remark")
  1348. count, _ := this.GetInt64("count")
  1349. warehousing_unit := this.GetString("warehousing_unit")
  1350. damage := models.XtDrugDamage{
  1351. DrugName: drug_name,
  1352. SpecificationName: "",
  1353. WarehousingUnit: warehousing_unit,
  1354. Count: count,
  1355. LastPrice: last_price,
  1356. RetailPrice: retail_price,
  1357. NewPrice: new_price,
  1358. Manufacturer: manufacturer,
  1359. Dealer: "",
  1360. Remark: remark,
  1361. DrugId: drug_id,
  1362. Number: number,
  1363. }
  1364. err := service.ModifyDrugDamage(id, damage)
  1365. fmt.Println(err)
  1366. this.ServeSuccessJSON(map[string]interface{}{
  1367. "damage": damage,
  1368. })
  1369. }
  1370. func (this *SelfDrugApiController) DeleteDrugDamage() {
  1371. id, _ := this.GetInt64("id")
  1372. err := service.DeleteDrugDamage(id)
  1373. fmt.Println(err)
  1374. returnData := make(map[string]interface{}, 0)
  1375. returnData["msg"] = "ok"
  1376. this.ServeSuccessJSON(returnData)
  1377. }
  1378. func (this *SelfDrugApiController) GetDrugDamagePrint() {
  1379. idsSplit := this.GetString("ids")
  1380. ids := strings.Split(idsSplit, ",")
  1381. list, _ := service.GetDrugDamagePrint(ids)
  1382. this.ServeSuccessJSON(map[string]interface{}{
  1383. "list": list,
  1384. })
  1385. }
  1386. func (this *SelfDrugApiController) GetWarehoseInfoById() {
  1387. id, _ := this.GetInt64("id")
  1388. list, _ := service.GetWarehoseInfoById(id)
  1389. this.ServeSuccessJSON(map[string]interface{}{
  1390. "list": list,
  1391. })
  1392. }