dialysis_api_controller.go 122KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263
  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/advice_remind/create", &DialysisApiController{}, "Post:CreateRemindDoctorAdvice")
  41. beego.Router("/api/solution/get", &DialysisApiController{}, "Get:GetSolution")
  42. beego.Router("/api/schedule/get", &DialysisApiController{}, "Get:GetSchedule")
  43. beego.Router("/api/today_monitor/get", &DialysisApiController{}, "Get:GetTodayMonitor")
  44. beego.Router("/api/dryweight/commit", &DialysisApiController{}, "Post:UploadDryWeight")
  45. beego.Router("/api/func_per/get", &DialysisApiController{}, "Get:GetFuncPurview")
  46. beego.Router("/api/doctoradvice/get", &DialysisApiController{}, "Get:GetLastOrNextDoctorAdvice")
  47. beego.Router("/api/dialysisgoods/get", &DialysisApiController{}, "Get:GetDialysisGoods")
  48. beego.Router("/api/goodstatistics/get", &DialysisApiController{}, "Get:GetDialysisGoodsStatistics")
  49. beego.Router("/api/queue/get", &DialysisApiController{}, "Get:GetQueueCall")
  50. beego.Router("/api/queue/update", &DialysisApiController{}, "Get:UpdateQueueCall")
  51. }
  52. func (c *DialysisApiController) GetQueueCall() {
  53. adminUserInfo := c.GetAdminUserInfo()
  54. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  55. if queueConfig.ID <= 0 {
  56. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  57. queueConfig.Qhsj = 10
  58. queueConfig.Jzdcbbcs = 3
  59. queueConfig.Jzbbsy = 1
  60. queueConfig.Jzjhyc = 0
  61. queueConfig.Sjdcbbcs = 3
  62. queueConfig.Sjbbsy = 0
  63. queueConfig.Sjjhyc = 0
  64. queueConfig.Txxqyxs = 0
  65. queueConfig.Txglsyxs = 0
  66. }
  67. c.ServeSuccessJSON(map[string]interface{}{
  68. "queue_config": queueConfig,
  69. })
  70. }
  71. func (c *DialysisApiController) UpdateQueueCall() {
  72. adminUserInfo := c.GetAdminUserInfo()
  73. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  74. if queueConfig.ID <= 0 {
  75. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  76. queueConfig.Qhsj = 10
  77. queueConfig.Jzdcbbcs = 3
  78. queueConfig.Jzbbsy = 1
  79. queueConfig.Jzjhyc = 0
  80. queueConfig.Sjdcbbcs = 3
  81. queueConfig.Sjbbsy = 0
  82. queueConfig.Sjjhyc = 0
  83. queueConfig.Txxqyxs = 0
  84. queueConfig.Txglsyxs = 0
  85. queueConfig.CreateTime = time.Now().Unix()
  86. queueConfig.UpdateTime = time.Now().Unix()
  87. }
  88. qhsj, _ := c.GetInt64("qhsj", 0)
  89. if qhsj > 0 {
  90. queueConfig.Qhsj = qhsj
  91. }
  92. jzdcbbcs, _ := c.GetInt64("jzdcbbcs", 0)
  93. if jzdcbbcs > 0 {
  94. queueConfig.Jzdcbbcs = jzdcbbcs
  95. }
  96. jzbbsy, _ := c.GetInt64("jzbbsy", 0)
  97. if jzbbsy > 0 {
  98. queueConfig.Jzbbsy = jzbbsy
  99. }
  100. jzjhyc, _ := c.GetInt64("jzjhyc", 0)
  101. queueConfig.Jzjhyc = jzjhyc
  102. sjdcbbcs, _ := c.GetInt64("sjdcbbcs", 0)
  103. if sjdcbbcs > 0 {
  104. queueConfig.Sjdcbbcs = sjdcbbcs
  105. }
  106. sjbbsy, _ := c.GetInt64("sjbbsy", 0)
  107. if sjbbsy > 0 {
  108. queueConfig.Sjbbsy = sjbbsy
  109. }
  110. sjjhyc, _ := c.GetInt64("sjjhyc", 0)
  111. queueConfig.Sjjhyc = sjjhyc
  112. txxqyxs, _ := c.GetInt64("txxqyxs", 0)
  113. queueConfig.Txxqyxs = txxqyxs
  114. txglsyxs, _ := c.GetInt64("txglsyxs", 0)
  115. queueConfig.Txglsyxs = txglsyxs
  116. queueConfig.UpdateTime = time.Now().Unix()
  117. service.UpDateQueueCallInfo(queueConfig)
  118. c.ServeSuccessJSON(map[string]interface{}{
  119. "queue_config": queueConfig,
  120. })
  121. }
  122. func (c *DialysisApiController) PostPrescription() {
  123. patient, _ := c.GetInt64("patient", 0)
  124. recordDateStr := c.GetString("record_date")
  125. if patient <= 0 {
  126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  127. return
  128. }
  129. adminUserInfo := c.GetAdminUserInfo()
  130. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  131. if patientInfo.ID == 0 {
  132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  133. return
  134. }
  135. if len(recordDateStr) == 0 {
  136. recordDateStr = time.Now().Format("2006-01-02")
  137. }
  138. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  139. if parseDateErr != nil {
  140. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  142. return
  143. }
  144. mode_id, _ := c.GetInt64("mode_id", 0)
  145. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  146. dialyzer, _ := c.GetInt64("dialyzer", 0)
  147. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  148. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  149. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  150. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  151. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  152. replacement_way, _ := c.GetInt64("replacement_way", 0)
  153. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  154. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  155. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  156. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  157. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  158. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  159. kalium, _ := c.GetFloat("kalium", 0)
  160. sodium, _ := c.GetFloat("sodium", 0)
  161. replacement_total, _ := c.GetFloat("replacement_total", 0)
  162. calcium, _ := c.GetFloat("calcium", 0)
  163. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  164. glucose, _ := c.GetFloat("glucose", 0)
  165. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  166. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  167. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  168. conductivity, _ := c.GetFloat("conductivity", 0)
  169. remark := c.GetString("remark")
  170. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  171. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  172. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  173. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  174. body_fluid, _ := c.GetInt64("body_fluid", 0)
  175. special_medicine, _ := c.GetInt64("special_medicine", 0)
  176. special_medicine_other := c.GetString("special_medicine_other")
  177. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  178. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  179. blood_access, _ := c.GetInt64("blood_access", 0)
  180. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  181. body_fluid_other := c.GetString("body_fluid_other")
  182. target_ktv, _ := c.GetFloat("target_ktv", 0)
  183. niprocart, _ := c.GetInt64("niprocart", 0)
  184. jms, _ := c.GetInt64("jms", 0)
  185. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  186. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  187. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  188. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  189. filtryzer, _ := c.GetInt64("filtryzer", 0)
  190. dialyzers, _ := c.GetInt64("dialyzers", 0)
  191. injector, _ := c.GetInt64("injector", 0)
  192. bloodlines, _ := c.GetInt64("bloodlines", 0)
  193. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  194. safe_package, _ := c.GetInt64("package", 0)
  195. a_liquid, _ := c.GetInt64("a_liquid", 0)
  196. preImpules, _ := c.GetFloat("pre_impulse", 0)
  197. fmt.Println("", preImpules)
  198. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  199. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  200. //heparin_sodium := c.GetString("heparin_sodium")
  201. //fmt.Println("肝素钠",heparin_sodium)
  202. //nucleoprotamine := c.GetString("nucleoprotamine")
  203. //fmt.Println("鱼精蛋白",nucleoprotamine)
  204. //push_the_protamine := c.GetString("push_the_protamine")
  205. //fmt.Println("下机前推注鱼精蛋白",push_the_protamine)
  206. // var prescription_doctor int64
  207. blood := c.GetString("blood")
  208. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  209. dialysis_irrigation := c.GetString("dialysis_irrigation")
  210. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  211. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  212. //if template.TemplateId == 2 || template.TemplateId == 6 {
  213. // if appRole.UserType == 3 {
  214. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  215. // if getPermissionErr != nil {
  216. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  217. // return
  218. // } else if headNursePermission == nil {
  219. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  220. // return
  221. // }
  222. // }
  223. //}
  224. prescription := models.DialysisPrescription{
  225. UserOrgId: adminUserInfo.CurrentOrgId,
  226. PatientId: patient,
  227. RecordDate: recordDate.Unix(),
  228. ModeId: mode_id,
  229. DialysisDuration: dialysis_duration,
  230. Dialyzer: dialyzer,
  231. ReplacementTotal: replacement_total,
  232. PerfusionApparatus: perfusion_apparatus,
  233. BloodFlowVolume: blood_flow_volume,
  234. DewaterAmount: dewater_amount,
  235. DisplaceLiqui: displace_liqui,
  236. ReplacementWay: replacement_way,
  237. Anticoagulant: anticoagulant,
  238. AnticoagulantShouji: anticoagulant_shouji,
  239. AnticoagulantWeichi: anticoagulant_weichi,
  240. AnticoagulantZongliang: anticoagulant_zongliang,
  241. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  242. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  243. Kalium: kalium,
  244. Sodium: sodium,
  245. Calcium: calcium,
  246. Bicarbonate: bicarbonate,
  247. Glucose: glucose,
  248. // DryWeight: dry_weight,
  249. DialysateFlow: dialysate_flow,
  250. DialysateTemperature: dialysate_temperature,
  251. Conductivity: conductivity,
  252. Remark: remark,
  253. Status: 1,
  254. CreatedTime: time.Now().Unix(),
  255. UpdatedTime: time.Now().Unix(),
  256. DialysisDurationMinute: dialysisDurationMinute,
  257. DialysisDurationHour: dialysisDurationHour,
  258. TargetUltrafiltration: targetUltrafiltration,
  259. DialysateFormulation: dialysateFormulation,
  260. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  261. BodyFluid: body_fluid,
  262. SpecialMedicine: special_medicine,
  263. SpecialMedicineOther: special_medicine_other,
  264. DisplaceLiquiPart: displace_liqui_part,
  265. DisplaceLiquiValue: displace_liqui_value,
  266. BloodAccess: blood_access,
  267. Ultrafiltration: ultrafiltration,
  268. BodyFluidOther: body_fluid_other,
  269. TargetKtv: target_ktv,
  270. Niprocart: niprocart,
  271. Jms: jms,
  272. FistulaNeedleSet: fistula_needle_set,
  273. FistulaNeedleSet16: fistula_needle_set_16,
  274. Hemoperfusion: hemoperfusion,
  275. DialyserSterilised: dialyser_sterilised,
  276. Filtryzer: filtryzer,
  277. Dialyzers: dialyzers,
  278. Injector: injector,
  279. Bloodlines: bloodlines,
  280. TubingHemodialysis: tubing_hemodialysis,
  281. Package: safe_package,
  282. ALiquid: a_liquid,
  283. PreImpulse: preImpules,
  284. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  285. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  286. Blood: blood,
  287. DialysisDialyszers: dialysis_dialyszers,
  288. DialysisIrrigation: dialysis_irrigation,
  289. }
  290. if appRole.UserType == 2 || appRole.UserType == 1 {
  291. prescription.PrescriptionDoctor = appRole.AdminUserId
  292. }
  293. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  294. if dialysisPrescription.ID == 0 { //新增
  295. if mode_id > 0 {
  296. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  297. }
  298. prescription.Creater = adminUserInfo.AdminUser.Id
  299. err := service.AddSigleRecord(&prescription)
  300. if err == nil {
  301. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  302. if updateErr != nil {
  303. utils.ErrorLog("%v", updateErr)
  304. }
  305. c.ServeSuccessJSON(map[string]interface{}{
  306. "prescription": &prescription,
  307. })
  308. } else {
  309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  310. }
  311. } else { //修改
  312. if mode_id > 0 {
  313. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  314. }
  315. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  316. //if template.TemplateId == 1 {
  317. // if dialysisPrescription.Creater > 0 && dialysisPrescription.Creater != adminUserInfo.AdminUser.Id {
  318. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  319. // if getPermissionErr != nil {
  320. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  321. // return
  322. // } else if headNursePermission == nil {
  323. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  324. // return
  325. // }
  326. // }
  327. //}
  328. if appRole.UserType == 2 || appRole.UserType == 1 {
  329. prescription_doctor := adminUserInfo.AdminUser.Id
  330. prescription.PrescriptionDoctor = prescription_doctor
  331. }
  332. if dialysisPrescription.Creater == 0 { //体重称
  333. prescription.Creater = adminUserInfo.AdminUser.Id
  334. } else {
  335. prescription.Creater = dialysisPrescription.Creater
  336. }
  337. prescription.CreatedTime = dialysisPrescription.CreatedTime
  338. prescription.UpdatedTime = time.Now().Unix()
  339. prescription.Modifier = adminUserInfo.AdminUser.Id
  340. prescription.ID = dialysisPrescription.ID
  341. updateErr := service.UpDateDialysisPrescription(&prescription)
  342. if updateErr == nil {
  343. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  344. if updateErr != nil {
  345. utils.ErrorLog("%v", updateErr)
  346. }
  347. c.ServeSuccessJSON(map[string]interface{}{
  348. "prescription": &prescription,
  349. })
  350. } else {
  351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  352. }
  353. }
  354. }
  355. func (c *DialysisApiController) PostSoulution() {
  356. patient, _ := c.GetInt64("patient", 0)
  357. recordDateStr := c.GetString("record_date")
  358. if patient <= 0 {
  359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  360. return
  361. }
  362. adminUserInfo := c.GetAdminUserInfo()
  363. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  364. if patientInfo.ID == 0 {
  365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  366. return
  367. }
  368. if len(recordDateStr) == 0 {
  369. recordDateStr = time.Now().Format("2006-01-02")
  370. }
  371. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  372. if parseDateErr != nil {
  373. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  375. return
  376. }
  377. mode_id, _ := c.GetInt64("mode_id", 0)
  378. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  379. dialyzer, _ := c.GetInt64("dialyzer", 0)
  380. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  381. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  382. replacement_total, _ := c.GetFloat("replacement_total", 0)
  383. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  384. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  385. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  386. replacement_way, _ := c.GetInt64("replacement_way", 0)
  387. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  388. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  389. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  390. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  391. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  392. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  393. kalium, _ := c.GetFloat("kalium", 0)
  394. sodium, _ := c.GetFloat("sodium", 0)
  395. calcium, _ := c.GetFloat("calcium", 0)
  396. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  397. glucose, _ := c.GetFloat("glucose", 0)
  398. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  399. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  400. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  401. conductivity, _ := c.GetFloat("conductivity", 0)
  402. remark := c.GetString("remark")
  403. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  404. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  405. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  406. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  407. body_fluid, _ := c.GetInt64("body_fluid", 0)
  408. special_medicine, _ := c.GetInt64("special_medicine", 0)
  409. special_medicine_other := c.GetString("special_medicine_other")
  410. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  411. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  412. blood_access, _ := c.GetInt64("blood_access", 0)
  413. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  414. body_fluid_other := c.GetString("body_fluid_other")
  415. target_ktv, _ := c.GetFloat("target_ktv", 0)
  416. niprocart, _ := c.GetInt64("niprocart", 0)
  417. jms, _ := c.GetInt64("jms", 0)
  418. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  419. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  420. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  421. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  422. filtryzer, _ := c.GetInt64("filtryzer", 0)
  423. dialyzers, _ := c.GetInt64("dialyzers", 0)
  424. injector, _ := c.GetInt64("injector", 0)
  425. bloodlines, _ := c.GetInt64("bloodlines", 0)
  426. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  427. safe_package, _ := c.GetInt64("package", 0)
  428. a_liquid, _ := c.GetInt64("a_liquid", 0)
  429. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  430. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  431. blood := c.GetString("blood")
  432. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  433. dialysis_irrigation := c.GetString("dialysis_irrigation")
  434. var prescription_doctor int64
  435. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  436. if appRole.UserType == 2 || appRole.UserType == 1 {
  437. prescription_doctor = appRole.AdminUserId
  438. }
  439. if mode_id > 0 {
  440. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  441. }
  442. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  443. //
  444. //if template.TemplateId == 2 || template.TemplateId == 6 {
  445. // if appRole.UserType == 3 {
  446. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  447. // if getPermissionErr != nil {
  448. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  449. // return
  450. // } else if headNursePermission == nil {
  451. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  452. // return
  453. // }
  454. // }
  455. //}
  456. prescription := models.DialysisPrescription{
  457. UserOrgId: adminUserInfo.CurrentOrgId,
  458. PatientId: patient,
  459. RecordDate: recordDate.Unix(),
  460. ModeId: mode_id,
  461. DialysisDuration: dialysis_duration,
  462. Dialyzer: dialyzer,
  463. PerfusionApparatus: perfusion_apparatus,
  464. BloodFlowVolume: blood_flow_volume,
  465. DewaterAmount: dewater_amount,
  466. DisplaceLiqui: displace_liqui,
  467. ReplacementWay: replacement_way,
  468. Anticoagulant: anticoagulant,
  469. AnticoagulantShouji: anticoagulant_shouji,
  470. AnticoagulantWeichi: anticoagulant_weichi,
  471. AnticoagulantZongliang: anticoagulant_zongliang,
  472. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  473. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  474. Kalium: kalium,
  475. Sodium: sodium,
  476. Calcium: calcium,
  477. Bicarbonate: bicarbonate,
  478. Glucose: glucose,
  479. // DryWeight: dry_weight,
  480. DialysateFlow: dialysate_flow,
  481. DialysateTemperature: dialysate_temperature,
  482. Conductivity: conductivity,
  483. Remark: remark,
  484. PrescriptionDoctor: prescription_doctor,
  485. Status: 1,
  486. CreatedTime: time.Now().Unix(),
  487. UpdatedTime: time.Now().Unix(),
  488. DialysisDurationMinute: dialysisDurationMinute,
  489. DialysisDurationHour: dialysisDurationHour,
  490. TargetUltrafiltration: targetUltrafiltration,
  491. DialysateFormulation: dialysateFormulation,
  492. ReplacementTotal: replacement_total,
  493. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  494. BodyFluid: body_fluid,
  495. SpecialMedicine: special_medicine,
  496. SpecialMedicineOther: special_medicine_other,
  497. DisplaceLiquiPart: displace_liqui_part,
  498. DisplaceLiquiValue: displace_liqui_value,
  499. BloodAccess: blood_access,
  500. Ultrafiltration: ultrafiltration,
  501. BodyFluidOther: body_fluid_other,
  502. TargetKtv: target_ktv,
  503. Niprocart: niprocart,
  504. Jms: jms,
  505. FistulaNeedleSet: fistula_needle_set,
  506. FistulaNeedleSet16: fistula_needle_set_16,
  507. Hemoperfusion: hemoperfusion,
  508. DialyserSterilised: dialyser_sterilised,
  509. Filtryzer: filtryzer,
  510. Dialyzers: dialyzers,
  511. Injector: injector,
  512. Bloodlines: bloodlines,
  513. TubingHemodialysis: tubing_hemodialysis,
  514. Package: safe_package,
  515. ALiquid: a_liquid,
  516. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  517. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  518. Blood: blood,
  519. DialysisIrrigation: dialysis_irrigation,
  520. DialysisDialyszers: dialysis_dialyszers,
  521. }
  522. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  523. if dialysisPrescription.ID == 0 { //新增
  524. if appRole.UserType == 2 || appRole.UserType == 1 {
  525. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  526. }
  527. prescription.Creater = adminUserInfo.AdminUser.Id
  528. //prescription.Creater = adminUserInfo.AdminUser.Id
  529. } else { //修改
  530. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  531. //if template.TemplateId == 1 {
  532. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  533. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  534. // if getPermissionErr != nil {
  535. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  536. // return
  537. // } else if headNursePermission == nil {
  538. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  539. // return
  540. // }
  541. // }
  542. //}
  543. if appRole.UserType == 2 || appRole.UserType == 1 {
  544. prescription_doctor := adminUserInfo.AdminUser.Id
  545. prescription.PrescriptionDoctor = prescription_doctor
  546. } else {
  547. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  548. }
  549. if dialysisPrescription.Creater == 0 {
  550. prescription.Creater = adminUserInfo.AdminUser.Id
  551. } else {
  552. prescription.Creater = dialysisPrescription.Creater
  553. }
  554. prescription.CreatedTime = dialysisPrescription.CreatedTime
  555. prescription.UpdatedTime = time.Now().Unix()
  556. prescription.Modifier = adminUserInfo.AdminUser.Id
  557. prescription.ID = dialysisPrescription.ID
  558. }
  559. solution := models.DialysisSolution{
  560. RegistrarsId: adminUserInfo.AdminUser.Id,
  561. UserOrgId: adminUserInfo.CurrentOrgId,
  562. Doctor: prescription_doctor,
  563. PatientId: patient,
  564. ModeId: mode_id,
  565. DialysisDuration: dialysis_duration,
  566. PerfusionApparatus: perfusion_apparatus,
  567. BloodFlowVolume: blood_flow_volume,
  568. Dewater: dewater_amount,
  569. DisplaceLiqui: displace_liqui,
  570. ReplacementWay: replacement_way,
  571. Anticoagulant: anticoagulant,
  572. AnticoagulantShouji: anticoagulant_shouji,
  573. AnticoagulantWeichi: anticoagulant_weichi,
  574. AnticoagulantZongliang: anticoagulant_zongliang,
  575. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  576. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  577. Kalium: kalium,
  578. Sodium: sodium,
  579. Calcium: calcium,
  580. Bicarbonate: bicarbonate,
  581. Glucose: glucose,
  582. // DryWeight: dry_weight,
  583. DialysateFlow: dialysate_flow,
  584. DialysateTemperature: dialysate_temperature,
  585. Conductivity: conductivity,
  586. Remark: remark,
  587. Status: 1,
  588. CreatedTime: time.Now().Unix(),
  589. UpdatedTime: time.Now().Unix(),
  590. DialysisDurationMinute: dialysisDurationMinute,
  591. DialysisDurationHour: dialysisDurationHour,
  592. TargetUltrafiltration: targetUltrafiltration,
  593. DialysateFormulation: dialysateFormulation,
  594. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  595. BodyFluid: body_fluid,
  596. SpecialMedicine: special_medicine,
  597. SpecialMedicineOther: special_medicine_other,
  598. DisplaceLiquiPart: displace_liqui_part,
  599. DisplaceLiquiValue: displace_liqui_value,
  600. BloodAccess: blood_access,
  601. Ultrafiltration: ultrafiltration,
  602. BodyFluidOther: body_fluid_other,
  603. ReplacementTotal: replacement_total,
  604. TargetKtv: target_ktv,
  605. }
  606. err := service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  607. if err == nil {
  608. c.ServeSuccessJSON(map[string]interface{}{
  609. "solution": &solution,
  610. "prescription": &prescription,
  611. })
  612. } else {
  613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  614. }
  615. }
  616. func (c *DialysisApiController) PostDouleCheck() {
  617. id, _ := c.GetInt64("patient", 0)
  618. recordDateStr := c.GetString("record_date")
  619. checkTimeStr := c.GetString("check_time")
  620. firstCheckTimeStr := c.GetString("first_check_time")
  621. creater, _ := c.GetInt64("creater", 0)
  622. modifier, _ := c.GetInt64("modifier", 0)
  623. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  624. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  625. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  626. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  627. dialysis_item_desc := c.GetString("dialysis_item_desc")
  628. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  629. vascular_access_desc := c.GetString("vascular_access_desc")
  630. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  631. collator, _ := c.GetInt64("collator", 0)
  632. if id <= 0 {
  633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  634. return
  635. }
  636. adminUserInfo := c.GetAdminUserInfo()
  637. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  638. if patient.ID == 0 {
  639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  640. return
  641. }
  642. if len(recordDateStr) == 0 {
  643. recordDateStr = time.Now().Format("2006-01-02")
  644. }
  645. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  646. if parseDateErr != nil {
  647. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  649. return
  650. }
  651. var checkDate int64
  652. if len(checkTimeStr) == 0 {
  653. //checkTimeStr = time.Now().Format("2006-01-02 15:04")
  654. checkDate = 0
  655. } else {
  656. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", checkTimeStr)
  657. checkDate = checkDateUnix.Unix()
  658. }
  659. var firstCheckTimeDate int64
  660. if len(firstCheckTimeStr) == 0 {
  661. //firstCheckTimeStr = time.Now().Format("2006-01-02 15:04")
  662. firstCheckTimeDate = 0
  663. } else {
  664. firstCheckTimeDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", firstCheckTimeStr)
  665. firstCheckTimeDate = firstCheckTimeDateUnix.Unix()
  666. }
  667. doubleCheck := models.DoubleCheck{
  668. UserOrgId: adminUserInfo.CurrentOrgId,
  669. PatientId: id,
  670. DialysisItemCheck: dialysis_item_check,
  671. DialysisParameterCheck: dialysis_parameter_check,
  672. VascularAccessVerification: vascular_access_verification,
  673. PipelineConnectionCheck: pipeline_connection_check,
  674. DialysisItemDesc: dialysis_item_desc,
  675. DialysisParameterDesc: dialysis_parameter_desc,
  676. VascularAccessDesc: vascular_access_desc,
  677. PipelineConnectionDesc: pipeline_connection_desc,
  678. Collator: collator,
  679. Status: 1,
  680. CreatedTime: time.Now().Unix(),
  681. UpdatedTime: time.Now().Unix(),
  682. CheckDate: recordDate.Unix(),
  683. }
  684. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  685. if check.ID == 0 { //新增
  686. doubleCheck.FirstCheckTime = firstCheckTimeDate
  687. doubleCheck.CheckTime = checkDate
  688. doubleCheck.Creater = creater
  689. doubleCheck.Modifier = modifier
  690. err := service.AddSigleDoubleCheck(&doubleCheck)
  691. if err == nil {
  692. c.ServeSuccessJSON(map[string]interface{}{
  693. "doubleCheck": doubleCheck,
  694. })
  695. } else {
  696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  697. }
  698. } else { //修改
  699. doubleCheck.FirstCheckTime = firstCheckTimeDate
  700. doubleCheck.CheckTime = checkDate
  701. doubleCheck.Creater = creater
  702. doubleCheck.Modifier = modifier
  703. doubleCheck.CreatedTime = check.CreatedTime
  704. doubleCheck.UpdatedTime = time.Now().Unix()
  705. doubleCheck.ID = check.ID
  706. err := service.UpdateDoubleCheck(&doubleCheck)
  707. if err == nil {
  708. c.ServeSuccessJSON(map[string]interface{}{
  709. "doubleCheck": doubleCheck,
  710. })
  711. } else {
  712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  713. }
  714. }
  715. }
  716. func (c *DialysisApiController) PostReceiveTreatmentAsses() {
  717. id, _ := c.GetInt64("patient", 0)
  718. recordDateStr := c.GetString("record_date")
  719. way, _ := c.GetInt64("way", 0)
  720. consciousness, _ := c.GetInt64("consciousness", 0)
  721. appetite, _ := c.GetInt64("appetite", 0)
  722. condition, _ := c.GetInt64("condition", 0)
  723. posture, _ := c.GetInt64("posture")
  724. score := c.GetString("score")
  725. sick_condition, _ := c.GetInt64("sick_condition", 0)
  726. danger_level, _ := c.GetInt64("danger_level", 0)
  727. intake, _ := c.GetInt64("intake", 0)
  728. nutrition, _ := c.GetInt64("nutrition", 0)
  729. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  730. psychological_assessment_other := c.GetString("psychological_assessment_other")
  731. sick_condition_other := c.GetString("sick_condition_other")
  732. //precaution, _ := c.GetInt64("precaution", 0)
  733. precaution := c.GetString("precaution")
  734. precaution_other := c.GetString("precaution_other")
  735. psychological_other := c.GetString("psychological_other")
  736. admission_number := c.GetString("admission_number")
  737. if id <= 0 {
  738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  739. return
  740. }
  741. adminUserInfo := c.GetAdminUserInfo()
  742. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  743. if patient.ID == 0 {
  744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  745. return
  746. }
  747. if len(recordDateStr) == 0 {
  748. recordDateStr = time.Now().Format("2006-01-02")
  749. }
  750. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  751. if parseDateErr != nil {
  752. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  754. return
  755. }
  756. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  757. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  758. UserOrgId: adminUserInfo.CurrentOrgId,
  759. PatientId: id,
  760. RecordDate: recordDate.Unix(),
  761. Way: way,
  762. Consciousness: consciousness,
  763. Appetite: appetite,
  764. Condition: condition,
  765. SickCondition: sick_condition,
  766. DangerLevel: danger_level,
  767. Intake: intake,
  768. Nutrition: nutrition,
  769. PsychologicalAssessment: psychological_assessment,
  770. PsychologicalAssessmentOther: psychological_assessment_other,
  771. SickConditionOther: sick_condition_other,
  772. Posture: posture,
  773. CreatedTime: time.Now().Unix(),
  774. UpdateTime: time.Now().Unix(),
  775. Status: 1,
  776. Score: score,
  777. Precaution: precaution,
  778. PrecautionOther: precaution_other,
  779. PsychologicalOther: psychological_other,
  780. AdmissionNumber: admission_number,
  781. }
  782. if receiveTreatment.ID == 0 { //新增
  783. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  784. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  785. if err == nil {
  786. c.ServeSuccessJSON(map[string]interface{}{
  787. "receiveTreatmentAsses": receiveTreatmentAsses,
  788. })
  789. } else {
  790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  791. }
  792. } else { //修改
  793. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  794. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  795. // if getPermissionErr != nil {
  796. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  797. // return
  798. // } else if headNursePermission == nil {
  799. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  800. // return
  801. // }
  802. //}
  803. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  804. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  805. receiveTreatmentAsses.UpdateTime = time.Now().Unix()
  806. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  807. receiveTreatmentAsses.ID = receiveTreatment.ID
  808. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  809. if err == nil {
  810. c.ServeSuccessJSON(map[string]interface{}{
  811. "receiveTreatmentAsses": receiveTreatmentAsses,
  812. })
  813. } else {
  814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  815. }
  816. }
  817. }
  818. func (c *DialysisApiController) PostAssessmentAfterDislysis() {
  819. patient, _ := c.GetInt64("patient", 0)
  820. recordDateStr := c.GetString("record_date")
  821. fmt.Println(recordDateStr)
  822. if patient <= 0 {
  823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  824. return
  825. }
  826. adminUserInfo := c.GetAdminUserInfo()
  827. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  828. if patientInfo.ID == 0 {
  829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  830. return
  831. }
  832. if len(recordDateStr) == 0 {
  833. recordDateStr = time.Now().Format("2006-01-02")
  834. }
  835. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  836. if parseDateErr != nil {
  837. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  839. return
  840. }
  841. // data := make(map[string]interface{}, 0)
  842. var data models.AssessmentAfterDislysis
  843. var err error
  844. err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
  845. fmt.Println(err)
  846. if err != nil {
  847. c.ErrorLog("数据解析错误:%v", err)
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  849. return
  850. }
  851. fmt.Println("丰管业配置", data.SealingFluidDispose)
  852. assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  853. assessment.DialysisOrderId = data.DialysisOrderId
  854. assessment.Evaluator = adminUserInfo.AdminUser.Id
  855. assessment.Status = 1
  856. assessment.WeightAfter = data.WeightAfter
  857. assessment.WeightLoss = data.WeightLoss
  858. assessment.Temperature = data.Temperature
  859. assessment.SystolicBloodPressure = data.SystolicBloodPressure
  860. assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
  861. assessment.PulseFrequency = data.PulseFrequency
  862. assessment.ActualUltrafiltration = data.ActualUltrafiltration
  863. assessment.ActualDisplacement = data.ActualDisplacement
  864. assessment.ActualTreatmentHour = data.ActualTreatmentHour
  865. assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
  866. assessment.Cruor = data.Cruor
  867. assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
  868. assessment.DialysisIntakes = data.DialysisIntakes
  869. assessment.InternalFistula = data.InternalFistula
  870. assessment.BloodAccessPartId = data.BloodAccessPartId
  871. assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
  872. assessment.Catheter = data.Catheter
  873. assessment.Complication = data.Complication
  874. assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
  875. assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
  876. assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
  877. assessment.PatientGose = data.PatientGose
  878. assessment.InpatientDepartment = data.InpatientDepartment
  879. assessment.ObservationContent = data.ObservationContent
  880. assessment.ObservationContentOther = data.ObservationContentOther
  881. assessment.Remark = data.Remark
  882. assessment.BreathingRate = data.BreathingRate
  883. assessment.DialysisProcess = data.DialysisProcess
  884. assessment.InAdvanceMinute = data.InAdvanceMinute
  885. assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
  886. assessment.InAdvanceReason = data.InAdvanceReason
  887. assessment.HemostasisOpera = data.HemostasisOpera
  888. assessment.HemostasisMinute = data.HemostasisMinute
  889. assessment.TremorNoise = data.TremorNoise
  890. assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
  891. assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
  892. assessment.ArterialTube = data.ArterialTube
  893. assessment.IntravenousTube = data.IntravenousTube
  894. assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
  895. assessment.Dialyzer = data.Dialyzer
  896. assessment.IsEat = data.IsEat
  897. assessment.CvcA = data.CvcA
  898. assessment.CvcV = data.CvcV
  899. assessment.Channel = data.Channel
  900. assessment.ReturnBlood = data.ReturnBlood
  901. assessment.RehydrationVolume = data.RehydrationVolume
  902. assessment.DialysisDuring = data.DialysisDuring
  903. assessment.StrokeVolume = data.StrokeVolume
  904. assessment.BloodFlow = data.BloodFlow
  905. assessment.SealingFluidDispose = data.SealingFluidDispose
  906. assessment.SealingFluidSpecial = data.SealingFluidSpecial
  907. assessment.DosageOfAnticoagulants = data.DosageOfAnticoagulants
  908. assessment.SupineSystolicBloodPressure = data.SupineSystolicBloodPressure
  909. assessment.SettingPressure = data.SettingPressure
  910. assessment.SupineDiastolicBloodPressure = data.SupineDiastolicBloodPressure
  911. assessment.DiastolicPressure = data.DiastolicPressure
  912. assessment.AdditionalWeight = data.AdditionalWeight
  913. assessment.OtherComplication = data.OtherComplication
  914. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  915. if assessment.ID > 0 {
  916. if appRole.UserType == 2 || appRole.UserType == 1 {
  917. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  918. assessment.AssessmentTime = time.Now().Unix()
  919. } else {
  920. if assessment.Creater == 0 {
  921. assessment.Modifier = adminUserInfo.AdminUser.Id
  922. assessment.Creater = adminUserInfo.AdminUser.Id
  923. } else {
  924. assessment.Modifier = adminUserInfo.AdminUser.Id
  925. }
  926. }
  927. assessment.UpdatedTime = time.Now().Unix()
  928. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  929. } else {
  930. if appRole.UserType == 2 || appRole.UserType == 1 {
  931. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  932. assessment.AssessmentTime = time.Now().Unix()
  933. } else {
  934. assessment.Creater = adminUserInfo.AdminUser.Id
  935. }
  936. assessment.CreatedTime = time.Now().Unix()
  937. assessment.UpdatedTime = time.Now().Unix()
  938. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  939. assessment.PatientId = patient
  940. assessment.AssessmentDate = recordDate.Unix()
  941. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  942. }
  943. if err != nil {
  944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  945. return
  946. }
  947. c.ServeSuccessJSON(map[string]interface{}{
  948. "AssessmentAfterDislysis": &assessment,
  949. })
  950. }
  951. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  952. patient, _ := c.GetInt64("patient", 0)
  953. recordDateStr := c.GetString("record_date")
  954. if patient <= 0 {
  955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  956. return
  957. }
  958. adminUserInfo := c.GetAdminUserInfo()
  959. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  960. if patientInfo.ID == 0 {
  961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  962. return
  963. }
  964. if len(recordDateStr) == 0 {
  965. recordDateStr = time.Now().Format("2006-01-02")
  966. }
  967. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  968. if parseDateErr != nil {
  969. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  971. return
  972. }
  973. weight_before, _ := c.GetFloat("weight_before", 0)
  974. dry_weight, _ := c.GetFloat("dry_weight", 0)
  975. additional_weight, _ := c.GetFloat("additional_weight", 0)
  976. temperature, _ := c.GetFloat("temperature", 0)
  977. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  978. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  979. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  980. last_post_dialysis := c.GetString("last_post_dialysis")
  981. dialysis_interphase := c.GetString("dialysis_interphase")
  982. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  983. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  984. //bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  985. bloodAccessPartId := c.GetString("blood_access_part_id")
  986. internalFistula := c.GetString("internal_fistula")
  987. internal_fistula_skin := c.GetString("internal_fistula_skin")
  988. catheter := c.GetString("catheter")
  989. catheter_bend, _ := c.GetInt("catheter_bend")
  990. complication := c.GetString("complication")
  991. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  992. hemorrhage := c.GetString("hemorrhage")
  993. hemorrhage_other := c.GetString("hemorrhage_other")
  994. remark := c.GetString("remark")
  995. puncture_method := c.GetString("puncture_method")
  996. dialysis_count, _ := c.GetInt64("dialysis_count", 0)
  997. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  998. emergency_treatment_other := c.GetString("emergency_treatment_other")
  999. ductus_arantii := c.GetString("ductus_arantii")
  1000. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  1001. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  1002. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  1003. //puncture_way, _ := c.GetInt64("puncture_way", 0)
  1004. puncture_way := c.GetString("puncture_way")
  1005. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  1006. internal_fistula_other := c.GetString("internal_fistula_other")
  1007. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  1008. breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  1009. is_infect, _ := c.GetInt64("is_infect", 0)
  1010. exposed, _ := c.GetFloat("exposed", 0)
  1011. //skin, _ := c.GetInt64("skin", 0)
  1012. skin := c.GetString("skin")
  1013. skin_other := c.GetString("skin_other")
  1014. infect_other := c.GetString("infect_other")
  1015. ductus_arantii_other := c.GetString("ductus_arantii_other")
  1016. machine_type := c.GetString("machine_type")
  1017. puncture_needle := c.GetString("puncture_needle")
  1018. humor_excessive_symptom, _ := c.GetInt64("humor_excessive_symptom", 0)
  1019. phinholing := c.GetString("pinholing")
  1020. catheter_suture := c.GetString("catheter_suture")
  1021. catheter_suture_other := c.GetString("catheter_suture_other")
  1022. edema := c.GetString("edema")
  1023. urine_volume, _ := c.GetFloat("urine_volume", 0)
  1024. special_treatment := c.GetString("special_treatment")
  1025. catheter_maintenance := c.GetString("catheter_maintenance")
  1026. thrombusType := c.GetString("thromubus_type")
  1027. thrombusInt, _ := strconv.ParseInt(thrombusType, 10, 64)
  1028. thrombus_a := c.GetString("thromubus_a")
  1029. thrombus_av := c.GetString("thrombus_av")
  1030. thrombus_v := c.GetString("thromubus_v")
  1031. assessmentBeforeDislysis := models.PredialysisEvaluation{
  1032. DialysisCount: dialysis_count,
  1033. EmergencyTreatment: emergency_treatment,
  1034. EmergencyTreatmentOther: emergency_treatment_other,
  1035. DuctusArantii: ductus_arantii,
  1036. VenousCatheterization: venous_catheterization,
  1037. VenousCatheterizationPart: venous_catheterization_part,
  1038. VenousCatheterizationPartOther: venous_catheterization_part_other,
  1039. PunctureWay: puncture_way,
  1040. BloodAccessInternalFistula: blood_access_internal_fistula,
  1041. BloodAccessNoise: blood_access_noise,
  1042. InternalFistulaOther: internal_fistula_other,
  1043. Evaluator: adminUserInfo.AdminUser.Id,
  1044. UserOrgId: adminUserInfo.CurrentOrgId,
  1045. PatientId: patient,
  1046. AssessmentDate: recordDate.Unix(),
  1047. Temperature: temperature,
  1048. PulseFrequency: pulse_frequency,
  1049. SystolicBloodPressure: systolic_blood_pressure,
  1050. DiastolicBloodPressure: diastolic_blood_pressure,
  1051. WeightBefore: weight_before,
  1052. DryWeight: dry_weight,
  1053. AdditionalWeight: additional_weight,
  1054. DialysisInterphase: dialysis_interphase,
  1055. LastPostDialysis: last_post_dialysis,
  1056. SymptomBeforeDialysis: symptom_before_dialysis,
  1057. InternalFistula: internalFistula,
  1058. InternalFistulaSkin: internal_fistula_skin,
  1059. Catheter: catheter,
  1060. CatheterBend: catheter_bend,
  1061. Complication: complication,
  1062. CreatedTime: time.Now().Unix(),
  1063. Status: 1,
  1064. Remark: remark,
  1065. IsHemorrhage: is_hemorrhage,
  1066. Hemorrhage: hemorrhage,
  1067. HemorrhageOther: hemorrhage_other,
  1068. BloodAccessPartId: bloodAccessPartId,
  1069. BloodAccessPartOperaId: bloodAccessPartOperaId,
  1070. PunctureMethod: puncture_method,
  1071. BreathingRate: breathing_rate,
  1072. IsInfect: is_infect,
  1073. Exposed: exposed,
  1074. Skin: skin,
  1075. SkinOther: skin_other,
  1076. InfectOther: infect_other,
  1077. DuctusArantiiOther: ductus_arantii_other,
  1078. MachineType: machine_type,
  1079. PunctureNeedle: puncture_needle,
  1080. HumorExcessiveSymptom: humor_excessive_symptom,
  1081. Phinholing: phinholing,
  1082. CatheterSuture: catheter_suture,
  1083. CatheterSutureOther: catheter_suture_other,
  1084. Edema: edema,
  1085. UrineVolume: urine_volume,
  1086. SpecialTreatment: special_treatment,
  1087. CatheterMaintenance: catheter_maintenance,
  1088. ThromubusType: thrombusInt,
  1089. ThrombusAv: thrombus_av,
  1090. ThromubusA: thrombus_a,
  1091. ThromubusV: thrombus_v,
  1092. }
  1093. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1094. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1095. if evaluation.ID == 0 { //新增
  1096. if appRole.UserType == 2 || appRole.UserType == 1 {
  1097. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1098. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1099. } else {
  1100. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  1101. }
  1102. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  1103. if err == nil {
  1104. c.ServeSuccessJSON(map[string]interface{}{
  1105. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  1106. })
  1107. } else {
  1108. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1110. }
  1111. } else { //修改
  1112. //if appRole.UserType == 3 {
  1113. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  1114. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1115. // if getPermissionErr != nil {
  1116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1117. // return
  1118. // } else if headNursePermission == nil {
  1119. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1120. // return
  1121. // }
  1122. // }
  1123. //}
  1124. if appRole.UserType == 2 || appRole.UserType == 1 {
  1125. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1126. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1127. } else {
  1128. if evaluation.Creater == 0 {
  1129. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  1130. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  1131. } else {
  1132. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  1133. }
  1134. }
  1135. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  1136. assessmentBeforeDislysis.ID = evaluation.ID
  1137. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  1138. //
  1139. //新增逻辑
  1140. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  1141. var dewater_amount float64
  1142. dewater_amount = 0
  1143. if evaluation.DryWeight > 0 {
  1144. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  1145. if templateInfo.TemplateId == 17 && templateInfo.TemplateId == 22 && templateInfo.TemplateId == 21 {
  1146. dewater_amount = dewater_amount * 1000
  1147. }
  1148. if dewater_amount <= 0 {
  1149. dewater_amount = 0
  1150. }
  1151. } else {
  1152. dewater_amount = 0
  1153. }
  1154. // 计算透析处方的相关超滤量
  1155. schedual, _ := service.MobileGetSchedualDetail(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1156. var lastDialysisPrescribe *models.DialysisPrescription
  1157. var dialysisSolution *models.DialysisSolution
  1158. var dialysisPrescribe *models.DialysisPrescription
  1159. var mode_id int64
  1160. if schedual != nil {
  1161. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  1162. if dialysisPrescribe == nil {
  1163. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1164. }
  1165. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1166. // 获取透析模版
  1167. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1168. mode_id = schedual.ModeId
  1169. } else {
  1170. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  1171. // 获取透析模版
  1172. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1173. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  1174. if dialysisPrescribe == nil && dialysisSolution != nil {
  1175. mode_id = dialysisSolution.ModeId
  1176. }
  1177. if dialysisPrescribe == nil && dialysisSolution == nil {
  1178. mode_id = 0
  1179. }
  1180. }
  1181. // 插入透析处方
  1182. if dialysisPrescribe == nil && dialysisSolution != nil {
  1183. var newprescribe models.DialysisPrescription
  1184. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1185. newprescribe.PatientId = dialysisSolution.PatientId
  1186. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1187. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1188. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1189. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1190. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1191. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1192. newprescribe.ModeId = dialysisSolution.ModeId
  1193. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1194. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1195. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1196. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1197. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1198. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1199. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1200. newprescribe.Glucose = dialysisSolution.Glucose
  1201. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1202. newprescribe.Kalium = dialysisSolution.Kalium
  1203. newprescribe.Sodium = dialysisSolution.Sodium
  1204. newprescribe.Calcium = dialysisSolution.Calcium
  1205. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1206. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1207. newprescribe.Conductivity = dialysisSolution.Conductivity
  1208. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1209. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1210. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1211. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1212. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1213. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1214. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1215. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1216. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1217. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1218. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1219. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1220. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1221. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1222. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1223. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1224. newprescribe.CreatedTime = time.Now().Unix()
  1225. newprescribe.UpdatedTime = time.Now().Unix()
  1226. newprescribe.RecordDate = recordDate.Unix()
  1227. newprescribe.DewaterAmount = dewater_amount
  1228. newprescribe.TargetUltrafiltration = dewater_amount
  1229. newprescribe.Status = 1
  1230. err := service.AddSigleRecord(&newprescribe)
  1231. if err != nil {
  1232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1233. }
  1234. }
  1235. if dialysisPrescribe == nil && dialysisSolution == nil {
  1236. if lastDialysisPrescribe != nil {
  1237. var newprescribe models.DialysisPrescription
  1238. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  1239. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  1240. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  1241. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  1242. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  1243. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  1244. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  1245. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  1246. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  1247. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  1248. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  1249. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  1250. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  1251. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  1252. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  1253. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  1254. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  1255. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  1256. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  1257. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  1258. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  1259. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  1260. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  1261. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  1262. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  1263. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  1264. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  1265. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  1266. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  1267. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  1268. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  1269. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  1270. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  1271. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  1272. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  1273. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  1274. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  1275. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  1276. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  1277. newprescribe.CreatedTime = time.Now().Unix()
  1278. newprescribe.UpdatedTime = time.Now().Unix()
  1279. newprescribe.RecordDate = recordDate.Unix()
  1280. newprescribe.DewaterAmount = dewater_amount
  1281. newprescribe.TargetUltrafiltration = dewater_amount
  1282. newprescribe.Status = 1
  1283. err := service.AddSigleRecord(&newprescribe)
  1284. if err != nil {
  1285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1286. }
  1287. } else {
  1288. var newprescribe models.DialysisPrescription
  1289. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  1290. newprescribe.PatientId = patient
  1291. newprescribe.ModeId = mode_id
  1292. newprescribe.CreatedTime = time.Now().Unix()
  1293. newprescribe.UpdatedTime = time.Now().Unix()
  1294. newprescribe.RecordDate = recordDate.Unix()
  1295. newprescribe.DewaterAmount = dewater_amount
  1296. newprescribe.TargetUltrafiltration = dewater_amount
  1297. newprescribe.Status = 1
  1298. err := service.AddSigleRecord(&newprescribe)
  1299. if err != nil {
  1300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1301. }
  1302. }
  1303. }
  1304. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  1305. if err == nil {
  1306. c.ServeSuccessJSON(map[string]interface{}{
  1307. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  1308. })
  1309. } else {
  1310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1311. }
  1312. }
  1313. }
  1314. func (c *DialysisApiController) PostTreatmentSummary() {
  1315. patient, _ := c.GetInt64("patient", 0)
  1316. recordDateStr := c.GetString("record_date")
  1317. if patient <= 0 {
  1318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1319. return
  1320. }
  1321. adminUserInfo := c.GetAdminUserInfo()
  1322. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1323. if patientInfo.ID == 0 {
  1324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1325. return
  1326. }
  1327. if len(recordDateStr) == 0 {
  1328. recordDateStr = time.Now().Format("2006-01-02")
  1329. }
  1330. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1331. if parseDateErr != nil {
  1332. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1334. return
  1335. }
  1336. mission := c.GetString("mission")
  1337. dialysis_summary := c.GetString("dialysis_summary")
  1338. nursingRecord := c.GetString("nursing_record")
  1339. specialRecord := c.GetString("special_record")
  1340. sj_nurse := adminUserInfo.AdminUser.Id
  1341. zl_nurse := adminUserInfo.AdminUser.Id
  1342. hd_nurse := adminUserInfo.AdminUser.Id
  1343. xj_nurse := adminUserInfo.AdminUser.Id
  1344. zl_doctor := adminUserInfo.AdminUser.Id
  1345. treatmentSummary := models.TreatmentSummary{
  1346. UserOrgId: adminUserInfo.CurrentOrgId,
  1347. PatientId: patient,
  1348. AssessmentDate: recordDate.Unix(),
  1349. Mission: mission,
  1350. DialysisSummary: dialysis_summary,
  1351. SjNurse: sj_nurse,
  1352. ZlNurse: zl_nurse,
  1353. HdNurse: hd_nurse,
  1354. XjNurse: xj_nurse,
  1355. ZlDoctor: zl_doctor,
  1356. Status: 1,
  1357. CreatedTime: time.Now().Unix(),
  1358. NursingRecord: nursingRecord,
  1359. SpecialRecord: specialRecord,
  1360. }
  1361. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1362. if tempTreatmentSummary.ID == 0 { //新增
  1363. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  1364. err := service.AddSigleSummaryRecord(&treatmentSummary)
  1365. if err == nil {
  1366. c.ServeSuccessJSON(map[string]interface{}{
  1367. "summary": treatmentSummary,
  1368. })
  1369. } else {
  1370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1371. }
  1372. } else { //修改
  1373. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  1374. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1375. // if getPermissionErr != nil {
  1376. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1377. // return
  1378. // } else if headNursePermission == nil {
  1379. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1380. // return
  1381. // }
  1382. //}
  1383. treatmentSummary.Creater = tempTreatmentSummary.Creater
  1384. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  1385. treatmentSummary.UpdatedTime = time.Now().Unix()
  1386. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  1387. treatmentSummary.ID = tempTreatmentSummary.ID
  1388. err := service.UpdateSummeRecord(&treatmentSummary)
  1389. if err == nil {
  1390. c.ServeSuccessJSON(map[string]interface{}{
  1391. "summary": treatmentSummary,
  1392. })
  1393. } else {
  1394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1395. }
  1396. }
  1397. }
  1398. func (c *DialysisApiController) GetDeviceList() {
  1399. adminUserInfo := c.GetAdminUserInfo()
  1400. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  1401. c.ServeSuccessJSON(map[string]interface{}{
  1402. "device": device,
  1403. })
  1404. }
  1405. func (c *DialysisApiController) GetAllDeviceZone() {
  1406. adminUserInfo := c.GetAdminUserInfo()
  1407. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  1408. dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1409. if err == nil {
  1410. c.ServeSuccessJSON(map[string]interface{}{
  1411. "zone": zone,
  1412. "dics": dics,
  1413. })
  1414. }
  1415. }
  1416. func (c *DialysisApiController) GetDialysisWatch() {
  1417. page, _ := c.GetInt64("page", 1)
  1418. limit, _ := c.GetInt64("limit", 10)
  1419. schedulType, _ := c.GetInt64("schedul_type", 0)
  1420. startTime, _ := c.GetInt64("schedul_time", 0)
  1421. partitionType, _ := c.GetInt64("partition_type", 0)
  1422. keywords := c.GetString("keywords")
  1423. adminUserInfo := c.GetAdminUserInfo()
  1424. if len(keywords) > 0 {
  1425. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  1426. if err == nil {
  1427. c.ServeSuccessJSON(map[string]interface{}{
  1428. "schedule": dialysisSchedule,
  1429. "total": total,
  1430. })
  1431. } else {
  1432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1433. }
  1434. } else {
  1435. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  1436. if err == nil {
  1437. c.ServeSuccessJSON(map[string]interface{}{
  1438. "schedule": dialysisSchedule,
  1439. "total": total,
  1440. })
  1441. } else {
  1442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1443. }
  1444. }
  1445. }
  1446. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  1447. patientId, _ := c.GetInt64("id", 0)
  1448. record_date, _ := c.GetInt64("record_date", 0)
  1449. adminUserInfo := c.GetAdminUserInfo()
  1450. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1451. var dialysisStatus int64
  1452. if dialysisOrder == nil { //没有透析记录
  1453. dialysisStatus = 0 //未透析
  1454. } else {
  1455. dialysisStatus = dialysisOrder.Stage
  1456. }
  1457. //用户基本信息
  1458. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1459. //接诊评估
  1460. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1461. //透前评估
  1462. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1463. //临时医嘱
  1464. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1465. //双人核对
  1466. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1467. //透析监测
  1468. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  1469. //透后评估
  1470. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1471. //透析小结
  1472. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1473. //透析处方
  1474. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1475. if dialysisPrescription.ID == 0 {
  1476. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  1477. c.ServeSuccessJSON(map[string]interface{}{
  1478. "patientInfo": schedualPatientInfo,
  1479. "dialysisPrescription": solution,
  1480. "receiverTreatmentAccess": receiverTreatmentAccess,
  1481. "predialysisEvaluation": PredialysisEvaluation,
  1482. "doctorAdvice": DoctorAdvice,
  1483. "doubleCheck": DoubleCheck,
  1484. "assessmentAfterDislysis": AssessmentAfterDislysis,
  1485. "treatmentSummary": TreatmentSummary,
  1486. "monitorRecord": Record,
  1487. "dialysisStatus": dialysisStatus,
  1488. "dialysisOrder": dialysisOrder,
  1489. "isSolution": 1,
  1490. })
  1491. } else {
  1492. c.ServeSuccessJSON(map[string]interface{}{
  1493. "patientInfo": schedualPatientInfo,
  1494. "dialysisPrescription": dialysisPrescription,
  1495. "receiverTreatmentAccess": receiverTreatmentAccess,
  1496. "predialysisEvaluation": PredialysisEvaluation,
  1497. "doctorAdvice": DoctorAdvice,
  1498. "doubleCheck": DoubleCheck,
  1499. "assessmentAfterDislysis": AssessmentAfterDislysis,
  1500. "treatmentSummary": TreatmentSummary,
  1501. "monitorRecord": Record,
  1502. "dialysisStatus": dialysisStatus,
  1503. "dialysisOrder": dialysisOrder,
  1504. "isSolution": 2,
  1505. })
  1506. }
  1507. }
  1508. func (c *DialysisApiController) CreateDoctorAdvice() {
  1509. patient, _ := c.GetInt64("id", 0)
  1510. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  1511. record_date, _ := c.GetInt64("record_date", 0)
  1512. if patient <= 0 {
  1513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1514. return
  1515. }
  1516. adminUserInfo := c.GetAdminUserInfo()
  1517. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1518. if patientInfo.ID == 0 {
  1519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1520. return
  1521. }
  1522. var advice models.DoctorAdvice
  1523. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  1524. if code > 0 {
  1525. c.ServeFailJSONWithSGJErrorCode(code)
  1526. return
  1527. }
  1528. if advice.ParentId > 0 {
  1529. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  1530. if old.ID == 0 || old.PatientId != patient {
  1531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1532. return
  1533. }
  1534. if old.StopState == 1 || old.ExecutionState == 1 {
  1535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1536. return
  1537. }
  1538. if old.ParentId > 0 {
  1539. advice.ParentId = old.ParentId
  1540. }
  1541. advice.StartTime = old.StartTime
  1542. advice.AdviceDoctor = old.AdviceDoctor
  1543. advice.DeliveryWay = old.DeliveryWay
  1544. advice.ExecutionFrequency = old.ExecutionFrequency
  1545. }
  1546. advice.RecordDate = record_date
  1547. advice.DialysisOrderId = dialysis_id
  1548. advice.Status = 1
  1549. advice.CreatedTime = time.Now().Unix()
  1550. advice.UpdatedTime = time.Now().Unix()
  1551. advice.StopState = 2
  1552. advice.ExecutionState = 2
  1553. advice.AdviceType = 2
  1554. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1555. advice.PatientId = patient
  1556. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1557. err := service.CreateDoctorAdvice(&advice)
  1558. if err != nil {
  1559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1560. return
  1561. }
  1562. for _, subAdvice := range subAdivice {
  1563. subAdvice.ParentId = advice.ID
  1564. subAdvice.PatientId = patient
  1565. subAdvice.RecordDate = record_date
  1566. subAdvice.CreatedTime = time.Now().Unix()
  1567. subAdvice.UpdatedTime = time.Now().Unix()
  1568. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  1569. }
  1570. service.CreateSubDoctorAdvice(subAdivice)
  1571. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  1572. c.ServeSuccessJSON(map[string]interface{}{
  1573. "msg": "ok",
  1574. "advice": advice,
  1575. "subAdvice": subAdivices,
  1576. })
  1577. return
  1578. }
  1579. func (c *DialysisApiController) EditDoctorAdvice() {
  1580. patient, _ := c.GetInt64("patient", 0)
  1581. id, _ := c.GetInt64("id", 0)
  1582. parent_id, _ := c.GetInt64("parent_id", 0)
  1583. execution_time := c.GetString("execution_time")
  1584. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  1585. // checker, _ := c.GetInt64("checker", 0)
  1586. if id <= 0 || patient <= 0 {
  1587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1588. return
  1589. }
  1590. adminUserInfo := c.GetAdminUserInfo()
  1591. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1592. if advice.ID == 0 || advice.PatientId != patient {
  1593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1594. return
  1595. }
  1596. if len(execution_time) <= 0 {
  1597. utils.ErrorLog("execution_time")
  1598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1599. return
  1600. }
  1601. execution_staff := adminUserInfo.AdminUser.Id
  1602. checker := adminUserInfo.AdminUser.Id
  1603. timeLayout2 := "2006-01-02 15:04"
  1604. loc, _ := time.LoadLocation("Local")
  1605. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1606. if errs != nil {
  1607. utils.ErrorLog(errs.Error())
  1608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1609. return
  1610. }
  1611. advices := models.DoctorAdvice{
  1612. ExecutionStaff: execution_staff,
  1613. ExecutionTime: theTime.Unix(),
  1614. Checker: checker,
  1615. UpdatedTime: time.Now().Unix(),
  1616. }
  1617. var err error
  1618. if parent_id > 0 {
  1619. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  1620. } else {
  1621. err = service.ExceDoctorAdviceById(&advices, id, patient)
  1622. }
  1623. if err != nil {
  1624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1625. return
  1626. }
  1627. c.ServeSuccessJSON(map[string]interface{}{
  1628. "msg": "ok",
  1629. "advice": advice,
  1630. })
  1631. return
  1632. }
  1633. func (c *DialysisApiController) GetDoctorAdvice() {
  1634. patient, _ := c.GetInt64("patient_id", 0)
  1635. parent_id, _ := c.GetInt64("parent_id", 0)
  1636. adviceId, _ := c.GetInt64("id", 0)
  1637. if patient <= 0 {
  1638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1639. return
  1640. }
  1641. dminUserInfo := c.GetAdminUserInfo()
  1642. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  1643. if patientInfo.ID == 0 {
  1644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1645. return
  1646. }
  1647. var subAdvice []*models.DoctorAdvice
  1648. var advice models.DoctorAdvice
  1649. if parent_id > 0 {
  1650. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  1651. if advice.ID == 0 || advice.PatientId != patient {
  1652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1653. return
  1654. }
  1655. subAdvice = service.FindSubAdivceById(patient, parent_id)
  1656. } else {
  1657. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  1658. if advice.ID == 0 || advice.PatientId != patient {
  1659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1660. return
  1661. }
  1662. subAdvice = service.FindSubAdivceById(patient, adviceId)
  1663. }
  1664. c.ServeSuccessJSON(map[string]interface{}{
  1665. "msg": "ok",
  1666. "advice": advice,
  1667. "subAdvice": subAdvice,
  1668. })
  1669. }
  1670. func (this *DialysisApiController) DelMonitor() {
  1671. recordID, _ := this.GetInt64("record_id")
  1672. patientID, _ := this.GetInt64("patient_id")
  1673. if recordID <= 0 || patientID <= 0 {
  1674. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1675. return
  1676. }
  1677. adminInfo := this.GetAdminUserInfo()
  1678. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  1679. if getPatientErr != nil {
  1680. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  1681. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1682. return
  1683. } else if patient == nil {
  1684. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1685. return
  1686. }
  1687. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  1688. if getMonitorErr != nil {
  1689. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1690. return
  1691. }
  1692. //if monitor != nil {
  1693. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  1694. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1695. // if getPermissionErr != nil {
  1696. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1697. // return
  1698. // } else if headNursePermission == nil {
  1699. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1700. // return
  1701. // }
  1702. // }
  1703. //}
  1704. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  1705. if err != nil {
  1706. this.ErrorLog("删除透析监测记录失败:%v", err)
  1707. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1708. return
  1709. }
  1710. this.ServeSuccessJSON(map[string]interface{}{
  1711. "record_id": monitor.ID,
  1712. })
  1713. }
  1714. func (c *DialysisApiController) CreateMonitor() {
  1715. patient, _ := c.GetInt64("id", 0)
  1716. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  1717. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  1718. operate_time, _ := c.GetInt64("operate_time", 0)
  1719. // monitoring_time := c.GetString("monitoring_time")
  1720. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1721. breathing_rated, _ := c.GetFloat("breathing_rated", 0)
  1722. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1723. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1724. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  1725. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1726. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  1727. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  1728. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  1729. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  1730. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  1731. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  1732. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  1733. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  1734. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  1735. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1736. temperature, _ := c.GetFloat("temperature", 0)
  1737. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  1738. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  1739. conductivity, _ := c.GetFloat("conductivity", 0)
  1740. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  1741. heparin, _ := c.GetFloat("heparin", 0)
  1742. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1743. ktv, _ := c.GetFloat("ktv", 0)
  1744. symptom := c.GetString("symptom")
  1745. dispose := c.GetString("dispose")
  1746. result := c.GetString("results")
  1747. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  1748. monitoring_date = monitoring_date / 1000
  1749. // operate_time = operate_time / 1000
  1750. if patient <= 0 {
  1751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1752. return
  1753. }
  1754. adminUserInfo := c.GetAdminUserInfo()
  1755. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1756. if patientInfo.ID == 0 {
  1757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1758. return
  1759. }
  1760. monitorRecord := models.MonitoringRecord{
  1761. PatientId: patient,
  1762. MonitoringDate: monitoring_date,
  1763. DialysisOrderId: dialysis_order_id,
  1764. OperateTime: operate_time,
  1765. // MonitoringTime: monitoring_time,
  1766. PulseFrequency: pulse_frequency,
  1767. BreathingRate: breathing_rated,
  1768. SystolicBloodPressure: systolic_blood_pressure,
  1769. DiastolicBloodPressure: diastolic_blood_pressure,
  1770. BloodPressureType: blood_pressure_type,
  1771. BloodFlowVolume: blood_flow_volume,
  1772. VenousPressure: venous_pressure,
  1773. VenousPressureType: venous_pressure_type,
  1774. TransmembranePressure: transmembrane_pressure,
  1775. TransmembranePressureType: transmembrane_pressure_type,
  1776. UltrafiltrationRate: ultrafiltration_rate,
  1777. UltrafiltrationVolume: ultrafiltration_volume,
  1778. SodiumConcentration: sodium_concentration,
  1779. ArterialPressure: arterial_pressure,
  1780. ArterialPressureType: arterial_pressure_type,
  1781. DialysateTemperature: dialysate_temperature,
  1782. Temperature: temperature,
  1783. ReplacementRate: replacement_rate,
  1784. DisplacementQuantity: displacement_quantity,
  1785. Ktv: ktv,
  1786. Symptom: symptom,
  1787. Dispose: dispose,
  1788. Result: result,
  1789. MonitoringNurse: monitoring_nurse,
  1790. Status: 1,
  1791. CreatedTime: time.Now().Unix(),
  1792. UpdatedTime: time.Now().Unix(),
  1793. UserOrgId: adminUserInfo.CurrentOrgId,
  1794. Conductivity: conductivity,
  1795. DisplacementFlowQuantity: displacement_flow_quantity,
  1796. Heparin: heparin,
  1797. DialysateFlow: dialysate_flow,
  1798. }
  1799. err := service.CreateMonitor(&monitorRecord)
  1800. if err != nil {
  1801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  1802. return
  1803. }
  1804. c.ServeSuccessJSON(map[string]interface{}{
  1805. "msg": "ok",
  1806. "monitor": monitorRecord,
  1807. })
  1808. return
  1809. }
  1810. // 已弃用
  1811. // func (c *DialysisApiController) CreateRecordData() {
  1812. // patient, _ := c.GetInt64("id", 0)
  1813. // status, _ := c.GetInt64("status", 0)
  1814. // now := time.Now()
  1815. // year, month, day := now.Date()
  1816. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1817. // todayTimeStamp := today_time.Unix()
  1818. // if patient <= 0 {
  1819. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1820. // return
  1821. // }
  1822. // adminUserInfo := c.GetAdminUserInfo()
  1823. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1824. // if patientInfo.ID == 0 {
  1825. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1826. // return
  1827. // }
  1828. // record := &models.DialysisOrder{
  1829. // DialysisDate: todayTimeStamp,
  1830. // UserOrgId: adminUserInfo.CurrentOrgId,
  1831. // PatientId: patient,
  1832. // Stage: status,
  1833. // Status: 1,
  1834. // CreatedTime: time.Now().Unix(),
  1835. // UpdatedTime: time.Now().Unix(),
  1836. // }
  1837. // if status == 1 {
  1838. // //创建透析记录
  1839. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  1840. // if err == nil {
  1841. // c.ServeSuccessJSON(map[string]interface{}{
  1842. // "dialysisOrder": record,
  1843. // })
  1844. // } else {
  1845. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1846. // }
  1847. // } else {
  1848. // record_id, _ := c.GetInt64("record_id", 0)
  1849. // //修改透析记录状态
  1850. // errs := service.ModifyDialysisRecord(record_id)
  1851. // //结束时候透析次数加1
  1852. // service.UpdateSolutionByPatientId(patient)
  1853. // if errs == nil {
  1854. // c.ServeSuccessJSON(map[string]interface{}{
  1855. // "dialysisOrder": record,
  1856. // })
  1857. // } else {
  1858. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1859. // }
  1860. // }
  1861. // }
  1862. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  1863. dataBody := make(map[string]interface{}, 0)
  1864. err := json.Unmarshal(data, &dataBody)
  1865. if err != nil {
  1866. utils.ErrorLog(err.Error())
  1867. code = enums.ErrorCodeParamWrong
  1868. return
  1869. }
  1870. timeLayout := "2006-01-02 "
  1871. timeLayout2 := "2006-01-02 15:04"
  1872. loc, _ := time.LoadLocation("Local")
  1873. if action == "create" {
  1874. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1875. utils.ErrorLog("advice_type")
  1876. code = enums.ErrorCodeParamWrong
  1877. return
  1878. }
  1879. adviceType := int64(dataBody["advice_type"].(float64))
  1880. if adviceType != 1 && adviceType != 2 {
  1881. utils.ErrorLog("advice_type != 1&&2")
  1882. code = enums.ErrorCodeParamWrong
  1883. return
  1884. }
  1885. advice.AdviceType = adviceType
  1886. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1887. utils.ErrorLog("advice_date")
  1888. code = enums.ErrorCodeParamWrong
  1889. return
  1890. }
  1891. adviceDate, _ := dataBody["advice_date"].(string)
  1892. if len(adviceDate) == 0 {
  1893. utils.ErrorLog("len(adviceDate) == 0")
  1894. code = enums.ErrorCodeParamWrong
  1895. return
  1896. }
  1897. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1898. if err != nil {
  1899. utils.ErrorLog(err.Error())
  1900. code = enums.ErrorCodeParamWrong
  1901. return
  1902. }
  1903. advice.AdviceDate = theTime.Unix()
  1904. }
  1905. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1906. utils.ErrorLog("start_time")
  1907. code = enums.ErrorCodeParamWrong
  1908. return
  1909. }
  1910. startDate, _ := dataBody["start_time"].(string)
  1911. if len(startDate) == 0 {
  1912. utils.ErrorLog("len(startDate) == 0")
  1913. code = enums.ErrorCodeParamWrong
  1914. return
  1915. }
  1916. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  1917. if err != nil {
  1918. utils.ErrorLog(err.Error())
  1919. code = enums.ErrorCodeParamWrong
  1920. return
  1921. }
  1922. advice.StartTime = theTime.Unix()
  1923. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  1924. utils.ErrorLog("advice_name")
  1925. code = enums.ErrorCodeParamWrong
  1926. return
  1927. }
  1928. adviceName, _ := dataBody["advice_name"].(string)
  1929. if len(adviceName) == 0 {
  1930. utils.ErrorLog("len(advice_name) == 0")
  1931. code = enums.ErrorCodeParamWrong
  1932. return
  1933. }
  1934. advice.AdviceName = adviceName
  1935. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  1936. utils.ErrorLog("delivery_way")
  1937. code = enums.ErrorCodeParamWrong
  1938. return
  1939. }
  1940. deliveryWay, _ := dataBody["delivery_way"].(string)
  1941. if len(deliveryWay) == 0 {
  1942. utils.ErrorLog("len(deliveryWay) == 0")
  1943. code = enums.ErrorCodeParamWrong
  1944. return
  1945. }
  1946. advice.DeliveryWay = deliveryWay
  1947. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  1948. utils.ErrorLog("execution_frequency")
  1949. code = enums.ErrorCodeParamWrong
  1950. return
  1951. }
  1952. execution_frequency, _ := dataBody["execution_frequency"].(string)
  1953. if len(execution_frequency) == 0 {
  1954. utils.ErrorLog("len(execution_frequency) == 0")
  1955. code = enums.ErrorCodeParamWrong
  1956. return
  1957. }
  1958. advice.ExecutionFrequency = execution_frequency
  1959. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  1960. adviceDsc, _ := dataBody["advice_desc"].(string)
  1961. advice.AdviceDesc = adviceDsc
  1962. }
  1963. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  1964. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  1965. advice.DrugSpecUnit = drugSpecUnit
  1966. }
  1967. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  1968. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  1969. advice.SingleDose = singleDose
  1970. }
  1971. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  1972. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  1973. advice.SingleDoseUnit = singleDoseUnit
  1974. }
  1975. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  1976. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  1977. advice.PrescribingNumber = prescribingNumber
  1978. }
  1979. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  1980. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  1981. advice.PrescribingNumberUnit = prescribingNumberUnit
  1982. }
  1983. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  1984. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  1985. if len(thisContagions) > 0 {
  1986. for _, item := range thisContagions {
  1987. items := item.(map[string]interface{})
  1988. advice_name, _ := items["advice_name"].(string)
  1989. advice_desc, _ := items["advice_desc"].(string)
  1990. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  1991. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  1992. single_dose_unit, _ := items["single_dose_unit"].(string)
  1993. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  1994. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  1995. advice := &models.DoctorAdvice{
  1996. AdviceName: advice_name,
  1997. AdviceDesc: advice_desc,
  1998. SingleDose: single_dose,
  1999. SingleDoseUnit: single_dose_unit,
  2000. DrugSpecUnit: drug_spec_unit,
  2001. PrescribingNumber: prescribing_number,
  2002. PrescribingNumberUnit: prescribing_number_unit,
  2003. }
  2004. subAdvice = append(subAdvice, advice)
  2005. }
  2006. }
  2007. }
  2008. return
  2009. }
  2010. func (c *DialysisApiController) GetDialysisOrder() {
  2011. xtno := c.GetString("xtno")
  2012. xtdate := c.GetString("xtdate")
  2013. timeLayout := "2006-01-02"
  2014. loc, _ := time.LoadLocation("Local")
  2015. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  2016. if err != nil {
  2017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2018. return
  2019. }
  2020. xttime := theTime.Unix()
  2021. operatorIDs := make([]int64, 0)
  2022. adminUserInfo := c.GetAdminUserInfo()
  2023. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  2024. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.CurrentOrgId, xtno, xttime)
  2025. //透析单
  2026. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2027. if dialysisOrder != nil {
  2028. if dialysisOrder.FinishNurse > 0 {
  2029. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  2030. }
  2031. if dialysisOrder.StartNurse > 0 {
  2032. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  2033. }
  2034. }
  2035. //透前评估
  2036. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2037. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  2038. //透后评估
  2039. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2040. if AssessmentAfterDislysis.Modifier > 0 {
  2041. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  2042. }
  2043. //上次透前评估
  2044. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2045. lastOrder, _ := service.GetLastTimeOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2046. //透析处方
  2047. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2048. if dialysisPrescription.PrescriptionDoctor > 0 {
  2049. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  2050. }
  2051. //获取病人的透析模式
  2052. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2053. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2054. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2055. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2056. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2057. //获取透析处方
  2058. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2059. //获取临时医嘱
  2060. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2061. config, err := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  2062. //获取医嘱内容
  2063. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2064. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2065. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2066. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2067. //获取上次的透后体重
  2068. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2069. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2070. //获取透析次数
  2071. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  2072. if len(DoctorAdvice) > 0 {
  2073. for _, item := range DoctorAdvice {
  2074. if item.AdviceDoctor > 0 {
  2075. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2076. }
  2077. if item.ExecutionStaff > 0 {
  2078. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2079. }
  2080. if item.Checker > 0 {
  2081. operatorIDs = append(operatorIDs, item.Checker)
  2082. }
  2083. }
  2084. }
  2085. //透析监测
  2086. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2087. //透析检测
  2088. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2089. //透析小结
  2090. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2091. //接诊评估
  2092. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2093. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2094. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2095. patientInfo.TotalDialysis = dialysis_count
  2096. //相关操作对应的操作人
  2097. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  2098. operators, err := service.GetAdminUserEsOne(adminUserInfo.CurrentOrgId)
  2099. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  2100. //获取当前日期月份的第一天
  2101. firstmonth := service.GetFirstDateOfMonth(theTime)
  2102. firstMonthDate := firstmonth.Unix()
  2103. //获取当前月份的病人透析次数
  2104. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  2105. //获取his数据
  2106. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2107. if config.IsOpen == 1 {
  2108. c.ServeSuccessJSON(map[string]interface{}{
  2109. "xtdate": xtdate,
  2110. "users": adminUser,
  2111. "patientInfo": patientInfo,
  2112. "PredialysisEvaluation": PredialysisEvaluation,
  2113. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2114. "dialysisPrescription": dialysisPrescription,
  2115. "advices": hisAdvice,
  2116. "monitors": Record,
  2117. "summary": TreatmentSummary,
  2118. "receiverTreatmentAccess": receiverTreatmentAccess,
  2119. "dialysisOrder": dialysisOrder,
  2120. "operators": operators,
  2121. "org_template_info": templateInfo,
  2122. "check": check,
  2123. "schedule": schedule,
  2124. "dialysisway": dialysisway,
  2125. "order": order,
  2126. "doctorAdvice": doctorAdvice,
  2127. "doctor": doctor,
  2128. "nurse": nurse,
  2129. "doctorAdevieInfo": doctorAdevieInfo,
  2130. "total": total,
  2131. "startNuse": startNuse,
  2132. "DoctorName": DoctorName,
  2133. "assessmentAfterDislysis": assessmentAfterDislysis,
  2134. "predialysName": predialysName,
  2135. "FinishNuse": FinishNuse,
  2136. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  2137. "dialysiscount": dialysiscount,
  2138. "last_order": lastOrder,
  2139. })
  2140. }
  2141. if config.IsOpen == 0 || config.IsOpen == 2 {
  2142. c.ServeSuccessJSON(map[string]interface{}{
  2143. "xtdate": xtdate,
  2144. "users": adminUser,
  2145. "patientInfo": patientInfo,
  2146. "PredialysisEvaluation": PredialysisEvaluation,
  2147. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2148. "dialysisPrescription": dialysisPrescription,
  2149. "advices": DoctorAdvice,
  2150. "monitors": Record,
  2151. "summary": TreatmentSummary,
  2152. "receiverTreatmentAccess": receiverTreatmentAccess,
  2153. "dialysisOrder": dialysisOrder,
  2154. "operators": operators,
  2155. "org_template_info": templateInfo,
  2156. "check": check,
  2157. "schedule": schedule,
  2158. "dialysisway": dialysisway,
  2159. "order": order,
  2160. "doctorAdvice": doctorAdvice,
  2161. "doctor": doctor,
  2162. "nurse": nurse,
  2163. "doctorAdevieInfo": doctorAdevieInfo,
  2164. "total": total,
  2165. "startNuse": startNuse,
  2166. "DoctorName": DoctorName,
  2167. "assessmentAfterDislysis": assessmentAfterDislysis,
  2168. "predialysName": predialysName,
  2169. "FinishNuse": FinishNuse,
  2170. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  2171. "dialysiscount": dialysiscount,
  2172. "last_order": lastOrder,
  2173. })
  2174. }
  2175. }
  2176. //
  2177. func (c *DialysisApiController) GetLongAdvice() {
  2178. patient_id, _ := c.GetInt64("patient_id")
  2179. adminUserInfo := c.GetAdminUserInfo()
  2180. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2181. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  2182. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  2183. c.ServeSuccessJSON(map[string]interface{}{
  2184. "status": "1",
  2185. })
  2186. return
  2187. } else { //开启推送提醒
  2188. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  2189. var advice_three []*models.DoctorAdvice
  2190. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  2191. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id)
  2192. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id)
  2193. for _, advice := range advices {
  2194. if advice.FrequencyType == 3 {
  2195. t := time.Now()
  2196. week := int(t.Weekday())
  2197. switch week {
  2198. case 1:
  2199. if strings.Index(advice.WeekDay, "周一") == -1 {
  2200. advice_three = append(advice_three, advice)
  2201. }
  2202. break
  2203. case 2:
  2204. if strings.Index(advice.WeekDay, "周二") == -1 {
  2205. advice_three = append(advice_three, advice)
  2206. }
  2207. break
  2208. case 3:
  2209. if strings.Index(advice.WeekDay, "周三") == -1 {
  2210. advice_three = append(advice_three, advice)
  2211. }
  2212. break
  2213. case 4:
  2214. if strings.Index(advice.WeekDay, "周四") == -1 {
  2215. advice_three = append(advice_three, advice)
  2216. }
  2217. break
  2218. case 5:
  2219. if strings.Index(advice.WeekDay, "周五") == -1 {
  2220. advice_three = append(advice_three, advice)
  2221. }
  2222. break
  2223. case 6:
  2224. if strings.Index(advice.WeekDay, "周六") == -1 {
  2225. advice_three = append(advice_three, advice)
  2226. }
  2227. break
  2228. case 0:
  2229. if strings.Index(advice.WeekDay, "周日") == -1 {
  2230. advice_three = append(advice_three, advice)
  2231. }
  2232. break
  2233. }
  2234. }
  2235. }
  2236. for _, advice := range advices_two {
  2237. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  2238. now := p.Unix()
  2239. dayStr := strconv.FormatInt(advice.DayCount, 10)
  2240. dayStr2 := "-" + dayStr
  2241. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  2242. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  2243. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  2244. for _, ad := range advices {
  2245. advice_three = append(advice_three, ad)
  2246. }
  2247. }
  2248. if err == nil {
  2249. c.ServeSuccessJSON(map[string]interface{}{
  2250. "status": "2",
  2251. "advices": advices,
  2252. "advices_two": RemoveRepeatedElement(advice_three),
  2253. "is_open_remind": config.IsOpenRemind,
  2254. })
  2255. }
  2256. }
  2257. }
  2258. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  2259. newArr = make([]*models.DoctorAdvice, 0)
  2260. for i := 0; i < len(arr); i++ {
  2261. repeat := false
  2262. for j := i + 1; j < len(arr); j++ {
  2263. if arr[i].ID == arr[j].ID {
  2264. repeat = true
  2265. break
  2266. }
  2267. }
  2268. if !repeat {
  2269. newArr = append(newArr, arr[i])
  2270. }
  2271. }
  2272. return
  2273. }
  2274. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  2275. patient, _ := c.GetInt64("id", 0)
  2276. groupNo, _ := c.GetInt64("groupno", 0)
  2277. if patient <= 0 {
  2278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2279. return
  2280. }
  2281. adminUserInfo := c.GetAdminUserInfo()
  2282. dataBody := make(map[string]interface{}, 0)
  2283. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2284. if err != nil {
  2285. utils.ErrorLog(err.Error())
  2286. return
  2287. }
  2288. utils.ErrorLog("%v", dataBody)
  2289. timeLayout := "2006-01-02 15:04"
  2290. loc, _ := time.LoadLocation("Local")
  2291. timeLayout2 := "2006-01-02"
  2292. loc2, _ := time.LoadLocation("Local")
  2293. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2294. utils.ErrorLog("advice_type")
  2295. return
  2296. }
  2297. adviceType := int64(2)
  2298. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2299. utils.ErrorLog("advice_date")
  2300. return
  2301. }
  2302. adviceDate, _ := dataBody["advice_date"].(string)
  2303. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  2304. fmt.Println("the-----------------", theTime)
  2305. AdviceDate := theTime.Unix()
  2306. RecordDate := theTime.Unix()
  2307. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2308. utils.ErrorLog("start_time")
  2309. return
  2310. }
  2311. startTime, _ := dataBody["start_time"].(string)
  2312. if len(startTime) == 0 {
  2313. utils.ErrorLog("len(start_time) == 0")
  2314. return
  2315. }
  2316. theTimeUnix, err := time.ParseInLocation(timeLayout, startTime, loc)
  2317. if err != nil {
  2318. utils.ErrorLog(err.Error())
  2319. return
  2320. }
  2321. StartTime := theTimeUnix.Unix()
  2322. fmt.Println("startTIME", StartTime)
  2323. Remark := ""
  2324. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2325. remark, _ := dataBody["remark"].(string)
  2326. Remark = remark
  2327. }
  2328. var advices []*models.GroupAdvice
  2329. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  2330. utils.ErrorLog("advices")
  2331. return
  2332. }
  2333. adviceNames := dataBody["advices"].([]interface{})
  2334. for _, adviceNameMap := range adviceNames {
  2335. adviceNameM := adviceNameMap.(map[string]interface{})
  2336. var advice models.GroupAdvice
  2337. advice.Remark = Remark
  2338. advice.AdviceType = adviceType
  2339. advice.StartTime = StartTime
  2340. advice.AdviceDate = AdviceDate
  2341. advice.RecordDate = RecordDate
  2342. advice.Status = 1
  2343. advice.CreatedTime = time.Now().Unix()
  2344. advice.UpdatedTime = time.Now().Unix()
  2345. advice.StopState = 2
  2346. advice.ExecutionState = 2
  2347. advice.UserOrgId = adminUserInfo.CurrentOrgId
  2348. advice.PatientId = patient
  2349. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2350. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  2351. utils.ErrorLog("advice_name")
  2352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2353. return
  2354. }
  2355. adviceName, _ := adviceNameM["advice_name"].(string)
  2356. if len(adviceName) == 0 {
  2357. utils.ErrorLog("len(advice_name) == 0")
  2358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2359. return
  2360. }
  2361. advice.AdviceName = adviceName
  2362. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  2363. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  2364. advice.DrugSpec = drugSpec
  2365. }
  2366. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  2367. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  2368. advice.AdviceDesc = adviceDesc
  2369. }
  2370. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  2371. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  2372. advice.DrugSpecUnit = drugSpecUnit
  2373. }
  2374. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  2375. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  2376. // advice.SingleDose = singleDose
  2377. //}
  2378. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  2379. //single_dose := int64(adviceNameM["single_dose"].(float64))
  2380. advice.SingleDose = adviceNameM["single_dose"].(float64)
  2381. }
  2382. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  2383. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  2384. advice.SingleDoseUnit = singleDoseUnit
  2385. }
  2386. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  2387. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  2388. // advice.PrescribingNumber = prescribingNumber
  2389. //}
  2390. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  2391. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  2392. }
  2393. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  2394. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  2395. advice.PrescribingNumberUnit = prescribingNumberUnit
  2396. }
  2397. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  2398. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  2399. advice.DeliveryWay = deliveryWay
  2400. }
  2401. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  2402. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2403. advice.ExecutionFrequency = executionFrequency
  2404. }
  2405. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  2406. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  2407. advice.FrequencyType = frequency_type
  2408. }
  2409. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  2410. day_count := int64(adviceNameM["day_count"].(float64))
  2411. advice.DayCount = day_count
  2412. }
  2413. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  2414. way := int64(adviceNameM["way"].(float64))
  2415. advice.Way = way
  2416. }
  2417. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  2418. drug_id := int64(adviceNameM["drug_id"].(float64))
  2419. advice.DrugId = drug_id
  2420. }
  2421. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  2422. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  2423. advice.DrugNameId = drug_name_id
  2424. }
  2425. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  2426. week_day, _ := adviceNameM["week_day"].(string)
  2427. advice.WeekDay = week_day
  2428. }
  2429. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  2430. template_id, _ := adviceNameM["template_id"].(string)
  2431. advice.TemplateId = template_id
  2432. }
  2433. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  2434. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2435. advice.ExecutionFrequency = executionFrequency
  2436. }
  2437. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  2438. children := adviceNameM["child"].([]interface{})
  2439. if len(children) > 0 {
  2440. for _, childrenMap := range children {
  2441. childMap := childrenMap.(map[string]interface{})
  2442. var child models.GroupAdvice
  2443. child.Remark = Remark
  2444. child.AdviceType = adviceType
  2445. child.StartTime = StartTime
  2446. child.AdviceDate = AdviceDate
  2447. child.RecordDate = RecordDate
  2448. child.Status = 1
  2449. child.CreatedTime = time.Now().Unix()
  2450. child.UpdatedTime = time.Now().Unix()
  2451. child.StopState = 2
  2452. child.ExecutionState = 2
  2453. child.UserOrgId = adminUserInfo.CurrentOrgId
  2454. child.PatientId = patient
  2455. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  2456. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  2457. utils.ErrorLog("child advice_name")
  2458. return
  2459. }
  2460. childAdviceName, _ := childMap["advice_name"].(string)
  2461. if len(childAdviceName) == 0 {
  2462. utils.ErrorLog("len(child advice_name) == 0")
  2463. return
  2464. }
  2465. child.AdviceName = childAdviceName
  2466. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  2467. childAdviceDesc, _ := childMap["advice_desc"].(string)
  2468. child.AdviceDesc = childAdviceDesc
  2469. }
  2470. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  2471. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  2472. child.DrugSpec = childDrugSpec
  2473. }
  2474. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  2475. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  2476. child.DrugSpecUnit = childDrugSpecUnit
  2477. }
  2478. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  2479. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  2480. child.SingleDose = childSingleDose
  2481. }
  2482. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  2483. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  2484. child.SingleDoseUnit = childSingleDoseUnit
  2485. }
  2486. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  2487. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  2488. child.PrescribingNumber = childPrescribingNumber
  2489. }
  2490. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  2491. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  2492. child.PrescribingNumberUnit = childPrescribingNumberUnit
  2493. }
  2494. child.DeliveryWay = advice.DeliveryWay
  2495. child.ExecutionFrequency = advice.ExecutionFrequency
  2496. advice.Children = append(advice.Children, &child)
  2497. }
  2498. }
  2499. }
  2500. advices = append(advices, &advice)
  2501. }
  2502. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  2503. if err != nil {
  2504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2505. return
  2506. }
  2507. c.ServeSuccessJSON(map[string]interface{}{
  2508. "msg": "ok",
  2509. "advices": list,
  2510. })
  2511. return
  2512. }
  2513. func (c *DialysisApiController) GetSolution() {
  2514. patient_id, _ := c.GetInt64("patient_id")
  2515. mode_id, _ := c.GetInt64("mode_id")
  2516. adminUserInfo := c.GetAdminUserInfo()
  2517. solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  2518. prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  2519. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, mode_id)
  2520. if err != nil {
  2521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2522. return
  2523. }
  2524. c.ServeSuccessJSON(map[string]interface{}{
  2525. "solution": solution,
  2526. "prescription": prescription,
  2527. "system_prescription": system_prescription,
  2528. })
  2529. }
  2530. func (c *DialysisApiController) GetSchedule() {
  2531. schedual_type, _ := c.GetInt64("schedual_type")
  2532. adminUserInfo := c.GetAdminUserInfo()
  2533. timeLayout := "2006-01-02 15:04:05"
  2534. date := time.Now().Format("2006-01-02") + " 00:00:00"
  2535. loc, _ := time.LoadLocation("Local")
  2536. theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  2537. scheduleTime := theStartTime.Unix()
  2538. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  2539. c.ServeSuccessJSON(map[string]interface{}{
  2540. "number": deviceNumber,
  2541. })
  2542. }
  2543. func (this *DialysisApiController) GetTodayMonitor() {
  2544. thisTime := time.Now()
  2545. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  2546. timeLayout := "2006-01-02 15:04:05"
  2547. loc, _ := time.LoadLocation("Local")
  2548. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2549. theAssessmentDateTime := theStartTime.Unix()
  2550. patientID, _ := this.GetInt64("patient_id")
  2551. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  2552. adminInfo := this.GetAdminUserInfo()
  2553. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  2554. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  2555. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  2556. var ultrafiltration_rate float64
  2557. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  2558. if prescription.ID > 0 {
  2559. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2560. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2561. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  2562. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2563. record.UltrafiltrationRate = ultrafiltration_rate
  2564. }
  2565. if template.TemplateId == 20 || template.TemplateId == 22 { //adminInfo.CurrentOrgId == 9538
  2566. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2567. record.UltrafiltrationRate = ultrafiltration_rate
  2568. }
  2569. // 只针对方济医院
  2570. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  2571. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2572. ultrafiltration_rate = value
  2573. record.UltrafiltrationRate = ultrafiltration_rate
  2574. }
  2575. }
  2576. }
  2577. // record.UltrafiltrationRate = ultrafiltration_rate
  2578. record.UltrafiltrationVolume = 0
  2579. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  2580. if ultrafiltration_rate > 0 {
  2581. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  2582. record.UltrafiltrationVolume = value
  2583. }
  2584. }
  2585. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 {
  2586. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  2587. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  2588. record.UltrafiltrationVolume = ultrafiltration_volume
  2589. }
  2590. }
  2591. this.ServeSuccessJSON(map[string]interface{}{
  2592. "monitor": record,
  2593. })
  2594. }
  2595. func (c *DialysisApiController) UploadDryWeight() {
  2596. patient_id, _ := c.GetInt64("id")
  2597. dry_weight, _ := c.GetFloat("dry_weight")
  2598. doctor_id, _ := c.GetInt64("doctor_id")
  2599. remark := c.GetString("remark")
  2600. adminUserInfo := c.GetAdminUserInfo()
  2601. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  2602. fmt.Println(err)
  2603. if err == gorm.ErrRecordNotFound {
  2604. dryWeight := &models.SgjPatientDryweight{
  2605. PatientId: patient_id,
  2606. DryWeight: dry_weight,
  2607. Remakes: remark,
  2608. Ctime: time.Now().Unix(),
  2609. Mtime: time.Now().Unix(),
  2610. Creator: doctor_id,
  2611. Status: 1,
  2612. UserOrgId: adminUserInfo.CurrentOrgId,
  2613. AdjustedValue: "/",
  2614. UserId: adminUserInfo.AdminUser.Id,
  2615. }
  2616. createErr := service.CreatePatientWeightAdjust(dryWeight)
  2617. if createErr == nil {
  2618. c.ServeSuccessJSON(map[string]interface{}{
  2619. "msg": "提交成功",
  2620. "weight": dryWeight,
  2621. })
  2622. }
  2623. } else {
  2624. dryWeight := &models.SgjPatientDryweight{
  2625. PatientId: patient_id,
  2626. DryWeight: dry_weight,
  2627. Remakes: remark,
  2628. Ctime: time.Now().Unix(),
  2629. Mtime: time.Now().Unix(),
  2630. Creator: doctor_id,
  2631. Status: 1,
  2632. UserOrgId: adminUserInfo.CurrentOrgId,
  2633. AdjustedValue: "/",
  2634. UserId: adminUserInfo.AdminUser.Id,
  2635. }
  2636. var value float64
  2637. value = dry_weight - weightAdjust.DryWeight
  2638. fmt.Println(value)
  2639. if value < 0 {
  2640. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  2641. } else if value == 0 {
  2642. dryWeight.AdjustedValue = "/"
  2643. } else if value > 0 {
  2644. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  2645. }
  2646. fmt.Println(value)
  2647. createErr := service.CreatePatientWeightAdjust(dryWeight)
  2648. if createErr == nil {
  2649. c.ServeSuccessJSON(map[string]interface{}{
  2650. "msg": "提交成功",
  2651. "weight": dryWeight,
  2652. })
  2653. }
  2654. }
  2655. }
  2656. func (this *DialysisApiController) GetFuncPurview() {
  2657. adminUserInfo := this.GetAdminUserInfo()
  2658. user_id := adminUserInfo.AdminUser.Id
  2659. app_id := adminUserInfo.CurrentAppId
  2660. org_id := adminUserInfo.CurrentOrgId
  2661. create_url := this.GetString("create_url")
  2662. modify_url := this.GetString("modify_url")
  2663. modify_other_url := this.GetString("modify_other_url")
  2664. del_url := this.GetString("del_url")
  2665. del_other_url := this.GetString("del_other_url")
  2666. exce_url := this.GetString("exce_url")
  2667. check_url := this.GetString("check_url")
  2668. modify_exce_url := this.GetString("modify_exce_url")
  2669. module, _ := this.GetInt64("module", 0)
  2670. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  2671. var is_has_create bool
  2672. var is_has_modify bool
  2673. var is_has_modify_other bool
  2674. var is_has_del bool
  2675. var is_has_del_other bool
  2676. var is_has_exce bool
  2677. var is_has_check bool
  2678. var is_has_modify_exce bool
  2679. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  2680. if adminUserInfo.AdminUser.Id != org.Creator {
  2681. if app_role != nil {
  2682. if len(app_role.RoleIds) > 0 {
  2683. roles := strings.Split(app_role.RoleIds, ",")
  2684. var userRolePurviews string
  2685. for _, item := range roles {
  2686. role_id, _ := strconv.ParseInt(item, 10, 64)
  2687. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  2688. if len(userRolePurviews) == 0 {
  2689. userRolePurviews = purviews
  2690. } else {
  2691. userRolePurviews = userRolePurviews + "," + purviews
  2692. }
  2693. }
  2694. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  2695. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  2696. for _, item := range funcPurviews {
  2697. //for _, url := range strings.Split(item.Urlfor,","){
  2698. if strings.Split(item.Urlfor, ",")[1] == create_url {
  2699. is_has_create = true
  2700. }
  2701. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  2702. is_has_modify = true
  2703. }
  2704. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  2705. is_has_modify_other = true
  2706. }
  2707. if strings.Split(item.Urlfor, ",")[1] == del_url {
  2708. is_has_del = true
  2709. }
  2710. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  2711. is_has_del_other = true
  2712. }
  2713. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  2714. is_has_exce = true
  2715. }
  2716. if strings.Split(item.Urlfor, ",")[1] == check_url {
  2717. is_has_check = true
  2718. }
  2719. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  2720. is_has_modify_exce = true
  2721. }
  2722. }
  2723. } else {
  2724. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  2725. return
  2726. }
  2727. this.ServeSuccessJSON(map[string]interface{}{
  2728. "is_has_create": is_has_create,
  2729. "is_has_modify": is_has_modify,
  2730. "is_has_modify_other": is_has_modify_other,
  2731. "is_has_del": is_has_del,
  2732. "is_has_del_other": is_has_del_other,
  2733. "is_has_exce": is_has_exce,
  2734. "is_has_check": is_has_check,
  2735. "is_has_modify_exce": is_has_modify_exce,
  2736. "module": module,
  2737. })
  2738. } else {
  2739. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  2740. return
  2741. }
  2742. } else {
  2743. this.ServeSuccessJSON(map[string]interface{}{
  2744. "is_has_create": true,
  2745. "is_has_modify": true,
  2746. "is_has_modify_other": true,
  2747. "is_has_del": true,
  2748. "is_has_del_other": true,
  2749. "is_has_exce": true,
  2750. "is_has_check": true,
  2751. "is_has_modify_exce": true,
  2752. "module": true,
  2753. })
  2754. }
  2755. }
  2756. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  2757. change_type, _ := this.GetInt64("type", 0)
  2758. record_date := this.GetString("record_time")
  2759. patient_id, _ := this.GetInt64("patient_id", 0)
  2760. timeLayout := "2006-01-02"
  2761. loc, _ := time.LoadLocation("Local")
  2762. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2763. record_time := theAdviceRecordTime.Unix()
  2764. adminUserInfo := this.GetAdminUserInfo()
  2765. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  2766. if err == nil {
  2767. if len(advices) == 0 {
  2768. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  2769. return
  2770. } else {
  2771. this.ServeSuccessJSON(map[string]interface{}{
  2772. "advices": advices,
  2773. "schedule": sch,
  2774. })
  2775. return
  2776. }
  2777. } else {
  2778. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2779. return
  2780. }
  2781. }
  2782. func (c *DialysisApiController) GetDialysisGoods() {
  2783. schedualDate := c.GetString("schedule_date")
  2784. schedule_type, _ := c.GetInt64("schedule_type")
  2785. partition_id, _ := c.GetInt64("partition_id")
  2786. page, _ := c.GetInt("page")
  2787. limit, _ := c.GetInt("limit")
  2788. keywords := c.GetString("keywords")
  2789. patient_id, _ := c.GetInt64("patient_id")
  2790. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  2791. if parseDateErr != nil && len(schedualDate) != 0 {
  2792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2793. return
  2794. }
  2795. schedualEndDate := int64(0)
  2796. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  2797. if parseDateErr != nil && len(schedualDate) != 0 {
  2798. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2799. return
  2800. }
  2801. schedualEndDate = endDate.Unix()
  2802. adminUser := c.GetAdminUserInfo()
  2803. _, err := service.FindStockOutByIsSys(adminUser.CurrentOrgId, 1, date.Unix())
  2804. goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
  2805. if err == gorm.ErrRecordNotFound {
  2806. dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate)
  2807. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  2808. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  2809. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  2810. item.LastAutomaticReduceDetail = goodUser
  2811. item.LastDialysisBeforePrepare = lastGoodUserDetial
  2812. }
  2813. c.ServeSuccessJSON(map[string]interface{}{
  2814. "dialysis_goods": dialysisGoods,
  2815. "good_type": goodTypes,
  2816. "total": total,
  2817. })
  2818. return
  2819. } else if err == nil {
  2820. //获取当天排班的每个患者的库存使用情况
  2821. dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate)
  2822. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  2823. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  2824. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  2825. fmt.Println(goodUser)
  2826. fmt.Println(lastGoodUserDetial)
  2827. item.LastAutomaticReduceDetail = goodUser
  2828. item.LastDialysisBeforePrepare = lastGoodUserDetial
  2829. }
  2830. if err == nil {
  2831. c.ServeSuccessJSON(map[string]interface{}{
  2832. "dialysis_goods": dialysisGoods,
  2833. "good_type": goodTypes,
  2834. "total": total,
  2835. })
  2836. return
  2837. } else {
  2838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2839. return
  2840. }
  2841. } else if err != nil {
  2842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2843. return
  2844. }
  2845. }
  2846. func (c *DialysisApiController) GetDialysisGoodsStatistics() {
  2847. start_time := c.GetString("start_time")
  2848. end_time := c.GetString("end_time")
  2849. timeLayout := "2006-01-02"
  2850. loc, _ := time.LoadLocation("Local")
  2851. var theStartTime int64
  2852. if len(start_time) > 0 {
  2853. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2854. if err != nil {
  2855. utils.ErrorLog(err.Error())
  2856. }
  2857. theStartTime = theTime.Unix()
  2858. }
  2859. var theEndtTime int64
  2860. if len(end_time) > 0 {
  2861. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2862. if err != nil {
  2863. utils.ErrorLog(err.Error())
  2864. }
  2865. theEndtTime = theTime.Unix()
  2866. }
  2867. adminUser := c.GetAdminUserInfo()
  2868. outInfo, err := service.MobileGetGoodsStatistics(adminUser.CurrentOrgId, theStartTime, theEndtTime)
  2869. if err == nil {
  2870. c.ServeSuccessJSON(map[string]interface{}{
  2871. "stock_out": outInfo,
  2872. })
  2873. return
  2874. } else {
  2875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2876. return
  2877. }
  2878. }