dialysis_api_controller.go 115KB

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