gobal_config_api_controller.go 78KB

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