gobal_config_api_controller.go 76KB

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