dialysis_api_controller.go 116KB

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