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