gobal_config_api_controller.go 81KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "bytes"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/jinzhu/gorm"
  11. "io/ioutil"
  12. "log"
  13. "os"
  14. "path"
  15. "reflect"
  16. "regexp"
  17. "runtime"
  18. "strconv"
  19. "strings"
  20. "time"
  21. "github.com/astaxie/beego"
  22. )
  23. type GobalConfigApiController struct {
  24. BaseAuthAPIController
  25. }
  26. func GobalConfigRegistRouters() {
  27. beego.Router("/api/stock/automaticreduce/isopen", &GobalConfigApiController{}, "post:PostStockConfig")
  28. beego.Router("/api/drugstock/automaticreduce/isopen", &GobalConfigApiController{}, "post:PostDrugStockConfig")
  29. beego.Router("/api/automaticreduce/get", &GobalConfigApiController{}, "get:GetConfig")
  30. beego.Router("/api/drugstockautomaticreduce/get", &GobalConfigApiController{}, "get:GetDrugStockConfig")
  31. beego.Router("/api/print/template/commit", &GobalConfigApiController{}, "post:PostPrintTemplateTwo")
  32. beego.Router("/api/print/template/get", &GobalConfigApiController{}, "get:GetPrintTemplate")
  33. beego.Router("/api/dataupload/config/commit", &GobalConfigApiController{}, "post:PostConfig")
  34. beego.Router("/api/dataupload/config/modify", &GobalConfigApiController{}, "post:ModifyConfig")
  35. beego.Router("/api/dataupload/config/get", &GobalConfigApiController{}, "get:GetDataUploadConfig")
  36. beego.Router("/api/dataupload/is_docking/get", &GobalConfigApiController{}, "get:GetDataUploadIsDocking")
  37. beego.Router("/api/adviceconfig/isopen", &GobalConfigApiController{}, "post:PostDoctorAdviceConfig")
  38. beego.Router("/api/adviceconfig/get", &GobalConfigApiController{}, "get:GetDoctorAdviceConfig")
  39. beego.Router("/api/advicetemplate/init/commit", &GobalConfigApiController{}, "post:PostInitAdviceTemplate")
  40. beego.Router("/api/advicetemplate/init/get", &GobalConfigApiController{}, "get:GetAdviceInitConfig")
  41. beego.Router("/api/systemprescription/commit", &GobalConfigApiController{}, "post:CreateSystemPrescription")
  42. beego.Router("/api/systemprescription/update", &GobalConfigApiController{}, "post:UpdateSystemPrescription")
  43. beego.Router("/api/systemprescription/all", &GobalConfigApiController{}, "get:GetAllSystemPrescription")
  44. beego.Router("/api/systemprescription/get", &GobalConfigApiController{}, "get:GetSystemPrescription")
  45. beego.Router("/api/advicetemplate/getprintinfo", &GobalConfigApiController{}, "post:GetPrintInfo")
  46. beego.Router("/api/public/orgs", &GobalConfigApiController{}, "get:GetOrgs")
  47. beego.Router("/api/org/change", &GobalConfigApiController{}, "post:ChangeOrg")
  48. beego.Router("/api/log/generate", &GobalConfigApiController{}, "get:GenerateLog")
  49. beego.Router("/api/patients/search", &GobalConfigApiController{}, "Post:GetPatientsByKeyWord")
  50. beego.Router("/api/xtconfig/get", &GobalConfigApiController{}, "get:GetXTHisConfig")
  51. beego.Router("/api/xtconfig/isopen", &GobalConfigApiController{}, "post:PostXTHisConfig")
  52. beego.Router("/api/hisstockpriceconfig/get", &GobalConfigApiController{}, "get:GetHisStockPriceConfig")
  53. beego.Router("/api/hisstockpriceconfig/isopen", &GobalConfigApiController{}, "post:PostHisStockPriceConfig")
  54. beego.Router("/api/xtconfigproject/isopen", &GobalConfigApiController{}, "post:PostXTHisProjectConfig")
  55. beego.Router("/api/isopen/init", &GobalConfigApiController{}, "get:GetAllIsOpenConfig")
  56. beego.Router("/api/passdetail/export", &GobalConfigApiController{}, "get:GetPassExportData")
  57. beego.Router("/api/consumedetail/export", &GobalConfigApiController{}, "get:GetExportData")
  58. beego.Router("/api/drugstock/getdrugindetail", &GobalConfigApiController{}, "get:GetDrugInDetail")
  59. beego.Router("/api/drugstock/getdrugcancelorder", &GobalConfigApiController{}, "get:GetDrugCancelOrder")
  60. beego.Router("/api/drugstock/getdrugoutdetail", &GobalConfigApiController{}, "get:GetDrugOutDetail")
  61. beego.Router("/api/drugstock/getdrugcanceldetail", &GobalConfigApiController{}, "get:GetDrugCancelDetail")
  62. beego.Router("/api/monitor/open", &GobalConfigApiController{}, "get:AddMonitorOpen")
  63. beego.Router("/api/monitor/getmonitorconfig", &GobalConfigApiController{}, "Get:GetMonitorConfig")
  64. beego.Router("/api/order/addorderconfig", &GobalConfigApiController{}, "Get:AddOrderConfig")
  65. beego.Router("/api/order/getorderconfig", &GobalConfigApiController{}, "Get:GetOrderConfig")
  66. beego.Router("/api/drugstock/getdrugautomaticlist", &GobalConfigApiController{}, "Get:GetDrugAutoMaticList")
  67. beego.Router("/api/drugstock/getdrugwarehouseorderinfo", &GobalConfigApiController{}, "Get:GetDrugWarehuseOrderInfo")
  68. //新接口
  69. beego.Router("/api/drugstock/drugstocklist", &GobalConfigApiController{}, "Get:GetDrugStockList")
  70. beego.Router("/api/drugstock/getdrugstockflow", &GobalConfigApiController{}, "Get:GetDrugStockFllow")
  71. beego.Router("/api/drugoutstock/getoutdrugstockflow", &GobalConfigApiController{}, "Get:GetDrugOutStockFlow")
  72. beego.Router("/api/drug/getbatchorderdetail", &GobalConfigApiController{}, "Get:GetBatchOrderDetail")
  73. beego.Router("/api/drug/getdrugcountlist", &GobalConfigApiController{}, "Get:GetDrugCountList")
  74. beego.Router("/api/drug/getsingleorderdetail", &GobalConfigApiController{}, "Get:GetSingleOrderDetail")
  75. beego.Router("/api/drug/getautodrugdetial", &GobalConfigApiController{}, "Get:GetAutoDrugDetail")
  76. beego.Router("/api/drug/getdrugorderinprint", &GobalConfigApiController{}, "Get:GetDrugOrderInPrint")
  77. beego.Router("/api/drug/getdrugoutorderdetailprint", &GobalConfigApiController{}, "Get:GetDrugOutOrderPrint")
  78. beego.Router("/api/drug/getdrugbatchnumber", &GobalConfigApiController{}, "Get:GetDrugBatchNumber")
  79. beego.Router("/api/drug/exportdruglist", &GobalConfigApiController{}, "Get:ExportDrugList")
  80. beego.Router("/api/drug/getexportoutorderdruglist", &GobalConfigApiController{}, "Get:GetExportOutOrderDrugList")
  81. beego.Router("/api/drug/getdrugflow", &GobalConfigApiController{}, "Get:GetDrugFlow")
  82. beego.Router("/api/drug/getcancelstockdetail", &GobalConfigApiController{}, "Get:GetCancelStockDetail")
  83. beego.Router("/api/changestocksetting/isopen", &GobalConfigApiController{}, "Get:ChangeStockSetting")
  84. beego.Router("/api/changeadviceconfig", &GobalConfigApiController{}, "Get:ChangeAdviceConfig")
  85. beego.Router("/api/changeprescriptionconfig", &GobalConfigApiController{}, "Get:ChangePrescriptionConfig")
  86. beego.Router("/api/changedrugopenconfig", &GobalConfigApiController{}, "Get:ChangeDrugOpenConfig")
  87. beego.Router("/api/changesettleopenconfig", &GobalConfigApiController{}, "Get:ChangeSettleOpenConfig")
  88. beego.Router("/api/changegoodoutopen", &GobalConfigApiController{}, "Get:ChangeGoodOutOpen")
  89. }
  90. //provinces, _ := service.GetDistrictsByUpid(0)21
  91. func (c *GobalConfigApiController) PostStockConfig() {
  92. is_open, _ := c.GetInt64("is_open", 0)
  93. adminUserInfo := c.GetAdminUserInfo()
  94. org_id := adminUserInfo.CurrentOrgId
  95. config := models.GobalConfig{
  96. OrgId: org_id,
  97. IsOpen: is_open,
  98. Status: 1,
  99. CreateTime: time.Now().Unix(),
  100. UpdateTime: time.Now().Unix(),
  101. IsOpenRemind: 0,
  102. }
  103. errs, configs := service.FindAutomaticReduceRecordByOrgId(org_id)
  104. if errs == gorm.ErrRecordNotFound {
  105. err := service.CreateAutomaticReduceRecord(&config)
  106. if err != nil {
  107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  108. return
  109. }
  110. } else if errs == nil {
  111. modifyConfig := models.GobalConfig{
  112. ID: configs.ID,
  113. OrgId: org_id,
  114. IsOpen: is_open,
  115. Status: 1,
  116. CreateTime: time.Now().Unix(),
  117. UpdateTime: time.Now().Unix(),
  118. IsOpenRemind: configs.IsOpenRemind,
  119. }
  120. err := service.UpdateAutomaticReduceRecord(&modifyConfig)
  121. if err != nil {
  122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  123. return
  124. }
  125. }
  126. if is_open == 1 {
  127. service.UpdateGobalConfig(org_id)
  128. }
  129. c.ServeSuccessJSON(map[string]interface{}{
  130. "is_open": is_open,
  131. })
  132. return
  133. }
  134. func (c *GobalConfigApiController) PostDrugStockConfig() {
  135. is_open, _ := c.GetInt64("is_open", 0)
  136. adminUserInfo := c.GetAdminUserInfo()
  137. org_id := adminUserInfo.CurrentOrgId
  138. config := models.DrugStockConfig{
  139. OrgId: org_id,
  140. IsOpen: is_open,
  141. Status: 1,
  142. CreateTime: time.Now().Unix(),
  143. UpdateTime: time.Now().Unix(),
  144. }
  145. errs, configs := service.FindDrugStockAutomaticReduceRecordByOrgId(org_id)
  146. if is_open == 1 {
  147. service.UpdateSettleOpenConfigOne(org_id, 2)
  148. }
  149. if errs == gorm.ErrRecordNotFound {
  150. err := service.CreateDrugAutomaticReduceRecord(&config)
  151. if err != nil {
  152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  153. return
  154. }
  155. } else if errs == nil {
  156. modifyConfig := models.DrugStockConfig{
  157. ID: configs.ID,
  158. OrgId: org_id,
  159. IsOpen: is_open,
  160. Status: 1,
  161. CreateTime: time.Now().Unix(),
  162. UpdateTime: time.Now().Unix(),
  163. }
  164. err := service.UpdateDrugStockAutomaticReduceRecord(&modifyConfig)
  165. if err != nil {
  166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  167. return
  168. }
  169. }
  170. c.ServeSuccessJSON(map[string]interface{}{
  171. "is_open": is_open,
  172. })
  173. return
  174. }
  175. func (c *GobalConfigApiController) GetConfig() {
  176. adminUserInfo := c.GetAdminUserInfo()
  177. _, config := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  178. c.ServeSuccessJSON(map[string]interface{}{
  179. "config": config,
  180. })
  181. }
  182. func (c *GobalConfigApiController) GetDrugStockConfig() {
  183. adminUserInfo := c.GetAdminUserInfo()
  184. _, config := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  185. c.ServeSuccessJSON(map[string]interface{}{
  186. "config": config,
  187. })
  188. }
  189. func (c *GobalConfigApiController) PostPrintTemplate() {
  190. template_id, _ := c.GetInt64("template_id", 0)
  191. adminUserInfo := c.GetAdminUserInfo()
  192. org_id := adminUserInfo.CurrentOrgId
  193. template := models.GobalTemplate{
  194. OrgId: org_id,
  195. TemplateId: template_id,
  196. Status: 1,
  197. Ctime: time.Now().Unix(),
  198. Mtime: time.Now().Unix(),
  199. }
  200. errs, templates := service.FindPrintTemplateByOrgId(org_id)
  201. if errs == gorm.ErrRecordNotFound {
  202. err := service.CreatePrintTemplateRecord(&template)
  203. if err != nil {
  204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  205. return
  206. }
  207. } else if errs == nil {
  208. templates := models.GobalTemplate{
  209. ID: templates.ID,
  210. OrgId: org_id,
  211. TemplateId: template_id,
  212. Status: 1,
  213. Ctime: templates.Ctime,
  214. Mtime: time.Now().Unix(),
  215. }
  216. err := service.UpdatePrintTemplate(&templates)
  217. if err != nil {
  218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  219. return
  220. }
  221. }
  222. c.ServeSuccessJSON(map[string]interface{}{
  223. "template_id": template_id,
  224. })
  225. return
  226. }
  227. func (c *GobalConfigApiController) PostPrintTemplateTwo() {
  228. template_id, _ := c.GetInt64("template_id", 0)
  229. adminUserInfo := c.GetAdminUserInfo()
  230. org_id := adminUserInfo.CurrentOrgId
  231. template := models.GobalTemplate{
  232. OrgId: org_id,
  233. TemplateId: template_id,
  234. Status: 1,
  235. Ctime: time.Now().Unix(),
  236. Mtime: time.Now().Unix(),
  237. }
  238. errs, templates := service.FindPrintTemplateByOrgId(org_id)
  239. if errs == gorm.ErrRecordNotFound {
  240. err := service.CreatePrintTemplateRecord(&template)
  241. if err != nil {
  242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  243. return
  244. }
  245. if err == nil { //处理模版切换,显示配置处理逻辑
  246. //service.FindAllConfig
  247. //先将所有数据设置为显示
  248. updateErr := service.UpdateFiledConfig(adminUserInfo.CurrentOrgId)
  249. if updateErr == nil {
  250. //查出该模版对应显示配置字段中所有隐藏的字段
  251. _, config := service.FindAllHideFiledConfig(template_id)
  252. var fileds []string
  253. for _, item := range config {
  254. fileds = append(fileds, item.FiledName)
  255. }
  256. service.UpdateShowFieldConfig(adminUserInfo.CurrentOrgId, fileds)
  257. }
  258. }
  259. FiledList, _ := service.FindFiledByOrgId(adminUserInfo.CurrentOrgId)
  260. c.ServeSuccessJSON(map[string]interface{}{
  261. "template_id": template_id,
  262. "fileds": FiledList,
  263. })
  264. } else if errs == nil {
  265. templates := models.GobalTemplate{
  266. ID: templates.ID,
  267. OrgId: org_id,
  268. TemplateId: template_id,
  269. Status: 1,
  270. Ctime: templates.Ctime,
  271. Mtime: time.Now().Unix(),
  272. }
  273. err := service.UpdatePrintTemplate(&templates)
  274. if err != nil {
  275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  276. return
  277. }
  278. if err == nil { //处理模版切换,显示配置处理逻辑
  279. //service.FindAllConfig
  280. //先将所有数据设置为显示
  281. updateErr := service.UpdateFiledConfig(adminUserInfo.CurrentOrgId)
  282. if updateErr == nil {
  283. //查出该模版对应显示配置字段中所有隐藏的字段
  284. _, config := service.FindAllHideFiledConfig(template_id)
  285. var fileds []string
  286. for _, item := range config {
  287. fileds = append(fileds, item.FiledName)
  288. }
  289. service.UpdateShowFieldConfig(adminUserInfo.CurrentOrgId, fileds)
  290. }
  291. }
  292. FiledList, _ := service.FindFiledByOrgId(adminUserInfo.CurrentOrgId)
  293. c.ServeSuccessJSON(map[string]interface{}{
  294. "template_id": template_id,
  295. "fileds": FiledList,
  296. })
  297. return
  298. }
  299. }
  300. func (c *GobalConfigApiController) GetPrintTemplate() {
  301. adminUserInfo := c.GetAdminUserInfo()
  302. _, template := service.FindPrintTemplateByOrgId(adminUserInfo.CurrentOrgId)
  303. c.ServeSuccessJSON(map[string]interface{}{
  304. "template": template,
  305. })
  306. }
  307. func (c *GobalConfigApiController) PostConfig() {
  308. gateway_address := c.GetString("gateway_address")
  309. app_id := c.GetString("app_id")
  310. key := c.GetString("key")
  311. config_type, _ := c.GetInt64("config_type")
  312. time_type, _ := c.GetInt64("time_type")
  313. province, _ := c.GetInt64("province")
  314. city, _ := c.GetInt64("city")
  315. if config_type > 1 {
  316. _, err := service.GetDockingStatus(config_type, province, city)
  317. if err == gorm.ErrRecordNotFound {
  318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotDocking)
  319. return
  320. }
  321. }
  322. adminUserInfo := c.GetAdminUserInfo()
  323. org_id := adminUserInfo.CurrentOrgId
  324. config := &models.DataUploadConfig{
  325. OrgId: org_id,
  326. ProvinceId: province,
  327. CityId: city,
  328. GatewayAddress: gateway_address,
  329. AppId: app_id,
  330. Key: key,
  331. Status: 1,
  332. CreateTime: time.Now().Unix(),
  333. ModifyTime: time.Now().Unix(),
  334. TimeQuantum: time_type,
  335. ConfigType: config_type,
  336. }
  337. err := service.CreateConfigData(config)
  338. if err == nil {
  339. c.ServeSuccessJSON(map[string]interface{}{
  340. "config": config,
  341. })
  342. } else {
  343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  344. return
  345. }
  346. }
  347. func (c *GobalConfigApiController) GetDataUploadConfig() {
  348. config_type, _ := c.GetInt64("config_type")
  349. adminUserInfo := c.GetAdminUserInfo()
  350. org_id := adminUserInfo.CurrentOrgId
  351. config, err := service.GetConfigData(org_id, config_type)
  352. fmt.Println(err)
  353. if err == nil {
  354. c.ServeSuccessJSON(map[string]interface{}{
  355. "config": config,
  356. })
  357. } else {
  358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  359. return
  360. }
  361. }
  362. func (c *GobalConfigApiController) GetDataUploadIsDocking() {
  363. config_type, _ := c.GetInt64("config_type")
  364. province, _ := c.GetInt64("province")
  365. city, _ := c.GetInt64("city")
  366. config, err := service.GetDockingStatus(config_type, province, city)
  367. fmt.Println(config)
  368. fmt.Println(err)
  369. if err == gorm.ErrRecordNotFound {
  370. c.ServeSuccessJSON(map[string]interface{}{
  371. "is_docking": 2,
  372. })
  373. } else if err == nil {
  374. if config.ID > 0 {
  375. c.ServeSuccessJSON(map[string]interface{}{
  376. "is_docking": 1,
  377. })
  378. } else {
  379. c.ServeSuccessJSON(map[string]interface{}{
  380. "is_docking": 2,
  381. })
  382. }
  383. }
  384. }
  385. func (c *GobalConfigApiController) ModifyConfig() {
  386. id, _ := c.GetInt64("id")
  387. gateway_address := c.GetString("gateway_address")
  388. app_id := c.GetString("app_id")
  389. key := c.GetString("key")
  390. config_type, _ := c.GetInt64("config_type")
  391. time_type, _ := c.GetInt64("time_type")
  392. province, _ := c.GetInt64("province")
  393. city, _ := c.GetInt64("city")
  394. adminUserInfo := c.GetAdminUserInfo()
  395. org_id := adminUserInfo.CurrentOrgId
  396. if config_type > 1 {
  397. _, err := service.GetDockingStatus(config_type, province, city)
  398. if err == gorm.ErrRecordNotFound {
  399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotDocking)
  400. return
  401. }
  402. }
  403. tempConfig, _ := service.GetConfigDataById(id)
  404. config := &models.DataUploadConfig{
  405. ID: tempConfig.ID,
  406. OrgId: org_id,
  407. ProvinceId: province,
  408. CityId: city,
  409. GatewayAddress: gateway_address,
  410. AppId: app_id,
  411. Key: key,
  412. Status: 1,
  413. CreateTime: tempConfig.CreateTime,
  414. ModifyTime: time.Now().Unix(),
  415. TimeQuantum: time_type,
  416. ConfigType: config_type,
  417. }
  418. err := service.SaveConfigData(config)
  419. if err == nil {
  420. c.ServeSuccessJSON(map[string]interface{}{
  421. "config": config,
  422. })
  423. } else {
  424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  425. return
  426. }
  427. }
  428. func (c *GobalConfigApiController) PostDoctorAdviceConfig() {
  429. is_open_remind, _ := c.GetInt64("is_open_remind", 0)
  430. adminUserInfo := c.GetAdminUserInfo()
  431. org_id := adminUserInfo.CurrentOrgId
  432. config := models.DoctorAdviceConfig{
  433. UserOrgId: org_id,
  434. IsOpenRemind: is_open_remind,
  435. Status: 1,
  436. CreateTime: time.Now().Unix(),
  437. UpdateTime: time.Now().Unix(),
  438. }
  439. errs, configs := service.FindDoctorAdviceRecordByOrgId(org_id)
  440. if errs == gorm.ErrRecordNotFound {
  441. err := service.CreateDoctorAdviceRecord(&config)
  442. if err != nil {
  443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  444. return
  445. }
  446. } else if errs == nil {
  447. modifyConfig := models.DoctorAdviceConfig{
  448. ID: configs.ID,
  449. UserOrgId: org_id,
  450. Status: 1,
  451. CreateTime: time.Now().Unix(),
  452. UpdateTime: time.Now().Unix(),
  453. IsOpenRemind: is_open_remind,
  454. }
  455. err := service.UpdateDoctorAdviceRecord(&modifyConfig)
  456. if err != nil {
  457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  458. return
  459. }
  460. }
  461. c.ServeSuccessJSON(map[string]interface{}{
  462. "is_open_remind": is_open_remind,
  463. })
  464. return
  465. }
  466. func (c *GobalConfigApiController) GetDoctorAdviceConfig() {
  467. adminUserInfo := c.GetAdminUserInfo()
  468. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  469. c.ServeSuccessJSON(map[string]interface{}{
  470. "config": config,
  471. })
  472. }
  473. //SF6090214798525
  474. func (c *GobalConfigApiController) Load(filename string, v interface{}) {
  475. //ReadFile函数会读取文件的全部内容,并将结果以[]byte类型返回
  476. data, err := ioutil.ReadFile(filename)
  477. if err != nil {
  478. return
  479. }
  480. //读取的数据为json格式,需要进行解码
  481. err = json.Unmarshal(data, v)
  482. if err != nil {
  483. return
  484. }
  485. }
  486. type Config struct {
  487. Parent_template []*models.VMDoctorAdviceParentTemplate "json:parent_template"
  488. }
  489. func LoadConfig(dataFile string) *Config {
  490. var config Config
  491. _, filename, _, _ := runtime.Caller(1)
  492. datapath := path.Join(path.Dir(filename), dataFile)
  493. config_file, err := os.Open(datapath)
  494. if err != nil {
  495. emit("Failed to open config file '%s': %s\n", datapath, err)
  496. return &config
  497. }
  498. fi, _ := config_file.Stat()
  499. buffer := make([]byte, fi.Size())
  500. _, err = config_file.Read(buffer)
  501. buffer, err = StripComments(buffer) //去掉注释
  502. if err != nil {
  503. emit("Failed to strip comments from json: %s\n", err)
  504. return &config
  505. }
  506. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  507. err = json.Unmarshal(buffer, &config) //解析json格式数据
  508. if err != nil {
  509. emit("Failed unmarshalling json: %s\n", err)
  510. return &config
  511. }
  512. return &config
  513. }
  514. func StripComments(data []byte) ([]byte, error) {
  515. data = bytes.Replace(data, []byte("\r"), []byte(""), 0) // Windows
  516. lines := bytes.Split(data, []byte("\n")) //split to muli lines
  517. filtered := make([][]byte, 0)
  518. for _, line := range lines {
  519. match, err := regexp.Match(`^\s*#`, line)
  520. if err != nil {
  521. return nil, err
  522. }
  523. if !match {
  524. filtered = append(filtered, line)
  525. }
  526. }
  527. return bytes.Join(filtered, []byte("\n")), nil
  528. }
  529. func emit(msgfmt string, args ...interface{}) {
  530. log.Printf(msgfmt, args...)
  531. }
  532. func (c *GobalConfigApiController) GetAdviceInitConfig() {
  533. adminUserInfo := c.GetAdminUserInfo()
  534. advice_init, _ := service.FindAdviceInitConfig(adminUserInfo.CurrentOrgId)
  535. c.ServeSuccessJSON(map[string]interface{}{
  536. "advice_init": advice_init,
  537. })
  538. }
  539. func (c *GobalConfigApiController) PostInitAdviceTemplate() {
  540. is_init, _ := c.GetInt64("is_init")
  541. adminUserInfo := c.GetAdminUserInfo()
  542. adviceInit := &models.AdviceInit{
  543. UserOrgId: adminUserInfo.CurrentOrgId,
  544. CreateTime: time.Now().Unix(),
  545. UpdateTime: time.Now().Unix(),
  546. Status: 1,
  547. IsInit: is_init,
  548. }
  549. adviceParentTemplate := LoadConfig("./advice_template.json").Parent_template
  550. for _, item := range adviceParentTemplate {
  551. parentTemplate := &models.DoctorAdviceParentTemplate{
  552. OrgId: adminUserInfo.CurrentOrgId,
  553. Name: item.Name,
  554. Status: 1,
  555. CreatedTime: time.Now().Unix(),
  556. UpdatedTime: time.Now().Unix(),
  557. AdviceType: item.AdviceType,
  558. }
  559. createErr := service.CreateDoctorParentTemplate(parentTemplate)
  560. fmt.Println(parentTemplate.ID)
  561. if createErr == nil {
  562. for _, adviceTemplateItem := range item.DoctorAdviceTemplate {
  563. adviceTeplate := &models.DoctorAdviceTemplate{
  564. OrgId: adminUserInfo.CurrentOrgId,
  565. AdviceName: adviceTemplateItem.AdviceName,
  566. AdviceDesc: adviceTemplateItem.AdviceDesc,
  567. SingleDose: adviceTemplateItem.SingleDose,
  568. SingleDoseUnit: adviceTemplateItem.SingleDoseUnit,
  569. PrescribingNumber: adviceTemplateItem.PrescribingNumber,
  570. PrescribingNumberUnit: adviceTemplateItem.PrescribingNumberUnit,
  571. DeliveryWay: adviceTemplateItem.DeliveryWay,
  572. ExecutionFrequency: adviceTemplateItem.ExecutionFrequency,
  573. AdviceDoctor: adviceTemplateItem.AdviceDoctor,
  574. Status: 1,
  575. CreatedTime: time.Now().Unix(),
  576. UpdatedTime: time.Now().Unix(),
  577. TemplateId: parentTemplate.ID,
  578. DrugSpec: adviceTemplateItem.DrugSpec,
  579. DrugSpecUnit: adviceTemplateItem.DrugSpecUnit,
  580. ParentId: adviceTemplateItem.ParentId,
  581. AdviceType: adviceTemplateItem.AdviceType,
  582. DayCount: adviceTemplateItem.DayCount,
  583. WeekDays: adviceTemplateItem.WeekDays,
  584. FrequencyType: adviceTemplateItem.FrequencyType,
  585. }
  586. createErr := service.CreateDoctorTemplate(adviceTeplate)
  587. if createErr == nil {
  588. for _, childItem := range adviceTemplateItem.SubDoctorAdviceTemplate {
  589. adviceTeplate := &models.DoctorAdviceTemplate{
  590. OrgId: adminUserInfo.CurrentOrgId,
  591. AdviceName: childItem.AdviceName,
  592. AdviceDesc: childItem.AdviceDesc,
  593. SingleDose: childItem.SingleDose,
  594. SingleDoseUnit: childItem.SingleDoseUnit,
  595. PrescribingNumber: childItem.PrescribingNumber,
  596. PrescribingNumberUnit: childItem.PrescribingNumberUnit,
  597. DeliveryWay: childItem.DeliveryWay,
  598. ExecutionFrequency: childItem.ExecutionFrequency,
  599. AdviceDoctor: childItem.AdviceDoctor,
  600. Status: 1,
  601. CreatedTime: time.Now().Unix(),
  602. UpdatedTime: time.Now().Unix(),
  603. TemplateId: parentTemplate.ID,
  604. DrugSpec: childItem.DrugSpec,
  605. DrugSpecUnit: childItem.DrugSpecUnit,
  606. ParentId: adviceTeplate.ID,
  607. AdviceType: childItem.AdviceType,
  608. DayCount: childItem.DayCount,
  609. WeekDays: childItem.WeekDays,
  610. FrequencyType: childItem.FrequencyType,
  611. }
  612. service.CreateDoctorTemplate(adviceTeplate)
  613. }
  614. }
  615. }
  616. }
  617. }
  618. err := service.CreateAdviceInitConfig(adviceInit)
  619. if err == nil {
  620. c.ServeSuccessJSON(map[string]interface{}{
  621. "init_config": adviceInit,
  622. })
  623. } else {
  624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  625. return
  626. }
  627. }
  628. func (c *GobalConfigApiController) CreateSystemPrescription() {
  629. adminUserInfo := c.GetAdminUserInfo()
  630. var solution models.SystemPrescription
  631. code := defaultSystemSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  632. if code > 0 {
  633. c.ServeFailJSONWithSGJErrorCode(code)
  634. return
  635. }
  636. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  637. solution.Doctor = adminUserInfo.AdminUser.Id
  638. solution.Status = 1
  639. solution.CreatedTime = time.Now().Unix()
  640. solution.UserOrgId = adminUserInfo.CurrentOrgId
  641. solution.UpdatedTime = time.Now().Unix()
  642. err := service.CreateSystemDialysisSolution(&solution)
  643. if err != nil {
  644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  645. return
  646. }
  647. prescriptions, _ := service.FindAllSystemPrescription(adminUserInfo.CurrentOrgId)
  648. c.ServeSuccessJSON(map[string]interface{}{
  649. "prescription": solution,
  650. "prescriptions": prescriptions,
  651. })
  652. return
  653. }
  654. func (c *GobalConfigApiController) UpdateSystemPrescription() {
  655. id, _ := c.GetInt64("id", 0)
  656. if id <= 0 {
  657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  658. return
  659. }
  660. adminUserInfo := c.GetAdminUserInfo()
  661. solution, _ := service.FindSystemDialysisSolution(adminUserInfo.CurrentOrgId, id)
  662. if solution.ID == 0 {
  663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  664. return
  665. }
  666. code := defaultSystemSolutionFormData(&solution, c.Ctx.Input.RequestBody, "edit")
  667. if code > 0 {
  668. c.ServeFailJSONWithSGJErrorCode(code)
  669. return
  670. }
  671. solution.UpdatedTime = time.Now().Unix()
  672. solution.Doctor = adminUserInfo.AdminUser.Id
  673. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  674. err := service.UpdateSystemDialysisSolution(&solution)
  675. if err != nil {
  676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  677. return
  678. }
  679. c.ServeSuccessJSON(map[string]interface{}{
  680. "msg": "ok",
  681. "prescription": solution,
  682. })
  683. return
  684. }
  685. func (c *GobalConfigApiController) GetAllSystemPrescription() {
  686. adminUserInfo := c.GetAdminUserInfo()
  687. prescriptions, _ := service.FindAllSystemPrescription(adminUserInfo.CurrentOrgId)
  688. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  689. c.ServeSuccessJSON(map[string]interface{}{
  690. "prescriptions": prescriptions,
  691. "stockType": stockType,
  692. })
  693. }
  694. func (c *GobalConfigApiController) GetSystemPrescription() {
  695. adminUserInfo := c.GetAdminUserInfo()
  696. id, _ := c.GetInt64("id", 0)
  697. prescription, _ := service.FindSystemDialysisPrescriptionByMode(adminUserInfo.CurrentOrgId, id)
  698. c.ServeSuccessJSON(map[string]interface{}{
  699. "prescription": prescription,
  700. })
  701. }
  702. func defaultSystemSolutionFormData(solution *models.SystemPrescription, data []byte, method string) (code int) {
  703. dataBody := make(map[string]interface{}, 0)
  704. err := json.Unmarshal(data, &dataBody)
  705. utils.InfoLog(string(data))
  706. if err != nil {
  707. utils.ErrorLog(err.Error())
  708. code = enums.ErrorCodeParamWrong
  709. return
  710. }
  711. if method == "create" {
  712. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  713. utils.ErrorLog("mode")
  714. code = enums.ErrorCodeParamWrong
  715. return
  716. }
  717. mode := int64(dataBody["mode"].(float64))
  718. if mode <= 0 {
  719. utils.ErrorLog("mode <= 0")
  720. code = enums.ErrorCodeParamWrong
  721. return
  722. }
  723. solution.ModeId = mode
  724. }
  725. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  726. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  727. solution.DialysisDuration = dialysisDuration
  728. }
  729. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  730. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  731. solution.TargetUltrafiltration = targetUltrafiltration
  732. }
  733. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  734. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  735. solution.DialysateFormulation = dialysateFormulation
  736. }
  737. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  738. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  739. solution.DialysisDurationHour = int64(dialysisDurationHour)
  740. }
  741. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  742. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  743. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  744. }
  745. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  746. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  747. solution.HemodialysisMachine = hemodialysisMachine
  748. }
  749. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  750. dialyzer := int64(dataBody["dialyzer"].(float64))
  751. solution.Dialyzer = dialyzer
  752. }
  753. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  754. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  755. solution.PerfusionApparatus = perfusionApparatus
  756. }
  757. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  758. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  759. solution.BloodFlowVolume = bloodFlowVolume
  760. }
  761. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  762. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  763. solution.Dewater = dewater
  764. }
  765. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  766. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  767. solution.DisplaceLiqui = displaceLiqui
  768. }
  769. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  770. replacementWay := int64(dataBody["replacement_way"].(float64))
  771. solution.ReplacementWay = replacementWay
  772. }
  773. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  774. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  775. solution.Anticoagulant = anticoagulant
  776. }
  777. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  778. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  779. solution.AnticoagulantShouji = anticoagulantShouji
  780. }
  781. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  782. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  783. solution.AnticoagulantWeichi = anticoagulantWeichi
  784. }
  785. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  786. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  787. solution.AnticoagulantZongliang = anticoagulantZongliang
  788. }
  789. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  790. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  791. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  792. }
  793. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  794. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  795. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  796. }
  797. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  798. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  799. solution.Kalium = kalium
  800. }
  801. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  802. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  803. solution.Sodium = sodium
  804. }
  805. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  806. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  807. solution.Calcium = calcium
  808. }
  809. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  810. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  811. solution.Bicarbonate = bicarbonate
  812. }
  813. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  814. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  815. solution.Glucose = glucose
  816. }
  817. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  818. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  819. // solution.DryWeight = dryWeight
  820. // }
  821. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  822. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  823. solution.DialysateFlow = dialysateFlow
  824. }
  825. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  826. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  827. solution.DialysateTemperature = dialysateTemperature
  828. }
  829. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  830. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  831. solution.Conductivity = conductivity
  832. }
  833. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  834. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  835. solution.ReplacementTotal = replacementTotal
  836. }
  837. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  838. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  839. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  840. }
  841. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  842. body_fluid := int64(dataBody["body_fluid"].(float64))
  843. solution.BodyFluid = body_fluid
  844. }
  845. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  846. body_fluid_other := dataBody["body_fluid_other"].(string)
  847. solution.BodyFluidOther = body_fluid_other
  848. }
  849. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  850. special_medicine := int64(dataBody["special_medicine"].(float64))
  851. solution.SpecialMedicine = special_medicine
  852. }
  853. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  854. special_medicine_other := dataBody["special_medicine_other"].(string)
  855. solution.SpecialMedicineOther = special_medicine_other
  856. }
  857. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  858. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  859. solution.DisplaceLiquiPart = displace_liqui_part
  860. }
  861. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  862. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  863. solution.DisplaceLiquiValue = displace_liqui_value
  864. }
  865. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  866. blood_access := int64(dataBody["blood_access"].(float64))
  867. solution.BloodAccess = blood_access
  868. }
  869. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  870. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  871. solution.Ultrafiltration = ultrafiltration
  872. }
  873. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  874. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  875. solution.TargetKtv = target_ktv
  876. }
  877. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  878. remark := dataBody["remark"].(string)
  879. solution.Remark = remark
  880. }
  881. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  882. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  883. fmt.Println("dialysisDialysis22222222222", dialysisDialyszers)
  884. solution.DialysisDialyszers = dialysisDialyszers
  885. }
  886. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  887. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  888. solution.DialysisIrrigation = dialysisIrrigation
  889. }
  890. return
  891. }
  892. func (c *GobalConfigApiController) GetPrintInfo() {
  893. adminUserInfo := c.GetAdminUserInfo()
  894. OrgID := adminUserInfo.CurrentOrgId
  895. dataBody := make(map[string]interface{}, 0)
  896. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  897. idsInters := dataBody["ids"].([]interface{})
  898. advice_type, _ := c.GetInt64("advice_type")
  899. stop_type, _ := c.GetInt64("stop_type")
  900. fmt.Println("advcie_type23323232322332", advice_type)
  901. fmt.Println("stop_type33332323223232323", stop_type)
  902. if len(idsInters) == 0 {
  903. if err != nil {
  904. c.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  905. return
  906. }
  907. }
  908. ids := make([]int64, 0)
  909. for _, idsInter := range idsInters {
  910. id := int64(idsInter.(float64))
  911. ids = append(ids, id)
  912. }
  913. getPrint, err := service.GetPrint(ids, OrgID, advice_type, stop_type)
  914. c.ServeSuccessJSON(map[string]interface{}{
  915. "doctoradvice": getPrint,
  916. })
  917. }
  918. func (c *GobalConfigApiController) GetOrgs() {
  919. adminUserInfo := c.GetAdminUserInfo()
  920. //获取当前人姓名
  921. var id = adminUserInfo.AdminUser.Id
  922. orgId := adminUserInfo.CurrentOrgId
  923. var orgs []*models.Org
  924. adminUser, err := service.GetHomeData(adminUserInfo.AdminUser.Id)
  925. creator, err := service.GetCreator(id, orgId)
  926. admin, err := service.GetSuperAdmin(id)
  927. if err != nil {
  928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  929. return
  930. }
  931. for _, item := range adminUser.Org {
  932. orgs = append(orgs, item)
  933. }
  934. for _, item := range adminUser.VMApp_Role {
  935. for _, subItem := range item.Org {
  936. orgs = append(orgs, subItem)
  937. }
  938. }
  939. orgs = RemoveRepeatedOrgElement(orgs)
  940. fmt.Println("~~~~")
  941. role, _ := service.GetAdminUserInfoByID(orgId, id)
  942. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  943. c.ServeSuccessJSON(map[string]interface{}{
  944. "orgs": orgs,
  945. "adminUser": adminUser,
  946. "creator": creator,
  947. "admin": admin,
  948. "role": role,
  949. "org_config": miConfig,
  950. })
  951. }
  952. func (this *GobalConfigApiController) ChangeOrg() {
  953. org_id, _ := this.GetInt64("org_id")
  954. adminUserInfo := this.GetAdminUserInfo()
  955. tempOrg, err := service.GetOrgById(org_id)
  956. if err != nil {
  957. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  958. return
  959. }
  960. if tempOrg == nil {
  961. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrgNoExist)
  962. return
  963. }
  964. mobile := adminUserInfo.AdminUser.Mobile
  965. // 只取最近被创建的 admin_role
  966. adminUser, getAdminErr := service.GetValidAdminUserByMobileReturnErr(mobile) //账号信息唯一值
  967. if getAdminErr != nil {
  968. utils.ErrorLog("获取管理员失败:%v", getAdminErr)
  969. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  970. this.ServeJSON()
  971. return
  972. } else if adminUser == nil {
  973. utils.ErrorLog("查找不到 mobile = %v 的用户", mobile)
  974. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
  975. this.ServeJSON()
  976. return
  977. } else {
  978. adminUserInfo.CurrentOrgId = tempOrg.Id
  979. orgApp, _ := service.GetOrgApp(tempOrg.Id, 3)
  980. subscibe, _ := service.GetOrgSubscibe(tempOrg.Id)
  981. adminUserInfo.CurrentAppId = orgApp.Id
  982. appRole, _ := service.GetAppRole(tempOrg.Id, orgApp.Id, adminUserInfo.AdminUser.Id)
  983. var FiledList []*models.FiledConfig
  984. FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
  985. if len(FiledList) == 0 {
  986. err := service.BatchInsertFiledConfig(tempOrg.Id)
  987. if err == nil {
  988. FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
  989. } else {
  990. utils.ErrorLog("字段批量插入失败:%v", err)
  991. }
  992. }
  993. //产寻该机构是否有收缩压和舒张压
  994. pressure, err := service.GetDefaultSystolicPressure(tempOrg.Id)
  995. fmt.Println(err)
  996. if len(pressure) == 0 {
  997. err = service.BathInsertQualityControlTwo(tempOrg.Id)
  998. } else {
  999. utils.ErrorLog("字段批量插入失败:%v", err)
  1000. }
  1001. major, err := service.GetInspectionMajor(tempOrg.Id)
  1002. if len(major) == 0 {
  1003. QualityeList, err := service.FindQualityByOrgId(tempOrg.Id)
  1004. if len(QualityeList) == 0 {
  1005. err = service.BatchInsertQualityControl(tempOrg.Id)
  1006. } else {
  1007. utils.ErrorLog("字段批量插入失败:%v", err)
  1008. }
  1009. InspectionList, err := service.FindeInspectionByOrgId(tempOrg.Id)
  1010. if len(InspectionList) == 0 {
  1011. err = service.BatchInspectionConfiguration(tempOrg.Id)
  1012. } else {
  1013. utils.ErrorLog("字段批量插入失败:%v", err)
  1014. }
  1015. } else {
  1016. utils.ErrorLog("字段批量插入失败:%v", err)
  1017. }
  1018. //查询该机构是否存在医护排班
  1019. _, errcode := service.GetDoctorScheduleByOrgId(tempOrg.Id)
  1020. //如果没有就插入
  1021. if errcode == gorm.ErrRecordNotFound {
  1022. err = service.BatchInsertDoctorSchedule(tempOrg.Id)
  1023. } else {
  1024. utils.ErrorLog("医护排班默认数据插入失败:%v", err)
  1025. }
  1026. var didRegistedForSCRM bool = false
  1027. var didRegistedForCDM bool = false
  1028. var didRegistedForMall bool = false
  1029. var curAppUrlfors []string
  1030. var pruviews []*models.Purview
  1031. if len(curAppUrlfors) == 0 {
  1032. if adminUser.Id == tempOrg.Creator {
  1033. urlfors_xt, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(3)
  1034. urlfors_cdm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(4)
  1035. urlfors_scrm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(6)
  1036. urlfors_mall, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(7)
  1037. curAppUrlfors = append(curAppUrlfors, urlfors_xt...)
  1038. curAppUrlfors = append(curAppUrlfors, urlfors_scrm...)
  1039. curAppUrlfors = append(curAppUrlfors, urlfors_cdm...)
  1040. curAppUrlfors = append(curAppUrlfors, urlfors_mall...)
  1041. didRegistedForSCRM = true
  1042. didRegistedForCDM = true
  1043. didRegistedForMall = true
  1044. } else {
  1045. appRole, _ := service.FindAdminUserIDA(appRole.Id)
  1046. if appRole.Id > 0 && len(appRole.RoleIds) > 0 {
  1047. role_arr := strings.Split(appRole.RoleIds, ",")
  1048. var ids string
  1049. for _, role_id := range role_arr {
  1050. id, _ := strconv.ParseInt(role_id, 10, 64)
  1051. purview_ids, _ := service.GetRolePurviewIds(id)
  1052. if len(ids) == 0 {
  1053. ids = purview_ids
  1054. } else {
  1055. ids = ids + "," + purview_ids
  1056. }
  1057. }
  1058. if len(ids) != 0 {
  1059. pruviews, _ = service.GetPurviewById(ids)
  1060. for _, item := range pruviews {
  1061. if item.Module == 3 && item.Parentid > 0 {
  1062. fmt.Println(item.Urlfor)
  1063. curAppUrlfors = append(curAppUrlfors, item.Urlfor)
  1064. }
  1065. }
  1066. } else {
  1067. curAppUrlfors = append(curAppUrlfors, "")
  1068. }
  1069. } else {
  1070. curAppUrlfors = append(curAppUrlfors, "")
  1071. }
  1072. for _, item := range pruviews {
  1073. if item.Module == 6 {
  1074. didRegistedForSCRM = true
  1075. }
  1076. if item.Module == 4 {
  1077. didRegistedForCDM = true
  1078. }
  1079. if item.Module == 7 {
  1080. didRegistedForMall = true
  1081. }
  1082. }
  1083. }
  1084. }
  1085. userInfo := map[string]interface{}{
  1086. "id": adminUser.Id,
  1087. "mobile": adminUser.Mobile,
  1088. "user_name": appRole.UserName,
  1089. "avatar": appRole.Avatar,
  1090. "intro": appRole.Intro,
  1091. "user_type": appRole.UserType,
  1092. "user_title": appRole.UserTitle,
  1093. }
  1094. org := map[string]interface{}{
  1095. "id": tempOrg.Id,
  1096. "org_name": tempOrg.OrgName,
  1097. "org_short_name": tempOrg.OrgShortName,
  1098. "org_intro": tempOrg.OrgIntroduction,
  1099. "org_logo": tempOrg.OrgLogo,
  1100. "province": tempOrg.Province,
  1101. "city": tempOrg.City,
  1102. "district": tempOrg.District,
  1103. "address": tempOrg.Address,
  1104. }
  1105. tempInfo, _ := service.GetOrgInfoTemplate(tempOrg.Id)
  1106. template_info := map[string]interface{}{
  1107. "id": tempInfo.ID,
  1108. "org_id": tempInfo.OrgId,
  1109. "template_id": tempInfo.TemplateId,
  1110. }
  1111. if tempOrg != nil && appRole != nil {
  1112. // 插入一条登录记录
  1113. ip := this.GetString("ip")
  1114. loginLog := &models.AdminUserLoginLog{
  1115. AdminUserId: adminUser.Id,
  1116. OrgId: tempOrg.Id,
  1117. AppId: appRole.AppId,
  1118. IP: ip,
  1119. OperateType: 3,
  1120. AppType: 3,
  1121. CreateTime: time.Now().Unix(),
  1122. }
  1123. if insertErr := service.InsertLoginLog(loginLog); insertErr != nil {
  1124. utils.ErrorLog("为手机号为%v的用户插入一条登录记录失败:%v", mobile, insertErr)
  1125. }
  1126. }
  1127. this.SetSession("admin_user_info", adminUserInfo)
  1128. this.ServeSuccessJSON(map[string]interface{}{
  1129. "user": userInfo,
  1130. "org": org,
  1131. "urlfors": curAppUrlfors,
  1132. "current_org_id": adminUserInfo.CurrentOrgId,
  1133. "current_app_id": adminUserInfo.CurrentAppId,
  1134. "subscibe": subscibe,
  1135. "template_info": template_info,
  1136. "fileds": FiledList,
  1137. "scrm_role_exist": didRegistedForSCRM,
  1138. "cdm_role_exist": didRegistedForCDM,
  1139. "mall_role_exist": didRegistedForMall,
  1140. })
  1141. }
  1142. }
  1143. func RemoveRepeatedOrgElement(orgs []*models.Org) (newOrgs []*models.Org) {
  1144. newOrgs = make([]*models.Org, 0)
  1145. for i := 0; i < len(orgs); i++ {
  1146. repeat := false
  1147. for j := i + 1; j < len(orgs); j++ {
  1148. if orgs[i].Id == orgs[j].Id {
  1149. repeat = true
  1150. break
  1151. }
  1152. }
  1153. if !repeat {
  1154. newOrgs = append(newOrgs, orgs[i])
  1155. }
  1156. }
  1157. return
  1158. }
  1159. func (this *GobalConfigApiController) GenerateLog() {
  1160. log_type, _ := this.GetInt64("log_type", 0)
  1161. logs, err := service.GetExportLogByType(this.GetAdminUserInfo().CurrentOrgId, log_type)
  1162. if err != nil {
  1163. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1164. return
  1165. }
  1166. this.ServeSuccessJSON(map[string]interface{}{
  1167. "logs": logs,
  1168. })
  1169. }
  1170. func (this *GobalConfigApiController) GetPatientsByKeyWord() {
  1171. keyWord := this.GetString("keyword")
  1172. adminUserInfo := this.GetAdminUserInfo()
  1173. patient, err := service.GetPatientsByKey(adminUserInfo.CurrentOrgId, keyWord)
  1174. if err != nil {
  1175. utils.ErrorLog(err.Error())
  1176. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1177. return
  1178. }
  1179. this.ServeSuccessJSON(map[string]interface{}{
  1180. "patient": patient,
  1181. })
  1182. }
  1183. func (c *GobalConfigApiController) PostXTHisConfig() {
  1184. is_open, _ := c.GetBool("is_open", false)
  1185. adminUserInfo := c.GetAdminUserInfo()
  1186. org_id := adminUserInfo.CurrentOrgId
  1187. isOpen := 0
  1188. if is_open {
  1189. isOpen = 1
  1190. } else {
  1191. isOpen = 2
  1192. }
  1193. config := models.XtHisConfig{
  1194. UserOrgId: org_id,
  1195. IsOpen: int64(isOpen),
  1196. Status: 1,
  1197. Ctime: time.Now().Unix(),
  1198. Mtime: time.Now().Unix(),
  1199. }
  1200. errs, configs := service.FindXTHisRecordByOrgId(org_id)
  1201. if errs == gorm.ErrRecordNotFound {
  1202. err := service.CreateXTHisRecord(&config)
  1203. if err != nil {
  1204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1205. return
  1206. }
  1207. } else if errs == nil {
  1208. modifyConfig := models.XtHisConfig{
  1209. ID: configs.ID,
  1210. UserOrgId: org_id,
  1211. Status: 1,
  1212. Ctime: time.Now().Unix(),
  1213. Mtime: time.Now().Unix(),
  1214. IsOpen: int64(isOpen),
  1215. }
  1216. err := service.UpdateXTHisRecord(&modifyConfig)
  1217. redis := service.RedisClient()
  1218. defer redis.Close()
  1219. key := strconv.FormatInt(org_id, 10) + ":" + ":his_config"
  1220. redis.Set(key, "", time.Second)
  1221. if err != nil {
  1222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1223. return
  1224. }
  1225. }
  1226. c.ServeSuccessJSON(map[string]interface{}{
  1227. "is_open": is_open,
  1228. })
  1229. return
  1230. }
  1231. func (c *GobalConfigApiController) PostHisStockPriceConfig() {
  1232. is_open, _ := c.GetBool("is_open", false)
  1233. adminUserInfo := c.GetAdminUserInfo()
  1234. org_id := adminUserInfo.CurrentOrgId
  1235. isOpen := 0
  1236. if is_open {
  1237. isOpen = 1
  1238. } else {
  1239. isOpen = 2
  1240. }
  1241. config := models.HisStockPriceConfig{
  1242. UserOrgId: org_id,
  1243. IsOpen: int64(isOpen),
  1244. Status: 1,
  1245. Ctime: time.Now().Unix(),
  1246. Mtime: time.Now().Unix(),
  1247. }
  1248. errs, configs := service.FindHisStockPriceRecordByOrgId(org_id)
  1249. if errs == gorm.ErrRecordNotFound {
  1250. err := service.CreateHisStockPriceRecord(&config)
  1251. if err != nil {
  1252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1253. return
  1254. }
  1255. } else if errs == nil {
  1256. modifyConfig := models.HisStockPriceConfig{
  1257. ID: configs.ID,
  1258. UserOrgId: org_id,
  1259. Status: 1,
  1260. Ctime: time.Now().Unix(),
  1261. Mtime: time.Now().Unix(),
  1262. IsOpen: int64(isOpen),
  1263. }
  1264. err := service.UpdateHisStockPriceRecord(&modifyConfig)
  1265. if err != nil {
  1266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1267. return
  1268. }
  1269. }
  1270. c.ServeSuccessJSON(map[string]interface{}{
  1271. "is_open": is_open,
  1272. })
  1273. return
  1274. }
  1275. func (c *GobalConfigApiController) PostXTHisProjectConfig() {
  1276. is_open, _ := c.GetBool("is_open", false)
  1277. adminUserInfo := c.GetAdminUserInfo()
  1278. org_id := adminUserInfo.CurrentOrgId
  1279. isOpen := 0
  1280. if is_open {
  1281. isOpen = 1
  1282. } else {
  1283. isOpen = 2
  1284. }
  1285. config := models.XtHisProjectConfig{
  1286. UserOrgId: org_id,
  1287. IsOpen: int64(isOpen),
  1288. Status: 1,
  1289. Ctime: time.Now().Unix(),
  1290. Mtime: time.Now().Unix(),
  1291. }
  1292. errs, configs := service.FindXTHisProjectByOrgId(org_id)
  1293. if errs == gorm.ErrRecordNotFound {
  1294. err := service.CreateXTHisProjectRecord(&config)
  1295. redis := service.RedisClient()
  1296. key := strconv.FormatInt(org_id, 10) + ":his_project_config"
  1297. redis.Set(key, "", time.Second)
  1298. defer redis.Close()
  1299. if err != nil {
  1300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1301. return
  1302. }
  1303. } else if errs == nil {
  1304. modifyConfig := models.XtHisProjectConfig{
  1305. ID: configs.ID,
  1306. UserOrgId: org_id,
  1307. Status: 1,
  1308. Ctime: time.Now().Unix(),
  1309. Mtime: time.Now().Unix(),
  1310. IsOpen: int64(isOpen),
  1311. }
  1312. err := service.UpdateXTHisProjectRecord(&modifyConfig)
  1313. if err != nil {
  1314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1315. return
  1316. }
  1317. }
  1318. c.ServeSuccessJSON(map[string]interface{}{
  1319. "is_open": is_open,
  1320. })
  1321. return
  1322. }
  1323. func (c *GobalConfigApiController) GetXTHisConfig() {
  1324. adminUserInfo := c.GetAdminUserInfo()
  1325. _, config := service.FindXTHisRecordByOrgId(adminUserInfo.CurrentOrgId)
  1326. _, project_config := service.FindXTHisProjectByOrgId(adminUserInfo.CurrentOrgId)
  1327. c.ServeSuccessJSON(map[string]interface{}{
  1328. "config": config,
  1329. "project_config": project_config,
  1330. })
  1331. }
  1332. func (c *GobalConfigApiController) GetHisStockPriceConfig() {
  1333. adminUserInfo := c.GetAdminUserInfo()
  1334. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1335. c.ServeSuccessJSON(map[string]interface{}{
  1336. "config": config,
  1337. })
  1338. }
  1339. func (c *GobalConfigApiController) GetAllIsOpenConfig() {
  1340. adminUserInfo := c.GetAdminUserInfo()
  1341. _, config := service.FindXTHisRecordByOrgId(adminUserInfo.CurrentOrgId)
  1342. _, project_config := service.FindXTHisProjectByOrgIdOne(adminUserInfo.CurrentOrgId)
  1343. stockSetting, _ := service.FindStockSettingById(adminUserInfo.CurrentOrgId)
  1344. adviceSetting, _ := service.FindAdviceSettingById(adminUserInfo.CurrentOrgId)
  1345. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminUserInfo.CurrentOrgId)
  1346. drugOutConfig, _ := service.FindDrugOutConfigById(adminUserInfo.CurrentOrgId)
  1347. drugSettleConfig, _ := service.FindeDrugSettleConfigById(adminUserInfo.CurrentOrgId)
  1348. goodOutConfig, _ := service.FindGoodOutConfigById(adminUserInfo.CurrentOrgId)
  1349. c.ServeSuccessJSON(map[string]interface{}{
  1350. "is_open_xt_his": config.IsOpen,
  1351. "is_open_xt_his_project": project_config.IsOpen,
  1352. "is_open_stock": stockSetting.IsType,
  1353. "is_open_advice": adviceSetting.IsAdviceOpen,
  1354. "is_prescription_advice": prescriptionConfig.IsOpen,
  1355. "is_open": drugOutConfig.IsOpen,
  1356. "is_seetle_open": drugSettleConfig.IsOpen,
  1357. "is_out_open": goodOutConfig.IsOpen,
  1358. })
  1359. }
  1360. func (c *GobalConfigApiController) GetPassExportData() {
  1361. }
  1362. func (c *GobalConfigApiController) GetExportData() {
  1363. start_time := c.GetString("start_time")
  1364. end_time := c.GetString("end_time")
  1365. p_type, _ := c.GetInt64("p_type")
  1366. timeLayout := "2006-01-02"
  1367. loc, _ := time.LoadLocation("Local")
  1368. var startTime int64
  1369. if len(start_time) > 0 {
  1370. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1371. if err != nil {
  1372. fmt.Println(err)
  1373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1374. return
  1375. }
  1376. startTime = theTime.Unix()
  1377. }
  1378. var endTime int64
  1379. if len(end_time) > 0 {
  1380. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1381. if err != nil {
  1382. utils.ErrorLog(err.Error())
  1383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1384. return
  1385. }
  1386. endTime = theTime.Unix()
  1387. }
  1388. adminInfo := c.GetAdminUserInfo()
  1389. order, _ := service.GetExportHisOrderList(adminInfo.CurrentOrgId, startTime, endTime, p_type)
  1390. c.ServeSuccessJSON(map[string]interface{}{
  1391. "order": order,
  1392. })
  1393. }
  1394. func (c *GobalConfigApiController) GetDrugInDetail() {
  1395. start_time := c.GetString("start_time")
  1396. end_time := c.GetString("end_time")
  1397. storehouse_id, _ := c.GetInt64("storehouse_id")
  1398. timeLayout := "2006-01-02"
  1399. loc, _ := time.LoadLocation("Local")
  1400. var startTime int64
  1401. if len(start_time) > 0 {
  1402. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1403. if err != nil {
  1404. fmt.Println(err)
  1405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1406. return
  1407. }
  1408. startTime = theTime.Unix()
  1409. }
  1410. var endTime int64
  1411. if len(end_time) > 0 {
  1412. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1413. if err != nil {
  1414. utils.ErrorLog(err.Error())
  1415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1416. return
  1417. }
  1418. endTime = theTime.Unix()
  1419. }
  1420. adminInfo := c.GetAdminUserInfo()
  1421. order_type, _ := c.GetInt64("order_type")
  1422. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1423. keyword := c.GetString("keyword")
  1424. page, _ := c.GetInt64("page")
  1425. limit, _ := c.GetInt64("limit")
  1426. detail, total, err := service.GetDrugInOrderDetail(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit, storehouse_id)
  1427. var drugType = "药品类型"
  1428. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  1429. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminInfo.CurrentOrgId)
  1430. houseList, _ := service.GetAllStorehouseName(adminInfo.CurrentOrgId)
  1431. if err != nil {
  1432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1433. return
  1434. }
  1435. c.ServeSuccessJSON(map[string]interface{}{
  1436. "detail": detail,
  1437. "total": total,
  1438. "drugTypeParent": drugTypeList,
  1439. "houseList": houseList,
  1440. })
  1441. }
  1442. func (c *GobalConfigApiController) GetDrugCancelOrder() {
  1443. start_time := c.GetString("start_time")
  1444. end_time := c.GetString("end_time")
  1445. timeLayout := "2006-01-02"
  1446. loc, _ := time.LoadLocation("Local")
  1447. var startTime int64
  1448. if len(start_time) > 0 {
  1449. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1450. if err != nil {
  1451. fmt.Println(err)
  1452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1453. return
  1454. }
  1455. startTime = theTime.Unix()
  1456. }
  1457. var endTime int64
  1458. if len(end_time) > 0 {
  1459. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1460. if err != nil {
  1461. utils.ErrorLog(err.Error())
  1462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1463. return
  1464. }
  1465. endTime = theTime.Unix()
  1466. }
  1467. adminInfo := c.GetAdminUserInfo()
  1468. order_type, _ := c.GetInt64("order_type")
  1469. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1470. keyword := c.GetString("keyword")
  1471. limit, _ := c.GetInt64("limit")
  1472. page, _ := c.GetInt64("page")
  1473. order, total, err := service.GetDrugReturnOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, limit, page)
  1474. if err != nil {
  1475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1476. return
  1477. }
  1478. c.ServeSuccessJSON(map[string]interface{}{
  1479. "order": order,
  1480. "total": total,
  1481. })
  1482. }
  1483. func (c *GobalConfigApiController) GetDrugOutDetail() {
  1484. start_time := c.GetString("start_time")
  1485. end_time := c.GetString("end_time")
  1486. storehouse_id, _ := c.GetInt64("storehouse_id")
  1487. timeLayout := "2006-01-02"
  1488. loc, _ := time.LoadLocation("Local")
  1489. var startTime int64
  1490. if len(start_time) > 0 {
  1491. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1492. if err != nil {
  1493. fmt.Println(err)
  1494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1495. return
  1496. }
  1497. startTime = theTime.Unix()
  1498. }
  1499. var endTime int64
  1500. if len(end_time) > 0 {
  1501. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1502. if err != nil {
  1503. utils.ErrorLog(err.Error())
  1504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1505. return
  1506. }
  1507. endTime = theTime.Unix()
  1508. }
  1509. adminInfo := c.GetAdminUserInfo()
  1510. order_type, _ := c.GetInt64("order_type")
  1511. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1512. keyword := c.GetString("keyword")
  1513. limit, _ := c.GetInt64("limit")
  1514. page, _ := c.GetInt64("page")
  1515. order, total, err := service.GetDrugOutOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit, storehouse_id)
  1516. houseList, _ := service.GetAllStoreHouseList(adminInfo.CurrentOrgId)
  1517. var drugType = "药品类型"
  1518. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  1519. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminInfo.CurrentOrgId)
  1520. if err != nil {
  1521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1522. return
  1523. }
  1524. c.ServeSuccessJSON(map[string]interface{}{
  1525. "order": order,
  1526. "total": total,
  1527. "drugTypeList": drugTypeList,
  1528. "houseList": houseList,
  1529. })
  1530. }
  1531. func (c *GobalConfigApiController) GetDrugCancelDetail() {
  1532. start_time := c.GetString("start_time")
  1533. end_time := c.GetString("end_time")
  1534. storehouse_id, _ := c.GetInt64("storehouse_id")
  1535. timeLayout := "2006-01-02"
  1536. loc, _ := time.LoadLocation("Local")
  1537. var startTime int64
  1538. if len(start_time) > 0 {
  1539. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1540. if err != nil {
  1541. fmt.Println(err)
  1542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1543. return
  1544. }
  1545. startTime = theTime.Unix()
  1546. }
  1547. var endTime int64
  1548. if len(end_time) > 0 {
  1549. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1550. if err != nil {
  1551. utils.ErrorLog(err.Error())
  1552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1553. return
  1554. }
  1555. endTime = theTime.Unix()
  1556. }
  1557. adminInfo := c.GetAdminUserInfo()
  1558. order_type, _ := c.GetInt64("order_type")
  1559. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1560. keyword := c.GetString("keyword")
  1561. limit, _ := c.GetInt64("limit")
  1562. page, _ := c.GetInt64("page")
  1563. orderPrint, _ := service.GetDrugCancelOrderPrint(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, storehouse_id)
  1564. order, total, err := service.GetDrugCancelOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit, storehouse_id)
  1565. var drugType = "药品类型"
  1566. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  1567. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminInfo.CurrentOrgId)
  1568. houseList, _ := service.GetAllStoreHouseList(adminInfo.CurrentOrgId)
  1569. if err != nil {
  1570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1571. return
  1572. }
  1573. c.ServeSuccessJSON(map[string]interface{}{
  1574. "order": order,
  1575. "total": total,
  1576. "orderPrint": orderPrint,
  1577. "drugTypeList": drugTypeList,
  1578. "houseList": houseList,
  1579. })
  1580. }
  1581. func (c *GobalConfigApiController) AddMonitorOpen() {
  1582. is_open, _ := c.GetInt64("is_open")
  1583. fmt.Println("is_open22222222", is_open)
  1584. adminUserInfo := c.GetAdminUserInfo()
  1585. orgId := adminUserInfo.CurrentOrgId
  1586. config := models.XtMonitorConfig{
  1587. IsOpen: is_open,
  1588. UserOrgId: orgId,
  1589. Status: 1,
  1590. Ctime: time.Now().Unix(),
  1591. }
  1592. //查询该机构是否存在
  1593. _, errcode := service.GetMonitorConfigById(orgId)
  1594. if errcode == gorm.ErrRecordNotFound {
  1595. err := service.AddMonitorOpen(&config)
  1596. if err != nil {
  1597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1598. return
  1599. }
  1600. c.ServeSuccessJSON(map[string]interface{}{
  1601. "config": config,
  1602. })
  1603. } else if errcode == nil {
  1604. err := service.UpdateMonitorOpen(orgId, &config)
  1605. fmt.Println("err", err)
  1606. }
  1607. }
  1608. func (c *GobalConfigApiController) GetMonitorConfig() {
  1609. userInfo := c.GetAdminUserInfo()
  1610. orgId := userInfo.CurrentOrgId
  1611. config, err := service.GetMonitorConfig(orgId)
  1612. if err != nil {
  1613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1614. return
  1615. }
  1616. c.ServeSuccessJSON(map[string]interface{}{
  1617. "config": config,
  1618. })
  1619. }
  1620. func (c *GobalConfigApiController) AddOrderConfig() {
  1621. is_open, _ := c.GetInt64("is_open")
  1622. fmt.Println("344555555555555", is_open)
  1623. adminUserInfo := c.GetAdminUserInfo()
  1624. orgId := adminUserInfo.CurrentOrgId
  1625. config := models.XtOrderConfig{
  1626. IsOpen: is_open,
  1627. UserOrgId: orgId,
  1628. Status: 1,
  1629. Ctime: time.Now().Unix(),
  1630. }
  1631. //查询
  1632. _, errcode := service.GetOrderConfigById(orgId)
  1633. if errcode == gorm.ErrRecordNotFound {
  1634. err := service.AddOrderConfig(&config)
  1635. if err != nil {
  1636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1637. return
  1638. }
  1639. c.ServeSuccessJSON(map[string]interface{}{
  1640. "config": config,
  1641. })
  1642. } else if errcode == nil {
  1643. err := service.UpdateOrderConfig(orgId, &config)
  1644. fmt.Println("2222", err)
  1645. }
  1646. }
  1647. func (c *GobalConfigApiController) GetOrderConfig() {
  1648. adminUserInfo := c.GetAdminUserInfo()
  1649. orgId := adminUserInfo.CurrentOrgId
  1650. config, err := service.GetOrderConfig(orgId)
  1651. if err != nil {
  1652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1653. return
  1654. }
  1655. c.ServeSuccessJSON(map[string]interface{}{
  1656. "config": config,
  1657. })
  1658. }
  1659. func (c *GobalConfigApiController) GetDrugAutoMaticList() {
  1660. adminUserInfo := c.GetAdminUserInfo()
  1661. orgId := adminUserInfo.CurrentOrgId
  1662. warehous_out_id, _ := c.GetInt64("warehous_out_id")
  1663. record_time, _ := c.GetInt64("record_time")
  1664. warehouse_out_order_number := c.GetString("warehouse_out_order_number")
  1665. drugConfig, _ := service.GetDrugStockConfig(orgId)
  1666. list, err := service.GetDrugAutoMaticList(orgId, warehous_out_id, record_time, warehouse_out_order_number)
  1667. drugList, err := service.GetAllBaseDrugList(orgId)
  1668. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1669. if err != nil {
  1670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1671. return
  1672. }
  1673. c.ServeSuccessJSON(map[string]interface{}{
  1674. "list": list,
  1675. "drugConfig": drugConfig,
  1676. "drugList": drugList,
  1677. "manufacturerList": manufacturerList,
  1678. })
  1679. }
  1680. func (c *GobalConfigApiController) GetDrugWarehuseOrderInfo() {
  1681. adminUserInfo := c.GetAdminUserInfo()
  1682. orgId := adminUserInfo.CurrentOrgId
  1683. list, _ := service.GetDrugWarehuseOrderInfo(orgId)
  1684. c.ServeSuccessJSON(map[string]interface{}{
  1685. "list": list,
  1686. })
  1687. }
  1688. func (c *GobalConfigApiController) GetDrugStockList() {
  1689. page, _ := c.GetInt64("page", -1)
  1690. limit, _ := c.GetInt64("limit", -1)
  1691. keyword := c.GetString("keyword")
  1692. drug_type, _ := c.GetInt64("drug_type")
  1693. start_time := c.GetString("start_time")
  1694. end_time := c.GetString("end_time")
  1695. timeLayout := "2006-01-02"
  1696. loc, _ := time.LoadLocation("Local")
  1697. storehouse_id, _ := c.GetInt64("storehouse_id")
  1698. drug_id, _ := c.GetInt64("drug_id")
  1699. var startTime int64
  1700. if len(start_time) > 0 {
  1701. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1702. if err != nil {
  1703. fmt.Println(err)
  1704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1705. return
  1706. }
  1707. startTime = theTime.Unix()
  1708. }
  1709. var endTime int64
  1710. if len(end_time) > 0 {
  1711. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1712. if err != nil {
  1713. utils.ErrorLog(err.Error())
  1714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1715. return
  1716. }
  1717. endTime = theTime.Unix()
  1718. }
  1719. adminUserInfo := c.GetAdminUserInfo()
  1720. list, total, err := service.GetAllBaseDurgListCount(page, limit, keyword, drug_type, startTime, endTime, adminUserInfo.CurrentOrgId, storehouse_id, drug_id)
  1721. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  1722. houseList, _ := service.GetAllStoreHouseListOne(adminUserInfo.CurrentOrgId)
  1723. medicalList, _ := service.GetAllBaseDrugStockList(adminUserInfo.CurrentOrgId)
  1724. if err != nil {
  1725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1726. return
  1727. }
  1728. c.ServeSuccessJSON(map[string]interface{}{
  1729. "list": list,
  1730. "total": total,
  1731. "manufacturerList": manufacturerList,
  1732. "houseList": houseList,
  1733. "medicalList": medicalList,
  1734. })
  1735. }
  1736. func (c *GobalConfigApiController) GetDrugStockFllow() {
  1737. drug_id, _ := c.GetInt64("drug_id")
  1738. start_time := c.GetString("start_time")
  1739. end_time := c.GetString("end_time")
  1740. stock_type, _ := c.GetInt64("stock_type")
  1741. page, _ := c.GetInt64("page")
  1742. limit, _ := c.GetInt64("limit")
  1743. timeLayout := "2006-01-02"
  1744. loc, _ := time.LoadLocation("Local")
  1745. var startTime int64
  1746. if len(start_time) > 0 {
  1747. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1748. if err != nil {
  1749. fmt.Println(err)
  1750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1751. return
  1752. }
  1753. startTime = theTime.Unix()
  1754. }
  1755. var endTime int64
  1756. if len(end_time) > 0 {
  1757. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1758. if err != nil {
  1759. utils.ErrorLog(err.Error())
  1760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1761. return
  1762. }
  1763. endTime = theTime.Unix()
  1764. }
  1765. orgId := c.GetAdminUserInfo().CurrentOrgId
  1766. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1767. medical, _ := service.GetBaseDrugMedical(drug_id)
  1768. //查询入库数据
  1769. if stock_type == 3 || stock_type == 0 {
  1770. list, total, err := service.GetDrugStockFlow(drug_id, startTime, endTime, page, limit, orgId)
  1771. if err != nil {
  1772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1773. return
  1774. }
  1775. c.ServeSuccessJSON(map[string]interface{}{
  1776. "list": list,
  1777. "total": total,
  1778. "manufacturerList": manufacturerList,
  1779. "drug": medical,
  1780. })
  1781. }
  1782. }
  1783. func (c *GobalConfigApiController) GetDrugOutStockFlow() {
  1784. drug_id, _ := c.GetInt64("drug_id")
  1785. start_time := c.GetString("start_time")
  1786. end_time := c.GetString("end_time")
  1787. stock_type, _ := c.GetInt64("stock_type")
  1788. page, _ := c.GetInt64("page")
  1789. limit, _ := c.GetInt64("limit")
  1790. timeLayout := "2006-01-02"
  1791. loc, _ := time.LoadLocation("Local")
  1792. var startTime int64
  1793. if len(start_time) > 0 {
  1794. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1795. if err != nil {
  1796. fmt.Println(err)
  1797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1798. return
  1799. }
  1800. startTime = theTime.Unix()
  1801. }
  1802. var endTime int64
  1803. if len(end_time) > 0 {
  1804. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1805. if err != nil {
  1806. utils.ErrorLog(err.Error())
  1807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1808. return
  1809. }
  1810. endTime = theTime.Unix()
  1811. }
  1812. orgId := c.GetAdminUserInfo().CurrentOrgId
  1813. outList, total, err := service.GetDrugStockOutFlow(drug_id, startTime, endTime, page, limit, orgId, stock_type)
  1814. if err != nil {
  1815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1816. return
  1817. }
  1818. c.ServeSuccessJSON(map[string]interface{}{
  1819. "outList": outList,
  1820. "total": total,
  1821. })
  1822. }
  1823. func (c *GobalConfigApiController) GetBatchOrderDetail() {
  1824. drug_id, _ := c.GetInt64("drug_id")
  1825. orgId := c.GetAdminUserInfo().CurrentOrgId
  1826. limit, _ := c.GetInt64("limit")
  1827. page, _ := c.GetInt64("page")
  1828. start_time := c.GetString("start_time")
  1829. end_time := c.GetString("end_time")
  1830. start_first_time := c.GetString("start_first_time")
  1831. end_first_time := c.GetString("end_first_time")
  1832. timeLayout := "2006-01-02"
  1833. loc, _ := time.LoadLocation("Local")
  1834. var startTime int64
  1835. if len(start_time) > 0 {
  1836. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1837. if err != nil {
  1838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1839. return
  1840. }
  1841. startTime = theTime.Unix()
  1842. }
  1843. var endTime int64
  1844. if len(end_time) > 0 {
  1845. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1846. if err != nil {
  1847. utils.ErrorLog(err.Error())
  1848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1849. return
  1850. }
  1851. endTime = theTime.Unix()
  1852. }
  1853. var startFistTime int64
  1854. if len(start_first_time) > 0 {
  1855. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_first_time+" 00:00:00", loc)
  1856. if err != nil {
  1857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1858. return
  1859. }
  1860. startFistTime = theTime.Unix()
  1861. }
  1862. var endFirstTime int64
  1863. if len(end_first_time) > 0 {
  1864. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_first_time+" 23:59:59", loc)
  1865. if err != nil {
  1866. utils.ErrorLog(err.Error())
  1867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1868. return
  1869. }
  1870. endFirstTime = theTime.Unix()
  1871. }
  1872. detail, total, err := service.GetBatchOrderDetail(drug_id, orgId, page, limit, startTime, endTime, startFistTime, endFirstTime)
  1873. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1874. drug, _ := service.GetBaseDrugMedical(drug_id)
  1875. houseList, _ := service.GetAllStoreHouseList(orgId)
  1876. if err != nil {
  1877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1878. return
  1879. }
  1880. c.ServeSuccessJSON(map[string]interface{}{
  1881. "detail": detail,
  1882. "total": total,
  1883. "manufacturerList": manufacturerList,
  1884. "drug": drug,
  1885. "houseList": houseList,
  1886. })
  1887. }
  1888. func (c *GobalConfigApiController) GetDrugCountList() {
  1889. start_time := c.GetString("start_time")
  1890. end_time := c.GetString("end_time")
  1891. timeLayout := "2006-01-02"
  1892. loc, _ := time.LoadLocation("Local")
  1893. var startTime int64
  1894. if len(start_time) > 0 {
  1895. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1896. if err != nil {
  1897. fmt.Println(err)
  1898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1899. return
  1900. }
  1901. startTime = theTime.Unix()
  1902. }
  1903. var endTime int64
  1904. if len(end_time) > 0 {
  1905. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1906. if err != nil {
  1907. utils.ErrorLog(err.Error())
  1908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1909. return
  1910. }
  1911. endTime = theTime.Unix()
  1912. }
  1913. orgId := c.GetAdminUserInfo().CurrentOrgId
  1914. countList, err := service.GetMinCountList(startTime, endTime, orgId)
  1915. outCountList, _ := service.GetOutDrugCountList(startTime, endTime, orgId)
  1916. auCountList, err := service.GetAutoDrugCountList(startTime, endTime, orgId)
  1917. info, _ := service.GetDrugWarehouOrderInfo(startTime, endTime, orgId)
  1918. cancelCountList, _ := service.GetCancelDrugCountList(startTime, endTime, orgId)
  1919. if err != nil {
  1920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1921. return
  1922. }
  1923. c.ServeSuccessJSON(map[string]interface{}{
  1924. "outCountList": outCountList,
  1925. "auCountList": auCountList,
  1926. "minCount": countList,
  1927. "info": info,
  1928. "cancelCountList": cancelCountList,
  1929. })
  1930. }
  1931. func (c *GobalConfigApiController) GetSingleOrderDetail() {
  1932. id, _ := c.GetInt64("id")
  1933. start_time, _ := c.GetInt64("start_time")
  1934. orgId := c.GetAdminUserInfo().CurrentOrgId
  1935. list, err := service.GetSingleOrderDetail(id, orgId)
  1936. drugoutlist, _ := service.GetDrugWarehouseOutDetailSeventy(id, orgId)
  1937. dealerList, err := service.GetAllDealerList(orgId)
  1938. manufacturerList, err := service.GetAllManufacturerList(orgId)
  1939. drugFlowList, _ := service.GetDrugStockFlowDetail(start_time, orgId)
  1940. flowlist, _ := service.GetSingeOrderFlow(id, orgId)
  1941. drugList, _ := service.GetDrugFlowList(id, orgId)
  1942. drugListOne, _ := service.GetDrugFlowListGroupByIdOne(id, orgId)
  1943. drugListFlow, err := service.GetDrugFlowListGroupById(id, orgId)
  1944. if err != nil {
  1945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1946. return
  1947. }
  1948. c.ServeSuccessJSON(map[string]interface{}{
  1949. "list": list,
  1950. "dealerList": dealerList,
  1951. "manufacturerList": manufacturerList,
  1952. "drugFlowList": drugFlowList,
  1953. "flowlist": flowlist,
  1954. "drugList": drugList,
  1955. "drugListFlow": drugListFlow,
  1956. "drugListOne": drugListOne,
  1957. "drugoutlist": drugoutlist,
  1958. })
  1959. }
  1960. func (c *GobalConfigApiController) GetAutoDrugDetail() {
  1961. warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
  1962. id, _ := c.GetInt64("drug_id")
  1963. record_time, _ := c.GetInt64("record_time")
  1964. orgId := c.GetAdminUserInfo().CurrentOrgId
  1965. //获取自动出库
  1966. list, err, total := service.FindDrugStockUserDetailByIdThree(id, record_time, orgId)
  1967. //获取手动出库
  1968. outList, err := service.FindeDrugWarehouserInfo(warehouse_out_id, id, orgId)
  1969. batchNumber, err := service.GetDrugFlowBatch(warehouse_out_id, id, orgId)
  1970. if err != nil {
  1971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1972. return
  1973. }
  1974. c.ServeSuccessJSON(map[string]interface{}{
  1975. "list": list,
  1976. "total": total,
  1977. "outList": outList,
  1978. "batchNumber": batchNumber,
  1979. })
  1980. }
  1981. func (c *GobalConfigApiController) GetDrugOrderInPrint() {
  1982. id := c.GetString("id")
  1983. ids := strings.Split(id, ",")
  1984. admin := c.GetAdminUserInfo()
  1985. info, _ := service.FindDrugWarehousingByIdOne(ids, admin.CurrentOrgId)
  1986. manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  1987. warehousingInfo, _ := service.FindDrugWarehousingInfoByIdOne(ids, admin.CurrentOrgId)
  1988. c.ServeSuccessJSON(map[string]interface{}{
  1989. "info": info,
  1990. "warehousing": warehousingInfo,
  1991. "manufacturerList": manufacturerList,
  1992. })
  1993. }
  1994. func (c *GobalConfigApiController) GetDrugOutOrderPrint() {
  1995. id := c.GetString("id")
  1996. ids := strings.Split(id, ",")
  1997. admin := c.GetAdminUserInfo()
  1998. info, _ := service.FindeDrugWarehouseOutOrder(ids, admin.CurrentOrgId)
  1999. manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  2000. warehousing, _ := service.GetExportOutOrderDrugListOne(ids)
  2001. drug_warhouse_out, _ := service.GetDrugWarehouseOutTenty(ids, admin.CurrentOrgId)
  2002. fmt.Println("drug_warhouse_out9999999", drug_warhouse_out)
  2003. c.ServeSuccessJSON(map[string]interface{}{
  2004. "info": info,
  2005. "warehousing": warehousing,
  2006. "manufacturerList": manufacturerList,
  2007. "drug_warhouse_out": drug_warhouse_out,
  2008. })
  2009. }
  2010. func (c *GobalConfigApiController) GetDrugBatchNumber() {
  2011. id, _ := c.GetInt64("id")
  2012. orgId := c.GetAdminUserInfo().CurrentOrgId
  2013. list, _ := service.GetDrugBatchNumber(id, orgId)
  2014. c.ServeSuccessJSON(map[string]interface{}{
  2015. "list": list,
  2016. })
  2017. }
  2018. func (c *GobalConfigApiController) ExportDrugList() {
  2019. orderId := c.GetString("order_id")
  2020. ids := strings.Split(orderId, ",")
  2021. list, _ := service.ExportDrugList(ids)
  2022. orgId := c.GetAdminUserInfo().CurrentOrgId
  2023. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2024. dealerList, _ := service.GetAllDealerList(orgId)
  2025. c.ServeSuccessJSON(map[string]interface{}{
  2026. "list": list,
  2027. "manufacturerList": manufacturerList,
  2028. "dealerList": dealerList,
  2029. })
  2030. }
  2031. func (c *GobalConfigApiController) GetExportOutOrderDrugList() {
  2032. orderId := c.GetString("order_id")
  2033. ids := strings.Split(orderId, ",")
  2034. orgId := c.GetAdminUserInfo().CurrentOrgId
  2035. //list, _ := service.GetExportOutOrderDrugList(ids)
  2036. list, _ := service.GetExportOutOrderDrugListOne(ids)
  2037. outInfoList, _ := service.GetDrugOutListFlow(ids, orgId)
  2038. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2039. dealerList, _ := service.GetAllDealerList(orgId)
  2040. c.ServeSuccessJSON(map[string]interface{}{
  2041. "list": list,
  2042. "manufacturerList": manufacturerList,
  2043. "dealerList": dealerList,
  2044. "outInfoList": outInfoList,
  2045. })
  2046. }
  2047. func (c *GobalConfigApiController) GetDrugFlow() {
  2048. start_time := c.GetString("start_time")
  2049. end_time := c.GetString("end_time")
  2050. timeLayout := "2006-01-02"
  2051. loc, _ := time.LoadLocation("Local")
  2052. var startTime int64
  2053. if len(start_time) > 0 {
  2054. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2055. if err != nil {
  2056. fmt.Println(err)
  2057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2058. return
  2059. }
  2060. startTime = theTime.Unix()
  2061. }
  2062. var endTime int64
  2063. if len(end_time) > 0 {
  2064. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2065. if err != nil {
  2066. utils.ErrorLog(err.Error())
  2067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2068. return
  2069. }
  2070. endTime = theTime.Unix()
  2071. }
  2072. orgId := c.GetAdminUserInfo().CurrentOrgId
  2073. drug_id, _ := c.GetInt64("drug_id")
  2074. page, _ := c.GetInt64("page")
  2075. limit, _ := c.GetInt64("limit")
  2076. stock_type, _ := c.GetInt64("stock_type")
  2077. list, total, _ := service.GetDrugFlow(drug_id, orgId, limit, page, startTime, endTime, stock_type)
  2078. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2079. dealerList, _ := service.GetAllDealerList(orgId)
  2080. medical, _ := service.GetBaseDrugMedical(drug_id)
  2081. houseList, _ := service.GetAllStoreHouseList(orgId)
  2082. c.ServeSuccessJSON(map[string]interface{}{
  2083. "list": list,
  2084. "total": total,
  2085. "manufacturerList": manufacturerList,
  2086. "dealerList": dealerList,
  2087. "drug": medical,
  2088. "houseList": houseList,
  2089. })
  2090. }
  2091. func (c *GobalConfigApiController) GetCancelStockDetail() {
  2092. id, _ := c.GetInt64("id")
  2093. list, _ := service.GetCancelStockDetail(id)
  2094. c.ServeSuccessJSON(map[string]interface{}{
  2095. "list": list,
  2096. })
  2097. }
  2098. func (c *GobalConfigApiController) ChangeStockSetting() {
  2099. is_type, _ := c.GetInt64("is_type")
  2100. orgId := c.GetAdminUserInfo().CurrentOrgId
  2101. setting := models.XtStockSetting{
  2102. IsType: is_type,
  2103. UserOrgId: orgId,
  2104. Status: 1,
  2105. Ctime: time.Now().Unix(),
  2106. Mtime: 0,
  2107. }
  2108. //查询机该机构是否已经配置
  2109. _, errcode := service.GetStockSettingIsExsit(orgId)
  2110. if errcode == gorm.ErrRecordNotFound {
  2111. service.CreateStockSetting(setting)
  2112. c.ServeSuccessJSON(map[string]interface{}{
  2113. "msg": 1,
  2114. })
  2115. } else if errcode == nil {
  2116. service.UpdateStockSetting(orgId, setting)
  2117. c.ServeSuccessJSON(map[string]interface{}{
  2118. "msg": 1,
  2119. })
  2120. }
  2121. }
  2122. func (c *GobalConfigApiController) ChangeAdviceConfig() {
  2123. is_advice_open, _ := c.GetInt64("is_advice_open")
  2124. orgId := c.GetAdminUserInfo().CurrentOrgId
  2125. setting := models.XtAdviceSetting{
  2126. IsAdviceOpen: is_advice_open,
  2127. UserOrgId: orgId,
  2128. Status: 1,
  2129. Ctime: time.Now().Unix(),
  2130. Mtime: 0,
  2131. }
  2132. //查询是否存在
  2133. _, errcode := service.GetAdviceConfig(orgId)
  2134. if errcode == gorm.ErrRecordNotFound {
  2135. service.CreateAdviceSetting(setting)
  2136. c.ServeSuccessJSON(map[string]interface{}{
  2137. "msg": 1,
  2138. })
  2139. } else if errcode == nil {
  2140. service.UpdateAdviceSetting(orgId, setting)
  2141. c.ServeSuccessJSON(map[string]interface{}{
  2142. "msg": 1,
  2143. })
  2144. }
  2145. }
  2146. func (c *GobalConfigApiController) ChangePrescriptionConfig() {
  2147. is_open_prescription_xt_his, _ := c.GetInt64("is_open_prescription_xt_his")
  2148. orgId := c.GetAdminUserInfo().CurrentOrgId
  2149. _, errcode := service.GetPrescriptionConfig(orgId)
  2150. if errcode == gorm.ErrRecordNotFound {
  2151. config := models.XtPrescriptionConfig{
  2152. UserOrgId: orgId,
  2153. IsOpen: is_open_prescription_xt_his,
  2154. Status: 1,
  2155. Ctime: time.Now().Unix(),
  2156. }
  2157. service.CreatePrescriptionConfig(config)
  2158. c.ServeSuccessJSON(map[string]interface{}{
  2159. "msg": 1,
  2160. })
  2161. } else if errcode == nil {
  2162. config := models.XtPrescriptionConfig{
  2163. UserOrgId: orgId,
  2164. IsOpen: is_open_prescription_xt_his,
  2165. Status: 1,
  2166. Ctime: time.Now().Unix(),
  2167. }
  2168. service.UpdatePrescriptionConfig(orgId, config)
  2169. c.ServeSuccessJSON(map[string]interface{}{
  2170. "msg": 1,
  2171. })
  2172. }
  2173. }
  2174. func (c *GobalConfigApiController) ChangeDrugOpenConfig() {
  2175. drug_out_open, _ := c.GetInt64("drug_out_open")
  2176. orgId := c.GetAdminUserInfo().CurrentOrgId
  2177. if drug_out_open == 1 {
  2178. service.UpdateDrugStockAutomaticReduceRecordOne(orgId, 2)
  2179. service.UpdatePharyConfig(orgId, 2)
  2180. service.UpdateSettleOpenConfigOne(orgId, 2)
  2181. }
  2182. _, errcode := service.GetDrugOpenConfig(orgId)
  2183. if errcode == gorm.ErrRecordNotFound {
  2184. config := models.DrugOutConfig{
  2185. UserOrgId: orgId,
  2186. IsOpen: drug_out_open,
  2187. Status: 1,
  2188. Ctime: time.Now().Unix(),
  2189. }
  2190. service.CreateDrugOutConfig(config)
  2191. c.ServeSuccessJSON(map[string]interface{}{
  2192. "msg": 1,
  2193. })
  2194. } else if errcode == nil {
  2195. service.UpdateDrugOutConfig(orgId, drug_out_open)
  2196. c.ServeSuccessJSON(map[string]interface{}{
  2197. "msg": 1,
  2198. })
  2199. }
  2200. }
  2201. func (this *GobalConfigApiController) ChangeSettleOpenConfig() {
  2202. drug_out_open, _ := this.GetInt64("drug_settle_open")
  2203. orgId := this.GetAdminUserInfo().CurrentOrgId
  2204. config := models.HisSettleStockConfig{
  2205. UserOrgId: orgId,
  2206. Ctime: time.Now().Unix(),
  2207. Mtime: 0,
  2208. Status: 1,
  2209. IsOpen: drug_out_open,
  2210. }
  2211. if drug_out_open == 1 {
  2212. service.UpdateDrugOutConfig(orgId, 2)
  2213. service.UpdateDrugStockAutomaticReduceRecordOne(orgId, 2)
  2214. service.UpdatePharyConfig(orgId, 2)
  2215. service.UpdateGoodAutoConfig(orgId)
  2216. service.UpdateGoodOutConfig(orgId)
  2217. }
  2218. openConfig, errcode := service.GetSettleOpenConfig(orgId)
  2219. if errcode == gorm.ErrRecordNotFound {
  2220. service.CreateSettleOpenConfig(config)
  2221. } else if errcode == nil {
  2222. service.UpdateSettleOpenConfig(openConfig.ID, config)
  2223. }
  2224. this.ServeSuccessJSON(map[string]interface{}{
  2225. "msg": 1,
  2226. })
  2227. }
  2228. func (this *GobalConfigApiController) ChangeGoodOutOpen() {
  2229. good_open, _ := this.GetInt64("good_open")
  2230. orgId := this.GetAdminUserInfo().CurrentOrgId
  2231. config, errcode := service.GetGoodOutOpenConfig(orgId)
  2232. outConfig := models.XtGoodOutConfig{
  2233. UserOrgId: orgId,
  2234. IsOpen: good_open,
  2235. Status: 1,
  2236. Ctime: time.Now().Unix(),
  2237. Mtime: time.Now().Unix(),
  2238. }
  2239. if good_open == 1 {
  2240. service.UpdateGoodAutoConfig(orgId)
  2241. service.UpdateSettleOpenConfigTwo(orgId, 2)
  2242. }
  2243. if errcode == gorm.ErrRecordNotFound {
  2244. service.CreateGoodOutOpenConfig(outConfig)
  2245. } else if errcode == nil {
  2246. service.UpdateGoodOutOpenConfig(config.ID, outConfig)
  2247. }
  2248. this.ServeSuccessJSON(map[string]interface{}{
  2249. "msg": 1,
  2250. })
  2251. }