dialysis_api_controller.go 159KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178
  1. package controllers
  2. import (
  3. "XT_New/models"
  4. "XT_New/service"
  5. "XT_New/utils"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/jinzhu/gorm"
  9. "math"
  10. "reflect"
  11. "strconv"
  12. "strings"
  13. //"strings"
  14. "time"
  15. "XT_New/enums"
  16. "github.com/astaxie/beego"
  17. )
  18. type DialysisApiController struct {
  19. BaseAuthAPIController
  20. }
  21. func DialysisApiRegistRouters() {
  22. beego.Router("/api/dialysis/device", &DialysisApiController{}, "get:GetDeviceList")
  23. beego.Router("/api/dialysis/patients", &DialysisApiController{}, "get:GetDialysisWatch")
  24. beego.Router("/api/dialysis/zone", &DialysisApiController{}, "get:GetAllDeviceZone")
  25. beego.Router("/api/dialysis/info", &DialysisApiController{}, "get:GetSchedualPatientsInfo")
  26. beego.Router("/api/dialysis/advice/create", &DialysisApiController{}, "Post:CreateDoctorAdvice")
  27. beego.Router("/api/dialysis/advice/get", &DialysisApiController{}, "Get:GetDoctorAdvice")
  28. beego.Router("/api/dialysis/advice/edit", &DialysisApiController{}, "put:EditDoctorAdvice")
  29. beego.Router("/api/dialysis/monitor/create", &DialysisApiController{}, "Post:CreateMonitor")
  30. beego.Router("/api/dialysis/monitor/del", &DialysisApiController{}, "Post:DelMonitor")
  31. beego.Router("/api/dialysis/dialysisorder", &DialysisApiController{}, "Get:GetDialysisOrder")
  32. beego.Router("/api/dialysis/prescription", &DialysisApiController{}, "Post:PostPrescription")
  33. beego.Router("/api/dialysis/soulution", &DialysisApiController{}, "Post:PostSoulution")
  34. beego.Router("/api/dialysis/dobule", &DialysisApiController{}, "Post:PostDouleCheck")
  35. beego.Router("/api/dialysis/accepts", &DialysisApiController{}, "Post:PostReceiveTreatmentAsses")
  36. beego.Router("/api/dialysis/assessmentbeforedislysis", &DialysisApiController{}, "Post:PostAssessmentBeforeDislysis")
  37. beego.Router("/api/dialysis/assessmentafterdislysis", &DialysisApiController{}, "Post:PostAssessmentAfterDislysis")
  38. beego.Router("/api/dialysis/treatmentsummary", &DialysisApiController{}, "Post:PostTreatmentSummary")
  39. beego.Router("/api/dialysis/advice_remind", &DialysisApiController{}, "Get:GetLongAdvice")
  40. beego.Router("/api/dialysis/advice_remind/one", &DialysisApiController{}, "Get:GetLongAdviceOne")
  41. beego.Router("/api/dialysis/advice_remind/two", &DialysisApiController{}, "Get:GetLongAdviceTwo")
  42. beego.Router("/api/advice_remind/create", &DialysisApiController{}, "Post:CreateRemindDoctorAdvice")
  43. beego.Router("/api/solution/get", &DialysisApiController{}, "Get:GetSolution")
  44. beego.Router("/api/schedule/get", &DialysisApiController{}, "Get:GetSchedule")
  45. beego.Router("/api/today_monitor/get", &DialysisApiController{}, "Get:GetTodayMonitor")
  46. beego.Router("/api/dryweight/commit", &DialysisApiController{}, "Post:UploadDryWeight")
  47. beego.Router("/api/func_per/get", &DialysisApiController{}, "Get:GetFuncPurview")
  48. beego.Router("/api/doctoradvice/get", &DialysisApiController{}, "Get:GetLastOrNextDoctorAdvice")
  49. beego.Router("/api/dialysisgoods/get", &DialysisApiController{}, "Get:GetDialysisGoods")
  50. beego.Router("/api/goodstatistics/get", &DialysisApiController{}, "Get:GetDialysisGoodsStatistics")
  51. beego.Router("/api/queue/get", &DialysisApiController{}, "Get:GetQueueCall")
  52. beego.Router("/api/queue/update", &DialysisApiController{}, "Get:UpdateQueueCall")
  53. beego.Router("/api/get/getrolelist", &DialysisApiController{}, "Get:GetRoleList")
  54. beego.Router("/api/getinitprintdata", &DialysisApiController{}, "Get:GetInitPrintData")
  55. beego.Router("/api/schedule/getorderdoctoradvice", &DialysisApiController{}, "Get:GetOrderDoctorAdvice")
  56. beego.Router("/api/getinitprintdateone", &DialysisApiController{}, "Get:GetInitPrintDataOne")
  57. }
  58. func (c *DialysisApiController) GetQueueCall() {
  59. adminUserInfo := c.GetAdminUserInfo()
  60. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  61. if queueConfig.ID <= 0 {
  62. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  63. queueConfig.Qhsj = 10
  64. queueConfig.Jzdcbbcs = 3
  65. queueConfig.Jzbbsy = 1
  66. queueConfig.Jzjhyc = 0
  67. queueConfig.Sjdcbbcs = 3
  68. queueConfig.Sjbbsy = 0
  69. queueConfig.Sjjhyc = 0
  70. queueConfig.Txxqyxs = 0
  71. queueConfig.Txglsyxs = 0
  72. }
  73. c.ServeSuccessJSON(map[string]interface{}{
  74. "queue_config": queueConfig,
  75. })
  76. }
  77. func (c *DialysisApiController) UpdateQueueCall() {
  78. adminUserInfo := c.GetAdminUserInfo()
  79. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  80. if queueConfig.ID <= 0 {
  81. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  82. queueConfig.Qhsj = 10
  83. queueConfig.Jzdcbbcs = 3
  84. queueConfig.Jzbbsy = 1
  85. queueConfig.Jzjhyc = 0
  86. queueConfig.Sjdcbbcs = 3
  87. queueConfig.Sjbbsy = 0
  88. queueConfig.Sjjhyc = 0
  89. queueConfig.Txxqyxs = 0
  90. queueConfig.Txglsyxs = 0
  91. queueConfig.CreateTime = time.Now().Unix()
  92. queueConfig.UpdateTime = time.Now().Unix()
  93. }
  94. qhsj, _ := c.GetInt64("qhsj", 0)
  95. if qhsj > 0 {
  96. queueConfig.Qhsj = qhsj
  97. }
  98. jzdcbbcs, _ := c.GetInt64("jzdcbbcs", 0)
  99. if jzdcbbcs > 0 {
  100. queueConfig.Jzdcbbcs = jzdcbbcs
  101. }
  102. jzbbsy, _ := c.GetInt64("jzbbsy", 0)
  103. if jzbbsy > 0 {
  104. queueConfig.Jzbbsy = jzbbsy
  105. }
  106. jzjhyc, _ := c.GetInt64("jzjhyc", 0)
  107. queueConfig.Jzjhyc = jzjhyc
  108. sjdcbbcs, _ := c.GetInt64("sjdcbbcs", 0)
  109. if sjdcbbcs > 0 {
  110. queueConfig.Sjdcbbcs = sjdcbbcs
  111. }
  112. sjbbsy, _ := c.GetInt64("sjbbsy", 0)
  113. if sjbbsy > 0 {
  114. queueConfig.Sjbbsy = sjbbsy
  115. }
  116. sjjhyc, _ := c.GetInt64("sjjhyc", 0)
  117. queueConfig.Sjjhyc = sjjhyc
  118. txxqyxs, _ := c.GetInt64("txxqyxs", 0)
  119. queueConfig.Txxqyxs = txxqyxs
  120. txglsyxs, _ := c.GetInt64("txglsyxs", 0)
  121. queueConfig.Txglsyxs = txglsyxs
  122. queueConfig.UpdateTime = time.Now().Unix()
  123. service.UpDateQueueCallInfo(queueConfig)
  124. c.ServeSuccessJSON(map[string]interface{}{
  125. "queue_config": queueConfig,
  126. })
  127. }
  128. func (c *DialysisApiController) PostPrescription() {
  129. patient, _ := c.GetInt64("patient_id", 0)
  130. recordDateStr := c.GetString("record_date")
  131. if patient <= 0 {
  132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  133. return
  134. }
  135. adminUserInfo := c.GetAdminUserInfo()
  136. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  137. if patientInfo.ID == 0 {
  138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  139. return
  140. }
  141. if len(recordDateStr) == 0 {
  142. recordDateStr = time.Now().Format("2006-01-02")
  143. }
  144. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  145. if parseDateErr != nil {
  146. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  148. return
  149. }
  150. mode_id, _ := c.GetInt64("mode_id", 0)
  151. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  152. dialyzer, _ := c.GetInt64("dialyzer", 0)
  153. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  154. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  155. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  156. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  157. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  158. replacement_way, _ := c.GetInt64("replacement_way", 0)
  159. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  160. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  161. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  162. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  163. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  164. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  165. kalium, _ := c.GetFloat("kalium", 0)
  166. sodium, _ := c.GetFloat("sodium", 0)
  167. replacement_total, _ := c.GetFloat("replacement_total", 0)
  168. calcium, _ := c.GetFloat("calcium", 0)
  169. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  170. glucose, _ := c.GetFloat("glucose", 0)
  171. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  172. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  173. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  174. conductivity, _ := c.GetFloat("conductivity", 0)
  175. remark := c.GetString("remark")
  176. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  177. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  178. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  179. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  180. body_fluid, _ := c.GetInt64("body_fluid", 0)
  181. special_medicine, _ := c.GetInt64("special_medicine", 0)
  182. special_medicine_other := c.GetString("special_medicine_other")
  183. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  184. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  185. blood_access, _ := c.GetInt64("blood_access", 0)
  186. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  187. body_fluid_other := c.GetString("body_fluid_other")
  188. target_ktv, _ := c.GetFloat("target_ktv", 0)
  189. niprocart, _ := c.GetInt64("niprocart", 0)
  190. jms, _ := c.GetInt64("jms", 0)
  191. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  192. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  193. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  194. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  195. filtryzer, _ := c.GetInt64("filtryzer", 0)
  196. dialyzers, _ := c.GetInt64("dialyzers", 0)
  197. injector, _ := c.GetInt64("injector", 0)
  198. bloodlines, _ := c.GetInt64("bloodlines", 0)
  199. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  200. safe_package, _ := c.GetInt64("package", 0)
  201. a_liquid, _ := c.GetInt64("a_liquid", 0)
  202. preImpules, _ := c.GetFloat("pre_impulse", 0)
  203. fmt.Println("", preImpules)
  204. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  205. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  206. //heparin_sodium := c.GetString("heparin_sodium")
  207. //fmt.Println("肝素钠",heparin_sodium)
  208. //nucleoprotamine := c.GetString("nucleoprotamine")
  209. //fmt.Println("鱼精蛋白",nucleoprotamine)
  210. //push_the_protamine := c.GetString("push_the_protamine")
  211. //fmt.Println("下机前推注鱼精蛋白",push_the_protamine)
  212. // var prescription_doctor int64
  213. blood := c.GetString("blood")
  214. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  215. dialysis_irrigation := c.GetString("dialysis_irrigation")
  216. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  217. displace_speed := c.GetString("displace_speed")
  218. illness, _ := c.GetInt64("illness")
  219. amylaceum := c.GetString("amylaceum")
  220. single_time := c.GetString("single_time")
  221. single_water := c.GetString("single_water")
  222. replacement_flow := c.GetString("replacement_flow")
  223. plasma_separator := c.GetString("plasma_separator")
  224. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  225. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  226. oxygen_flow := c.GetString("oxygen_flow")
  227. oxygen_time := c.GetString("oxygen_time")
  228. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  229. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  230. puncture_needle := c.GetString("puncture_needle")
  231. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  232. epo := c.GetString("epo")
  233. epo_count, _ := c.GetFloat("epo_count", 0)
  234. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  235. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  236. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  237. //if template.TemplateId == 2 || template.TemplateId == 6 {
  238. // if appRole.UserType == 3 {
  239. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  240. // if getPermissionErr != nil {
  241. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  242. // return
  243. // } else if headNursePermission == nil {
  244. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  245. // return
  246. // }
  247. // }
  248. //}
  249. prescription := models.DialysisPrescription{
  250. UserOrgId: adminUserInfo.CurrentOrgId,
  251. PatientId: patient,
  252. RecordDate: recordDate.Unix(),
  253. ModeId: mode_id,
  254. DialysisDuration: dialysis_duration,
  255. Dialyzer: dialyzer,
  256. ReplacementTotal: replacement_total,
  257. PerfusionApparatus: perfusion_apparatus,
  258. BloodFlowVolume: blood_flow_volume,
  259. DewaterAmount: dewater_amount,
  260. DisplaceLiqui: displace_liqui,
  261. ReplacementWay: replacement_way,
  262. Anticoagulant: anticoagulant,
  263. AnticoagulantShouji: anticoagulant_shouji,
  264. AnticoagulantWeichi: anticoagulant_weichi,
  265. AnticoagulantZongliang: anticoagulant_zongliang,
  266. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  267. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  268. Kalium: kalium,
  269. Sodium: sodium,
  270. Calcium: calcium,
  271. Bicarbonate: bicarbonate,
  272. Glucose: glucose,
  273. // DryWeight: dry_weight,
  274. DialysateFlow: dialysate_flow,
  275. DialysateTemperature: dialysate_temperature,
  276. Conductivity: conductivity,
  277. Remark: remark,
  278. Status: 1,
  279. CreatedTime: time.Now().Unix(),
  280. UpdatedTime: time.Now().Unix(),
  281. DialysisDurationMinute: dialysisDurationMinute,
  282. DialysisDurationHour: dialysisDurationHour,
  283. TargetUltrafiltration: targetUltrafiltration,
  284. DialysateFormulation: dialysateFormulation,
  285. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  286. BodyFluid: body_fluid,
  287. SpecialMedicine: special_medicine,
  288. SpecialMedicineOther: special_medicine_other,
  289. DisplaceLiquiPart: displace_liqui_part,
  290. DisplaceLiquiValue: displace_liqui_value,
  291. BloodAccess: blood_access,
  292. Ultrafiltration: ultrafiltration,
  293. BodyFluidOther: body_fluid_other,
  294. TargetKtv: target_ktv,
  295. Niprocart: niprocart,
  296. Jms: jms,
  297. FistulaNeedleSet: fistula_needle_set,
  298. FistulaNeedleSet16: fistula_needle_set_16,
  299. Hemoperfusion: hemoperfusion,
  300. DialyserSterilised: dialyser_sterilised,
  301. Filtryzer: filtryzer,
  302. Dialyzers: dialyzers,
  303. Injector: injector,
  304. Bloodlines: bloodlines,
  305. TubingHemodialysis: tubing_hemodialysis,
  306. Package: safe_package,
  307. ALiquid: a_liquid,
  308. PreImpulse: preImpules,
  309. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  310. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  311. Blood: blood,
  312. DialysisDialyszers: dialysis_dialyszers,
  313. DialysisIrrigation: dialysis_irrigation,
  314. AntioxidantCommodityName: antioxidant_commodity_name,
  315. DisplaceSpeed: displace_speed,
  316. Illness: illness,
  317. Amylaceum: amylaceum,
  318. SingleTime: single_time,
  319. SingleWater: single_water,
  320. ReplacementFlow: replacement_flow,
  321. PlasmaSeparator: plasma_separator,
  322. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  323. OxygenFlow: oxygen_flow,
  324. OxygenUptake: oxygen_uptake,
  325. OxygenTime: oxygen_time,
  326. HemodialysisPipelines: hemodialysis_pipelines,
  327. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  328. PunctureNeedle: puncture_needle,
  329. PunctureNeedleCount: puncture_needle_count,
  330. Epo: epo,
  331. EpoCount: epo_count,
  332. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  333. }
  334. if appRole.UserType == 2 || appRole.UserType == 1 {
  335. prescription.PrescriptionDoctor = appRole.AdminUserId
  336. }
  337. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  338. if dialysisPrescription.ID == 0 { //新增
  339. if mode_id > 0 {
  340. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  341. }
  342. prescription.Creater = adminUserInfo.AdminUser.Id
  343. err := service.AddSigleRecord(&prescription)
  344. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  345. redis := service.RedisClient()
  346. //清空key 值
  347. redis.Set(key, "", time.Second)
  348. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  349. redis.Set(keyTwo, "", time.Second)
  350. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  351. redis.Set(keyThree, "", time.Second)
  352. defer redis.Close()
  353. if err == nil {
  354. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  355. if updateErr != nil {
  356. utils.ErrorLog("%v", updateErr)
  357. }
  358. c.ServeSuccessJSON(map[string]interface{}{
  359. "prescription": &prescription,
  360. })
  361. } else {
  362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  363. }
  364. } else { //修改
  365. if mode_id > 0 {
  366. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  367. }
  368. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  369. //if template.TemplateId == 1 {
  370. // if dialysisPrescription.Creater > 0 && dialysisPrescription.Creater != adminUserInfo.AdminUser.Id {
  371. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  372. // if getPermissionErr != nil {
  373. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  374. // return
  375. // } else if headNursePermission == nil {
  376. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  377. // return
  378. // }
  379. // }
  380. //}
  381. if appRole.UserType == 2 || appRole.UserType == 1 {
  382. prescription_doctor := adminUserInfo.AdminUser.Id
  383. prescription.PrescriptionDoctor = prescription_doctor
  384. }
  385. if dialysisPrescription.Creater == 0 { //体重称
  386. prescription.Creater = adminUserInfo.AdminUser.Id
  387. } else {
  388. prescription.Creater = dialysisPrescription.Creater
  389. }
  390. prescription.CreatedTime = dialysisPrescription.CreatedTime
  391. prescription.UpdatedTime = time.Now().Unix()
  392. prescription.Modifier = adminUserInfo.AdminUser.Id
  393. prescription.ID = dialysisPrescription.ID
  394. updateErr := service.UpDateDialysisPrescription(&prescription)
  395. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  396. redis := service.RedisClient()
  397. defer redis.Close()
  398. //清空key 值
  399. redis.Set(key, "", time.Second)
  400. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  401. redis.Set(keyOne, "", time.Second)
  402. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  403. redis.Set(keyThree, "", time.Second)
  404. if updateErr == nil {
  405. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  406. if updateErr != nil {
  407. utils.ErrorLog("%v", updateErr)
  408. }
  409. c.ServeSuccessJSON(map[string]interface{}{
  410. "prescription": &prescription,
  411. })
  412. } else {
  413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  414. }
  415. }
  416. }
  417. func (c *DialysisApiController) PostSoulution() {
  418. patient, _ := c.GetInt64("patient", 0)
  419. recordDateStr := c.GetString("record_date")
  420. if patient <= 0 {
  421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  422. return
  423. }
  424. adminUserInfo := c.GetAdminUserInfo()
  425. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  426. if patientInfo.ID == 0 {
  427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  428. return
  429. }
  430. if len(recordDateStr) == 0 {
  431. recordDateStr = time.Now().Format("2006-01-02")
  432. }
  433. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  434. if parseDateErr != nil {
  435. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  437. return
  438. }
  439. mode_id, _ := c.GetInt64("mode_id", 0)
  440. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  441. dialyzer, _ := c.GetInt64("dialyzer", 0)
  442. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  443. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  444. replacement_total, _ := c.GetFloat("replacement_total", 0)
  445. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  446. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  447. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  448. replacement_way, _ := c.GetInt64("replacement_way", 0)
  449. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  450. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  451. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  452. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  453. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  454. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  455. kalium, _ := c.GetFloat("kalium", 0)
  456. sodium, _ := c.GetFloat("sodium", 0)
  457. calcium, _ := c.GetFloat("calcium", 0)
  458. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  459. glucose, _ := c.GetFloat("glucose", 0)
  460. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  461. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  462. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  463. conductivity, _ := c.GetFloat("conductivity", 0)
  464. remark := c.GetString("remark")
  465. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  466. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  467. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  468. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  469. body_fluid, _ := c.GetInt64("body_fluid", 0)
  470. special_medicine, _ := c.GetInt64("special_medicine", 0)
  471. special_medicine_other := c.GetString("special_medicine_other")
  472. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  473. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  474. blood_access, _ := c.GetInt64("blood_access", 0)
  475. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  476. body_fluid_other := c.GetString("body_fluid_other")
  477. target_ktv, _ := c.GetFloat("target_ktv", 0)
  478. niprocart, _ := c.GetInt64("niprocart", 0)
  479. jms, _ := c.GetInt64("jms", 0)
  480. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  481. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  482. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  483. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  484. filtryzer, _ := c.GetInt64("filtryzer", 0)
  485. dialyzers, _ := c.GetInt64("dialyzers", 0)
  486. injector, _ := c.GetInt64("injector", 0)
  487. bloodlines, _ := c.GetInt64("bloodlines", 0)
  488. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  489. safe_package, _ := c.GetInt64("package", 0)
  490. a_liquid, _ := c.GetInt64("a_liquid", 0)
  491. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  492. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  493. blood := c.GetString("blood")
  494. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  495. dialysis_irrigation := c.GetString("dialysis_irrigation")
  496. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  497. displace_speed := c.GetString("displace_speed")
  498. illness, _ := c.GetInt64("illness")
  499. amylaceum := c.GetString("amylaceum")
  500. single_time := c.GetString("single_time")
  501. single_water := c.GetString("single_water")
  502. replacement_flow := c.GetString("replacement_flow")
  503. plasma_separator := c.GetString("plasma_separator")
  504. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  505. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  506. oxygen_flow := c.GetString("oxygen_flow")
  507. oxygen_time := c.GetString("oxygen_time")
  508. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  509. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  510. puncture_needle := c.GetString("puncture_needle")
  511. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  512. epo := c.GetString("epo")
  513. epo_count, _ := c.GetFloat("epo_count", 0)
  514. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  515. impulse := c.GetString("impulse")
  516. preImpules, parseDateErr := strconv.ParseFloat(impulse, 64)
  517. fmt.Println("", preImpules)
  518. var prescription_doctor int64
  519. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  520. if appRole.UserType == 2 || appRole.UserType == 1 {
  521. prescription_doctor = appRole.AdminUserId
  522. }
  523. if mode_id > 0 {
  524. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  525. }
  526. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  527. //
  528. //if template.TemplateId == 2 || template.TemplateId == 6 {
  529. // if appRole.UserType == 3 {
  530. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  531. // if getPermissionErr != nil {
  532. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  533. // return
  534. // } else if headNursePermission == nil {
  535. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  536. // return
  537. // }
  538. // }
  539. //}
  540. prescription := models.DialysisPrescription{
  541. UserOrgId: adminUserInfo.CurrentOrgId,
  542. PatientId: patient,
  543. RecordDate: recordDate.Unix(),
  544. ModeId: mode_id,
  545. DialysisDuration: dialysis_duration,
  546. Dialyzer: dialyzer,
  547. PerfusionApparatus: perfusion_apparatus,
  548. BloodFlowVolume: blood_flow_volume,
  549. DewaterAmount: dewater_amount,
  550. DisplaceLiqui: displace_liqui,
  551. ReplacementWay: replacement_way,
  552. Anticoagulant: anticoagulant,
  553. AnticoagulantShouji: anticoagulant_shouji,
  554. AnticoagulantWeichi: anticoagulant_weichi,
  555. AnticoagulantZongliang: anticoagulant_zongliang,
  556. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  557. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  558. Kalium: kalium,
  559. Sodium: sodium,
  560. Calcium: calcium,
  561. Bicarbonate: bicarbonate,
  562. Glucose: glucose,
  563. // DryWeight: dry_weight,
  564. DialysateFlow: dialysate_flow,
  565. DialysateTemperature: dialysate_temperature,
  566. Conductivity: conductivity,
  567. Remark: remark,
  568. PrescriptionDoctor: prescription_doctor,
  569. Status: 1,
  570. CreatedTime: time.Now().Unix(),
  571. UpdatedTime: time.Now().Unix(),
  572. DialysisDurationMinute: dialysisDurationMinute,
  573. DialysisDurationHour: dialysisDurationHour,
  574. TargetUltrafiltration: targetUltrafiltration,
  575. DialysateFormulation: dialysateFormulation,
  576. ReplacementTotal: replacement_total,
  577. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  578. BodyFluid: body_fluid,
  579. SpecialMedicine: special_medicine,
  580. SpecialMedicineOther: special_medicine_other,
  581. DisplaceLiquiPart: displace_liqui_part,
  582. DisplaceLiquiValue: displace_liqui_value,
  583. BloodAccess: blood_access,
  584. Ultrafiltration: ultrafiltration,
  585. BodyFluidOther: body_fluid_other,
  586. TargetKtv: target_ktv,
  587. Niprocart: niprocart,
  588. Jms: jms,
  589. FistulaNeedleSet: fistula_needle_set,
  590. FistulaNeedleSet16: fistula_needle_set_16,
  591. Hemoperfusion: hemoperfusion,
  592. DialyserSterilised: dialyser_sterilised,
  593. Filtryzer: filtryzer,
  594. Dialyzers: dialyzers,
  595. Injector: injector,
  596. Bloodlines: bloodlines,
  597. TubingHemodialysis: tubing_hemodialysis,
  598. Package: safe_package,
  599. ALiquid: a_liquid,
  600. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  601. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  602. Blood: blood,
  603. DialysisIrrigation: dialysis_irrigation,
  604. DialysisDialyszers: dialysis_dialyszers,
  605. AntioxidantCommodityName: antioxidant_commodity_name,
  606. DisplaceSpeed: displace_speed,
  607. Illness: illness,
  608. Amylaceum: amylaceum,
  609. SingleTime: single_time,
  610. SingleWater: single_water,
  611. ReplacementFlow: replacement_flow,
  612. PlasmaSeparator: plasma_separator,
  613. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  614. OxygenTime: oxygen_time,
  615. OxygenUptake: oxygen_uptake,
  616. OxygenFlow: oxygen_flow,
  617. HemodialysisPipelines: hemodialysis_pipelines,
  618. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  619. PunctureNeedle: puncture_needle,
  620. PunctureNeedleCount: puncture_needle_count,
  621. Epo: epo,
  622. EpoCount: epo_count,
  623. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  624. PreImpulse: preImpules,
  625. }
  626. //查询最近透析准备表里是否存在 透析器 灌流器
  627. //splitStr := strings.Split(dialysis_dialyszers, ",")
  628. //
  629. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  630. //
  631. //mation, _ := service.GetGoodInfoMation(adminUserInfo.CurrentOrgId)
  632. //if len(mation)>0{
  633. // for _, item := range splitStr {
  634. // for _,it := range mation{
  635. // if(item == it.SpecificationName){
  636. //
  637. // //查询最近一次的透析器
  638. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  639. //
  640. // if errcode == gorm.ErrRecordNotFound{
  641. // //插入数据
  642. // prepare := models.DialysisBeforePrepare{
  643. // UserOrgId: adminUserInfo.CurrentOrgId,
  644. // PatientId: patient,
  645. // RecordDate: recordDate.Unix(),
  646. // GoodTypeId: it.GoodTypeId,
  647. // GoodId: it.ID,
  648. // Count: 1,
  649. // Ctime: time.Now().Unix(),
  650. // Creater: adminUserInfo.AdminUser.Id,
  651. // Status:1,
  652. //
  653. // }
  654. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  655. // fmt.Println("",errcode)
  656. // }
  657. // }
  658. // }
  659. //
  660. // }
  661. //
  662. // for _, item := range splitIrrigation {
  663. // for _,it := range mation{
  664. // if(item == it.SpecificationName){
  665. // //查询最近一次的透析器
  666. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  667. // if errcode == gorm.ErrRecordNotFound{
  668. // //插入数据
  669. // prepare := models.DialysisBeforePrepare{
  670. // UserOrgId: adminUserInfo.CurrentOrgId,
  671. // PatientId: patient,
  672. // RecordDate: recordDate.Unix(),
  673. // GoodTypeId: it.GoodTypeId,
  674. // GoodId: it.ID,
  675. // Count: 1,
  676. // Ctime: time.Now().Unix(),
  677. // Creater: adminUserInfo.AdminUser.Id,
  678. // Status:1,
  679. //
  680. // }
  681. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  682. // fmt.Println(errcode)
  683. // }
  684. // }
  685. // }
  686. // }
  687. //}
  688. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  689. if dialysisPrescription.ID == 0 { //新增
  690. if appRole.UserType == 2 || appRole.UserType == 1 {
  691. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  692. }
  693. prescription.Creater = adminUserInfo.AdminUser.Id
  694. } else { //修改
  695. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  696. //if template.TemplateId == 1 {
  697. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  698. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  699. // if getPermissionErr != nil {
  700. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  701. // return
  702. // } else if headNursePermission == nil {
  703. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  704. // return
  705. // }
  706. // }
  707. //}
  708. if appRole.UserType == 2 || appRole.UserType == 1 {
  709. prescription_doctor := adminUserInfo.AdminUser.Id
  710. prescription.PrescriptionDoctor = prescription_doctor
  711. } else {
  712. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  713. }
  714. if dialysisPrescription.Creater == 0 {
  715. prescription.Creater = adminUserInfo.AdminUser.Id
  716. } else {
  717. prescription.Creater = dialysisPrescription.Creater
  718. }
  719. prescription.CreatedTime = dialysisPrescription.CreatedTime
  720. prescription.UpdatedTime = time.Now().Unix()
  721. prescription.Modifier = adminUserInfo.AdminUser.Id
  722. prescription.ID = dialysisPrescription.ID
  723. }
  724. solution := models.DialysisSolution{
  725. RegistrarsId: adminUserInfo.AdminUser.Id,
  726. UserOrgId: adminUserInfo.CurrentOrgId,
  727. Doctor: prescription_doctor,
  728. PatientId: patient,
  729. ModeId: mode_id,
  730. DialysisDuration: dialysis_duration,
  731. PerfusionApparatus: perfusion_apparatus,
  732. BloodFlowVolume: blood_flow_volume,
  733. Dewater: dewater_amount,
  734. DisplaceLiqui: displace_liqui,
  735. ReplacementWay: replacement_way,
  736. Anticoagulant: anticoagulant,
  737. AnticoagulantShouji: anticoagulant_shouji,
  738. AnticoagulantWeichi: anticoagulant_weichi,
  739. AnticoagulantZongliang: anticoagulant_zongliang,
  740. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  741. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  742. Kalium: kalium,
  743. Sodium: sodium,
  744. Calcium: calcium,
  745. Bicarbonate: bicarbonate,
  746. Glucose: glucose,
  747. // DryWeight: dry_weight,
  748. DialysateFlow: dialysate_flow,
  749. DialysateTemperature: dialysate_temperature,
  750. Conductivity: conductivity,
  751. Remark: remark,
  752. Status: 1,
  753. CreatedTime: time.Now().Unix(),
  754. UpdatedTime: time.Now().Unix(),
  755. DialysisDurationMinute: dialysisDurationMinute,
  756. DialysisDurationHour: dialysisDurationHour,
  757. TargetUltrafiltration: targetUltrafiltration,
  758. DialysateFormulation: dialysateFormulation,
  759. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  760. BodyFluid: body_fluid,
  761. SpecialMedicine: special_medicine,
  762. SpecialMedicineOther: special_medicine_other,
  763. DisplaceLiquiPart: displace_liqui_part,
  764. DisplaceLiquiValue: displace_liqui_value,
  765. BloodAccess: blood_access,
  766. Ultrafiltration: ultrafiltration,
  767. BodyFluidOther: body_fluid_other,
  768. ReplacementTotal: replacement_total,
  769. TargetKtv: target_ktv,
  770. DialysisIrrigation: dialysis_irrigation,
  771. DialysisDialyszers: dialysis_dialyszers,
  772. HemodialysisPipelines: hemodialysis_pipelines,
  773. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  774. PunctureNeedle: puncture_needle,
  775. PunctureNeedleCount: puncture_needle_count,
  776. Epo: epo,
  777. EpoCount: epo_count,
  778. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  779. OxygenUptake: oxygen_uptake,
  780. OxygenFlow: oxygen_flow,
  781. OxygenTime: oxygen_time,
  782. PreImpulse: preImpules,
  783. }
  784. err := service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  785. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  786. redis := service.RedisClient()
  787. //清空key 值
  788. redis.Set(key, "", time.Second)
  789. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  790. //清空key 值
  791. redis.Set(keyOne, "", time.Second)
  792. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  793. redis.Set(keyTwo, "", time.Second)
  794. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  795. redis.Set(keyThree, "", time.Second)
  796. defer redis.Close()
  797. if err == nil {
  798. c.ServeSuccessJSON(map[string]interface{}{
  799. "solution": &solution,
  800. "prescription": &prescription,
  801. })
  802. } else {
  803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  804. }
  805. }
  806. func (c *DialysisApiController) PostDouleCheck() {
  807. id, _ := c.GetInt64("patient", 0)
  808. recordDateStr := c.GetString("record_date")
  809. checkTimeStr := c.GetString("check_time")
  810. firstCheckTimeStr := c.GetString("first_check_time")
  811. creater, _ := c.GetInt64("creater", 0)
  812. modifier, _ := c.GetInt64("modifier", 0)
  813. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  814. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  815. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  816. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  817. dialysis_item_desc := c.GetString("dialysis_item_desc")
  818. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  819. vascular_access_desc := c.GetString("vascular_access_desc")
  820. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  821. collator, _ := c.GetInt64("collator", 0)
  822. employee_number := c.GetString("employee_number")
  823. if id <= 0 {
  824. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  825. return
  826. }
  827. adminUserInfo := c.GetAdminUserInfo()
  828. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  829. if patient.ID == 0 {
  830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  831. return
  832. }
  833. if len(recordDateStr) == 0 {
  834. recordDateStr = time.Now().Format("2006-01-02")
  835. }
  836. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  837. if parseDateErr != nil {
  838. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  839. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  840. return
  841. }
  842. var checkDate int64
  843. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  844. list, _ := service.GetRoleList(adminUserInfo.CurrentOrgId, modifier)
  845. if employee_number != list.JobNumber {
  846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorEmployeeNumber)
  847. return
  848. }
  849. }
  850. if len(checkTimeStr) == 0 {
  851. //checkTimeStr = time.Now().Format("2006-01-02 15:04")
  852. checkDate = 0
  853. } else {
  854. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", checkTimeStr)
  855. checkDate = checkDateUnix.Unix()
  856. }
  857. var firstCheckTimeDate int64
  858. if len(firstCheckTimeStr) == 0 {
  859. //firstCheckTimeStr = time.Now().Format("2006-01-02 15:04")
  860. firstCheckTimeDate = 0
  861. } else {
  862. firstCheckTimeDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", firstCheckTimeStr)
  863. firstCheckTimeDate = firstCheckTimeDateUnix.Unix()
  864. }
  865. doubleCheck := models.DoubleCheck{
  866. UserOrgId: adminUserInfo.CurrentOrgId,
  867. PatientId: id,
  868. DialysisItemCheck: dialysis_item_check,
  869. DialysisParameterCheck: dialysis_parameter_check,
  870. VascularAccessVerification: vascular_access_verification,
  871. PipelineConnectionCheck: pipeline_connection_check,
  872. DialysisItemDesc: dialysis_item_desc,
  873. DialysisParameterDesc: dialysis_parameter_desc,
  874. VascularAccessDesc: vascular_access_desc,
  875. PipelineConnectionDesc: pipeline_connection_desc,
  876. Collator: collator,
  877. Status: 1,
  878. CreatedTime: time.Now().Unix(),
  879. UpdatedTime: time.Now().Unix(),
  880. CheckDate: recordDate.Unix(),
  881. EmployeeNumber: employee_number,
  882. }
  883. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  884. if check.ID == 0 { //新增
  885. doubleCheck.FirstCheckTime = firstCheckTimeDate
  886. doubleCheck.CheckTime = checkDate
  887. doubleCheck.Creater = creater
  888. doubleCheck.Modifier = modifier
  889. err := service.AddSigleDoubleCheck(&doubleCheck)
  890. redis := service.RedisClient()
  891. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  892. //清空key 值
  893. redis.Set(key, "", time.Second)
  894. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  895. redis.Set(keyTwo, "", time.Second)
  896. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  897. redis.Set(keyThree, "", time.Second)
  898. defer redis.Close()
  899. if err == nil {
  900. c.ServeSuccessJSON(map[string]interface{}{
  901. "doubleCheck": doubleCheck,
  902. })
  903. } else {
  904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  905. }
  906. } else { //修改
  907. doubleCheck.FirstCheckTime = firstCheckTimeDate
  908. doubleCheck.CheckTime = checkDate
  909. doubleCheck.Creater = creater
  910. doubleCheck.Modifier = modifier
  911. doubleCheck.CreatedTime = check.CreatedTime
  912. doubleCheck.UpdatedTime = time.Now().Unix()
  913. doubleCheck.ID = check.ID
  914. redis := service.RedisClient()
  915. err := service.UpdateDoubleCheck(&doubleCheck)
  916. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  917. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  918. redis.Set(keyTwo, "", time.Second)
  919. //清空key 值
  920. redis.Set(key, "", time.Second)
  921. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  922. redis.Set(keyThree, "", time.Second)
  923. defer redis.Close()
  924. if err == nil {
  925. c.ServeSuccessJSON(map[string]interface{}{
  926. "doubleCheck": doubleCheck,
  927. })
  928. } else {
  929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  930. }
  931. }
  932. }
  933. func (c *DialysisApiController) PostReceiveTreatmentAsses() {
  934. id, _ := c.GetInt64("patient", 0)
  935. recordDateStr := c.GetString("record_date")
  936. way, _ := c.GetInt64("way", 0)
  937. consciousness, _ := c.GetInt64("consciousness", 0)
  938. appetite, _ := c.GetInt64("appetite", 0)
  939. condition, _ := c.GetInt64("condition", 0)
  940. posture, _ := c.GetInt64("posture")
  941. score := c.GetString("score")
  942. sick_condition, _ := c.GetInt64("sick_condition", 0)
  943. danger_level, _ := c.GetInt64("danger_level", 0)
  944. intake, _ := c.GetInt64("intake", 0)
  945. nutrition, _ := c.GetInt64("nutrition", 0)
  946. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  947. psychological_assessment_other := c.GetString("psychological_assessment_other")
  948. sick_condition_other := c.GetString("sick_condition_other")
  949. //precaution, _ := c.GetInt64("precaution", 0)
  950. precaution := c.GetString("precaution")
  951. precaution_other := c.GetString("precaution_other")
  952. psychological_other := c.GetString("psychological_other")
  953. admission_number := c.GetString("admission_number")
  954. tumble, _ := c.GetInt64("tumble")
  955. if id <= 0 {
  956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  957. return
  958. }
  959. adminUserInfo := c.GetAdminUserInfo()
  960. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  961. if patient.ID == 0 {
  962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  963. return
  964. }
  965. if len(recordDateStr) == 0 {
  966. recordDateStr = time.Now().Format("2006-01-02")
  967. }
  968. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  969. if parseDateErr != nil {
  970. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  972. return
  973. }
  974. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  975. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  976. UserOrgId: adminUserInfo.CurrentOrgId,
  977. PatientId: id,
  978. RecordDate: recordDate.Unix(),
  979. Way: way,
  980. Consciousness: consciousness,
  981. Appetite: appetite,
  982. Condition: condition,
  983. SickCondition: sick_condition,
  984. DangerLevel: danger_level,
  985. Intake: intake,
  986. Nutrition: nutrition,
  987. PsychologicalAssessment: psychological_assessment,
  988. PsychologicalAssessmentOther: psychological_assessment_other,
  989. SickConditionOther: sick_condition_other,
  990. Posture: posture,
  991. CreatedTime: time.Now().Unix(),
  992. UpdateTime: time.Now().Unix(),
  993. Status: 1,
  994. Score: score,
  995. Precaution: precaution,
  996. PrecautionOther: precaution_other,
  997. PsychologicalOther: psychological_other,
  998. AdmissionNumber: admission_number,
  999. Tumble: tumble,
  1000. }
  1001. if receiveTreatment.ID == 0 { //新增
  1002. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1003. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1004. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1005. redis := service.RedisClient()
  1006. //清空key 值
  1007. redis.Set(key, "", time.Second)
  1008. defer redis.Close()
  1009. if err == nil {
  1010. c.ServeSuccessJSON(map[string]interface{}{
  1011. "receiveTreatmentAsses": receiveTreatmentAsses,
  1012. })
  1013. } else {
  1014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1015. }
  1016. } else { //修改
  1017. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1018. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1019. // if getPermissionErr != nil {
  1020. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1021. // return
  1022. // } else if headNursePermission == nil {
  1023. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1024. // return
  1025. // }
  1026. //}
  1027. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1028. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1029. receiveTreatmentAsses.UpdateTime = time.Now().Unix()
  1030. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1031. receiveTreatmentAsses.ID = receiveTreatment.ID
  1032. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1033. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1034. redis := service.RedisClient()
  1035. defer redis.Close()
  1036. redis.Set(keyOne, "", time.Second*60*60*18)
  1037. if err == nil {
  1038. c.ServeSuccessJSON(map[string]interface{}{
  1039. "receiveTreatmentAsses": receiveTreatmentAsses,
  1040. })
  1041. } else {
  1042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1043. }
  1044. }
  1045. }
  1046. func (c *DialysisApiController) PostAssessmentAfterDislysis() {
  1047. patient, _ := c.GetInt64("patient", 0)
  1048. recordDateStr := c.GetString("record_date")
  1049. fmt.Println(recordDateStr)
  1050. if patient <= 0 {
  1051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1052. return
  1053. }
  1054. adminUserInfo := c.GetAdminUserInfo()
  1055. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1056. if patientInfo.ID == 0 {
  1057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1058. return
  1059. }
  1060. if len(recordDateStr) == 0 {
  1061. recordDateStr = time.Now().Format("2006-01-02")
  1062. }
  1063. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1064. if parseDateErr != nil {
  1065. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1067. return
  1068. }
  1069. // data := make(map[string]interface{}, 0)
  1070. var data models.AssessmentAfterDislysis
  1071. var err error
  1072. err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
  1073. fmt.Println(err)
  1074. if err != nil {
  1075. c.ErrorLog("数据解析错误:%v", err)
  1076. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1077. return
  1078. }
  1079. assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1080. assessment.DialysisOrderId = data.DialysisOrderId
  1081. assessment.Evaluator = adminUserInfo.AdminUser.Id
  1082. assessment.Status = 1
  1083. assessment.WeightAfter = data.WeightAfter
  1084. assessment.WeightLoss = data.WeightLoss
  1085. assessment.Temperature = data.Temperature
  1086. assessment.SystolicBloodPressure = data.SystolicBloodPressure
  1087. assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
  1088. assessment.PulseFrequency = data.PulseFrequency
  1089. assessment.ActualUltrafiltration = data.ActualUltrafiltration
  1090. assessment.ActualDisplacement = data.ActualDisplacement
  1091. assessment.ActualTreatmentHour = data.ActualTreatmentHour
  1092. assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
  1093. assessment.Cruor = data.Cruor
  1094. assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
  1095. assessment.DialysisIntakes = data.DialysisIntakes
  1096. assessment.InternalFistula = data.InternalFistula
  1097. assessment.BloodAccessPartId = data.BloodAccessPartId
  1098. assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
  1099. assessment.Catheter = data.Catheter
  1100. assessment.Complication = data.Complication
  1101. assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
  1102. assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
  1103. assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
  1104. assessment.PatientGose = data.PatientGose
  1105. assessment.InpatientDepartment = data.InpatientDepartment
  1106. assessment.ObservationContent = data.ObservationContent
  1107. assessment.ObservationContentOther = data.ObservationContentOther
  1108. assessment.Remark = data.Remark
  1109. assessment.BreathingRate = data.BreathingRate
  1110. assessment.DialysisProcess = data.DialysisProcess
  1111. assessment.InAdvanceMinute = data.InAdvanceMinute
  1112. assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
  1113. assessment.InAdvanceReason = data.InAdvanceReason
  1114. assessment.HemostasisOpera = data.HemostasisOpera
  1115. assessment.HemostasisMinute = data.HemostasisMinute
  1116. assessment.TremorNoise = data.TremorNoise
  1117. assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
  1118. assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
  1119. assessment.ArterialTube = data.ArterialTube
  1120. assessment.IntravenousTube = data.IntravenousTube
  1121. assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
  1122. assessment.Dialyzer = data.Dialyzer
  1123. assessment.IsEat = data.IsEat
  1124. assessment.CvcA = data.CvcA
  1125. assessment.CvcV = data.CvcV
  1126. assessment.Channel = data.Channel
  1127. assessment.ReturnBlood = data.ReturnBlood
  1128. assessment.RehydrationVolume = data.RehydrationVolume
  1129. assessment.DialysisDuring = data.DialysisDuring
  1130. assessment.StrokeVolume = data.StrokeVolume
  1131. assessment.BloodFlow = data.BloodFlow
  1132. assessment.SealingFluidDispose = data.SealingFluidDispose
  1133. assessment.SealingFluidSpecial = data.SealingFluidSpecial
  1134. assessment.DosageOfAnticoagulants = data.DosageOfAnticoagulants
  1135. assessment.SupineSystolicBloodPressure = data.SupineSystolicBloodPressure
  1136. assessment.SettingPressure = data.SettingPressure
  1137. assessment.SupineDiastolicBloodPressure = data.SupineDiastolicBloodPressure
  1138. assessment.DiastolicPressure = data.DiastolicPressure
  1139. assessment.AdditionalWeight = data.AdditionalWeight
  1140. assessment.OtherComplication = data.OtherComplication
  1141. assessment.Ktv = data.Ktv
  1142. assessment.Urr = data.Urr
  1143. assessment.Hypertenison = data.Hypertenison
  1144. assessment.Hypopiesia = data.Hypopiesia
  1145. assessment.LeaveOfficeMethod = data.LeaveOfficeMethod
  1146. assessment.Lapse = data.Lapse
  1147. assessment.Consciousness = data.Consciousness
  1148. assessment.Fallrisk = data.Fallrisk
  1149. assessment.MachineRun = data.MachineRun
  1150. assessment.AfterUrea = data.AfterUrea
  1151. assessment.PipCoagulation = data.PipCoagulation
  1152. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1153. if assessment.ID > 0 {
  1154. if appRole.UserType == 2 || appRole.UserType == 1 {
  1155. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1156. assessment.AssessmentTime = time.Now().Unix()
  1157. } else {
  1158. if assessment.Creater == 0 {
  1159. assessment.Modifier = adminUserInfo.AdminUser.Id
  1160. assessment.Creater = adminUserInfo.AdminUser.Id
  1161. } else {
  1162. assessment.Modifier = adminUserInfo.AdminUser.Id
  1163. }
  1164. }
  1165. assessment.UpdatedTime = time.Now().Unix()
  1166. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  1167. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1168. redis := service.RedisClient()
  1169. //清空key 值
  1170. redis.Set(key, "", time.Second)
  1171. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1172. redis.Set(keyThree, "", time.Second)
  1173. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1174. redis.Set(keyTwo, "", time.Second)
  1175. defer redis.Close()
  1176. } else {
  1177. if appRole.UserType == 2 || appRole.UserType == 1 {
  1178. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1179. assessment.AssessmentTime = time.Now().Unix()
  1180. } else {
  1181. assessment.Creater = adminUserInfo.AdminUser.Id
  1182. }
  1183. assessment.CreatedTime = time.Now().Unix()
  1184. assessment.UpdatedTime = time.Now().Unix()
  1185. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  1186. assessment.PatientId = patient
  1187. assessment.AssessmentDate = recordDate.Unix()
  1188. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  1189. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1190. redis := service.RedisClient()
  1191. //清空key 值
  1192. redis.Set(key, "", time.Second)
  1193. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1194. redis.Set(keyThree, "", time.Second)
  1195. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1196. redis.Set(keyTwo, "", time.Second)
  1197. defer redis.Close()
  1198. }
  1199. if err != nil {
  1200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1201. return
  1202. }
  1203. c.ServeSuccessJSON(map[string]interface{}{
  1204. "AssessmentAfterDislysis": &assessment,
  1205. })
  1206. }
  1207. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  1208. patient, _ := c.GetInt64("patient", 0)
  1209. recordDateStr := c.GetString("record_date")
  1210. if patient <= 0 {
  1211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1212. return
  1213. }
  1214. adminUserInfo := c.GetAdminUserInfo()
  1215. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1216. if patientInfo.ID == 0 {
  1217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1218. return
  1219. }
  1220. if len(recordDateStr) == 0 {
  1221. recordDateStr = time.Now().Format("2006-01-02")
  1222. }
  1223. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1224. if parseDateErr != nil {
  1225. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1227. return
  1228. }
  1229. weight_before, _ := c.GetFloat("weight_before", 0)
  1230. dry_weight, _ := c.GetFloat("dry_weight", 0)
  1231. additional_weight, _ := c.GetFloat("additional_weight", 0)
  1232. temperature, _ := c.GetFloat("temperature", 0)
  1233. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1234. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1235. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1236. last_post_dialysis := c.GetString("last_post_dialysis")
  1237. dialysis_interphase := c.GetString("dialysis_interphase")
  1238. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  1239. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1240. //bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  1241. bloodAccessPartId := c.GetString("blood_access_part_id")
  1242. internalFistula := c.GetString("internal_fistula")
  1243. internal_fistula_skin := c.GetString("internal_fistula_skin")
  1244. catheter := c.GetString("catheter")
  1245. catheter_bend, _ := c.GetInt("catheter_bend")
  1246. complication := c.GetString("complication")
  1247. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  1248. hemorrhage := c.GetString("hemorrhage")
  1249. hemorrhage_other := c.GetString("hemorrhage_other")
  1250. remark := c.GetString("remark")
  1251. puncture_method := c.GetString("puncture_method")
  1252. dialysis_count := c.GetString("dialysis_count")
  1253. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  1254. emergency_treatment_other := c.GetString("emergency_treatment_other")
  1255. ductus_arantii := c.GetString("ductus_arantii")
  1256. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  1257. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  1258. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  1259. //puncture_way, _ := c.GetInt64("puncture_way", 0)
  1260. puncture_way := c.GetString("puncture_way")
  1261. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  1262. internal_fistula_other := c.GetString("internal_fistula_other")
  1263. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  1264. //breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  1265. breathing_rate := c.GetString("breathing_rate")
  1266. is_infect, _ := c.GetInt64("is_infect", 0)
  1267. exposed, _ := c.GetFloat("exposed", 0)
  1268. skin := c.GetString("skin")
  1269. skin_other := c.GetString("skin_other")
  1270. infect_other := c.GetString("infect_other")
  1271. ductus_arantii_other := c.GetString("ductus_arantii_other")
  1272. machine_type := c.GetString("machine_type")
  1273. puncture_needle := c.GetString("puncture_needle")
  1274. //humor_excessive_symptom, _ := c.GetInt64("humor_excessive_symptom", 0)
  1275. humor_excessive_symptom := c.GetString("humor_excessive_symptom")
  1276. phinholing := c.GetString("pinholing")
  1277. catheter_suture := c.GetString("catheter_suture")
  1278. catheter_suture_other := c.GetString("catheter_suture_other")
  1279. edema := c.GetString("edema")
  1280. urine_volume, _ := c.GetFloat("urine_volume", 0)
  1281. special_treatment := c.GetString("special_treatment")
  1282. catheter_maintenance := c.GetString("catheter_maintenance")
  1283. thrombusType := c.GetString("thromubus_type")
  1284. thrombusInt, _ := strconv.ParseInt(thrombusType, 10, 64)
  1285. thrombus_a := c.GetString("thromubus_a")
  1286. thrombus_av := c.GetString("thrombus_av")
  1287. thrombus_v := c.GetString("thromubus_v")
  1288. dehydration := c.GetString("dehydration")
  1289. pre_dialysis_drugs := c.GetString("pre_dialysis_drugs")
  1290. period, _ := c.GetInt64("period")
  1291. estimated_food_intake := c.GetString("estimated_food_intake")
  1292. blood_pressure_during_dialysis := c.GetString("blood_pressure_during_dialysis")
  1293. urea_befor := c.GetString("urea_befor")
  1294. suction := c.GetString("suction")
  1295. assessmentBeforeDislysis := models.PredialysisEvaluation{
  1296. DialysisCount: dialysis_count,
  1297. EmergencyTreatment: emergency_treatment,
  1298. EmergencyTreatmentOther: emergency_treatment_other,
  1299. DuctusArantii: ductus_arantii,
  1300. VenousCatheterization: venous_catheterization,
  1301. VenousCatheterizationPart: venous_catheterization_part,
  1302. VenousCatheterizationPartOther: venous_catheterization_part_other,
  1303. PunctureWay: puncture_way,
  1304. BloodAccessInternalFistula: blood_access_internal_fistula,
  1305. BloodAccessNoise: blood_access_noise,
  1306. InternalFistulaOther: internal_fistula_other,
  1307. Evaluator: adminUserInfo.AdminUser.Id,
  1308. UserOrgId: adminUserInfo.CurrentOrgId,
  1309. PatientId: patient,
  1310. AssessmentDate: recordDate.Unix(),
  1311. Temperature: temperature,
  1312. PulseFrequency: pulse_frequency,
  1313. SystolicBloodPressure: systolic_blood_pressure,
  1314. DiastolicBloodPressure: diastolic_blood_pressure,
  1315. WeightBefore: weight_before,
  1316. DryWeight: dry_weight,
  1317. AdditionalWeight: additional_weight,
  1318. DialysisInterphase: dialysis_interphase,
  1319. LastPostDialysis: last_post_dialysis,
  1320. SymptomBeforeDialysis: symptom_before_dialysis,
  1321. InternalFistula: internalFistula,
  1322. InternalFistulaSkin: internal_fistula_skin,
  1323. Catheter: catheter,
  1324. CatheterBend: catheter_bend,
  1325. Complication: complication,
  1326. CreatedTime: time.Now().Unix(),
  1327. Status: 1,
  1328. Remark: remark,
  1329. IsHemorrhage: is_hemorrhage,
  1330. Hemorrhage: hemorrhage,
  1331. HemorrhageOther: hemorrhage_other,
  1332. BloodAccessPartId: bloodAccessPartId,
  1333. BloodAccessPartOperaId: bloodAccessPartOperaId,
  1334. PunctureMethod: puncture_method,
  1335. BreathingRate: breathing_rate,
  1336. IsInfect: is_infect,
  1337. Exposed: exposed,
  1338. Skin: skin,
  1339. SkinOther: skin_other,
  1340. InfectOther: infect_other,
  1341. DuctusArantiiOther: ductus_arantii_other,
  1342. MachineType: machine_type,
  1343. PunctureNeedle: puncture_needle,
  1344. HumorExcessiveSymptom: humor_excessive_symptom,
  1345. Phinholing: phinholing,
  1346. CatheterSuture: catheter_suture,
  1347. CatheterSutureOther: catheter_suture_other,
  1348. Edema: edema,
  1349. UrineVolume: urine_volume,
  1350. SpecialTreatment: special_treatment,
  1351. CatheterMaintenance: catheter_maintenance,
  1352. ThromubusType: thrombusInt,
  1353. ThrombusAv: thrombus_av,
  1354. ThromubusA: thrombus_a,
  1355. ThromubusV: thrombus_v,
  1356. Dehydration: dehydration,
  1357. PreDialysisDrugs: pre_dialysis_drugs,
  1358. Period: period,
  1359. EstimatedFoodIntake: estimated_food_intake,
  1360. BloodPressureDuringDialysis: blood_pressure_during_dialysis,
  1361. UreaBefor: urea_befor,
  1362. Suction: suction,
  1363. }
  1364. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1365. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1366. if evaluation.ID == 0 { //新增
  1367. if appRole.UserType == 2 || appRole.UserType == 1 {
  1368. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1369. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1370. } else {
  1371. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  1372. }
  1373. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  1374. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1375. redis := service.RedisClient()
  1376. //清空key 值
  1377. redis.Set(key, "", time.Second)
  1378. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1379. redis.Set(keyOne, "", time.Second)
  1380. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1381. redis.Set(keyTwo, "", time.Second)
  1382. defer redis.Close()
  1383. if err == nil {
  1384. c.ServeSuccessJSON(map[string]interface{}{
  1385. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  1386. })
  1387. } else {
  1388. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1390. }
  1391. } else { //修改
  1392. //if appRole.UserType == 3 {
  1393. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  1394. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1395. // if getPermissionErr != nil {
  1396. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1397. // return
  1398. // } else if headNursePermission == nil {
  1399. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1400. // return
  1401. // }
  1402. // }
  1403. //}
  1404. if appRole.UserType == 2 || appRole.UserType == 1 {
  1405. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1406. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1407. } else {
  1408. if evaluation.Creater == 0 {
  1409. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  1410. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  1411. } else {
  1412. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  1413. }
  1414. }
  1415. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  1416. assessmentBeforeDislysis.ID = evaluation.ID
  1417. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  1418. //
  1419. //新增逻辑
  1420. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  1421. var dewater_amount float64
  1422. dewater_amount = 0
  1423. if evaluation.DryWeight > 0 {
  1424. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  1425. if templateInfo.TemplateId == 17 || templateInfo.TemplateId == 22 || templateInfo.TemplateId == 21 || templateInfo.TemplateId == 34 {
  1426. dewater_amount = dewater_amount * 1000
  1427. }
  1428. if dewater_amount <= 0 {
  1429. dewater_amount = 0
  1430. }
  1431. } else {
  1432. dewater_amount = 0
  1433. }
  1434. // 计算透析处方的相关超滤量
  1435. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1436. var lastDialysisPrescribe *models.DialysisPrescription
  1437. var dialysisSolution *models.DialysisSolution
  1438. var dialysisPrescribe *models.DialysisPrescription
  1439. var mode_id int64
  1440. if schedual != nil {
  1441. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  1442. if dialysisPrescribe == nil {
  1443. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1444. }
  1445. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1446. // 获取透析模版
  1447. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1448. mode_id = schedual.ModeId
  1449. } else {
  1450. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  1451. // 获取透析模版
  1452. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1453. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  1454. if dialysisPrescribe == nil && dialysisSolution != nil {
  1455. mode_id = dialysisSolution.ModeId
  1456. }
  1457. if dialysisPrescribe == nil && dialysisSolution == nil {
  1458. mode_id = 0
  1459. }
  1460. }
  1461. // 插入透析处方
  1462. if dialysisPrescribe == nil && dialysisSolution != nil {
  1463. var newprescribe models.DialysisPrescription
  1464. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1465. newprescribe.PatientId = dialysisSolution.PatientId
  1466. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1467. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1468. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1469. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1470. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1471. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1472. newprescribe.ModeId = dialysisSolution.ModeId
  1473. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1474. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1475. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1476. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1477. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1478. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1479. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1480. newprescribe.Glucose = dialysisSolution.Glucose
  1481. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1482. newprescribe.Kalium = dialysisSolution.Kalium
  1483. newprescribe.Sodium = dialysisSolution.Sodium
  1484. newprescribe.Calcium = dialysisSolution.Calcium
  1485. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1486. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1487. newprescribe.Conductivity = dialysisSolution.Conductivity
  1488. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1489. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1490. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1491. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1492. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1493. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1494. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1495. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1496. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1497. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1498. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1499. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1500. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1501. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1502. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1503. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1504. newprescribe.CreatedTime = time.Now().Unix()
  1505. newprescribe.UpdatedTime = time.Now().Unix()
  1506. newprescribe.RecordDate = recordDate.Unix()
  1507. newprescribe.DewaterAmount = dewater_amount
  1508. newprescribe.TargetUltrafiltration = dewater_amount
  1509. newprescribe.Status = 1
  1510. err := service.AddSigleRecord(&newprescribe)
  1511. if err != nil {
  1512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1513. }
  1514. }
  1515. if dialysisPrescribe == nil && dialysisSolution == nil {
  1516. if lastDialysisPrescribe != nil {
  1517. var newprescribe models.DialysisPrescription
  1518. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  1519. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  1520. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  1521. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  1522. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  1523. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  1524. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  1525. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  1526. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  1527. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  1528. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  1529. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  1530. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  1531. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  1532. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  1533. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  1534. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  1535. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  1536. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  1537. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  1538. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  1539. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  1540. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  1541. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  1542. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  1543. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  1544. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  1545. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  1546. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  1547. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  1548. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  1549. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  1550. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  1551. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  1552. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  1553. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  1554. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  1555. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  1556. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  1557. newprescribe.CreatedTime = time.Now().Unix()
  1558. newprescribe.UpdatedTime = time.Now().Unix()
  1559. newprescribe.RecordDate = recordDate.Unix()
  1560. newprescribe.DewaterAmount = dewater_amount
  1561. newprescribe.TargetUltrafiltration = dewater_amount
  1562. newprescribe.Status = 1
  1563. err := service.AddSigleRecord(&newprescribe)
  1564. if err != nil {
  1565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1566. }
  1567. } else {
  1568. var newprescribe models.DialysisPrescription
  1569. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  1570. newprescribe.PatientId = patient
  1571. newprescribe.ModeId = mode_id
  1572. newprescribe.CreatedTime = time.Now().Unix()
  1573. newprescribe.UpdatedTime = time.Now().Unix()
  1574. newprescribe.RecordDate = recordDate.Unix()
  1575. newprescribe.DewaterAmount = dewater_amount
  1576. newprescribe.TargetUltrafiltration = dewater_amount
  1577. newprescribe.Status = 1
  1578. err := service.AddSigleRecord(&newprescribe)
  1579. if err != nil {
  1580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1581. }
  1582. }
  1583. }
  1584. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  1585. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1586. redis := service.RedisClient()
  1587. //清空key 值
  1588. redis.Set(key, "", time.Second)
  1589. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1590. redis.Set(keyOne, "", time.Second)
  1591. defer redis.Close()
  1592. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1593. redis.Set(keyTwo, "", time.Second)
  1594. if err == nil {
  1595. c.ServeSuccessJSON(map[string]interface{}{
  1596. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  1597. })
  1598. } else {
  1599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1600. }
  1601. }
  1602. }
  1603. func (c *DialysisApiController) PostTreatmentSummary() {
  1604. patient, _ := c.GetInt64("patient", 0)
  1605. recordDateStr := c.GetString("record_date")
  1606. if patient <= 0 {
  1607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1608. return
  1609. }
  1610. adminUserInfo := c.GetAdminUserInfo()
  1611. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1612. if patientInfo.ID == 0 {
  1613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1614. return
  1615. }
  1616. if len(recordDateStr) == 0 {
  1617. recordDateStr = time.Now().Format("2006-01-02")
  1618. }
  1619. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1620. if parseDateErr != nil {
  1621. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1623. return
  1624. }
  1625. mission := c.GetString("mission")
  1626. dialysis_summary := c.GetString("dialysis_summary")
  1627. nursingRecord := c.GetString("nursing_record")
  1628. specialRecord := c.GetString("special_record")
  1629. sj_nurse := adminUserInfo.AdminUser.Id
  1630. zl_nurse := adminUserInfo.AdminUser.Id
  1631. hd_nurse := adminUserInfo.AdminUser.Id
  1632. xj_nurse := adminUserInfo.AdminUser.Id
  1633. zl_doctor := adminUserInfo.AdminUser.Id
  1634. treatmentSummary := models.TreatmentSummary{
  1635. UserOrgId: adminUserInfo.CurrentOrgId,
  1636. PatientId: patient,
  1637. AssessmentDate: recordDate.Unix(),
  1638. Mission: mission,
  1639. DialysisSummary: dialysis_summary,
  1640. SjNurse: sj_nurse,
  1641. ZlNurse: zl_nurse,
  1642. HdNurse: hd_nurse,
  1643. XjNurse: xj_nurse,
  1644. ZlDoctor: zl_doctor,
  1645. Status: 1,
  1646. CreatedTime: time.Now().Unix(),
  1647. NursingRecord: nursingRecord,
  1648. SpecialRecord: specialRecord,
  1649. }
  1650. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1651. if tempTreatmentSummary.ID == 0 { //新增
  1652. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  1653. err := service.AddSigleSummaryRecord(&treatmentSummary)
  1654. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  1655. redis := service.RedisClient()
  1656. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  1657. redis.Set(keyOne, "", time.Second)
  1658. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1659. redis.Set(keyThree, "", time.Second)
  1660. defer redis.Close()
  1661. //清空key 值
  1662. redis.Set(key, "", time.Second)
  1663. if err == nil {
  1664. c.ServeSuccessJSON(map[string]interface{}{
  1665. "summary": treatmentSummary,
  1666. })
  1667. } else {
  1668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1669. }
  1670. } else { //修改
  1671. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  1672. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1673. // if getPermissionErr != nil {
  1674. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1675. // return
  1676. // } else if headNursePermission == nil {
  1677. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1678. // return
  1679. // }
  1680. //}
  1681. treatmentSummary.Creater = tempTreatmentSummary.Creater
  1682. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  1683. treatmentSummary.UpdatedTime = time.Now().Unix()
  1684. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  1685. treatmentSummary.ID = tempTreatmentSummary.ID
  1686. err := service.UpdateSummeRecord(&treatmentSummary)
  1687. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  1688. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  1689. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1690. //清空key 值
  1691. redis := service.RedisClient()
  1692. redis.Set(key, "", time.Second)
  1693. redis.Set(keyOne, "", time.Second)
  1694. redis.Set(keyThree, "", time.Second)
  1695. defer redis.Close()
  1696. if err == nil {
  1697. c.ServeSuccessJSON(map[string]interface{}{
  1698. "summary": treatmentSummary,
  1699. })
  1700. } else {
  1701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1702. }
  1703. }
  1704. }
  1705. func (c *DialysisApiController) GetDeviceList() {
  1706. adminUserInfo := c.GetAdminUserInfo()
  1707. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  1708. c.ServeSuccessJSON(map[string]interface{}{
  1709. "device": device,
  1710. })
  1711. }
  1712. func (c *DialysisApiController) GetAllDeviceZone() {
  1713. adminUserInfo := c.GetAdminUserInfo()
  1714. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  1715. dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1716. if err == nil {
  1717. c.ServeSuccessJSON(map[string]interface{}{
  1718. "zone": zone,
  1719. "dics": dics,
  1720. })
  1721. }
  1722. }
  1723. func (c *DialysisApiController) GetDialysisWatch() {
  1724. page, _ := c.GetInt64("page", 1)
  1725. limit, _ := c.GetInt64("limit", 10)
  1726. schedulType, _ := c.GetInt64("schedul_type", 0)
  1727. startTime, _ := c.GetInt64("schedul_time", 0)
  1728. partitionType, _ := c.GetInt64("partition_type", 0)
  1729. keywords := c.GetString("keywords")
  1730. start_time, _ := c.GetInt64("start_time")
  1731. end_time, _ := c.GetInt64("end_time")
  1732. adminUserInfo := c.GetAdminUserInfo()
  1733. if len(keywords) > 0 {
  1734. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  1735. if err == nil {
  1736. c.ServeSuccessJSON(map[string]interface{}{
  1737. "schedule": dialysisSchedule,
  1738. "total": total,
  1739. })
  1740. } else {
  1741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1742. }
  1743. } else {
  1744. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  1745. if err == nil {
  1746. c.ServeSuccessJSON(map[string]interface{}{
  1747. "schedule": dialysisSchedule,
  1748. "total": total,
  1749. })
  1750. } else {
  1751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1752. }
  1753. }
  1754. }
  1755. //func (c *DialysisApiController) GetDialysisWatch() {
  1756. // page, _ := c.GetInt64("page", 1)
  1757. // limit, _ := c.GetInt64("limit", 10)
  1758. // schedulType, _ := c.GetInt64("schedul_type", 0)
  1759. // startTime, _ := c.GetInt64("schedul_time", 0)
  1760. // partitionType, _ := c.GetInt64("partition_type", 0)
  1761. // keywords := c.GetString("keywords")
  1762. //
  1763. // adminUserInfo := c.GetAdminUserInfo()
  1764. // if len(keywords) > 0 {
  1765. // dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  1766. //
  1767. // //获取所有床位号
  1768. // numberList, _ := service.GetAllDeviceNumberByListSix(adminUserInfo.CurrentOrgId)
  1769. //
  1770. // //获取透析处方
  1771. // prescriptions, _ := service.GetAllPrescriptionByListTwo(adminUserInfo.CurrentOrgId, startTime)
  1772. // //获取透前评估
  1773. // assessmentBefores, _ := service.GetAllAssessmentBeforesByListThree(adminUserInfo.CurrentOrgId, startTime)
  1774. // //获取上机
  1775. // dialysisOrders, _ := service.GetAllDialysisOrdersByListThree(adminUserInfo.CurrentOrgId, startTime)
  1776. // //获取透后
  1777. // AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListThree(adminUserInfo.CurrentOrgId, startTime)
  1778. //
  1779. // //获取透后监测
  1780. // monitorlist, _ := service.GetAllMonitorListThree(adminUserInfo.CurrentOrgId, startTime)
  1781. //
  1782. // //获取所有的患者
  1783. // patients, _ := service.GetAllPatientListByListSix(adminUserInfo.CurrentOrgId,keywords)
  1784. //
  1785. // //获取所有透析模式
  1786. // treatments, _ := service.GetAllTreatModeByList(adminUserInfo.CurrentOrgId)
  1787. //
  1788. // for key, scheduals := range dialysisSchedule {
  1789. // // 获取患者信息
  1790. // for _, patient := range patients {
  1791. // if scheduals.PatientId == patient.ID {
  1792. // dialysisSchedule[key].MonitorPatients = patient
  1793. // break
  1794. // }
  1795. // }
  1796. // // 床位信息
  1797. // for _, device := range numberList {
  1798. // if scheduals.BedId == device.ID {
  1799. // dialysisSchedule[key].DeviceNumber = device
  1800. // break
  1801. // }
  1802. // }
  1803. //
  1804. // // 医嘱信息
  1805. // for _, prescription := range prescriptions {
  1806. // if scheduals.PatientId == prescription.PatientId {
  1807. // dialysisSchedule[key].Prescription = prescription
  1808. // break
  1809. // }
  1810. // }
  1811. //
  1812. // // 透前评估
  1813. // for _, assessmentBefore := range assessmentBefores {
  1814. // if scheduals.PatientId == assessmentBefore.PatientId {
  1815. // dialysisSchedule[key].AssessmentBeforeDislysis = assessmentBefore
  1816. // break
  1817. // }
  1818. // }
  1819. //
  1820. // // 透析上下机
  1821. // for _, dialysisOrder := range dialysisOrders {
  1822. // if scheduals.PatientId == dialysisOrder.PatientId {
  1823. // dialysisSchedule[key].DialysisOrder = dialysisOrder
  1824. // break
  1825. // }
  1826. // }
  1827. //
  1828. // records := make([]*models.MonitoringRecord, 0)
  1829. // // 透析监测
  1830. // for _, it := range monitorlist {
  1831. // records := append(records, it)
  1832. // if scheduals.PatientId == it.PatientId {
  1833. // dialysisSchedule[key].MonitoringRecord = records
  1834. // }
  1835. // }
  1836. //
  1837. // // 透后评估
  1838. // for _, afterDislysis := range AssessmentAfterDislysis {
  1839. // if scheduals.PatientId == afterDislysis.PatientId {
  1840. // dialysisSchedule[key].AssessmentAfterDislysis = afterDislysis
  1841. // break
  1842. // }
  1843. // }
  1844. //
  1845. // //透析模式
  1846. // for _, treatment := range treatments {
  1847. // if scheduals.ModeId == treatment.ID {
  1848. // dialysisSchedule[key].TreatmentMode = treatment
  1849. // break
  1850. // }
  1851. // }
  1852. // }
  1853. // //获取所有床位号
  1854. // if err == nil {
  1855. // c.ServeSuccessJSON(map[string]interface{}{
  1856. // "schedule": dialysisSchedule,
  1857. // "total": total,
  1858. // })
  1859. // } else {
  1860. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1861. // }
  1862. //
  1863. // } else {
  1864. // dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  1865. // if err == nil {
  1866. // c.ServeSuccessJSON(map[string]interface{}{
  1867. // "schedule": dialysisSchedule,
  1868. // "total": total,
  1869. // })
  1870. // } else {
  1871. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1872. // }
  1873. // }
  1874. //}
  1875. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  1876. patientId, _ := c.GetInt64("id", 0)
  1877. record_date, _ := c.GetInt64("record_date", 0)
  1878. adminUserInfo := c.GetAdminUserInfo()
  1879. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1880. var dialysisStatus int64
  1881. if dialysisOrder == nil { //没有透析记录
  1882. dialysisStatus = 0 //未透析
  1883. } else {
  1884. dialysisStatus = dialysisOrder.Stage
  1885. }
  1886. //用户基本信息
  1887. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1888. //接诊评估
  1889. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1890. //透前评估
  1891. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1892. //临时医嘱
  1893. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1894. //双人核对
  1895. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1896. //透析监测
  1897. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  1898. //透后评估
  1899. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1900. //透析小结
  1901. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1902. //透析处方
  1903. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1904. if dialysisPrescription.ID == 0 {
  1905. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  1906. c.ServeSuccessJSON(map[string]interface{}{
  1907. "patientInfo": schedualPatientInfo,
  1908. "dialysisPrescription": solution,
  1909. "receiverTreatmentAccess": receiverTreatmentAccess,
  1910. "predialysisEvaluation": PredialysisEvaluation,
  1911. "doctorAdvice": DoctorAdvice,
  1912. "doubleCheck": DoubleCheck,
  1913. "assessmentAfterDislysis": AssessmentAfterDislysis,
  1914. "treatmentSummary": TreatmentSummary,
  1915. "monitorRecord": Record,
  1916. "dialysisStatus": dialysisStatus,
  1917. "dialysisOrder": dialysisOrder,
  1918. "isSolution": 1,
  1919. })
  1920. } else {
  1921. c.ServeSuccessJSON(map[string]interface{}{
  1922. "patientInfo": schedualPatientInfo,
  1923. "dialysisPrescription": dialysisPrescription,
  1924. "receiverTreatmentAccess": receiverTreatmentAccess,
  1925. "predialysisEvaluation": PredialysisEvaluation,
  1926. "doctorAdvice": DoctorAdvice,
  1927. "doubleCheck": DoubleCheck,
  1928. "assessmentAfterDislysis": AssessmentAfterDislysis,
  1929. "treatmentSummary": TreatmentSummary,
  1930. "monitorRecord": Record,
  1931. "dialysisStatus": dialysisStatus,
  1932. "dialysisOrder": dialysisOrder,
  1933. "isSolution": 2,
  1934. })
  1935. }
  1936. }
  1937. func (c *DialysisApiController) CreateDoctorAdvice() {
  1938. patient, _ := c.GetInt64("id", 0)
  1939. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  1940. record_date, _ := c.GetInt64("record_date", 0)
  1941. if patient <= 0 {
  1942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1943. return
  1944. }
  1945. adminUserInfo := c.GetAdminUserInfo()
  1946. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1947. if patientInfo.ID == 0 {
  1948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1949. return
  1950. }
  1951. var advice models.DoctorAdvice
  1952. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  1953. if code > 0 {
  1954. c.ServeFailJSONWithSGJErrorCode(code)
  1955. return
  1956. }
  1957. if advice.ParentId > 0 {
  1958. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  1959. if old.ID == 0 || old.PatientId != patient {
  1960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1961. return
  1962. }
  1963. if old.StopState == 1 || old.ExecutionState == 1 {
  1964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1965. return
  1966. }
  1967. if old.ParentId > 0 {
  1968. advice.ParentId = old.ParentId
  1969. }
  1970. advice.StartTime = old.StartTime
  1971. advice.AdviceDoctor = old.AdviceDoctor
  1972. advice.DeliveryWay = old.DeliveryWay
  1973. advice.ExecutionFrequency = old.ExecutionFrequency
  1974. }
  1975. advice.RecordDate = record_date
  1976. advice.DialysisOrderId = dialysis_id
  1977. advice.Status = 1
  1978. advice.CreatedTime = time.Now().Unix()
  1979. advice.UpdatedTime = time.Now().Unix()
  1980. advice.StopState = 2
  1981. advice.ExecutionState = 2
  1982. advice.AdviceType = 2
  1983. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1984. advice.PatientId = patient
  1985. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1986. err := service.CreateDoctorAdvice(&advice)
  1987. if err != nil {
  1988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1989. return
  1990. }
  1991. for _, subAdvice := range subAdivice {
  1992. subAdvice.ParentId = advice.ID
  1993. subAdvice.PatientId = patient
  1994. subAdvice.RecordDate = record_date
  1995. subAdvice.CreatedTime = time.Now().Unix()
  1996. subAdvice.UpdatedTime = time.Now().Unix()
  1997. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  1998. }
  1999. service.CreateSubDoctorAdvice(subAdivice)
  2000. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  2001. c.ServeSuccessJSON(map[string]interface{}{
  2002. "msg": "ok",
  2003. "advice": advice,
  2004. "subAdvice": subAdivices,
  2005. })
  2006. return
  2007. }
  2008. func (c *DialysisApiController) EditDoctorAdvice() {
  2009. patient, _ := c.GetInt64("patient", 0)
  2010. id, _ := c.GetInt64("id", 0)
  2011. parent_id, _ := c.GetInt64("parent_id", 0)
  2012. execution_time := c.GetString("execution_time")
  2013. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  2014. // checker, _ := c.GetInt64("checker", 0)
  2015. if id <= 0 || patient <= 0 {
  2016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2017. return
  2018. }
  2019. adminUserInfo := c.GetAdminUserInfo()
  2020. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2021. if advice.ID == 0 || advice.PatientId != patient {
  2022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2023. return
  2024. }
  2025. if len(execution_time) <= 0 {
  2026. utils.ErrorLog("execution_time")
  2027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2028. return
  2029. }
  2030. execution_staff := adminUserInfo.AdminUser.Id
  2031. checker := adminUserInfo.AdminUser.Id
  2032. timeLayout2 := "2006-01-02 15:04"
  2033. loc, _ := time.LoadLocation("Local")
  2034. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  2035. if errs != nil {
  2036. utils.ErrorLog(errs.Error())
  2037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2038. return
  2039. }
  2040. advices := models.DoctorAdvice{
  2041. ExecutionStaff: execution_staff,
  2042. ExecutionTime: theTime.Unix(),
  2043. Checker: checker,
  2044. UpdatedTime: time.Now().Unix(),
  2045. }
  2046. var err error
  2047. if parent_id > 0 {
  2048. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  2049. } else {
  2050. err = service.ExceDoctorAdviceById(&advices, id, patient)
  2051. }
  2052. if err != nil {
  2053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2054. return
  2055. }
  2056. c.ServeSuccessJSON(map[string]interface{}{
  2057. "msg": "ok",
  2058. "advice": advice,
  2059. })
  2060. return
  2061. }
  2062. func (c *DialysisApiController) GetDoctorAdvice() {
  2063. patient, _ := c.GetInt64("patient_id", 0)
  2064. parent_id, _ := c.GetInt64("parent_id", 0)
  2065. adviceId, _ := c.GetInt64("id", 0)
  2066. if patient <= 0 {
  2067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2068. return
  2069. }
  2070. dminUserInfo := c.GetAdminUserInfo()
  2071. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  2072. if patientInfo.ID == 0 {
  2073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2074. return
  2075. }
  2076. var subAdvice []*models.DoctorAdvice
  2077. var advice models.DoctorAdvice
  2078. if parent_id > 0 {
  2079. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  2080. if advice.ID == 0 || advice.PatientId != patient {
  2081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2082. return
  2083. }
  2084. subAdvice = service.FindSubAdivceById(patient, parent_id)
  2085. } else {
  2086. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  2087. if advice.ID == 0 || advice.PatientId != patient {
  2088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2089. return
  2090. }
  2091. subAdvice = service.FindSubAdivceById(patient, adviceId)
  2092. }
  2093. c.ServeSuccessJSON(map[string]interface{}{
  2094. "msg": "ok",
  2095. "advice": advice,
  2096. "subAdvice": subAdvice,
  2097. })
  2098. }
  2099. func (this *DialysisApiController) DelMonitor() {
  2100. recordID, _ := this.GetInt64("record_id")
  2101. patientID, _ := this.GetInt64("patient_id")
  2102. if recordID <= 0 || patientID <= 0 {
  2103. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2104. return
  2105. }
  2106. adminInfo := this.GetAdminUserInfo()
  2107. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  2108. if getPatientErr != nil {
  2109. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2111. return
  2112. } else if patient == nil {
  2113. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2114. return
  2115. }
  2116. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  2117. if getMonitorErr != nil {
  2118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2119. return
  2120. }
  2121. //if monitor != nil {
  2122. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  2123. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2124. // if getPermissionErr != nil {
  2125. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2126. // return
  2127. // } else if headNursePermission == nil {
  2128. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2129. // return
  2130. // }
  2131. // }
  2132. //}
  2133. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  2134. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_records"
  2135. redis := service.RedisClient()
  2136. //清空key 值
  2137. redis.Set(key, "", time.Second)
  2138. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_record_list_all"
  2139. redis.Set(keyOne, "", time.Second)
  2140. defer redis.Close()
  2141. if err != nil {
  2142. this.ErrorLog("删除透析监测记录失败:%v", err)
  2143. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  2144. return
  2145. }
  2146. this.ServeSuccessJSON(map[string]interface{}{
  2147. "record_id": monitor.ID,
  2148. })
  2149. }
  2150. func (c *DialysisApiController) CreateMonitor() {
  2151. patient, _ := c.GetInt64("id", 0)
  2152. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  2153. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  2154. operate_time, _ := c.GetInt64("operate_time", 0)
  2155. // monitoring_time := c.GetString("monitoring_time")
  2156. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  2157. //breathing_rated, _ := c.GetFloat("breathing_rated", 0)
  2158. breathing_rated := c.GetString("breathing_rated")
  2159. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  2160. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  2161. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  2162. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  2163. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  2164. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  2165. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  2166. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  2167. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  2168. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  2169. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  2170. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  2171. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  2172. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  2173. temperature, _ := c.GetFloat("temperature", 0)
  2174. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  2175. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  2176. conductivity, _ := c.GetFloat("conductivity", 0)
  2177. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  2178. heparin, _ := c.GetFloat("heparin", 0)
  2179. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  2180. ktv, _ := c.GetFloat("ktv", 0)
  2181. symptom := c.GetString("symptom")
  2182. dispose := c.GetString("dispose")
  2183. result := c.GetString("results")
  2184. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  2185. monitor_anticoagulant, _ := c.GetInt64("monitor_anticoagulant")
  2186. monitor_anticoagulant_value := c.GetString("monitor_anticoagulant_value")
  2187. monitoring_date = monitoring_date / 1000
  2188. // operate_time = operate_time / 1000
  2189. if patient <= 0 {
  2190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2191. return
  2192. }
  2193. adminUserInfo := c.GetAdminUserInfo()
  2194. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2195. if patientInfo.ID == 0 {
  2196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2197. return
  2198. }
  2199. monitorRecord := models.MonitoringRecord{
  2200. PatientId: patient,
  2201. MonitoringDate: monitoring_date,
  2202. DialysisOrderId: dialysis_order_id,
  2203. OperateTime: operate_time,
  2204. // MonitoringTime: monitoring_time,
  2205. PulseFrequency: pulse_frequency,
  2206. BreathingRate: breathing_rated,
  2207. SystolicBloodPressure: systolic_blood_pressure,
  2208. DiastolicBloodPressure: diastolic_blood_pressure,
  2209. BloodPressureType: blood_pressure_type,
  2210. BloodFlowVolume: blood_flow_volume,
  2211. VenousPressure: venous_pressure,
  2212. VenousPressureType: venous_pressure_type,
  2213. TransmembranePressure: transmembrane_pressure,
  2214. TransmembranePressureType: transmembrane_pressure_type,
  2215. UltrafiltrationRate: ultrafiltration_rate,
  2216. UltrafiltrationVolume: ultrafiltration_volume,
  2217. SodiumConcentration: sodium_concentration,
  2218. ArterialPressure: arterial_pressure,
  2219. ArterialPressureType: arterial_pressure_type,
  2220. DialysateTemperature: dialysate_temperature,
  2221. Temperature: temperature,
  2222. ReplacementRate: replacement_rate,
  2223. DisplacementQuantity: displacement_quantity,
  2224. Ktv: ktv,
  2225. Symptom: symptom,
  2226. Dispose: dispose,
  2227. Result: result,
  2228. MonitoringNurse: monitoring_nurse,
  2229. Status: 1,
  2230. CreatedTime: time.Now().Unix(),
  2231. UpdatedTime: time.Now().Unix(),
  2232. UserOrgId: adminUserInfo.CurrentOrgId,
  2233. Conductivity: conductivity,
  2234. DisplacementFlowQuantity: displacement_flow_quantity,
  2235. Heparin: heparin,
  2236. DialysateFlow: dialysate_flow,
  2237. MonitorAnticoagulant: monitor_anticoagulant,
  2238. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  2239. }
  2240. err := service.CreateMonitor(&monitorRecord)
  2241. redis := service.RedisClient()
  2242. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_record_list_all"
  2243. redis.Set(key, "", time.Second)
  2244. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  2245. redis.Set(keyOne, "", time.Second)
  2246. redis.Close()
  2247. if err != nil {
  2248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2249. return
  2250. }
  2251. c.ServeSuccessJSON(map[string]interface{}{
  2252. "msg": "ok",
  2253. "monitor": monitorRecord,
  2254. })
  2255. return
  2256. }
  2257. // 已弃用
  2258. // func (c *DialysisApiController) CreateRecordData() {
  2259. // patient, _ := c.GetInt64("id", 0)
  2260. // status, _ := c.GetInt64("status", 0)
  2261. // now := time.Now()
  2262. // year, month, day := now.Date()
  2263. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2264. // todayTimeStamp := today_time.Unix()
  2265. // if patient <= 0 {
  2266. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2267. // return
  2268. // }
  2269. // adminUserInfo := c.GetAdminUserInfo()
  2270. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2271. // if patientInfo.ID == 0 {
  2272. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2273. // return
  2274. // }
  2275. // record := &models.DialysisOrder{
  2276. // DialysisDate: todayTimeStamp,
  2277. // UserOrgId: adminUserInfo.CurrentOrgId,
  2278. // PatientId: patient,
  2279. // Stage: status,
  2280. // Status: 1,
  2281. // CreatedTime: time.Now().Unix(),
  2282. // UpdatedTime: time.Now().Unix(),
  2283. // }
  2284. // if status == 1 {
  2285. // //创建透析记录
  2286. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  2287. // if err == nil {
  2288. // c.ServeSuccessJSON(map[string]interface{}{
  2289. // "dialysisOrder": record,
  2290. // })
  2291. // } else {
  2292. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2293. // }
  2294. // } else {
  2295. // record_id, _ := c.GetInt64("record_id", 0)
  2296. // //修改透析记录状态
  2297. // errs := service.ModifyDialysisRecord(record_id)
  2298. // //结束时候透析次数加1
  2299. // service.UpdateSolutionByPatientId(patient)
  2300. // if errs == nil {
  2301. // c.ServeSuccessJSON(map[string]interface{}{
  2302. // "dialysisOrder": record,
  2303. // })
  2304. // } else {
  2305. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2306. // }
  2307. // }
  2308. // }
  2309. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  2310. dataBody := make(map[string]interface{}, 0)
  2311. err := json.Unmarshal(data, &dataBody)
  2312. if err != nil {
  2313. utils.ErrorLog(err.Error())
  2314. code = enums.ErrorCodeParamWrong
  2315. return
  2316. }
  2317. timeLayout := "2006-01-02 "
  2318. timeLayout2 := "2006-01-02 15:04"
  2319. loc, _ := time.LoadLocation("Local")
  2320. if action == "create" {
  2321. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2322. utils.ErrorLog("advice_type")
  2323. code = enums.ErrorCodeParamWrong
  2324. return
  2325. }
  2326. adviceType := int64(dataBody["advice_type"].(float64))
  2327. if adviceType != 1 && adviceType != 2 {
  2328. utils.ErrorLog("advice_type != 1&&2")
  2329. code = enums.ErrorCodeParamWrong
  2330. return
  2331. }
  2332. advice.AdviceType = adviceType
  2333. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2334. utils.ErrorLog("advice_date")
  2335. code = enums.ErrorCodeParamWrong
  2336. return
  2337. }
  2338. adviceDate, _ := dataBody["advice_date"].(string)
  2339. if len(adviceDate) == 0 {
  2340. utils.ErrorLog("len(adviceDate) == 0")
  2341. code = enums.ErrorCodeParamWrong
  2342. return
  2343. }
  2344. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2345. if err != nil {
  2346. utils.ErrorLog(err.Error())
  2347. code = enums.ErrorCodeParamWrong
  2348. return
  2349. }
  2350. advice.AdviceDate = theTime.Unix()
  2351. }
  2352. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2353. utils.ErrorLog("start_time")
  2354. code = enums.ErrorCodeParamWrong
  2355. return
  2356. }
  2357. startDate, _ := dataBody["start_time"].(string)
  2358. if len(startDate) == 0 {
  2359. utils.ErrorLog("len(startDate) == 0")
  2360. code = enums.ErrorCodeParamWrong
  2361. return
  2362. }
  2363. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  2364. if err != nil {
  2365. utils.ErrorLog(err.Error())
  2366. code = enums.ErrorCodeParamWrong
  2367. return
  2368. }
  2369. advice.StartTime = theTime.Unix()
  2370. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2371. utils.ErrorLog("advice_name")
  2372. code = enums.ErrorCodeParamWrong
  2373. return
  2374. }
  2375. adviceName, _ := dataBody["advice_name"].(string)
  2376. if len(adviceName) == 0 {
  2377. utils.ErrorLog("len(advice_name) == 0")
  2378. code = enums.ErrorCodeParamWrong
  2379. return
  2380. }
  2381. advice.AdviceName = adviceName
  2382. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  2383. utils.ErrorLog("delivery_way")
  2384. code = enums.ErrorCodeParamWrong
  2385. return
  2386. }
  2387. deliveryWay, _ := dataBody["delivery_way"].(string)
  2388. if len(deliveryWay) == 0 {
  2389. utils.ErrorLog("len(deliveryWay) == 0")
  2390. code = enums.ErrorCodeParamWrong
  2391. return
  2392. }
  2393. advice.DeliveryWay = deliveryWay
  2394. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  2395. utils.ErrorLog("execution_frequency")
  2396. code = enums.ErrorCodeParamWrong
  2397. return
  2398. }
  2399. execution_frequency, _ := dataBody["execution_frequency"].(string)
  2400. if len(execution_frequency) == 0 {
  2401. utils.ErrorLog("len(execution_frequency) == 0")
  2402. code = enums.ErrorCodeParamWrong
  2403. return
  2404. }
  2405. advice.ExecutionFrequency = execution_frequency
  2406. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  2407. adviceDsc, _ := dataBody["advice_desc"].(string)
  2408. advice.AdviceDesc = adviceDsc
  2409. }
  2410. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  2411. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  2412. advice.DrugSpecUnit = drugSpecUnit
  2413. }
  2414. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  2415. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  2416. advice.SingleDose = singleDose
  2417. }
  2418. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  2419. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  2420. advice.SingleDoseUnit = singleDoseUnit
  2421. }
  2422. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  2423. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  2424. advice.PrescribingNumber = prescribingNumber
  2425. }
  2426. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  2427. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  2428. advice.PrescribingNumberUnit = prescribingNumberUnit
  2429. }
  2430. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  2431. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  2432. if len(thisContagions) > 0 {
  2433. for _, item := range thisContagions {
  2434. items := item.(map[string]interface{})
  2435. advice_name, _ := items["advice_name"].(string)
  2436. advice_desc, _ := items["advice_desc"].(string)
  2437. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  2438. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  2439. single_dose_unit, _ := items["single_dose_unit"].(string)
  2440. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  2441. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  2442. advice := &models.DoctorAdvice{
  2443. AdviceName: advice_name,
  2444. AdviceDesc: advice_desc,
  2445. SingleDose: single_dose,
  2446. SingleDoseUnit: single_dose_unit,
  2447. DrugSpecUnit: drug_spec_unit,
  2448. PrescribingNumber: prescribing_number,
  2449. PrescribingNumberUnit: prescribing_number_unit,
  2450. }
  2451. subAdvice = append(subAdvice, advice)
  2452. }
  2453. }
  2454. }
  2455. return
  2456. }
  2457. func (c *DialysisApiController) GetDialysisOrder() {
  2458. xtno := c.GetString("xtno")
  2459. xtdate := c.GetString("xtdate")
  2460. timeLayout := "2006-01-02"
  2461. loc, _ := time.LoadLocation("Local")
  2462. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  2463. if err != nil {
  2464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2465. return
  2466. }
  2467. xttime := theTime.Unix()
  2468. operatorIDs := make([]int64, 0)
  2469. adminUserInfo := c.GetAdminUserInfo()
  2470. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  2471. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.CurrentOrgId, xtno, xttime)
  2472. //透析单
  2473. dialysisOrder, _ := service.MobileGetSchedualDialysisRecordTen(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2474. if dialysisOrder != nil {
  2475. if dialysisOrder.FinishNurse > 0 {
  2476. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  2477. }
  2478. if dialysisOrder.StartNurse > 0 {
  2479. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  2480. }
  2481. }
  2482. //透前评估
  2483. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2484. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  2485. //透后评估
  2486. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2487. if AssessmentAfterDislysis.Modifier > 0 {
  2488. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  2489. }
  2490. //上次透前评估
  2491. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2492. lastOrder, _ := service.GetLastTimeOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2493. //透析处方
  2494. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2495. if dialysisPrescription.PrescriptionDoctor > 0 {
  2496. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  2497. }
  2498. //获取病人的透析模式
  2499. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2500. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2501. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2502. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2503. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2504. //获取透析处方
  2505. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2506. //获取临时医嘱
  2507. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2508. //config, err := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  2509. //获取医嘱内容
  2510. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2511. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2512. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2513. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2514. //获取上次的透后体重
  2515. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2516. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2517. //获取透析次数
  2518. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  2519. if len(DoctorAdvice) > 0 {
  2520. for _, item := range DoctorAdvice {
  2521. if item.AdviceDoctor > 0 {
  2522. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2523. }
  2524. if item.ExecutionStaff > 0 {
  2525. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2526. }
  2527. if item.Checker > 0 {
  2528. operatorIDs = append(operatorIDs, item.Checker)
  2529. }
  2530. }
  2531. }
  2532. //透析监测
  2533. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2534. //透析检测
  2535. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2536. //透析小结
  2537. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2538. //接诊评估
  2539. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2540. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2541. if adminUserInfo.CurrentOrgId != 10101 {
  2542. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2543. patientInfo.TotalDialysis = dialysis_count
  2544. }
  2545. if adminUserInfo.CurrentOrgId == 10101 {
  2546. dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2547. patientInfo.TotalDialysis = dialysis_count
  2548. }
  2549. //相关操作对应的操作人
  2550. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  2551. operators, err := service.GetAdminUserEsOne(adminUserInfo.CurrentOrgId)
  2552. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  2553. //获取当前日期月份的第一天
  2554. firstmonth := service.GetFirstDateOfMonth(theTime)
  2555. firstMonthDate := firstmonth.Unix()
  2556. //获取当前月份的病人透析次数
  2557. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  2558. //获取his数据
  2559. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2560. //hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2561. config, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  2562. project_config, _ := service.GetHisProjectConfig(adminUserInfo.CurrentOrgId)
  2563. projects, _ := service.FindAllHisProjectById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2564. //if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  2565. // for _, item := range projects {
  2566. // var advice *models.HisDoctorAdviceInfo
  2567. // advice.ID = item.ID
  2568. // advice.Checker = item.Checker
  2569. // advice.CheckTime = item.CheckTime
  2570. // advice.CheckState = item.CheckState
  2571. // advice.ExecutionState = item.ExecutionState
  2572. // advice.ExecutionStaff = item.ExecutionStaff
  2573. // advice.PrescribingNumber = float64(item.Count)
  2574. // advice.PrescribingNumberUnit = item.Unit
  2575. // advice.AdviceDoctor = item.Doctor
  2576. // if item.Type == 3 {
  2577. // advice.AdviceName = item.GoodInfo.GoodName
  2578. // } else if item.Type == 2 {
  2579. // advice.AdviceName = item.HisProject.ProjectName
  2580. // }
  2581. // advice.StartTime = item.StartTime
  2582. // hisAdvice = append(hisAdvice, advice)
  2583. // }
  2584. //}
  2585. if config.IsOpen == 1 {
  2586. c.ServeSuccessJSON(map[string]interface{}{
  2587. "xtdate": xtdate,
  2588. "users": adminUser,
  2589. "patientInfo": patientInfo,
  2590. "PredialysisEvaluation": PredialysisEvaluation,
  2591. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2592. "dialysisPrescription": dialysisPrescription,
  2593. "advices": hisAdvice,
  2594. "monitors": Record,
  2595. "summary": TreatmentSummary,
  2596. "receiverTreatmentAccess": receiverTreatmentAccess,
  2597. "dialysisOrder": dialysisOrder,
  2598. "operators": operators,
  2599. "org_template_info": templateInfo,
  2600. "check": check,
  2601. "schedule": schedule,
  2602. "dialysisway": dialysisway,
  2603. "order": order,
  2604. "doctorAdvice": doctorAdvice,
  2605. "doctor": doctor,
  2606. "nurse": nurse,
  2607. "doctorAdevieInfo": doctorAdevieInfo,
  2608. "total": total,
  2609. "startNuse": startNuse,
  2610. "DoctorName": DoctorName,
  2611. "assessmentAfterDislysis": assessmentAfterDislysis,
  2612. "predialysName": predialysName,
  2613. "FinishNuse": FinishNuse,
  2614. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  2615. "dialysiscount": dialysiscount,
  2616. "last_order": lastOrder,
  2617. "project_config": project_config,
  2618. "projects": projects,
  2619. })
  2620. }
  2621. if config.IsOpen == 0 || config.IsOpen == 2 {
  2622. c.ServeSuccessJSON(map[string]interface{}{
  2623. "xtdate": xtdate,
  2624. "users": adminUser,
  2625. "patientInfo": patientInfo,
  2626. "PredialysisEvaluation": PredialysisEvaluation,
  2627. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2628. "dialysisPrescription": dialysisPrescription,
  2629. "advices": DoctorAdvice,
  2630. "monitors": Record,
  2631. "summary": TreatmentSummary,
  2632. "receiverTreatmentAccess": receiverTreatmentAccess,
  2633. "dialysisOrder": dialysisOrder,
  2634. "operators": operators,
  2635. "org_template_info": templateInfo,
  2636. "check": check,
  2637. "schedule": schedule,
  2638. "dialysisway": dialysisway,
  2639. "order": order,
  2640. "doctorAdvice": doctorAdvice,
  2641. "doctor": doctor,
  2642. "nurse": nurse,
  2643. "doctorAdevieInfo": doctorAdevieInfo,
  2644. "total": total,
  2645. "startNuse": startNuse,
  2646. "DoctorName": DoctorName,
  2647. "assessmentAfterDislysis": assessmentAfterDislysis,
  2648. "predialysName": predialysName,
  2649. "FinishNuse": FinishNuse,
  2650. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  2651. "dialysiscount": dialysiscount,
  2652. "last_order": lastOrder,
  2653. "project_config": project_config,
  2654. "projects": projects,
  2655. })
  2656. }
  2657. }
  2658. //
  2659. func (c *DialysisApiController) GetLongAdvice() {
  2660. patient_id, _ := c.GetInt64("patient_id")
  2661. adminUserInfo := c.GetAdminUserInfo()
  2662. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2663. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  2664. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  2665. c.ServeSuccessJSON(map[string]interface{}{
  2666. "status": "1",
  2667. })
  2668. return
  2669. } else { //开启推送提醒
  2670. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  2671. var advice_three []*models.DoctorAdvice
  2672. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  2673. recordDateStr := time.Now().Format("2006-01-02")
  2674. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2675. nowtime := recordDate.Unix()
  2676. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  2677. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  2678. for _, advice := range advices {
  2679. if advice.FrequencyType == 3 {
  2680. t := time.Now()
  2681. week := int(t.Weekday())
  2682. switch week {
  2683. case 1:
  2684. if strings.Index(advice.WeekDay, "周一") == -1 {
  2685. advice_three = append(advice_three, advice)
  2686. }
  2687. break
  2688. case 2:
  2689. if strings.Index(advice.WeekDay, "周二") == -1 {
  2690. advice_three = append(advice_three, advice)
  2691. }
  2692. break
  2693. case 3:
  2694. if strings.Index(advice.WeekDay, "周三") == -1 {
  2695. advice_three = append(advice_three, advice)
  2696. }
  2697. break
  2698. case 4:
  2699. if strings.Index(advice.WeekDay, "周四") == -1 {
  2700. advice_three = append(advice_three, advice)
  2701. }
  2702. break
  2703. case 5:
  2704. if strings.Index(advice.WeekDay, "周五") == -1 {
  2705. advice_three = append(advice_three, advice)
  2706. }
  2707. break
  2708. case 6:
  2709. if strings.Index(advice.WeekDay, "周六") == -1 {
  2710. advice_three = append(advice_three, advice)
  2711. }
  2712. break
  2713. case 0:
  2714. if strings.Index(advice.WeekDay, "周日") == -1 {
  2715. advice_three = append(advice_three, advice)
  2716. }
  2717. break
  2718. }
  2719. }
  2720. }
  2721. for _, advice := range advices_two {
  2722. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  2723. now := p.Unix()
  2724. dayStr := strconv.FormatInt(advice.DayCount, 10)
  2725. dayStr2 := "-" + dayStr
  2726. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  2727. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  2728. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  2729. for _, ad := range advices {
  2730. advice_three = append(advice_three, ad)
  2731. }
  2732. }
  2733. if err == nil {
  2734. c.ServeSuccessJSON(map[string]interface{}{
  2735. "status": "2",
  2736. "advices": advices,
  2737. "advices_two": RemoveRepeatedElement(advice_three),
  2738. "is_open_remind": config.IsOpenRemind,
  2739. })
  2740. }
  2741. }
  2742. }
  2743. func (c *DialysisApiController) GetLongAdviceOne() {
  2744. patient_id, _ := c.GetInt64("patient_id")
  2745. schedule_date := c.GetString("schedule_date")
  2746. adminUserInfo := c.GetAdminUserInfo()
  2747. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2748. timeLayout := "2006-01-02"
  2749. loc, _ := time.LoadLocation("Local")
  2750. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  2751. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  2752. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  2753. c.ServeSuccessJSON(map[string]interface{}{
  2754. "status": "1",
  2755. })
  2756. return
  2757. } else { //开启推送提醒
  2758. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  2759. var advice_three []*models.DoctorAdvice
  2760. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  2761. //recordDateStr := time.Now().Format("2006-01-02")
  2762. //recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2763. //
  2764. //nowtime := recordDate.Unix()
  2765. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  2766. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  2767. fmt.Println("advice23323232233232233223232332232323322323wodee", theTime.Unix())
  2768. for _, advice := range advices {
  2769. if advice.FrequencyType == 3 {
  2770. t := time.Now()
  2771. week := int(t.Weekday())
  2772. switch week {
  2773. case 1:
  2774. if strings.Index(advice.WeekDay, "周一") == -1 {
  2775. advice_three = append(advice_three, advice)
  2776. }
  2777. break
  2778. case 2:
  2779. if strings.Index(advice.WeekDay, "周二") == -1 {
  2780. advice_three = append(advice_three, advice)
  2781. }
  2782. break
  2783. case 3:
  2784. if strings.Index(advice.WeekDay, "周三") == -1 {
  2785. advice_three = append(advice_three, advice)
  2786. }
  2787. break
  2788. case 4:
  2789. if strings.Index(advice.WeekDay, "周四") == -1 {
  2790. advice_three = append(advice_three, advice)
  2791. }
  2792. break
  2793. case 5:
  2794. if strings.Index(advice.WeekDay, "周五") == -1 {
  2795. advice_three = append(advice_three, advice)
  2796. }
  2797. break
  2798. case 6:
  2799. if strings.Index(advice.WeekDay, "周六") == -1 {
  2800. advice_three = append(advice_three, advice)
  2801. }
  2802. break
  2803. case 0:
  2804. if strings.Index(advice.WeekDay, "周日") == -1 {
  2805. advice_three = append(advice_three, advice)
  2806. }
  2807. break
  2808. }
  2809. }
  2810. }
  2811. for _, advice := range advices_two {
  2812. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  2813. now := p.Unix()
  2814. dayStr := strconv.FormatInt(advice.DayCount, 10)
  2815. dayStr2 := "-" + dayStr
  2816. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  2817. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  2818. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  2819. for _, ad := range advices {
  2820. advice_three = append(advice_three, ad)
  2821. }
  2822. }
  2823. if err == nil {
  2824. c.ServeSuccessJSON(map[string]interface{}{
  2825. "status": "2",
  2826. "advices": advices,
  2827. "advices_two": RemoveRepeatedElement(advice_three),
  2828. "is_open_remind": config.IsOpenRemind,
  2829. })
  2830. }
  2831. }
  2832. }
  2833. func (c *DialysisApiController) GetLongAdviceTwo() {
  2834. patient_id, _ := c.GetInt64("patient_id")
  2835. schedule_date, _ := c.GetInt64("schedule_date")
  2836. adminUserInfo := c.GetAdminUserInfo()
  2837. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2838. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  2839. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  2840. c.ServeSuccessJSON(map[string]interface{}{
  2841. "status": "1",
  2842. })
  2843. return
  2844. } else { //开启推送提醒
  2845. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  2846. var advice_three []*models.DoctorAdvice
  2847. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  2848. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  2849. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  2850. fmt.Println("advice23323232233232233223232332232323322323wodee", schedule_date)
  2851. for _, advice := range advices {
  2852. if advice.FrequencyType == 3 {
  2853. t := time.Now()
  2854. week := int(t.Weekday())
  2855. switch week {
  2856. case 1:
  2857. if strings.Index(advice.WeekDay, "周一") == -1 {
  2858. advice_three = append(advice_three, advice)
  2859. }
  2860. break
  2861. case 2:
  2862. if strings.Index(advice.WeekDay, "周二") == -1 {
  2863. advice_three = append(advice_three, advice)
  2864. }
  2865. break
  2866. case 3:
  2867. if strings.Index(advice.WeekDay, "周三") == -1 {
  2868. advice_three = append(advice_three, advice)
  2869. }
  2870. break
  2871. case 4:
  2872. if strings.Index(advice.WeekDay, "周四") == -1 {
  2873. advice_three = append(advice_three, advice)
  2874. }
  2875. break
  2876. case 5:
  2877. if strings.Index(advice.WeekDay, "周五") == -1 {
  2878. advice_three = append(advice_three, advice)
  2879. }
  2880. break
  2881. case 6:
  2882. if strings.Index(advice.WeekDay, "周六") == -1 {
  2883. advice_three = append(advice_three, advice)
  2884. }
  2885. break
  2886. case 0:
  2887. if strings.Index(advice.WeekDay, "周日") == -1 {
  2888. advice_three = append(advice_three, advice)
  2889. }
  2890. break
  2891. }
  2892. }
  2893. }
  2894. for _, advice := range advices_two {
  2895. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  2896. now := p.Unix()
  2897. dayStr := strconv.FormatInt(advice.DayCount, 10)
  2898. dayStr2 := "-" + dayStr
  2899. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  2900. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  2901. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  2902. for _, ad := range advices {
  2903. advice_three = append(advice_three, ad)
  2904. }
  2905. }
  2906. if err == nil {
  2907. c.ServeSuccessJSON(map[string]interface{}{
  2908. "status": "2",
  2909. "advices": advices,
  2910. "advices_two": RemoveRepeatedElement(advice_three),
  2911. "is_open_remind": config.IsOpenRemind,
  2912. })
  2913. }
  2914. }
  2915. }
  2916. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  2917. newArr = make([]*models.DoctorAdvice, 0)
  2918. for i := 0; i < len(arr); i++ {
  2919. repeat := false
  2920. for j := i + 1; j < len(arr); j++ {
  2921. if arr[i].ID == arr[j].ID {
  2922. repeat = true
  2923. break
  2924. }
  2925. }
  2926. if !repeat {
  2927. newArr = append(newArr, arr[i])
  2928. }
  2929. }
  2930. return
  2931. }
  2932. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  2933. patient, _ := c.GetInt64("id", 0)
  2934. groupNo, _ := c.GetInt64("groupno", 0)
  2935. if patient <= 0 {
  2936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2937. return
  2938. }
  2939. adminUserInfo := c.GetAdminUserInfo()
  2940. dataBody := make(map[string]interface{}, 0)
  2941. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2942. if err != nil {
  2943. utils.ErrorLog(err.Error())
  2944. return
  2945. }
  2946. utils.ErrorLog("%v", dataBody)
  2947. timeLayout := "2006-01-02 15:04"
  2948. loc, _ := time.LoadLocation("Local")
  2949. timeLayout2 := "2006-01-02"
  2950. loc2, _ := time.LoadLocation("Local")
  2951. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2952. utils.ErrorLog("advice_type")
  2953. return
  2954. }
  2955. adviceType := int64(2)
  2956. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2957. utils.ErrorLog("advice_date")
  2958. return
  2959. }
  2960. adviceDate, _ := dataBody["advice_date"].(string)
  2961. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  2962. AdviceDate := theTime.Unix()
  2963. RecordDate := theTime.Unix()
  2964. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2965. utils.ErrorLog("start_time")
  2966. return
  2967. }
  2968. startTime, _ := dataBody["start_time"].(string)
  2969. if len(startTime) == 0 {
  2970. utils.ErrorLog("len(start_time) == 0")
  2971. return
  2972. }
  2973. theTimeUnix, err := time.ParseInLocation(timeLayout, startTime, loc)
  2974. if err != nil {
  2975. utils.ErrorLog(err.Error())
  2976. return
  2977. }
  2978. StartTime := theTimeUnix.Unix()
  2979. fmt.Println("startTIME", StartTime)
  2980. Remark := ""
  2981. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2982. remark, _ := dataBody["remark"].(string)
  2983. Remark = remark
  2984. }
  2985. var advices []*models.GroupAdvice
  2986. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  2987. utils.ErrorLog("advices")
  2988. return
  2989. }
  2990. adviceNames := dataBody["advices"].([]interface{})
  2991. for _, adviceNameMap := range adviceNames {
  2992. adviceNameM := adviceNameMap.(map[string]interface{})
  2993. var advice models.GroupAdvice
  2994. advice.Remark = Remark
  2995. advice.AdviceType = adviceType
  2996. advice.StartTime = StartTime
  2997. advice.AdviceDate = AdviceDate
  2998. advice.RecordDate = RecordDate
  2999. advice.Status = 1
  3000. advice.CreatedTime = time.Now().Unix()
  3001. advice.UpdatedTime = time.Now().Unix()
  3002. advice.StopState = 2
  3003. advice.ExecutionState = 2
  3004. advice.UserOrgId = adminUserInfo.CurrentOrgId
  3005. advice.PatientId = patient
  3006. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3007. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  3008. utils.ErrorLog("advice_name")
  3009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3010. return
  3011. }
  3012. adviceName, _ := adviceNameM["advice_name"].(string)
  3013. if len(adviceName) == 0 {
  3014. utils.ErrorLog("len(advice_name) == 0")
  3015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3016. return
  3017. }
  3018. advice.AdviceName = adviceName
  3019. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  3020. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  3021. advice.DrugSpec = drugSpec
  3022. }
  3023. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  3024. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  3025. advice.AdviceDesc = adviceDesc
  3026. }
  3027. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  3028. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  3029. advice.DrugSpecUnit = drugSpecUnit
  3030. }
  3031. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  3032. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  3033. // advice.SingleDose = singleDose
  3034. //}
  3035. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  3036. //single_dose := int64(adviceNameM["single_dose"].(float64))
  3037. advice.SingleDose = adviceNameM["single_dose"].(float64)
  3038. }
  3039. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  3040. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  3041. advice.SingleDoseUnit = singleDoseUnit
  3042. }
  3043. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  3044. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  3045. // advice.PrescribingNumber = prescribingNumber
  3046. //}
  3047. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  3048. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  3049. }
  3050. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  3051. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  3052. advice.PrescribingNumberUnit = prescribingNumberUnit
  3053. }
  3054. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  3055. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  3056. advice.DeliveryWay = deliveryWay
  3057. }
  3058. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3059. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3060. advice.ExecutionFrequency = executionFrequency
  3061. }
  3062. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  3063. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  3064. advice.FrequencyType = frequency_type
  3065. }
  3066. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  3067. day_count := int64(adviceNameM["day_count"].(float64))
  3068. advice.DayCount = day_count
  3069. }
  3070. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  3071. way := int64(adviceNameM["way"].(float64))
  3072. advice.Way = way
  3073. }
  3074. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  3075. drug_id := int64(adviceNameM["drug_id"].(float64))
  3076. advice.DrugId = drug_id
  3077. }
  3078. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  3079. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  3080. advice.DrugNameId = drug_name_id
  3081. }
  3082. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  3083. week_day, _ := adviceNameM["week_day"].(string)
  3084. advice.WeekDay = week_day
  3085. }
  3086. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  3087. template_id, _ := adviceNameM["template_id"].(string)
  3088. advice.TemplateId = template_id
  3089. }
  3090. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3091. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3092. advice.ExecutionFrequency = executionFrequency
  3093. }
  3094. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  3095. children := adviceNameM["child"].([]interface{})
  3096. if len(children) > 0 {
  3097. for _, childrenMap := range children {
  3098. childMap := childrenMap.(map[string]interface{})
  3099. var child models.GroupAdvice
  3100. child.Remark = Remark
  3101. child.AdviceType = adviceType
  3102. child.StartTime = StartTime
  3103. child.AdviceDate = AdviceDate
  3104. child.RecordDate = RecordDate
  3105. child.Status = 1
  3106. child.CreatedTime = time.Now().Unix()
  3107. child.UpdatedTime = time.Now().Unix()
  3108. child.StopState = 2
  3109. child.ExecutionState = 2
  3110. child.UserOrgId = adminUserInfo.CurrentOrgId
  3111. child.PatientId = patient
  3112. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  3113. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  3114. utils.ErrorLog("child advice_name")
  3115. return
  3116. }
  3117. childAdviceName, _ := childMap["advice_name"].(string)
  3118. if len(childAdviceName) == 0 {
  3119. utils.ErrorLog("len(child advice_name) == 0")
  3120. return
  3121. }
  3122. child.AdviceName = childAdviceName
  3123. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  3124. childAdviceDesc, _ := childMap["advice_desc"].(string)
  3125. child.AdviceDesc = childAdviceDesc
  3126. }
  3127. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  3128. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  3129. child.DrugSpec = childDrugSpec
  3130. }
  3131. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  3132. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  3133. child.DrugSpecUnit = childDrugSpecUnit
  3134. }
  3135. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  3136. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3137. child.SingleDose = childSingleDose
  3138. }
  3139. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  3140. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3141. child.SingleDose = childMap["single_dose"].(float64)
  3142. }
  3143. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  3144. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3145. child.Remark = childMap["remark"].(string)
  3146. }
  3147. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  3148. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3149. child.DrugId = int64(childMap["drug_id"].(float64))
  3150. }
  3151. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  3152. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  3153. child.SingleDoseUnit = childSingleDoseUnit
  3154. }
  3155. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  3156. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  3157. child.PrescribingNumber = childPrescribingNumber
  3158. }
  3159. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  3160. //childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  3161. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  3162. }
  3163. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  3164. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  3165. child.PrescribingNumberUnit = childPrescribingNumberUnit
  3166. }
  3167. child.DeliveryWay = advice.DeliveryWay
  3168. child.ExecutionFrequency = advice.ExecutionFrequency
  3169. advice.Children = append(advice.Children, &child)
  3170. }
  3171. }
  3172. }
  3173. advices = append(advices, &advice)
  3174. }
  3175. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  3176. redis := service.RedisClient()
  3177. formatAdviceDate := theTime.Format("2006-01-02")
  3178. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3179. redis.Set(key, "", time.Second)
  3180. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  3181. redis.Set(keyOne, "", time.Second)
  3182. keyFour := "scheduals_" + formatAdviceDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3183. redis.Set(keyFour, "", time.Second)
  3184. defer redis.Close()
  3185. if err != nil {
  3186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3187. return
  3188. }
  3189. c.ServeSuccessJSON(map[string]interface{}{
  3190. "msg": "ok",
  3191. "advices": list,
  3192. })
  3193. return
  3194. }
  3195. func (c *DialysisApiController) GetSolution() {
  3196. patient_id, _ := c.GetInt64("patient_id")
  3197. mode_id, _ := c.GetInt64("mode_id")
  3198. adminUserInfo := c.GetAdminUserInfo()
  3199. solution, err := service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  3200. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  3201. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, mode_id)
  3202. if err != nil {
  3203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3204. return
  3205. }
  3206. c.ServeSuccessJSON(map[string]interface{}{
  3207. "solution": solution,
  3208. "prescription": prescription,
  3209. "system_prescription": system_prescription,
  3210. })
  3211. }
  3212. func (c *DialysisApiController) GetSchedule() {
  3213. schedual_type, _ := c.GetInt64("schedual_type")
  3214. adminUserInfo := c.GetAdminUserInfo()
  3215. //timeLayout := "2006-01-02 15:04:05"
  3216. //
  3217. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  3218. //loc, _ := time.LoadLocation("Local")
  3219. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  3220. //scheduleTime := theStartTime.Unix()
  3221. scheduleTime, _ := c.GetInt64("record_date")
  3222. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  3223. c.ServeSuccessJSON(map[string]interface{}{
  3224. "number": deviceNumber,
  3225. })
  3226. }
  3227. func (this *DialysisApiController) GetTodayMonitor() {
  3228. thisTime := time.Now()
  3229. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3230. timeLayout := "2006-01-02 15:04:05"
  3231. loc, _ := time.LoadLocation("Local")
  3232. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3233. theAssessmentDateTime := theStartTime.Unix()
  3234. patientID, _ := this.GetInt64("patient_id")
  3235. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3236. adminInfo := this.GetAdminUserInfo()
  3237. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  3238. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  3239. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  3240. var ultrafiltration_rate float64
  3241. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  3242. //针对福建医师汇 获取透前评估预增脱水量
  3243. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  3244. fmt.Println("透前评估数据", evaluation)
  3245. if prescription.ID > 0 {
  3246. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3247. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3248. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  3249. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3250. record.UltrafiltrationRate = ultrafiltration_rate
  3251. }
  3252. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10121 {
  3253. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3254. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3255. record.UltrafiltrationRate = ultrafiltration_rate
  3256. }
  3257. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10234 {
  3258. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3259. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3260. record.UltrafiltrationRate = ultrafiltration_rate
  3261. }
  3262. if template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 { //adminInfo.CurrentOrgId == 9538
  3263. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3264. record.UltrafiltrationRate = ultrafiltration_rate
  3265. }
  3266. if template.TemplateId == 41 { //adminInfo.CurrentOrgId == 9538
  3267. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3268. record.UltrafiltrationRate = ultrafiltration_rate
  3269. }
  3270. if template.TemplateId == 43 { //adminInfo.CurrentOrgId == 9538
  3271. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3272. record.UltrafiltrationRate = ultrafiltration_rate
  3273. }
  3274. if template.TemplateId == 46 || template.TemplateId == 54 { //adminInfo.CurrentOrgId == 9538
  3275. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3276. record.UltrafiltrationRate = ultrafiltration_rate
  3277. }
  3278. if template.TemplateId == 47 { //adminInfo.CurrentOrgId == 9538
  3279. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3280. record.UltrafiltrationRate = ultrafiltration_rate
  3281. }
  3282. // 只针对方济医院
  3283. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  3284. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3285. ultrafiltration_rate = value
  3286. record.UltrafiltrationRate = ultrafiltration_rate
  3287. }
  3288. }
  3289. }
  3290. // record.UltrafiltrationRate = ultrafiltration_rate
  3291. record.UltrafiltrationVolume = 0
  3292. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  3293. if ultrafiltration_rate > 0 {
  3294. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3295. record.UltrafiltrationVolume = value
  3296. }
  3297. }
  3298. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 {
  3299. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  3300. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3301. record.UltrafiltrationVolume = ultrafiltration_volume
  3302. }
  3303. }
  3304. if template.TemplateId == 47 || template.TemplateId == 54 {
  3305. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3306. }
  3307. this.ServeSuccessJSON(map[string]interface{}{
  3308. "monitor": record,
  3309. })
  3310. }
  3311. func (c *DialysisApiController) UploadDryWeight() {
  3312. patient_id, _ := c.GetInt64("id")
  3313. dry_weight, _ := c.GetFloat("dry_weight")
  3314. doctor_id, _ := c.GetInt64("doctor_id")
  3315. remark := c.GetString("remark")
  3316. adminUserInfo := c.GetAdminUserInfo()
  3317. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  3318. fmt.Println(err)
  3319. if err == gorm.ErrRecordNotFound {
  3320. dryWeight := &models.SgjPatientDryweight{
  3321. PatientId: patient_id,
  3322. DryWeight: dry_weight,
  3323. Remakes: remark,
  3324. Ctime: time.Now().Unix(),
  3325. Mtime: time.Now().Unix(),
  3326. Creator: doctor_id,
  3327. Status: 1,
  3328. UserOrgId: adminUserInfo.CurrentOrgId,
  3329. AdjustedValue: "/",
  3330. UserId: adminUserInfo.AdminUser.Id,
  3331. }
  3332. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3333. loc, _ := time.LoadLocation("Local")
  3334. nowTime := time.Now()
  3335. nowDay := nowTime.Format("2006-01-02")
  3336. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3337. redis := service.RedisClient()
  3338. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  3339. redis.Set(keyOne, "", time.Second)
  3340. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3341. redis.Set(key, "", time.Second)
  3342. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3343. redis.Set(keyTwo, "", time.Second)
  3344. redis.Close()
  3345. if createErr == nil {
  3346. c.ServeSuccessJSON(map[string]interface{}{
  3347. "msg": "提交成功",
  3348. "weight": dryWeight,
  3349. })
  3350. }
  3351. } else {
  3352. dryWeight := &models.SgjPatientDryweight{
  3353. PatientId: patient_id,
  3354. DryWeight: dry_weight,
  3355. Remakes: remark,
  3356. Ctime: time.Now().Unix(),
  3357. Mtime: time.Now().Unix(),
  3358. Creator: doctor_id,
  3359. Status: 1,
  3360. UserOrgId: adminUserInfo.CurrentOrgId,
  3361. AdjustedValue: "/",
  3362. UserId: adminUserInfo.AdminUser.Id,
  3363. }
  3364. var value float64
  3365. value = dry_weight - weightAdjust.DryWeight
  3366. fmt.Println(value)
  3367. if value < 0 {
  3368. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  3369. } else if value == 0 {
  3370. dryWeight.AdjustedValue = "/"
  3371. } else if value > 0 {
  3372. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  3373. }
  3374. fmt.Println(value)
  3375. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3376. loc, _ := time.LoadLocation("Local")
  3377. nowTime := time.Now()
  3378. nowDay := nowTime.Format("2006-01-02")
  3379. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3380. redis := service.RedisClient()
  3381. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  3382. redis.Set(keyOne, "", time.Second)
  3383. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3384. redis.Set(key, "", time.Second)
  3385. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3386. redis.Set(keyTwo, "", time.Second)
  3387. redis.Close()
  3388. if createErr == nil {
  3389. c.ServeSuccessJSON(map[string]interface{}{
  3390. "msg": "提交成功",
  3391. "weight": dryWeight,
  3392. })
  3393. }
  3394. }
  3395. }
  3396. func (this *DialysisApiController) GetFuncPurview() {
  3397. adminUserInfo := this.GetAdminUserInfo()
  3398. user_id := adminUserInfo.AdminUser.Id
  3399. app_id := adminUserInfo.CurrentAppId
  3400. org_id := adminUserInfo.CurrentOrgId
  3401. create_url := this.GetString("create_url")
  3402. modify_url := this.GetString("modify_url")
  3403. modify_other_url := this.GetString("modify_other_url")
  3404. del_url := this.GetString("del_url")
  3405. del_other_url := this.GetString("del_other_url")
  3406. exce_url := this.GetString("exce_url")
  3407. check_url := this.GetString("check_url")
  3408. modify_exce_url := this.GetString("modify_exce_url")
  3409. module, _ := this.GetInt64("module", 0)
  3410. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  3411. var is_has_create bool
  3412. var is_has_modify bool
  3413. var is_has_modify_other bool
  3414. var is_has_del bool
  3415. var is_has_del_other bool
  3416. var is_has_exce bool
  3417. var is_has_check bool
  3418. var is_has_modify_exce bool
  3419. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  3420. if adminUserInfo.AdminUser.Id != org.Creator {
  3421. if app_role != nil {
  3422. if len(app_role.RoleIds) > 0 {
  3423. roles := strings.Split(app_role.RoleIds, ",")
  3424. var userRolePurviews string
  3425. for _, item := range roles {
  3426. role_id, _ := strconv.ParseInt(item, 10, 64)
  3427. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  3428. if len(userRolePurviews) == 0 {
  3429. userRolePurviews = purviews
  3430. } else {
  3431. userRolePurviews = userRolePurviews + "," + purviews
  3432. }
  3433. }
  3434. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  3435. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  3436. for _, item := range funcPurviews {
  3437. //for _, url := range strings.Split(item.Urlfor,","){
  3438. if strings.Split(item.Urlfor, ",")[1] == create_url {
  3439. is_has_create = true
  3440. }
  3441. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  3442. is_has_modify = true
  3443. }
  3444. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  3445. is_has_modify_other = true
  3446. }
  3447. if strings.Split(item.Urlfor, ",")[1] == del_url {
  3448. is_has_del = true
  3449. }
  3450. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  3451. is_has_del_other = true
  3452. }
  3453. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  3454. is_has_exce = true
  3455. }
  3456. if strings.Split(item.Urlfor, ",")[1] == check_url {
  3457. is_has_check = true
  3458. }
  3459. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  3460. is_has_modify_exce = true
  3461. }
  3462. }
  3463. } else {
  3464. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  3465. return
  3466. }
  3467. this.ServeSuccessJSON(map[string]interface{}{
  3468. "is_has_create": is_has_create,
  3469. "is_has_modify": is_has_modify,
  3470. "is_has_modify_other": is_has_modify_other,
  3471. "is_has_del": is_has_del,
  3472. "is_has_del_other": is_has_del_other,
  3473. "is_has_exce": is_has_exce,
  3474. "is_has_check": is_has_check,
  3475. "is_has_modify_exce": is_has_modify_exce,
  3476. "module": module,
  3477. })
  3478. } else {
  3479. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  3480. return
  3481. }
  3482. } else {
  3483. this.ServeSuccessJSON(map[string]interface{}{
  3484. "is_has_create": true,
  3485. "is_has_modify": true,
  3486. "is_has_modify_other": true,
  3487. "is_has_del": true,
  3488. "is_has_del_other": true,
  3489. "is_has_exce": true,
  3490. "is_has_check": true,
  3491. "is_has_modify_exce": true,
  3492. "module": true,
  3493. })
  3494. }
  3495. }
  3496. func (this *DialysisApiController) GetOrderDoctorAdvice() {
  3497. patient_id, _ := this.GetInt64("patient_id", 0)
  3498. advice_date, _ := this.GetInt64("advice_date")
  3499. adminUserInfo := this.GetAdminUserInfo()
  3500. doctorAdvice, _ := service.GetBloodDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  3501. hisDoctorAdvice, _ := service.GetHisDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  3502. this.ServeSuccessJSON(map[string]interface{}{
  3503. "doctorAdvice": doctorAdvice,
  3504. "hisDoctorAdvice": hisDoctorAdvice,
  3505. })
  3506. }
  3507. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  3508. change_type, _ := this.GetInt64("type", 0)
  3509. record_date := this.GetString("record_time")
  3510. patient_id, _ := this.GetInt64("patient_id", 0)
  3511. timeLayout := "2006-01-02"
  3512. loc, _ := time.LoadLocation("Local")
  3513. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3514. record_time := theAdviceRecordTime.Unix()
  3515. adminUserInfo := this.GetAdminUserInfo()
  3516. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  3517. if err == nil {
  3518. if len(advices) == 0 {
  3519. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  3520. return
  3521. } else {
  3522. this.ServeSuccessJSON(map[string]interface{}{
  3523. "advices": advices,
  3524. "schedule": sch,
  3525. })
  3526. return
  3527. }
  3528. } else {
  3529. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3530. return
  3531. }
  3532. }
  3533. func (c *DialysisApiController) GetDialysisGoods() {
  3534. schedualDate := c.GetString("schedule_date")
  3535. schedule_type, _ := c.GetInt64("schedule_type")
  3536. partition_id, _ := c.GetInt64("partition_id")
  3537. page, _ := c.GetInt("page")
  3538. limit, _ := c.GetInt("limit")
  3539. keywords := c.GetString("keywords")
  3540. patient_id, _ := c.GetInt64("patient_id")
  3541. good_type, _ := c.GetInt64("good_type")
  3542. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  3543. if parseDateErr != nil && len(schedualDate) != 0 {
  3544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3545. return
  3546. }
  3547. schedualEndDate := int64(0)
  3548. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  3549. if parseDateErr != nil && len(schedualDate) != 0 {
  3550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3551. return
  3552. }
  3553. schedualEndDate = endDate.Unix()
  3554. adminUser := c.GetAdminUserInfo()
  3555. _, err := service.FindStockOutByIsSys(adminUser.CurrentOrgId, 1, date.Unix())
  3556. goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
  3557. if err == gorm.ErrRecordNotFound {
  3558. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  3559. var ids []int64
  3560. for _, item := range list {
  3561. ids = append(ids, item.PatientId)
  3562. }
  3563. dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  3564. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3565. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  3566. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  3567. item.LastAutomaticReduceDetail = goodUser
  3568. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3569. }
  3570. c.ServeSuccessJSON(map[string]interface{}{
  3571. "dialysis_goods": dialysisGoods,
  3572. "good_type": goodTypes,
  3573. "total": total,
  3574. })
  3575. return
  3576. } else if err == nil {
  3577. //获取当天排班的每个患者的库存使用情况
  3578. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  3579. var ids []int64
  3580. for _, item := range list {
  3581. ids = append(ids, item.PatientId)
  3582. }
  3583. dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  3584. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3585. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  3586. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  3587. fmt.Println(goodUser)
  3588. fmt.Println(lastGoodUserDetial)
  3589. item.LastAutomaticReduceDetail = goodUser
  3590. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3591. }
  3592. if err == nil {
  3593. c.ServeSuccessJSON(map[string]interface{}{
  3594. "dialysis_goods": dialysisGoods,
  3595. "good_type": goodTypes,
  3596. "total": total,
  3597. })
  3598. return
  3599. } else {
  3600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3601. return
  3602. }
  3603. } else if err != nil {
  3604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3605. return
  3606. }
  3607. }
  3608. func (c *DialysisApiController) GetDialysisGoodsStatistics() {
  3609. start_time := c.GetString("start_time")
  3610. end_time := c.GetString("end_time")
  3611. timeLayout := "2006-01-02"
  3612. loc, _ := time.LoadLocation("Local")
  3613. var theStartTime int64
  3614. if len(start_time) > 0 {
  3615. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3616. if err != nil {
  3617. utils.ErrorLog(err.Error())
  3618. }
  3619. theStartTime = theTime.Unix()
  3620. }
  3621. var theEndtTime int64
  3622. if len(end_time) > 0 {
  3623. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3624. if err != nil {
  3625. utils.ErrorLog(err.Error())
  3626. }
  3627. theEndtTime = theTime.Unix()
  3628. }
  3629. adminUser := c.GetAdminUserInfo()
  3630. outInfo, err := service.MobileGetGoodsStatistics(adminUser.CurrentOrgId, theStartTime, theEndtTime)
  3631. if err == nil {
  3632. c.ServeSuccessJSON(map[string]interface{}{
  3633. "stock_out": outInfo,
  3634. })
  3635. return
  3636. } else {
  3637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3638. return
  3639. }
  3640. }
  3641. func (c *DialysisApiController) GetRoleList() {
  3642. orgId := c.GetAdminUserInfo().CurrentOrgId
  3643. admin_user_id, _ := c.GetInt64("admin_user_id")
  3644. list, err := service.GetRoleList(orgId, admin_user_id)
  3645. if err == nil {
  3646. c.ServeSuccessJSON(map[string]interface{}{
  3647. "adminRole": list,
  3648. })
  3649. return
  3650. } else {
  3651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3652. return
  3653. }
  3654. }
  3655. func (c *DialysisApiController) GetInitPrintData() {
  3656. patient_id, _ := c.GetInt64("patient_id")
  3657. record_date, _ := c.GetInt64("record_date")
  3658. orgId := c.GetAdminUserInfo().CurrentOrgId
  3659. list, err := service.GetInitPrintData(patient_id, record_date, orgId)
  3660. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, record_date, orgId)
  3661. if err == nil {
  3662. c.ServeSuccessJSON(map[string]interface{}{
  3663. "list": list,
  3664. "assessmentAfterDislysis": assessmentAfterDislysis,
  3665. })
  3666. return
  3667. } else {
  3668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3669. return
  3670. }
  3671. }
  3672. func (c *DialysisApiController) GetInitPrintDataOne() {
  3673. patient_id, _ := c.GetInt64("patient_id")
  3674. start_time := c.GetString("record_date")
  3675. timeLayout := "2006-01-02"
  3676. loc, _ := time.LoadLocation("Local")
  3677. var theStartTime int64
  3678. if len(start_time) > 0 {
  3679. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3680. if err != nil {
  3681. utils.ErrorLog(err.Error())
  3682. }
  3683. theStartTime = theTime.Unix()
  3684. }
  3685. orgId := c.GetAdminUserInfo().CurrentOrgId
  3686. list, err := service.GetInitPrintData(patient_id, theStartTime, orgId)
  3687. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, theStartTime, orgId)
  3688. if err == nil {
  3689. c.ServeSuccessJSON(map[string]interface{}{
  3690. "list": list,
  3691. "assessmentAfterDislysis": assessmentAfterDislysis,
  3692. })
  3693. return
  3694. } else {
  3695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3696. return
  3697. }
  3698. }