dialysis_api_controller.go 176KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859
  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. if prescription.ID > 0 {
  1596. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  1597. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  1598. if template.TemplateId == 6 || template.TemplateId == 32 { //adminUserInfo.Org.Id == 9538
  1599. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  1600. }
  1601. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  1602. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  1603. }
  1604. // 只针对方济医院
  1605. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  1606. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  1607. ultrafiltration_rate = value
  1608. }
  1609. }
  1610. }
  1611. record := models.MonitoringRecord{
  1612. UserOrgId: adminUserInfo.Org.Id,
  1613. PatientId: patientID,
  1614. DialysisOrderId: dialysisRecord.ID,
  1615. MonitoringDate: schedulestartTime,
  1616. OperateTime: startDate.Unix(),
  1617. // MonitoringTime: recordTime,
  1618. MonitoringNurse: nurseID,
  1619. Dispose: tempdispose,
  1620. UltrafiltrationRate: ultrafiltration_rate,
  1621. UltrafiltrationVolume: 0,
  1622. Status: 1,
  1623. CreatedTime: time.Now().Unix(),
  1624. UpdatedTime: time.Now().Unix(),
  1625. }
  1626. //只针对广慈医院
  1627. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 {
  1628. // 查询病人是否有透前评估数据
  1629. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1630. //如果有数据就插入
  1631. if errcode == nil {
  1632. record.SystolicBloodPressure = befor.SystolicBloodPressure
  1633. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  1634. record.BreathingRate = befor.BreathingRate
  1635. record.PulseFrequency = befor.PulseFrequency
  1636. record.Temperature = befor.Temperature
  1637. }
  1638. }
  1639. // 如果当天有插入数据,则不再往透析纪录里插入数据
  1640. if newdialysisRecord.ID > 0 {
  1641. err := service.CreateMonitor(&record)
  1642. if err != nil {
  1643. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  1644. return
  1645. }
  1646. }
  1647. go func() {
  1648. ssoDomain := beego.AppConfig.String("call_domain")
  1649. api := ssoDomain + "/index/uppatient"
  1650. values := make(url.Values)
  1651. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  1652. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1653. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  1654. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  1655. http.PostForm(api, values)
  1656. }()
  1657. if createErr != nil {
  1658. this.ErrorLog("上机失败:%v", createErr)
  1659. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1660. return
  1661. }
  1662. this.ServeSuccessJSON(map[string]interface{}{
  1663. "dialysis_order": newdialysisRecord,
  1664. "monitor": record,
  1665. })
  1666. }
  1667. func (c *DialysisAPIController) PostSolution() {
  1668. id, _ := c.GetInt64("patient", 0)
  1669. recordDateStr := c.GetString("record_date")
  1670. if id <= 0 {
  1671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1672. return
  1673. }
  1674. adminUserInfo := c.GetMobileAdminUserInfo()
  1675. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1676. if patient.ID == 0 {
  1677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1678. return
  1679. }
  1680. if len(recordDateStr) == 0 {
  1681. recordDateStr = time.Now().Format("2006-01-02")
  1682. }
  1683. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1684. if parseDateErr != nil {
  1685. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1687. return
  1688. }
  1689. mode_id, _ := c.GetInt64("mode_id", 0)
  1690. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1691. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1692. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1693. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1694. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1695. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1696. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1697. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1698. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1699. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1700. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1701. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1702. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1703. kalium, _ := c.GetFloat("kalium", 0)
  1704. sodium, _ := c.GetFloat("sodium", 0)
  1705. calcium, _ := c.GetFloat("calcium", 0)
  1706. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1707. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1708. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1709. glucose, _ := c.GetFloat("glucose", 0)
  1710. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1711. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1712. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1713. conductivity, _ := c.GetFloat("conductivity", 0)
  1714. remark := c.GetString("remark")
  1715. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1716. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1717. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1718. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1719. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1720. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1721. special_medicine_other := c.GetString("special_medicine_other")
  1722. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1723. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1724. blood_access, _ := c.GetInt64("blood_access", 0)
  1725. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1726. body_fluid_other := c.GetString("body_fluid_other")
  1727. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1728. niprocart, _ := c.GetInt64("niprocart", 0)
  1729. jms, _ := c.GetInt64("jms", 0)
  1730. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1731. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1732. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1733. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1734. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1735. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1736. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1737. injector, _ := c.GetInt64("injector", 0)
  1738. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1739. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1740. safe_package, _ := c.GetInt64("package", 0)
  1741. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1742. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1743. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1744. blood := c.GetString("blood")
  1745. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1746. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1747. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1748. displace_speed := c.GetString("displace_speed")
  1749. illness, _ := c.GetInt64("illness")
  1750. amylaceum := c.GetString("amylaceum")
  1751. single_time := c.GetString("single_time")
  1752. single_water := c.GetString("single_water")
  1753. replacement_flow := c.GetString("replacement_flow")
  1754. plasma_separator := c.GetString("plasma_separator")
  1755. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1756. if mode_id > 0 {
  1757. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1758. }
  1759. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1760. //
  1761. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1762. // if appRole.UserType == 3 {
  1763. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1764. // if getPermissionErr != nil {
  1765. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1766. // return
  1767. // } else if headNursePermission == nil {
  1768. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1769. // return
  1770. // }
  1771. // }
  1772. //}
  1773. prescription := models.DialysisPrescription{
  1774. UserOrgId: adminUserInfo.Org.Id,
  1775. PatientId: id,
  1776. RecordDate: recordDate.Unix(),
  1777. ModeId: mode_id,
  1778. DialysisDuration: dialysis_duration,
  1779. Dialyzer: dialyzer,
  1780. PerfusionApparatus: perfusion_apparatus,
  1781. BloodFlowVolume: blood_flow_volume,
  1782. DewaterAmount: dewater_amount,
  1783. DisplaceLiqui: displace_liqui,
  1784. ReplacementWay: replacement_way,
  1785. Anticoagulant: anticoagulant,
  1786. AnticoagulantShouji: anticoagulant_shouji,
  1787. AnticoagulantWeichi: anticoagulant_weichi,
  1788. AnticoagulantZongliang: anticoagulant_zongliang,
  1789. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1790. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1791. Kalium: kalium,
  1792. Sodium: sodium,
  1793. Calcium: calcium,
  1794. Bicarbonate: bicarbonate,
  1795. Glucose: glucose,
  1796. // DryWeight: dry_weight,
  1797. DialysateFlow: dialysate_flow,
  1798. DialysateTemperature: dialysate_temperature,
  1799. Conductivity: conductivity,
  1800. Remark: remark,
  1801. Status: 1,
  1802. CreatedTime: time.Now().Unix(),
  1803. UpdatedTime: time.Now().Unix(),
  1804. DialysisDurationMinute: dialysisDurationMinute,
  1805. DialysisDurationHour: dialysisDurationHour,
  1806. TargetUltrafiltration: targetUltrafiltration,
  1807. DialysateFormulation: dialysateFormulation,
  1808. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1809. BodyFluid: body_fluid,
  1810. SpecialMedicine: special_medicine,
  1811. SpecialMedicineOther: special_medicine_other,
  1812. DisplaceLiquiPart: displace_liqui_part,
  1813. DisplaceLiquiValue: displace_liqui_value,
  1814. BloodAccess: blood_access,
  1815. Ultrafiltration: ultrafiltration,
  1816. BodyFluidOther: body_fluid_other,
  1817. ReplacementTotal: replacement_total,
  1818. Niprocart: niprocart,
  1819. Jms: jms,
  1820. FistulaNeedleSet: fistula_needle_set,
  1821. FistulaNeedleSet16: fistula_needle_set_16,
  1822. Hemoperfusion: hemoperfusion,
  1823. DialyserSterilised: dialyser_sterilised,
  1824. Filtryzer: filtryzer,
  1825. TargetKtv: target_ktv,
  1826. Dialyzers: dialyzers,
  1827. Injector: injector,
  1828. Bloodlines: bloodlines,
  1829. TubingHemodialysis: tubing_hemodialysis,
  1830. Package: safe_package,
  1831. ALiquid: a_liquid,
  1832. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1833. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1834. Blood: blood,
  1835. DialysisDialyszers: dialysis_dialyszers,
  1836. DialysisIrrigation: dialysis_irrigation,
  1837. AntioxidantCommodityName: antioxidant_commodity_name,
  1838. DisplaceSpeed: displace_speed,
  1839. Illness: illness,
  1840. Amylaceum: amylaceum,
  1841. SingleWater: single_water,
  1842. SingleTime: single_time,
  1843. ReplacementFlow: replacement_flow,
  1844. PlasmaSeparator: plasma_separator,
  1845. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1846. }
  1847. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1848. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1849. //
  1850. if appRole.UserType == 2 || appRole.UserType == 1 {
  1851. prescription_doctor = adminUserInfo.AdminUser.Id
  1852. prescription.PrescriptionDoctor = prescription_doctor
  1853. }
  1854. if dialysisPrescription.ID == 0 { //新增
  1855. prescription.Creater = adminUserInfo.AdminUser.Id
  1856. } else { //修改
  1857. if dialysisPrescription.Creater == 0 {
  1858. prescription.Creater = adminUserInfo.AdminUser.Id
  1859. } else {
  1860. prescription.Creater = dialysisPrescription.Creater
  1861. }
  1862. //if/**/
  1863. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1864. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  1865. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1866. // if getPermissionErr != nil {
  1867. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1868. // return
  1869. // } else if headNursePermission == nil {
  1870. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1871. // return
  1872. // }
  1873. //}
  1874. //prescription.Creater = dialysisPrescription.Creater
  1875. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1876. prescription.Modifier = adminUserInfo.AdminUser.Id
  1877. prescription.ID = dialysisPrescription.ID
  1878. }
  1879. solution := models.DialysisSolution{
  1880. RegistrarsId: adminUserInfo.AdminUser.Id,
  1881. UserOrgId: adminUserInfo.Org.Id,
  1882. Doctor: prescription_doctor,
  1883. PatientId: id,
  1884. ModeId: mode_id,
  1885. DialysisDuration: dialysis_duration,
  1886. PerfusionApparatus: perfusion_apparatus,
  1887. BloodFlowVolume: blood_flow_volume,
  1888. Dewater: dewater_amount,
  1889. DisplaceLiqui: displace_liqui,
  1890. ReplacementWay: replacement_way,
  1891. Anticoagulant: anticoagulant,
  1892. AnticoagulantShouji: anticoagulant_shouji,
  1893. AnticoagulantWeichi: anticoagulant_weichi,
  1894. AnticoagulantZongliang: anticoagulant_zongliang,
  1895. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1896. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1897. Kalium: kalium,
  1898. Sodium: sodium,
  1899. Calcium: calcium,
  1900. Bicarbonate: bicarbonate,
  1901. Glucose: glucose,
  1902. // DryWeight: dry_weight,
  1903. DialysateFlow: dialysate_flow,
  1904. DialysateTemperature: dialysate_temperature,
  1905. Conductivity: conductivity,
  1906. Remark: remark,
  1907. Status: 1,
  1908. CreatedTime: time.Now().Unix(),
  1909. UpdatedTime: time.Now().Unix(),
  1910. DialysisDurationMinute: dialysisDurationMinute,
  1911. DialysisDurationHour: dialysisDurationHour,
  1912. TargetUltrafiltration: targetUltrafiltration,
  1913. DialysateFormulation: dialysateFormulation,
  1914. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1915. BodyFluid: body_fluid,
  1916. SpecialMedicine: special_medicine,
  1917. SpecialMedicineOther: special_medicine_other,
  1918. DisplaceLiquiPart: displace_liqui_part,
  1919. DisplaceLiquiValue: displace_liqui_value,
  1920. BloodAccess: blood_access,
  1921. Ultrafiltration: ultrafiltration,
  1922. BodyFluidOther: body_fluid_other,
  1923. ReplacementTotal: replacement_total,
  1924. TargetKtv: target_ktv,
  1925. DialysisDialyszers: dialysis_dialyszers,
  1926. DialysisIrrigation: dialysis_irrigation,
  1927. }
  1928. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  1929. //查询最近透析准备表里是否存在 透析器 灌流器
  1930. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1931. //
  1932. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1933. //
  1934. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1935. //if len(mation)>0{
  1936. // for _, item := range splitStr {
  1937. // for _,it := range mation{
  1938. // if(item == it.SpecificationName){
  1939. //
  1940. // //查询最近一次的透析器
  1941. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1942. //
  1943. // if errcode == gorm.ErrRecordNotFound{
  1944. // //插入数据
  1945. // prepare := models.DialysisBeforePrepare{
  1946. // UserOrgId: adminUserInfo.Org.Id,
  1947. // PatientId: id,
  1948. // RecordDate: recordDate.Unix(),
  1949. // GoodTypeId: it.GoodTypeId,
  1950. // GoodId: it.ID,
  1951. // Count: 1,
  1952. // Ctime: time.Now().Unix(),
  1953. // Creater: adminUserInfo.AdminUser.Id,
  1954. // Status:1,
  1955. //
  1956. // }
  1957. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1958. // fmt.Println("",errcode)
  1959. // }
  1960. // }
  1961. // }
  1962. //
  1963. // }
  1964. //
  1965. // for _, item := range splitIrrigation {
  1966. // for _,it := range mation{
  1967. // if(item == it.SpecificationName){
  1968. // //查询最近一次的透析器
  1969. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1970. // if errcode == gorm.ErrRecordNotFound{
  1971. // //插入数据
  1972. // prepare := models.DialysisBeforePrepare{
  1973. // UserOrgId: adminUserInfo.Org.Id,
  1974. // PatientId: id,
  1975. // RecordDate: recordDate.Unix(),
  1976. // GoodTypeId: it.GoodTypeId,
  1977. // GoodId: it.ID,
  1978. // Count: 1,
  1979. // Ctime: time.Now().Unix(),
  1980. // Creater: adminUserInfo.AdminUser.Id,
  1981. // Status:1,
  1982. //
  1983. // }
  1984. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1985. // fmt.Println(errcode)
  1986. // }
  1987. // }
  1988. // }
  1989. // }
  1990. //}
  1991. c.ServeSuccessJSON(map[string]interface{}{
  1992. "solution": &solution,
  1993. "prescription": &prescription,
  1994. })
  1995. }
  1996. func (c *DialysisAPIController) GetAcceptsAssessment() {
  1997. patient, _ := c.GetInt64("patient", 0)
  1998. adminUserInfo := c.GetMobileAdminUserInfo()
  1999. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  2000. c.ServeSuccessJSON(map[string]interface{}{
  2001. "receiveTreatmentAsses": receiveTreatmentAsses,
  2002. })
  2003. }
  2004. func (this *DialysisAPIController) PostSignInfo() {
  2005. patientID, _ := this.GetInt64("patient_id")
  2006. recordDateStr := this.GetString("date")
  2007. if patientID <= 0 {
  2008. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2009. return
  2010. }
  2011. if len(recordDateStr) == 0 {
  2012. recordDateStr = time.Now().Format("2006-01-02")
  2013. }
  2014. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2015. if parseDateErr != nil {
  2016. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2017. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2018. return
  2019. }
  2020. adminInfo := this.GetMobileAdminUserInfo()
  2021. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  2022. if err != nil {
  2023. this.ErrorLog("签名失败:%v", err)
  2024. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2025. return
  2026. }
  2027. this.ServeSuccessJSON(map[string]interface{}{
  2028. "doctor_id": adminInfo.AdminUser.Id,
  2029. })
  2030. }
  2031. func (this *DialysisAPIController) GetLastMonitorRecord() {
  2032. patientID, _ := this.GetInt64("patient_id")
  2033. adminInfo := this.GetMobileAdminUserInfo()
  2034. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  2035. this.ServeSuccessJSON(map[string]interface{}{
  2036. "monitor": record,
  2037. })
  2038. }
  2039. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  2040. thisTime := time.Now()
  2041. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  2042. timeLayout := "2006-01-02 15:04:05"
  2043. loc, _ := time.LoadLocation("Local")
  2044. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2045. theAssessmentDateTime := theStartTime.Unix()
  2046. patientID, _ := this.GetInt64("patient_id")
  2047. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  2048. adminInfo := this.GetMobileAdminUserInfo()
  2049. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  2050. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  2051. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  2052. var ultrafiltration_rate float64
  2053. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  2054. if prescription.ID > 0 {
  2055. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2056. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2057. if template.TemplateId == 6 {
  2058. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2059. record.UltrafiltrationRate = ultrafiltration_rate
  2060. }
  2061. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  2062. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  2063. record.UltrafiltrationRate = ultrafiltration_rate
  2064. }
  2065. if template.TemplateId == 20 || template.TemplateId == 22 {
  2066. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2067. record.UltrafiltrationRate = ultrafiltration_rate
  2068. }
  2069. // 只针对方济医院
  2070. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  2071. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2072. ultrafiltration_rate = value
  2073. record.UltrafiltrationRate = ultrafiltration_rate
  2074. }
  2075. }
  2076. }
  2077. // record.UltrafiltrationRate = ultrafiltration_rate
  2078. if adminInfo.Org.Id != 9538 {
  2079. record.UltrafiltrationVolume = 0
  2080. }
  2081. 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
  2082. if ultrafiltration_rate > 0 {
  2083. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  2084. record.UltrafiltrationVolume = value
  2085. }
  2086. }
  2087. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 { //adminInfo.Org.Id == 9538
  2088. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  2089. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  2090. record.UltrafiltrationVolume = ultrafiltration_volume
  2091. }
  2092. }
  2093. this.ServeSuccessJSON(map[string]interface{}{
  2094. "monitor": record,
  2095. })
  2096. }
  2097. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  2098. record_id, _ := this.GetInt64("id")
  2099. nurseID, _ := this.GetInt64("nurse")
  2100. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2101. bedID, _ := this.GetInt64("bed")
  2102. start_time := this.GetString("start_time")
  2103. schedual_type, _ := this.GetInt64("schedual_type")
  2104. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2105. change_nurse, _ := this.GetInt64("change_nurse")
  2106. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2107. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2108. if record_id == 0 {
  2109. this.ErrorLog("id:%v", record_id)
  2110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2111. return
  2112. }
  2113. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2114. if parseStartDateErr != nil {
  2115. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2116. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2117. return
  2118. }
  2119. adminUserInfo := this.GetMobileAdminUserInfo()
  2120. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2121. if getNurseErr != nil {
  2122. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2124. return
  2125. } else if nurse == nil {
  2126. this.ErrorLog("护士不存在")
  2127. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2128. return
  2129. }
  2130. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2131. //if getNurseErr != nil {
  2132. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  2133. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2134. // return
  2135. //} else if nurse == nil {
  2136. // this.ErrorLog("护士不存在")
  2137. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2138. // return
  2139. //}
  2140. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2141. if getDeviceNumberErr != nil {
  2142. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2143. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2144. return
  2145. } else if deviceNumber == nil {
  2146. this.ErrorLog("床位号不存在")
  2147. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2148. return
  2149. }
  2150. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  2151. //
  2152. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  2153. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2154. // if getPermissionErr != nil {
  2155. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2156. // return
  2157. // } else if headNursePermission == nil {
  2158. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2159. // return
  2160. // }
  2161. //}
  2162. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2163. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2164. timeLayout := "2006-01-02 15:04:05"
  2165. loc, _ := time.LoadLocation("Local")
  2166. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2167. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2168. schedulestartTime := theStartTime.Unix()
  2169. scheduleendTime := theEndTime.Unix()
  2170. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2171. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2172. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2173. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  2174. if err == gorm.ErrRecordNotFound { //空床位
  2175. // 修改了床位逻辑
  2176. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2177. if daySchedule.ID > 0 {
  2178. daySchedule.BedId = bedID
  2179. daySchedule.PartitionId = deviceNumber.ZoneID
  2180. daySchedule.ScheduleType = schedual_type
  2181. daySchedule.UpdatedTime = time.Now().Unix()
  2182. err := service.UpdateSchedule(&daySchedule)
  2183. if err != nil {
  2184. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2185. return
  2186. }
  2187. }
  2188. } else if err == nil {
  2189. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2190. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2191. if daySchedule.ID > 0 {
  2192. daySchedule.BedId = bedID
  2193. daySchedule.PartitionId = deviceNumber.ZoneID
  2194. daySchedule.ScheduleType = schedual_type
  2195. daySchedule.UpdatedTime = time.Now().Unix()
  2196. err := service.UpdateSchedule(&daySchedule)
  2197. if err != nil {
  2198. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2199. return
  2200. }
  2201. }
  2202. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2203. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2204. return
  2205. }
  2206. } else if err != nil {
  2207. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2208. return
  2209. }
  2210. }
  2211. dialysisRecord := &models.DialysisOrder{
  2212. ID: record_id,
  2213. UserOrgId: adminUserInfo.Org.Id,
  2214. BedID: bedID,
  2215. StartNurse: nurseID,
  2216. StartTime: startDate.Unix(),
  2217. PunctureNurse: puncture_nurse,
  2218. Creator: adminUserInfo.AdminUser.Id,
  2219. Modifier: adminUserInfo.AdminUser.Id,
  2220. WashpipeNurse: washpipe_nurse,
  2221. SchedualType: schedual_type,
  2222. ChangeNurse: change_nurse,
  2223. DifficultPunctureNurse: difficult_puncture_nurse,
  2224. NewFistulaNurse: new_fistula_nurse,
  2225. }
  2226. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  2227. if updateErr != nil {
  2228. this.ErrorLog("修改上机失败:%v", updateErr)
  2229. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2230. return
  2231. }
  2232. if updateErr == nil {
  2233. if tempDialysisRecord.Stage == 2 {
  2234. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  2235. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2236. fmt.Println(value)
  2237. a, b := math.Modf(value)
  2238. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2239. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2240. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  2241. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  2242. if updateAssessmentErr != nil {
  2243. utils.ErrorLog("%v", updateAssessmentErr)
  2244. }
  2245. }
  2246. }
  2247. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2248. this.ServeSuccessJSON(map[string]interface{}{
  2249. "dialysis_order": dialysisRecords,
  2250. })
  2251. }
  2252. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  2253. record_id, _ := c.GetInt64("id")
  2254. nurseID, _ := c.GetInt64("nurse")
  2255. end_time := c.GetString("end_time")
  2256. if record_id <= 0 || nurseID <= 0 {
  2257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2258. return
  2259. }
  2260. adminUserInfo := c.GetMobileAdminUserInfo()
  2261. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2262. if getNurseErr != nil {
  2263. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2265. return
  2266. } else if nurse == nil {
  2267. c.ErrorLog("护士不存在")
  2268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2269. return
  2270. }
  2271. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2272. if parseEndDateErr != nil {
  2273. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2275. return
  2276. }
  2277. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  2278. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  2279. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2280. // if getPermissionErr != nil {
  2281. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2282. // return
  2283. // } else if headNursePermission == nil {
  2284. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2285. // return
  2286. // }
  2287. //}
  2288. dialysisRecord := &models.DialysisOrder{
  2289. ID: record_id,
  2290. UserOrgId: adminUserInfo.Org.Id,
  2291. EndTime: endDate.Unix(),
  2292. FinishNurse: nurseID,
  2293. FinishModifier: adminUserInfo.AdminUser.Id,
  2294. }
  2295. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  2296. if updateErr != nil {
  2297. c.ErrorLog("修改下机失败:%v", updateErr)
  2298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2299. return
  2300. }
  2301. if updateErr == nil {
  2302. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  2303. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2304. a, b := math.Modf(value)
  2305. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2306. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2307. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  2308. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  2309. if updateAssessmentErr != nil {
  2310. utils.ErrorLog("%v", updateAssessmentErr)
  2311. }
  2312. }
  2313. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2314. c.ServeSuccessJSON(map[string]interface{}{
  2315. "dialysis_order": dialysisRecords,
  2316. })
  2317. }
  2318. func (c *DialysisAPIController) GetLongAdvice() {
  2319. patient_id, _ := c.GetInt64("id")
  2320. adminUserInfo := c.GetMobileAdminUserInfo()
  2321. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  2322. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  2323. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  2324. c.ServeSuccessJSON(map[string]interface{}{
  2325. "status": "1",
  2326. })
  2327. return
  2328. } else { //开启推送提醒
  2329. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  2330. var advice_three []*models.DoctorAdvice
  2331. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  2332. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id)
  2333. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id)
  2334. for _, advice := range advices {
  2335. if advice.FrequencyType == 3 {
  2336. t := time.Now()
  2337. week := int(t.Weekday())
  2338. fmt.Println(t.Weekday())
  2339. fmt.Println(week)
  2340. switch week {
  2341. case 1:
  2342. if strings.Index(advice.WeekDay, "周一") == -1 {
  2343. advice_three = append(advice_three, advice)
  2344. }
  2345. break
  2346. case 2:
  2347. if strings.Index(advice.WeekDay, "周二") == -1 {
  2348. advice_three = append(advice_three, advice)
  2349. }
  2350. break
  2351. case 3:
  2352. if strings.Index(advice.WeekDay, "周三") == -1 {
  2353. advice_three = append(advice_three, advice)
  2354. }
  2355. break
  2356. case 4:
  2357. if strings.Index(advice.WeekDay, "周四") == -1 {
  2358. advice_three = append(advice_three, advice)
  2359. }
  2360. break
  2361. case 5:
  2362. if strings.Index(advice.WeekDay, "周五") == -1 {
  2363. advice_three = append(advice_three, advice)
  2364. }
  2365. break
  2366. case 6:
  2367. if strings.Index(advice.WeekDay, "周六") == -1 {
  2368. advice_three = append(advice_three, advice)
  2369. }
  2370. break
  2371. case 0:
  2372. if strings.Index(advice.WeekDay, "周日") == -1 {
  2373. advice_three = append(advice_three, advice)
  2374. }
  2375. break
  2376. }
  2377. }
  2378. }
  2379. for _, advice := range advices_two {
  2380. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  2381. now := p.Unix()
  2382. dayStr := strconv.FormatInt(advice.DayCount, 10)
  2383. dayStr2 := "-" + dayStr
  2384. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  2385. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  2386. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  2387. for _, ad := range advices {
  2388. advice_three = append(advice_three, ad)
  2389. }
  2390. }
  2391. if err == nil {
  2392. c.ServeSuccessJSON(map[string]interface{}{
  2393. "status": "2",
  2394. "advices": advices,
  2395. "advices_two": RemoveRepeatedElement(advice_three),
  2396. "is_open_remind": config.IsOpenRemind,
  2397. })
  2398. }
  2399. }
  2400. }
  2401. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  2402. newArr = make([]*models.DoctorAdvice, 0)
  2403. for i := 0; i < len(arr); i++ {
  2404. repeat := false
  2405. for j := i + 1; j < len(arr); j++ {
  2406. if arr[i].ID == arr[j].ID {
  2407. repeat = true
  2408. break
  2409. }
  2410. }
  2411. if !repeat {
  2412. newArr = append(newArr, arr[i])
  2413. }
  2414. }
  2415. return
  2416. }
  2417. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  2418. patient, _ := c.GetInt64("id", 0)
  2419. groupNo, _ := c.GetInt64("groupno", 0)
  2420. if patient <= 0 {
  2421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2422. return
  2423. }
  2424. adminUserInfo := c.GetMobileAdminUserInfo()
  2425. dataBody := make(map[string]interface{}, 0)
  2426. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2427. if err != nil {
  2428. utils.ErrorLog(err.Error())
  2429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2430. return
  2431. }
  2432. utils.ErrorLog("%v", dataBody)
  2433. timeLayout := "2006-01-02 15:04"
  2434. loc, _ := time.LoadLocation("Local")
  2435. timeLayout2 := "2006-01-02"
  2436. loc2, _ := time.LoadLocation("Local")
  2437. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2438. utils.ErrorLog("advice_type")
  2439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2440. return
  2441. }
  2442. adviceType := int64(2)
  2443. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2444. utils.ErrorLog("advice_date")
  2445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2446. return
  2447. }
  2448. adviceDate, _ := dataBody["advice_date"].(string)
  2449. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  2450. AdviceDate := theTime.Unix()
  2451. RecordDate := theTime.Unix()
  2452. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2453. utils.ErrorLog("start_time")
  2454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2455. return
  2456. }
  2457. startTime, _ := dataBody["start_time"].(string)
  2458. if len(startTime) == 0 {
  2459. utils.ErrorLog("len(start_time) == 0")
  2460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2461. return
  2462. }
  2463. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  2464. if err != nil {
  2465. utils.ErrorLog(err.Error())
  2466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2467. return
  2468. }
  2469. StartTime := theTime.Unix()
  2470. Remark := ""
  2471. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2472. remark, _ := dataBody["remark"].(string)
  2473. Remark = remark
  2474. }
  2475. var advices []*models.GroupAdvice
  2476. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  2477. utils.ErrorLog("advices")
  2478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2479. return
  2480. }
  2481. adviceNames := dataBody["advices"].([]interface{})
  2482. for _, adviceNameMap := range adviceNames {
  2483. adviceNameM := adviceNameMap.(map[string]interface{})
  2484. var advice models.GroupAdvice
  2485. advice.Remark = Remark
  2486. advice.AdviceType = adviceType
  2487. advice.StartTime = StartTime
  2488. advice.AdviceDate = AdviceDate
  2489. advice.RecordDate = RecordDate
  2490. advice.Status = 1
  2491. advice.CreatedTime = time.Now().Unix()
  2492. advice.UpdatedTime = time.Now().Unix()
  2493. advice.StopState = 2
  2494. advice.ExecutionState = 2
  2495. advice.UserOrgId = adminUserInfo.Org.Id
  2496. advice.PatientId = patient
  2497. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2498. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  2499. utils.ErrorLog("advice_name")
  2500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2501. return
  2502. }
  2503. adviceName, _ := adviceNameM["advice_name"].(string)
  2504. if len(adviceName) == 0 {
  2505. utils.ErrorLog("len(advice_name) == 0")
  2506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2507. return
  2508. }
  2509. advice.AdviceName = adviceName
  2510. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  2511. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  2512. advice.DrugSpec = drugSpec
  2513. }
  2514. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  2515. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  2516. advice.AdviceDesc = adviceDesc
  2517. }
  2518. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  2519. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  2520. advice.DrugSpecUnit = drugSpecUnit
  2521. }
  2522. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  2523. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  2524. // advice.SingleDose = singleDose
  2525. //}
  2526. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  2527. //single_dose := int64(adviceNameM["single_dose"].(float64))
  2528. advice.SingleDose = adviceNameM["single_dose"].(float64)
  2529. }
  2530. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  2531. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  2532. advice.SingleDoseUnit = singleDoseUnit
  2533. }
  2534. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  2535. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  2536. // advice.PrescribingNumber = prescribingNumber
  2537. //}
  2538. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  2539. //single_dose := int64(adviceNameM["single_dose"].(float64))
  2540. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  2541. }
  2542. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  2543. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  2544. advice.PrescribingNumberUnit = prescribingNumberUnit
  2545. }
  2546. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  2547. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  2548. advice.DeliveryWay = deliveryWay
  2549. }
  2550. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  2551. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2552. advice.ExecutionFrequency = executionFrequency
  2553. }
  2554. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  2555. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  2556. advice.FrequencyType = frequency_type
  2557. }
  2558. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  2559. day_count := int64(adviceNameM["day_count"].(float64))
  2560. advice.DayCount = day_count
  2561. }
  2562. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  2563. week_day, _ := adviceNameM["week_day"].(string)
  2564. advice.WeekDay = week_day
  2565. }
  2566. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  2567. way := int64(adviceNameM["way"].(float64))
  2568. advice.Way = way
  2569. }
  2570. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  2571. drug_id := int64(adviceNameM["drug_id"].(float64))
  2572. advice.DrugId = drug_id
  2573. }
  2574. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  2575. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  2576. advice.DrugNameId = drug_name_id
  2577. }
  2578. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  2579. template_id, _ := adviceNameM["template_id"].(string)
  2580. advice.TemplateId = template_id
  2581. }
  2582. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  2583. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2584. advice.ExecutionFrequency = executionFrequency
  2585. }
  2586. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  2587. children := adviceNameM["child"].([]interface{})
  2588. if len(children) > 0 {
  2589. for _, childrenMap := range children {
  2590. childMap := childrenMap.(map[string]interface{})
  2591. var child models.GroupAdvice
  2592. child.Remark = Remark
  2593. child.AdviceType = adviceType
  2594. child.StartTime = StartTime
  2595. child.AdviceDate = AdviceDate
  2596. child.RecordDate = RecordDate
  2597. child.Status = 1
  2598. child.CreatedTime = time.Now().Unix()
  2599. child.UpdatedTime = time.Now().Unix()
  2600. child.StopState = 2
  2601. child.ExecutionState = 2
  2602. child.UserOrgId = adminUserInfo.Org.Id
  2603. child.PatientId = patient
  2604. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  2605. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  2606. utils.ErrorLog("child advice_name")
  2607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2608. return
  2609. }
  2610. childAdviceName, _ := childMap["advice_name"].(string)
  2611. if len(childAdviceName) == 0 {
  2612. utils.ErrorLog("len(child advice_name) == 0")
  2613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2614. return
  2615. }
  2616. child.AdviceName = childAdviceName
  2617. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  2618. childAdviceDesc, _ := childMap["advice_desc"].(string)
  2619. child.AdviceDesc = childAdviceDesc
  2620. }
  2621. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  2622. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  2623. child.DrugSpec = childDrugSpec
  2624. }
  2625. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  2626. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  2627. child.DrugSpecUnit = childDrugSpecUnit
  2628. }
  2629. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  2630. child.SingleDose = childMap["single_dose"].(float64)
  2631. }
  2632. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  2633. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  2634. child.SingleDoseUnit = childSingleDoseUnit
  2635. }
  2636. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  2637. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  2638. }
  2639. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  2640. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  2641. child.PrescribingNumberUnit = childPrescribingNumberUnit
  2642. }
  2643. child.DeliveryWay = advice.DeliveryWay
  2644. child.ExecutionFrequency = advice.ExecutionFrequency
  2645. advice.Children = append(advice.Children, &child)
  2646. }
  2647. }
  2648. }
  2649. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  2650. if temp_advice.ID == 0 {
  2651. advices = append(advices, &advice)
  2652. }
  2653. }
  2654. if len(advices) > 0 {
  2655. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  2656. if err != nil {
  2657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2658. return
  2659. }
  2660. c.ServeSuccessJSON(map[string]interface{}{
  2661. "msg": "ok",
  2662. "advices": list,
  2663. })
  2664. } else {
  2665. c.ServeSuccessJSON(map[string]interface{}{
  2666. "msg": "ok",
  2667. })
  2668. }
  2669. return
  2670. }
  2671. func (c *DialysisAPIController) UploadDryWeight() {
  2672. patient_id, _ := c.GetInt64("id")
  2673. dry_weight, _ := c.GetFloat("dry_weight")
  2674. doctor_id, _ := c.GetInt64("doctor_id")
  2675. remark := c.GetString("remark")
  2676. adminUserInfo := c.GetMobileAdminUserInfo()
  2677. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  2678. if err == gorm.ErrRecordNotFound {
  2679. dryWeight := &models.SgjPatientDryweight{
  2680. PatientId: patient_id,
  2681. DryWeight: dry_weight,
  2682. Remakes: remark,
  2683. Ctime: time.Now().Unix(),
  2684. Mtime: time.Now().Unix(),
  2685. Creator: doctor_id,
  2686. Status: 1,
  2687. UserOrgId: adminUserInfo.Org.Id,
  2688. AdjustedValue: "/",
  2689. UserId: adminUserInfo.AdminUser.Id,
  2690. }
  2691. createErr := service.CreatePatientWeightAdjust(dryWeight)
  2692. if createErr == nil {
  2693. c.ServeSuccessJSON(map[string]interface{}{
  2694. "msg": "提交成功",
  2695. "weight": dryWeight,
  2696. })
  2697. }
  2698. } else {
  2699. dryWeight := &models.SgjPatientDryweight{
  2700. PatientId: patient_id,
  2701. DryWeight: dry_weight,
  2702. Remakes: remark,
  2703. Ctime: time.Now().Unix(),
  2704. Mtime: time.Now().Unix(),
  2705. Creator: doctor_id,
  2706. Status: 1,
  2707. UserOrgId: adminUserInfo.Org.Id,
  2708. AdjustedValue: "/",
  2709. UserId: adminUserInfo.AdminUser.Id,
  2710. }
  2711. var value float64
  2712. value = dry_weight - weightAdjust.DryWeight
  2713. if value < 0 {
  2714. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  2715. } else if value == 0 {
  2716. dryWeight.AdjustedValue = "/"
  2717. } else if value > 0 {
  2718. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  2719. }
  2720. createErr := service.CreatePatientWeightAdjust(dryWeight)
  2721. if createErr == nil {
  2722. c.ServeSuccessJSON(map[string]interface{}{
  2723. "msg": "提交成功",
  2724. "weight": dryWeight,
  2725. })
  2726. }
  2727. }
  2728. }
  2729. func (c *DialysisAPIController) GetSolution() {
  2730. patient_id, _ := c.GetInt64("patient_id")
  2731. mode_id, _ := c.GetInt64("mode_id")
  2732. adminUserInfo := c.GetMobileAdminUserInfo()
  2733. solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  2734. prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  2735. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, mode_id)
  2736. if err != nil {
  2737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2738. return
  2739. }
  2740. c.ServeSuccessJSON(map[string]interface{}{
  2741. "solution": solution,
  2742. "prescription": prescription,
  2743. "system_prescription": system_prescription,
  2744. })
  2745. }
  2746. func (c *DialysisAPIController) GetSchedule() {
  2747. schedual_type, _ := c.GetInt64("schedual_type")
  2748. adminUserInfo := c.GetMobileAdminUserInfo()
  2749. //timeLayout := "2006-01-02 15:04:05"
  2750. //
  2751. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  2752. //loc, _ := time.LoadLocation("Local")
  2753. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  2754. //scheduleTime := theStartTime.Unix()
  2755. scheduleTime, _ := c.GetInt64("record_date")
  2756. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  2757. c.ServeSuccessJSON(map[string]interface{}{
  2758. "number": deviceNumber,
  2759. })
  2760. }
  2761. func (c *DialysisAPIController) GetPatientId() {
  2762. id, _ := c.GetInt64("id")
  2763. patientId, _ := service.GetPatientId(id)
  2764. //获取该患者的所有传染病
  2765. list, _ := service.GetPatientInfectious(id)
  2766. c.ServeSuccessJSON(map[string]interface{}{
  2767. "patient": patientId,
  2768. "infectioulist": list,
  2769. })
  2770. }
  2771. func (this *DialysisAPIController) GetDialysisSchedule() {
  2772. schedualDate := this.GetString("date")
  2773. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  2774. if parseDateErr != nil {
  2775. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2776. return
  2777. }
  2778. adminInfo := this.GetMobileAdminUserInfo()
  2779. orgID := adminInfo.Org.Id
  2780. redis := service.RedisClient()
  2781. defer redis.Close()
  2782. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  2783. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  2784. if len(scheduals) > 0 {
  2785. //缓存数据
  2786. scheduals_json, err := json.Marshal(scheduals)
  2787. if err == nil {
  2788. redis.Set(key, scheduals_json, time.Second*30)
  2789. }
  2790. }
  2791. this.ServeSuccessJSON(map[string]interface{}{
  2792. "scheduals": scheduals,
  2793. })
  2794. }
  2795. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  2796. change_type, _ := this.GetInt64("type", 0)
  2797. record_date := this.GetString("record_time")
  2798. patient_id, _ := this.GetInt64("patient_id", 0)
  2799. timeLayout := "2006-01-02"
  2800. loc, _ := time.LoadLocation("Local")
  2801. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2802. record_time := theAdviceRecordTime.Unix()
  2803. adminUserInfo := this.GetMobileAdminUserInfo()
  2804. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  2805. if err == nil {
  2806. if len(advices) == 0 {
  2807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  2808. return
  2809. } else {
  2810. this.ServeSuccessJSON(map[string]interface{}{
  2811. "advices": advices,
  2812. "schedule": sch,
  2813. })
  2814. return
  2815. }
  2816. } else {
  2817. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2818. return
  2819. }
  2820. }
  2821. func (c *DialysisAPIController) CreateConsumables() {
  2822. record_date := c.GetString("record_time")
  2823. patient_id, _ := c.GetInt64("patient_id", 0)
  2824. adminUser := c.GetMobileAdminUserInfo()
  2825. timeLayout := "2006-01-02"
  2826. loc, _ := time.LoadLocation("Local")
  2827. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2828. record_time := theRecordTime.Unix()
  2829. dataBody := make(map[string]interface{}, 0)
  2830. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2831. if err != nil {
  2832. utils.ErrorLog(err.Error())
  2833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2834. return
  2835. }
  2836. var beforePrepares []*models.DialysisBeforePrepare
  2837. var updateBeforePrepares []*models.DialysisBeforePrepare
  2838. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  2839. goods, _ := dataBody["goods"].([]interface{})
  2840. if len(goods) > 0 {
  2841. for _, item := range goods {
  2842. items := item.(map[string]interface{})
  2843. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2844. utils.ErrorLog("good_id")
  2845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2846. return
  2847. }
  2848. good_id := int64(items["good_id"].(float64))
  2849. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2850. utils.ErrorLog("good_type_id")
  2851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2852. return
  2853. }
  2854. good_type_id := int64(items["good_type_id"].(float64))
  2855. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2856. utils.ErrorLog("count")
  2857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2858. return
  2859. }
  2860. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2861. commdity_code := items["commdity_code"].(string)
  2862. adminUser := c.GetMobileAdminUserInfo()
  2863. prepare := &models.DialysisBeforePrepare{
  2864. UserOrgId: adminUser.Org.Id,
  2865. PatientId: patient_id,
  2866. RecordDate: record_time,
  2867. GoodId: good_id,
  2868. GoodTypeId: good_type_id,
  2869. Count: count,
  2870. Ctime: time.Now().Unix(),
  2871. Mtime: time.Now().Unix(),
  2872. Creater: adminUser.AdminUser.Id,
  2873. Modifier: 0,
  2874. CommdityCode: commdity_code,
  2875. }
  2876. //问题点
  2877. record_count := service.FindDialysisBeforePrepare(prepare.PatientId, prepare.GoodId, prepare.GoodTypeId, adminUser.Org.Id, record_time)
  2878. if record_count == 0 {
  2879. beforePrepares = append(beforePrepares, prepare)
  2880. }
  2881. }
  2882. }
  2883. }
  2884. if len(beforePrepares) > 0 {
  2885. service.CreateDialysisBeforePrepare(beforePrepares)
  2886. }
  2887. var errs error
  2888. if dataBody["update_goods"] != nil && reflect.TypeOf(dataBody["update_goods"]).String() == "[]interface {}" {
  2889. goods, _ := dataBody["update_goods"].([]interface{})
  2890. if len(goods) > 0 {
  2891. for _, item := range goods {
  2892. items := item.(map[string]interface{})
  2893. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  2894. utils.ErrorLog("record_time")
  2895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2896. return
  2897. }
  2898. record_time := int64(items["record_time"].(float64))
  2899. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2900. utils.ErrorLog("id")
  2901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2902. return
  2903. }
  2904. id := int64(items["id"].(float64))
  2905. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  2906. utils.ErrorLog("patient_id")
  2907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2908. return
  2909. }
  2910. patient_id := int64(items["patient_id"].(float64))
  2911. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  2912. utils.ErrorLog("creater")
  2913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2914. return
  2915. }
  2916. creater := int64(items["creater"].(float64))
  2917. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2918. utils.ErrorLog("good_id")
  2919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2920. return
  2921. }
  2922. good_id := int64(items["good_id"].(float64))
  2923. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2924. utils.ErrorLog("good_type_id")
  2925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2926. return
  2927. }
  2928. good_type_id := int64(items["good_type_id"].(float64))
  2929. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2930. utils.ErrorLog("count")
  2931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2932. return
  2933. }
  2934. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2935. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  2936. utils.ErrorLog("ctime")
  2937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2938. return
  2939. }
  2940. ctime := int64(items["ctime"].(float64))
  2941. commdity_code := items["commdity_code"].(string)
  2942. prepare := &models.DialysisBeforePrepare{
  2943. ID: id,
  2944. UserOrgId: adminUser.Org.Id,
  2945. PatientId: patient_id,
  2946. RecordDate: record_time,
  2947. GoodId: good_id,
  2948. GoodTypeId: good_type_id,
  2949. Count: count,
  2950. Ctime: ctime,
  2951. Mtime: time.Now().Unix(),
  2952. Creater: creater,
  2953. Modifier: adminUser.AdminUser.Id,
  2954. Status: 1,
  2955. CommdityCode: commdity_code,
  2956. }
  2957. updateBeforePrepares = append(updateBeforePrepares, prepare)
  2958. }
  2959. }
  2960. //去重
  2961. updateBeforePrepares = RemoveRepeatedGood(updateBeforePrepares)
  2962. if len(updateBeforePrepares) > 0 {
  2963. for _, item := range updateBeforePrepares {
  2964. errs = service.UpdateDialysisBeforePrepareTwo(item)
  2965. }
  2966. }
  2967. }
  2968. if errs == nil {
  2969. c.ServeSuccessJSON(map[string]interface{}{
  2970. "msg": "提交成功",
  2971. })
  2972. return
  2973. } else {
  2974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2975. return
  2976. }
  2977. }
  2978. func (c *DialysisAPIController) CreateStockOutInfo() {
  2979. patient_id, _ := c.GetInt64("patient_id", 0)
  2980. record_date := c.GetString("record_time")
  2981. if patient_id <= 0 {
  2982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2983. return
  2984. }
  2985. adminInfo := c.GetMobileAdminUserInfo()
  2986. timeLayout := "2006-01-02"
  2987. loc, _ := time.LoadLocation("Local")
  2988. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2989. record_time := theRecordTime.Unix()
  2990. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  2991. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  2992. consumables = RemoveRepeatedGood(consumables)
  2993. if record.IsOpen == 1 {
  2994. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  2995. if err == gorm.ErrRecordNotFound {
  2996. //没有记录,则创建出库单
  2997. timeStr := time.Now().Format("2006-01-02")
  2998. timeArr := strings.Split(timeStr, "-")
  2999. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  3000. total = total + 1
  3001. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3002. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3003. number = number + total
  3004. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3005. creater := adminInfo.AdminUser.Id
  3006. warehouseOut := models.WarehouseOut{
  3007. WarehouseOutOrderNumber: warehousing_out_order,
  3008. OperationTime: time.Now().Unix(),
  3009. OrgId: adminInfo.Org.Id,
  3010. Creater: creater,
  3011. Ctime: time.Now().Unix(),
  3012. Status: 1,
  3013. WarehouseOutTime: record_time,
  3014. Dealer: 0,
  3015. Manufacturer: 0,
  3016. Type: 1,
  3017. IsSys: 1,
  3018. }
  3019. err := service.AddSigleWarehouseOut(&warehouseOut)
  3020. if err != nil {
  3021. utils.TraceLog("创建出库单失败 err = %v", err)
  3022. } else {
  3023. for _, item := range consumables {
  3024. if item.Count > 0 {
  3025. warehouseOutInfo := &models.WarehouseOutInfo{
  3026. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  3027. WarehouseOutId: warehouseOut.ID,
  3028. Status: 1,
  3029. Ctime: time.Now().Unix(),
  3030. Remark: "",
  3031. OrgId: adminInfo.Org.Id,
  3032. Type: 1,
  3033. Manufacturer: 0,
  3034. Dealer: 0,
  3035. IsSys: 1,
  3036. SysRecordTime: record_time,
  3037. GoodTypeId: item.GoodTypeId,
  3038. GoodId: item.GoodId,
  3039. }
  3040. warehouseOutInfo.Count = item.Count
  3041. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3042. warehouseOutInfo.Price = stockInInfo.Price
  3043. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3044. if err == nil {
  3045. details := &models.AutomaticReduceDetail{
  3046. WarehouseOutId: warehouseOutInfo.ID,
  3047. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3048. PatientId: patient_id,
  3049. Ctime: time.Now().Unix(),
  3050. Mtime: time.Now().Unix(),
  3051. Status: 1,
  3052. RecordTime: record_time,
  3053. OrgId: adminInfo.Org.Id,
  3054. GoodId: item.GoodId,
  3055. GoodTypeId: item.GoodTypeId,
  3056. Count: item.Count,
  3057. }
  3058. service.AddSigleAutoReduceRecordInfo(details)
  3059. }
  3060. }
  3061. }
  3062. }
  3063. } else if err == nil {
  3064. for _, item := range consumables {
  3065. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  3066. if err == gorm.ErrRecordNotFound {
  3067. warehouseOutInfo := &models.WarehouseOutInfo{
  3068. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3069. WarehouseOutId: out.ID,
  3070. Status: 1,
  3071. Ctime: time.Now().Unix(),
  3072. Remark: "",
  3073. OrgId: adminInfo.Org.Id,
  3074. Type: 1,
  3075. Manufacturer: 0,
  3076. Dealer: 0,
  3077. IsSys: 1,
  3078. SysRecordTime: record_time,
  3079. }
  3080. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3081. warehouseOutInfo.Price = stockInInfo.Price
  3082. warehouseOutInfo.GoodId = item.GoodId
  3083. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  3084. warehouseOutInfo.Count = item.Count
  3085. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3086. if err == nil {
  3087. details := &models.AutomaticReduceDetail{
  3088. WarehouseOutId: warehouseOutInfo.ID,
  3089. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3090. PatientId: patient_id,
  3091. Ctime: time.Now().Unix(),
  3092. Mtime: time.Now().Unix(),
  3093. Status: 1,
  3094. RecordTime: record_time,
  3095. OrgId: adminInfo.Org.Id,
  3096. GoodId: item.GoodId,
  3097. GoodTypeId: item.GoodTypeId,
  3098. Count: item.Count,
  3099. }
  3100. service.AddSigleAutoReduceRecordInfo(details)
  3101. }
  3102. } else if err == nil { //记录存在,则将增加数量
  3103. if outInfo.ID > 0 {
  3104. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  3105. }
  3106. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  3107. if count == 0 {
  3108. details := &models.AutomaticReduceDetail{
  3109. WarehouseOutId: outInfo.ID,
  3110. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3111. PatientId: patient_id,
  3112. Ctime: time.Now().Unix(),
  3113. Mtime: time.Now().Unix(),
  3114. Status: 1,
  3115. RecordTime: record_time,
  3116. OrgId: adminInfo.Org.Id,
  3117. GoodId: item.GoodId,
  3118. GoodTypeId: item.GoodTypeId,
  3119. Count: item.Count,
  3120. }
  3121. service.AddSigleAutoReduceRecordInfo(details)
  3122. } else if count == 1 {
  3123. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  3124. }
  3125. }
  3126. }
  3127. }
  3128. c.ServeSuccessJSON(map[string]interface{}{
  3129. "msg": "提交成功",
  3130. })
  3131. return
  3132. } else {
  3133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  3134. return
  3135. }
  3136. }
  3137. func (c *DialysisAPIController) EditConsumables() {
  3138. patient_id, _ := c.GetInt64("patient_id", 0)
  3139. record_date := c.GetString("record_time")
  3140. if patient_id <= 0 {
  3141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3142. return
  3143. }
  3144. adminInfo := c.GetMobileAdminUserInfo()
  3145. timeLayout := "2006-01-02"
  3146. loc, _ := time.LoadLocation("Local")
  3147. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3148. record_time := theRecordTime.Unix()
  3149. dataBody := make(map[string]interface{}, 0)
  3150. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3151. if err != nil {
  3152. utils.ErrorLog(err.Error())
  3153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3154. return
  3155. }
  3156. var beforePrepares []*models.DialysisBeforePrepare
  3157. var newBeforePrepares []*models.DialysisBeforePrepare
  3158. //判断是否开启自动出库
  3159. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  3160. if record.IsOpen == 1 {
  3161. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3162. goods, _ := dataBody["goods"].([]interface{})
  3163. if len(goods) > 0 {
  3164. for _, item := range goods {
  3165. items := item.(map[string]interface{})
  3166. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  3167. utils.ErrorLog("record_time")
  3168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3169. return
  3170. }
  3171. record_time := int64(items["record_time"].(float64))
  3172. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3173. utils.ErrorLog("id")
  3174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3175. return
  3176. }
  3177. id := int64(items["id"].(float64))
  3178. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  3179. utils.ErrorLog("patient_id")
  3180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3181. return
  3182. }
  3183. patient_id := int64(items["patient_id"].(float64))
  3184. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  3185. utils.ErrorLog("creater")
  3186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3187. return
  3188. }
  3189. creater := int64(items["creater"].(float64))
  3190. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3191. utils.ErrorLog("good_id")
  3192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3193. return
  3194. }
  3195. good_id := int64(items["good_id"].(float64))
  3196. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3197. utils.ErrorLog("good_type_id")
  3198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3199. return
  3200. }
  3201. good_type_id := int64(items["good_type_id"].(float64))
  3202. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3203. utils.ErrorLog("count")
  3204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3205. return
  3206. }
  3207. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3208. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  3209. utils.ErrorLog("ctime")
  3210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3211. return
  3212. }
  3213. ctime := int64(items["ctime"].(float64))
  3214. commdity_code := items["commdity_code"].(string)
  3215. adminUser := c.GetMobileAdminUserInfo()
  3216. prepare := &models.DialysisBeforePrepare{
  3217. ID: id,
  3218. UserOrgId: adminUser.Org.Id,
  3219. PatientId: patient_id,
  3220. RecordDate: record_time,
  3221. GoodId: good_id,
  3222. GoodTypeId: good_type_id,
  3223. Count: count,
  3224. Ctime: ctime,
  3225. Mtime: time.Now().Unix(),
  3226. Creater: creater,
  3227. Modifier: adminUser.AdminUser.Id,
  3228. Status: 1,
  3229. CommdityCode: commdity_code,
  3230. }
  3231. beforePrepares = append(beforePrepares, prepare)
  3232. }
  3233. }
  3234. }
  3235. //查询今日患者出库列表
  3236. consumables_source, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  3237. if dataBody["new_goods"] != nil && reflect.TypeOf(dataBody["new_goods"]).String() == "[]interface {}" {
  3238. goods, _ := dataBody["new_goods"].([]interface{})
  3239. if len(goods) > 0 {
  3240. for _, item := range goods {
  3241. items := item.(map[string]interface{})
  3242. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3243. utils.ErrorLog("good_id")
  3244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3245. return
  3246. }
  3247. good_id := int64(items["good_id"].(float64))
  3248. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3249. utils.ErrorLog("good_type_id")
  3250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3251. return
  3252. }
  3253. good_type_id := int64(items["good_type_id"].(float64))
  3254. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3255. utils.ErrorLog("count")
  3256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3257. return
  3258. }
  3259. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3260. commdity_code := items["commdity_code"].(string)
  3261. fmt.Println("commdityecode", commdity_code)
  3262. adminUser := c.GetMobileAdminUserInfo()
  3263. prepare := &models.DialysisBeforePrepare{
  3264. UserOrgId: adminUser.Org.Id,
  3265. PatientId: patient_id,
  3266. RecordDate: record_time,
  3267. GoodId: good_id,
  3268. GoodTypeId: good_type_id,
  3269. Count: count,
  3270. Ctime: time.Now().Unix(),
  3271. Mtime: time.Now().Unix(),
  3272. Creater: adminUser.AdminUser.Id,
  3273. Modifier: 0,
  3274. CommdityCode: commdity_code,
  3275. }
  3276. newBeforePrepares = append(newBeforePrepares, prepare)
  3277. }
  3278. newBeforePrepares = RemoveRepeatedGood(newBeforePrepares)
  3279. }
  3280. //创建数据
  3281. service.CreateDialysisBeforePrepare(newBeforePrepares)
  3282. }
  3283. //查询是否有出库单
  3284. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  3285. if err == gorm.ErrRecordNotFound {
  3286. //没有记录,则创建出库单
  3287. timeStr := time.Now().Format("2006-01-02")
  3288. timeArr := strings.Split(timeStr, "-")
  3289. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  3290. total = total + 1
  3291. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3292. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3293. number = number + total
  3294. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3295. creater := adminInfo.AdminUser.Id
  3296. warehouseOut := models.WarehouseOut{
  3297. WarehouseOutOrderNumber: warehousing_out_order,
  3298. OperationTime: time.Now().Unix(),
  3299. OrgId: adminInfo.Org.Id,
  3300. Creater: creater,
  3301. Ctime: time.Now().Unix(),
  3302. Status: 1,
  3303. WarehouseOutTime: record_time,
  3304. Dealer: 0,
  3305. Manufacturer: 0,
  3306. Type: 1,
  3307. IsSys: 1,
  3308. }
  3309. //创建出库单
  3310. err := service.AddSigleWarehouseOut(&warehouseOut)
  3311. fmt.Println("err", err)
  3312. if err != nil {
  3313. utils.TraceLog("创建出库单失败 err = %v", err)
  3314. } else {
  3315. for _, item := range beforePrepares {
  3316. if item.Count > 0 {
  3317. warehouseOutInfo := &models.WarehouseOutInfo{
  3318. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  3319. WarehouseOutId: warehouseOut.ID,
  3320. Count: 1,
  3321. Status: 1,
  3322. Ctime: time.Now().Unix(),
  3323. Remark: "",
  3324. OrgId: adminInfo.Org.Id,
  3325. Type: 1,
  3326. Manufacturer: 0,
  3327. Dealer: 0,
  3328. IsSys: 1,
  3329. SysRecordTime: record_time,
  3330. GoodTypeId: item.GoodTypeId,
  3331. GoodId: item.GoodId,
  3332. }
  3333. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3334. warehouseOutInfo.Price = stockInInfo.Price
  3335. //创建出库详情
  3336. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3337. if err == nil {
  3338. details := &models.AutomaticReduceDetail{
  3339. WarehouseOutId: warehouseOutInfo.ID,
  3340. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3341. PatientId: patient_id,
  3342. Ctime: time.Now().Unix(),
  3343. Mtime: time.Now().Unix(),
  3344. Status: 1,
  3345. RecordTime: record_time,
  3346. OrgId: adminInfo.Org.Id,
  3347. GoodId: item.GoodId,
  3348. GoodTypeId: item.GoodTypeId,
  3349. }
  3350. service.AddSigleAutoReduceRecordInfo(details)
  3351. }
  3352. }
  3353. }
  3354. }
  3355. //没有出库单创建
  3356. } else if err == nil {
  3357. if len(newBeforePrepares) > 0 { //新增
  3358. for _, item := range newBeforePrepares {
  3359. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  3360. if err == gorm.ErrRecordNotFound {
  3361. warehouseOutInfo := &models.WarehouseOutInfo{
  3362. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3363. WarehouseOutId: out.ID,
  3364. Status: 1,
  3365. Ctime: time.Now().Unix(),
  3366. Remark: "",
  3367. OrgId: adminInfo.Org.Id,
  3368. Type: 1,
  3369. Manufacturer: 0,
  3370. Dealer: 0,
  3371. IsSys: 1,
  3372. SysRecordTime: record_time,
  3373. }
  3374. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3375. warehouseOutInfo.Price = stockInInfo.Price
  3376. warehouseOutInfo.GoodId = item.GoodId
  3377. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  3378. warehouseOutInfo.Count = item.Count
  3379. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3380. if err == nil {
  3381. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  3382. if count == 0 {
  3383. details := &models.AutomaticReduceDetail{
  3384. WarehouseOutId: warehouseOutInfo.ID,
  3385. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3386. PatientId: patient_id,
  3387. Ctime: time.Now().Unix(),
  3388. Mtime: time.Now().Unix(),
  3389. Status: 1,
  3390. RecordTime: record_time,
  3391. OrgId: adminInfo.Org.Id,
  3392. GoodId: item.GoodId,
  3393. GoodTypeId: item.GoodTypeId,
  3394. Count: item.Count,
  3395. }
  3396. service.AddSigleAutoReduceRecordInfo(details)
  3397. } else if count == 1 {
  3398. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  3399. }
  3400. }
  3401. } else if err == nil { //记录存在,则将加数量
  3402. if outInfo.ID > 0 {
  3403. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  3404. }
  3405. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  3406. if count == 0 {
  3407. details := &models.AutomaticReduceDetail{
  3408. WarehouseOutId: outInfo.ID,
  3409. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3410. PatientId: patient_id,
  3411. Ctime: time.Now().Unix(),
  3412. Mtime: time.Now().Unix(),
  3413. Status: 1,
  3414. RecordTime: record_time,
  3415. OrgId: adminInfo.Org.Id,
  3416. GoodId: item.GoodId,
  3417. GoodTypeId: item.GoodTypeId,
  3418. Count: item.Count,
  3419. }
  3420. service.AddSigleAutoReduceRecordInfo(details)
  3421. } else if count == 1 {
  3422. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  3423. }
  3424. //details := &models.AutomaticReduceDetail{
  3425. // WarehouseOutId: outInfo.ID,
  3426. // WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3427. // PatientId: patient_id,
  3428. // Ctime: time.Now().Unix(),
  3429. // Mtime: time.Now().Unix(),
  3430. // Status: 1,
  3431. // RecordTime: record_time,
  3432. // OrgId: adminInfo.Org.Id,
  3433. // GoodId: item.GoodId,
  3434. // GoodTypeId: item.GoodTypeId,
  3435. // Count: item.Count,
  3436. //}
  3437. //service.AddSigleAutoReduceRecordInfo(details)
  3438. }
  3439. }
  3440. }
  3441. if len(beforePrepares) > 0 { //修改
  3442. for _, consumable := range consumables_source {
  3443. for _, before := range beforePrepares {
  3444. if consumable.GoodId == before.GoodId {
  3445. if consumable.Count != before.Count {
  3446. _, out := service.FindStockOutOrderNumberByTime(record_time, adminInfo.Org.Id)
  3447. //_, out := service.FindOldOrderInfoByGoodId(record_time, adminInfo.Org.Id)
  3448. //判断前端更改后的商品id的出库记录在数据库中是否存在
  3449. err, newOut := service.FindOrderInfoByGoodId(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id)
  3450. fmt.Println("err222222222222222222", err)
  3451. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  3452. warehouseOutInfo := &models.WarehouseOutInfo{
  3453. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3454. WarehouseOutId: out.ID,
  3455. Count: before.Count,
  3456. Status: 1,
  3457. Ctime: time.Now().Unix(),
  3458. Remark: "",
  3459. OrgId: adminInfo.Org.Id,
  3460. Type: 1,
  3461. Manufacturer: 0,
  3462. Dealer: 0,
  3463. IsSys: 1,
  3464. SysRecordTime: record_time,
  3465. }
  3466. stockInInfo, _ := service.FindLastStockInInfoRecord(before.GoodId, adminInfo.Org.Id)
  3467. warehouseOutInfo.Price = stockInInfo.Price
  3468. warehouseOutInfo.GoodId = before.GoodId
  3469. warehouseOutInfo.GoodTypeId = before.GoodTypeId
  3470. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3471. fmt.Println("err2223444444444444444444", err)
  3472. if err == nil {
  3473. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  3474. user, err := service.FindGoodUserById(before.GoodTypeId, before.GoodId, patient_id, adminInfo.Org.Id, record_time)
  3475. if err == gorm.ErrRecordNotFound {
  3476. details := &models.AutomaticReduceDetail{
  3477. WarehouseOutId: warehouseOutInfo.ID,
  3478. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3479. PatientId: patient_id,
  3480. Ctime: time.Now().Unix(),
  3481. Mtime: time.Now().Unix(),
  3482. Status: 1,
  3483. RecordTime: record_time,
  3484. OrgId: adminInfo.Org.Id,
  3485. GoodId: consumable.GoodId,
  3486. GoodTypeId: consumable.GoodTypeId,
  3487. Count: before.Count,
  3488. }
  3489. service.AddSigleAutoReduceRecordInfo(details)
  3490. } else if err == nil {
  3491. if user.ID > 0 {
  3492. //service.UpdateOrderInfoDetails( consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, a_liquid, warehouseOutInfo)
  3493. service.UpdateUserInfoDetails(consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, before.Count, warehouseOutInfo)
  3494. }
  3495. }
  3496. }
  3497. } else if err == nil { //存在,则更改使用人商品信息
  3498. fmt.Println("333333333")
  3499. //处理原来的数据
  3500. if newOut.ID > 0 {
  3501. if consumable.Count > before.Count { // 减少
  3502. num := int64(0)
  3503. if consumable.Count-before.Count > 0 {
  3504. num = consumable.Count - before.Count
  3505. } else {
  3506. num = before.Count - consumable.Count
  3507. }
  3508. service.UpdateOrderCountSub(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id, num)
  3509. } else if consumable.Count < before.Count { //增加
  3510. service.UpdateOrderCountAdd(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id, before.Count-consumable.Count)
  3511. }
  3512. user, err := service.FindGoodUserById(consumable.GoodTypeId, consumable.GoodId, patient_id, adminInfo.Org.Id, record_time)
  3513. if err == gorm.ErrRecordNotFound {
  3514. details := &models.AutomaticReduceDetail{
  3515. WarehouseOutId: newOut.ID,
  3516. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  3517. PatientId: patient_id,
  3518. Ctime: time.Now().Unix(),
  3519. Mtime: time.Now().Unix(),
  3520. Status: 1,
  3521. RecordTime: record_time,
  3522. OrgId: adminInfo.Org.Id,
  3523. GoodId: consumable.GoodId,
  3524. GoodTypeId: consumable.GoodTypeId,
  3525. Count: before.Count,
  3526. }
  3527. service.AddSigleAutoReduceRecordInfo(details)
  3528. } else if err == nil {
  3529. if user.ID > 0 {
  3530. service.UpdateUserInfoDetails(consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, before.Count, &newOut)
  3531. }
  3532. }
  3533. }
  3534. }
  3535. }
  3536. }
  3537. }
  3538. }
  3539. }
  3540. }
  3541. //更新自动出库的地方
  3542. var errs error
  3543. if len(beforePrepares) > 0 {
  3544. for _, item := range beforePrepares {
  3545. errs = service.UpdateDialysisBeforePrepareTwo(item)
  3546. detail := models.AutomaticReduceDetail{
  3547. PatientId: item.PatientId,
  3548. Status: 1,
  3549. RecordTime: item.RecordDate,
  3550. OrgId: item.UserOrgId,
  3551. GoodId: item.GoodId,
  3552. GoodTypeId: item.GoodTypeId,
  3553. Count: item.Count,
  3554. }
  3555. service.UpdateAutoReduceDetailSix(&detail)
  3556. }
  3557. }
  3558. if errs == nil {
  3559. c.ServeSuccessJSON(map[string]interface{}{
  3560. "msg": "修改成功",
  3561. })
  3562. return
  3563. } else {
  3564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3565. return
  3566. }
  3567. } else {
  3568. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3569. goods, _ := dataBody["goods"].([]interface{})
  3570. if len(goods) > 0 {
  3571. for _, item := range goods {
  3572. items := item.(map[string]interface{})
  3573. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  3574. utils.ErrorLog("record_time")
  3575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3576. return
  3577. }
  3578. record_time := int64(items["record_time"].(float64))
  3579. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3580. utils.ErrorLog("id")
  3581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3582. return
  3583. }
  3584. id := int64(items["id"].(float64))
  3585. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  3586. utils.ErrorLog("patient_id")
  3587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3588. return
  3589. }
  3590. patient_id := int64(items["patient_id"].(float64))
  3591. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  3592. utils.ErrorLog("creater")
  3593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3594. return
  3595. }
  3596. creater := int64(items["creater"].(float64))
  3597. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3598. utils.ErrorLog("good_id")
  3599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3600. return
  3601. }
  3602. good_id := int64(items["good_id"].(float64))
  3603. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3604. utils.ErrorLog("good_type_id")
  3605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3606. return
  3607. }
  3608. good_type_id := int64(items["good_type_id"].(float64))
  3609. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3610. utils.ErrorLog("count")
  3611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3612. return
  3613. }
  3614. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3615. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  3616. utils.ErrorLog("ctime")
  3617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3618. return
  3619. }
  3620. ctime := int64(items["ctime"].(float64))
  3621. adminUser := c.GetMobileAdminUserInfo()
  3622. prepare := &models.DialysisBeforePrepare{
  3623. ID: id,
  3624. UserOrgId: adminUser.Org.Id,
  3625. PatientId: patient_id,
  3626. RecordDate: record_time,
  3627. GoodId: good_id,
  3628. GoodTypeId: good_type_id,
  3629. Count: count,
  3630. Ctime: ctime,
  3631. Mtime: time.Now().Unix(),
  3632. Creater: creater,
  3633. Modifier: adminUser.AdminUser.Id,
  3634. Status: 1,
  3635. }
  3636. beforePrepares = append(beforePrepares, prepare)
  3637. }
  3638. }
  3639. }
  3640. if dataBody["new_goods"] != nil && reflect.TypeOf(dataBody["new_goods"]).String() == "[]interface {}" {
  3641. goods, _ := dataBody["new_goods"].([]interface{})
  3642. if len(goods) > 0 {
  3643. for _, item := range goods {
  3644. items := item.(map[string]interface{})
  3645. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3646. utils.ErrorLog("good_id")
  3647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3648. return
  3649. }
  3650. good_id := int64(items["good_id"].(float64))
  3651. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3652. utils.ErrorLog("good_type_id")
  3653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3654. return
  3655. }
  3656. good_type_id := int64(items["good_type_id"].(float64))
  3657. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3658. utils.ErrorLog("count")
  3659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3660. return
  3661. }
  3662. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3663. adminUser := c.GetMobileAdminUserInfo()
  3664. prepare := &models.DialysisBeforePrepare{
  3665. UserOrgId: adminUser.Org.Id,
  3666. PatientId: patient_id,
  3667. RecordDate: record_time,
  3668. GoodId: good_id,
  3669. GoodTypeId: good_type_id,
  3670. Count: count,
  3671. Ctime: time.Now().Unix(),
  3672. Mtime: time.Now().Unix(),
  3673. Creater: adminUser.AdminUser.Id,
  3674. Modifier: 0,
  3675. }
  3676. newBeforePrepares = append(newBeforePrepares, prepare)
  3677. }
  3678. }
  3679. service.CreateDialysisBeforePrepare(newBeforePrepares)
  3680. }
  3681. var errs error
  3682. if len(beforePrepares) > 0 {
  3683. for _, item := range beforePrepares {
  3684. errs = service.UpdateDialysisBeforePrepareTwo(item)
  3685. }
  3686. }
  3687. if errs == nil {
  3688. c.ServeSuccessJSON(map[string]interface{}{
  3689. "msg": "修改成功",
  3690. })
  3691. return
  3692. } else {
  3693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3694. return
  3695. }
  3696. }
  3697. }
  3698. func (c *DialysisAPIController) GetDialysisGoods() {
  3699. schedualDate := c.GetString("schedule_date")
  3700. schedule_type, _ := c.GetInt64("schedule_type")
  3701. partition_id, _ := c.GetInt64("partition_id")
  3702. page, _ := c.GetInt("page")
  3703. patient_id, _ := c.GetInt64("patient_id")
  3704. schedualEndDate := int64(0)
  3705. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  3706. if parseDateErr != nil && len(schedualDate) != 0 {
  3707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3708. return
  3709. }
  3710. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  3711. if parseDateErr != nil && len(schedualDate) != 0 {
  3712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3713. return
  3714. }
  3715. schedualEndDate = endDate.Unix()
  3716. adminUser := c.GetMobileAdminUserInfo()
  3717. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  3718. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  3719. //获取当天该病人的透析处方
  3720. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  3721. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  3722. if err == gorm.ErrRecordNotFound {
  3723. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  3724. if patient_id != 0 {
  3725. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3726. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  3727. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  3728. item.LastAutomaticReduceDetail = goodUser
  3729. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3730. }
  3731. }
  3732. c.ServeSuccessJSON(map[string]interface{}{
  3733. "dialysis_goods": dialysisGoods,
  3734. "good_type": goodTypes,
  3735. "total": total,
  3736. "prescribe": prescribe,
  3737. "good_info": good_info,
  3738. })
  3739. return
  3740. } else if err == nil {
  3741. //获取当天排班的每个患者的库存使用情况
  3742. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  3743. if patient_id != 0 {
  3744. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3745. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  3746. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  3747. fmt.Println(goodUser)
  3748. fmt.Println(lastGoodUserDetial)
  3749. item.LastAutomaticReduceDetail = goodUser
  3750. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3751. }
  3752. }
  3753. if err == nil {
  3754. c.ServeSuccessJSON(map[string]interface{}{
  3755. "dialysis_goods": dialysisGoods,
  3756. "good_type": goodTypes,
  3757. "total": total,
  3758. "prescribe": prescribe,
  3759. "good_info": good_info,
  3760. })
  3761. return
  3762. } else {
  3763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3764. return
  3765. }
  3766. } else if err != nil {
  3767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3768. return
  3769. }
  3770. }
  3771. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  3772. start_time := c.GetString("start_time")
  3773. end_time := c.GetString("end_time")
  3774. timeLayout := "2006-01-02"
  3775. loc, _ := time.LoadLocation("Local")
  3776. var theStartTime int64
  3777. if len(start_time) > 0 {
  3778. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3779. if err != nil {
  3780. utils.ErrorLog(err.Error())
  3781. }
  3782. theStartTime = theTime.Unix()
  3783. }
  3784. var theEndtTime int64
  3785. if len(end_time) > 0 {
  3786. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3787. if err != nil {
  3788. utils.ErrorLog(err.Error())
  3789. }
  3790. theEndtTime = theTime.Unix()
  3791. }
  3792. adminUser := c.GetMobileAdminUserInfo()
  3793. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  3794. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  3795. if err == nil {
  3796. c.ServeSuccessJSON(map[string]interface{}{
  3797. "stock_out": outInfo,
  3798. "stockCount": stockCount,
  3799. })
  3800. return
  3801. } else {
  3802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3803. return
  3804. }
  3805. }
  3806. func (c *DialysisAPIController) GetStockInGoodInfo() {
  3807. patient_id, _ := c.GetInt64("patient_id", 0)
  3808. record_time := c.GetString("record_time")
  3809. adminUser := c.GetMobileAdminUserInfo()
  3810. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  3811. if parseDateErr != nil && len(record_time) != 0 {
  3812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3813. return
  3814. }
  3815. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  3816. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  3817. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  3818. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  3819. //获取今日患者的透析处方参数
  3820. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  3821. c.ServeSuccessJSON(map[string]interface{}{
  3822. "good_type": goodTypes,
  3823. "good_user": goodUser,
  3824. "good_info": good_info,
  3825. "last_good_user": lastGoodUserDetial,
  3826. "prescription": prescribe,
  3827. })
  3828. return
  3829. }
  3830. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  3831. patient_id, _ := c.GetInt64("patient_id", 0)
  3832. record_date := c.GetString("record_time")
  3833. if patient_id <= 0 {
  3834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3835. return
  3836. }
  3837. adminInfo := c.GetMobileAdminUserInfo()
  3838. timeLayout := "2006-01-02"
  3839. loc, _ := time.LoadLocation("Local")
  3840. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3841. record_time := theRecordTime.Unix()
  3842. dataBody := make(map[string]interface{}, 0)
  3843. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3844. if err != nil {
  3845. utils.ErrorLog(err.Error())
  3846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3847. return
  3848. }
  3849. var beforePrepares []*models.DialysisBeforePrepare
  3850. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3851. goods, _ := dataBody["goods"].([]interface{})
  3852. if len(goods) > 0 {
  3853. for _, item := range goods {
  3854. items := item.(map[string]interface{})
  3855. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3856. utils.ErrorLog("good_id")
  3857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3858. return
  3859. }
  3860. good_id := int64(items["good_id"].(float64))
  3861. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3862. utils.ErrorLog("good_type_id")
  3863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3864. return
  3865. }
  3866. good_type_id := int64(items["good_type_id"].(float64))
  3867. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3868. utils.ErrorLog("count")
  3869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3870. return
  3871. }
  3872. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3873. adminUser := c.GetMobileAdminUserInfo()
  3874. prepare := &models.DialysisBeforePrepare{
  3875. UserOrgId: adminUser.Org.Id,
  3876. PatientId: patient_id,
  3877. RecordDate: record_time,
  3878. GoodId: good_id,
  3879. GoodTypeId: good_type_id,
  3880. Count: count,
  3881. Ctime: time.Now().Unix(),
  3882. Mtime: time.Now().Unix(),
  3883. Creater: adminUser.AdminUser.Id,
  3884. Modifier: 0,
  3885. }
  3886. record_count := service.FindDialysisBeforePrepare(prepare.PatientId, prepare.GoodId, prepare.GoodTypeId, adminUser.Org.Id, record_time)
  3887. if record_count == 0 {
  3888. beforePrepares = append(beforePrepares, prepare)
  3889. } else if record_count == 1 {
  3890. service.UpdateDialysisBeforePrepareTwo(prepare)
  3891. }
  3892. }
  3893. }
  3894. }
  3895. beforePrepares = RemoveRepeatedGood(beforePrepares)
  3896. if len(beforePrepares) > 0 {
  3897. service.CreateDialysisBeforePrepare(beforePrepares)
  3898. }
  3899. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  3900. //去重
  3901. consumables = RemoveRepeatedGood(consumables)
  3902. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  3903. if record.IsOpen == 1 {
  3904. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  3905. if err == gorm.ErrRecordNotFound {
  3906. //没有记录,则创建出库单
  3907. timeStr := time.Now().Format("2006-01-02")
  3908. timeArr := strings.Split(timeStr, "-")
  3909. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  3910. total = total + 1
  3911. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3912. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3913. number = number + total
  3914. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3915. creater := adminInfo.AdminUser.Id
  3916. warehouseOut := models.WarehouseOut{
  3917. WarehouseOutOrderNumber: warehousing_out_order,
  3918. OperationTime: time.Now().Unix(),
  3919. OrgId: adminInfo.Org.Id,
  3920. Creater: creater,
  3921. Ctime: time.Now().Unix(),
  3922. Status: 1,
  3923. WarehouseOutTime: record_time,
  3924. Dealer: 0,
  3925. Manufacturer: 0,
  3926. Type: 1,
  3927. IsSys: 1,
  3928. }
  3929. err := service.AddSigleWarehouseOut(&warehouseOut)
  3930. if err != nil {
  3931. utils.TraceLog("创建出库单失败 err = %v", err)
  3932. } else {
  3933. for _, item := range consumables {
  3934. if item.Count > 0 {
  3935. warehouseOutInfo := &models.WarehouseOutInfo{
  3936. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  3937. WarehouseOutId: warehouseOut.ID,
  3938. Status: 1,
  3939. Ctime: time.Now().Unix(),
  3940. Remark: "",
  3941. OrgId: adminInfo.Org.Id,
  3942. Type: 1,
  3943. Manufacturer: 0,
  3944. Dealer: 0,
  3945. IsSys: 1,
  3946. SysRecordTime: record_time,
  3947. GoodTypeId: item.GoodTypeId,
  3948. GoodId: item.GoodId,
  3949. }
  3950. warehouseOutInfo.Count = item.Count
  3951. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3952. warehouseOutInfo.Price = stockInInfo.Price
  3953. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3954. if err == nil {
  3955. details := &models.AutomaticReduceDetail{
  3956. WarehouseOutId: warehouseOutInfo.ID,
  3957. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3958. PatientId: patient_id,
  3959. Ctime: time.Now().Unix(),
  3960. Mtime: time.Now().Unix(),
  3961. Status: 1,
  3962. RecordTime: record_time,
  3963. OrgId: adminInfo.Org.Id,
  3964. GoodId: item.GoodId,
  3965. GoodTypeId: item.GoodTypeId,
  3966. Count: item.Count,
  3967. }
  3968. service.AddSigleAutoReduceRecordInfo(details)
  3969. }
  3970. }
  3971. }
  3972. }
  3973. } else if err == nil {
  3974. for _, item := range consumables {
  3975. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  3976. if err == gorm.ErrRecordNotFound {
  3977. warehouseOutInfo := &models.WarehouseOutInfo{
  3978. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3979. WarehouseOutId: out.ID,
  3980. Status: 1,
  3981. Ctime: time.Now().Unix(),
  3982. Remark: "",
  3983. OrgId: adminInfo.Org.Id,
  3984. Type: 1,
  3985. Manufacturer: 0,
  3986. Dealer: 0,
  3987. IsSys: 1,
  3988. SysRecordTime: record_time,
  3989. }
  3990. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3991. warehouseOutInfo.Price = stockInInfo.Price
  3992. warehouseOutInfo.GoodId = item.GoodId
  3993. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  3994. warehouseOutInfo.Count = item.Count
  3995. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3996. if err == nil {
  3997. details := &models.AutomaticReduceDetail{
  3998. WarehouseOutId: warehouseOutInfo.ID,
  3999. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4000. PatientId: patient_id,
  4001. Ctime: time.Now().Unix(),
  4002. Mtime: time.Now().Unix(),
  4003. Status: 1,
  4004. RecordTime: record_time,
  4005. OrgId: adminInfo.Org.Id,
  4006. GoodId: item.GoodId,
  4007. GoodTypeId: item.GoodTypeId,
  4008. Count: item.Count,
  4009. }
  4010. service.AddSigleAutoReduceRecordInfo(details)
  4011. }
  4012. } else if err == nil { //记录存在,则将增加数量
  4013. if outInfo.ID > 0 {
  4014. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  4015. }
  4016. details := &models.AutomaticReduceDetail{
  4017. WarehouseOutId: outInfo.ID,
  4018. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  4019. PatientId: patient_id,
  4020. Ctime: time.Now().Unix(),
  4021. Mtime: time.Now().Unix(),
  4022. Status: 1,
  4023. RecordTime: record_time,
  4024. OrgId: adminInfo.Org.Id,
  4025. GoodId: item.GoodId,
  4026. GoodTypeId: item.GoodTypeId,
  4027. Count: item.Count,
  4028. }
  4029. service.AddSigleAutoReduceRecordInfo(details)
  4030. }
  4031. }
  4032. }
  4033. c.ServeSuccessJSON(map[string]interface{}{
  4034. "msg": "提交成功",
  4035. })
  4036. return
  4037. } else {
  4038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  4039. return
  4040. }
  4041. }
  4042. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  4043. newArr = make([]*models.DialysisBeforePrepare, 0)
  4044. for i := 0; i < len(arr); i++ {
  4045. repeat := false
  4046. for j := i + 1; j < len(arr); j++ {
  4047. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  4048. repeat = true
  4049. break
  4050. }
  4051. }
  4052. if !repeat {
  4053. newArr = append(newArr, arr[i])
  4054. }
  4055. }
  4056. return
  4057. }
  4058. func (c *DialysisAPIController) GetAllDrug() {
  4059. patient_id, _ := c.GetInt64("patient_id", 0)
  4060. adminInfo := c.GetMobileAdminUserInfo()
  4061. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  4062. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  4063. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  4064. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  4065. c.ServeSuccessJSON(map[string]interface{}{
  4066. "base_drug_config": drugStockConfig,
  4067. "private_drug_config": privateDrugConfig,
  4068. "base_drug_list": drugList,
  4069. "private_drug_list": privateDrugList,
  4070. })
  4071. }
  4072. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  4073. newArr = make([]*models.DialysisBeforePrepare, 0)
  4074. for i := 0; i < len(arr); i++ {
  4075. repeat := false
  4076. for j := i + 1; j < len(arr); j++ {
  4077. if arr[i].GoodId == arr[j].GoodId {
  4078. repeat = true
  4079. break
  4080. }
  4081. }
  4082. if !repeat {
  4083. newArr = append(newArr, arr[i])
  4084. }
  4085. }
  4086. return
  4087. }
  4088. func (c *DialysisAPIController) GetDepartment() {
  4089. adminInfo := c.GetMobileAdminUserInfo()
  4090. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  4091. if err == nil {
  4092. c.ServeSuccessJSON(map[string]interface{}{
  4093. "departments": departments,
  4094. })
  4095. } else {
  4096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4097. return
  4098. }
  4099. }
  4100. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  4101. types, _ := c.GetInt("type", 0)
  4102. start_time := c.GetString("start_time")
  4103. end_time := c.GetString("end_time")
  4104. orgId := c.GetMobileAdminUserInfo().Org.Id
  4105. timeLayout := "2006-01-02"
  4106. loc, _ := time.LoadLocation("Local")
  4107. var startTime int64
  4108. if len(start_time) > 0 {
  4109. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4110. if err != nil {
  4111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4112. return
  4113. }
  4114. startTime = theTime.Unix()
  4115. }
  4116. var endTime int64
  4117. if len(end_time) > 0 {
  4118. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4119. if err != nil {
  4120. utils.ErrorLog(err.Error())
  4121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4122. return
  4123. }
  4124. endTime = theTime.Unix()
  4125. }
  4126. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  4127. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  4128. if err != nil {
  4129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4130. } else {
  4131. c.ServeSuccessJSON(map[string]interface{}{
  4132. "list": list,
  4133. "type": types,
  4134. "stockTotal": stockTotal,
  4135. })
  4136. }
  4137. }
  4138. func (c *DialysisAPIController) BatchDeleteMonitor() {
  4139. fmt.Println("jin2222245555555555")
  4140. ids := c.GetString("ids")
  4141. fmt.Println("dis22222222", ids)
  4142. idArray := strings.Split(ids, ",")
  4143. err := service.BatchDeleteMonitor(idArray)
  4144. fmt.Print("err", err)
  4145. c.ServeSuccessJSON(map[string]interface{}{
  4146. "msg": "批量删除成功",
  4147. })
  4148. return
  4149. }
  4150. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  4151. id, _ := c.GetInt64("id")
  4152. fmt.Println(id)
  4153. timeLayout := "2006-01-02"
  4154. loc, _ := time.LoadLocation("Local")
  4155. start_time := time.Now().Format("2006-01-02")
  4156. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4157. fmt.Println("start_timestart_time", start_time)
  4158. nowTime := time.Now()
  4159. endTime := nowTime.AddDate(-1, 0, 0)
  4160. endTimes := endTime.Format("2006-01-02")
  4161. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", endTimes+" 00:00:00", loc)
  4162. list, _ := service.GetPatientDialysisRecordList(id, endtime.Unix(), startime.Unix())
  4163. c.ServeSuccessJSON(map[string]interface{}{
  4164. "list": list,
  4165. })
  4166. return
  4167. }
  4168. func (c *DialysisAPIController) BathDeleteAdviceList() {
  4169. dataBody := make(map[string]interface{}, 0)
  4170. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4171. ids := c.GetString("ids")
  4172. fmt.Println("dis22222222", ids)
  4173. idArray := strings.Split(ids, ",")
  4174. origin, _ := c.GetInt64("origin")
  4175. if origin == 1 {
  4176. err = service.BatchDeleteAdvice(idArray)
  4177. fmt.Print("err", err)
  4178. c.ServeSuccessJSON(map[string]interface{}{
  4179. "msg": "批量删除成功",
  4180. })
  4181. return
  4182. }
  4183. if origin == 2 {
  4184. service.BatchDeleteHisAdvice(idArray)
  4185. }
  4186. }
  4187. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  4188. good_id, _ := c.GetInt64("good_id")
  4189. count, _ := c.GetInt64("count")
  4190. record_time, _ := c.GetInt64("record_time")
  4191. patient_id, _ := c.GetInt64("patient_id")
  4192. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  4193. c.ServeSuccessJSON(map[string]interface{}{
  4194. "detail": detail,
  4195. })
  4196. return
  4197. }
  4198. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  4199. good_id, _ := c.GetInt64("good_id")
  4200. record_time, _ := c.GetInt64("record_time")
  4201. patient_id, _ := c.GetInt64("patient_id")
  4202. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  4203. fmt.Print("err", err)
  4204. c.ServeSuccessJSON(map[string]interface{}{
  4205. "msg": "批量删除成功",
  4206. })
  4207. return
  4208. }
  4209. func (c *DialysisAPIController) BatchAdviceCheck() {
  4210. ids := c.GetString("ids")
  4211. idArray := strings.Split(ids, ",")
  4212. creator, _ := c.GetInt64("creator")
  4213. origin, _ := c.GetInt64("origin")
  4214. if origin == 1 {
  4215. err := service.BatchAdviceCheck(idArray, creator)
  4216. fmt.Println(err)
  4217. list, _ := service.GetAdviceExecutionById(idArray)
  4218. c.ServeSuccessJSON(map[string]interface{}{
  4219. "list": list,
  4220. })
  4221. return
  4222. }
  4223. if origin == 2 {
  4224. service.BatchHisAdviceCheck(idArray, creator)
  4225. list, _ := service.GetHisAdviceExecutionById(idArray)
  4226. c.ServeSuccessJSON(map[string]interface{}{
  4227. "list": list,
  4228. })
  4229. return
  4230. }
  4231. }
  4232. func (c *DialysisAPIController) BatchAdviceExecution() {
  4233. ids := c.GetString("ids")
  4234. fmt.Println("dis22222222", ids)
  4235. idArray := strings.Split(ids, ",")
  4236. executionTime := c.GetString("execution_time")
  4237. fmt.Println("333333333", executionTime)
  4238. creator, _ := c.GetInt64("creator")
  4239. timeLayout := "2006-01-02 15:04:05"
  4240. loc, _ := time.LoadLocation("Local")
  4241. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  4242. orgin, _ := c.GetInt64("origin")
  4243. if orgin == 1 {
  4244. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  4245. list, _ := service.GetAdviceExecutionById(idArray)
  4246. fmt.Println(err)
  4247. c.ServeSuccessJSON(map[string]interface{}{
  4248. "list": list,
  4249. })
  4250. return
  4251. }
  4252. if orgin == 2 {
  4253. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  4254. list, _ := service.GetHisAdviceExecutionById(idArray)
  4255. fmt.Println(err)
  4256. c.ServeSuccessJSON(map[string]interface{}{
  4257. "list": list,
  4258. })
  4259. return
  4260. }
  4261. }