dialysis_api_controller.go 177KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "XT_New/enums"
  11. "XT_New/models"
  12. "XT_New/service"
  13. "XT_New/utils"
  14. "github.com/astaxie/beego"
  15. "math"
  16. "net/http"
  17. "net/url"
  18. )
  19. // type DialysisTestAPIController struct {
  20. // MobileBaseAPIController
  21. // }
  22. // [get]/m/api/test
  23. // func (this *DialysisTestAPIController) Test() {
  24. // orgID := int64(3907)
  25. // now := time.Now()
  26. // nextWeek := now.AddDate(0, 0, 7)
  27. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  28. // nextTwoWeek := now.AddDate(0, 0, 14)
  29. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  30. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  31. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  32. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  33. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  34. // return
  35. // }
  36. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  37. // if exchangeErr != nil {
  38. // this.ErrorLog("%v", exchangeErr)
  39. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  40. // return
  41. // }
  42. // this.ServeSuccessJSON(map[string]interface{}{
  43. // // "now": now,
  44. // // "next_week": nextWeek,f
  45. // // "next_week_mon": nextWeekMon,
  46. // // "next_week_sun": nextWeekSun,
  47. // // "next_two_week_mon": nextTwoWeekMon,
  48. // // "next_two_week_sun": nextTwoWeekSun,
  49. // "next_week_schs": nextWeekSchs,
  50. // "next_two_week_schs": nextTwoWeekSchs,
  51. // })
  52. // }
  53. type DialysisAPIController struct {
  54. MobileBaseAPIAuthController
  55. }
  56. // /m/api/scheduals [get]
  57. // @param type:int
  58. // @param date:string
  59. func (this *DialysisAPIController) Scheduals() {
  60. schedualType, _ := this.GetInt64("type")
  61. schedualDate := this.GetString("date")
  62. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  63. schedualType = 0
  64. }
  65. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  66. if parseDateErr != nil {
  67. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  68. return
  69. }
  70. adminInfo := this.GetMobileAdminUserInfo()
  71. orgID := adminInfo.Org.Id
  72. redis := service.RedisClient()
  73. defer redis.Close()
  74. // cur_date := time.Now().Format("2006-01-02")
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. scheduals_json_str, _ := redis.Get(key).Result()
  77. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  78. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  79. if err != nil {
  80. this.ErrorLog("获取排班信息失败:%v", err)
  81. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  82. } else {
  83. if len(scheduals) > 0 {
  84. //缓存数据
  85. scheduals_json, err := json.Marshal(scheduals)
  86. if err == nil {
  87. redis.Set(key, scheduals_json, time.Second*30)
  88. }
  89. }
  90. this.ServeSuccessJSON(map[string]interface{}{
  91. "scheduals": scheduals,
  92. })
  93. }
  94. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  95. var dat []map[string]interface{}
  96. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  97. } else {
  98. }
  99. this.ServeSuccessJSON(map[string]interface{}{
  100. "scheduals": dat,
  101. "redis": "true",
  102. "date": schedualDate,
  103. })
  104. }
  105. }
  106. // /m/api/waiting_scheduals [get]
  107. // @param date:string
  108. func (this *DialysisAPIController) WaitingScheduals() {
  109. schedualDate := this.GetString("date")
  110. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  111. if parseDateErr != nil && len(schedualDate) != 0 {
  112. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  113. return
  114. }
  115. adminInfo := this.GetMobileAdminUserInfo()
  116. orgID := adminInfo.Org.Id
  117. redis := service.RedisClient()
  118. defer redis.Close()
  119. // cur_date := time.Now().Format("2006-01-02")
  120. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  121. wait_scheduals, _ := redis.Get(key).Result()
  122. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  123. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  124. if err != nil {
  125. this.ErrorLog("获取排班信息失败:%v", err)
  126. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  127. } else {
  128. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  129. for _, s := range scheduals {
  130. returnScheduals = append(returnScheduals, s)
  131. }
  132. if len(returnScheduals) > 0 {
  133. //缓存数据
  134. wait_scheduals_json, err := json.Marshal(scheduals)
  135. if err == nil {
  136. redis.Set(key, wait_scheduals_json, time.Second*30)
  137. }
  138. }
  139. this.ServeSuccessJSON(map[string]interface{}{
  140. "scheduals": scheduals,
  141. })
  142. }
  143. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  144. var dat []map[string]interface{}
  145. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  146. } else {
  147. }
  148. this.ServeSuccessJSON(map[string]interface{}{
  149. "scheduals": dat,
  150. "redis": "true",
  151. "date": schedualDate,
  152. })
  153. }
  154. }
  155. //else{
  156. // fmt.Println("33333333")
  157. //
  158. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  159. // if err != nil {
  160. // this.ErrorLog("获取排班信息失败:%v", err)
  161. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  162. // } else {
  163. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  164. // for _, s := range scheduals {
  165. //
  166. // returnScheduals = append(returnScheduals, s)
  167. // }
  168. //
  169. // this.ServeSuccessJSON(map[string]interface{}{
  170. // "scheduals": returnScheduals,
  171. // })
  172. // }
  173. //
  174. // }
  175. //if err == nil{
  176. //
  177. //
  178. //
  179. //
  180. //
  181. //}else{
  182. //}
  183. // /m/api/dialysis/record [get]
  184. // @param patient_id:int
  185. // @param date:string (yyyy-MM-dd)
  186. func (this *DialysisAPIController) DialysisRecord() {
  187. patientID, _ := this.GetInt64("patient_id")
  188. recordDateStr := this.GetString("date")
  189. if patientID <= 0 {
  190. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  191. return
  192. }
  193. if len(recordDateStr) == 0 {
  194. recordDateStr = time.Now().Format("2006-01-02")
  195. }
  196. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  197. if parseDateErr != nil {
  198. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  199. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  200. return
  201. }
  202. adminInfo := this.GetMobileAdminUserInfo()
  203. patient, getPatientErr := service.MobileGetPatientDetail(adminInfo.Org.Id, patientID)
  204. if getPatientErr != nil {
  205. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  206. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  207. return
  208. } else if patient == nil {
  209. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  210. return
  211. }
  212. schedual, getSchedualErr := service.MobileGetSchedualDetail(adminInfo.Org.Id, patientID, date.Unix())
  213. if getSchedualErr != nil {
  214. this.ErrorLog("获取患者排班信息失败:%v", getSchedualErr)
  215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  216. return
  217. }
  218. receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  219. if getRTARErr != nil {
  220. this.ErrorLog("获取接诊评估失败:%v", getRTARErr)
  221. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  222. return
  223. }
  224. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  225. if getPEErr != nil {
  226. this.ErrorLog("获取透前评估失败:%v", getPEErr)
  227. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  228. return
  229. }
  230. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  231. if getLPEErr != nil {
  232. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  233. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  234. return
  235. }
  236. doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  237. if getDoctorAdvicesErr != nil {
  238. this.ErrorLog("获取临时医嘱失败:%v", getDoctorAdvicesErr)
  239. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  240. return
  241. }
  242. dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  243. if getDialysisOrderErr != nil {
  244. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  245. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  246. return
  247. }
  248. doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  249. if getDoubleCheckErr != nil {
  250. this.ErrorLog("获取双人核对记录失败:%v", getDoubleCheckErr)
  251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  252. return
  253. }
  254. monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  255. if getMonitorRecordsErr != nil {
  256. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  257. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  258. return
  259. }
  260. var lastMonitorRecord *models.MonitoringRecord
  261. lastMonitorRecord, getLastErr := service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  262. if getLastErr != nil {
  263. this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
  264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  265. return
  266. }
  267. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  268. if getAADErr != nil {
  269. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  270. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  271. return
  272. }
  273. lastAssessmentAfterDislysis, getLAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  274. if getLAADErr != nil {
  275. this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
  276. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  277. return
  278. }
  279. treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  280. if getTreatmentSummaryErr != nil {
  281. this.ErrorLog("获取治疗小结失败:%v", getTreatmentSummaryErr)
  282. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  283. return
  284. }
  285. dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  286. //if getDialysisPrescribeErr != nil {
  287. // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  288. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  289. // return
  290. //}
  291. dialysisSolution, _ := service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  292. //if getDialysisSolutionErr != nil {
  293. // this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
  294. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  295. // return
  296. //}
  297. lastDialysisPrescribe, _ := service.MobileGetLastDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  298. //fmt.Println("上次透析处方",lastDialysisPrescribe.DialyzerPerfusionApparatus)
  299. //if getDialysisPrescribeErr != nil {
  300. // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  301. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  302. // return
  303. //}
  304. //获取系统透析处方模版
  305. systemDialysisPrescribe, _ := service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  306. //if getSystemDialysisPrescribeErr != nil {
  307. // this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr)
  308. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  309. // return
  310. //}
  311. //dialysisSolution, getDialysisSolutionErr := service.MobileGetDialysisSolution(adminInfo.Org.Id, patientID)
  312. //operators, _ := service.GetAllAdminUserES(adminInfo.Org.Id, adminInfo.App.Id)
  313. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  314. stockType, _ := service.GetStockType(adminInfo.Org.Id)
  315. prepare, _ := service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  316. //获取最后一次血管通路
  317. lastAssessment, parseDateErr := service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  318. prescribeOne, parseDateErr := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  319. var his_advices []*models.HisDoctorAdviceInfo
  320. if is_open_config.IsOpen == 1 {
  321. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  322. }
  323. if getLPEErr != nil {
  324. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  325. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  326. return
  327. }
  328. lastDryWeightDislysis, getDryErr := service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  329. if getDryErr != nil {
  330. this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
  331. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  332. return
  333. }
  334. //headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.Org.Id, adminInfo.App.Id, models.SpecialPermissionTypeHeadNurse)
  335. _, gobalConfig := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  336. //goodTypes, _ := service.FindAllGoodTypeByType(1) //查出所有库存配置的系统类型
  337. //goodInfos, _ := service.FindAllGoodInfo(adminInfo.Org.Id) //查出所有库存配置的系统类型
  338. operators, _ := service.GetAllStarfEs(adminInfo.Org.Id)
  339. //consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patientID, date.Unix())
  340. //lastConsumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patientID, date.Unix())
  341. returnData := map[string]interface{}{
  342. "patient": patient,
  343. "schedual": schedual,
  344. "prescription": dialysisPrescribe,
  345. "solution": dialysisSolution,
  346. "last_prescription": lastDialysisPrescribe,
  347. "receiver_treatment_access": receiverTreatmentAccess,
  348. "predialysis_evaluation": predialysisEvaluation,
  349. "doctor_advices": doctorAdvices,
  350. "double_check": doubleCheck,
  351. "assessment_after_dislysis": assessmentAfterDislysis,
  352. "treatment_summary": treatmentSummary,
  353. "monitor_records": monitorRecords,
  354. "dialysis_order": dialysisOrder,
  355. "operators": operators,
  356. "last_predialysis_evaluation": lastPredialysisEvaluation,
  357. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  358. "last_monitor_record": lastMonitorRecord,
  359. "config": gobalConfig,
  360. "dry_weight": lastDryWeightDislysis,
  361. "system_prescription": systemDialysisPrescribe,
  362. "his_advices": his_advices,
  363. "is_open_config": is_open_config,
  364. "stockType": stockType,
  365. "prepare": prepare,
  366. "lastAssessment": lastAssessment,
  367. "prescribeOne": prescribeOne,
  368. }
  369. this.ServeSuccessJSON(returnData)
  370. }
  371. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  372. adminInfo := c.GetMobileAdminUserInfo()
  373. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  374. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  375. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  376. returnData := map[string]interface{}{
  377. "admin_users": adminUsers,
  378. "devices": devices,
  379. "device_numbers": device_numbers,
  380. }
  381. c.ServeSuccessJSON(returnData)
  382. }
  383. func (c *DialysisAPIController) PostAtreatmentInfo() {
  384. id, _ := c.GetInt64("patient", 0)
  385. recordDateStr := c.GetString("record_date")
  386. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  387. summaryContent := c.GetString("summaryContent")
  388. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  389. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  390. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  391. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  392. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  393. nursingRecord := c.GetString("nursing_record")
  394. fmt.Println("护理记录", nursingRecord)
  395. specialRecord := c.GetString("special_record")
  396. fmt.Println("特殊记录", specialRecord)
  397. adminUserInfo := c.GetMobileAdminUserInfo()
  398. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  399. checkStaffId = adminUserInfo.AdminUser.Id
  400. deboardNurseId = adminUserInfo.AdminUser.Id
  401. treatDoctor = adminUserInfo.AdminUser.Id
  402. if id <= 0 {
  403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  404. return
  405. }
  406. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  407. if patient.ID == 0 {
  408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  409. return
  410. }
  411. if len(recordDateStr) == 0 {
  412. recordDateStr = time.Now().Format("2006-01-02")
  413. }
  414. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  415. if parseDateErr != nil {
  416. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  418. return
  419. }
  420. //now := time.Now()
  421. //year, month, day := now.Date()
  422. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  423. //todayTimeStamp := today_time.Unix()
  424. summary := models.TreatmentSummary{
  425. UserOrgId: adminUserInfo.Org.Id,
  426. PatientId: id,
  427. AssessmentDate: recordDate.Unix(),
  428. Mission: propagandaAndEducationContent,
  429. DialysisSummary: summaryContent,
  430. SjNurse: changeMedicalNurseId,
  431. ZlNurse: treatNurseId,
  432. HdNurse: checkStaffId,
  433. XjNurse: deboardNurseId,
  434. ZlDoctor: treatDoctor,
  435. CreatedTime: time.Now().Unix(),
  436. Status: 1,
  437. NursingRecord: nursingRecord,
  438. SpecialRecord: specialRecord,
  439. }
  440. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  441. if treatmentSummary.ID == 0 { //新增
  442. summary.Creater = adminUserInfo.AdminUser.Id
  443. service.AddSigleSummaryRecord(&summary)
  444. c.ServeSuccessJSON(map[string]interface{}{
  445. "summary": summary,
  446. })
  447. } else { //修改
  448. //if treatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  449. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, 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. summary.Creater = treatmentSummary.Creater
  459. summary.CreatedTime = treatmentSummary.CreatedTime
  460. summary.Modifier = adminUserInfo.AdminUser.Id
  461. summary.ID = treatmentSummary.ID
  462. service.UpdateSummeRecord(&summary)
  463. c.ServeSuccessJSON(map[string]interface{}{
  464. "summary": summary,
  465. })
  466. }
  467. }
  468. func (c *DialysisAPIController) PostDoubleCheck() {
  469. id, _ := c.GetInt64("patient", 0)
  470. recordDateStr := c.GetString("record_date")
  471. checkTimeStr := c.GetString("check_time")
  472. firstCheckTimeStr := c.GetString("first_check_time")
  473. creater, _ := c.GetInt64("creater", 0)
  474. modifier, _ := c.GetInt64("modifier", 0)
  475. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  476. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  477. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  478. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  479. dialysis_item_desc := c.GetString("dialysis_item_desc")
  480. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  481. vascular_access_desc := c.GetString("vascular_access_desc")
  482. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  483. collator, _ := c.GetInt64("collator", 0)
  484. if id <= 0 {
  485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  486. return
  487. }
  488. adminUserInfo := c.GetMobileAdminUserInfo()
  489. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  490. if patient.ID == 0 {
  491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  492. return
  493. }
  494. if len(recordDateStr) == 0 {
  495. recordDateStr = time.Now().Format("2006-01-02")
  496. }
  497. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  498. if parseDateErr != nil {
  499. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  501. return
  502. }
  503. var checkDate int64
  504. if len(checkTimeStr) == 0 {
  505. checkDate = 0
  506. } else {
  507. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  508. checkDate = checkDateUnix.Unix()
  509. }
  510. var firstCheckDate int64
  511. if len(firstCheckTimeStr) == 0 {
  512. firstCheckDate = 0
  513. } else {
  514. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  515. firstCheckDate = firstCheckDateUnix.Unix()
  516. }
  517. //now := time.Now()
  518. //year, month, day := now.Date()
  519. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  520. //todayTimeStamp := today_time.Unix()
  521. doubleCheck := models.DoubleCheck{
  522. UserOrgId: adminUserInfo.Org.Id,
  523. PatientId: id,
  524. DialysisItemCheck: dialysis_item_check,
  525. DialysisParameterCheck: dialysis_parameter_check,
  526. VascularAccessVerification: vascular_access_verification,
  527. PipelineConnectionCheck: pipeline_connection_check,
  528. DialysisItemDesc: dialysis_item_desc,
  529. DialysisParameterDesc: dialysis_parameter_desc,
  530. VascularAccessDesc: vascular_access_desc,
  531. PipelineConnectionDesc: pipeline_connection_desc,
  532. Collator: collator,
  533. Status: 1,
  534. CreatedTime: time.Now().Unix(),
  535. CheckDate: recordDate.Unix(),
  536. UpdatedTime: time.Now().Unix(),
  537. }
  538. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  539. if check.ID == 0 { //新增
  540. doubleCheck.FirstCheckTime = firstCheckDate
  541. doubleCheck.CheckTime = checkDate
  542. doubleCheck.Creater = creater
  543. doubleCheck.Modifier = modifier
  544. err := service.AddSigleDoubleCheck(&doubleCheck)
  545. if err == nil {
  546. c.ServeSuccessJSON(map[string]interface{}{
  547. "doubleCheck": &doubleCheck,
  548. })
  549. }
  550. } else { //修改
  551. doubleCheck.FirstCheckTime = firstCheckDate
  552. doubleCheck.CheckTime = checkDate
  553. doubleCheck.Creater = creater
  554. doubleCheck.Modifier = modifier
  555. doubleCheck.CreatedTime = check.CreatedTime
  556. doubleCheck.ID = check.ID
  557. err := service.UpdateDoubleCheck(&doubleCheck)
  558. if err == nil {
  559. c.ServeSuccessJSON(map[string]interface{}{
  560. "doubleCheck": &doubleCheck,
  561. })
  562. }
  563. }
  564. }
  565. func (c *DialysisAPIController) PostAcceptsAssessment() {
  566. id, _ := c.GetInt64("patient", 0)
  567. recordDateStr := c.GetString("record_date")
  568. way, _ := c.GetInt64("way", 0)
  569. consciousness, _ := c.GetInt64("consciousness", 0)
  570. appetite, _ := c.GetInt64("appetite", 0)
  571. condition, _ := c.GetInt64("condition", 0)
  572. posture, _ := c.GetInt64("posture")
  573. sick_condition, _ := c.GetInt64("sick_condition", 0)
  574. danger_level, _ := c.GetInt64("danger_level", 0)
  575. intake, _ := c.GetInt64("intake", 0)
  576. nutrition, _ := c.GetInt64("nutrition", 0)
  577. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  578. psychological_assessment_other := c.GetString("psychological_assessment_other")
  579. score := c.GetString("score")
  580. sick_condition_other := c.GetString("sick_condition_other")
  581. //precaution, _ := c.GetInt64("precaution", 0)
  582. precaution := c.GetString("precaution")
  583. precaution_other := c.GetString("precaution_other")
  584. psychological_other := c.GetString("psychological_other")
  585. admission_number := c.GetString("admission_number")
  586. tumble, _ := c.GetInt64("tumble")
  587. if id <= 0 {
  588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  589. return
  590. }
  591. adminUserInfo := c.GetMobileAdminUserInfo()
  592. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  593. if patient.ID == 0 {
  594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  595. return
  596. }
  597. //now := time.Now()
  598. //year, month, day := now.Date()
  599. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  600. //todayTimeStamp := today_time.Unix()
  601. if len(recordDateStr) == 0 {
  602. recordDateStr = time.Now().Format("2006-01-02")
  603. }
  604. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  605. if parseDateErr != nil {
  606. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  608. return
  609. }
  610. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  611. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  612. UserOrgId: adminUserInfo.Org.Id,
  613. PatientId: id,
  614. RecordDate: recordDate.Unix(),
  615. Way: way,
  616. Consciousness: consciousness,
  617. Appetite: appetite,
  618. Condition: condition,
  619. SickCondition: sick_condition,
  620. DangerLevel: danger_level,
  621. Intake: intake,
  622. Nutrition: nutrition,
  623. PsychologicalAssessment: psychological_assessment,
  624. PsychologicalAssessmentOther: psychological_assessment_other,
  625. SickConditionOther: sick_condition_other,
  626. Posture: posture,
  627. CreatedTime: time.Now().Unix(),
  628. UpdateTime: time.Now().Unix(),
  629. Status: 1,
  630. Score: score,
  631. Precaution: precaution,
  632. PrecautionOther: precaution_other,
  633. PsychologicalOther: psychological_other,
  634. AdmissionNumber: admission_number,
  635. Tumble: tumble,
  636. }
  637. if receiveTreatment.ID == 0 { //新增
  638. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  639. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  640. if err == nil {
  641. c.ServeSuccessJSON(map[string]interface{}{
  642. "receiveTreatmentAsses": receiveTreatmentAsses,
  643. })
  644. }
  645. } else { //修改
  646. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  647. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  648. // if getPermissionErr != nil {
  649. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  650. // return
  651. // } else if headNursePermission == nil {
  652. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  653. // return
  654. // }
  655. //}
  656. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  657. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  658. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  659. receiveTreatmentAsses.ID = receiveTreatment.ID
  660. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  661. if err == nil {
  662. c.ServeSuccessJSON(map[string]interface{}{
  663. "receiveTreatmentAsses": receiveTreatmentAsses,
  664. })
  665. }
  666. }
  667. }
  668. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  669. id, _ := c.GetInt64("patient", 0)
  670. recordDateStr := c.GetString("record_date")
  671. weightAfter, _ := c.GetFloat("weight_after", 0)
  672. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  673. weightReduce, _ := c.GetFloat("weight_loss", 0)
  674. temperature, _ := c.GetFloat("temperature", 0)
  675. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  676. breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  677. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  678. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  679. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  680. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  681. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  682. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  683. cruor := c.GetString("cruor")
  684. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  685. internalFistula := c.GetString("internal_fistula")
  686. catheter := c.GetString("catheter")
  687. complications := c.GetString("complication")
  688. remark := c.GetString("remark")
  689. dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  690. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  691. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  692. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  693. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  694. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  695. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  696. patientGose, _ := c.GetInt64("patient_gose", 0)
  697. inpatientDepartment := c.GetString("inpatient_department")
  698. observationContent := c.GetString("observation_content")
  699. observationContentOther := c.GetString("observation_content_other")
  700. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  701. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  702. in_advance_reason := c.GetString("in_advance_reason")
  703. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  704. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  705. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  706. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  707. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  708. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  709. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  710. dialyzer, _ := c.GetInt64("dialyzer", 0)
  711. in_advance_reason_other := c.GetString("in_advance_reason_other")
  712. is_eat, _ := c.GetInt64("is_eat", 0)
  713. cvc_a, _ := c.GetFloat("cvc_a", 0)
  714. cvc_v, _ := c.GetFloat("cvc_v", 0)
  715. channels, _ := c.GetInt64("channel", 0)
  716. return_blood, _ := c.GetInt64("return_blood", 0)
  717. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  718. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  719. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  720. blood_flow, _ := c.GetInt64("blood_flow", 0)
  721. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  722. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  723. sealing_fluid_special := c.GetString("sealing_fluid_special")
  724. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  725. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  726. setting_pressure := c.GetString("setting_pressure")
  727. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  728. diastolic_pressure := c.GetString("diastolic_pressure")
  729. other_complication := c.GetString("other_complication")
  730. ktv := c.GetString("ktv")
  731. urr := c.GetString("urr")
  732. hypertenison, _ := c.GetInt64("hypertenison")
  733. hypopiesia, _ := c.GetInt64("hypopiesia")
  734. leave_office_method, _ := c.GetInt64("leave_office_method")
  735. lapse, _ := c.GetInt64("lapse")
  736. consciousness, _ := c.GetInt64("consciousness")
  737. fallrisk, _ := c.GetInt64("fallrisk")
  738. if id <= 0 {
  739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  740. return
  741. }
  742. adminUserInfo := c.GetMobileAdminUserInfo()
  743. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  744. if patient.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. //now := time.Now()
  758. //year, month, day := now.Date()
  759. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  760. //todayTimeStamp := today_time.Unix()
  761. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  762. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  763. UserOrgId: adminUserInfo.Org.Id,
  764. PatientId: id,
  765. AssessmentDate: recordDate.Unix(),
  766. Temperature: temperature,
  767. PulseFrequency: pulse_frequency,
  768. BreathingRate: breathing_rate,
  769. SystolicBloodPressure: systolic_blood_pressure,
  770. DiastolicBloodPressure: diastolic_blood_pressure,
  771. ActualUltrafiltration: actual_ultrafiltration,
  772. ActualDisplacement: actual_displacement,
  773. ActualTreatmentHour: actualtreatHour,
  774. ActualTreatmentMinute: actualtreatmin,
  775. WeightAfter: weightAfter,
  776. AdditionalWeight: additionalWeight,
  777. WeightLoss: weightReduce,
  778. Cruor: cruor,
  779. SymptomAfterDialysis: symptomsAfterDialysi,
  780. InternalFistula: internalFistula,
  781. Catheter: catheter,
  782. Complication: complications,
  783. DialysisIntakes: dialysateVolume,
  784. CreatedTime: time.Now().Unix(),
  785. Status: 1,
  786. Remark: remark,
  787. BloodAccessPartId: blood_access_part_id,
  788. BloodAccessPartOperaId: blood_access_part_opera_id,
  789. DialysisIntakesUnit: dialysis_intakes_unit,
  790. PuncturePointOozingBlood: puncturePointOozingBlood,
  791. PuncturePointHaematoma: puncturePointHaematoma,
  792. InternalFistulaTremorAc: internalFistulaTremorAc,
  793. PatientGose: patientGose,
  794. InpatientDepartment: inpatientDepartment,
  795. ObservationContent: observationContent,
  796. ObservationContentOther: observationContentOther,
  797. DialysisProcess: dialysis_process,
  798. InAdvanceMinute: in_advance_minute,
  799. InAdvanceReason: in_advance_reason,
  800. HemostasisMinute: hemostasis_minute,
  801. HemostasisOpera: hemostasis_opera,
  802. TremorNoise: tremor_noise,
  803. DisequilibriumSyndrome: disequilibrium_syndrome,
  804. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  805. ArterialTube: arterial_tube,
  806. IntravenousTube: intravenous_tube,
  807. Dialyzer: dialyzer,
  808. InAdvanceReasonOther: in_advance_reason_other,
  809. IsEat: is_eat,
  810. CvcA: cvc_a,
  811. CvcV: cvc_v,
  812. Channel: channels,
  813. ReturnBlood: return_blood,
  814. RehydrationVolume: rehydration_volume,
  815. DialysisDuring: dialysis_during,
  816. StrokeVolume: stroke_volume,
  817. BloodFlow: blood_flow,
  818. SealingFluidDispose: sealing_fluid_dispose,
  819. SealingFluidSpecial: sealing_fluid_special,
  820. DosageOfAnticoagulants: dosage_of_anticoagulants,
  821. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  822. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  823. SettingPressure: setting_pressure,
  824. DiastolicPressure: diastolic_pressure,
  825. OtherComplication: other_complication,
  826. Ktv: ktv,
  827. Urr: urr,
  828. Hypopiesia: hypopiesia,
  829. Hypertenison: hypertenison,
  830. Lapse: lapse,
  831. LeaveOfficeMethod: leave_office_method,
  832. Consciousness: consciousness,
  833. Fallrisk: fallrisk,
  834. }
  835. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  836. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  837. if assessmentAfter.ID == 0 { //新增
  838. if appRole.UserType == 2 || appRole.UserType == 1 {
  839. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  840. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  841. } else {
  842. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  843. }
  844. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  845. if err == nil {
  846. c.ServeSuccessJSON(map[string]interface{}{
  847. "assessmentAfterDislysis": assessmentAfterDislysis,
  848. })
  849. }
  850. } else { //修改
  851. if appRole.UserType == 2 || appRole.UserType == 1 {
  852. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  853. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  854. } else {
  855. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  856. if assessmentAfterDislysis.Creater == 0 {
  857. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  858. }
  859. }
  860. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  861. assessmentAfterDislysis.ID = assessmentAfter.ID
  862. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  863. if err == nil {
  864. c.ServeSuccessJSON(map[string]interface{}{
  865. "assessmentAfterDislysis": assessmentAfterDislysis,
  866. })
  867. }
  868. }
  869. }
  870. func (c *DialysisAPIController) PostDialysisPrescription() {
  871. id, _ := c.GetInt64("patient", 0)
  872. recordDateStr := c.GetString("record_date")
  873. if id <= 0 {
  874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  875. return
  876. }
  877. adminUserInfo := c.GetMobileAdminUserInfo()
  878. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  879. if patient.ID == 0 {
  880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  881. return
  882. }
  883. if len(recordDateStr) == 0 {
  884. recordDateStr = time.Now().Format("2006-01-02")
  885. }
  886. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  887. if parseDateErr != nil {
  888. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  890. return
  891. }
  892. mode_id, _ := c.GetInt64("mode_id", 0)
  893. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  894. dialyzer, _ := c.GetInt64("dialyzer", 0)
  895. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  896. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  897. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  898. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  899. replacement_total, _ := c.GetFloat("replacement_total", 0)
  900. replacement_way, _ := c.GetInt64("replacement_way", 0)
  901. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  902. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  903. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  904. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  905. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  906. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  907. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  908. kalium, _ := c.GetFloat("kalium", 0)
  909. sodium, _ := c.GetFloat("sodium", 0)
  910. calcium, _ := c.GetFloat("calcium", 0)
  911. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  912. glucose, _ := c.GetFloat("glucose", 0)
  913. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  914. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  915. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  916. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  917. conductivity, _ := c.GetFloat("conductivity", 0)
  918. remark := c.GetString("remark")
  919. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  920. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  921. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  922. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  923. body_fluid, _ := c.GetInt64("body_fluid", 0)
  924. special_medicine, _ := c.GetInt64("special_medicine", 0)
  925. special_medicine_other := c.GetString("special_medicine_other")
  926. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  927. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  928. blood_access, _ := c.GetInt64("blood_access", 0)
  929. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  930. body_fluid_other := c.GetString("body_fluid_other")
  931. niprocart, _ := c.GetInt64("niprocart", 0)
  932. jms, _ := c.GetInt64("jms", 0)
  933. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  934. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  935. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  936. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  937. filtryzer, _ := c.GetInt64("filtryzer", 0)
  938. target_ktv, _ := c.GetFloat("target_ktv", 0)
  939. dialyzers, _ := c.GetInt64("dialyzers", 0)
  940. injector, _ := c.GetInt64("injector", 0)
  941. bloodlines, _ := c.GetInt64("bloodlines", 0)
  942. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  943. safe_package, _ := c.GetInt64("package", 0)
  944. a_liquid, _ := c.GetInt64("a_liquid", 0)
  945. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  946. fmt.Println("预冲量", pre_impulse)
  947. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  948. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  949. blood := c.GetString("blood")
  950. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  951. dialysis_irrigation := c.GetString("dialysis_irrigation")
  952. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  953. displace_speed := c.GetString("displace_speed")
  954. illness, _ := c.GetInt64("illness")
  955. amylaceum := c.GetString("amylaceum")
  956. single_time := c.GetString("single_time")
  957. single_water := c.GetString("single_water")
  958. replacement_flow := c.GetString("replacement_flow")
  959. plasma_separator := c.GetString("plasma_separator")
  960. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  961. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  962. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  963. //
  964. //if template.TemplateId == 2 || template.TemplateId == 6 {
  965. // if appRole.UserType == 3 {
  966. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  967. // if getPermissionErr != nil {
  968. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  969. // return
  970. // } else if headNursePermission == nil {
  971. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  972. // return
  973. // }
  974. // }
  975. //}
  976. //TODO 需要根据角色去判断
  977. prescription := models.DialysisPrescription{
  978. UserOrgId: adminUserInfo.Org.Id,
  979. PatientId: id,
  980. RecordDate: recordDate.Unix(),
  981. ModeId: mode_id,
  982. DialysisDuration: dialysis_duration,
  983. Dialyzer: dialyzer,
  984. PerfusionApparatus: perfusion_apparatus,
  985. BloodFlowVolume: blood_flow_volume,
  986. DewaterAmount: dewater_amount,
  987. DisplaceLiqui: displace_liqui,
  988. ReplacementWay: replacement_way,
  989. Anticoagulant: anticoagulant,
  990. AnticoagulantShouji: anticoagulant_shouji,
  991. AnticoagulantWeichi: anticoagulant_weichi,
  992. AnticoagulantZongliang: anticoagulant_zongliang,
  993. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  994. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  995. Kalium: kalium,
  996. Sodium: sodium,
  997. Calcium: calcium,
  998. Bicarbonate: bicarbonate,
  999. Glucose: glucose,
  1000. // DryWeight: dry_weight,
  1001. DialysateFlow: dialysate_flow,
  1002. DialysateTemperature: dialysate_temperature,
  1003. // PrescriptionDoctor: prescription_doctor,
  1004. ReplacementTotal: replacement_total,
  1005. Conductivity: conductivity,
  1006. Remark: remark,
  1007. Status: 1,
  1008. CreatedTime: time.Now().Unix(),
  1009. UpdatedTime: time.Now().Unix(),
  1010. DialysisDurationMinute: dialysisDurationMinute,
  1011. DialysisDurationHour: dialysisDurationHour,
  1012. TargetUltrafiltration: targetUltrafiltration,
  1013. DialysateFormulation: dialysateFormulation,
  1014. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1015. BodyFluid: body_fluid,
  1016. SpecialMedicine: special_medicine,
  1017. SpecialMedicineOther: special_medicine_other,
  1018. DisplaceLiquiPart: displace_liqui_part,
  1019. DisplaceLiquiValue: displace_liqui_value,
  1020. BloodAccess: blood_access,
  1021. Ultrafiltration: ultrafiltration,
  1022. BodyFluidOther: body_fluid_other,
  1023. Niprocart: niprocart,
  1024. Jms: jms,
  1025. FistulaNeedleSet: fistula_needle_set,
  1026. FistulaNeedleSet16: fistula_needle_set_16,
  1027. Hemoperfusion: hemoperfusion,
  1028. DialyserSterilised: dialyser_sterilised,
  1029. Filtryzer: filtryzer,
  1030. Dialyzers: dialyzers,
  1031. Injector: injector,
  1032. Bloodlines: bloodlines,
  1033. TubingHemodialysis: tubing_hemodialysis,
  1034. Package: safe_package,
  1035. ALiquid: a_liquid,
  1036. TargetKtv: target_ktv,
  1037. PreImpulse: pre_impulse,
  1038. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1039. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1040. Blood: blood,
  1041. DialysisDialyszers: dialysis_dialyszers,
  1042. DialysisIrrigation: dialysis_irrigation,
  1043. AntioxidantCommodityName: antioxidant_commodity_name,
  1044. DisplaceSpeed: displace_speed,
  1045. Illness: illness,
  1046. Amylaceum: amylaceum,
  1047. SingleTime: single_time,
  1048. SingleWater: single_water,
  1049. ReplacementFlow: replacement_flow,
  1050. PlasmaSeparator: plasma_separator,
  1051. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1052. }
  1053. //查询最近透析准备表里是否存在 透析器 灌流器
  1054. //
  1055. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1056. //
  1057. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1058. //
  1059. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1060. //if len(mation)>0{
  1061. // for _, item := range splitStr {
  1062. // for _,it := range mation{
  1063. // if(item == it.SpecificationName){
  1064. //
  1065. // //查询最近一次的透析器
  1066. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1067. //
  1068. // if errcode == gorm.ErrRecordNotFound{
  1069. // //插入数据
  1070. // prepare := models.DialysisBeforePrepare{
  1071. // UserOrgId: adminUserInfo.Org.Id,
  1072. // PatientId: id,
  1073. // RecordDate: recordDate.Unix(),
  1074. // GoodTypeId: it.GoodTypeId,
  1075. // GoodId: it.ID,
  1076. // Count: 1,
  1077. // Ctime: time.Now().Unix(),
  1078. // Creater: adminUserInfo.AdminUser.Id,
  1079. // Status:1,
  1080. //
  1081. // }
  1082. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1083. // fmt.Println("",errcode)
  1084. // }
  1085. // }
  1086. // }
  1087. //
  1088. // }
  1089. //
  1090. // for _, item := range splitIrrigation {
  1091. // for _,it := range mation{
  1092. // if(item == it.SpecificationName){
  1093. // //查询最近一次的透析器
  1094. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1095. // if errcode == gorm.ErrRecordNotFound{
  1096. // //插入数据
  1097. // prepare := models.DialysisBeforePrepare{
  1098. // UserOrgId: adminUserInfo.Org.Id,
  1099. // PatientId: id,
  1100. // RecordDate: recordDate.Unix(),
  1101. // GoodTypeId: it.GoodTypeId,
  1102. // GoodId: it.ID,
  1103. // Count: 1,
  1104. // Ctime: time.Now().Unix(),
  1105. // Creater: adminUserInfo.AdminUser.Id,
  1106. // Status:1,
  1107. //
  1108. // }
  1109. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1110. // fmt.Println(errcode)
  1111. // }
  1112. // }
  1113. // }
  1114. // }
  1115. //}
  1116. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1117. if dialysisPrescription.ID == 0 { //新增
  1118. //if mode_id > 0 {
  1119. // //service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1120. //}
  1121. if appRole.UserType == 2 || appRole.UserType == 1 {
  1122. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1123. }
  1124. prescription.Creater = adminUserInfo.AdminUser.Id
  1125. err := service.AddSigleRecord(&prescription)
  1126. if err == nil {
  1127. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1128. if updateErr != nil {
  1129. utils.ErrorLog("%v", updateErr)
  1130. }
  1131. c.ServeSuccessJSON(map[string]interface{}{
  1132. "prescription": prescription,
  1133. })
  1134. }
  1135. } else { //修改
  1136. //if mode_id > 0 {
  1137. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1138. //}
  1139. //if template.TemplateId == 1 {
  1140. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1141. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1142. // if getPermissionErr != nil {
  1143. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1144. // return
  1145. // } else if headNursePermission == nil {
  1146. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1147. // return
  1148. // }
  1149. // }
  1150. //}
  1151. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1152. prescription.Modifier = adminUserInfo.AdminUser.Id
  1153. if appRole.UserType == 2 || appRole.UserType == 1 {
  1154. prescription_doctor := adminUserInfo.AdminUser.Id
  1155. prescription.PrescriptionDoctor = prescription_doctor
  1156. } else {
  1157. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  1158. }
  1159. if dialysisPrescription.Creater == 0 { //体重称
  1160. prescription.Creater = adminUserInfo.AdminUser.Id
  1161. } else {
  1162. prescription.Creater = dialysisPrescription.Creater
  1163. }
  1164. prescription.ID = dialysisPrescription.ID
  1165. err := service.UpDateDialysisPrescription(&prescription)
  1166. if err == nil {
  1167. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1168. if updateErr != nil {
  1169. utils.ErrorLog("%v", updateErr)
  1170. }
  1171. c.ServeSuccessJSON(map[string]interface{}{
  1172. "prescription": prescription,
  1173. })
  1174. }
  1175. }
  1176. }
  1177. func (c *DialysisAPIController) Finish() {
  1178. id, _ := c.GetInt64("patient", 0)
  1179. recordDateStr := c.GetString("record_date")
  1180. nurseID, _ := c.GetInt64("nurse")
  1181. end_time := c.GetString("end_time")
  1182. if id <= 0 || nurseID <= 0 {
  1183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1184. return
  1185. }
  1186. adminUserInfo := c.GetMobileAdminUserInfo()
  1187. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1188. if patient.ID == 0 {
  1189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1190. return
  1191. }
  1192. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1193. if getNurseErr != nil {
  1194. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1196. return
  1197. } else if nurse == nil {
  1198. c.ErrorLog("护士不存在")
  1199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1200. return
  1201. }
  1202. if len(recordDateStr) == 0 {
  1203. recordDateStr = time.Now().Format("2006-01-02")
  1204. }
  1205. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1206. if parseDateErr != nil {
  1207. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1209. return
  1210. }
  1211. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  1212. if parseEndDateErr != nil {
  1213. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1215. return
  1216. }
  1217. //now := time.Now()
  1218. //year, month, day := now.Date()
  1219. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1220. //todayTimeStamp := today_time.Unix()
  1221. // 获取当天的第一条透析纪录
  1222. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  1223. if getMonitorRecordsErr != nil {
  1224. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1226. return
  1227. }
  1228. // 获取当前的最后一条透析纪录
  1229. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.Org.Id, id, recordDate.Unix())
  1230. if getMonitorRecordsErr != nil {
  1231. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1233. return
  1234. }
  1235. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  1236. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  1237. if getAADErr != nil {
  1238. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  1239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1240. return
  1241. }
  1242. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  1243. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  1244. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  1245. if assessmentAfterDislysis != nil {
  1246. tempassessmentAfterDislysis = *assessmentAfterDislysis
  1247. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  1248. } else {
  1249. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  1250. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  1251. tempassessmentAfterDislysis.Status = 1
  1252. tempassessmentAfterDislysis.PatientId = id
  1253. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  1254. }
  1255. if dialysisOrder.Stage == 1 {
  1256. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  1257. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1258. fmt.Println(value)
  1259. a, b := math.Modf(value)
  1260. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1261. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1262. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  1263. fmt.Println(hour)
  1264. fmt.Println(minute)
  1265. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  1266. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  1267. }
  1268. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  1269. //var num1 int64
  1270. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  1271. //fmt.Println(num1)
  1272. //sub := float64(num1 / 3600)
  1273. //fmt.Println(sub)
  1274. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  1275. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  1276. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  1277. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1278. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  1279. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  1280. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1281. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1282. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1283. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  1284. }
  1285. if adminUserInfo.Org.Id == 9583 {
  1286. //获取透析处方的最后一条数据
  1287. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  1288. if diaerr != nil {
  1289. c.ErrorLog("获取透析处方失败:%v", diaerr)
  1290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1291. return
  1292. }
  1293. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  1294. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  1295. }
  1296. }
  1297. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  1298. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1299. }
  1300. if lastAssessmentAfterDislysis != nil {
  1301. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  1302. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  1303. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  1304. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  1305. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  1306. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  1307. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  1308. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  1309. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  1310. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  1311. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  1312. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  1313. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  1314. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  1315. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  1316. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  1317. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  1318. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  1319. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  1320. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  1321. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  1322. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  1323. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  1324. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  1325. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  1326. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  1327. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  1328. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  1329. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  1330. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  1331. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  1332. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  1333. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  1334. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  1335. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  1336. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  1337. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  1338. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  1339. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  1340. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  1341. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  1342. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  1343. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  1344. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  1345. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  1346. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  1347. }
  1348. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  1349. if err != nil {
  1350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1351. return
  1352. }
  1353. if dialysisOrder == nil {
  1354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  1355. return
  1356. }
  1357. if dialysisOrder.Stage == 2 {
  1358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  1359. return
  1360. }
  1361. if dialysisOrder.Stage == 1 {
  1362. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id)
  1363. //结束时候透析次数加1
  1364. service.UpdateSolutionByPatientId(id)
  1365. dialysisOrder.Stage = 2
  1366. dialysisOrder.FinishNurse = nurseID
  1367. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  1368. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  1369. dialysisOrder.EndTime = endDate.Unix()
  1370. go func() {
  1371. ssoDomain := beego.AppConfig.String("call_domain")
  1372. api := ssoDomain + "/index/downpatient"
  1373. values := make(url.Values)
  1374. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  1375. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1376. values.Set("patient_id", strconv.FormatInt(id, 10))
  1377. http.PostForm(api, values)
  1378. }()
  1379. if err == nil {
  1380. c.ServeSuccessJSON(map[string]interface{}{
  1381. "dialysisOrder": dialysisOrder,
  1382. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  1383. })
  1384. } else {
  1385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1386. }
  1387. }
  1388. }
  1389. func (c *DialysisAPIController) GetAllZone() {
  1390. adminUserInfo := c.GetMobileAdminUserInfo()
  1391. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  1392. if err == nil {
  1393. c.ServeSuccessJSON(map[string]interface{}{
  1394. "zone": zone,
  1395. })
  1396. }
  1397. }
  1398. func (c *DialysisAPIController) GetSchedualPatientsList() {
  1399. adminUserInfo := c.GetMobileAdminUserInfo()
  1400. page, _ := c.GetInt64("page", 1)
  1401. limit, _ := c.GetInt64("limit", 10)
  1402. schedulType, _ := c.GetInt64("schedul_type", 0)
  1403. startTime, _ := c.GetInt64("schedul_time", 0)
  1404. partitionType, _ := c.GetInt64("partition_type", 0)
  1405. keywords := c.GetString("keywords")
  1406. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  1407. if err == nil {
  1408. c.ServeSuccessJSON(map[string]interface{}{
  1409. "schedule": dialysisSchedule,
  1410. })
  1411. }
  1412. return
  1413. }
  1414. // /m/api/dialysis/start [post]
  1415. // @param patient_id:int
  1416. // @param record_date:string 排班时间 (yyyy-mm-dd)
  1417. // @param nurse:int 上机护士
  1418. // @param bed:int 床位号
  1419. func (this *DialysisAPIController) StartDialysis() {
  1420. patientID, _ := this.GetInt64("patient_id")
  1421. recordDateStr := this.GetString("record_date")
  1422. nurseID, _ := this.GetInt64("nurse")
  1423. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1424. blood_drawing, _ := this.GetInt64("blood_drawing")
  1425. schedual_type, _ := this.GetInt64("schedual_type")
  1426. bedID, _ := this.GetInt64("bed")
  1427. start_time := this.GetString("start_time")
  1428. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1429. change_nurse, _ := this.GetInt64("change_nurse")
  1430. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  1431. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  1432. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  1433. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1434. return
  1435. }
  1436. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1437. if parseStartDateErr != nil {
  1438. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1439. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1440. return
  1441. }
  1442. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1443. if parseErr != nil {
  1444. this.ErrorLog("时间解析失败:%v", parseErr)
  1445. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1446. return
  1447. }
  1448. adminUserInfo := this.GetMobileAdminUserInfo()
  1449. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  1450. if getPatientErr != nil {
  1451. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  1452. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1453. return
  1454. } else if patient == nil {
  1455. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1456. return
  1457. }
  1458. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1459. if getNurseErr != nil {
  1460. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1461. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1462. return
  1463. } else if nurse == nil {
  1464. this.ErrorLog("护士不存在")
  1465. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1466. return
  1467. }
  1468. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1469. //if getNurseErr != nil {
  1470. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  1471. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1472. // return
  1473. //} else if nurse == nil {
  1474. // this.ErrorLog("护士不存在")
  1475. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1476. // return
  1477. //}
  1478. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  1479. if getDeviceNumberErr != nil {
  1480. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1481. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1482. return
  1483. } else if deviceNumber == nil {
  1484. this.ErrorLog("床位号不存在")
  1485. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1486. return
  1487. }
  1488. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1489. if getRecordErr != nil {
  1490. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  1491. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1492. return
  1493. } else if dialysisRecord != nil {
  1494. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  1495. return
  1496. }
  1497. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1498. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1499. timeLayout := "2006-01-02 15:04:05"
  1500. loc, _ := time.LoadLocation("Local")
  1501. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1502. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1503. schedulestartTime := theStartTime.Unix()
  1504. scheduleendTime := theEndTime.Unix()
  1505. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1506. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1507. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1508. //查询该床位是否有人用了
  1509. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1510. if err == gorm.ErrRecordNotFound { //空床位
  1511. // 修改了床位逻辑
  1512. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1513. if daySchedule.ID > 0 {
  1514. daySchedule.PartitionId = deviceNumber.ZoneID
  1515. daySchedule.BedId = bedID
  1516. daySchedule.ScheduleType = schedual_type
  1517. daySchedule.UpdatedTime = time.Now().Unix()
  1518. err := service.UpdateSchedule(&daySchedule)
  1519. if err != nil {
  1520. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1521. return
  1522. }
  1523. }
  1524. } else if err == nil {
  1525. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1526. if order_err == nil {
  1527. if order.ID > 0 { //该机位被其他人占用了
  1528. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1529. return
  1530. } else {
  1531. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1532. if daySchedule.ID > 0 {
  1533. daySchedule.PartitionId = deviceNumber.ZoneID
  1534. daySchedule.BedId = bedID
  1535. daySchedule.ScheduleType = schedual_type
  1536. daySchedule.UpdatedTime = time.Now().Unix()
  1537. err := service.UpdateSchedule(&daySchedule)
  1538. if err != nil {
  1539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1540. return
  1541. }
  1542. }
  1543. }
  1544. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  1545. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1546. if daySchedule.ID > 0 {
  1547. daySchedule.PartitionId = deviceNumber.ZoneID
  1548. daySchedule.BedId = bedID
  1549. daySchedule.ScheduleType = schedual_type
  1550. daySchedule.UpdatedTime = time.Now().Unix()
  1551. err := service.UpdateSchedule(&daySchedule)
  1552. if err != nil {
  1553. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1554. return
  1555. }
  1556. }
  1557. }
  1558. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1559. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1560. return
  1561. }
  1562. } else if err != nil {
  1563. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1564. return
  1565. }
  1566. dialysisRecord = &models.DialysisOrder{
  1567. DialysisDate: recordDate.Unix(),
  1568. UserOrgId: adminUserInfo.Org.Id,
  1569. PatientId: patientID,
  1570. Stage: 1,
  1571. BedID: bedID,
  1572. StartNurse: nurseID,
  1573. Status: 1,
  1574. StartTime: startDate.Unix(),
  1575. CreatedTime: time.Now().Unix(),
  1576. UpdatedTime: time.Now().Unix(),
  1577. PunctureNurse: puncture_nurse,
  1578. Creator: adminUserInfo.AdminUser.Id,
  1579. Modifier: adminUserInfo.AdminUser.Id,
  1580. SchedualType: schedual_type,
  1581. WashpipeNurse: washpipe_nurse,
  1582. ChangeNurse: change_nurse,
  1583. DifficultPunctureNurse: difficult_puncture_nurse,
  1584. NewFistulaNurse: new_fistula_nurse,
  1585. }
  1586. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  1587. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1588. var tempdispose string
  1589. // 只针对中能建
  1590. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  1591. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  1592. }
  1593. var ultrafiltration_rate float64
  1594. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  1595. //后期预增脱水量
  1596. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  1597. fmt.Println(evaluation)
  1598. if prescription.ID > 0 {
  1599. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  1600. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  1601. if (template.TemplateId == 6 || template.TemplateId == 32) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  1602. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  1603. }
  1604. //针对医师汇
  1605. if template.TemplateId == 6 && adminUserInfo.Org.Id == 9671 {
  1606. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  1607. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  1608. }
  1609. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  1610. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  1611. }
  1612. // 只针对方济医院
  1613. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  1614. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  1615. ultrafiltration_rate = value
  1616. }
  1617. }
  1618. }
  1619. record := models.MonitoringRecord{
  1620. UserOrgId: adminUserInfo.Org.Id,
  1621. PatientId: patientID,
  1622. DialysisOrderId: dialysisRecord.ID,
  1623. MonitoringDate: schedulestartTime,
  1624. OperateTime: startDate.Unix(),
  1625. // MonitoringTime: recordTime,
  1626. MonitoringNurse: nurseID,
  1627. Dispose: tempdispose,
  1628. UltrafiltrationRate: ultrafiltration_rate,
  1629. UltrafiltrationVolume: 0,
  1630. Status: 1,
  1631. CreatedTime: time.Now().Unix(),
  1632. UpdatedTime: time.Now().Unix(),
  1633. }
  1634. //只针对广慈医院
  1635. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 {
  1636. // 查询病人是否有透前评估数据
  1637. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1638. //如果有数据就插入
  1639. if errcode == nil {
  1640. record.SystolicBloodPressure = befor.SystolicBloodPressure
  1641. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  1642. record.BreathingRate = befor.BreathingRate
  1643. record.PulseFrequency = befor.PulseFrequency
  1644. record.Temperature = befor.Temperature
  1645. }
  1646. }
  1647. // 如果当天有插入数据,则不再往透析纪录里插入数据
  1648. if newdialysisRecord.ID > 0 {
  1649. err := service.CreateMonitor(&record)
  1650. if err != nil {
  1651. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  1652. return
  1653. }
  1654. }
  1655. go func() {
  1656. ssoDomain := beego.AppConfig.String("call_domain")
  1657. api := ssoDomain + "/index/uppatient"
  1658. values := make(url.Values)
  1659. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  1660. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1661. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  1662. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  1663. http.PostForm(api, values)
  1664. }()
  1665. if createErr != nil {
  1666. this.ErrorLog("上机失败:%v", createErr)
  1667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1668. return
  1669. }
  1670. this.ServeSuccessJSON(map[string]interface{}{
  1671. "dialysis_order": newdialysisRecord,
  1672. "monitor": record,
  1673. })
  1674. }
  1675. func (c *DialysisAPIController) PostSolution() {
  1676. id, _ := c.GetInt64("patient", 0)
  1677. recordDateStr := c.GetString("record_date")
  1678. if id <= 0 {
  1679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1680. return
  1681. }
  1682. adminUserInfo := c.GetMobileAdminUserInfo()
  1683. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1684. if patient.ID == 0 {
  1685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1686. return
  1687. }
  1688. if len(recordDateStr) == 0 {
  1689. recordDateStr = time.Now().Format("2006-01-02")
  1690. }
  1691. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1692. if parseDateErr != nil {
  1693. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1695. return
  1696. }
  1697. mode_id, _ := c.GetInt64("mode_id", 0)
  1698. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1699. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1700. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1701. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1702. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1703. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1704. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1705. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1706. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1707. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1708. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1709. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1710. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1711. kalium, _ := c.GetFloat("kalium", 0)
  1712. sodium, _ := c.GetFloat("sodium", 0)
  1713. calcium, _ := c.GetFloat("calcium", 0)
  1714. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1715. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1716. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1717. glucose, _ := c.GetFloat("glucose", 0)
  1718. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1719. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1720. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1721. conductivity, _ := c.GetFloat("conductivity", 0)
  1722. remark := c.GetString("remark")
  1723. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1724. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1725. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1726. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1727. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1728. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1729. special_medicine_other := c.GetString("special_medicine_other")
  1730. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1731. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1732. blood_access, _ := c.GetInt64("blood_access", 0)
  1733. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1734. body_fluid_other := c.GetString("body_fluid_other")
  1735. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1736. niprocart, _ := c.GetInt64("niprocart", 0)
  1737. jms, _ := c.GetInt64("jms", 0)
  1738. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1739. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1740. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1741. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1742. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1743. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1744. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1745. injector, _ := c.GetInt64("injector", 0)
  1746. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1747. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1748. safe_package, _ := c.GetInt64("package", 0)
  1749. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1750. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1751. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1752. blood := c.GetString("blood")
  1753. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1754. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1755. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1756. displace_speed := c.GetString("displace_speed")
  1757. illness, _ := c.GetInt64("illness")
  1758. amylaceum := c.GetString("amylaceum")
  1759. single_time := c.GetString("single_time")
  1760. single_water := c.GetString("single_water")
  1761. replacement_flow := c.GetString("replacement_flow")
  1762. plasma_separator := c.GetString("plasma_separator")
  1763. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1764. if mode_id > 0 {
  1765. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1766. }
  1767. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1768. //
  1769. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1770. // if appRole.UserType == 3 {
  1771. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1772. // if getPermissionErr != nil {
  1773. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1774. // return
  1775. // } else if headNursePermission == nil {
  1776. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1777. // return
  1778. // }
  1779. // }
  1780. //}
  1781. prescription := models.DialysisPrescription{
  1782. UserOrgId: adminUserInfo.Org.Id,
  1783. PatientId: id,
  1784. RecordDate: recordDate.Unix(),
  1785. ModeId: mode_id,
  1786. DialysisDuration: dialysis_duration,
  1787. Dialyzer: dialyzer,
  1788. PerfusionApparatus: perfusion_apparatus,
  1789. BloodFlowVolume: blood_flow_volume,
  1790. DewaterAmount: dewater_amount,
  1791. DisplaceLiqui: displace_liqui,
  1792. ReplacementWay: replacement_way,
  1793. Anticoagulant: anticoagulant,
  1794. AnticoagulantShouji: anticoagulant_shouji,
  1795. AnticoagulantWeichi: anticoagulant_weichi,
  1796. AnticoagulantZongliang: anticoagulant_zongliang,
  1797. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1798. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1799. Kalium: kalium,
  1800. Sodium: sodium,
  1801. Calcium: calcium,
  1802. Bicarbonate: bicarbonate,
  1803. Glucose: glucose,
  1804. // DryWeight: dry_weight,
  1805. DialysateFlow: dialysate_flow,
  1806. DialysateTemperature: dialysate_temperature,
  1807. Conductivity: conductivity,
  1808. Remark: remark,
  1809. Status: 1,
  1810. CreatedTime: time.Now().Unix(),
  1811. UpdatedTime: time.Now().Unix(),
  1812. DialysisDurationMinute: dialysisDurationMinute,
  1813. DialysisDurationHour: dialysisDurationHour,
  1814. TargetUltrafiltration: targetUltrafiltration,
  1815. DialysateFormulation: dialysateFormulation,
  1816. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1817. BodyFluid: body_fluid,
  1818. SpecialMedicine: special_medicine,
  1819. SpecialMedicineOther: special_medicine_other,
  1820. DisplaceLiquiPart: displace_liqui_part,
  1821. DisplaceLiquiValue: displace_liqui_value,
  1822. BloodAccess: blood_access,
  1823. Ultrafiltration: ultrafiltration,
  1824. BodyFluidOther: body_fluid_other,
  1825. ReplacementTotal: replacement_total,
  1826. Niprocart: niprocart,
  1827. Jms: jms,
  1828. FistulaNeedleSet: fistula_needle_set,
  1829. FistulaNeedleSet16: fistula_needle_set_16,
  1830. Hemoperfusion: hemoperfusion,
  1831. DialyserSterilised: dialyser_sterilised,
  1832. Filtryzer: filtryzer,
  1833. TargetKtv: target_ktv,
  1834. Dialyzers: dialyzers,
  1835. Injector: injector,
  1836. Bloodlines: bloodlines,
  1837. TubingHemodialysis: tubing_hemodialysis,
  1838. Package: safe_package,
  1839. ALiquid: a_liquid,
  1840. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1841. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1842. Blood: blood,
  1843. DialysisDialyszers: dialysis_dialyszers,
  1844. DialysisIrrigation: dialysis_irrigation,
  1845. AntioxidantCommodityName: antioxidant_commodity_name,
  1846. DisplaceSpeed: displace_speed,
  1847. Illness: illness,
  1848. Amylaceum: amylaceum,
  1849. SingleWater: single_water,
  1850. SingleTime: single_time,
  1851. ReplacementFlow: replacement_flow,
  1852. PlasmaSeparator: plasma_separator,
  1853. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1854. }
  1855. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1856. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1857. //
  1858. if appRole.UserType == 2 || appRole.UserType == 1 {
  1859. prescription_doctor = adminUserInfo.AdminUser.Id
  1860. prescription.PrescriptionDoctor = prescription_doctor
  1861. }
  1862. if dialysisPrescription.ID == 0 { //新增
  1863. prescription.Creater = adminUserInfo.AdminUser.Id
  1864. } else { //修改
  1865. if dialysisPrescription.Creater == 0 {
  1866. prescription.Creater = adminUserInfo.AdminUser.Id
  1867. } else {
  1868. prescription.Creater = dialysisPrescription.Creater
  1869. }
  1870. //if/**/
  1871. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1872. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  1873. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1874. // if getPermissionErr != nil {
  1875. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1876. // return
  1877. // } else if headNursePermission == nil {
  1878. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1879. // return
  1880. // }
  1881. //}
  1882. //prescription.Creater = dialysisPrescription.Creater
  1883. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1884. prescription.Modifier = adminUserInfo.AdminUser.Id
  1885. prescription.ID = dialysisPrescription.ID
  1886. }
  1887. solution := models.DialysisSolution{
  1888. RegistrarsId: adminUserInfo.AdminUser.Id,
  1889. UserOrgId: adminUserInfo.Org.Id,
  1890. Doctor: prescription_doctor,
  1891. PatientId: id,
  1892. ModeId: mode_id,
  1893. DialysisDuration: dialysis_duration,
  1894. PerfusionApparatus: perfusion_apparatus,
  1895. BloodFlowVolume: blood_flow_volume,
  1896. Dewater: dewater_amount,
  1897. DisplaceLiqui: displace_liqui,
  1898. ReplacementWay: replacement_way,
  1899. Anticoagulant: anticoagulant,
  1900. AnticoagulantShouji: anticoagulant_shouji,
  1901. AnticoagulantWeichi: anticoagulant_weichi,
  1902. AnticoagulantZongliang: anticoagulant_zongliang,
  1903. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1904. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1905. Kalium: kalium,
  1906. Sodium: sodium,
  1907. Calcium: calcium,
  1908. Bicarbonate: bicarbonate,
  1909. Glucose: glucose,
  1910. // DryWeight: dry_weight,
  1911. DialysateFlow: dialysate_flow,
  1912. DialysateTemperature: dialysate_temperature,
  1913. Conductivity: conductivity,
  1914. Remark: remark,
  1915. Status: 1,
  1916. CreatedTime: time.Now().Unix(),
  1917. UpdatedTime: time.Now().Unix(),
  1918. DialysisDurationMinute: dialysisDurationMinute,
  1919. DialysisDurationHour: dialysisDurationHour,
  1920. TargetUltrafiltration: targetUltrafiltration,
  1921. DialysateFormulation: dialysateFormulation,
  1922. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1923. BodyFluid: body_fluid,
  1924. SpecialMedicine: special_medicine,
  1925. SpecialMedicineOther: special_medicine_other,
  1926. DisplaceLiquiPart: displace_liqui_part,
  1927. DisplaceLiquiValue: displace_liqui_value,
  1928. BloodAccess: blood_access,
  1929. Ultrafiltration: ultrafiltration,
  1930. BodyFluidOther: body_fluid_other,
  1931. ReplacementTotal: replacement_total,
  1932. TargetKtv: target_ktv,
  1933. DialysisDialyszers: dialysis_dialyszers,
  1934. DialysisIrrigation: dialysis_irrigation,
  1935. }
  1936. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  1937. //查询最近透析准备表里是否存在 透析器 灌流器
  1938. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1939. //
  1940. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1941. //
  1942. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1943. //if len(mation)>0{
  1944. // for _, item := range splitStr {
  1945. // for _,it := range mation{
  1946. // if(item == it.SpecificationName){
  1947. //
  1948. // //查询最近一次的透析器
  1949. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1950. //
  1951. // if errcode == gorm.ErrRecordNotFound{
  1952. // //插入数据
  1953. // prepare := models.DialysisBeforePrepare{
  1954. // UserOrgId: adminUserInfo.Org.Id,
  1955. // PatientId: id,
  1956. // RecordDate: recordDate.Unix(),
  1957. // GoodTypeId: it.GoodTypeId,
  1958. // GoodId: it.ID,
  1959. // Count: 1,
  1960. // Ctime: time.Now().Unix(),
  1961. // Creater: adminUserInfo.AdminUser.Id,
  1962. // Status:1,
  1963. //
  1964. // }
  1965. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1966. // fmt.Println("",errcode)
  1967. // }
  1968. // }
  1969. // }
  1970. //
  1971. // }
  1972. //
  1973. // for _, item := range splitIrrigation {
  1974. // for _,it := range mation{
  1975. // if(item == it.SpecificationName){
  1976. // //查询最近一次的透析器
  1977. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1978. // if errcode == gorm.ErrRecordNotFound{
  1979. // //插入数据
  1980. // prepare := models.DialysisBeforePrepare{
  1981. // UserOrgId: adminUserInfo.Org.Id,
  1982. // PatientId: id,
  1983. // RecordDate: recordDate.Unix(),
  1984. // GoodTypeId: it.GoodTypeId,
  1985. // GoodId: it.ID,
  1986. // Count: 1,
  1987. // Ctime: time.Now().Unix(),
  1988. // Creater: adminUserInfo.AdminUser.Id,
  1989. // Status:1,
  1990. //
  1991. // }
  1992. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1993. // fmt.Println(errcode)
  1994. // }
  1995. // }
  1996. // }
  1997. // }
  1998. //}
  1999. c.ServeSuccessJSON(map[string]interface{}{
  2000. "solution": &solution,
  2001. "prescription": &prescription,
  2002. })
  2003. }
  2004. func (c *DialysisAPIController) GetAcceptsAssessment() {
  2005. patient, _ := c.GetInt64("patient", 0)
  2006. adminUserInfo := c.GetMobileAdminUserInfo()
  2007. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  2008. c.ServeSuccessJSON(map[string]interface{}{
  2009. "receiveTreatmentAsses": receiveTreatmentAsses,
  2010. })
  2011. }
  2012. func (this *DialysisAPIController) PostSignInfo() {
  2013. patientID, _ := this.GetInt64("patient_id")
  2014. recordDateStr := this.GetString("date")
  2015. if patientID <= 0 {
  2016. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2017. return
  2018. }
  2019. if len(recordDateStr) == 0 {
  2020. recordDateStr = time.Now().Format("2006-01-02")
  2021. }
  2022. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2023. if parseDateErr != nil {
  2024. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2025. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2026. return
  2027. }
  2028. adminInfo := this.GetMobileAdminUserInfo()
  2029. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  2030. if err != nil {
  2031. this.ErrorLog("签名失败:%v", err)
  2032. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2033. return
  2034. }
  2035. this.ServeSuccessJSON(map[string]interface{}{
  2036. "doctor_id": adminInfo.AdminUser.Id,
  2037. })
  2038. }
  2039. func (this *DialysisAPIController) GetLastMonitorRecord() {
  2040. patientID, _ := this.GetInt64("patient_id")
  2041. adminInfo := this.GetMobileAdminUserInfo()
  2042. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  2043. this.ServeSuccessJSON(map[string]interface{}{
  2044. "monitor": record,
  2045. })
  2046. }
  2047. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  2048. thisTime := time.Now()
  2049. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  2050. timeLayout := "2006-01-02 15:04:05"
  2051. loc, _ := time.LoadLocation("Local")
  2052. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2053. theAssessmentDateTime := theStartTime.Unix()
  2054. patientID, _ := this.GetInt64("patient_id")
  2055. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  2056. adminInfo := this.GetMobileAdminUserInfo()
  2057. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  2058. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  2059. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  2060. var ultrafiltration_rate float64
  2061. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  2062. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  2063. fmt.Println(evaluation)
  2064. if prescription.ID > 0 {
  2065. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2066. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2067. if template.TemplateId == 6 && adminInfo.Org.Id != 9538 {
  2068. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2069. record.UltrafiltrationRate = ultrafiltration_rate
  2070. }
  2071. //if template.TemplateId == 6 && adminInfo.Org.Id ==9671{
  2072. // dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2073. // ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2074. // record.UltrafiltrationRate = ultrafiltration_rate
  2075. //}
  2076. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  2077. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  2078. record.UltrafiltrationRate = ultrafiltration_rate
  2079. }
  2080. if template.TemplateId == 20 || template.TemplateId == 22 {
  2081. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2082. record.UltrafiltrationRate = ultrafiltration_rate
  2083. }
  2084. // 只针对方济医院
  2085. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  2086. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2087. ultrafiltration_rate = value
  2088. record.UltrafiltrationRate = ultrafiltration_rate
  2089. }
  2090. }
  2091. }
  2092. // record.UltrafiltrationRate = ultrafiltration_rate
  2093. record.UltrafiltrationVolume = 0
  2094. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 { //adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535
  2095. if ultrafiltration_rate > 0 {
  2096. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  2097. record.UltrafiltrationVolume = value
  2098. }
  2099. }
  2100. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 { //adminInfo.Org.Id == 9538
  2101. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  2102. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  2103. record.UltrafiltrationVolume = ultrafiltration_volume
  2104. }
  2105. }
  2106. this.ServeSuccessJSON(map[string]interface{}{
  2107. "monitor": record,
  2108. })
  2109. }
  2110. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  2111. record_id, _ := this.GetInt64("id")
  2112. nurseID, _ := this.GetInt64("nurse")
  2113. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2114. bedID, _ := this.GetInt64("bed")
  2115. start_time := this.GetString("start_time")
  2116. schedual_type, _ := this.GetInt64("schedual_type")
  2117. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2118. change_nurse, _ := this.GetInt64("change_nurse")
  2119. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2120. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2121. if record_id == 0 {
  2122. this.ErrorLog("id:%v", record_id)
  2123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2124. return
  2125. }
  2126. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2127. if parseStartDateErr != nil {
  2128. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2129. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2130. return
  2131. }
  2132. adminUserInfo := this.GetMobileAdminUserInfo()
  2133. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2134. if getNurseErr != nil {
  2135. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2136. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2137. return
  2138. } else if nurse == nil {
  2139. this.ErrorLog("护士不存在")
  2140. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2141. return
  2142. }
  2143. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2144. //if getNurseErr != nil {
  2145. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  2146. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2147. // return
  2148. //} else if nurse == nil {
  2149. // this.ErrorLog("护士不存在")
  2150. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2151. // return
  2152. //}
  2153. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2154. if getDeviceNumberErr != nil {
  2155. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2156. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2157. return
  2158. } else if deviceNumber == nil {
  2159. this.ErrorLog("床位号不存在")
  2160. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2161. return
  2162. }
  2163. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  2164. //
  2165. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  2166. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2167. // if getPermissionErr != nil {
  2168. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2169. // return
  2170. // } else if headNursePermission == nil {
  2171. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2172. // return
  2173. // }
  2174. //}
  2175. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2176. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2177. timeLayout := "2006-01-02 15:04:05"
  2178. loc, _ := time.LoadLocation("Local")
  2179. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2180. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2181. schedulestartTime := theStartTime.Unix()
  2182. scheduleendTime := theEndTime.Unix()
  2183. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2184. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2185. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2186. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  2187. if err == gorm.ErrRecordNotFound { //空床位
  2188. // 修改了床位逻辑
  2189. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2190. if daySchedule.ID > 0 {
  2191. daySchedule.BedId = bedID
  2192. daySchedule.PartitionId = deviceNumber.ZoneID
  2193. daySchedule.ScheduleType = schedual_type
  2194. daySchedule.UpdatedTime = time.Now().Unix()
  2195. err := service.UpdateSchedule(&daySchedule)
  2196. if err != nil {
  2197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2198. return
  2199. }
  2200. }
  2201. } else if err == nil {
  2202. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2203. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2204. if daySchedule.ID > 0 {
  2205. daySchedule.BedId = bedID
  2206. daySchedule.PartitionId = deviceNumber.ZoneID
  2207. daySchedule.ScheduleType = schedual_type
  2208. daySchedule.UpdatedTime = time.Now().Unix()
  2209. err := service.UpdateSchedule(&daySchedule)
  2210. if err != nil {
  2211. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2212. return
  2213. }
  2214. }
  2215. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2216. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2217. return
  2218. }
  2219. } else if err != nil {
  2220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2221. return
  2222. }
  2223. }
  2224. dialysisRecord := &models.DialysisOrder{
  2225. ID: record_id,
  2226. UserOrgId: adminUserInfo.Org.Id,
  2227. BedID: bedID,
  2228. StartNurse: nurseID,
  2229. StartTime: startDate.Unix(),
  2230. PunctureNurse: puncture_nurse,
  2231. Creator: adminUserInfo.AdminUser.Id,
  2232. Modifier: adminUserInfo.AdminUser.Id,
  2233. WashpipeNurse: washpipe_nurse,
  2234. SchedualType: schedual_type,
  2235. ChangeNurse: change_nurse,
  2236. DifficultPunctureNurse: difficult_puncture_nurse,
  2237. NewFistulaNurse: new_fistula_nurse,
  2238. }
  2239. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  2240. if updateErr != nil {
  2241. this.ErrorLog("修改上机失败:%v", updateErr)
  2242. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2243. return
  2244. }
  2245. if updateErr == nil {
  2246. if tempDialysisRecord.Stage == 2 {
  2247. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  2248. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2249. fmt.Println(value)
  2250. a, b := math.Modf(value)
  2251. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2252. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2253. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  2254. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  2255. if updateAssessmentErr != nil {
  2256. utils.ErrorLog("%v", updateAssessmentErr)
  2257. }
  2258. }
  2259. }
  2260. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2261. this.ServeSuccessJSON(map[string]interface{}{
  2262. "dialysis_order": dialysisRecords,
  2263. })
  2264. }
  2265. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  2266. record_id, _ := c.GetInt64("id")
  2267. nurseID, _ := c.GetInt64("nurse")
  2268. end_time := c.GetString("end_time")
  2269. if record_id <= 0 || nurseID <= 0 {
  2270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2271. return
  2272. }
  2273. adminUserInfo := c.GetMobileAdminUserInfo()
  2274. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2275. if getNurseErr != nil {
  2276. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2278. return
  2279. } else if nurse == nil {
  2280. c.ErrorLog("护士不存在")
  2281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2282. return
  2283. }
  2284. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2285. if parseEndDateErr != nil {
  2286. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2288. return
  2289. }
  2290. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  2291. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  2292. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2293. // if getPermissionErr != nil {
  2294. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2295. // return
  2296. // } else if headNursePermission == nil {
  2297. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2298. // return
  2299. // }
  2300. //}
  2301. dialysisRecord := &models.DialysisOrder{
  2302. ID: record_id,
  2303. UserOrgId: adminUserInfo.Org.Id,
  2304. EndTime: endDate.Unix(),
  2305. FinishNurse: nurseID,
  2306. FinishModifier: adminUserInfo.AdminUser.Id,
  2307. }
  2308. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  2309. if updateErr != nil {
  2310. c.ErrorLog("修改下机失败:%v", updateErr)
  2311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2312. return
  2313. }
  2314. if updateErr == nil {
  2315. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  2316. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2317. a, b := math.Modf(value)
  2318. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2319. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2320. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  2321. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  2322. if updateAssessmentErr != nil {
  2323. utils.ErrorLog("%v", updateAssessmentErr)
  2324. }
  2325. }
  2326. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2327. c.ServeSuccessJSON(map[string]interface{}{
  2328. "dialysis_order": dialysisRecords,
  2329. })
  2330. }
  2331. func (c *DialysisAPIController) GetLongAdvice() {
  2332. patient_id, _ := c.GetInt64("id")
  2333. adminUserInfo := c.GetMobileAdminUserInfo()
  2334. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  2335. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  2336. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  2337. c.ServeSuccessJSON(map[string]interface{}{
  2338. "status": "1",
  2339. })
  2340. return
  2341. } else { //开启推送提醒
  2342. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  2343. var advice_three []*models.DoctorAdvice
  2344. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  2345. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id)
  2346. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id)
  2347. for _, advice := range advices {
  2348. if advice.FrequencyType == 3 {
  2349. t := time.Now()
  2350. week := int(t.Weekday())
  2351. fmt.Println(t.Weekday())
  2352. fmt.Println(week)
  2353. switch week {
  2354. case 1:
  2355. if strings.Index(advice.WeekDay, "周一") == -1 {
  2356. advice_three = append(advice_three, advice)
  2357. }
  2358. break
  2359. case 2:
  2360. if strings.Index(advice.WeekDay, "周二") == -1 {
  2361. advice_three = append(advice_three, advice)
  2362. }
  2363. break
  2364. case 3:
  2365. if strings.Index(advice.WeekDay, "周三") == -1 {
  2366. advice_three = append(advice_three, advice)
  2367. }
  2368. break
  2369. case 4:
  2370. if strings.Index(advice.WeekDay, "周四") == -1 {
  2371. advice_three = append(advice_three, advice)
  2372. }
  2373. break
  2374. case 5:
  2375. if strings.Index(advice.WeekDay, "周五") == -1 {
  2376. advice_three = append(advice_three, advice)
  2377. }
  2378. break
  2379. case 6:
  2380. if strings.Index(advice.WeekDay, "周六") == -1 {
  2381. advice_three = append(advice_three, advice)
  2382. }
  2383. break
  2384. case 0:
  2385. if strings.Index(advice.WeekDay, "周日") == -1 {
  2386. advice_three = append(advice_three, advice)
  2387. }
  2388. break
  2389. }
  2390. }
  2391. }
  2392. for _, advice := range advices_two {
  2393. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  2394. now := p.Unix()
  2395. dayStr := strconv.FormatInt(advice.DayCount, 10)
  2396. dayStr2 := "-" + dayStr
  2397. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  2398. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  2399. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  2400. for _, ad := range advices {
  2401. advice_three = append(advice_three, ad)
  2402. }
  2403. }
  2404. if err == nil {
  2405. c.ServeSuccessJSON(map[string]interface{}{
  2406. "status": "2",
  2407. "advices": advices,
  2408. "advices_two": RemoveRepeatedElement(advice_three),
  2409. "is_open_remind": config.IsOpenRemind,
  2410. })
  2411. }
  2412. }
  2413. }
  2414. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  2415. newArr = make([]*models.DoctorAdvice, 0)
  2416. for i := 0; i < len(arr); i++ {
  2417. repeat := false
  2418. for j := i + 1; j < len(arr); j++ {
  2419. if arr[i].ID == arr[j].ID {
  2420. repeat = true
  2421. break
  2422. }
  2423. }
  2424. if !repeat {
  2425. newArr = append(newArr, arr[i])
  2426. }
  2427. }
  2428. return
  2429. }
  2430. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  2431. patient, _ := c.GetInt64("id", 0)
  2432. groupNo, _ := c.GetInt64("groupno", 0)
  2433. if patient <= 0 {
  2434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2435. return
  2436. }
  2437. adminUserInfo := c.GetMobileAdminUserInfo()
  2438. dataBody := make(map[string]interface{}, 0)
  2439. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2440. if err != nil {
  2441. utils.ErrorLog(err.Error())
  2442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2443. return
  2444. }
  2445. utils.ErrorLog("%v", dataBody)
  2446. timeLayout := "2006-01-02 15:04"
  2447. loc, _ := time.LoadLocation("Local")
  2448. timeLayout2 := "2006-01-02"
  2449. loc2, _ := time.LoadLocation("Local")
  2450. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2451. utils.ErrorLog("advice_type")
  2452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2453. return
  2454. }
  2455. adviceType := int64(2)
  2456. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2457. utils.ErrorLog("advice_date")
  2458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2459. return
  2460. }
  2461. adviceDate, _ := dataBody["advice_date"].(string)
  2462. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  2463. AdviceDate := theTime.Unix()
  2464. RecordDate := theTime.Unix()
  2465. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2466. utils.ErrorLog("start_time")
  2467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2468. return
  2469. }
  2470. startTime, _ := dataBody["start_time"].(string)
  2471. if len(startTime) == 0 {
  2472. utils.ErrorLog("len(start_time) == 0")
  2473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2474. return
  2475. }
  2476. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  2477. if err != nil {
  2478. utils.ErrorLog(err.Error())
  2479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2480. return
  2481. }
  2482. StartTime := theTime.Unix()
  2483. Remark := ""
  2484. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2485. remark, _ := dataBody["remark"].(string)
  2486. Remark = remark
  2487. }
  2488. var advices []*models.GroupAdvice
  2489. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  2490. utils.ErrorLog("advices")
  2491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2492. return
  2493. }
  2494. adviceNames := dataBody["advices"].([]interface{})
  2495. for _, adviceNameMap := range adviceNames {
  2496. adviceNameM := adviceNameMap.(map[string]interface{})
  2497. var advice models.GroupAdvice
  2498. advice.Remark = Remark
  2499. advice.AdviceType = adviceType
  2500. advice.StartTime = StartTime
  2501. advice.AdviceDate = AdviceDate
  2502. advice.RecordDate = RecordDate
  2503. advice.Status = 1
  2504. advice.CreatedTime = time.Now().Unix()
  2505. advice.UpdatedTime = time.Now().Unix()
  2506. advice.StopState = 2
  2507. advice.ExecutionState = 2
  2508. advice.UserOrgId = adminUserInfo.Org.Id
  2509. advice.PatientId = patient
  2510. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2511. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  2512. utils.ErrorLog("advice_name")
  2513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2514. return
  2515. }
  2516. adviceName, _ := adviceNameM["advice_name"].(string)
  2517. if len(adviceName) == 0 {
  2518. utils.ErrorLog("len(advice_name) == 0")
  2519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2520. return
  2521. }
  2522. advice.AdviceName = adviceName
  2523. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  2524. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  2525. advice.DrugSpec = drugSpec
  2526. }
  2527. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  2528. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  2529. advice.AdviceDesc = adviceDesc
  2530. }
  2531. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  2532. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  2533. advice.DrugSpecUnit = drugSpecUnit
  2534. }
  2535. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  2536. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  2537. // advice.SingleDose = singleDose
  2538. //}
  2539. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  2540. //single_dose := int64(adviceNameM["single_dose"].(float64))
  2541. advice.SingleDose = adviceNameM["single_dose"].(float64)
  2542. }
  2543. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  2544. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  2545. advice.SingleDoseUnit = singleDoseUnit
  2546. }
  2547. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  2548. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  2549. // advice.PrescribingNumber = prescribingNumber
  2550. //}
  2551. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  2552. //single_dose := int64(adviceNameM["single_dose"].(float64))
  2553. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  2554. }
  2555. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  2556. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  2557. advice.PrescribingNumberUnit = prescribingNumberUnit
  2558. }
  2559. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  2560. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  2561. advice.DeliveryWay = deliveryWay
  2562. }
  2563. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  2564. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2565. advice.ExecutionFrequency = executionFrequency
  2566. }
  2567. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  2568. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  2569. advice.FrequencyType = frequency_type
  2570. }
  2571. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  2572. day_count := int64(adviceNameM["day_count"].(float64))
  2573. advice.DayCount = day_count
  2574. }
  2575. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  2576. week_day, _ := adviceNameM["week_day"].(string)
  2577. advice.WeekDay = week_day
  2578. }
  2579. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  2580. way := int64(adviceNameM["way"].(float64))
  2581. advice.Way = way
  2582. }
  2583. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  2584. drug_id := int64(adviceNameM["drug_id"].(float64))
  2585. advice.DrugId = drug_id
  2586. }
  2587. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  2588. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  2589. advice.DrugNameId = drug_name_id
  2590. }
  2591. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  2592. template_id, _ := adviceNameM["template_id"].(string)
  2593. advice.TemplateId = template_id
  2594. }
  2595. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  2596. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2597. advice.ExecutionFrequency = executionFrequency
  2598. }
  2599. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  2600. children := adviceNameM["child"].([]interface{})
  2601. if len(children) > 0 {
  2602. for _, childrenMap := range children {
  2603. childMap := childrenMap.(map[string]interface{})
  2604. var child models.GroupAdvice
  2605. child.Remark = Remark
  2606. child.AdviceType = adviceType
  2607. child.StartTime = StartTime
  2608. child.AdviceDate = AdviceDate
  2609. child.RecordDate = RecordDate
  2610. child.Status = 1
  2611. child.CreatedTime = time.Now().Unix()
  2612. child.UpdatedTime = time.Now().Unix()
  2613. child.StopState = 2
  2614. child.ExecutionState = 2
  2615. child.UserOrgId = adminUserInfo.Org.Id
  2616. child.PatientId = patient
  2617. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  2618. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  2619. utils.ErrorLog("child advice_name")
  2620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2621. return
  2622. }
  2623. childAdviceName, _ := childMap["advice_name"].(string)
  2624. if len(childAdviceName) == 0 {
  2625. utils.ErrorLog("len(child advice_name) == 0")
  2626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2627. return
  2628. }
  2629. child.AdviceName = childAdviceName
  2630. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  2631. childAdviceDesc, _ := childMap["advice_desc"].(string)
  2632. child.AdviceDesc = childAdviceDesc
  2633. }
  2634. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  2635. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  2636. child.DrugSpec = childDrugSpec
  2637. }
  2638. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  2639. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  2640. child.DrugSpecUnit = childDrugSpecUnit
  2641. }
  2642. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  2643. child.SingleDose = childMap["single_dose"].(float64)
  2644. }
  2645. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  2646. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  2647. child.SingleDoseUnit = childSingleDoseUnit
  2648. }
  2649. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  2650. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  2651. }
  2652. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  2653. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  2654. child.PrescribingNumberUnit = childPrescribingNumberUnit
  2655. }
  2656. child.DeliveryWay = advice.DeliveryWay
  2657. child.ExecutionFrequency = advice.ExecutionFrequency
  2658. advice.Children = append(advice.Children, &child)
  2659. }
  2660. }
  2661. }
  2662. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  2663. if temp_advice.ID == 0 {
  2664. advices = append(advices, &advice)
  2665. }
  2666. }
  2667. if len(advices) > 0 {
  2668. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  2669. if err != nil {
  2670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2671. return
  2672. }
  2673. c.ServeSuccessJSON(map[string]interface{}{
  2674. "msg": "ok",
  2675. "advices": list,
  2676. })
  2677. } else {
  2678. c.ServeSuccessJSON(map[string]interface{}{
  2679. "msg": "ok",
  2680. })
  2681. }
  2682. return
  2683. }
  2684. func (c *DialysisAPIController) UploadDryWeight() {
  2685. patient_id, _ := c.GetInt64("id")
  2686. dry_weight, _ := c.GetFloat("dry_weight")
  2687. doctor_id, _ := c.GetInt64("doctor_id")
  2688. remark := c.GetString("remark")
  2689. adminUserInfo := c.GetMobileAdminUserInfo()
  2690. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  2691. if err == gorm.ErrRecordNotFound {
  2692. dryWeight := &models.SgjPatientDryweight{
  2693. PatientId: patient_id,
  2694. DryWeight: dry_weight,
  2695. Remakes: remark,
  2696. Ctime: time.Now().Unix(),
  2697. Mtime: time.Now().Unix(),
  2698. Creator: doctor_id,
  2699. Status: 1,
  2700. UserOrgId: adminUserInfo.Org.Id,
  2701. AdjustedValue: "/",
  2702. UserId: adminUserInfo.AdminUser.Id,
  2703. }
  2704. createErr := service.CreatePatientWeightAdjust(dryWeight)
  2705. if createErr == nil {
  2706. c.ServeSuccessJSON(map[string]interface{}{
  2707. "msg": "提交成功",
  2708. "weight": dryWeight,
  2709. })
  2710. }
  2711. } else {
  2712. dryWeight := &models.SgjPatientDryweight{
  2713. PatientId: patient_id,
  2714. DryWeight: dry_weight,
  2715. Remakes: remark,
  2716. Ctime: time.Now().Unix(),
  2717. Mtime: time.Now().Unix(),
  2718. Creator: doctor_id,
  2719. Status: 1,
  2720. UserOrgId: adminUserInfo.Org.Id,
  2721. AdjustedValue: "/",
  2722. UserId: adminUserInfo.AdminUser.Id,
  2723. }
  2724. var value float64
  2725. value = dry_weight - weightAdjust.DryWeight
  2726. if value < 0 {
  2727. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  2728. } else if value == 0 {
  2729. dryWeight.AdjustedValue = "/"
  2730. } else if value > 0 {
  2731. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  2732. }
  2733. createErr := service.CreatePatientWeightAdjust(dryWeight)
  2734. if createErr == nil {
  2735. c.ServeSuccessJSON(map[string]interface{}{
  2736. "msg": "提交成功",
  2737. "weight": dryWeight,
  2738. })
  2739. }
  2740. }
  2741. }
  2742. func (c *DialysisAPIController) GetSolution() {
  2743. patient_id, _ := c.GetInt64("patient_id")
  2744. mode_id, _ := c.GetInt64("mode_id")
  2745. adminUserInfo := c.GetMobileAdminUserInfo()
  2746. solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  2747. prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  2748. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, mode_id)
  2749. if err != nil {
  2750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2751. return
  2752. }
  2753. c.ServeSuccessJSON(map[string]interface{}{
  2754. "solution": solution,
  2755. "prescription": prescription,
  2756. "system_prescription": system_prescription,
  2757. })
  2758. }
  2759. func (c *DialysisAPIController) GetSchedule() {
  2760. schedual_type, _ := c.GetInt64("schedual_type")
  2761. adminUserInfo := c.GetMobileAdminUserInfo()
  2762. //timeLayout := "2006-01-02 15:04:05"
  2763. //
  2764. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  2765. //loc, _ := time.LoadLocation("Local")
  2766. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  2767. //scheduleTime := theStartTime.Unix()
  2768. scheduleTime, _ := c.GetInt64("record_date")
  2769. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  2770. c.ServeSuccessJSON(map[string]interface{}{
  2771. "number": deviceNumber,
  2772. })
  2773. }
  2774. func (c *DialysisAPIController) GetPatientId() {
  2775. id, _ := c.GetInt64("id")
  2776. patientId, _ := service.GetPatientId(id)
  2777. //获取该患者的所有传染病
  2778. list, _ := service.GetPatientInfectious(id)
  2779. c.ServeSuccessJSON(map[string]interface{}{
  2780. "patient": patientId,
  2781. "infectioulist": list,
  2782. })
  2783. }
  2784. func (this *DialysisAPIController) GetDialysisSchedule() {
  2785. schedualDate := this.GetString("date")
  2786. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  2787. if parseDateErr != nil {
  2788. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2789. return
  2790. }
  2791. adminInfo := this.GetMobileAdminUserInfo()
  2792. orgID := adminInfo.Org.Id
  2793. redis := service.RedisClient()
  2794. defer redis.Close()
  2795. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  2796. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  2797. if len(scheduals) > 0 {
  2798. //缓存数据
  2799. scheduals_json, err := json.Marshal(scheduals)
  2800. if err == nil {
  2801. redis.Set(key, scheduals_json, time.Second*30)
  2802. }
  2803. }
  2804. this.ServeSuccessJSON(map[string]interface{}{
  2805. "scheduals": scheduals,
  2806. })
  2807. }
  2808. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  2809. change_type, _ := this.GetInt64("type", 0)
  2810. record_date := this.GetString("record_time")
  2811. patient_id, _ := this.GetInt64("patient_id", 0)
  2812. timeLayout := "2006-01-02"
  2813. loc, _ := time.LoadLocation("Local")
  2814. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2815. record_time := theAdviceRecordTime.Unix()
  2816. adminUserInfo := this.GetMobileAdminUserInfo()
  2817. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  2818. if err == nil {
  2819. if len(advices) == 0 {
  2820. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  2821. return
  2822. } else {
  2823. this.ServeSuccessJSON(map[string]interface{}{
  2824. "advices": advices,
  2825. "schedule": sch,
  2826. })
  2827. return
  2828. }
  2829. } else {
  2830. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2831. return
  2832. }
  2833. }
  2834. func (c *DialysisAPIController) CreateConsumables() {
  2835. record_date := c.GetString("record_time")
  2836. patient_id, _ := c.GetInt64("patient_id", 0)
  2837. adminUser := c.GetMobileAdminUserInfo()
  2838. timeLayout := "2006-01-02"
  2839. loc, _ := time.LoadLocation("Local")
  2840. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2841. record_time := theRecordTime.Unix()
  2842. dataBody := make(map[string]interface{}, 0)
  2843. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2844. if err != nil {
  2845. utils.ErrorLog(err.Error())
  2846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2847. return
  2848. }
  2849. var beforePrepares []*models.DialysisBeforePrepare
  2850. var updateBeforePrepares []*models.DialysisBeforePrepare
  2851. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  2852. goods, _ := dataBody["goods"].([]interface{})
  2853. if len(goods) > 0 {
  2854. for _, item := range goods {
  2855. items := item.(map[string]interface{})
  2856. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2857. utils.ErrorLog("good_id")
  2858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2859. return
  2860. }
  2861. good_id := int64(items["good_id"].(float64))
  2862. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2863. utils.ErrorLog("good_type_id")
  2864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2865. return
  2866. }
  2867. good_type_id := int64(items["good_type_id"].(float64))
  2868. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2869. utils.ErrorLog("count")
  2870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2871. return
  2872. }
  2873. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2874. commdity_code := items["commdity_code"].(string)
  2875. adminUser := c.GetMobileAdminUserInfo()
  2876. prepare := &models.DialysisBeforePrepare{
  2877. UserOrgId: adminUser.Org.Id,
  2878. PatientId: patient_id,
  2879. RecordDate: record_time,
  2880. GoodId: good_id,
  2881. GoodTypeId: good_type_id,
  2882. Count: count,
  2883. Ctime: time.Now().Unix(),
  2884. Mtime: time.Now().Unix(),
  2885. Creater: adminUser.AdminUser.Id,
  2886. Modifier: 0,
  2887. CommdityCode: commdity_code,
  2888. }
  2889. //问题点
  2890. record_count := service.FindDialysisBeforePrepare(prepare.PatientId, prepare.GoodId, prepare.GoodTypeId, adminUser.Org.Id, record_time)
  2891. if record_count == 0 {
  2892. beforePrepares = append(beforePrepares, prepare)
  2893. }
  2894. }
  2895. }
  2896. }
  2897. if len(beforePrepares) > 0 {
  2898. service.CreateDialysisBeforePrepare(beforePrepares)
  2899. }
  2900. var errs error
  2901. if dataBody["update_goods"] != nil && reflect.TypeOf(dataBody["update_goods"]).String() == "[]interface {}" {
  2902. goods, _ := dataBody["update_goods"].([]interface{})
  2903. if len(goods) > 0 {
  2904. for _, item := range goods {
  2905. items := item.(map[string]interface{})
  2906. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  2907. utils.ErrorLog("record_time")
  2908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2909. return
  2910. }
  2911. record_time := int64(items["record_time"].(float64))
  2912. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2913. utils.ErrorLog("id")
  2914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2915. return
  2916. }
  2917. id := int64(items["id"].(float64))
  2918. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  2919. utils.ErrorLog("patient_id")
  2920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2921. return
  2922. }
  2923. patient_id := int64(items["patient_id"].(float64))
  2924. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  2925. utils.ErrorLog("creater")
  2926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2927. return
  2928. }
  2929. creater := int64(items["creater"].(float64))
  2930. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2931. utils.ErrorLog("good_id")
  2932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2933. return
  2934. }
  2935. good_id := int64(items["good_id"].(float64))
  2936. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2937. utils.ErrorLog("good_type_id")
  2938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2939. return
  2940. }
  2941. good_type_id := int64(items["good_type_id"].(float64))
  2942. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2943. utils.ErrorLog("count")
  2944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2945. return
  2946. }
  2947. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2948. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  2949. utils.ErrorLog("ctime")
  2950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2951. return
  2952. }
  2953. ctime := int64(items["ctime"].(float64))
  2954. commdity_code := items["commdity_code"].(string)
  2955. prepare := &models.DialysisBeforePrepare{
  2956. ID: id,
  2957. UserOrgId: adminUser.Org.Id,
  2958. PatientId: patient_id,
  2959. RecordDate: record_time,
  2960. GoodId: good_id,
  2961. GoodTypeId: good_type_id,
  2962. Count: count,
  2963. Ctime: ctime,
  2964. Mtime: time.Now().Unix(),
  2965. Creater: creater,
  2966. Modifier: adminUser.AdminUser.Id,
  2967. Status: 1,
  2968. CommdityCode: commdity_code,
  2969. }
  2970. updateBeforePrepares = append(updateBeforePrepares, prepare)
  2971. }
  2972. }
  2973. //去重
  2974. updateBeforePrepares = RemoveRepeatedGood(updateBeforePrepares)
  2975. if len(updateBeforePrepares) > 0 {
  2976. for _, item := range updateBeforePrepares {
  2977. errs = service.UpdateDialysisBeforePrepareTwo(item)
  2978. }
  2979. }
  2980. }
  2981. if errs == nil {
  2982. c.ServeSuccessJSON(map[string]interface{}{
  2983. "msg": "提交成功",
  2984. })
  2985. return
  2986. } else {
  2987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2988. return
  2989. }
  2990. }
  2991. func (c *DialysisAPIController) CreateStockOutInfo() {
  2992. patient_id, _ := c.GetInt64("patient_id", 0)
  2993. record_date := c.GetString("record_time")
  2994. if patient_id <= 0 {
  2995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2996. return
  2997. }
  2998. adminInfo := c.GetMobileAdminUserInfo()
  2999. timeLayout := "2006-01-02"
  3000. loc, _ := time.LoadLocation("Local")
  3001. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3002. record_time := theRecordTime.Unix()
  3003. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  3004. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  3005. consumables = RemoveRepeatedGood(consumables)
  3006. if record.IsOpen == 1 {
  3007. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  3008. if err == gorm.ErrRecordNotFound {
  3009. //没有记录,则创建出库单
  3010. timeStr := time.Now().Format("2006-01-02")
  3011. timeArr := strings.Split(timeStr, "-")
  3012. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  3013. total = total + 1
  3014. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3015. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3016. number = number + total
  3017. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3018. creater := adminInfo.AdminUser.Id
  3019. warehouseOut := models.WarehouseOut{
  3020. WarehouseOutOrderNumber: warehousing_out_order,
  3021. OperationTime: time.Now().Unix(),
  3022. OrgId: adminInfo.Org.Id,
  3023. Creater: creater,
  3024. Ctime: time.Now().Unix(),
  3025. Status: 1,
  3026. WarehouseOutTime: record_time,
  3027. Dealer: 0,
  3028. Manufacturer: 0,
  3029. Type: 1,
  3030. IsSys: 1,
  3031. }
  3032. err := service.AddSigleWarehouseOut(&warehouseOut)
  3033. if err != nil {
  3034. utils.TraceLog("创建出库单失败 err = %v", err)
  3035. } else {
  3036. for _, item := range consumables {
  3037. if item.Count > 0 {
  3038. warehouseOutInfo := &models.WarehouseOutInfo{
  3039. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  3040. WarehouseOutId: warehouseOut.ID,
  3041. Status: 1,
  3042. Ctime: time.Now().Unix(),
  3043. Remark: "",
  3044. OrgId: adminInfo.Org.Id,
  3045. Type: 1,
  3046. Manufacturer: 0,
  3047. Dealer: 0,
  3048. IsSys: 1,
  3049. SysRecordTime: record_time,
  3050. GoodTypeId: item.GoodTypeId,
  3051. GoodId: item.GoodId,
  3052. }
  3053. warehouseOutInfo.Count = item.Count
  3054. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3055. warehouseOutInfo.Price = stockInInfo.Price
  3056. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3057. if err == nil {
  3058. details := &models.AutomaticReduceDetail{
  3059. WarehouseOutId: warehouseOutInfo.ID,
  3060. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3061. PatientId: patient_id,
  3062. Ctime: time.Now().Unix(),
  3063. Mtime: time.Now().Unix(),
  3064. Status: 1,
  3065. RecordTime: record_time,
  3066. OrgId: adminInfo.Org.Id,
  3067. GoodId: item.GoodId,
  3068. GoodTypeId: item.GoodTypeId,
  3069. Count: item.Count,
  3070. }
  3071. service.AddSigleAutoReduceRecordInfo(details)
  3072. }
  3073. }
  3074. }
  3075. }
  3076. } else if err == nil {
  3077. for _, item := range consumables {
  3078. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  3079. if err == gorm.ErrRecordNotFound {
  3080. warehouseOutInfo := &models.WarehouseOutInfo{
  3081. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3082. WarehouseOutId: out.ID,
  3083. Status: 1,
  3084. Ctime: time.Now().Unix(),
  3085. Remark: "",
  3086. OrgId: adminInfo.Org.Id,
  3087. Type: 1,
  3088. Manufacturer: 0,
  3089. Dealer: 0,
  3090. IsSys: 1,
  3091. SysRecordTime: record_time,
  3092. }
  3093. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3094. warehouseOutInfo.Price = stockInInfo.Price
  3095. warehouseOutInfo.GoodId = item.GoodId
  3096. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  3097. warehouseOutInfo.Count = item.Count
  3098. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3099. if err == nil {
  3100. details := &models.AutomaticReduceDetail{
  3101. WarehouseOutId: warehouseOutInfo.ID,
  3102. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3103. PatientId: patient_id,
  3104. Ctime: time.Now().Unix(),
  3105. Mtime: time.Now().Unix(),
  3106. Status: 1,
  3107. RecordTime: record_time,
  3108. OrgId: adminInfo.Org.Id,
  3109. GoodId: item.GoodId,
  3110. GoodTypeId: item.GoodTypeId,
  3111. Count: item.Count,
  3112. }
  3113. service.AddSigleAutoReduceRecordInfo(details)
  3114. }
  3115. } else if err == nil { //记录存在,则将增加数量
  3116. if outInfo.ID > 0 {
  3117. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  3118. }
  3119. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  3120. if count == 0 {
  3121. details := &models.AutomaticReduceDetail{
  3122. WarehouseOutId: outInfo.ID,
  3123. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3124. PatientId: patient_id,
  3125. Ctime: time.Now().Unix(),
  3126. Mtime: time.Now().Unix(),
  3127. Status: 1,
  3128. RecordTime: record_time,
  3129. OrgId: adminInfo.Org.Id,
  3130. GoodId: item.GoodId,
  3131. GoodTypeId: item.GoodTypeId,
  3132. Count: item.Count,
  3133. }
  3134. service.AddSigleAutoReduceRecordInfo(details)
  3135. } else if count == 1 {
  3136. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  3137. }
  3138. }
  3139. }
  3140. }
  3141. c.ServeSuccessJSON(map[string]interface{}{
  3142. "msg": "提交成功",
  3143. })
  3144. return
  3145. } else {
  3146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  3147. return
  3148. }
  3149. }
  3150. func (c *DialysisAPIController) EditConsumables() {
  3151. patient_id, _ := c.GetInt64("patient_id", 0)
  3152. record_date := c.GetString("record_time")
  3153. if patient_id <= 0 {
  3154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3155. return
  3156. }
  3157. adminInfo := c.GetMobileAdminUserInfo()
  3158. timeLayout := "2006-01-02"
  3159. loc, _ := time.LoadLocation("Local")
  3160. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3161. record_time := theRecordTime.Unix()
  3162. dataBody := make(map[string]interface{}, 0)
  3163. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3164. if err != nil {
  3165. utils.ErrorLog(err.Error())
  3166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3167. return
  3168. }
  3169. var beforePrepares []*models.DialysisBeforePrepare
  3170. var newBeforePrepares []*models.DialysisBeforePrepare
  3171. //判断是否开启自动出库
  3172. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  3173. if record.IsOpen == 1 {
  3174. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3175. goods, _ := dataBody["goods"].([]interface{})
  3176. if len(goods) > 0 {
  3177. for _, item := range goods {
  3178. items := item.(map[string]interface{})
  3179. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  3180. utils.ErrorLog("record_time")
  3181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3182. return
  3183. }
  3184. record_time := int64(items["record_time"].(float64))
  3185. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3186. utils.ErrorLog("id")
  3187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3188. return
  3189. }
  3190. id := int64(items["id"].(float64))
  3191. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  3192. utils.ErrorLog("patient_id")
  3193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3194. return
  3195. }
  3196. patient_id := int64(items["patient_id"].(float64))
  3197. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  3198. utils.ErrorLog("creater")
  3199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3200. return
  3201. }
  3202. creater := int64(items["creater"].(float64))
  3203. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3204. utils.ErrorLog("good_id")
  3205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3206. return
  3207. }
  3208. good_id := int64(items["good_id"].(float64))
  3209. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3210. utils.ErrorLog("good_type_id")
  3211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3212. return
  3213. }
  3214. good_type_id := int64(items["good_type_id"].(float64))
  3215. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3216. utils.ErrorLog("count")
  3217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3218. return
  3219. }
  3220. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3221. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  3222. utils.ErrorLog("ctime")
  3223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3224. return
  3225. }
  3226. ctime := int64(items["ctime"].(float64))
  3227. commdity_code := items["commdity_code"].(string)
  3228. adminUser := c.GetMobileAdminUserInfo()
  3229. prepare := &models.DialysisBeforePrepare{
  3230. ID: id,
  3231. UserOrgId: adminUser.Org.Id,
  3232. PatientId: patient_id,
  3233. RecordDate: record_time,
  3234. GoodId: good_id,
  3235. GoodTypeId: good_type_id,
  3236. Count: count,
  3237. Ctime: ctime,
  3238. Mtime: time.Now().Unix(),
  3239. Creater: creater,
  3240. Modifier: adminUser.AdminUser.Id,
  3241. Status: 1,
  3242. CommdityCode: commdity_code,
  3243. }
  3244. beforePrepares = append(beforePrepares, prepare)
  3245. }
  3246. }
  3247. }
  3248. //查询今日患者出库列表
  3249. consumables_source, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  3250. if dataBody["new_goods"] != nil && reflect.TypeOf(dataBody["new_goods"]).String() == "[]interface {}" {
  3251. goods, _ := dataBody["new_goods"].([]interface{})
  3252. if len(goods) > 0 {
  3253. for _, item := range goods {
  3254. items := item.(map[string]interface{})
  3255. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3256. utils.ErrorLog("good_id")
  3257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3258. return
  3259. }
  3260. good_id := int64(items["good_id"].(float64))
  3261. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3262. utils.ErrorLog("good_type_id")
  3263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3264. return
  3265. }
  3266. good_type_id := int64(items["good_type_id"].(float64))
  3267. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3268. utils.ErrorLog("count")
  3269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3270. return
  3271. }
  3272. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3273. commdity_code := items["commdity_code"].(string)
  3274. fmt.Println("commdityecode", commdity_code)
  3275. adminUser := c.GetMobileAdminUserInfo()
  3276. prepare := &models.DialysisBeforePrepare{
  3277. UserOrgId: adminUser.Org.Id,
  3278. PatientId: patient_id,
  3279. RecordDate: record_time,
  3280. GoodId: good_id,
  3281. GoodTypeId: good_type_id,
  3282. Count: count,
  3283. Ctime: time.Now().Unix(),
  3284. Mtime: time.Now().Unix(),
  3285. Creater: adminUser.AdminUser.Id,
  3286. Modifier: 0,
  3287. CommdityCode: commdity_code,
  3288. }
  3289. newBeforePrepares = append(newBeforePrepares, prepare)
  3290. }
  3291. newBeforePrepares = RemoveRepeatedGood(newBeforePrepares)
  3292. }
  3293. //创建数据
  3294. service.CreateDialysisBeforePrepare(newBeforePrepares)
  3295. }
  3296. //查询是否有出库单
  3297. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  3298. if err == gorm.ErrRecordNotFound {
  3299. //没有记录,则创建出库单
  3300. timeStr := time.Now().Format("2006-01-02")
  3301. timeArr := strings.Split(timeStr, "-")
  3302. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  3303. total = total + 1
  3304. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3305. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3306. number = number + total
  3307. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3308. creater := adminInfo.AdminUser.Id
  3309. warehouseOut := models.WarehouseOut{
  3310. WarehouseOutOrderNumber: warehousing_out_order,
  3311. OperationTime: time.Now().Unix(),
  3312. OrgId: adminInfo.Org.Id,
  3313. Creater: creater,
  3314. Ctime: time.Now().Unix(),
  3315. Status: 1,
  3316. WarehouseOutTime: record_time,
  3317. Dealer: 0,
  3318. Manufacturer: 0,
  3319. Type: 1,
  3320. IsSys: 1,
  3321. }
  3322. //创建出库单
  3323. err := service.AddSigleWarehouseOut(&warehouseOut)
  3324. fmt.Println("err", err)
  3325. if err != nil {
  3326. utils.TraceLog("创建出库单失败 err = %v", err)
  3327. } else {
  3328. for _, item := range beforePrepares {
  3329. if item.Count > 0 {
  3330. warehouseOutInfo := &models.WarehouseOutInfo{
  3331. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  3332. WarehouseOutId: warehouseOut.ID,
  3333. Count: 1,
  3334. Status: 1,
  3335. Ctime: time.Now().Unix(),
  3336. Remark: "",
  3337. OrgId: adminInfo.Org.Id,
  3338. Type: 1,
  3339. Manufacturer: 0,
  3340. Dealer: 0,
  3341. IsSys: 1,
  3342. SysRecordTime: record_time,
  3343. GoodTypeId: item.GoodTypeId,
  3344. GoodId: item.GoodId,
  3345. }
  3346. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3347. warehouseOutInfo.Price = stockInInfo.Price
  3348. //创建出库详情
  3349. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3350. if err == nil {
  3351. details := &models.AutomaticReduceDetail{
  3352. WarehouseOutId: warehouseOutInfo.ID,
  3353. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3354. PatientId: patient_id,
  3355. Ctime: time.Now().Unix(),
  3356. Mtime: time.Now().Unix(),
  3357. Status: 1,
  3358. RecordTime: record_time,
  3359. OrgId: adminInfo.Org.Id,
  3360. GoodId: item.GoodId,
  3361. GoodTypeId: item.GoodTypeId,
  3362. }
  3363. service.AddSigleAutoReduceRecordInfo(details)
  3364. }
  3365. }
  3366. }
  3367. }
  3368. //没有出库单创建
  3369. } else if err == nil {
  3370. if len(newBeforePrepares) > 0 { //新增
  3371. for _, item := range newBeforePrepares {
  3372. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  3373. if err == gorm.ErrRecordNotFound {
  3374. warehouseOutInfo := &models.WarehouseOutInfo{
  3375. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3376. WarehouseOutId: out.ID,
  3377. Status: 1,
  3378. Ctime: time.Now().Unix(),
  3379. Remark: "",
  3380. OrgId: adminInfo.Org.Id,
  3381. Type: 1,
  3382. Manufacturer: 0,
  3383. Dealer: 0,
  3384. IsSys: 1,
  3385. SysRecordTime: record_time,
  3386. }
  3387. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3388. warehouseOutInfo.Price = stockInInfo.Price
  3389. warehouseOutInfo.GoodId = item.GoodId
  3390. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  3391. warehouseOutInfo.Count = item.Count
  3392. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3393. if err == nil {
  3394. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  3395. if count == 0 {
  3396. details := &models.AutomaticReduceDetail{
  3397. WarehouseOutId: warehouseOutInfo.ID,
  3398. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3399. PatientId: patient_id,
  3400. Ctime: time.Now().Unix(),
  3401. Mtime: time.Now().Unix(),
  3402. Status: 1,
  3403. RecordTime: record_time,
  3404. OrgId: adminInfo.Org.Id,
  3405. GoodId: item.GoodId,
  3406. GoodTypeId: item.GoodTypeId,
  3407. Count: item.Count,
  3408. }
  3409. service.AddSigleAutoReduceRecordInfo(details)
  3410. } else if count == 1 {
  3411. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  3412. }
  3413. }
  3414. } else if err == nil { //记录存在,则将加数量
  3415. if outInfo.ID > 0 {
  3416. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  3417. }
  3418. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  3419. if count == 0 {
  3420. details := &models.AutomaticReduceDetail{
  3421. WarehouseOutId: outInfo.ID,
  3422. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3423. PatientId: patient_id,
  3424. Ctime: time.Now().Unix(),
  3425. Mtime: time.Now().Unix(),
  3426. Status: 1,
  3427. RecordTime: record_time,
  3428. OrgId: adminInfo.Org.Id,
  3429. GoodId: item.GoodId,
  3430. GoodTypeId: item.GoodTypeId,
  3431. Count: item.Count,
  3432. }
  3433. service.AddSigleAutoReduceRecordInfo(details)
  3434. } else if count == 1 {
  3435. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  3436. }
  3437. //details := &models.AutomaticReduceDetail{
  3438. // WarehouseOutId: outInfo.ID,
  3439. // WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3440. // PatientId: patient_id,
  3441. // Ctime: time.Now().Unix(),
  3442. // Mtime: time.Now().Unix(),
  3443. // Status: 1,
  3444. // RecordTime: record_time,
  3445. // OrgId: adminInfo.Org.Id,
  3446. // GoodId: item.GoodId,
  3447. // GoodTypeId: item.GoodTypeId,
  3448. // Count: item.Count,
  3449. //}
  3450. //service.AddSigleAutoReduceRecordInfo(details)
  3451. }
  3452. }
  3453. }
  3454. if len(beforePrepares) > 0 { //修改
  3455. for _, consumable := range consumables_source {
  3456. for _, before := range beforePrepares {
  3457. if consumable.GoodId == before.GoodId {
  3458. if consumable.Count != before.Count {
  3459. _, out := service.FindStockOutOrderNumberByTime(record_time, adminInfo.Org.Id)
  3460. //_, out := service.FindOldOrderInfoByGoodId(record_time, adminInfo.Org.Id)
  3461. //判断前端更改后的商品id的出库记录在数据库中是否存在
  3462. err, newOut := service.FindOrderInfoByGoodId(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id)
  3463. fmt.Println("err222222222222222222", err)
  3464. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  3465. warehouseOutInfo := &models.WarehouseOutInfo{
  3466. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3467. WarehouseOutId: out.ID,
  3468. Count: before.Count,
  3469. Status: 1,
  3470. Ctime: time.Now().Unix(),
  3471. Remark: "",
  3472. OrgId: adminInfo.Org.Id,
  3473. Type: 1,
  3474. Manufacturer: 0,
  3475. Dealer: 0,
  3476. IsSys: 1,
  3477. SysRecordTime: record_time,
  3478. }
  3479. stockInInfo, _ := service.FindLastStockInInfoRecord(before.GoodId, adminInfo.Org.Id)
  3480. warehouseOutInfo.Price = stockInInfo.Price
  3481. warehouseOutInfo.GoodId = before.GoodId
  3482. warehouseOutInfo.GoodTypeId = before.GoodTypeId
  3483. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3484. fmt.Println("err2223444444444444444444", err)
  3485. if err == nil {
  3486. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  3487. user, err := service.FindGoodUserById(before.GoodTypeId, before.GoodId, patient_id, adminInfo.Org.Id, record_time)
  3488. if err == gorm.ErrRecordNotFound {
  3489. details := &models.AutomaticReduceDetail{
  3490. WarehouseOutId: warehouseOutInfo.ID,
  3491. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3492. PatientId: patient_id,
  3493. Ctime: time.Now().Unix(),
  3494. Mtime: time.Now().Unix(),
  3495. Status: 1,
  3496. RecordTime: record_time,
  3497. OrgId: adminInfo.Org.Id,
  3498. GoodId: consumable.GoodId,
  3499. GoodTypeId: consumable.GoodTypeId,
  3500. Count: before.Count,
  3501. }
  3502. service.AddSigleAutoReduceRecordInfo(details)
  3503. } else if err == nil {
  3504. if user.ID > 0 {
  3505. //service.UpdateOrderInfoDetails( consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, a_liquid, warehouseOutInfo)
  3506. service.UpdateUserInfoDetails(consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, before.Count, warehouseOutInfo)
  3507. }
  3508. }
  3509. }
  3510. } else if err == nil { //存在,则更改使用人商品信息
  3511. fmt.Println("333333333")
  3512. //处理原来的数据
  3513. if newOut.ID > 0 {
  3514. if consumable.Count > before.Count { // 减少
  3515. num := int64(0)
  3516. if consumable.Count-before.Count > 0 {
  3517. num = consumable.Count - before.Count
  3518. } else {
  3519. num = before.Count - consumable.Count
  3520. }
  3521. service.UpdateOrderCountSub(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id, num)
  3522. } else if consumable.Count < before.Count { //增加
  3523. service.UpdateOrderCountAdd(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id, before.Count-consumable.Count)
  3524. }
  3525. user, err := service.FindGoodUserById(consumable.GoodTypeId, consumable.GoodId, patient_id, adminInfo.Org.Id, record_time)
  3526. if err == gorm.ErrRecordNotFound {
  3527. details := &models.AutomaticReduceDetail{
  3528. WarehouseOutId: newOut.ID,
  3529. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  3530. PatientId: patient_id,
  3531. Ctime: time.Now().Unix(),
  3532. Mtime: time.Now().Unix(),
  3533. Status: 1,
  3534. RecordTime: record_time,
  3535. OrgId: adminInfo.Org.Id,
  3536. GoodId: consumable.GoodId,
  3537. GoodTypeId: consumable.GoodTypeId,
  3538. Count: before.Count,
  3539. }
  3540. service.AddSigleAutoReduceRecordInfo(details)
  3541. } else if err == nil {
  3542. if user.ID > 0 {
  3543. service.UpdateUserInfoDetails(consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, before.Count, &newOut)
  3544. }
  3545. }
  3546. }
  3547. }
  3548. }
  3549. }
  3550. }
  3551. }
  3552. }
  3553. }
  3554. //更新自动出库的地方
  3555. var errs error
  3556. if len(beforePrepares) > 0 {
  3557. for _, item := range beforePrepares {
  3558. errs = service.UpdateDialysisBeforePrepareTwo(item)
  3559. detail := models.AutomaticReduceDetail{
  3560. PatientId: item.PatientId,
  3561. Status: 1,
  3562. RecordTime: item.RecordDate,
  3563. OrgId: item.UserOrgId,
  3564. GoodId: item.GoodId,
  3565. GoodTypeId: item.GoodTypeId,
  3566. Count: item.Count,
  3567. }
  3568. service.UpdateAutoReduceDetailSix(&detail)
  3569. }
  3570. }
  3571. if errs == nil {
  3572. c.ServeSuccessJSON(map[string]interface{}{
  3573. "msg": "修改成功",
  3574. })
  3575. return
  3576. } else {
  3577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3578. return
  3579. }
  3580. } else {
  3581. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3582. goods, _ := dataBody["goods"].([]interface{})
  3583. if len(goods) > 0 {
  3584. for _, item := range goods {
  3585. items := item.(map[string]interface{})
  3586. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  3587. utils.ErrorLog("record_time")
  3588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3589. return
  3590. }
  3591. record_time := int64(items["record_time"].(float64))
  3592. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3593. utils.ErrorLog("id")
  3594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3595. return
  3596. }
  3597. id := int64(items["id"].(float64))
  3598. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  3599. utils.ErrorLog("patient_id")
  3600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3601. return
  3602. }
  3603. patient_id := int64(items["patient_id"].(float64))
  3604. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  3605. utils.ErrorLog("creater")
  3606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3607. return
  3608. }
  3609. creater := int64(items["creater"].(float64))
  3610. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3611. utils.ErrorLog("good_id")
  3612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3613. return
  3614. }
  3615. good_id := int64(items["good_id"].(float64))
  3616. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3617. utils.ErrorLog("good_type_id")
  3618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3619. return
  3620. }
  3621. good_type_id := int64(items["good_type_id"].(float64))
  3622. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3623. utils.ErrorLog("count")
  3624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3625. return
  3626. }
  3627. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3628. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  3629. utils.ErrorLog("ctime")
  3630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3631. return
  3632. }
  3633. ctime := int64(items["ctime"].(float64))
  3634. adminUser := c.GetMobileAdminUserInfo()
  3635. prepare := &models.DialysisBeforePrepare{
  3636. ID: id,
  3637. UserOrgId: adminUser.Org.Id,
  3638. PatientId: patient_id,
  3639. RecordDate: record_time,
  3640. GoodId: good_id,
  3641. GoodTypeId: good_type_id,
  3642. Count: count,
  3643. Ctime: ctime,
  3644. Mtime: time.Now().Unix(),
  3645. Creater: creater,
  3646. Modifier: adminUser.AdminUser.Id,
  3647. Status: 1,
  3648. }
  3649. beforePrepares = append(beforePrepares, prepare)
  3650. }
  3651. }
  3652. }
  3653. if dataBody["new_goods"] != nil && reflect.TypeOf(dataBody["new_goods"]).String() == "[]interface {}" {
  3654. goods, _ := dataBody["new_goods"].([]interface{})
  3655. if len(goods) > 0 {
  3656. for _, item := range goods {
  3657. items := item.(map[string]interface{})
  3658. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3659. utils.ErrorLog("good_id")
  3660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3661. return
  3662. }
  3663. good_id := int64(items["good_id"].(float64))
  3664. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3665. utils.ErrorLog("good_type_id")
  3666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3667. return
  3668. }
  3669. good_type_id := int64(items["good_type_id"].(float64))
  3670. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3671. utils.ErrorLog("count")
  3672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3673. return
  3674. }
  3675. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3676. adminUser := c.GetMobileAdminUserInfo()
  3677. prepare := &models.DialysisBeforePrepare{
  3678. UserOrgId: adminUser.Org.Id,
  3679. PatientId: patient_id,
  3680. RecordDate: record_time,
  3681. GoodId: good_id,
  3682. GoodTypeId: good_type_id,
  3683. Count: count,
  3684. Ctime: time.Now().Unix(),
  3685. Mtime: time.Now().Unix(),
  3686. Creater: adminUser.AdminUser.Id,
  3687. Modifier: 0,
  3688. }
  3689. newBeforePrepares = append(newBeforePrepares, prepare)
  3690. }
  3691. }
  3692. service.CreateDialysisBeforePrepare(newBeforePrepares)
  3693. }
  3694. var errs error
  3695. if len(beforePrepares) > 0 {
  3696. for _, item := range beforePrepares {
  3697. errs = service.UpdateDialysisBeforePrepareTwo(item)
  3698. }
  3699. }
  3700. if errs == nil {
  3701. c.ServeSuccessJSON(map[string]interface{}{
  3702. "msg": "修改成功",
  3703. })
  3704. return
  3705. } else {
  3706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3707. return
  3708. }
  3709. }
  3710. }
  3711. func (c *DialysisAPIController) GetDialysisGoods() {
  3712. schedualDate := c.GetString("schedule_date")
  3713. schedule_type, _ := c.GetInt64("schedule_type")
  3714. partition_id, _ := c.GetInt64("partition_id")
  3715. page, _ := c.GetInt("page")
  3716. patient_id, _ := c.GetInt64("patient_id")
  3717. schedualEndDate := int64(0)
  3718. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  3719. if parseDateErr != nil && len(schedualDate) != 0 {
  3720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3721. return
  3722. }
  3723. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  3724. if parseDateErr != nil && len(schedualDate) != 0 {
  3725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3726. return
  3727. }
  3728. schedualEndDate = endDate.Unix()
  3729. adminUser := c.GetMobileAdminUserInfo()
  3730. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  3731. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  3732. //获取当天该病人的透析处方
  3733. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  3734. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  3735. if err == gorm.ErrRecordNotFound {
  3736. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  3737. if patient_id != 0 {
  3738. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3739. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  3740. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  3741. item.LastAutomaticReduceDetail = goodUser
  3742. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3743. }
  3744. }
  3745. c.ServeSuccessJSON(map[string]interface{}{
  3746. "dialysis_goods": dialysisGoods,
  3747. "good_type": goodTypes,
  3748. "total": total,
  3749. "prescribe": prescribe,
  3750. "good_info": good_info,
  3751. })
  3752. return
  3753. } else if err == nil {
  3754. //获取当天排班的每个患者的库存使用情况
  3755. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  3756. if patient_id != 0 {
  3757. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3758. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  3759. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  3760. fmt.Println(goodUser)
  3761. fmt.Println(lastGoodUserDetial)
  3762. item.LastAutomaticReduceDetail = goodUser
  3763. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3764. }
  3765. }
  3766. if err == nil {
  3767. c.ServeSuccessJSON(map[string]interface{}{
  3768. "dialysis_goods": dialysisGoods,
  3769. "good_type": goodTypes,
  3770. "total": total,
  3771. "prescribe": prescribe,
  3772. "good_info": good_info,
  3773. })
  3774. return
  3775. } else {
  3776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3777. return
  3778. }
  3779. } else if err != nil {
  3780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3781. return
  3782. }
  3783. }
  3784. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  3785. start_time := c.GetString("start_time")
  3786. end_time := c.GetString("end_time")
  3787. timeLayout := "2006-01-02"
  3788. loc, _ := time.LoadLocation("Local")
  3789. var theStartTime int64
  3790. if len(start_time) > 0 {
  3791. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3792. if err != nil {
  3793. utils.ErrorLog(err.Error())
  3794. }
  3795. theStartTime = theTime.Unix()
  3796. }
  3797. var theEndtTime int64
  3798. if len(end_time) > 0 {
  3799. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3800. if err != nil {
  3801. utils.ErrorLog(err.Error())
  3802. }
  3803. theEndtTime = theTime.Unix()
  3804. }
  3805. adminUser := c.GetMobileAdminUserInfo()
  3806. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  3807. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  3808. if err == nil {
  3809. c.ServeSuccessJSON(map[string]interface{}{
  3810. "stock_out": outInfo,
  3811. "stockCount": stockCount,
  3812. })
  3813. return
  3814. } else {
  3815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3816. return
  3817. }
  3818. }
  3819. func (c *DialysisAPIController) GetStockInGoodInfo() {
  3820. patient_id, _ := c.GetInt64("patient_id", 0)
  3821. record_time := c.GetString("record_time")
  3822. adminUser := c.GetMobileAdminUserInfo()
  3823. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  3824. if parseDateErr != nil && len(record_time) != 0 {
  3825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3826. return
  3827. }
  3828. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  3829. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  3830. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  3831. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  3832. //获取今日患者的透析处方参数
  3833. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  3834. c.ServeSuccessJSON(map[string]interface{}{
  3835. "good_type": goodTypes,
  3836. "good_user": goodUser,
  3837. "good_info": good_info,
  3838. "last_good_user": lastGoodUserDetial,
  3839. "prescription": prescribe,
  3840. })
  3841. return
  3842. }
  3843. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  3844. patient_id, _ := c.GetInt64("patient_id", 0)
  3845. record_date := c.GetString("record_time")
  3846. if patient_id <= 0 {
  3847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3848. return
  3849. }
  3850. adminInfo := c.GetMobileAdminUserInfo()
  3851. timeLayout := "2006-01-02"
  3852. loc, _ := time.LoadLocation("Local")
  3853. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3854. record_time := theRecordTime.Unix()
  3855. dataBody := make(map[string]interface{}, 0)
  3856. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3857. if err != nil {
  3858. utils.ErrorLog(err.Error())
  3859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3860. return
  3861. }
  3862. var beforePrepares []*models.DialysisBeforePrepare
  3863. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3864. goods, _ := dataBody["goods"].([]interface{})
  3865. if len(goods) > 0 {
  3866. for _, item := range goods {
  3867. items := item.(map[string]interface{})
  3868. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3869. utils.ErrorLog("good_id")
  3870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3871. return
  3872. }
  3873. good_id := int64(items["good_id"].(float64))
  3874. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3875. utils.ErrorLog("good_type_id")
  3876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3877. return
  3878. }
  3879. good_type_id := int64(items["good_type_id"].(float64))
  3880. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3881. utils.ErrorLog("count")
  3882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3883. return
  3884. }
  3885. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3886. adminUser := c.GetMobileAdminUserInfo()
  3887. prepare := &models.DialysisBeforePrepare{
  3888. UserOrgId: adminUser.Org.Id,
  3889. PatientId: patient_id,
  3890. RecordDate: record_time,
  3891. GoodId: good_id,
  3892. GoodTypeId: good_type_id,
  3893. Count: count,
  3894. Ctime: time.Now().Unix(),
  3895. Mtime: time.Now().Unix(),
  3896. Creater: adminUser.AdminUser.Id,
  3897. Modifier: 0,
  3898. }
  3899. record_count := service.FindDialysisBeforePrepare(prepare.PatientId, prepare.GoodId, prepare.GoodTypeId, adminUser.Org.Id, record_time)
  3900. if record_count == 0 {
  3901. beforePrepares = append(beforePrepares, prepare)
  3902. } else if record_count == 1 {
  3903. service.UpdateDialysisBeforePrepareTwo(prepare)
  3904. }
  3905. }
  3906. }
  3907. }
  3908. beforePrepares = RemoveRepeatedGood(beforePrepares)
  3909. if len(beforePrepares) > 0 {
  3910. service.CreateDialysisBeforePrepare(beforePrepares)
  3911. }
  3912. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  3913. //去重
  3914. consumables = RemoveRepeatedGood(consumables)
  3915. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  3916. if record.IsOpen == 1 {
  3917. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  3918. if err == gorm.ErrRecordNotFound {
  3919. //没有记录,则创建出库单
  3920. timeStr := time.Now().Format("2006-01-02")
  3921. timeArr := strings.Split(timeStr, "-")
  3922. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  3923. total = total + 1
  3924. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3925. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3926. number = number + total
  3927. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3928. creater := adminInfo.AdminUser.Id
  3929. warehouseOut := models.WarehouseOut{
  3930. WarehouseOutOrderNumber: warehousing_out_order,
  3931. OperationTime: time.Now().Unix(),
  3932. OrgId: adminInfo.Org.Id,
  3933. Creater: creater,
  3934. Ctime: time.Now().Unix(),
  3935. Status: 1,
  3936. WarehouseOutTime: record_time,
  3937. Dealer: 0,
  3938. Manufacturer: 0,
  3939. Type: 1,
  3940. IsSys: 1,
  3941. }
  3942. err := service.AddSigleWarehouseOut(&warehouseOut)
  3943. if err != nil {
  3944. utils.TraceLog("创建出库单失败 err = %v", err)
  3945. } else {
  3946. for _, item := range consumables {
  3947. if item.Count > 0 {
  3948. warehouseOutInfo := &models.WarehouseOutInfo{
  3949. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  3950. WarehouseOutId: warehouseOut.ID,
  3951. Status: 1,
  3952. Ctime: time.Now().Unix(),
  3953. Remark: "",
  3954. OrgId: adminInfo.Org.Id,
  3955. Type: 1,
  3956. Manufacturer: 0,
  3957. Dealer: 0,
  3958. IsSys: 1,
  3959. SysRecordTime: record_time,
  3960. GoodTypeId: item.GoodTypeId,
  3961. GoodId: item.GoodId,
  3962. }
  3963. warehouseOutInfo.Count = item.Count
  3964. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3965. warehouseOutInfo.Price = stockInInfo.Price
  3966. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3967. if err == nil {
  3968. details := &models.AutomaticReduceDetail{
  3969. WarehouseOutId: warehouseOutInfo.ID,
  3970. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3971. PatientId: patient_id,
  3972. Ctime: time.Now().Unix(),
  3973. Mtime: time.Now().Unix(),
  3974. Status: 1,
  3975. RecordTime: record_time,
  3976. OrgId: adminInfo.Org.Id,
  3977. GoodId: item.GoodId,
  3978. GoodTypeId: item.GoodTypeId,
  3979. Count: item.Count,
  3980. }
  3981. service.AddSigleAutoReduceRecordInfo(details)
  3982. }
  3983. }
  3984. }
  3985. }
  3986. } else if err == nil {
  3987. for _, item := range consumables {
  3988. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  3989. if err == gorm.ErrRecordNotFound {
  3990. warehouseOutInfo := &models.WarehouseOutInfo{
  3991. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3992. WarehouseOutId: out.ID,
  3993. Status: 1,
  3994. Ctime: time.Now().Unix(),
  3995. Remark: "",
  3996. OrgId: adminInfo.Org.Id,
  3997. Type: 1,
  3998. Manufacturer: 0,
  3999. Dealer: 0,
  4000. IsSys: 1,
  4001. SysRecordTime: record_time,
  4002. }
  4003. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  4004. warehouseOutInfo.Price = stockInInfo.Price
  4005. warehouseOutInfo.GoodId = item.GoodId
  4006. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  4007. warehouseOutInfo.Count = item.Count
  4008. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4009. if err == nil {
  4010. details := &models.AutomaticReduceDetail{
  4011. WarehouseOutId: warehouseOutInfo.ID,
  4012. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4013. PatientId: patient_id,
  4014. Ctime: time.Now().Unix(),
  4015. Mtime: time.Now().Unix(),
  4016. Status: 1,
  4017. RecordTime: record_time,
  4018. OrgId: adminInfo.Org.Id,
  4019. GoodId: item.GoodId,
  4020. GoodTypeId: item.GoodTypeId,
  4021. Count: item.Count,
  4022. }
  4023. service.AddSigleAutoReduceRecordInfo(details)
  4024. }
  4025. } else if err == nil { //记录存在,则将增加数量
  4026. if outInfo.ID > 0 {
  4027. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  4028. }
  4029. details := &models.AutomaticReduceDetail{
  4030. WarehouseOutId: outInfo.ID,
  4031. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  4032. PatientId: patient_id,
  4033. Ctime: time.Now().Unix(),
  4034. Mtime: time.Now().Unix(),
  4035. Status: 1,
  4036. RecordTime: record_time,
  4037. OrgId: adminInfo.Org.Id,
  4038. GoodId: item.GoodId,
  4039. GoodTypeId: item.GoodTypeId,
  4040. Count: item.Count,
  4041. }
  4042. service.AddSigleAutoReduceRecordInfo(details)
  4043. }
  4044. }
  4045. }
  4046. c.ServeSuccessJSON(map[string]interface{}{
  4047. "msg": "提交成功",
  4048. })
  4049. return
  4050. } else {
  4051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  4052. return
  4053. }
  4054. }
  4055. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  4056. newArr = make([]*models.DialysisBeforePrepare, 0)
  4057. for i := 0; i < len(arr); i++ {
  4058. repeat := false
  4059. for j := i + 1; j < len(arr); j++ {
  4060. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  4061. repeat = true
  4062. break
  4063. }
  4064. }
  4065. if !repeat {
  4066. newArr = append(newArr, arr[i])
  4067. }
  4068. }
  4069. return
  4070. }
  4071. func (c *DialysisAPIController) GetAllDrug() {
  4072. patient_id, _ := c.GetInt64("patient_id", 0)
  4073. adminInfo := c.GetMobileAdminUserInfo()
  4074. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  4075. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  4076. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  4077. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  4078. c.ServeSuccessJSON(map[string]interface{}{
  4079. "base_drug_config": drugStockConfig,
  4080. "private_drug_config": privateDrugConfig,
  4081. "base_drug_list": drugList,
  4082. "private_drug_list": privateDrugList,
  4083. })
  4084. }
  4085. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  4086. newArr = make([]*models.DialysisBeforePrepare, 0)
  4087. for i := 0; i < len(arr); i++ {
  4088. repeat := false
  4089. for j := i + 1; j < len(arr); j++ {
  4090. if arr[i].GoodId == arr[j].GoodId {
  4091. repeat = true
  4092. break
  4093. }
  4094. }
  4095. if !repeat {
  4096. newArr = append(newArr, arr[i])
  4097. }
  4098. }
  4099. return
  4100. }
  4101. func (c *DialysisAPIController) GetDepartment() {
  4102. adminInfo := c.GetMobileAdminUserInfo()
  4103. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  4104. if err == nil {
  4105. c.ServeSuccessJSON(map[string]interface{}{
  4106. "departments": departments,
  4107. })
  4108. } else {
  4109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4110. return
  4111. }
  4112. }
  4113. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  4114. types, _ := c.GetInt("type", 0)
  4115. start_time := c.GetString("start_time")
  4116. end_time := c.GetString("end_time")
  4117. orgId := c.GetMobileAdminUserInfo().Org.Id
  4118. timeLayout := "2006-01-02"
  4119. loc, _ := time.LoadLocation("Local")
  4120. var startTime int64
  4121. if len(start_time) > 0 {
  4122. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4123. if err != nil {
  4124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4125. return
  4126. }
  4127. startTime = theTime.Unix()
  4128. }
  4129. var endTime int64
  4130. if len(end_time) > 0 {
  4131. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4132. if err != nil {
  4133. utils.ErrorLog(err.Error())
  4134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4135. return
  4136. }
  4137. endTime = theTime.Unix()
  4138. }
  4139. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  4140. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  4141. if err != nil {
  4142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4143. } else {
  4144. c.ServeSuccessJSON(map[string]interface{}{
  4145. "list": list,
  4146. "type": types,
  4147. "stockTotal": stockTotal,
  4148. })
  4149. }
  4150. }
  4151. func (c *DialysisAPIController) BatchDeleteMonitor() {
  4152. fmt.Println("jin2222245555555555")
  4153. ids := c.GetString("ids")
  4154. fmt.Println("dis22222222", ids)
  4155. idArray := strings.Split(ids, ",")
  4156. err := service.BatchDeleteMonitor(idArray)
  4157. fmt.Print("err", err)
  4158. c.ServeSuccessJSON(map[string]interface{}{
  4159. "msg": "批量删除成功",
  4160. })
  4161. return
  4162. }
  4163. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  4164. id, _ := c.GetInt64("id")
  4165. fmt.Println(id)
  4166. timeLayout := "2006-01-02"
  4167. loc, _ := time.LoadLocation("Local")
  4168. start_time := time.Now().Format("2006-01-02")
  4169. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4170. fmt.Println("start_timestart_time", start_time)
  4171. nowTime := time.Now()
  4172. endTime := nowTime.AddDate(-1, 0, 0)
  4173. endTimes := endTime.Format("2006-01-02")
  4174. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", endTimes+" 00:00:00", loc)
  4175. list, _ := service.GetPatientDialysisRecordList(id, endtime.Unix(), startime.Unix())
  4176. c.ServeSuccessJSON(map[string]interface{}{
  4177. "list": list,
  4178. })
  4179. return
  4180. }
  4181. func (c *DialysisAPIController) BathDeleteAdviceList() {
  4182. dataBody := make(map[string]interface{}, 0)
  4183. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4184. ids := c.GetString("ids")
  4185. fmt.Println("dis22222222", ids)
  4186. idArray := strings.Split(ids, ",")
  4187. origin, _ := c.GetInt64("origin")
  4188. if origin == 1 {
  4189. err = service.BatchDeleteAdvice(idArray)
  4190. fmt.Print("err", err)
  4191. c.ServeSuccessJSON(map[string]interface{}{
  4192. "msg": "批量删除成功",
  4193. })
  4194. return
  4195. }
  4196. if origin == 2 {
  4197. service.BatchDeleteHisAdvice(idArray)
  4198. }
  4199. }
  4200. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  4201. good_id, _ := c.GetInt64("good_id")
  4202. count, _ := c.GetInt64("count")
  4203. record_time, _ := c.GetInt64("record_time")
  4204. patient_id, _ := c.GetInt64("patient_id")
  4205. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  4206. c.ServeSuccessJSON(map[string]interface{}{
  4207. "detail": detail,
  4208. })
  4209. return
  4210. }
  4211. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  4212. good_id, _ := c.GetInt64("good_id")
  4213. record_time, _ := c.GetInt64("record_time")
  4214. patient_id, _ := c.GetInt64("patient_id")
  4215. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  4216. fmt.Print("err", err)
  4217. c.ServeSuccessJSON(map[string]interface{}{
  4218. "msg": "批量删除成功",
  4219. })
  4220. return
  4221. }
  4222. func (c *DialysisAPIController) BatchAdviceCheck() {
  4223. ids := c.GetString("ids")
  4224. idArray := strings.Split(ids, ",")
  4225. creator, _ := c.GetInt64("creator")
  4226. origin, _ := c.GetInt64("origin")
  4227. if origin == 1 {
  4228. err := service.BatchAdviceCheck(idArray, creator)
  4229. fmt.Println(err)
  4230. list, _ := service.GetAdviceExecutionById(idArray)
  4231. c.ServeSuccessJSON(map[string]interface{}{
  4232. "list": list,
  4233. })
  4234. return
  4235. }
  4236. if origin == 2 {
  4237. service.BatchHisAdviceCheck(idArray, creator)
  4238. list, _ := service.GetHisAdviceExecutionById(idArray)
  4239. c.ServeSuccessJSON(map[string]interface{}{
  4240. "list": list,
  4241. })
  4242. return
  4243. }
  4244. }
  4245. func (c *DialysisAPIController) BatchAdviceExecution() {
  4246. ids := c.GetString("ids")
  4247. fmt.Println("dis22222222", ids)
  4248. idArray := strings.Split(ids, ",")
  4249. executionTime := c.GetString("execution_time")
  4250. fmt.Println("333333333", executionTime)
  4251. creator, _ := c.GetInt64("creator")
  4252. timeLayout := "2006-01-02 15:04:05"
  4253. loc, _ := time.LoadLocation("Local")
  4254. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  4255. orgin, _ := c.GetInt64("origin")
  4256. if orgin == 1 {
  4257. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  4258. list, _ := service.GetAdviceExecutionById(idArray)
  4259. fmt.Println(err)
  4260. c.ServeSuccessJSON(map[string]interface{}{
  4261. "list": list,
  4262. })
  4263. return
  4264. }
  4265. if orgin == 2 {
  4266. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  4267. list, _ := service.GetHisAdviceExecutionById(idArray)
  4268. fmt.Println(err)
  4269. c.ServeSuccessJSON(map[string]interface{}{
  4270. "list": list,
  4271. })
  4272. return
  4273. }
  4274. }