dialysis_api_controller.go 224KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/jinzhu/gorm"
  7. "reflect"
  8. "strconv"
  9. "strings"
  10. "time"
  11. "XT_New/enums"
  12. "XT_New/models"
  13. "XT_New/service"
  14. "XT_New/utils"
  15. "github.com/astaxie/beego"
  16. "math"
  17. "net/http"
  18. "net/url"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. fmt.Println("key22332323232232323", key)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. redis.Set(key, "", time.Second)
  79. patients, _ := service.GetAllPatientListSix(orgID)
  80. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  81. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  82. if err != nil {
  83. this.ErrorLog("获取排班信息失败:%v", err)
  84. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  85. } else {
  86. if len(scheduals) > 0 {
  87. devices, _ := service.GetAllDevicetByListSix(orgID)
  88. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  89. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  90. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  91. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  92. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  93. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  94. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  95. for key, item := range scheduals {
  96. // 获取患者信息
  97. for _, patient := range patients {
  98. if item.PatientId == patient.ID {
  99. scheduals[key].SchedualPatient = patient
  100. break
  101. }
  102. }
  103. // 床位信息
  104. for _, device := range devices {
  105. if item.BedId == device.ID {
  106. scheduals[key].DeviceNumber = device
  107. break
  108. }
  109. }
  110. // 医嘱信息
  111. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  112. for _, advice := range advices {
  113. if item.PatientId == advice.PatientId {
  114. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  115. }
  116. }
  117. // 医嘱信息
  118. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  119. for _, hisAdvice := range hisAdvices {
  120. if item.PatientId == hisAdvice.PatientId {
  121. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  122. }
  123. }
  124. // 医嘱信息
  125. for _, prescription := range prescriptions {
  126. if item.PatientId == prescription.PatientId {
  127. scheduals[key].Prescription = prescription
  128. break
  129. }
  130. }
  131. // 透前评估
  132. for _, assessmentBefore := range assessmentBefores {
  133. if item.PatientId == assessmentBefore.PatientId {
  134. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  135. break
  136. }
  137. }
  138. // 透析上下机
  139. for _, dialysisOrder := range dialysisOrders {
  140. if item.PatientId == dialysisOrder.PatientId {
  141. scheduals[key].DialysisOrder = dialysisOrder
  142. break
  143. }
  144. }
  145. // 治疗小节
  146. for _, afterDislysis := range AssessmentAfterDislysis {
  147. if item.PatientId == afterDislysis.PatientId {
  148. scheduals[key].AssessmentAfterDislysis = afterDislysis
  149. break
  150. }
  151. }
  152. // 透后评估
  153. for _, treatmentSummary := range treatmentSummarys {
  154. if item.PatientId == treatmentSummary.PatientId {
  155. scheduals[key].TreatmentSummary = treatmentSummary
  156. break
  157. }
  158. }
  159. }
  160. //缓存数据
  161. scheduals_json, err := json.Marshal(&scheduals)
  162. if err == nil {
  163. redis.Set(key, scheduals_json, time.Second*60)
  164. }
  165. }
  166. //获取今日所有的处方开的耗材
  167. _, configs := service.FindXTHisProjectByOrgId(orgID)
  168. project := make([]*models.HisPrescriptionProjectTwo, 0)
  169. if configs.ID > 0 && configs.IsOpen == 1 {
  170. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  171. }
  172. this.ServeSuccessJSON(map[string]interface{}{
  173. "scheduals": scheduals,
  174. "project": project,
  175. })
  176. }
  177. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  178. var dat []map[string]interface{}
  179. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  180. } else {
  181. }
  182. //获取今日所有的处方开的耗材
  183. _, configs := service.FindXTHisProjectByOrgId(orgID)
  184. project := make([]*models.HisPrescriptionProjectTwo, 0)
  185. if configs.ID > 0 && configs.IsOpen == 1 {
  186. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  187. }
  188. //获取今日透析准备的数据
  189. //goodList, err := service.MobileGetDialysisGoodsSeven(orgID, date.Unix())
  190. //fmt.Println("goodlist23323232323233232332233223323233", goodList, err)
  191. //
  192. //list, err := service.MobileGetDialysisGoodsSix(orgID, date.Unix())
  193. //
  194. //for _, item := range goodList {
  195. // for _, it := range list {
  196. // if item.RecordDate == it.RecordDate && item.PatientId == it.PatientId {
  197. // item.Children = append(item.Children, it)
  198. // }
  199. // }
  200. //}
  201. //autoList, _ := service.GetMobileAutoReduce(orgID, date.Unix())
  202. this.ServeSuccessJSON(map[string]interface{}{
  203. "scheduals": dat,
  204. "redis": "true",
  205. "date": schedualDate,
  206. "project": project,
  207. //"goodList": goodList,
  208. //"autoList": autoList,
  209. })
  210. }
  211. }
  212. // /m/api/waiting_scheduals [get]
  213. // @param date:string
  214. func (this *DialysisAPIController) WaitingScheduals() {
  215. schedualDate := this.GetString("date")
  216. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  217. if parseDateErr != nil && len(schedualDate) != 0 {
  218. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  219. return
  220. }
  221. adminInfo := this.GetMobileAdminUserInfo()
  222. orgID := adminInfo.Org.Id
  223. redis := service.RedisClient()
  224. defer redis.Close()
  225. // cur_date := time.Now().Format("2006-01-02")
  226. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  227. wait_scheduals, _ := redis.Get(key).Result()
  228. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  229. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  230. if err != nil {
  231. this.ErrorLog("获取排班信息失败:%v", err)
  232. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  233. } else {
  234. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  235. for _, s := range scheduals {
  236. returnScheduals = append(returnScheduals, s)
  237. }
  238. if len(returnScheduals) > 0 {
  239. //缓存数据
  240. wait_scheduals_json, err := json.Marshal(scheduals)
  241. if err == nil {
  242. redis.Set(key, wait_scheduals_json, time.Second*30)
  243. }
  244. }
  245. this.ServeSuccessJSON(map[string]interface{}{
  246. "scheduals": scheduals,
  247. })
  248. }
  249. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  250. var dat []map[string]interface{}
  251. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  252. } else {
  253. }
  254. this.ServeSuccessJSON(map[string]interface{}{
  255. "scheduals": dat,
  256. "redis": "true",
  257. "date": schedualDate,
  258. })
  259. }
  260. }
  261. //else{
  262. // fmt.Println("33333333")
  263. //
  264. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  265. // if err != nil {
  266. // this.ErrorLog("获取排班信息失败:%v", err)
  267. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  268. // } else {
  269. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  270. // for _, s := range scheduals {
  271. //
  272. // returnScheduals = append(returnScheduals, s)
  273. // }
  274. //
  275. // this.ServeSuccessJSON(map[string]interface{}{
  276. // "scheduals": returnScheduals,
  277. // })
  278. // }
  279. //
  280. // }
  281. //if err == nil{
  282. //
  283. //
  284. //
  285. //
  286. //
  287. //}else{
  288. //}
  289. // /m/api/dialysis/record [get]
  290. // @param patient_id:int
  291. // @param date:string (yyyy-MM-dd)
  292. func (this *DialysisAPIController) DialysisRecord() {
  293. patientID, _ := this.GetInt64("patient_id")
  294. recordDateStr := this.GetString("date")
  295. if patientID <= 0 {
  296. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  297. return
  298. }
  299. if len(recordDateStr) == 0 {
  300. recordDateStr = time.Now().Format("2006-01-02")
  301. }
  302. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  303. if parseDateErr != nil {
  304. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  305. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  306. return
  307. }
  308. adminInfo := this.GetMobileAdminUserInfo()
  309. ch := make(chan struct{})
  310. count := 24 // count 表示活动的协程个数
  311. var patient models.Patients
  312. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  313. var predialysisEvaluation *models.PredialysisEvaluation
  314. var lastPredialysisEvaluation *models.PredialysisEvaluation
  315. var doctorAdvices []*models.DoctorAdvice
  316. var dialysisOrder *models.DialysisOrder
  317. var doubleCheck *models.DoubleCheck
  318. var monitorRecords []*models.MonitoringRecord
  319. var lastMonitorRecord *models.MonitoringRecord
  320. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  321. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  322. var treatmentSummary *models.TreatmentSummary
  323. var dialysisPrescribe *models.DialysisPrescription
  324. var dialysisSolution *models.DialysisSolution
  325. var lastDialysisPrescribe *models.DialysisPrescription
  326. var systemDialysisPrescribe *models.SystemPrescription
  327. var is_project_open_config models.XtHisProjectConfig
  328. var projects []*models.HisPrescriptionProject
  329. var stockType []*models.GoodsTypeOne
  330. var prepare []*models.XtDialysisBeforePrepare
  331. var lastAssessment models.XtPatientVascularAccess
  332. var lastDryWeightDislysis *models.SgjPatientDryweight
  333. var gobalConfig models.GobalConfig
  334. var operators []*models.SgjUserAdminRoles
  335. // 先走redis,没有走数据库
  336. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  337. go func() {
  338. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  339. ch <- struct{}{}
  340. }()
  341. go func() {
  342. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  343. ch <- struct{}{}
  344. }()
  345. go func() {
  346. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  347. ch <- struct{}{}
  348. }()
  349. go func() {
  350. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  351. ch <- struct{}{}
  352. }()
  353. go func() {
  354. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  355. ch <- struct{}{}
  356. }()
  357. go func() {
  358. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  359. ch <- struct{}{}
  360. }()
  361. go func() {
  362. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  363. ch <- struct{}{}
  364. }()
  365. go func() {
  366. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  367. ch <- struct{}{}
  368. }()
  369. go func() {
  370. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  371. ch <- struct{}{}
  372. }()
  373. go func() {
  374. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  375. ch <- struct{}{}
  376. }()
  377. go func() {
  378. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  379. ch <- struct{}{}
  380. }()
  381. go func() {
  382. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  383. ch <- struct{}{}
  384. }()
  385. go func() {
  386. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  387. ch <- struct{}{}
  388. }()
  389. go func() {
  390. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  391. ch <- struct{}{}
  392. }()
  393. go func() {
  394. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  395. ch <- struct{}{}
  396. }()
  397. go func() {
  398. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  399. ch <- struct{}{}
  400. }()
  401. go func() {
  402. // 先走redis,没有走数据库
  403. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  404. ch <- struct{}{}
  405. }()
  406. go func() {
  407. // 先走redis,没有走数据库
  408. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  409. ch <- struct{}{}
  410. }()
  411. go func() {
  412. // // 先走redis,没有走数据库
  413. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  414. ch <- struct{}{}
  415. }()
  416. go func() {
  417. // 先走redis,没有走数据库
  418. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  419. ch <- struct{}{}
  420. }()
  421. go func() {
  422. // //获取最后一次血管通路
  423. // 先走redis,没有走数据库
  424. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  425. ch <- struct{}{}
  426. }()
  427. go func() {
  428. // 先走redis,没有走数据库
  429. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  430. ch <- struct{}{}
  431. }()
  432. go func() {
  433. // 先走redis,没有走数据库
  434. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  435. ch <- struct{}{}
  436. }()
  437. go func() {
  438. // 先走redis,没有走数据库
  439. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  440. ch <- struct{}{}
  441. }()
  442. for range ch {
  443. // 每次从ch中接收数据,表明一个活动的协程结束
  444. count--
  445. // 当所有活动的协程都结束时,关闭管道
  446. if count == 0 {
  447. close(ch)
  448. }
  449. }
  450. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  451. fmt.Println("prescribeOne23223323232323223320303203200320320w02323232")
  452. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  453. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  454. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  455. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  456. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  457. var team_projects []*models.HisPrescriptionProject
  458. //var index int64 = 0
  459. for _, item := range temp_team_projects {
  460. //组套里面非检验项目的
  461. if item.HisProject.CostClassify != 3 {
  462. projects = append(projects, item)
  463. }
  464. //组套里面检验项目的
  465. if item.HisProject.CostClassify == 3 {
  466. team_projects = append(team_projects, item)
  467. }
  468. }
  469. team_projects = RemoveRepeatedCheckRecod(team_projects)
  470. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  471. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  472. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  473. var his_advices []*models.HisDoctorAdviceInfo
  474. fmt.Println("w233232322332233223", is_open_config.IsOpen)
  475. if is_open_config.IsOpen == 1 {
  476. // 先走redis,没有走数据库
  477. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  478. }
  479. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  480. fmt.Println("t233232322332233223", is_advice_open.IsAdviceOpen)
  481. if is_advice_open.IsAdviceOpen == 1 {
  482. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  483. }
  484. fmt.Println("doctorAdvices23344334344433434334343434wode", doctorAdvices)
  485. returnData := map[string]interface{}{
  486. "patient": patient,
  487. "schedual": schedual,
  488. "prescription": dialysisPrescribe,
  489. "solution": dialysisSolution,
  490. "last_prescription": lastDialysisPrescribe,
  491. "receiver_treatment_access": receiverTreatmentAccess,
  492. "predialysis_evaluation": predialysisEvaluation,
  493. "doctor_advices": doctorAdvices,
  494. "double_check": doubleCheck,
  495. "assessment_after_dislysis": assessmentAfterDislysis,
  496. "treatment_summary": treatmentSummary,
  497. "monitor_records": monitorRecords,
  498. "dialysis_order": dialysisOrder,
  499. "operators": operators,
  500. "last_predialysis_evaluation": lastPredialysisEvaluation,
  501. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  502. "last_monitor_record": lastMonitorRecord,
  503. "config": gobalConfig,
  504. "dry_weight": lastDryWeightDislysis,
  505. "system_prescription": systemDialysisPrescribe,
  506. "his_advices": his_advices,
  507. "is_open_config": is_open_config,
  508. "stockType": stockType,
  509. "prepare": prepare,
  510. "lastAssessment": lastAssessment,
  511. "prescribeOne": prescribeOne,
  512. "is_project_open_config": is_project_open_config,
  513. "project": projects,
  514. "team_projects": team_projects,
  515. "is_advice_open": is_advice_open,
  516. "prescription_open": prescriptionConfig.IsOpen,
  517. }
  518. this.ServeSuccessJSON(returnData)
  519. }
  520. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  521. adminInfo := c.GetMobileAdminUserInfo()
  522. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  523. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  524. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  525. returnData := map[string]interface{}{
  526. "admin_users": adminUsers,
  527. "devices": devices,
  528. "device_numbers": device_numbers,
  529. }
  530. c.ServeSuccessJSON(returnData)
  531. }
  532. func (c *DialysisAPIController) PostAtreatmentInfo() {
  533. id, _ := c.GetInt64("patient", 0)
  534. recordDateStr := c.GetString("record_date")
  535. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  536. summaryContent := c.GetString("summaryContent")
  537. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  538. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  539. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  540. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  541. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  542. nursingRecord := c.GetString("nursing_record")
  543. fmt.Println("护理记录", nursingRecord)
  544. specialRecord := c.GetString("special_record")
  545. fmt.Println("特殊记录", specialRecord)
  546. adminUserInfo := c.GetMobileAdminUserInfo()
  547. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  548. checkStaffId = adminUserInfo.AdminUser.Id
  549. deboardNurseId = adminUserInfo.AdminUser.Id
  550. treatDoctor = adminUserInfo.AdminUser.Id
  551. if id <= 0 {
  552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  553. return
  554. }
  555. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  556. if patient.ID == 0 {
  557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  558. return
  559. }
  560. if len(recordDateStr) == 0 {
  561. recordDateStr = time.Now().Format("2006-01-02")
  562. }
  563. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  564. if parseDateErr != nil {
  565. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  567. return
  568. }
  569. summary := models.TreatmentSummary{
  570. UserOrgId: adminUserInfo.Org.Id,
  571. PatientId: id,
  572. AssessmentDate: recordDate.Unix(),
  573. Mission: propagandaAndEducationContent,
  574. DialysisSummary: summaryContent,
  575. SjNurse: changeMedicalNurseId,
  576. ZlNurse: treatNurseId,
  577. HdNurse: checkStaffId,
  578. XjNurse: deboardNurseId,
  579. ZlDoctor: treatDoctor,
  580. CreatedTime: time.Now().Unix(),
  581. Status: 1,
  582. NursingRecord: nursingRecord,
  583. SpecialRecord: specialRecord,
  584. }
  585. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  586. if treatmentSummary.ID == 0 { //新增
  587. summary.Creater = adminUserInfo.AdminUser.Id
  588. service.AddSigleSummaryRecord(&summary)
  589. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  590. redis := service.RedisClient()
  591. //清空key 值
  592. redis.Set(key, "", time.Second)
  593. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  594. redis.Set(keyOne, "", time.Second)
  595. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  596. redis.Set(keyThree, "", time.Second)
  597. defer redis.Close()
  598. c.ServeSuccessJSON(map[string]interface{}{
  599. "summary": summary,
  600. })
  601. } else { //修改
  602. summary.Creater = treatmentSummary.Creater
  603. summary.CreatedTime = treatmentSummary.CreatedTime
  604. summary.Modifier = adminUserInfo.AdminUser.Id
  605. summary.ID = treatmentSummary.ID
  606. service.UpdateSummeRecord(&summary)
  607. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  608. redis := service.RedisClient()
  609. //清空key 值
  610. redis.Set(key, "", time.Second)
  611. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  612. redis.Set(keyOne, "", time.Second)
  613. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  614. redis.Set(keyThree, "", time.Second)
  615. defer redis.Close()
  616. c.ServeSuccessJSON(map[string]interface{}{
  617. "summary": summary,
  618. })
  619. }
  620. }
  621. func (c *DialysisAPIController) PostDoubleCheck() {
  622. id, _ := c.GetInt64("patient", 0)
  623. recordDateStr := c.GetString("record_date")
  624. checkTimeStr := c.GetString("check_time")
  625. firstCheckTimeStr := c.GetString("first_check_time")
  626. creater, _ := c.GetInt64("creater", 0)
  627. modifier, _ := c.GetInt64("modifier", 0)
  628. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  629. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  630. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  631. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  632. dialysis_item_desc := c.GetString("dialysis_item_desc")
  633. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  634. vascular_access_desc := c.GetString("vascular_access_desc")
  635. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  636. collator, _ := c.GetInt64("collator", 0)
  637. employee_number := c.GetString("employee_number")
  638. if id <= 0 {
  639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  640. return
  641. }
  642. adminUserInfo := c.GetMobileAdminUserInfo()
  643. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  644. if patient.ID == 0 {
  645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  646. return
  647. }
  648. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  649. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  650. if employee_number != list.JobNumber {
  651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorEmployeeNumber)
  652. return
  653. }
  654. }
  655. if len(recordDateStr) == 0 {
  656. recordDateStr = time.Now().Format("2006-01-02")
  657. }
  658. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  659. if parseDateErr != nil {
  660. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  662. return
  663. }
  664. var checkDate int64
  665. if len(checkTimeStr) == 0 {
  666. checkDate = 0
  667. } else {
  668. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  669. checkDate = checkDateUnix.Unix()
  670. }
  671. var firstCheckDate int64
  672. if len(firstCheckTimeStr) == 0 {
  673. firstCheckDate = 0
  674. } else {
  675. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  676. firstCheckDate = firstCheckDateUnix.Unix()
  677. }
  678. //now := time.Now()
  679. //year, month, day := now.Date()
  680. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  681. //todayTimeStamp := today_time.Unix()
  682. doubleCheck := models.DoubleCheck{
  683. UserOrgId: adminUserInfo.Org.Id,
  684. PatientId: id,
  685. DialysisItemCheck: dialysis_item_check,
  686. DialysisParameterCheck: dialysis_parameter_check,
  687. VascularAccessVerification: vascular_access_verification,
  688. PipelineConnectionCheck: pipeline_connection_check,
  689. DialysisItemDesc: dialysis_item_desc,
  690. DialysisParameterDesc: dialysis_parameter_desc,
  691. VascularAccessDesc: vascular_access_desc,
  692. PipelineConnectionDesc: pipeline_connection_desc,
  693. Collator: collator,
  694. Status: 1,
  695. CreatedTime: time.Now().Unix(),
  696. CheckDate: recordDate.Unix(),
  697. UpdatedTime: time.Now().Unix(),
  698. EmployeeNumber: employee_number,
  699. }
  700. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  701. if check.ID == 0 { //新增
  702. doubleCheck.FirstCheckTime = firstCheckDate
  703. doubleCheck.CheckTime = checkDate
  704. doubleCheck.Creater = creater
  705. doubleCheck.Modifier = modifier
  706. err := service.AddSigleDoubleCheck(&doubleCheck)
  707. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  708. redis := service.RedisClient()
  709. defer redis.Close()
  710. //清空key 值
  711. redis.Set(key, "", time.Second)
  712. if err == nil {
  713. c.ServeSuccessJSON(map[string]interface{}{
  714. "doubleCheck": &doubleCheck,
  715. })
  716. }
  717. } else { //修改
  718. doubleCheck.FirstCheckTime = firstCheckDate
  719. doubleCheck.CheckTime = checkDate
  720. doubleCheck.Creater = creater
  721. doubleCheck.Modifier = modifier
  722. doubleCheck.CreatedTime = check.CreatedTime
  723. doubleCheck.ID = check.ID
  724. doubleCheck.EmployeeNumber = employee_number
  725. err := service.UpdateDoubleCheck(&doubleCheck)
  726. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  727. redis := service.RedisClient()
  728. defer redis.Close()
  729. //清空key 值
  730. redis.Set(key, "", time.Second)
  731. if err == nil {
  732. c.ServeSuccessJSON(map[string]interface{}{
  733. "doubleCheck": &doubleCheck,
  734. })
  735. }
  736. }
  737. }
  738. func (c *DialysisAPIController) PostAcceptsAssessment() {
  739. id, _ := c.GetInt64("patient", 0)
  740. recordDateStr := c.GetString("record_date")
  741. way, _ := c.GetInt64("way", 0)
  742. consciousness, _ := c.GetInt64("consciousness", 0)
  743. appetite, _ := c.GetInt64("appetite", 0)
  744. condition, _ := c.GetInt64("condition", 0)
  745. posture, _ := c.GetInt64("posture")
  746. sick_condition, _ := c.GetInt64("sick_condition", 0)
  747. danger_level, _ := c.GetInt64("danger_level", 0)
  748. intake, _ := c.GetInt64("intake", 0)
  749. nutrition, _ := c.GetInt64("nutrition", 0)
  750. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  751. psychological_assessment_other := c.GetString("psychological_assessment_other")
  752. score := c.GetString("score")
  753. sick_condition_other := c.GetString("sick_condition_other")
  754. //precaution, _ := c.GetInt64("precaution", 0)
  755. precaution := c.GetString("precaution")
  756. precaution_other := c.GetString("precaution_other")
  757. psychological_other := c.GetString("psychological_other")
  758. admission_number := c.GetString("admission_number")
  759. tumble, _ := c.GetInt64("tumble")
  760. if id <= 0 {
  761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  762. return
  763. }
  764. adminUserInfo := c.GetMobileAdminUserInfo()
  765. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  766. if patient.ID == 0 {
  767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  768. return
  769. }
  770. //now := time.Now()
  771. //year, month, day := now.Date()
  772. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  773. //todayTimeStamp := today_time.Unix()
  774. if len(recordDateStr) == 0 {
  775. recordDateStr = time.Now().Format("2006-01-02")
  776. }
  777. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  778. if parseDateErr != nil {
  779. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  781. return
  782. }
  783. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  784. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  785. UserOrgId: adminUserInfo.Org.Id,
  786. PatientId: id,
  787. RecordDate: recordDate.Unix(),
  788. Way: way,
  789. Consciousness: consciousness,
  790. Appetite: appetite,
  791. Condition: condition,
  792. SickCondition: sick_condition,
  793. DangerLevel: danger_level,
  794. Intake: intake,
  795. Nutrition: nutrition,
  796. PsychologicalAssessment: psychological_assessment,
  797. PsychologicalAssessmentOther: psychological_assessment_other,
  798. SickConditionOther: sick_condition_other,
  799. Posture: posture,
  800. CreatedTime: time.Now().Unix(),
  801. UpdateTime: time.Now().Unix(),
  802. Status: 1,
  803. Score: score,
  804. Precaution: precaution,
  805. PrecautionOther: precaution_other,
  806. PsychologicalOther: psychological_other,
  807. AdmissionNumber: admission_number,
  808. Tumble: tumble,
  809. }
  810. if receiveTreatment.ID == 0 { //新增
  811. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  812. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  813. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  814. redis := service.RedisClient()
  815. defer redis.Close()
  816. //清空key 值
  817. redis.Set(key, "", time.Second)
  818. if err == nil {
  819. c.ServeSuccessJSON(map[string]interface{}{
  820. "receiveTreatmentAsses": receiveTreatmentAsses,
  821. })
  822. }
  823. } else { //修改
  824. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  825. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  826. // if getPermissionErr != nil {
  827. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  828. // return
  829. // } else if headNursePermission == nil {
  830. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  831. // return
  832. // }
  833. //}
  834. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  835. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  836. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  837. receiveTreatmentAsses.ID = receiveTreatment.ID
  838. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  839. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  840. redis := service.RedisClient()
  841. defer redis.Close()
  842. //清空key 值
  843. redis.Set(key, "", time.Second)
  844. if err == nil {
  845. c.ServeSuccessJSON(map[string]interface{}{
  846. "receiveTreatmentAsses": receiveTreatmentAsses,
  847. })
  848. }
  849. }
  850. }
  851. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  852. id, _ := c.GetInt64("patient", 0)
  853. recordDateStr := c.GetString("record_date")
  854. weightAfter, _ := c.GetFloat("weight_after", 0)
  855. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  856. weightReduce, _ := c.GetFloat("weight_loss", 0)
  857. temperature, _ := c.GetFloat("temperature", 0)
  858. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  859. //breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  860. breathing_rate := c.GetString("breathing_rate")
  861. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  862. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  863. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  864. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  865. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  866. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  867. cruor := c.GetString("cruor")
  868. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  869. internalFistula := c.GetString("internal_fistula")
  870. catheter := c.GetString("catheter")
  871. complications := c.GetString("complication")
  872. remark := c.GetString("remark")
  873. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  874. dialysis_intakes := c.GetString("dialysis_intakes")
  875. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  876. fmt.Println("dialysateVolumewode 23323233223232wode", dialysateVolume)
  877. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  878. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  879. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  880. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  881. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  882. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  883. patientGose, _ := c.GetInt64("patient_gose", 0)
  884. inpatientDepartment := c.GetString("inpatient_department")
  885. observationContent := c.GetString("observation_content")
  886. observationContentOther := c.GetString("observation_content_other")
  887. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  888. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  889. in_advance_reason := c.GetString("in_advance_reason")
  890. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  891. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  892. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  893. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  894. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  895. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  896. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  897. dialyzer, _ := c.GetInt64("dialyzer", 0)
  898. in_advance_reason_other := c.GetString("in_advance_reason_other")
  899. is_eat, _ := c.GetInt64("is_eat", 0)
  900. cvc_a, _ := c.GetFloat("cvc_a", 0)
  901. cvc_v, _ := c.GetFloat("cvc_v", 0)
  902. channels, _ := c.GetInt64("channel", 0)
  903. return_blood, _ := c.GetInt64("return_blood", 0)
  904. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  905. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  906. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  907. blood_flow, _ := c.GetInt64("blood_flow", 0)
  908. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  909. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  910. sealing_fluid_special := c.GetString("sealing_fluid_special")
  911. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  912. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  913. setting_pressure := c.GetString("setting_pressure")
  914. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  915. diastolic_pressure := c.GetString("diastolic_pressure")
  916. other_complication := c.GetString("other_complication")
  917. ktv := c.GetString("ktv")
  918. urr := c.GetString("urr")
  919. hypertenison, _ := c.GetInt64("hypertenison")
  920. hypopiesia, _ := c.GetInt64("hypopiesia")
  921. leave_office_method, _ := c.GetInt64("leave_office_method")
  922. lapse, _ := c.GetInt64("lapse")
  923. consciousness, _ := c.GetInt64("consciousness")
  924. fallrisk, _ := c.GetInt64("fallrisk")
  925. machine_run := c.GetString("machine_run")
  926. after_urea := c.GetString("after_urea")
  927. pip_coagulation := c.GetString("pip_coagulation")
  928. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  929. if id <= 0 {
  930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  931. return
  932. }
  933. adminUserInfo := c.GetMobileAdminUserInfo()
  934. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  935. if patient.ID == 0 {
  936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  937. return
  938. }
  939. if len(recordDateStr) == 0 {
  940. recordDateStr = time.Now().Format("2006-01-02")
  941. }
  942. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  943. if parseDateErr != nil {
  944. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  946. return
  947. }
  948. //now := time.Now()
  949. //year, month, day := now.Date()
  950. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  951. //todayTimeStamp := today_time.Unix()
  952. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  953. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  954. UserOrgId: adminUserInfo.Org.Id,
  955. PatientId: id,
  956. AssessmentDate: recordDate.Unix(),
  957. Temperature: temperature,
  958. PulseFrequency: pulse_frequency,
  959. BreathingRate: breathing_rate,
  960. SystolicBloodPressure: systolic_blood_pressure,
  961. DiastolicBloodPressure: diastolic_blood_pressure,
  962. ActualUltrafiltration: actual_ultrafiltration,
  963. ActualDisplacement: actual_displacement,
  964. ActualTreatmentHour: actualtreatHour,
  965. ActualTreatmentMinute: actualtreatmin,
  966. WeightAfter: weightAfter,
  967. AdditionalWeight: additionalWeight,
  968. WeightLoss: weightReduce,
  969. Cruor: cruor,
  970. SymptomAfterDialysis: symptomsAfterDialysi,
  971. InternalFistula: internalFistula,
  972. Catheter: catheter,
  973. Complication: complications,
  974. DialysisIntakes: dialysateVolume,
  975. CreatedTime: time.Now().Unix(),
  976. Status: 1,
  977. Remark: remark,
  978. BloodAccessPartId: blood_access_part_id,
  979. BloodAccessPartOperaId: blood_access_part_opera_id,
  980. DialysisIntakesUnit: dialysis_intakes_unit,
  981. PuncturePointOozingBlood: puncturePointOozingBlood,
  982. PuncturePointHaematoma: puncturePointHaematoma,
  983. InternalFistulaTremorAc: internalFistulaTremorAc,
  984. PatientGose: patientGose,
  985. InpatientDepartment: inpatientDepartment,
  986. ObservationContent: observationContent,
  987. ObservationContentOther: observationContentOther,
  988. DialysisProcess: dialysis_process,
  989. InAdvanceMinute: in_advance_minute,
  990. InAdvanceReason: in_advance_reason,
  991. HemostasisMinute: hemostasis_minute,
  992. HemostasisOpera: hemostasis_opera,
  993. TremorNoise: tremor_noise,
  994. DisequilibriumSyndrome: disequilibrium_syndrome,
  995. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  996. ArterialTube: arterial_tube,
  997. IntravenousTube: intravenous_tube,
  998. Dialyzer: dialyzer,
  999. InAdvanceReasonOther: in_advance_reason_other,
  1000. IsEat: is_eat,
  1001. CvcA: cvc_a,
  1002. CvcV: cvc_v,
  1003. Channel: channels,
  1004. ReturnBlood: return_blood,
  1005. RehydrationVolume: rehydration_volume,
  1006. DialysisDuring: dialysis_during,
  1007. StrokeVolume: stroke_volume,
  1008. BloodFlow: blood_flow,
  1009. SealingFluidDispose: sealing_fluid_dispose,
  1010. SealingFluidSpecial: sealing_fluid_special,
  1011. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1012. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1013. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1014. SettingPressure: setting_pressure,
  1015. DiastolicPressure: diastolic_pressure,
  1016. OtherComplication: other_complication,
  1017. Ktv: ktv,
  1018. Urr: urr,
  1019. Hypopiesia: hypopiesia,
  1020. Hypertenison: hypertenison,
  1021. Lapse: lapse,
  1022. LeaveOfficeMethod: leave_office_method,
  1023. Consciousness: consciousness,
  1024. Fallrisk: fallrisk,
  1025. MachineRun: machine_run,
  1026. AfterUrea: after_urea,
  1027. PipCoagulation: pip_coagulation,
  1028. AccumulatedBloodVolume: accumulated_blood_volume,
  1029. }
  1030. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1031. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1032. if assessmentAfter.ID == 0 { //新增
  1033. if appRole.UserType == 2 || appRole.UserType == 1 {
  1034. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1035. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1036. } else {
  1037. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1038. }
  1039. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1040. redis := service.RedisClient()
  1041. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1042. redis.Set(keyTwo, "", time.Second)
  1043. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1044. //清空key 值
  1045. redis.Set(key, "", time.Second)
  1046. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1047. redis.Set(keyOne, "", time.Second)
  1048. defer redis.Close()
  1049. if err == nil {
  1050. c.ServeSuccessJSON(map[string]interface{}{
  1051. "assessmentAfterDislysis": assessmentAfterDislysis,
  1052. })
  1053. }
  1054. } else { //修改
  1055. if appRole.UserType == 2 || appRole.UserType == 1 {
  1056. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1057. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1058. } else {
  1059. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1060. if assessmentAfterDislysis.Creater == 0 {
  1061. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1062. }
  1063. }
  1064. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1065. assessmentAfterDislysis.ID = assessmentAfter.ID
  1066. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1067. redis := service.RedisClient()
  1068. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1069. redis.Set(keyTwo, "", time.Second)
  1070. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1071. //清空key 值
  1072. redis.Set(key, "", time.Second)
  1073. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1074. redis.Set(keyOne, "", time.Second)
  1075. fmt.Println("err233332323232232323", err)
  1076. if err == nil {
  1077. c.ServeSuccessJSON(map[string]interface{}{
  1078. "assessmentAfterDislysis": assessmentAfterDislysis,
  1079. })
  1080. }
  1081. }
  1082. }
  1083. func (c *DialysisAPIController) PostDialysisPrescription() {
  1084. id, _ := c.GetInt64("patient", 0)
  1085. recordDateStr := c.GetString("record_date")
  1086. if id <= 0 {
  1087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1088. return
  1089. }
  1090. adminUserInfo := c.GetMobileAdminUserInfo()
  1091. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1092. if patient.ID == 0 {
  1093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1094. return
  1095. }
  1096. if len(recordDateStr) == 0 {
  1097. recordDateStr = time.Now().Format("2006-01-02")
  1098. }
  1099. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1100. if parseDateErr != nil {
  1101. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1103. return
  1104. }
  1105. mode_id, _ := c.GetInt64("mode_id", 0)
  1106. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1107. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1108. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1109. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1110. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1111. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1112. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1113. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1114. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1115. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1116. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1117. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1118. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1119. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1120. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1121. kalium, _ := c.GetFloat("kalium", 0)
  1122. sodium, _ := c.GetFloat("sodium", 0)
  1123. calcium, _ := c.GetFloat("calcium", 0)
  1124. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1125. glucose, _ := c.GetFloat("glucose", 0)
  1126. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1127. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1128. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1129. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1130. conductivity, _ := c.GetFloat("conductivity", 0)
  1131. remark := c.GetString("remark")
  1132. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1133. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1134. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1135. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1136. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1137. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1138. special_medicine_other := c.GetString("special_medicine_other")
  1139. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1140. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1141. blood_access, _ := c.GetInt64("blood_access", 0)
  1142. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1143. body_fluid_other := c.GetString("body_fluid_other")
  1144. niprocart, _ := c.GetInt64("niprocart", 0)
  1145. jms, _ := c.GetInt64("jms", 0)
  1146. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1147. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1148. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1149. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1150. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1151. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1152. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1153. injector, _ := c.GetInt64("injector", 0)
  1154. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1155. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1156. safe_package, _ := c.GetInt64("package", 0)
  1157. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1158. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1159. fmt.Println("预冲量", pre_impulse)
  1160. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1161. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1162. blood := c.GetString("blood")
  1163. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1164. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1165. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1166. displace_speed := c.GetString("displace_speed")
  1167. illness, _ := c.GetInt64("illness")
  1168. amylaceum := c.GetString("amylaceum")
  1169. single_time := c.GetString("single_time")
  1170. single_water := c.GetString("single_water")
  1171. replacement_flow := c.GetString("replacement_flow")
  1172. plasma_separator := c.GetString("plasma_separator")
  1173. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1174. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1175. oxygen_flow := c.GetString("oxygen_flow")
  1176. oxygen_time := c.GetString("oxygen_time")
  1177. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1178. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1179. puncture_needle := c.GetString("puncture_needle")
  1180. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1181. epo := c.GetString("epo")
  1182. epo_count, _ := c.GetFloat("epo_count", 0)
  1183. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1184. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1185. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1186. //
  1187. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1188. // if appRole.UserType == 3 {
  1189. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1190. // if getPermissionErr != nil {
  1191. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1192. // return
  1193. // } else if headNursePermission == nil {
  1194. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1195. // return
  1196. // }
  1197. // }
  1198. //}
  1199. //TODO 需要根据角色去判断
  1200. prescription := models.DialysisPrescription{
  1201. UserOrgId: adminUserInfo.Org.Id,
  1202. PatientId: id,
  1203. RecordDate: recordDate.Unix(),
  1204. ModeId: mode_id,
  1205. DialysisDuration: dialysis_duration,
  1206. Dialyzer: dialyzer,
  1207. PerfusionApparatus: perfusion_apparatus,
  1208. BloodFlowVolume: blood_flow_volume,
  1209. DewaterAmount: dewater_amount,
  1210. DisplaceLiqui: displace_liqui,
  1211. ReplacementWay: replacement_way,
  1212. Anticoagulant: anticoagulant,
  1213. AnticoagulantShouji: anticoagulant_shouji,
  1214. AnticoagulantWeichi: anticoagulant_weichi,
  1215. AnticoagulantZongliang: anticoagulant_zongliang,
  1216. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1217. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1218. Kalium: kalium,
  1219. Sodium: sodium,
  1220. Calcium: calcium,
  1221. Bicarbonate: bicarbonate,
  1222. Glucose: glucose,
  1223. // DryWeight: dry_weight,
  1224. DialysateFlow: dialysate_flow,
  1225. DialysateTemperature: dialysate_temperature,
  1226. // PrescriptionDoctor: prescription_doctor,
  1227. ReplacementTotal: replacement_total,
  1228. Conductivity: conductivity,
  1229. Remark: remark,
  1230. Status: 1,
  1231. CreatedTime: time.Now().Unix(),
  1232. UpdatedTime: time.Now().Unix(),
  1233. DialysisDurationMinute: dialysisDurationMinute,
  1234. DialysisDurationHour: dialysisDurationHour,
  1235. TargetUltrafiltration: targetUltrafiltration,
  1236. DialysateFormulation: dialysateFormulation,
  1237. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1238. BodyFluid: body_fluid,
  1239. SpecialMedicine: special_medicine,
  1240. SpecialMedicineOther: special_medicine_other,
  1241. DisplaceLiquiPart: displace_liqui_part,
  1242. DisplaceLiquiValue: displace_liqui_value,
  1243. BloodAccess: blood_access,
  1244. Ultrafiltration: ultrafiltration,
  1245. BodyFluidOther: body_fluid_other,
  1246. Niprocart: niprocart,
  1247. Jms: jms,
  1248. FistulaNeedleSet: fistula_needle_set,
  1249. FistulaNeedleSet16: fistula_needle_set_16,
  1250. Hemoperfusion: hemoperfusion,
  1251. DialyserSterilised: dialyser_sterilised,
  1252. Filtryzer: filtryzer,
  1253. Dialyzers: dialyzers,
  1254. Injector: injector,
  1255. Bloodlines: bloodlines,
  1256. TubingHemodialysis: tubing_hemodialysis,
  1257. Package: safe_package,
  1258. ALiquid: a_liquid,
  1259. TargetKtv: target_ktv,
  1260. PreImpulse: pre_impulse,
  1261. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1262. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1263. Blood: blood,
  1264. DialysisDialyszers: dialysis_dialyszers,
  1265. DialysisIrrigation: dialysis_irrigation,
  1266. AntioxidantCommodityName: antioxidant_commodity_name,
  1267. DisplaceSpeed: displace_speed,
  1268. Illness: illness,
  1269. Amylaceum: amylaceum,
  1270. SingleTime: single_time,
  1271. SingleWater: single_water,
  1272. ReplacementFlow: replacement_flow,
  1273. PlasmaSeparator: plasma_separator,
  1274. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1275. OxygenUptake: oxygen_uptake,
  1276. OxygenFlow: oxygen_flow,
  1277. OxygenTime: oxygen_time,
  1278. HemodialysisPipelines: hemodialysis_pipelines,
  1279. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1280. PunctureNeedle: puncture_needle,
  1281. PunctureNeedleCount: puncture_needle_count,
  1282. Epo: epo,
  1283. EpoCount: epo_count,
  1284. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1285. }
  1286. //查询最近透析准备表里是否存在 透析器 灌流器
  1287. //
  1288. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1289. //
  1290. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1291. //
  1292. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1293. //if len(mation)>0{
  1294. // for _, item := range splitStr {
  1295. // for _,it := range mation{
  1296. // if(item == it.SpecificationName){
  1297. //
  1298. // //查询最近一次的透析器
  1299. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1300. //
  1301. // if errcode == gorm.ErrRecordNotFound{
  1302. // //插入数据
  1303. // prepare := models.DialysisBeforePrepare{
  1304. // UserOrgId: adminUserInfo.Org.Id,
  1305. // PatientId: id,
  1306. // RecordDate: recordDate.Unix(),
  1307. // GoodTypeId: it.GoodTypeId,
  1308. // GoodId: it.ID,
  1309. // Count: 1,
  1310. // Ctime: time.Now().Unix(),
  1311. // Creater: adminUserInfo.AdminUser.Id,
  1312. // Status:1,
  1313. //
  1314. // }
  1315. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1316. // fmt.Println("",errcode)
  1317. // }
  1318. // }
  1319. // }
  1320. //
  1321. // }
  1322. //
  1323. // for _, item := range splitIrrigation {
  1324. // for _,it := range mation{
  1325. // if(item == it.SpecificationName){
  1326. // //查询最近一次的透析器
  1327. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1328. // if errcode == gorm.ErrRecordNotFound{
  1329. // //插入数据
  1330. // prepare := models.DialysisBeforePrepare{
  1331. // UserOrgId: adminUserInfo.Org.Id,
  1332. // PatientId: id,
  1333. // RecordDate: recordDate.Unix(),
  1334. // GoodTypeId: it.GoodTypeId,
  1335. // GoodId: it.ID,
  1336. // Count: 1,
  1337. // Ctime: time.Now().Unix(),
  1338. // Creater: adminUserInfo.AdminUser.Id,
  1339. // Status:1,
  1340. //
  1341. // }
  1342. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1343. // fmt.Println(errcode)
  1344. // }
  1345. // }
  1346. // }
  1347. // }
  1348. //}
  1349. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1350. if dialysisPrescription.ID == 0 { //新增
  1351. if appRole.UserType == 2 || appRole.UserType == 1 {
  1352. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1353. }
  1354. prescription.Creater = adminUserInfo.AdminUser.Id
  1355. //针对河间咸得
  1356. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1357. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1358. prescription.DisplaceLiquiPart = 0
  1359. prescription.DisplaceLiquiValue = 0
  1360. }
  1361. }
  1362. err := service.AddSigleRecord(&prescription)
  1363. //获取key,清空redis
  1364. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1365. redis := service.RedisClient()
  1366. //清空key 值
  1367. redis.Set(key, "", time.Second)
  1368. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1369. //清空key 值
  1370. redis.Set(keyOne, "", time.Second)
  1371. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1372. //清空key 值
  1373. redis.Set(keyTwo, "", time.Second)
  1374. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1375. redis.Set(keySix, "", time.Second)
  1376. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1377. redis.Set(keySeven, "", time.Second)
  1378. if err == nil {
  1379. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1380. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  1381. //清空key 值
  1382. redis.Set(keyThree, "", time.Second)
  1383. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  1384. //清空key 值
  1385. redis.Set(keyFour, "", time.Second)
  1386. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  1387. redis.Set(keyFive, "", time.Second)
  1388. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1389. redis.Set(keySix, "", time.Second)
  1390. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1391. redis.Set(keySeven, "", time.Second)
  1392. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1393. //清空key 值
  1394. redis.Set(keyOne, "", time.Second)
  1395. if updateErr != nil {
  1396. utils.ErrorLog("%v", updateErr)
  1397. }
  1398. defer redis.Close()
  1399. c.ServeSuccessJSON(map[string]interface{}{
  1400. "prescription": prescription,
  1401. })
  1402. }
  1403. } else { //修改
  1404. //if mode_id > 0 {
  1405. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1406. //}
  1407. //if template.TemplateId == 1 {
  1408. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1409. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1410. // if getPermissionErr != nil {
  1411. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1412. // return
  1413. // } else if headNursePermission == nil {
  1414. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1415. // return
  1416. // }
  1417. // }
  1418. //}
  1419. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1420. prescription.Modifier = adminUserInfo.AdminUser.Id
  1421. if appRole.UserType == 2 || appRole.UserType == 1 {
  1422. prescription_doctor := adminUserInfo.AdminUser.Id
  1423. prescription.PrescriptionDoctor = prescription_doctor
  1424. } else {
  1425. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  1426. }
  1427. if dialysisPrescription.Creater == 0 { //体重称
  1428. prescription.Creater = adminUserInfo.AdminUser.Id
  1429. } else {
  1430. prescription.Creater = dialysisPrescription.Creater
  1431. }
  1432. prescription.ID = dialysisPrescription.ID
  1433. err := service.UpDateDialysisPrescription(&prescription)
  1434. //获取key,清空redis
  1435. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1436. redis := service.RedisClient()
  1437. //清空key 值
  1438. redis.Set(key, "", time.Second)
  1439. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1440. //清空key 值
  1441. redis.Set(keyOne, "", time.Second)
  1442. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1443. redis.Set(keySix, "", time.Second)
  1444. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1445. redis.Set(keySeven, "", time.Second)
  1446. if err == nil {
  1447. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1448. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1449. //清空key 值
  1450. redis.Set(keyOne, "", time.Second)
  1451. defer redis.Close()
  1452. if updateErr != nil {
  1453. utils.ErrorLog("%v", updateErr)
  1454. }
  1455. c.ServeSuccessJSON(map[string]interface{}{
  1456. "prescription": prescription,
  1457. })
  1458. }
  1459. }
  1460. }
  1461. func (c *DialysisAPIController) Finish() {
  1462. id, _ := c.GetInt64("patient", 0)
  1463. recordDateStr := c.GetString("record_date")
  1464. nurseID, _ := c.GetInt64("nurse")
  1465. end_time := c.GetString("end_time")
  1466. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  1467. internal_fistula := c.GetString("blood_access_internal_fistula")
  1468. catheter := c.GetString("catheter")
  1469. cruor := c.GetString("cruor")
  1470. if id <= 0 || nurseID <= 0 {
  1471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1472. return
  1473. }
  1474. adminUserInfo := c.GetMobileAdminUserInfo()
  1475. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1476. if patient.ID == 0 {
  1477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1478. return
  1479. }
  1480. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1481. if getNurseErr != nil {
  1482. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1484. return
  1485. } else if nurse == nil {
  1486. c.ErrorLog("护士不存在")
  1487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1488. return
  1489. }
  1490. if len(recordDateStr) == 0 {
  1491. recordDateStr = time.Now().Format("2006-01-02")
  1492. }
  1493. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1494. if parseDateErr != nil {
  1495. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1497. return
  1498. }
  1499. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  1500. if parseEndDateErr != nil {
  1501. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1503. return
  1504. }
  1505. //now := time.Now()
  1506. //year, month, day := now.Date()
  1507. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1508. //todayTimeStamp := today_time.Unix()
  1509. // 获取当天的第一条透析纪录
  1510. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  1511. if getMonitorRecordsErr != nil {
  1512. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1514. return
  1515. }
  1516. // 获取当前的最后一条透析纪录
  1517. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1518. if getMonitorRecordsErr != nil {
  1519. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1521. return
  1522. }
  1523. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  1524. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1525. if getAADErr != nil {
  1526. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  1527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1528. return
  1529. }
  1530. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1531. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  1532. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  1533. if assessmentAfterDislysis != nil {
  1534. tempassessmentAfterDislysis = *assessmentAfterDislysis
  1535. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  1536. } else {
  1537. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  1538. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  1539. tempassessmentAfterDislysis.Status = 1
  1540. tempassessmentAfterDislysis.PatientId = id
  1541. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  1542. }
  1543. //长沙南雅
  1544. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  1545. //获取最后一条透析处方数据
  1546. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  1547. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  1548. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration
  1549. }
  1550. if dialysisOrder.Stage == 1 {
  1551. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  1552. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1553. fmt.Println(value)
  1554. a, b := math.Modf(value)
  1555. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1556. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1557. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  1558. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  1559. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  1560. }
  1561. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  1562. //var num1 int64
  1563. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  1564. //fmt.Println(num1)
  1565. //sub := float64(num1 / 3600)
  1566. //fmt.Println(sub)
  1567. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  1568. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  1569. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  1570. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1571. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  1572. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  1573. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1574. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1575. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1576. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  1577. }
  1578. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 {
  1579. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1580. if evaluation.SystolicBloodPressure == 0 {
  1581. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  1582. pre := models.PredialysisEvaluation{
  1583. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  1584. }
  1585. fmt.Println("prew", pre)
  1586. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  1587. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1588. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1589. redis := service.RedisClient()
  1590. redis.Set(key, "", time.Second)
  1591. redis.Set(keyOne, "", time.Second)
  1592. defer redis.Close()
  1593. fmt.Println(getNurseErr)
  1594. }
  1595. if evaluation.DiastolicBloodPressure == 0 {
  1596. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  1597. pres := models.PredialysisEvaluation{
  1598. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  1599. }
  1600. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  1601. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1602. redis := service.RedisClient()
  1603. redis.Set(key, "", time.Second)
  1604. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1605. redis.Set(keyOne, "", time.Second)
  1606. defer redis.Close()
  1607. fmt.Println(getNurseErr)
  1608. }
  1609. if evaluation.PulseFrequency == 0 {
  1610. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  1611. press := models.PredialysisEvaluation{
  1612. PulseFrequency: evaluation.PulseFrequency,
  1613. }
  1614. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  1615. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1616. redis := service.RedisClient()
  1617. redis.Set(key, "", time.Second)
  1618. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1619. redis.Set(keyOne, "", time.Second)
  1620. defer redis.Close()
  1621. fmt.Println(getNurseErr)
  1622. }
  1623. if evaluation.Temperature == 0 {
  1624. evaluation.Temperature = fmonitorRecords.Temperature
  1625. press := models.PredialysisEvaluation{
  1626. Temperature: evaluation.Temperature,
  1627. }
  1628. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  1629. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1630. redis := service.RedisClient()
  1631. redis.Set(key, "", time.Second)
  1632. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1633. redis.Set(keyOne, "", time.Second)
  1634. defer redis.Close()
  1635. fmt.Println(getNurseErr)
  1636. }
  1637. }
  1638. if adminUserInfo.Org.Id == 9583 {
  1639. //获取透析处方的最后一条数据
  1640. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  1641. if diaerr != nil {
  1642. c.ErrorLog("获取透析处方失败:%v", diaerr)
  1643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1644. return
  1645. }
  1646. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  1647. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  1648. }
  1649. }
  1650. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  1651. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1652. }
  1653. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  1654. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1655. }
  1656. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  1657. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1658. }
  1659. if lastAssessmentAfterDislysis != nil {
  1660. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  1661. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  1662. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  1663. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  1664. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  1665. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  1666. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  1667. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  1668. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  1669. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  1670. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  1671. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  1672. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  1673. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  1674. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  1675. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  1676. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  1677. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  1678. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  1679. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  1680. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  1681. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  1682. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  1683. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  1684. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  1685. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  1686. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  1687. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  1688. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  1689. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  1690. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  1691. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  1692. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  1693. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  1694. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  1695. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  1696. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  1697. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  1698. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  1699. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  1700. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  1701. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  1702. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  1703. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  1704. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  1705. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  1706. }
  1707. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  1708. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1709. redis := service.RedisClient()
  1710. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1711. redis.Set(keyOne, "", time.Second)
  1712. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  1713. redis.Set(keyTwo, "", time.Second)
  1714. defer redis.Close()
  1715. //清空key 值
  1716. redis.Set(key, "", time.Second)
  1717. if err != nil {
  1718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1719. return
  1720. }
  1721. if dialysisOrder == nil {
  1722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  1723. return
  1724. }
  1725. if dialysisOrder.Stage == 2 {
  1726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  1727. return
  1728. }
  1729. if dialysisOrder.Stage == 1 {
  1730. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor)
  1731. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  1732. redis := service.RedisClient()
  1733. defer redis.Close()
  1734. //清空key 值
  1735. redis.Set(key, "", time.Second)
  1736. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  1737. redis.Set(keyOne, "", time.Second)
  1738. //结束时候透析次数加1
  1739. service.UpdateSolutionByPatientId(id)
  1740. dialysisOrder.Stage = 2
  1741. dialysisOrder.FinishNurse = nurseID
  1742. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  1743. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  1744. dialysisOrder.EndTime = endDate.Unix()
  1745. go func() {
  1746. ssoDomain := beego.AppConfig.String("call_domain")
  1747. api := ssoDomain + "/index/downpatient"
  1748. values := make(url.Values)
  1749. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  1750. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1751. values.Set("patient_id", strconv.FormatInt(id, 10))
  1752. http.PostForm(api, values)
  1753. }()
  1754. if err == nil {
  1755. c.ServeSuccessJSON(map[string]interface{}{
  1756. "dialysisOrder": dialysisOrder,
  1757. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  1758. })
  1759. } else {
  1760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1761. }
  1762. }
  1763. }
  1764. func (c *DialysisAPIController) GetAllZone() {
  1765. adminUserInfo := c.GetMobileAdminUserInfo()
  1766. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  1767. if err == nil {
  1768. c.ServeSuccessJSON(map[string]interface{}{
  1769. "zone": zone,
  1770. })
  1771. }
  1772. }
  1773. func (c *DialysisAPIController) GetSchedualPatientsList() {
  1774. adminUserInfo := c.GetMobileAdminUserInfo()
  1775. page, _ := c.GetInt64("page", 1)
  1776. limit, _ := c.GetInt64("limit", 10)
  1777. schedulType, _ := c.GetInt64("schedul_type", 0)
  1778. startTime, _ := c.GetInt64("schedul_time", 0)
  1779. partitionType, _ := c.GetInt64("partition_type", 0)
  1780. keywords := c.GetString("keywords")
  1781. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  1782. if err == nil {
  1783. c.ServeSuccessJSON(map[string]interface{}{
  1784. "schedule": dialysisSchedule,
  1785. })
  1786. }
  1787. return
  1788. }
  1789. // /m/api/dialysis/start [post]
  1790. // @param patient_id:int
  1791. // @param record_date:string 排班时间 (yyyy-mm-dd)
  1792. // @param nurse:int 上机护士
  1793. // @param bed:int 床位号
  1794. func (this *DialysisAPIController) StartDialysis() {
  1795. patientID, _ := this.GetInt64("patient_id")
  1796. recordDateStr := this.GetString("record_date")
  1797. nurseID, _ := this.GetInt64("nurse")
  1798. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1799. blood_drawing, _ := this.GetInt64("blood_drawing")
  1800. schedual_type, _ := this.GetInt64("schedual_type")
  1801. bedID, _ := this.GetInt64("bed")
  1802. start_time := this.GetString("start_time")
  1803. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1804. change_nurse, _ := this.GetInt64("change_nurse")
  1805. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  1806. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  1807. zone_id, _ := this.GetInt64("zone_id")
  1808. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  1809. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1810. return
  1811. }
  1812. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1813. if parseStartDateErr != nil {
  1814. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1815. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1816. return
  1817. }
  1818. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1819. if parseErr != nil {
  1820. this.ErrorLog("时间解析失败:%v", parseErr)
  1821. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1822. return
  1823. }
  1824. adminUserInfo := this.GetMobileAdminUserInfo()
  1825. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  1826. if getPatientErr != nil {
  1827. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  1828. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1829. return
  1830. } else if patient == nil {
  1831. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1832. return
  1833. }
  1834. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1835. if getNurseErr != nil {
  1836. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1837. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1838. return
  1839. } else if nurse == nil {
  1840. this.ErrorLog("护士不存在")
  1841. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1842. return
  1843. }
  1844. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1845. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  1846. if getDeviceNumberErr != nil {
  1847. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1848. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1849. return
  1850. } else if deviceNumber == nil {
  1851. this.ErrorLog("床位号不存在")
  1852. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1853. return
  1854. }
  1855. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1856. if getRecordErr != nil {
  1857. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  1858. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1859. return
  1860. } else if dialysisRecord != nil {
  1861. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  1862. return
  1863. }
  1864. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1865. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1866. timeLayout := "2006-01-02 15:04:05"
  1867. loc, _ := time.LoadLocation("Local")
  1868. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1869. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1870. schedulestartTime := theStartTime.Unix()
  1871. scheduleendTime := theEndTime.Unix()
  1872. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1873. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1874. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1875. //查询该床位是否有人用了
  1876. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1877. if err == gorm.ErrRecordNotFound { //空床位
  1878. // 修改了床位逻辑
  1879. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1880. if daySchedule.ID > 0 {
  1881. daySchedule.PartitionId = deviceNumber.ZoneID
  1882. daySchedule.BedId = bedID
  1883. daySchedule.ScheduleType = schedual_type
  1884. daySchedule.UpdatedTime = time.Now().Unix()
  1885. xtSchedule := models.Schedule{
  1886. PartitionId: deviceNumber.ZoneID,
  1887. BedId: bedID,
  1888. ScheduleType: schedual_type,
  1889. UpdatedTime: time.Now().Unix(),
  1890. }
  1891. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1892. if err != nil {
  1893. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1894. return
  1895. }
  1896. }
  1897. } else if err == nil {
  1898. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1899. if order_err == nil {
  1900. if order.ID > 0 { //该机位被其他人占用了
  1901. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1902. return
  1903. } else {
  1904. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1905. if daySchedule.ID > 0 {
  1906. //daySchedule.PartitionId = deviceNumber.ZoneID
  1907. //daySchedule.BedId = bedID
  1908. //daySchedule.ScheduleType = schedual_type
  1909. //daySchedule.UpdatedTime = time.Now().Unix()
  1910. //err := service.UpdateSchedule(&daySchedule)
  1911. xtSchedule := models.Schedule{
  1912. PartitionId: deviceNumber.ZoneID,
  1913. BedId: bedID,
  1914. ScheduleType: schedual_type,
  1915. UpdatedTime: time.Now().Unix(),
  1916. }
  1917. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1918. if err != nil {
  1919. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1920. return
  1921. }
  1922. }
  1923. }
  1924. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  1925. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1926. if daySchedule.ID > 0 {
  1927. //daySchedule.PartitionId = deviceNumber.ZoneID
  1928. //daySchedule.BedId = bedID
  1929. //daySchedule.ScheduleType = schedual_type
  1930. //daySchedule.UpdatedTime = time.Now().Unix()
  1931. //err := service.UpdateSchedule(&daySchedule)
  1932. xtSchedule := models.Schedule{
  1933. PartitionId: deviceNumber.ZoneID,
  1934. BedId: bedID,
  1935. ScheduleType: schedual_type,
  1936. UpdatedTime: time.Now().Unix(),
  1937. }
  1938. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1939. if err != nil {
  1940. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1941. return
  1942. }
  1943. }
  1944. }
  1945. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1947. return
  1948. }
  1949. } else if err != nil {
  1950. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1951. return
  1952. }
  1953. dialysisRecord = &models.DialysisOrder{
  1954. DialysisDate: recordDate.Unix(),
  1955. UserOrgId: adminUserInfo.Org.Id,
  1956. PatientId: patientID,
  1957. Stage: 1,
  1958. BedID: bedID,
  1959. StartNurse: nurseID,
  1960. Status: 1,
  1961. StartTime: startDate.Unix(),
  1962. CreatedTime: time.Now().Unix(),
  1963. UpdatedTime: time.Now().Unix(),
  1964. PunctureNurse: puncture_nurse,
  1965. Creator: adminUserInfo.AdminUser.Id,
  1966. Modifier: adminUserInfo.AdminUser.Id,
  1967. SchedualType: schedual_type,
  1968. WashpipeNurse: washpipe_nurse,
  1969. ChangeNurse: change_nurse,
  1970. DifficultPunctureNurse: difficult_puncture_nurse,
  1971. NewFistulaNurse: new_fistula_nurse,
  1972. ZoneId: zone_id,
  1973. }
  1974. //查询该床位是否有人用了
  1975. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1976. if errorscode == gorm.ErrRecordNotFound {
  1977. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  1978. redis := service.RedisClient()
  1979. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  1980. redis.Set(key, "", time.Second)
  1981. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  1982. //清空key 值
  1983. redis.Set(keyOne, "", time.Second)
  1984. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1985. //清空key 值
  1986. redis.Set(keyTwo, "", time.Second)
  1987. if createErr != nil {
  1988. this.ErrorLog("上机失败:%v", createErr)
  1989. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1990. return
  1991. }
  1992. }
  1993. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1994. var tempdispose string
  1995. // 只针对中能建
  1996. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  1997. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  1998. }
  1999. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  2000. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2001. }
  2002. var ultrafiltration_rate float64
  2003. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2004. //后期预增脱水量
  2005. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2006. if prescription.ID > 0 {
  2007. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2008. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2009. if (template.TemplateId == 6 || template.TemplateId == 32) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  2010. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2011. }
  2012. //针对医师汇
  2013. if adminUserInfo.Org.Id == 10121 {
  2014. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2015. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2016. }
  2017. //针对通道
  2018. if adminUserInfo.Org.Id == 10234 {
  2019. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  2020. }
  2021. //针对监利大垸医院
  2022. if template.TemplateId == 41 {
  2023. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2024. }
  2025. //针对肇庆三鹤血液透析中心
  2026. if template.TemplateId == 43 {
  2027. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2028. }
  2029. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2030. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2031. }
  2032. // 只针对方济医院
  2033. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2034. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2035. ultrafiltration_rate = value
  2036. }
  2037. }
  2038. }
  2039. record := models.MonitoringRecord{
  2040. UserOrgId: adminUserInfo.Org.Id,
  2041. PatientId: patientID,
  2042. DialysisOrderId: dialysisRecord.ID,
  2043. MonitoringDate: schedulestartTime,
  2044. OperateTime: startDate.Unix(),
  2045. // MonitoringTime: recordTime,
  2046. MonitoringNurse: nurseID,
  2047. Dispose: tempdispose,
  2048. UltrafiltrationRate: ultrafiltration_rate,
  2049. UltrafiltrationVolume: 0,
  2050. Status: 1,
  2051. CreatedTime: time.Now().Unix(),
  2052. UpdatedTime: time.Now().Unix(),
  2053. }
  2054. //只针对广慈医院
  2055. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 {
  2056. // 查询病人是否有透前评估数据
  2057. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2058. //如果有数据就插入
  2059. if errcode == nil {
  2060. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2061. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2062. record.BreathingRate = befor.BreathingRate
  2063. record.PulseFrequency = befor.PulseFrequency
  2064. record.Temperature = befor.Temperature
  2065. }
  2066. }
  2067. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2068. if newdialysisRecord.ID > 0 {
  2069. err := service.CreateMonitor(&record)
  2070. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  2071. redis := service.RedisClient()
  2072. //清空key 值
  2073. redis.Set(key, "", time.Second)
  2074. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  2075. redis.Set(keyOne, "", time.Second)
  2076. defer redis.Close()
  2077. if err != nil {
  2078. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2079. return
  2080. }
  2081. }
  2082. go func() {
  2083. ssoDomain := beego.AppConfig.String("call_domain")
  2084. api := ssoDomain + "/index/uppatient"
  2085. values := make(url.Values)
  2086. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  2087. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2088. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  2089. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  2090. http.PostForm(api, values)
  2091. }()
  2092. this.ServeSuccessJSON(map[string]interface{}{
  2093. "dialysis_order": newdialysisRecord,
  2094. "monitor": record,
  2095. })
  2096. return
  2097. }
  2098. func (c *DialysisAPIController) PostSolution() {
  2099. id, _ := c.GetInt64("patient", 0)
  2100. recordDateStr := c.GetString("record_date")
  2101. if id <= 0 {
  2102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2103. return
  2104. }
  2105. adminUserInfo := c.GetMobileAdminUserInfo()
  2106. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2107. if patient.ID == 0 {
  2108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2109. return
  2110. }
  2111. if len(recordDateStr) == 0 {
  2112. recordDateStr = time.Now().Format("2006-01-02")
  2113. }
  2114. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2115. if parseDateErr != nil {
  2116. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2118. return
  2119. }
  2120. mode_id, _ := c.GetInt64("mode_id", 0)
  2121. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  2122. dialyzer, _ := c.GetInt64("dialyzer", 0)
  2123. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  2124. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  2125. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  2126. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  2127. replacement_way, _ := c.GetInt64("replacement_way", 0)
  2128. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  2129. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  2130. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  2131. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  2132. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  2133. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  2134. kalium, _ := c.GetFloat("kalium", 0)
  2135. sodium, _ := c.GetFloat("sodium", 0)
  2136. calcium, _ := c.GetFloat("calcium", 0)
  2137. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  2138. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  2139. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  2140. glucose, _ := c.GetFloat("glucose", 0)
  2141. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  2142. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  2143. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  2144. conductivity, _ := c.GetFloat("conductivity", 0)
  2145. remark := c.GetString("remark")
  2146. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  2147. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  2148. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  2149. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  2150. body_fluid, _ := c.GetInt64("body_fluid", 0)
  2151. special_medicine, _ := c.GetInt64("special_medicine", 0)
  2152. special_medicine_other := c.GetString("special_medicine_other")
  2153. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  2154. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  2155. blood_access, _ := c.GetInt64("blood_access", 0)
  2156. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  2157. body_fluid_other := c.GetString("body_fluid_other")
  2158. replacement_total, _ := c.GetFloat("replacement_total", 0)
  2159. niprocart, _ := c.GetInt64("niprocart", 0)
  2160. jms, _ := c.GetInt64("jms", 0)
  2161. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  2162. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  2163. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  2164. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  2165. filtryzer, _ := c.GetInt64("filtryzer", 0)
  2166. target_ktv, _ := c.GetFloat("target_ktv", 0)
  2167. dialyzers, _ := c.GetInt64("dialyzers", 0)
  2168. injector, _ := c.GetInt64("injector", 0)
  2169. bloodlines, _ := c.GetInt64("bloodlines", 0)
  2170. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  2171. safe_package, _ := c.GetInt64("package", 0)
  2172. a_liquid, _ := c.GetInt64("a_liquid", 0)
  2173. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  2174. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  2175. blood := c.GetString("blood")
  2176. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  2177. dialysis_irrigation := c.GetString("dialysis_irrigation")
  2178. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  2179. displace_speed := c.GetString("displace_speed")
  2180. illness, _ := c.GetInt64("illness")
  2181. amylaceum := c.GetString("amylaceum")
  2182. single_time := c.GetString("single_time")
  2183. single_water := c.GetString("single_water")
  2184. replacement_flow := c.GetString("replacement_flow")
  2185. plasma_separator := c.GetString("plasma_separator")
  2186. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  2187. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  2188. oxygen_flow := c.GetString("oxygen_flow")
  2189. oxygen_time := c.GetString("oxygen_time")
  2190. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  2191. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  2192. puncture_needle := c.GetString("puncture_needle")
  2193. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  2194. epo := c.GetString("epo")
  2195. epo_count, _ := c.GetFloat("epo_count", 0)
  2196. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  2197. pre_impulse := c.GetString("pre_impulse")
  2198. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  2199. if mode_id > 0 {
  2200. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2201. }
  2202. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2203. //
  2204. //if template.TemplateId == 2 || template.TemplateId == 6 {
  2205. // if appRole.UserType == 3 {
  2206. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2207. // if getPermissionErr != nil {
  2208. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2209. // return
  2210. // } else if headNursePermission == nil {
  2211. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2212. // return
  2213. // }
  2214. // }
  2215. //}
  2216. prescription := models.DialysisPrescription{
  2217. UserOrgId: adminUserInfo.Org.Id,
  2218. PatientId: id,
  2219. RecordDate: recordDate.Unix(),
  2220. ModeId: mode_id,
  2221. DialysisDuration: dialysis_duration,
  2222. Dialyzer: dialyzer,
  2223. PerfusionApparatus: perfusion_apparatus,
  2224. BloodFlowVolume: blood_flow_volume,
  2225. DewaterAmount: dewater_amount,
  2226. DisplaceLiqui: displace_liqui,
  2227. ReplacementWay: replacement_way,
  2228. Anticoagulant: anticoagulant,
  2229. AnticoagulantShouji: anticoagulant_shouji,
  2230. AnticoagulantWeichi: anticoagulant_weichi,
  2231. AnticoagulantZongliang: anticoagulant_zongliang,
  2232. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  2233. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  2234. Kalium: kalium,
  2235. Sodium: sodium,
  2236. Calcium: calcium,
  2237. Bicarbonate: bicarbonate,
  2238. Glucose: glucose,
  2239. // DryWeight: dry_weight,
  2240. DialysateFlow: dialysate_flow,
  2241. DialysateTemperature: dialysate_temperature,
  2242. Conductivity: conductivity,
  2243. Remark: remark,
  2244. Status: 1,
  2245. CreatedTime: time.Now().Unix(),
  2246. UpdatedTime: time.Now().Unix(),
  2247. DialysisDurationMinute: dialysisDurationMinute,
  2248. DialysisDurationHour: dialysisDurationHour,
  2249. TargetUltrafiltration: targetUltrafiltration,
  2250. DialysateFormulation: dialysateFormulation,
  2251. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  2252. BodyFluid: body_fluid,
  2253. SpecialMedicine: special_medicine,
  2254. SpecialMedicineOther: special_medicine_other,
  2255. DisplaceLiquiPart: displace_liqui_part,
  2256. DisplaceLiquiValue: displace_liqui_value,
  2257. BloodAccess: blood_access,
  2258. Ultrafiltration: ultrafiltration,
  2259. BodyFluidOther: body_fluid_other,
  2260. ReplacementTotal: replacement_total,
  2261. Niprocart: niprocart,
  2262. Jms: jms,
  2263. FistulaNeedleSet: fistula_needle_set,
  2264. FistulaNeedleSet16: fistula_needle_set_16,
  2265. Hemoperfusion: hemoperfusion,
  2266. DialyserSterilised: dialyser_sterilised,
  2267. Filtryzer: filtryzer,
  2268. TargetKtv: target_ktv,
  2269. Dialyzers: dialyzers,
  2270. Injector: injector,
  2271. Bloodlines: bloodlines,
  2272. TubingHemodialysis: tubing_hemodialysis,
  2273. Package: safe_package,
  2274. ALiquid: a_liquid,
  2275. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  2276. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  2277. Blood: blood,
  2278. DialysisDialyszers: dialysis_dialyszers,
  2279. DialysisIrrigation: dialysis_irrigation,
  2280. AntioxidantCommodityName: antioxidant_commodity_name,
  2281. DisplaceSpeed: displace_speed,
  2282. Illness: illness,
  2283. Amylaceum: amylaceum,
  2284. SingleWater: single_water,
  2285. SingleTime: single_time,
  2286. ReplacementFlow: replacement_flow,
  2287. PlasmaSeparator: plasma_separator,
  2288. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  2289. OxygenUptake: oxygen_uptake,
  2290. OxygenTime: oxygen_time,
  2291. OxygenFlow: oxygen_flow,
  2292. HemodialysisPipelines: hemodialysis_pipelines,
  2293. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  2294. PunctureNeedle: puncture_needle,
  2295. PunctureNeedleCount: puncture_needle_count,
  2296. Epo: epo,
  2297. EpoCount: epo_count,
  2298. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  2299. PreImpulse: impulse,
  2300. }
  2301. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2302. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2303. //
  2304. if appRole.UserType == 2 || appRole.UserType == 1 {
  2305. prescription_doctor = adminUserInfo.AdminUser.Id
  2306. prescription.PrescriptionDoctor = prescription_doctor
  2307. }
  2308. if dialysisPrescription.ID == 0 { //新增
  2309. prescription.Creater = adminUserInfo.AdminUser.Id
  2310. } else { //修改
  2311. if dialysisPrescription.Creater == 0 {
  2312. prescription.Creater = adminUserInfo.AdminUser.Id
  2313. } else {
  2314. prescription.Creater = dialysisPrescription.Creater
  2315. }
  2316. //if/**/
  2317. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2318. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  2319. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2320. // if getPermissionErr != nil {
  2321. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2322. // return
  2323. // } else if headNursePermission == nil {
  2324. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2325. // return
  2326. // }
  2327. //}
  2328. //prescription.Creater = dialysisPrescription.Creater
  2329. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2330. prescription.Modifier = adminUserInfo.AdminUser.Id
  2331. prescription.ID = dialysisPrescription.ID
  2332. }
  2333. solution := models.DialysisSolution{
  2334. RegistrarsId: adminUserInfo.AdminUser.Id,
  2335. UserOrgId: adminUserInfo.Org.Id,
  2336. Doctor: prescription_doctor,
  2337. PatientId: id,
  2338. ModeId: mode_id,
  2339. DialysisDuration: dialysis_duration,
  2340. PerfusionApparatus: perfusion_apparatus,
  2341. BloodFlowVolume: blood_flow_volume,
  2342. Dewater: dewater_amount,
  2343. DisplaceLiqui: displace_liqui,
  2344. ReplacementWay: replacement_way,
  2345. Anticoagulant: anticoagulant,
  2346. AnticoagulantShouji: anticoagulant_shouji,
  2347. AnticoagulantWeichi: anticoagulant_weichi,
  2348. AnticoagulantZongliang: anticoagulant_zongliang,
  2349. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  2350. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  2351. Kalium: kalium,
  2352. Sodium: sodium,
  2353. Calcium: calcium,
  2354. Bicarbonate: bicarbonate,
  2355. Glucose: glucose,
  2356. // DryWeight: dry_weight,
  2357. DialysateFlow: dialysate_flow,
  2358. DialysateTemperature: dialysate_temperature,
  2359. Conductivity: conductivity,
  2360. Remark: remark,
  2361. Status: 1,
  2362. CreatedTime: time.Now().Unix(),
  2363. UpdatedTime: time.Now().Unix(),
  2364. DialysisDurationMinute: dialysisDurationMinute,
  2365. DialysisDurationHour: dialysisDurationHour,
  2366. TargetUltrafiltration: targetUltrafiltration,
  2367. DialysateFormulation: dialysateFormulation,
  2368. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  2369. BodyFluid: body_fluid,
  2370. SpecialMedicine: special_medicine,
  2371. SpecialMedicineOther: special_medicine_other,
  2372. DisplaceLiquiPart: displace_liqui_part,
  2373. DisplaceLiquiValue: displace_liqui_value,
  2374. BloodAccess: blood_access,
  2375. Ultrafiltration: ultrafiltration,
  2376. BodyFluidOther: body_fluid_other,
  2377. ReplacementTotal: replacement_total,
  2378. TargetKtv: target_ktv,
  2379. DialysisDialyszers: dialysis_dialyszers,
  2380. DialysisIrrigation: dialysis_irrigation,
  2381. HemodialysisPipelines: hemodialysis_pipelines,
  2382. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  2383. PunctureNeedle: puncture_needle,
  2384. PunctureNeedleCount: puncture_needle_count,
  2385. Epo: epo,
  2386. EpoCount: epo_count,
  2387. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  2388. PreImpulse: impulse,
  2389. }
  2390. //针对河间咸的
  2391. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  2392. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  2393. solution.DisplaceLiquiPart = 0
  2394. solution.DisplaceLiquiValue = 0
  2395. }
  2396. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2397. prescription.DisplaceLiquiPart = 0
  2398. prescription.DisplaceLiquiValue = 0
  2399. }
  2400. }
  2401. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  2402. //获取key,清空redis
  2403. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2404. redis := service.RedisClient()
  2405. defer redis.Close()
  2406. //清空key 值
  2407. redis.Set(key, "", time.Second)
  2408. //清空长期医嘱的key
  2409. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2410. redis.Set(soulution_key, "", time.Second)
  2411. //查询最近透析准备表里是否存在 透析器 灌流器
  2412. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2413. redis.Set(keyOne, "", time.Second)
  2414. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2415. redis.Set(keyTwo, "", time.Second)
  2416. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2417. redis.Set(keyThree, "", time.Second)
  2418. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2419. redis.Set(keyFour, "", time.Second)
  2420. //splitStr := strings.Split(dialysis_dialyszers, ",")
  2421. //
  2422. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  2423. //
  2424. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  2425. //if len(mation)>0{
  2426. // for _, item := range splitStr {
  2427. // for _,it := range mation{
  2428. // if(item == it.SpecificationName){
  2429. //
  2430. // //查询最近一次的透析器
  2431. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2432. //
  2433. // if errcode == gorm.ErrRecordNotFound{
  2434. // //插入数据
  2435. // prepare := models.DialysisBeforePrepare{
  2436. // UserOrgId: adminUserInfo.Org.Id,
  2437. // PatientId: id,
  2438. // RecordDate: recordDate.Unix(),
  2439. // GoodTypeId: it.GoodTypeId,
  2440. // GoodId: it.ID,
  2441. // Count: 1,
  2442. // Ctime: time.Now().Unix(),
  2443. // Creater: adminUserInfo.AdminUser.Id,
  2444. // Status:1,
  2445. //
  2446. // }
  2447. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2448. // fmt.Println("",errcode)
  2449. // }
  2450. // }
  2451. // }
  2452. //
  2453. // }
  2454. //
  2455. // for _, item := range splitIrrigation {
  2456. // for _,it := range mation{
  2457. // if(item == it.SpecificationName){
  2458. // //查询最近一次的透析器
  2459. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2460. // if errcode == gorm.ErrRecordNotFound{
  2461. // //插入数据
  2462. // prepare := models.DialysisBeforePrepare{
  2463. // UserOrgId: adminUserInfo.Org.Id,
  2464. // PatientId: id,
  2465. // RecordDate: recordDate.Unix(),
  2466. // GoodTypeId: it.GoodTypeId,
  2467. // GoodId: it.ID,
  2468. // Count: 1,
  2469. // Ctime: time.Now().Unix(),
  2470. // Creater: adminUserInfo.AdminUser.Id,
  2471. // Status:1,
  2472. //
  2473. // }
  2474. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2475. // fmt.Println(errcode)
  2476. // }
  2477. // }
  2478. // }
  2479. // }
  2480. //}
  2481. c.ServeSuccessJSON(map[string]interface{}{
  2482. "solution": &solution,
  2483. "prescription": &prescription,
  2484. })
  2485. }
  2486. func (c *DialysisAPIController) GetAcceptsAssessment() {
  2487. patient, _ := c.GetInt64("patient", 0)
  2488. adminUserInfo := c.GetMobileAdminUserInfo()
  2489. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  2490. c.ServeSuccessJSON(map[string]interface{}{
  2491. "receiveTreatmentAsses": receiveTreatmentAsses,
  2492. })
  2493. }
  2494. func (this *DialysisAPIController) PostSignInfo() {
  2495. patientID, _ := this.GetInt64("patient_id")
  2496. recordDateStr := this.GetString("date")
  2497. if patientID <= 0 {
  2498. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2499. return
  2500. }
  2501. if len(recordDateStr) == 0 {
  2502. recordDateStr = time.Now().Format("2006-01-02")
  2503. }
  2504. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2505. if parseDateErr != nil {
  2506. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2507. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2508. return
  2509. }
  2510. adminInfo := this.GetMobileAdminUserInfo()
  2511. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  2512. if err != nil {
  2513. this.ErrorLog("签名失败:%v", err)
  2514. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2515. return
  2516. }
  2517. this.ServeSuccessJSON(map[string]interface{}{
  2518. "doctor_id": adminInfo.AdminUser.Id,
  2519. })
  2520. }
  2521. func (this *DialysisAPIController) GetLastMonitorRecord() {
  2522. patientID, _ := this.GetInt64("patient_id")
  2523. adminInfo := this.GetMobileAdminUserInfo()
  2524. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  2525. this.ServeSuccessJSON(map[string]interface{}{
  2526. "monitor": record,
  2527. })
  2528. }
  2529. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  2530. thisTime := time.Now()
  2531. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  2532. timeLayout := "2006-01-02 15:04:05"
  2533. loc, _ := time.LoadLocation("Local")
  2534. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2535. theAssessmentDateTime := theStartTime.Unix()
  2536. patientID, _ := this.GetInt64("patient_id")
  2537. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  2538. adminInfo := this.GetMobileAdminUserInfo()
  2539. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  2540. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  2541. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  2542. var ultrafiltration_rate float64
  2543. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  2544. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  2545. fmt.Println(evaluation)
  2546. if prescription.ID > 0 {
  2547. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2548. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2549. if template.TemplateId == 6 && adminInfo.Org.Id != 9538 {
  2550. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2551. record.UltrafiltrationRate = ultrafiltration_rate
  2552. }
  2553. //if template.TemplateId == 6 && adminInfo.Org.Id ==9671{
  2554. // dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2555. // ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2556. // record.UltrafiltrationRate = ultrafiltration_rate
  2557. //}
  2558. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  2559. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  2560. record.UltrafiltrationRate = ultrafiltration_rate
  2561. }
  2562. if template.TemplateId == 20 || template.TemplateId == 22 {
  2563. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2564. record.UltrafiltrationRate = ultrafiltration_rate
  2565. }
  2566. // 只针对方济医院
  2567. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  2568. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2569. ultrafiltration_rate = value
  2570. record.UltrafiltrationRate = ultrafiltration_rate
  2571. }
  2572. fmt.Println("hhh23232323223232323323232323", template.TemplateId)
  2573. if template.TemplateId == 41 || template.TemplateId == 47 {
  2574. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2575. fmt.Println("prescritpin2332322323232323223", ultrafiltration_rate)
  2576. record.UltrafiltrationRate = ultrafiltration_rate
  2577. }
  2578. if template.TemplateId == 43 {
  2579. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2580. record.UltrafiltrationRate = ultrafiltration_rate
  2581. }
  2582. if template.TemplateId == 46 || template.TemplateId == 54 {
  2583. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2584. record.UltrafiltrationRate = ultrafiltration_rate
  2585. }
  2586. //if template.TemplateId == 47 {
  2587. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2588. // record.UltrafiltrationRate = ultrafiltration_rate
  2589. //}
  2590. }
  2591. }
  2592. // record.UltrafiltrationRate = ultrafiltration_rate
  2593. record.UltrafiltrationVolume = 0
  2594. 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
  2595. if ultrafiltration_rate > 0 {
  2596. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  2597. record.UltrafiltrationVolume = value
  2598. }
  2599. }
  2600. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 { //adminInfo.Org.Id == 9538
  2601. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  2602. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  2603. record.UltrafiltrationVolume = ultrafiltration_volume
  2604. }
  2605. }
  2606. if template.TemplateId == 47 || template.TemplateId == 54 {
  2607. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  2608. }
  2609. this.ServeSuccessJSON(map[string]interface{}{
  2610. "monitor": record,
  2611. })
  2612. }
  2613. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  2614. record_id, _ := this.GetInt64("id")
  2615. nurseID, _ := this.GetInt64("nurse")
  2616. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2617. bedID, _ := this.GetInt64("bed")
  2618. start_time := this.GetString("start_time")
  2619. schedual_type, _ := this.GetInt64("schedual_type")
  2620. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2621. change_nurse, _ := this.GetInt64("change_nurse")
  2622. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2623. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2624. patient_id, _ := this.GetInt64("patient_id")
  2625. record_date, _ := this.GetInt64("record_date")
  2626. if record_id == 0 {
  2627. this.ErrorLog("id:%v", record_id)
  2628. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2629. return
  2630. }
  2631. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2632. if parseStartDateErr != nil {
  2633. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2634. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2635. return
  2636. }
  2637. adminUserInfo := this.GetMobileAdminUserInfo()
  2638. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2639. if getNurseErr != nil {
  2640. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2641. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2642. return
  2643. } else if nurse == nil {
  2644. this.ErrorLog("护士不存在")
  2645. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2646. return
  2647. }
  2648. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2649. //if getNurseErr != nil {
  2650. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  2651. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2652. // return
  2653. //} else if nurse == nil {
  2654. // this.ErrorLog("护士不存在")
  2655. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2656. // return
  2657. //}
  2658. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2659. if getDeviceNumberErr != nil {
  2660. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2661. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2662. return
  2663. } else if deviceNumber == nil {
  2664. this.ErrorLog("床位号不存在")
  2665. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2666. return
  2667. }
  2668. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  2669. //
  2670. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  2671. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2672. // if getPermissionErr != nil {
  2673. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2674. // return
  2675. // } else if headNursePermission == nil {
  2676. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2677. // return
  2678. // }
  2679. //}
  2680. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2681. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2682. timeLayout := "2006-01-02 15:04:05"
  2683. loc, _ := time.LoadLocation("Local")
  2684. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2685. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2686. schedulestartTime := theStartTime.Unix()
  2687. scheduleendTime := theEndTime.Unix()
  2688. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2689. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2690. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2691. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  2692. if err == gorm.ErrRecordNotFound { //空床位
  2693. // 修改了床位逻辑
  2694. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2695. if daySchedule.ID > 0 {
  2696. //daySchedule.BedId = bedID
  2697. //daySchedule.PartitionId = deviceNumber.ZoneID
  2698. //daySchedule.ScheduleType = schedual_type
  2699. //daySchedule.UpdatedTime = time.Now().Unix()
  2700. //err := service.UpdateSchedule(&daySchedule)
  2701. xtSchedule := models.Schedule{
  2702. PartitionId: deviceNumber.ZoneID,
  2703. BedId: bedID,
  2704. ScheduleType: schedual_type,
  2705. UpdatedTime: time.Now().Unix(),
  2706. }
  2707. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2708. if err != nil {
  2709. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2710. return
  2711. }
  2712. }
  2713. } else if err == nil {
  2714. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2715. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2716. if daySchedule.ID > 0 {
  2717. //daySchedule.BedId = bedID
  2718. //daySchedule.PartitionId = deviceNumber.ZoneID
  2719. //
  2720. //daySchedule.ScheduleType = schedual_type
  2721. //daySchedule.UpdatedTime = time.Now().Unix()
  2722. //err := service.UpdateSchedule(&daySchedule)
  2723. xtSchedule := models.Schedule{
  2724. PartitionId: deviceNumber.ZoneID,
  2725. BedId: bedID,
  2726. ScheduleType: schedual_type,
  2727. UpdatedTime: time.Now().Unix(),
  2728. }
  2729. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2730. if err != nil {
  2731. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2732. return
  2733. }
  2734. }
  2735. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2736. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2737. return
  2738. }
  2739. } else if err != nil {
  2740. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2741. return
  2742. }
  2743. }
  2744. dialysisRecord := &models.DialysisOrder{
  2745. ID: record_id,
  2746. UserOrgId: adminUserInfo.Org.Id,
  2747. BedID: bedID,
  2748. StartNurse: nurseID,
  2749. StartTime: startDate.Unix(),
  2750. PunctureNurse: puncture_nurse,
  2751. Creator: adminUserInfo.AdminUser.Id,
  2752. Modifier: adminUserInfo.AdminUser.Id,
  2753. WashpipeNurse: washpipe_nurse,
  2754. SchedualType: schedual_type,
  2755. ChangeNurse: change_nurse,
  2756. DifficultPunctureNurse: difficult_puncture_nurse,
  2757. NewFistulaNurse: new_fistula_nurse,
  2758. }
  2759. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  2760. redis := service.RedisClient()
  2761. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  2762. redis.Set(key, "", time.Second)
  2763. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  2764. //清空key 值
  2765. redis.Set(keyOne, "", time.Second)
  2766. scheduleDateStartOne := startDate.Format("2006-01-02")
  2767. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2768. redis.Set(keyTwo, "", time.Second)
  2769. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  2770. redis.Set(keyThree, "", time.Second)
  2771. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  2772. redis.Set(keyFour, "", time.Second)
  2773. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  2774. redis.Set(keyFive, "", time.Second)
  2775. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  2776. redis.Set(keySix, "", time.Second)
  2777. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  2778. redis.Set(keySeven, "", time.Second)
  2779. if updateErr != nil {
  2780. this.ErrorLog("修改上机失败:%v", updateErr)
  2781. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2782. return
  2783. }
  2784. if updateErr == nil {
  2785. if tempDialysisRecord.Stage == 2 {
  2786. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  2787. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2788. fmt.Println(value)
  2789. a, b := math.Modf(value)
  2790. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2791. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2792. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  2793. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  2794. redis := service.RedisClient()
  2795. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  2796. redis.Set(key, "", time.Second)
  2797. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  2798. redis.Set(keyOne, "", time.Second)
  2799. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  2800. //清空key 值
  2801. redis.Set(keySix, "", time.Second)
  2802. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  2803. redis.Set(keySeven, "", time.Second)
  2804. redis.Close()
  2805. if updateAssessmentErr != nil {
  2806. utils.ErrorLog("%v", updateAssessmentErr)
  2807. }
  2808. }
  2809. }
  2810. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2811. this.ServeSuccessJSON(map[string]interface{}{
  2812. "dialysis_order": dialysisRecords,
  2813. })
  2814. }
  2815. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  2816. record_id, _ := c.GetInt64("id")
  2817. nurseID, _ := c.GetInt64("nurse")
  2818. end_time := c.GetString("end_time")
  2819. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2820. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  2821. catheter := c.GetString("catheter")
  2822. cruor := c.GetString("cruor")
  2823. if record_id <= 0 || nurseID <= 0 {
  2824. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2825. return
  2826. }
  2827. adminUserInfo := c.GetMobileAdminUserInfo()
  2828. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2829. if getNurseErr != nil {
  2830. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2832. return
  2833. } else if nurse == nil {
  2834. c.ErrorLog("护士不存在")
  2835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2836. return
  2837. }
  2838. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2839. if parseEndDateErr != nil {
  2840. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2842. return
  2843. }
  2844. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  2845. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  2846. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2847. // if getPermissionErr != nil {
  2848. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2849. // return
  2850. // } else if headNursePermission == nil {
  2851. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2852. // return
  2853. // }
  2854. //}
  2855. dialysisRecord := &models.DialysisOrder{
  2856. ID: record_id,
  2857. UserOrgId: adminUserInfo.Org.Id,
  2858. EndTime: endDate.Unix(),
  2859. FinishNurse: nurseID,
  2860. FinishModifier: adminUserInfo.AdminUser.Id,
  2861. PuncturePointHaematoma: puncture_point_haematoma,
  2862. BloodAccessInternalFistula: blood_access_internal_fistula,
  2863. Catheter: catheter,
  2864. Cruor: cruor,
  2865. }
  2866. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  2867. redis := service.RedisClient()
  2868. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  2869. //清空key 值
  2870. redis.Set(key, "", time.Second)
  2871. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  2872. //清空key 值
  2873. redis.Set(keyOne, "", time.Second)
  2874. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  2875. redis.Set(keySeven, "", time.Second)
  2876. redis.Close()
  2877. if updateErr != nil {
  2878. c.ErrorLog("修改下机失败:%v", updateErr)
  2879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2880. return
  2881. }
  2882. if updateErr == nil {
  2883. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  2884. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2885. a, b := math.Modf(value)
  2886. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2887. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2888. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  2889. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  2890. redis := service.RedisClient()
  2891. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  2892. redis.Set(keyTen, "", time.Second)
  2893. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  2894. redis.Set(keyTwo, "", time.Second)
  2895. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  2896. redis.Set(key, "", time.Second)
  2897. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  2898. redis.Set(keyThree, "", time.Second)
  2899. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  2900. redis.Set(keySeven, "", time.Second)
  2901. defer redis.Close()
  2902. if updateAssessmentErr != nil {
  2903. utils.ErrorLog("%v", updateAssessmentErr)
  2904. }
  2905. }
  2906. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2907. c.ServeSuccessJSON(map[string]interface{}{
  2908. "dialysis_order": dialysisRecords,
  2909. })
  2910. }
  2911. func (c *DialysisAPIController) GetLongAdvice() {
  2912. patient_id, _ := c.GetInt64("id")
  2913. adminUserInfo := c.GetMobileAdminUserInfo()
  2914. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  2915. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  2916. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  2917. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  2918. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  2919. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  2920. c.ServeSuccessJSON(map[string]interface{}{
  2921. "status": "1",
  2922. })
  2923. return
  2924. } else { //开启推送提醒
  2925. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  2926. var advice_three []*models.DoctorAdvice
  2927. recordDateStr := time.Now().Format("2006-01-02")
  2928. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2929. nowtime := recordDate.Unix()
  2930. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  2931. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  2932. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  2933. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  2934. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  2935. for _, advice := range advices {
  2936. if advice.FrequencyType == 3 {
  2937. t := time.Now()
  2938. week := int(t.Weekday())
  2939. fmt.Println(t.Weekday())
  2940. fmt.Println(week)
  2941. switch week {
  2942. case 1:
  2943. if strings.Index(advice.WeekDay, "周一") == -1 {
  2944. advice_three = append(advice_three, advice)
  2945. }
  2946. break
  2947. case 2:
  2948. if strings.Index(advice.WeekDay, "周二") == -1 {
  2949. advice_three = append(advice_three, advice)
  2950. }
  2951. break
  2952. case 3:
  2953. if strings.Index(advice.WeekDay, "周三") == -1 {
  2954. advice_three = append(advice_three, advice)
  2955. }
  2956. break
  2957. case 4:
  2958. if strings.Index(advice.WeekDay, "周四") == -1 {
  2959. advice_three = append(advice_three, advice)
  2960. }
  2961. break
  2962. case 5:
  2963. if strings.Index(advice.WeekDay, "周五") == -1 {
  2964. advice_three = append(advice_three, advice)
  2965. }
  2966. break
  2967. case 6:
  2968. if strings.Index(advice.WeekDay, "周六") == -1 {
  2969. advice_three = append(advice_three, advice)
  2970. }
  2971. break
  2972. case 0:
  2973. if strings.Index(advice.WeekDay, "周日") == -1 {
  2974. advice_three = append(advice_three, advice)
  2975. }
  2976. break
  2977. }
  2978. }
  2979. }
  2980. for _, advice := range advices_two {
  2981. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  2982. now := p.Unix()
  2983. dayStr := strconv.FormatInt(advice.DayCount, 10)
  2984. dayStr2 := "-" + dayStr
  2985. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  2986. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  2987. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  2988. for _, ad := range advices {
  2989. advice_three = append(advice_three, ad)
  2990. }
  2991. }
  2992. if err == nil {
  2993. c.ServeSuccessJSON(map[string]interface{}{
  2994. "status": "2",
  2995. "advices": advices,
  2996. "advices_two": RemoveRepeatedElement(advice_three),
  2997. "is_open_remind": config.IsOpenRemind,
  2998. "his_config_open": hisConfig.IsOpen,
  2999. "is_advice_open": is_advice_open.IsAdviceOpen,
  3000. "prescription_open": prescription_open.IsOpen,
  3001. })
  3002. }
  3003. }
  3004. }
  3005. func (c *DialysisAPIController) GetLongAdviceOne() {
  3006. patient_id, _ := c.GetInt64("id")
  3007. startTime := c.GetString("schedule_date")
  3008. timeLayout := "2006-01-02"
  3009. loc, _ := time.LoadLocation("Local")
  3010. var theStartTime int64
  3011. if len(startTime) > 0 {
  3012. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3013. if err != nil {
  3014. utils.ErrorLog(err.Error())
  3015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3016. return
  3017. }
  3018. theStartTime = theTime.Unix()
  3019. }
  3020. adminUserInfo := c.GetMobileAdminUserInfo()
  3021. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  3022. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  3023. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  3024. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  3025. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3026. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3027. c.ServeSuccessJSON(map[string]interface{}{
  3028. "status": "1",
  3029. })
  3030. return
  3031. } else { //开启推送提醒
  3032. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3033. var advice_three []*models.DoctorAdvice
  3034. fmt.Println("theStartTime23434343433434433443434343434334", theStartTime)
  3035. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  3036. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  3037. for _, advice := range advices {
  3038. if advice.FrequencyType == 3 {
  3039. t := time.Now()
  3040. week := int(t.Weekday())
  3041. fmt.Println(t.Weekday())
  3042. fmt.Println(week)
  3043. switch week {
  3044. case 1:
  3045. if strings.Index(advice.WeekDay, "周一") == -1 {
  3046. advice_three = append(advice_three, advice)
  3047. }
  3048. break
  3049. case 2:
  3050. if strings.Index(advice.WeekDay, "周二") == -1 {
  3051. advice_three = append(advice_three, advice)
  3052. }
  3053. break
  3054. case 3:
  3055. if strings.Index(advice.WeekDay, "周三") == -1 {
  3056. advice_three = append(advice_three, advice)
  3057. }
  3058. break
  3059. case 4:
  3060. if strings.Index(advice.WeekDay, "周四") == -1 {
  3061. advice_three = append(advice_three, advice)
  3062. }
  3063. break
  3064. case 5:
  3065. if strings.Index(advice.WeekDay, "周五") == -1 {
  3066. advice_three = append(advice_three, advice)
  3067. }
  3068. break
  3069. case 6:
  3070. if strings.Index(advice.WeekDay, "周六") == -1 {
  3071. advice_three = append(advice_three, advice)
  3072. }
  3073. break
  3074. case 0:
  3075. if strings.Index(advice.WeekDay, "周日") == -1 {
  3076. advice_three = append(advice_three, advice)
  3077. }
  3078. break
  3079. }
  3080. }
  3081. }
  3082. for _, advice := range advices_two {
  3083. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3084. now := p.Unix()
  3085. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3086. dayStr2 := "-" + dayStr
  3087. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3088. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3089. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  3090. for _, ad := range advices {
  3091. advice_three = append(advice_three, ad)
  3092. }
  3093. }
  3094. if err == nil {
  3095. c.ServeSuccessJSON(map[string]interface{}{
  3096. "status": "2",
  3097. "advices": advices,
  3098. "advices_two": RemoveRepeatedElement(advice_three),
  3099. "is_open_remind": config.IsOpenRemind,
  3100. "his_config_open": hisConfig.IsOpen,
  3101. "is_advice_open": is_advice_open.IsAdviceOpen,
  3102. "prescription_open": prescription_open.IsOpen,
  3103. })
  3104. }
  3105. }
  3106. }
  3107. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  3108. newArr = make([]*models.DoctorAdvice, 0)
  3109. for i := 0; i < len(arr); i++ {
  3110. repeat := false
  3111. for j := i + 1; j < len(arr); j++ {
  3112. if arr[i].ID == arr[j].ID {
  3113. repeat = true
  3114. break
  3115. }
  3116. }
  3117. if !repeat {
  3118. newArr = append(newArr, arr[i])
  3119. }
  3120. }
  3121. return
  3122. }
  3123. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  3124. patient, _ := c.GetInt64("id", 0)
  3125. groupNo, _ := c.GetInt64("groupno", 0)
  3126. if patient <= 0 {
  3127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3128. return
  3129. }
  3130. adminUserInfo := c.GetMobileAdminUserInfo()
  3131. dataBody := make(map[string]interface{}, 0)
  3132. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3133. if err != nil {
  3134. utils.ErrorLog(err.Error())
  3135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3136. return
  3137. }
  3138. utils.ErrorLog("%v", dataBody)
  3139. timeLayout := "2006-01-02 15:04"
  3140. loc, _ := time.LoadLocation("Local")
  3141. timeLayout2 := "2006-01-02"
  3142. loc2, _ := time.LoadLocation("Local")
  3143. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3144. utils.ErrorLog("advice_type")
  3145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3146. return
  3147. }
  3148. adviceType := int64(2)
  3149. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3150. utils.ErrorLog("advice_date")
  3151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3152. return
  3153. }
  3154. adviceDate, _ := dataBody["advice_date"].(string)
  3155. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  3156. AdviceDate := theTime.Unix()
  3157. RecordDate := theTime.Unix()
  3158. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3159. utils.ErrorLog("start_time")
  3160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3161. return
  3162. }
  3163. startTime, _ := dataBody["start_time"].(string)
  3164. if len(startTime) == 0 {
  3165. utils.ErrorLog("len(start_time) == 0")
  3166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3167. return
  3168. }
  3169. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  3170. if err != nil {
  3171. utils.ErrorLog(err.Error())
  3172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3173. return
  3174. }
  3175. StartTime := theTime.Unix()
  3176. Remark := ""
  3177. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3178. remark, _ := dataBody["remark"].(string)
  3179. Remark = remark
  3180. }
  3181. var advices []*models.GroupAdvice
  3182. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  3183. utils.ErrorLog("advices")
  3184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3185. return
  3186. }
  3187. adviceNames := dataBody["advices"].([]interface{})
  3188. for _, adviceNameMap := range adviceNames {
  3189. adviceNameM := adviceNameMap.(map[string]interface{})
  3190. var advice models.GroupAdvice
  3191. advice.Remark = Remark
  3192. advice.AdviceType = adviceType
  3193. advice.StartTime = StartTime
  3194. advice.AdviceDate = AdviceDate
  3195. advice.RecordDate = RecordDate
  3196. advice.Status = 1
  3197. advice.CreatedTime = time.Now().Unix()
  3198. advice.UpdatedTime = time.Now().Unix()
  3199. advice.StopState = 2
  3200. advice.ExecutionState = 2
  3201. advice.UserOrgId = adminUserInfo.Org.Id
  3202. advice.PatientId = patient
  3203. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3204. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  3205. utils.ErrorLog("advice_name")
  3206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3207. return
  3208. }
  3209. adviceName, _ := adviceNameM["advice_name"].(string)
  3210. if len(adviceName) == 0 {
  3211. utils.ErrorLog("len(advice_name) == 0")
  3212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3213. return
  3214. }
  3215. advice.AdviceName = adviceName
  3216. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  3217. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  3218. advice.DrugSpec = drugSpec
  3219. }
  3220. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  3221. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  3222. advice.AdviceDesc = adviceDesc
  3223. }
  3224. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  3225. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  3226. advice.DrugSpecUnit = drugSpecUnit
  3227. }
  3228. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  3229. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  3230. // advice.SingleDose = singleDose
  3231. //}
  3232. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  3233. //single_dose := int64(adviceNameM["single_dose"].(float64))
  3234. advice.SingleDose = adviceNameM["single_dose"].(float64)
  3235. }
  3236. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  3237. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  3238. advice.SingleDoseUnit = singleDoseUnit
  3239. }
  3240. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  3241. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  3242. // advice.PrescribingNumber = prescribingNumber
  3243. //}
  3244. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  3245. //single_dose := int64(adviceNameM["single_dose"].(float64))
  3246. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  3247. }
  3248. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  3249. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  3250. advice.PrescribingNumberUnit = prescribingNumberUnit
  3251. }
  3252. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  3253. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  3254. advice.DeliveryWay = deliveryWay
  3255. }
  3256. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3257. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3258. advice.ExecutionFrequency = executionFrequency
  3259. }
  3260. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  3261. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  3262. advice.FrequencyType = frequency_type
  3263. }
  3264. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  3265. day_count := int64(adviceNameM["day_count"].(float64))
  3266. advice.DayCount = day_count
  3267. }
  3268. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  3269. week_day, _ := adviceNameM["week_day"].(string)
  3270. advice.WeekDay = week_day
  3271. }
  3272. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  3273. way := int64(adviceNameM["way"].(float64))
  3274. advice.Way = way
  3275. }
  3276. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  3277. drug_id := int64(adviceNameM["drug_id"].(float64))
  3278. advice.DrugId = drug_id
  3279. }
  3280. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  3281. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  3282. advice.DrugNameId = drug_name_id
  3283. }
  3284. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  3285. template_id, _ := adviceNameM["template_id"].(string)
  3286. advice.TemplateId = template_id
  3287. }
  3288. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  3289. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3290. advice.ExecutionFrequency = executionFrequency
  3291. }
  3292. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  3293. children := adviceNameM["child"].([]interface{})
  3294. if len(children) > 0 {
  3295. for _, childrenMap := range children {
  3296. childMap := childrenMap.(map[string]interface{})
  3297. var child models.GroupAdvice
  3298. child.Remark = Remark
  3299. child.AdviceType = adviceType
  3300. child.StartTime = StartTime
  3301. child.AdviceDate = AdviceDate
  3302. child.RecordDate = RecordDate
  3303. child.Status = 1
  3304. child.CreatedTime = time.Now().Unix()
  3305. child.UpdatedTime = time.Now().Unix()
  3306. child.StopState = 2
  3307. child.ExecutionState = 2
  3308. child.UserOrgId = adminUserInfo.Org.Id
  3309. child.PatientId = patient
  3310. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  3311. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  3312. utils.ErrorLog("child advice_name")
  3313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3314. return
  3315. }
  3316. childAdviceName, _ := childMap["advice_name"].(string)
  3317. if len(childAdviceName) == 0 {
  3318. utils.ErrorLog("len(child advice_name) == 0")
  3319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3320. return
  3321. }
  3322. child.AdviceName = childAdviceName
  3323. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  3324. childAdviceDesc, _ := childMap["advice_desc"].(string)
  3325. child.AdviceDesc = childAdviceDesc
  3326. }
  3327. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  3328. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  3329. child.DrugSpec = childDrugSpec
  3330. }
  3331. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  3332. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  3333. child.DrugSpecUnit = childDrugSpecUnit
  3334. }
  3335. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  3336. child.SingleDose = childMap["single_dose"].(float64)
  3337. }
  3338. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  3339. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  3340. child.SingleDoseUnit = childSingleDoseUnit
  3341. }
  3342. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  3343. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  3344. }
  3345. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  3346. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  3347. child.PrescribingNumberUnit = childPrescribingNumberUnit
  3348. }
  3349. child.DeliveryWay = advice.DeliveryWay
  3350. child.ExecutionFrequency = advice.ExecutionFrequency
  3351. advice.Children = append(advice.Children, &child)
  3352. }
  3353. }
  3354. }
  3355. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  3356. if temp_advice.ID == 0 {
  3357. advices = append(advices, &advice)
  3358. }
  3359. }
  3360. if len(advices) > 0 {
  3361. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  3362. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  3363. redis := service.RedisClient()
  3364. //清空key 值
  3365. redis.Set(key, "", time.Second)
  3366. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3367. redis.Set(keyOne, "", time.Second)
  3368. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3369. defer redis.Close()
  3370. redis.Set(keyThree, "", time.Second)
  3371. if err != nil {
  3372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3373. return
  3374. }
  3375. c.ServeSuccessJSON(map[string]interface{}{
  3376. "msg": "ok",
  3377. "advices": list,
  3378. })
  3379. } else {
  3380. c.ServeSuccessJSON(map[string]interface{}{
  3381. "msg": "ok",
  3382. })
  3383. }
  3384. return
  3385. }
  3386. func (c *DialysisAPIController) UploadDryWeight() {
  3387. patient_id, _ := c.GetInt64("id")
  3388. dry_weight, _ := c.GetFloat("dry_weight")
  3389. doctor_id, _ := c.GetInt64("doctor_id")
  3390. remark := c.GetString("remark")
  3391. adminUserInfo := c.GetMobileAdminUserInfo()
  3392. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  3393. if err == gorm.ErrRecordNotFound {
  3394. dryWeight := &models.SgjPatientDryweight{
  3395. PatientId: patient_id,
  3396. DryWeight: dry_weight,
  3397. Remakes: remark,
  3398. Ctime: time.Now().Unix(),
  3399. Mtime: time.Now().Unix(),
  3400. Creator: doctor_id,
  3401. Status: 1,
  3402. UserOrgId: adminUserInfo.Org.Id,
  3403. AdjustedValue: "/",
  3404. UserId: adminUserInfo.AdminUser.Id,
  3405. }
  3406. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3407. redis := service.RedisClient()
  3408. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  3409. redis.Set(keyOne, "", time.Second)
  3410. loc, _ := time.LoadLocation("Local")
  3411. nowTime := time.Now()
  3412. nowDay := nowTime.Format("2006-01-02")
  3413. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3414. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3415. redis.Set(key, "", time.Second)
  3416. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3417. redis.Set(keyTwo, "", time.Second)
  3418. redis.Close()
  3419. if createErr == nil {
  3420. c.ServeSuccessJSON(map[string]interface{}{
  3421. "msg": "提交成功",
  3422. "weight": dryWeight,
  3423. })
  3424. }
  3425. } else {
  3426. dryWeight := &models.SgjPatientDryweight{
  3427. PatientId: patient_id,
  3428. DryWeight: dry_weight,
  3429. Remakes: remark,
  3430. Ctime: time.Now().Unix(),
  3431. Mtime: time.Now().Unix(),
  3432. Creator: doctor_id,
  3433. Status: 1,
  3434. UserOrgId: adminUserInfo.Org.Id,
  3435. AdjustedValue: "/",
  3436. UserId: adminUserInfo.AdminUser.Id,
  3437. }
  3438. var value float64
  3439. value = dry_weight - weightAdjust.DryWeight
  3440. if value < 0 {
  3441. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  3442. } else if value == 0 {
  3443. dryWeight.AdjustedValue = "/"
  3444. } else if value > 0 {
  3445. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  3446. }
  3447. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3448. redis := service.RedisClient()
  3449. loc, _ := time.LoadLocation("Local")
  3450. nowTime := time.Now()
  3451. nowDay := nowTime.Format("2006-01-02")
  3452. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3453. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  3454. redis.Set(keyOne, "", time.Second)
  3455. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3456. redis.Set(key, "", time.Second)
  3457. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3458. redis.Set(keyTwo, "", time.Second)
  3459. redis.Close()
  3460. if createErr == nil {
  3461. c.ServeSuccessJSON(map[string]interface{}{
  3462. "msg": "提交成功",
  3463. "weight": dryWeight,
  3464. })
  3465. }
  3466. }
  3467. }
  3468. func (c *DialysisAPIController) GetSolution() {
  3469. patient_id, _ := c.GetInt64("patient_id")
  3470. mode_id, _ := c.GetInt64("mode_id")
  3471. adminUserInfo := c.GetMobileAdminUserInfo()
  3472. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  3473. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  3474. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  3475. if err != nil {
  3476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3477. return
  3478. }
  3479. c.ServeSuccessJSON(map[string]interface{}{
  3480. "solution": solution,
  3481. "prescription": prescription,
  3482. "system_prescription": system_prescription,
  3483. })
  3484. }
  3485. func (c *DialysisAPIController) GetSchedule() {
  3486. schedual_type, _ := c.GetInt64("schedual_type")
  3487. adminUserInfo := c.GetMobileAdminUserInfo()
  3488. //timeLayout := "2006-01-02 15:04:05"
  3489. //
  3490. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  3491. //loc, _ := time.LoadLocation("Local")
  3492. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  3493. //scheduleTime := theStartTime.Unix()
  3494. scheduleTime, _ := c.GetInt64("record_date")
  3495. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  3496. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  3497. c.ServeSuccessJSON(map[string]interface{}{
  3498. "number": deviceNumber,
  3499. "list": list,
  3500. })
  3501. }
  3502. func (c *DialysisAPIController) GetPatientId() {
  3503. id, _ := c.GetInt64("id")
  3504. //orgid := c.GetMobileAdminUserInfo().Org.Id
  3505. patientId, _ := service.GetPatientId(id)
  3506. //获取该患者的所有传染病
  3507. list, _ := service.GetPatientInfectious(id)
  3508. c.ServeSuccessJSON(map[string]interface{}{
  3509. "patient": patientId,
  3510. "infectioulist": list,
  3511. })
  3512. }
  3513. func (this *DialysisAPIController) GetDialysisSchedule() {
  3514. schedualDate := this.GetString("date")
  3515. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  3516. if parseDateErr != nil {
  3517. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3518. return
  3519. }
  3520. adminInfo := this.GetMobileAdminUserInfo()
  3521. orgID := adminInfo.Org.Id
  3522. redis := service.RedisClient()
  3523. defer redis.Close()
  3524. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  3525. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  3526. if len(scheduals) > 0 {
  3527. //缓存数据
  3528. scheduals_json, err := json.Marshal(scheduals)
  3529. if err == nil {
  3530. redis.Set(key, scheduals_json, time.Second*30)
  3531. }
  3532. }
  3533. this.ServeSuccessJSON(map[string]interface{}{
  3534. "scheduals": scheduals,
  3535. })
  3536. }
  3537. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  3538. change_type, _ := this.GetInt64("type", 0)
  3539. record_date := this.GetString("record_time")
  3540. patient_id, _ := this.GetInt64("patient_id", 0)
  3541. timeLayout := "2006-01-02"
  3542. loc, _ := time.LoadLocation("Local")
  3543. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3544. record_time := theAdviceRecordTime.Unix()
  3545. adminUserInfo := this.GetMobileAdminUserInfo()
  3546. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  3547. if err == nil {
  3548. if len(advices) == 0 {
  3549. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  3550. return
  3551. } else {
  3552. this.ServeSuccessJSON(map[string]interface{}{
  3553. "advices": advices,
  3554. "schedule": sch,
  3555. })
  3556. return
  3557. }
  3558. } else {
  3559. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3560. return
  3561. }
  3562. }
  3563. func (c *DialysisAPIController) CreateConsumables() {
  3564. record_date := c.GetString("record_time")
  3565. patient_id, _ := c.GetInt64("patient_id", 0)
  3566. active, _ := c.GetInt64("active")
  3567. adminUser := c.GetMobileAdminUserInfo()
  3568. timeLayout := "2006-01-02"
  3569. loc, _ := time.LoadLocation("Local")
  3570. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3571. record_time := theRecordTime.Unix()
  3572. dataBody := make(map[string]interface{}, 0)
  3573. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3574. if err != nil {
  3575. utils.ErrorLog(err.Error())
  3576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3577. return
  3578. }
  3579. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  3580. var beforePrepares []*models.DialysisBeforePrepareGoods
  3581. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  3582. var dialysisBefor []*models.DialysisBeforePrepare
  3583. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3584. goods, _ := dataBody["goods"].([]interface{})
  3585. if len(goods) > 0 {
  3586. for _, item := range goods {
  3587. items := item.(map[string]interface{})
  3588. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3589. utils.ErrorLog("good_id")
  3590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3591. return
  3592. }
  3593. good_id := int64(items["good_id"].(float64))
  3594. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3595. utils.ErrorLog("good_type_id")
  3596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3597. return
  3598. }
  3599. good_type_id := int64(items["good_type_id"].(float64))
  3600. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3601. utils.ErrorLog("count")
  3602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3603. return
  3604. }
  3605. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3606. commdity_code := items["commdity_code"].(string)
  3607. fmt.Println("commdity", commdity_code)
  3608. prepareGoods := &models.DialysisBeforePrepareGoods{
  3609. GoodTypeId: good_type_id,
  3610. GoodId: good_id,
  3611. Count: count,
  3612. StorehouseId: houseConfig.StorehouseOutInfo,
  3613. }
  3614. beforePrepares = append(beforePrepares, prepareGoods)
  3615. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  3616. GoodTypeId: good_type_id,
  3617. GoodId: good_id,
  3618. Count: count,
  3619. StorehouseId: houseConfig.StorehouseOutInfo,
  3620. }
  3621. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  3622. prepare := &models.DialysisBeforePrepare{
  3623. GoodTypeId: good_type_id,
  3624. GoodId: good_id,
  3625. Count: count,
  3626. PatientId: patient_id,
  3627. RecordDate: record_time,
  3628. UserOrgId: adminUser.Org.Id,
  3629. Status: 1,
  3630. Ctime: time.Now().Unix(),
  3631. Creater: adminUser.AdminUser.Id,
  3632. CommdityCode: commdity_code,
  3633. StorehouseId: houseConfig.StorehouseOutInfo,
  3634. }
  3635. dialysisBefor = append(dialysisBefor, prepare)
  3636. }
  3637. }
  3638. //查询是否有库存
  3639. for _, item := range dialysisBefor {
  3640. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  3641. if err == gorm.ErrRecordNotFound {
  3642. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  3643. c.ServeSuccessJSON(map[string]interface{}{
  3644. "message": "1",
  3645. "good_name": goodObj.GoodName,
  3646. "specification_name": goodObj.SpecificationName,
  3647. })
  3648. return
  3649. }
  3650. if err != nil {
  3651. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  3652. c.ServeSuccessJSON(map[string]interface{}{
  3653. "message": "1",
  3654. "good_name": goodObj.GoodName,
  3655. "specification_name": goodObj.SpecificationName,
  3656. })
  3657. return
  3658. }
  3659. }
  3660. //新增
  3661. if active == 1 && len(goods) > 0 {
  3662. for _, item := range dialysisBefor {
  3663. dialyPrepareOne := models.DialysisBeforePrepare{
  3664. GoodTypeId: item.GoodTypeId,
  3665. GoodId: item.GoodId,
  3666. PatientId: item.PatientId,
  3667. RecordDate: item.RecordDate,
  3668. UserOrgId: item.UserOrgId,
  3669. Count: item.Count,
  3670. Ctime: time.Now().Unix(),
  3671. Creater: item.Creater,
  3672. CommdityCode: item.CommdityCode,
  3673. Status: 1,
  3674. StorehouseId: houseConfig.StorehouseOutInfo,
  3675. }
  3676. //先清除再插入
  3677. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  3678. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  3679. //查询默认仓库
  3680. //houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  3681. //goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.Org.Id)
  3682. //var sum_count int64
  3683. //var sum_in_count int64
  3684. //for _, it := range goodList {
  3685. // sum_count += it.StockCount
  3686. // sum_in_count += it.WarehousingCount
  3687. //}
  3688. //service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, adminUser.Org.Id)
  3689. //查询默认仓库
  3690. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  3691. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  3692. var total_count int64
  3693. for _, it := range stockList {
  3694. total_count += it.StockCount
  3695. }
  3696. //基础库插入数据
  3697. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  3698. }
  3699. if err == nil {
  3700. c.ServeSuccessJSON(map[string]interface{}{
  3701. "msg": "保存成功",
  3702. "message": "2",
  3703. })
  3704. return
  3705. } else {
  3706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3707. return
  3708. }
  3709. }
  3710. if len(beforePrepares) > 0 && active == 2 {
  3711. for _, item := range beforePrepares {
  3712. //1.查看该患者该耗材型号最后一次出库数量
  3713. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  3714. //判断当前出库数量和最后一次出库数量的大小
  3715. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  3716. if item.Count <= goodInfo.Count {
  3717. //出库
  3718. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  3719. //查询今日出库数据
  3720. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  3721. for _, it := range list {
  3722. prepare := models.DialysisBeforePrepare{
  3723. UserOrgId: it.OrgId,
  3724. PatientId: patient_id,
  3725. RecordDate: it.RecordTime,
  3726. GoodId: it.GoodId,
  3727. GoodTypeId: it.GoodTypeId,
  3728. Count: it.Count,
  3729. Ctime: time.Now().Unix(),
  3730. Creater: adminUser.AdminUser.Id,
  3731. Status: 1,
  3732. StorehouseId: houseConfig.StorehouseOutInfo,
  3733. }
  3734. //删除准备表数据
  3735. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  3736. service.CreateDialysisBeforePrepareOne(&prepare)
  3737. }
  3738. }
  3739. var last_total int64
  3740. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  3741. if item.Count >= goodInfo.Count {
  3742. //查询当前批次当前耗材最后一条出库数据
  3743. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  3744. //计算当前出库和最后一次出库数据相差数据
  3745. last_total = item.Count - lastOutInfo.Count
  3746. //查询该批次剩余库存
  3747. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  3748. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  3749. if lastInfo.StockCount >= last_total {
  3750. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  3751. //service.ConsumablesDeliveryTotalEight(adminInfo.Org.Id, patient_id, record_time, beforePrepares,adminInfo.AdminUser.Id,item.Count)
  3752. //查询今日出库数据
  3753. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  3754. for _, it := range list {
  3755. prepare := models.DialysisBeforePrepare{
  3756. UserOrgId: it.OrgId,
  3757. PatientId: patient_id,
  3758. RecordDate: it.RecordTime,
  3759. GoodId: it.GoodId,
  3760. GoodTypeId: it.GoodTypeId,
  3761. Count: it.Count,
  3762. Ctime: time.Now().Unix(),
  3763. Creater: adminUser.AdminUser.Id,
  3764. Status: 1,
  3765. StorehouseId: houseConfig.StorehouseOutInfo,
  3766. }
  3767. //删除准备表数据
  3768. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  3769. service.CreateDialysisBeforePrepareOne(&prepare)
  3770. //查询默认仓库
  3771. //houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  3772. //goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.Org.Id)
  3773. //var sum_count int64
  3774. //var sum_in_count int64
  3775. //for _, it := range goodList {
  3776. // sum_count += it.StockCount
  3777. // sum_in_count += it.WarehousingCount
  3778. //}
  3779. //service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, adminUser.Org.Id)
  3780. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  3781. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  3782. var total_count int64
  3783. for _, it := range stockList {
  3784. total_count += it.StockCount
  3785. }
  3786. //基础库插入数据
  3787. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  3788. }
  3789. }
  3790. //如果库存不够,则出库到下一个批次
  3791. if lastInfo.StockCount < last_total {
  3792. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  3793. //查询今日出库数据
  3794. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  3795. for _, it := range list {
  3796. prepare := models.DialysisBeforePrepare{
  3797. UserOrgId: it.OrgId,
  3798. PatientId: patient_id,
  3799. RecordDate: it.RecordTime,
  3800. GoodId: it.GoodId,
  3801. GoodTypeId: it.GoodTypeId,
  3802. Count: it.Count,
  3803. Ctime: time.Now().Unix(),
  3804. Creater: adminUser.AdminUser.Id,
  3805. Status: 1,
  3806. StorehouseId: houseConfig.StorehouseOutInfo,
  3807. }
  3808. //删除准备表数据
  3809. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  3810. service.CreateDialysisBeforePrepareOne(&prepare)
  3811. //查询默认仓库
  3812. //houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  3813. //goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.Org.Id)
  3814. //var sum_count int64
  3815. //var sum_in_count int64
  3816. //for _, it := range goodList {
  3817. // sum_count += it.StockCount
  3818. // sum_in_count += it.WarehousingCount
  3819. //}
  3820. //service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, adminUser.Org.Id)
  3821. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  3822. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  3823. var total_count int64
  3824. for _, it := range stockList {
  3825. total_count += it.StockCount
  3826. }
  3827. //基础库插入数据
  3828. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  3829. }
  3830. if err != nil {
  3831. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  3832. c.ServeSuccessJSON(map[string]interface{}{
  3833. "message": "1",
  3834. "good_name": goodObj.GoodName,
  3835. "specification_name": goodObj.SpecificationName,
  3836. })
  3837. return
  3838. }
  3839. }
  3840. }
  3841. if err != nil {
  3842. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  3843. c.ServeSuccessJSON(map[string]interface{}{
  3844. "message": "1",
  3845. "good_name": goodObj.GoodName,
  3846. "specification_name": goodObj.SpecificationName,
  3847. })
  3848. return
  3849. }
  3850. }
  3851. }
  3852. }
  3853. var errs error
  3854. if errs == nil {
  3855. c.ServeSuccessJSON(map[string]interface{}{
  3856. "msg": "提交成功",
  3857. "message": "2",
  3858. "good_name": "",
  3859. "specification_name": "",
  3860. })
  3861. return
  3862. } else {
  3863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3864. return
  3865. }
  3866. }
  3867. func (c *DialysisAPIController) CreateStockOutInfo() {
  3868. patient_id, _ := c.GetInt64("patient_id", 0)
  3869. record_date := c.GetString("record_time")
  3870. if patient_id <= 0 {
  3871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3872. return
  3873. }
  3874. adminInfo := c.GetMobileAdminUserInfo()
  3875. timeLayout := "2006-01-02"
  3876. loc, _ := time.LoadLocation("Local")
  3877. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3878. record_time := theRecordTime.Unix()
  3879. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  3880. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  3881. consumables = RemoveRepeatedGood(consumables)
  3882. if record.IsOpen == 1 {
  3883. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  3884. //查询是否有库存
  3885. for _, item := range consumables {
  3886. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  3887. if item.Count > warehouse.Count {
  3888. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  3889. c.ServeSuccessJSON(map[string]interface{}{
  3890. "message": "1",
  3891. "good_name": goodObj.GoodName,
  3892. "specification_name": goodObj.SpecificationName,
  3893. })
  3894. return
  3895. }
  3896. }
  3897. //查询是否有出库单
  3898. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  3899. if err == gorm.ErrRecordNotFound {
  3900. //没有记录,则创建出库单
  3901. timeStr := time.Now().Format("2006-01-02")
  3902. timeArr := strings.Split(timeStr, "-")
  3903. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  3904. total = total + 1
  3905. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3906. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3907. number = number + total
  3908. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3909. creater := adminInfo.AdminUser.Id
  3910. warehouseOut := models.WarehouseOut{
  3911. WarehouseOutOrderNumber: warehousing_out_order,
  3912. OperationTime: time.Now().Unix(),
  3913. OrgId: adminInfo.Org.Id,
  3914. Creater: creater,
  3915. Ctime: time.Now().Unix(),
  3916. Status: 1,
  3917. WarehouseOutTime: record_time,
  3918. Dealer: 0,
  3919. Manufacturer: 0,
  3920. Type: 1,
  3921. IsSys: 1,
  3922. StorehouseId: houseConfig.StorehouseOutInfo,
  3923. IsCheck: 1,
  3924. }
  3925. err := service.AddSigleWarehouseOut(&warehouseOut)
  3926. if err != nil {
  3927. utils.TraceLog("创建出库单失败 err = %v", err)
  3928. } else {
  3929. for _, item := range consumables {
  3930. //出库
  3931. service.ConsumablesDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  3932. }
  3933. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  3934. if len(list) == 0 {
  3935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3936. return
  3937. }
  3938. for _, item := range list {
  3939. prepare := models.DialysisBeforePrepare{
  3940. UserOrgId: adminInfo.Org.Id,
  3941. PatientId: patient_id,
  3942. RecordDate: record_time,
  3943. GoodId: item.GoodId,
  3944. GoodTypeId: item.GoodTypeId,
  3945. Count: item.Count,
  3946. Creater: adminInfo.AdminUser.Id,
  3947. Status: 1,
  3948. Ctime: time.Now().Unix(),
  3949. StorehouseId: houseConfig.StorehouseOutInfo,
  3950. }
  3951. //清空准备表数据
  3952. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  3953. service.CreateDialysisBeforePrepareOne(&prepare)
  3954. //查询默认仓库
  3955. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  3956. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  3957. var total_count int64
  3958. for _, it := range stockList {
  3959. total_count += it.StockCount
  3960. }
  3961. //基础库插入数据
  3962. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  3963. }
  3964. }
  3965. //
  3966. } else if err == nil {
  3967. for _, item := range consumables {
  3968. //出库
  3969. service.ConsumablesDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  3970. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  3971. if len(list) == 0 {
  3972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3973. return
  3974. }
  3975. for _, item := range list {
  3976. prepare := models.DialysisBeforePrepare{
  3977. UserOrgId: adminInfo.Org.Id,
  3978. PatientId: patient_id,
  3979. RecordDate: record_time,
  3980. GoodId: item.GoodId,
  3981. GoodTypeId: item.GoodTypeId,
  3982. Count: item.Count,
  3983. Creater: adminInfo.AdminUser.Id,
  3984. Status: 1,
  3985. Ctime: time.Now().Unix(),
  3986. StorehouseId: houseConfig.StorehouseOutInfo,
  3987. }
  3988. //清空准备表数据
  3989. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  3990. service.CreateDialysisBeforePrepareOne(&prepare)
  3991. //查询默认仓库
  3992. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  3993. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  3994. var total_count int64
  3995. for _, it := range stockList {
  3996. total_count += it.StockCount
  3997. }
  3998. //基础库插入数据
  3999. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  4000. }
  4001. }
  4002. }
  4003. c.ServeSuccessJSON(map[string]interface{}{
  4004. "msg": "提交成功",
  4005. "message": "2",
  4006. "good_name": "",
  4007. "specification_name": "",
  4008. })
  4009. return
  4010. } else {
  4011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  4012. return
  4013. }
  4014. }
  4015. func (c *DialysisAPIController) EditConsumables() {
  4016. patient_id, _ := c.GetInt64("patient_id", 0)
  4017. record_date := c.GetString("record_time")
  4018. if patient_id <= 0 {
  4019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4020. return
  4021. }
  4022. adminInfo := c.GetMobileAdminUserInfo()
  4023. timeLayout := "2006-01-02"
  4024. loc, _ := time.LoadLocation("Local")
  4025. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4026. record_time := theRecordTime.Unix()
  4027. dataBody := make(map[string]interface{}, 0)
  4028. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4029. if err != nil {
  4030. utils.ErrorLog(err.Error())
  4031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4032. return
  4033. }
  4034. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4035. var beforePrepares []*models.DialysisBeforePrepareGoods
  4036. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  4037. //判断是否开启自动出库
  4038. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  4039. if record.IsOpen == 1 {
  4040. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  4041. goods, _ := dataBody["goods"].([]interface{})
  4042. if len(goods) > 0 {
  4043. for _, item := range goods {
  4044. items := item.(map[string]interface{})
  4045. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4046. utils.ErrorLog("good_id")
  4047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4048. return
  4049. }
  4050. good_id := int64(items["good_id"].(float64))
  4051. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  4052. utils.ErrorLog("good_type_id")
  4053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4054. return
  4055. }
  4056. good_type_id := int64(items["good_type_id"].(float64))
  4057. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  4058. utils.ErrorLog("count")
  4059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4060. return
  4061. }
  4062. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  4063. commdity_code := items["commdity_code"].(string)
  4064. fmt.Println(commdity_code)
  4065. prepareGoods := &models.DialysisBeforePrepareGoods{
  4066. GoodTypeId: good_type_id,
  4067. GoodId: good_id,
  4068. Count: count,
  4069. StorehouseId: houseConfig.StorehouseOutInfo,
  4070. }
  4071. beforePrepares = append(beforePrepares, prepareGoods)
  4072. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  4073. GoodTypeId: good_type_id,
  4074. GoodId: good_id,
  4075. Count: count,
  4076. StorehouseId: houseConfig.StorehouseOutInfo,
  4077. }
  4078. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  4079. }
  4080. for _, item := range beforePrepares {
  4081. //1.查看该患者该耗材型号最后一次出库数量
  4082. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  4083. //判断当前出库数量和最后一次出库数量的大小
  4084. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  4085. if item.Count < goodInfo.Count {
  4086. //出库
  4087. err = ConsumablesDeliveryTotalSeven(adminInfo.Org.Id, patient_id, record_time, beforePrepares, adminInfo.AdminUser.Id, item.Count)
  4088. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4089. //goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.GoodId, adminInfo.Org.Id)
  4090. //var sum_count int64
  4091. //var sum_in_count int64
  4092. //for _, it := range goodList {
  4093. // sum_count += it.StockCount
  4094. // sum_in_count += it.WarehousingCount
  4095. //}
  4096. //service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, adminInfo.Org.Id)
  4097. //查询默认仓库
  4098. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4099. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4100. var total_count int64
  4101. for _, it := range stockList {
  4102. total_count += it.StockCount
  4103. }
  4104. //基础库插入数据
  4105. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  4106. break
  4107. }
  4108. var last_total int64
  4109. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  4110. if item.Count > goodInfo.Count {
  4111. //计算当前出库和最后一次出库数据相差数据
  4112. last_total = item.Count - goodInfo.Count
  4113. //查询该批次剩余库存
  4114. lastInfo, _ := service.GetLastStockOut(goodInfo.WarehouseInfotId)
  4115. if lastInfo.StockCount == 0 {
  4116. //查询该耗材的总库存
  4117. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  4118. if wareinfo.StockCount == 0 {
  4119. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4120. c.ServeSuccessJSON(map[string]interface{}{
  4121. "message": "1",
  4122. "good_name": goodObj.GoodName,
  4123. "specification_name": goodObj.SpecificationName,
  4124. })
  4125. return
  4126. }
  4127. }
  4128. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  4129. //查询该耗材的总库存
  4130. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  4131. // 如果库存差大于剩余库存则提示库存不足
  4132. if last_total > wareinfo.StockCount {
  4133. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4134. c.ServeSuccessJSON(map[string]interface{}{
  4135. "message": "1",
  4136. "good_name": goodObj.GoodName,
  4137. "specification_name": goodObj.SpecificationName,
  4138. })
  4139. return
  4140. } else {
  4141. err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  4142. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4143. //goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.GoodId, adminInfo.Org.Id)
  4144. //var sum_count int64
  4145. //var sum_in_count int64
  4146. //for _, it := range goodList {
  4147. // sum_count += it.StockCount
  4148. // sum_in_count += it.WarehousingCount
  4149. //}
  4150. //service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, adminInfo.Org.Id)
  4151. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4152. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4153. var total_count int64
  4154. for _, it := range stockList {
  4155. total_count += it.StockCount
  4156. }
  4157. //基础库插入数据
  4158. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  4159. break
  4160. }
  4161. }
  4162. }
  4163. //查询今日出库数据
  4164. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  4165. for _, it := range list {
  4166. prepare := models.DialysisBeforePrepare{
  4167. UserOrgId: it.OrgId,
  4168. PatientId: patient_id,
  4169. RecordDate: it.RecordTime,
  4170. GoodId: it.GoodId,
  4171. GoodTypeId: it.GoodTypeId,
  4172. Count: it.Count,
  4173. Ctime: time.Now().Unix(),
  4174. Creater: adminInfo.AdminUser.Id,
  4175. Status: 1,
  4176. StorehouseId: houseConfig.StorehouseOutInfo,
  4177. }
  4178. //删除准备表数据
  4179. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  4180. service.CreateDialysisBeforePrepareOne(&prepare)
  4181. //查询默认仓库
  4182. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4183. //goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, it.GoodId, adminInfo.Org.Id)
  4184. //var sum_count int64
  4185. //var sum_in_count int64
  4186. //for _, it := range goodList {
  4187. // sum_count += it.StockCount
  4188. // sum_in_count += it.WarehousingCount
  4189. //}
  4190. //service.UpdateGoodByGoodId(it.GoodId, sum_count, sum_in_count, adminInfo.Org.Id)
  4191. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4192. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4193. var total_count int64
  4194. for _, it := range stockList {
  4195. total_count += it.StockCount
  4196. }
  4197. //基础库插入数据
  4198. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  4199. if err != nil {
  4200. goodObj, _ := service.GetGoodInformationByGoodId(it.GoodId)
  4201. c.ServeSuccessJSON(map[string]interface{}{
  4202. "message": "2",
  4203. "good_name": goodObj.GoodName,
  4204. "specification_name": goodObj.SpecificationName,
  4205. })
  4206. return
  4207. }
  4208. }
  4209. }
  4210. }
  4211. //更新自动出库的地方
  4212. var errs error
  4213. if errs == nil {
  4214. c.ServeSuccessJSON(map[string]interface{}{
  4215. "msg": "修改成功",
  4216. "message": "2",
  4217. "good_name": "",
  4218. "specification_name": "",
  4219. })
  4220. return
  4221. } else {
  4222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4223. return
  4224. }
  4225. }
  4226. }
  4227. func (c *DialysisAPIController) GetDialysisGoods() {
  4228. schedualDate := c.GetString("schedule_date")
  4229. schedule_type, _ := c.GetInt64("schedule_type")
  4230. partition_id, _ := c.GetInt64("partition_id")
  4231. page, _ := c.GetInt("page")
  4232. patient_id, _ := c.GetInt64("patient_id")
  4233. schedualEndDate := int64(0)
  4234. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  4235. if parseDateErr != nil && len(schedualDate) != 0 {
  4236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4237. return
  4238. }
  4239. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  4240. if parseDateErr != nil && len(schedualDate) != 0 {
  4241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4242. return
  4243. }
  4244. schedualEndDate = endDate.Unix()
  4245. adminUser := c.GetMobileAdminUserInfo()
  4246. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  4247. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  4248. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  4249. //获取当天该病人的透析处方
  4250. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  4251. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  4252. if err == gorm.ErrRecordNotFound {
  4253. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  4254. if patient_id != 0 {
  4255. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4256. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  4257. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  4258. item.LastAutomaticReduceDetail = goodUser
  4259. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4260. item.Project = project
  4261. }
  4262. }
  4263. c.ServeSuccessJSON(map[string]interface{}{
  4264. "dialysis_goods": dialysisGoods,
  4265. "good_type": goodTypes,
  4266. "total": total,
  4267. "prescribe": prescribe,
  4268. "good_info": good_info,
  4269. })
  4270. return
  4271. } else if err == nil {
  4272. //获取当天排班的每个患者的库存使用情况
  4273. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  4274. if patient_id != 0 {
  4275. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4276. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  4277. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  4278. item.Project = project
  4279. item.LastAutomaticReduceDetail = goodUser
  4280. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4281. }
  4282. }
  4283. if err == nil {
  4284. c.ServeSuccessJSON(map[string]interface{}{
  4285. "dialysis_goods": dialysisGoods,
  4286. "good_type": goodTypes,
  4287. "total": total,
  4288. "prescribe": prescribe,
  4289. "good_info": good_info,
  4290. "project": project,
  4291. })
  4292. return
  4293. } else {
  4294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4295. return
  4296. }
  4297. } else if err != nil {
  4298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4299. return
  4300. }
  4301. }
  4302. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  4303. start_time := c.GetString("start_time")
  4304. end_time := c.GetString("end_time")
  4305. timeLayout := "2006-01-02"
  4306. loc, _ := time.LoadLocation("Local")
  4307. var theStartTime int64
  4308. if len(start_time) > 0 {
  4309. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4310. if err != nil {
  4311. utils.ErrorLog(err.Error())
  4312. }
  4313. theStartTime = theTime.Unix()
  4314. }
  4315. var theEndtTime int64
  4316. if len(end_time) > 0 {
  4317. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4318. if err != nil {
  4319. utils.ErrorLog(err.Error())
  4320. }
  4321. theEndtTime = theTime.Unix()
  4322. }
  4323. adminUser := c.GetMobileAdminUserInfo()
  4324. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  4325. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  4326. if err == nil {
  4327. c.ServeSuccessJSON(map[string]interface{}{
  4328. "stock_out": outInfo,
  4329. "stockCount": stockCount,
  4330. })
  4331. return
  4332. } else {
  4333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4334. return
  4335. }
  4336. }
  4337. func (c *DialysisAPIController) GetStockInGoodInfo() {
  4338. patient_id, _ := c.GetInt64("patient_id", 0)
  4339. record_time := c.GetString("record_time")
  4340. adminUser := c.GetMobileAdminUserInfo()
  4341. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  4342. if parseDateErr != nil && len(record_time) != 0 {
  4343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4344. return
  4345. }
  4346. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  4347. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  4348. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  4349. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  4350. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  4351. //获取今日患者的透析处方参数
  4352. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  4353. c.ServeSuccessJSON(map[string]interface{}{
  4354. "good_type": goodTypes,
  4355. "good_user": goodUser,
  4356. "good_info": good_info,
  4357. "last_good_user": lastGoodUserDetial,
  4358. "project": project,
  4359. "prescription": prescribe,
  4360. })
  4361. return
  4362. }
  4363. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  4364. patient_id, _ := c.GetInt64("patient_id", 0)
  4365. record_date := c.GetString("record_time")
  4366. timeLayout := "2006-01-02"
  4367. loc, _ := time.LoadLocation("Local")
  4368. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4369. record_time := theRecordTime.Unix()
  4370. adminInfo := c.GetMobileAdminUserInfo()
  4371. dataBody := make(map[string]interface{}, 0)
  4372. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4373. if err != nil {
  4374. utils.ErrorLog(err.Error())
  4375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4376. return
  4377. }
  4378. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4379. var beforePrepares []*models.DialysisBeforePrepareGoods
  4380. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  4381. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  4382. goods, _ := dataBody["goods"].([]interface{})
  4383. if len(goods) > 0 {
  4384. for _, item := range goods {
  4385. items := item.(map[string]interface{})
  4386. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4387. utils.ErrorLog("good_id")
  4388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4389. return
  4390. }
  4391. good_id := int64(items["good_id"].(float64))
  4392. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  4393. utils.ErrorLog("good_type_id")
  4394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4395. return
  4396. }
  4397. good_type_id := int64(items["good_type_id"].(float64))
  4398. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  4399. utils.ErrorLog("count")
  4400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4401. return
  4402. }
  4403. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  4404. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  4405. utils.ErrorLog("project_id")
  4406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4407. return
  4408. }
  4409. project_id := int64(items["project_id"].(float64))
  4410. prepare := &models.DialysisBeforePrepareGoods{
  4411. GoodId: good_id,
  4412. GoodTypeId: good_type_id,
  4413. Count: count,
  4414. ProjectId: project_id,
  4415. StorehouseId: houseConfig.StorehouseOutInfo,
  4416. }
  4417. beforePrepares = append(beforePrepares, prepare)
  4418. newPrepare := &models.NewDialysisBeforePrepareGoods{
  4419. GoodId: good_id,
  4420. GoodTypeId: good_type_id,
  4421. Count: count,
  4422. ProjectId: project_id,
  4423. StorehouseId: houseConfig.StorehouseOutInfo,
  4424. }
  4425. newBeforePrepares = append(newBeforePrepares, newPrepare)
  4426. }
  4427. }
  4428. }
  4429. //查询是否有库存
  4430. for _, item := range beforePrepares {
  4431. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4432. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  4433. if item.Count > warehouse.Count {
  4434. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4435. c.ServeSuccessJSON(map[string]interface{}{
  4436. "message": "1",
  4437. "good_name": goodObj.GoodName,
  4438. "specification_name": goodObj.SpecificationName,
  4439. })
  4440. return
  4441. }
  4442. }
  4443. //出库逻辑
  4444. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  4445. if err != nil {
  4446. utils.ErrorLog(err.Error())
  4447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4448. return
  4449. }
  4450. //查询当天出库的数据
  4451. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  4452. for _, item := range list {
  4453. prepare := models.DialysisBeforePrepare{
  4454. UserOrgId: item.OrgId,
  4455. PatientId: item.PatientId,
  4456. RecordDate: item.RecordTime,
  4457. GoodId: item.GoodId,
  4458. GoodTypeId: item.GoodTypeId,
  4459. Count: item.Count,
  4460. Creater: adminInfo.AdminUser.Id,
  4461. Status: 1,
  4462. Ctime: time.Now().Unix(),
  4463. ProjectId: item.ProjectId,
  4464. StorehouseId: houseConfig.StorehouseOutInfo,
  4465. }
  4466. //清空准备表的数据
  4467. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4468. //插入准备表数据
  4469. service.CreateDialysisBeforePrepareOne(&prepare)
  4470. //查询默认仓库
  4471. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4472. //goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.GoodId, adminInfo.Org.Id)
  4473. //var sum_count int64
  4474. //var sum_in_count int64
  4475. //for _, it := range goodList {
  4476. // sum_count += it.StockCount
  4477. // sum_in_count += it.WarehousingCount
  4478. //}
  4479. //service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, adminInfo.Org.Id)
  4480. //查询默认仓库
  4481. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4482. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4483. var total_count int64
  4484. for _, it := range stockList {
  4485. total_count += it.StockCount
  4486. }
  4487. //基础库插入数据
  4488. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  4489. }
  4490. //更新自动出库的地方
  4491. var errs error
  4492. if errs == nil {
  4493. c.ServeSuccessJSON(map[string]interface{}{
  4494. "msg": "修改成功",
  4495. "message": "2",
  4496. "good_name": "",
  4497. "specification_name": "",
  4498. })
  4499. return
  4500. } else {
  4501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4502. return
  4503. }
  4504. }
  4505. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  4506. newArr = make([]*models.DialysisBeforePrepare, 0)
  4507. for i := 0; i < len(arr); i++ {
  4508. repeat := false
  4509. for j := i + 1; j < len(arr); j++ {
  4510. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  4511. repeat = true
  4512. break
  4513. }
  4514. }
  4515. if !repeat {
  4516. newArr = append(newArr, arr[i])
  4517. }
  4518. }
  4519. return
  4520. }
  4521. func (c *DialysisAPIController) GetAllDrug() {
  4522. patient_id, _ := c.GetInt64("patient_id", 0)
  4523. adminInfo := c.GetMobileAdminUserInfo()
  4524. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  4525. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  4526. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  4527. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  4528. c.ServeSuccessJSON(map[string]interface{}{
  4529. "base_drug_config": drugStockConfig,
  4530. "private_drug_config": privateDrugConfig,
  4531. "base_drug_list": drugList,
  4532. "private_drug_list": privateDrugList,
  4533. })
  4534. }
  4535. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  4536. newArr = make([]*models.DialysisBeforePrepare, 0)
  4537. for i := 0; i < len(arr); i++ {
  4538. repeat := false
  4539. for j := i + 1; j < len(arr); j++ {
  4540. if arr[i].GoodId == arr[j].GoodId {
  4541. repeat = true
  4542. break
  4543. }
  4544. }
  4545. if !repeat {
  4546. newArr = append(newArr, arr[i])
  4547. }
  4548. }
  4549. return
  4550. }
  4551. func (c *DialysisAPIController) GetDepartment() {
  4552. adminInfo := c.GetMobileAdminUserInfo()
  4553. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  4554. if err == nil {
  4555. c.ServeSuccessJSON(map[string]interface{}{
  4556. "departments": departments,
  4557. })
  4558. } else {
  4559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4560. return
  4561. }
  4562. }
  4563. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  4564. types, _ := c.GetInt("type", 0)
  4565. start_time := c.GetString("start_time")
  4566. end_time := c.GetString("end_time")
  4567. orgId := c.GetMobileAdminUserInfo().Org.Id
  4568. timeLayout := "2006-01-02"
  4569. loc, _ := time.LoadLocation("Local")
  4570. var startTime int64
  4571. if len(start_time) > 0 {
  4572. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4573. if err != nil {
  4574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4575. return
  4576. }
  4577. startTime = theTime.Unix()
  4578. }
  4579. var endTime int64
  4580. if len(end_time) > 0 {
  4581. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4582. if err != nil {
  4583. utils.ErrorLog(err.Error())
  4584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4585. return
  4586. }
  4587. endTime = theTime.Unix()
  4588. }
  4589. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  4590. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  4591. if err != nil {
  4592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4593. } else {
  4594. c.ServeSuccessJSON(map[string]interface{}{
  4595. "list": list,
  4596. "type": types,
  4597. "stockTotal": stockTotal,
  4598. })
  4599. }
  4600. }
  4601. func (c *DialysisAPIController) BatchDeleteMonitor() {
  4602. ids := c.GetString("ids")
  4603. //patient_id, _ := c.GetInt64("patient_id")
  4604. //monitoring_date, _ := c.GetInt64("monitoring_date")
  4605. idArray := strings.Split(ids, ",")
  4606. err := service.BatchDeleteMonitor(idArray)
  4607. fmt.Print("err", err)
  4608. //orgid := c.GetMobileAdminUserInfo().Org.Id
  4609. //redis := service.RedisClient()
  4610. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  4611. //redis.Set(key, "", time.Second)
  4612. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  4613. //redis.Set(keyOne, "", time.Second)
  4614. //fmt.Println("keyo呢32332322332332232332",keyOne)
  4615. //redis.Close()
  4616. c.ServeSuccessJSON(map[string]interface{}{
  4617. "msg": "批量删除成功",
  4618. })
  4619. return
  4620. }
  4621. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  4622. id, _ := c.GetInt64("id")
  4623. timeLayout := "2006-01-02"
  4624. loc, _ := time.LoadLocation("Local")
  4625. start_time := time.Now().Format("2006-01-02")
  4626. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4627. nowTime := time.Now()
  4628. endTime := nowTime.AddDate(-1, 0, 0)
  4629. endTimes := endTime.Format("2006-01-02")
  4630. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", endTimes+" 00:00:00", loc)
  4631. list, _ := service.GetPatientDialysisRecordList(id, endtime.Unix(), startime.Unix())
  4632. c.ServeSuccessJSON(map[string]interface{}{
  4633. "list": list,
  4634. })
  4635. return
  4636. }
  4637. func (c *DialysisAPIController) BathDeleteAdviceList() {
  4638. dataBody := make(map[string]interface{}, 0)
  4639. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4640. ids := c.GetString("ids")
  4641. idArray := strings.Split(ids, ",")
  4642. origin, _ := c.GetInt64("origin")
  4643. if origin == 1 {
  4644. err = service.BatchDeleteAdvice(idArray)
  4645. fmt.Print("err", err)
  4646. c.ServeSuccessJSON(map[string]interface{}{
  4647. "msg": "批量删除成功",
  4648. })
  4649. return
  4650. }
  4651. if origin == 2 {
  4652. service.BatchDeleteHisAdvice(idArray)
  4653. }
  4654. }
  4655. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  4656. good_id, _ := c.GetInt64("good_id")
  4657. count, _ := c.GetInt64("count")
  4658. record_time, _ := c.GetInt64("record_time")
  4659. patient_id, _ := c.GetInt64("patient_id")
  4660. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  4661. c.ServeSuccessJSON(map[string]interface{}{
  4662. "detail": detail,
  4663. })
  4664. return
  4665. }
  4666. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  4667. good_id, _ := c.GetInt64("good_id")
  4668. record_time, _ := c.GetInt64("record_time")
  4669. patient_id, _ := c.GetInt64("patient_id")
  4670. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  4671. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  4672. fmt.Print("err", err)
  4673. c.ServeSuccessJSON(map[string]interface{}{
  4674. "msg": "批量删除成功",
  4675. })
  4676. return
  4677. }
  4678. func (c *DialysisAPIController) BatchAdviceCheck() {
  4679. ids := c.GetString("ids")
  4680. idArray := strings.Split(ids, ",")
  4681. creator, _ := c.GetInt64("creator")
  4682. origin, _ := c.GetInt64("origin")
  4683. if origin == 1 {
  4684. err := service.BatchAdviceCheck(idArray, creator)
  4685. fmt.Println(err)
  4686. list, _ := service.GetAdviceExecutionById(idArray)
  4687. c.ServeSuccessJSON(map[string]interface{}{
  4688. "list": list,
  4689. })
  4690. return
  4691. }
  4692. if origin == 2 {
  4693. service.BatchHisAdviceCheck(idArray, creator)
  4694. list, _ := service.GetHisAdviceExecutionById(idArray)
  4695. c.ServeSuccessJSON(map[string]interface{}{
  4696. "list": list,
  4697. })
  4698. return
  4699. }
  4700. }
  4701. func (c *DialysisAPIController) BatchAdviceExecution() {
  4702. ids := c.GetString("ids")
  4703. idArray := strings.Split(ids, ",")
  4704. executionTime := c.GetString("execution_time")
  4705. creator, _ := c.GetInt64("creator")
  4706. timeLayout := "2006-01-02 15:04:05"
  4707. loc, _ := time.LoadLocation("Local")
  4708. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  4709. orgin, _ := c.GetInt64("origin")
  4710. if orgin == 1 {
  4711. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  4712. list, _ := service.GetAdviceExecutionById(idArray)
  4713. fmt.Println(err)
  4714. c.ServeSuccessJSON(map[string]interface{}{
  4715. "list": list,
  4716. })
  4717. return
  4718. }
  4719. if orgin == 2 {
  4720. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  4721. list, _ := service.GetHisAdviceExecutionById(idArray)
  4722. fmt.Println(err)
  4723. c.ServeSuccessJSON(map[string]interface{}{
  4724. "list": list,
  4725. })
  4726. return
  4727. }
  4728. }
  4729. func (c *DialysisAPIController) UpdateStockGoods() {
  4730. good_id, _ := c.GetInt64("good_id")
  4731. record_time, _ := c.GetInt64("record_time")
  4732. patient_id, _ := c.GetInt64("patient_id")
  4733. count, _ := c.GetInt64("count")
  4734. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  4735. fmt.Print("err", err)
  4736. c.ServeSuccessJSON(map[string]interface{}{
  4737. "msg": "更新成功",
  4738. })
  4739. return
  4740. }
  4741. //当前数据比上一次出库数据少
  4742. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  4743. //查询该患者当天已经出库的耗材信息
  4744. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  4745. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  4746. for i := len(goods_yc) - 1; i >= 0; i-- {
  4747. goods_yc_temp := goods_yc[i]
  4748. for j := len(goods) - 1; j >= 0; j-- {
  4749. goods_temp := goods[j]
  4750. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  4751. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  4752. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  4753. if goods_yc_temp.Count == goods_temp.Count {
  4754. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  4755. goods = append(goods[:j], goods[j+1:]...)
  4756. break
  4757. }
  4758. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  4759. if goods_yc_temp.Count > goods_temp.Count {
  4760. temp_count := goods_yc_temp.Count - goods_temp.Count
  4761. goods_yc[i].Count = temp_count
  4762. goods = append(goods[:j], goods[j+1:]...)
  4763. break
  4764. }
  4765. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  4766. if goods_yc_temp.Count < goods_temp.Count {
  4767. temp_count := goods_temp.Count - goods_yc_temp.Count
  4768. goods[j].Count = temp_count
  4769. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  4770. break
  4771. }
  4772. }
  4773. }
  4774. }
  4775. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  4776. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  4777. //退库
  4778. if len(goods_yc) > 0 {
  4779. for _, good_yc := range goods_yc {
  4780. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  4781. ConsumablesDeliveryDeleteFour(orgID, record_time, good_yc, &out, patient_id, creater, count)
  4782. }
  4783. }
  4784. return nil
  4785. }
  4786. //耗材出库删除
  4787. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  4788. // 先根据相关信息查询当天该耗材的出库信息
  4789. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  4790. if err != nil {
  4791. return err
  4792. }
  4793. var delete_count int64 = 0
  4794. delete_count = warehouseOutInfos.Count - count
  4795. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  4796. // 在出库记录表里记录退库详情
  4797. warehouseOutInfo := &models.WarehouseOutInfo{
  4798. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4799. WarehouseOutId: warehouseOut.ID,
  4800. Status: 1,
  4801. Ctime: time.Now().Unix(),
  4802. OrgId: orgID,
  4803. Type: 1,
  4804. IsSys: 1,
  4805. SysRecordTime: record_time,
  4806. GoodTypeId: good_yc.GoodTypeId,
  4807. GoodId: good_yc.GoodId,
  4808. PatientId: good_yc.PatientId,
  4809. ConsumableType: 2,
  4810. StorehouseId: houseConfig.StorehouseOutInfo,
  4811. IsCheck: 1,
  4812. }
  4813. warehouseOutInfo.Count = count
  4814. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  4815. warehouseOutInfo.Price = stockInInfo.Price
  4816. warehouseOutInfo.Dealer = stockInInfo.Dealer
  4817. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  4818. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  4819. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  4820. warehouseOutInfo.Number = warehouseOutInfos.Number
  4821. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  4822. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  4823. //查找当天是否存在出库记录
  4824. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time)
  4825. if errcod == gorm.ErrRecordNotFound {
  4826. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4827. //插入详情明细表
  4828. stockFlow := models.VmStockFlow{
  4829. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4830. WarehouseOutId: warehouseOut.ID,
  4831. GoodId: good_yc.GoodId,
  4832. Number: warehouseOutInfos.Number,
  4833. ProductDate: stockInInfo.ProductDate,
  4834. ExpireDate: stockInInfo.ExpiryDate,
  4835. Count: count,
  4836. Price: stockInInfo.Price,
  4837. Status: 1,
  4838. Ctime: time.Now().Unix(),
  4839. UserOrgId: good_yc.OrgId,
  4840. Manufacturer: stockInInfo.Manufacturer,
  4841. Dealer: stockInInfo.Dealer,
  4842. LicenseNumber: stockInInfo.LicenseNumber,
  4843. IsEdit: 2,
  4844. Creator: creater,
  4845. SystemTime: record_time,
  4846. ConsumableType: 3,
  4847. WarehousingDetailId: 0,
  4848. IsSys: 1,
  4849. UpdateCreator: creater,
  4850. PatientId: patient_id,
  4851. StorehouseId: houseConfig.StorehouseOutInfo,
  4852. }
  4853. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  4854. if errflow == gorm.ErrRecordNotFound {
  4855. //创建流水表
  4856. err := service.CreateStockFlowOne(stockFlow)
  4857. fmt.Println("err", err)
  4858. } else if errflow == nil {
  4859. //插入详情明细表
  4860. stockFlow := models.VmStockFlow{
  4861. ID: exsit.ID,
  4862. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  4863. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4864. WarehouseOutId: warehouseOut.ID,
  4865. GoodId: good_yc.GoodId,
  4866. Number: warehouseOutInfos.Number,
  4867. ProductDate: stockInInfo.ProductDate,
  4868. ExpireDate: stockInInfo.ExpiryDate,
  4869. Count: exsit.Count - delete_count,
  4870. Price: stockInInfo.Price,
  4871. Status: 1,
  4872. Ctime: time.Now().Unix(),
  4873. UserOrgId: good_yc.OrgId,
  4874. Manufacturer: stockInInfo.Manufacturer,
  4875. Dealer: stockInInfo.Dealer,
  4876. LicenseNumber: stockInInfo.LicenseNumber,
  4877. IsEdit: 2,
  4878. Creator: creater,
  4879. SystemTime: record_time,
  4880. ConsumableType: 3,
  4881. WarehousingDetailId: 0,
  4882. IsSys: 1,
  4883. UpdateCreator: creater,
  4884. PatientId: patient_id,
  4885. StorehouseId: houseConfig.StorehouseOutInfo,
  4886. }
  4887. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  4888. }
  4889. if errOne != nil {
  4890. return errOne
  4891. }
  4892. } else if errcod == nil {
  4893. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time)
  4894. //插入详情明细表
  4895. stockFlow := models.VmStockFlow{
  4896. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  4897. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4898. WarehouseOutId: warehouseOut.ID,
  4899. GoodId: good_yc.GoodId,
  4900. Number: warehouseOutInfos.Number,
  4901. ProductDate: stockInInfo.ProductDate,
  4902. ExpireDate: stockInInfo.ExpiryDate,
  4903. Count: count,
  4904. Price: stockInInfo.Price,
  4905. Status: 1,
  4906. Ctime: time.Now().Unix(),
  4907. UserOrgId: good_yc.OrgId,
  4908. Manufacturer: stockInInfo.Manufacturer,
  4909. Dealer: stockInInfo.Dealer,
  4910. LicenseNumber: stockInInfo.LicenseNumber,
  4911. IsEdit: 2,
  4912. Creator: creater,
  4913. SystemTime: record_time,
  4914. ConsumableType: 3,
  4915. WarehousingDetailId: 0,
  4916. IsSys: 1,
  4917. UpdateCreator: creater,
  4918. PatientId: patient_id,
  4919. ReturnCount: delete_count,
  4920. StorehouseId: houseConfig.StorehouseOutInfo,
  4921. }
  4922. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  4923. if errflows == gorm.ErrRecordNotFound {
  4924. //创建流水表
  4925. service.CreateStockFlowOne(stockFlow)
  4926. } else if errflows == nil {
  4927. stockFlow := models.VmStockFlow{
  4928. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  4929. ID: exsit.ID,
  4930. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4931. WarehouseOutId: warehouseOut.ID,
  4932. GoodId: good_yc.GoodId,
  4933. Number: warehouseOutInfos.Number,
  4934. ProductDate: stockInInfo.ProductDate,
  4935. ExpireDate: stockInInfo.ExpiryDate,
  4936. Count: exsit.Count - delete_count,
  4937. Price: stockInInfo.Price,
  4938. Status: 1,
  4939. Ctime: time.Now().Unix(),
  4940. UserOrgId: good_yc.OrgId,
  4941. Manufacturer: stockInInfo.Manufacturer,
  4942. Dealer: stockInInfo.Dealer,
  4943. LicenseNumber: stockInInfo.LicenseNumber,
  4944. IsEdit: 2,
  4945. Creator: creater,
  4946. SystemTime: record_time,
  4947. ConsumableType: 3,
  4948. WarehousingDetailId: 0,
  4949. IsSys: 1,
  4950. UpdateCreator: creater,
  4951. PatientId: patient_id,
  4952. ReturnCount: delete_count,
  4953. StorehouseId: houseConfig.StorehouseOutInfo,
  4954. }
  4955. //service.UpdatedStockFlow(stockFlow)
  4956. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  4957. }
  4958. }
  4959. //更改自动出库的表格
  4960. details := models.BloodAutomaticReduceDetail{
  4961. WarehouseOutId: warehouseOutInfo.ID,
  4962. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4963. PatientId: patient_id,
  4964. Ctime: time.Now().Unix(),
  4965. Mtime: time.Now().Unix(),
  4966. Status: 1,
  4967. RecordTime: record_time,
  4968. OrgId: orgID,
  4969. GoodId: good_yc.GoodId,
  4970. GoodTypeId: good_yc.GoodTypeId,
  4971. Count: count,
  4972. StorehouseId: houseConfig.StorehouseOutInfo,
  4973. }
  4974. //查询当天耗材是否已经存在数据
  4975. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  4976. if errcode == gorm.ErrRecordNotFound {
  4977. errTwo := service.CreateAutoReduceRecord(&details)
  4978. if errTwo != nil {
  4979. return errTwo
  4980. }
  4981. } else if errcode == nil {
  4982. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  4983. service.CreateAutoReduceRecord(&details)
  4984. }
  4985. // 删除出库完成后,要增加对应批次的库存数量
  4986. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count)
  4987. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  4988. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  4989. fmt.Println("errOne", errOne)
  4990. if errThree != nil {
  4991. return errThree
  4992. }
  4993. if good_yc.Count == 0 {
  4994. return nil
  4995. } else {
  4996. return errors.New("退库和出库数据不匹配")
  4997. }
  4998. }
  4999. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  5000. //查询该患者当天已经出库的耗材信息
  5001. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  5002. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  5003. for i := len(goods_yc) - 1; i >= 0; i-- {
  5004. goods_yc_temp := goods_yc[i]
  5005. for j := len(goods) - 1; j >= 0; j-- {
  5006. goods_temp := goods[j]
  5007. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  5008. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  5009. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  5010. if goods_yc_temp.Count == goods_temp.Count {
  5011. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  5012. goods = append(goods[:j], goods[j+1:]...)
  5013. break
  5014. }
  5015. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  5016. if goods_yc_temp.Count > goods_temp.Count {
  5017. temp_count := goods_yc_temp.Count - goods_temp.Count
  5018. goods_yc[i].Count = temp_count
  5019. goods = append(goods[:j], goods[j+1:]...)
  5020. break
  5021. }
  5022. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  5023. if goods_yc_temp.Count < goods_temp.Count {
  5024. temp_count := goods_temp.Count - goods_yc_temp.Count
  5025. goods[j].Count = temp_count
  5026. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  5027. break
  5028. }
  5029. }
  5030. }
  5031. }
  5032. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  5033. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  5034. if len(goods) > 0 {
  5035. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  5036. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  5037. if err == gorm.ErrRecordNotFound {
  5038. //没有记录,则创建出库单
  5039. timeStr := time.Now().Format("2006-01-02")
  5040. timeArr := strings.Split(timeStr, "-")
  5041. total, _ := service.FindAllWarehouseOut(orgID)
  5042. total = total + 1
  5043. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5044. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5045. number = number + total
  5046. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5047. warehouseOut := models.WarehouseOut{
  5048. WarehouseOutOrderNumber: warehousing_out_order,
  5049. OperationTime: time.Now().Unix(),
  5050. OrgId: orgID,
  5051. Creater: creater,
  5052. Ctime: time.Now().Unix(),
  5053. Status: 1,
  5054. WarehouseOutTime: record_time,
  5055. Dealer: 0,
  5056. Manufacturer: 0,
  5057. Type: 1,
  5058. IsSys: 1,
  5059. StorehouseId: houseConfig.StorehouseOutInfo,
  5060. IsCheck: 1,
  5061. }
  5062. err := service.AddSigleWarehouseOut(&warehouseOut)
  5063. if err != nil {
  5064. utils.TraceLog("创建出库单失败 err = %v", err)
  5065. return err
  5066. } else {
  5067. out = warehouseOut
  5068. }
  5069. }
  5070. for _, item := range goods {
  5071. var newCount int64 = 0
  5072. for _, it := range goodOne {
  5073. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  5074. newCount = it.Count
  5075. }
  5076. }
  5077. prepare := models.DialysisBeforePrepare{
  5078. GoodTypeId: item.GoodTypeId,
  5079. GoodId: item.GoodId,
  5080. Count: item.Count,
  5081. StorehouseId: houseConfig.StorehouseOutInfo,
  5082. }
  5083. service.ConsumablesDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  5084. }
  5085. }
  5086. if len(goods_yc) > 0 {
  5087. for _, good_yc := range goods_yc {
  5088. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  5089. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  5090. }
  5091. }
  5092. return nil
  5093. }
  5094. //耗材出库删除
  5095. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  5096. // 先根据相关信息查询当天该耗材的出库信息
  5097. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  5098. if err != nil {
  5099. return err
  5100. }
  5101. var delete_count int64 = 0
  5102. for _, ware := range warehouseOutInfos {
  5103. // 判断当前出库的数据和删除出库数量
  5104. if good_yc.Count <= ware.Count {
  5105. delete_count = good_yc.Count
  5106. } else {
  5107. delete_count = ware.Count
  5108. }
  5109. // 在出库记录表里记录退库详情
  5110. warehouseOutInfo := &models.WarehouseOutInfo{
  5111. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5112. WarehouseOutId: warehouseOut.ID,
  5113. Status: 1,
  5114. Ctime: time.Now().Unix(),
  5115. Remark: "",
  5116. OrgId: orgID,
  5117. Type: 1,
  5118. Manufacturer: 0,
  5119. Dealer: 0,
  5120. IsSys: 0,
  5121. SysRecordTime: record_time,
  5122. GoodTypeId: good_yc.GoodTypeId,
  5123. GoodId: good_yc.GoodId,
  5124. StorehouseId: warehouseOut.StorehouseId,
  5125. IsCheck: 1,
  5126. }
  5127. warehouseOutInfo.Count = delete_count
  5128. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  5129. warehouseOutInfo.Price = stockInInfo.Price
  5130. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5131. if errOne != nil {
  5132. return errOne
  5133. }
  5134. // 删除出库完成后,要增加对应批次的库存数量
  5135. // 删除出库完成后,要改变流水库存
  5136. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  5137. fmt.Println("errOne", errOne)
  5138. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count)
  5139. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  5140. if errThree != nil {
  5141. return errThree
  5142. }
  5143. }
  5144. if good_yc.Count == 0 {
  5145. return nil
  5146. } else {
  5147. return errors.New("退库和出库数据不匹配")
  5148. }
  5149. }
  5150. func (this *DialysisAPIController) GetMobileScheduleList() {
  5151. limit, _ := this.GetInt64("limit")
  5152. page, _ := this.GetInt64("page")
  5153. type_options_visible, _ := this.GetInt64("type_options_visible")
  5154. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  5155. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  5156. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  5157. }
  5158. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  5159. newArr = make([]*models.HisPrescriptionProject, 0)
  5160. for i := 0; i < len(arr); i++ {
  5161. repeat := false
  5162. for j := i + 1; j < len(arr); j++ {
  5163. if arr[i].TeamId == arr[j].TeamId {
  5164. repeat = true
  5165. break
  5166. }
  5167. }
  5168. if !repeat {
  5169. newArr = append(newArr, arr[i])
  5170. }
  5171. }
  5172. return
  5173. }
  5174. func (this *DialysisAPIController) GetRoleList() {
  5175. admin_user_id, _ := this.GetInt64("admin_user_id")
  5176. orgid := this.GetMobileAdminUserInfo().Org.Id
  5177. list, err := service.GetRoleList(orgid, admin_user_id)
  5178. fmt.Println(err)
  5179. this.ServeSuccessJSON(map[string]interface{}{
  5180. "list": list,
  5181. })
  5182. return
  5183. }
  5184. func (this *DialysisAPIController) SavePatientSign() {
  5185. adminUserInfo := this.GetMobileAdminUserInfo()
  5186. patient_id, _ := this.GetInt64("patient_id")
  5187. dialysis_date, _ := this.GetInt64("dialysis_date")
  5188. orgid := adminUserInfo.Org.Id
  5189. var esdata models.DialysisOrder
  5190. var err error
  5191. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  5192. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5193. return
  5194. }
  5195. esdata.Hash = esdata.Hash
  5196. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  5197. order := models.DialysisOrder{
  5198. Hash: esdata.Hash,
  5199. Url: esdata.Url,
  5200. }
  5201. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  5202. redis := service.RedisClient()
  5203. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  5204. redis.Set(key, "", time.Second)
  5205. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  5206. //清空key 值
  5207. redis.Set(keyOne, "", time.Second)
  5208. //scheduleDateStartOne := startDate.Format("2006-01-02")
  5209. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5210. //redis.Set(keyTwo, "", time.Second)
  5211. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  5212. redis.Set(keyThree, "", time.Second)
  5213. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  5214. redis.Set(keyFour, "", time.Second)
  5215. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  5216. redis.Set(keyFive, "", time.Second)
  5217. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  5218. redis.Set(keySix, "", time.Second)
  5219. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  5220. redis.Set(keySeven, "", time.Second)
  5221. if err != nil {
  5222. fmt.Println(err)
  5223. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  5224. return
  5225. }
  5226. this.ServeSuccessJSON(map[string]interface{}{
  5227. "electronic_signature": esdata,
  5228. })
  5229. }
  5230. func (this *DialysisAPIController) GetPatientSign() {
  5231. patient_id, _ := this.GetInt64("patient_id")
  5232. dialysis_date, _ := this.GetInt64("dialysis_date")
  5233. adminUserInfo := this.GetMobileAdminUserInfo()
  5234. orgId := adminUserInfo.Org.Id
  5235. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  5236. if err != nil {
  5237. fmt.Println(err)
  5238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  5239. return
  5240. }
  5241. this.ServeSuccessJSON(map[string]interface{}{
  5242. "dialysisOrder": dialysisOrder,
  5243. })
  5244. }