patient_api_controller.go 211KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math"
  6. "strings"
  7. "XT_New/enums"
  8. "XT_New/models"
  9. "XT_New/service"
  10. "XT_New/utils"
  11. "github.com/jinzhu/gorm"
  12. // "fmt"
  13. "reflect"
  14. "strconv"
  15. "time"
  16. )
  17. type PatientApiController struct {
  18. MobileBaseAPIAuthController
  19. }
  20. func (c *PatientApiController) GetPatientInfoWithDiseases() {
  21. id, _ := c.GetInt64("patient", 0)
  22. if id <= 0 {
  23. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  24. return
  25. }
  26. adminUserInfo := c.GetMobileAdminUserInfo()
  27. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  28. if patient.ID == 0 {
  29. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  30. return
  31. }
  32. Registrars, err := service.GetAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, patient.RegistrarsId)
  33. if err != nil {
  34. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. return
  36. }
  37. if Registrars != nil {
  38. patient.Registrars = Registrars.Name
  39. }
  40. c.ServeSuccessJSON(map[string]interface{}{
  41. "patient": patient,
  42. })
  43. return
  44. }
  45. func (c *PatientApiController) CreateDialysisSolution() {
  46. id, _ := c.GetInt64("patient", 0)
  47. if id <= 0 {
  48. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  49. return
  50. }
  51. adminUserInfo := c.GetMobileAdminUserInfo()
  52. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  53. if patient.ID == 0 {
  54. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  55. return
  56. }
  57. //根据路由来做权限
  58. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  59. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  60. //if template.TemplateId == 2 || template.TemplateId == 6 {
  61. // if appRole.UserType == 3 {
  62. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  63. // if getPermissionErr != nil {
  64. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  65. // return
  66. // } else if headNursePermission == nil {
  67. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  68. // return
  69. // }
  70. // }
  71. //}
  72. var solution models.DialysisSolution
  73. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  74. if code > 0 {
  75. c.ServeFailJSONWithSGJErrorCode(code)
  76. return
  77. }
  78. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  79. solution.Doctor = adminUserInfo.AdminUser.Id
  80. solution.Status = 1
  81. solution.PatientId = id
  82. solution.CreatedTime = time.Now().Unix()
  83. solution.UserOrgId = adminUserInfo.Org.Id
  84. solution.UpdatedTime = time.Now().Unix()
  85. solution.SubName = ""
  86. solution.ParentId = 0
  87. err := service.CreatePatientDialysisSolution(&solution)
  88. if err != nil {
  89. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  90. return
  91. }
  92. c.ServeSuccessJSON(map[string]interface{}{
  93. "msg": "ok",
  94. "solution": solution,
  95. })
  96. return
  97. }
  98. func (c *PatientApiController) EditDialysisSolution() {
  99. id, _ := c.GetInt64("id", 0)
  100. if id <= 0 {
  101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  102. return
  103. }
  104. adminUserInfo := c.GetMobileAdminUserInfo()
  105. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.Org.Id, id)
  106. if solution.ID == 0 {
  107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  108. return
  109. }
  110. //if solution.Doctor != adminUserInfo.AdminUser.Id {
  111. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  112. // if getPermissionErr != nil {
  113. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  114. // return
  115. // } else if headNursePermission == nil {
  116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  117. // return
  118. // }
  119. //}
  120. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "update")
  121. if code > 0 {
  122. c.ServeFailJSONWithSGJErrorCode(code)
  123. return
  124. }
  125. // solution.RegistrarsId = adminUserInfo.AdminUser.Id
  126. solution.Doctor = adminUserInfo.AdminUser.Id
  127. solution.Status = 1
  128. // solution.PatientId = id
  129. // solution.CreatedTime = time.Now().Unix()
  130. // solution.UserOrgId = adminUserInfo.Org.Id
  131. solution.UpdatedTime = time.Now().Unix()
  132. // solution.SubName = ""
  133. // solution.ParentId = 0
  134. err := service.UpdatePatientDialysisSolution(&solution)
  135. if err != nil {
  136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  137. return
  138. }
  139. c.ServeSuccessJSON(map[string]interface{}{
  140. "msg": "ok",
  141. "solution": solution,
  142. })
  143. return
  144. }
  145. func (c *PatientApiController) CreateDoctorAdvice() {
  146. patient, _ := c.GetInt64("id", 0)
  147. if patient <= 0 {
  148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  149. return
  150. }
  151. adminUserInfo := c.GetMobileAdminUserInfo()
  152. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  153. if patientInfo.ID == 0 {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  155. return
  156. }
  157. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  158. //if appRole.UserType == 3{
  159. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  160. // return
  161. //}
  162. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  163. //
  164. //if appRole.UserType == 3 {
  165. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  166. // if getPermissionErr != nil {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  168. // return
  169. // } else if headNursePermission == nil {
  170. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  171. // return
  172. // }
  173. //}
  174. var advice models.DoctorAdvice
  175. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  176. if code > 0 {
  177. c.ServeFailJSONWithSGJErrorCode(code)
  178. return
  179. }
  180. if advice.ParentId > 0 {
  181. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  182. if old.ID == 0 || old.PatientId != patient {
  183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  184. return
  185. }
  186. if old.StopState == 1 || old.ExecutionState == 1 {
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  188. return
  189. }
  190. if old.ParentId > 0 {
  191. advice.ParentId = old.ParentId
  192. }
  193. advice.StartTime = old.StartTime
  194. advice.AdviceDoctor = old.AdviceDoctor
  195. advice.DeliveryWay = old.DeliveryWay
  196. advice.ExecutionFrequency = old.ExecutionFrequency
  197. advice.GroupNo = old.GroupNo
  198. }
  199. advice.Status = 1
  200. advice.CreatedTime = time.Now().Unix()
  201. advice.UpdatedTime = time.Now().Unix()
  202. advice.StopState = 2
  203. advice.ExecutionState = 2
  204. advice.UserOrgId = adminUserInfo.Org.Id
  205. advice.PatientId = patient
  206. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  207. err := service.CreateDoctorAdvice(&advice)
  208. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  209. redis := service.RedisClient()
  210. defer redis.Close()
  211. redis.Set(key, "", time.Second)
  212. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  213. redis.Set(keyOne, "", time.Second)
  214. if err != nil {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  216. return
  217. }
  218. c.ServeSuccessJSON(map[string]interface{}{
  219. "msg": "ok",
  220. "advice": advice,
  221. })
  222. return
  223. }
  224. func (c *PatientApiController) EditDoctorAdvice() {
  225. id, _ := c.GetInt64("id", 0)
  226. patient_id, _ := c.GetInt64("patient_id")
  227. doc_advice_date, _ := c.GetInt64("advice_date")
  228. if id <= 0 {
  229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  230. return
  231. }
  232. redis := service.RedisClient()
  233. adminUserInfo := c.GetMobileAdminUserInfo()
  234. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  235. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  236. //
  237. //if appRole.UserType == 3 {
  238. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  239. // if getPermissionErr != nil {
  240. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  241. // return
  242. // } else if headNursePermission == nil {
  243. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  244. // return
  245. // }
  246. //}
  247. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  248. if advice.ID == 0 {
  249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  250. return
  251. }
  252. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  253. if code > 0 {
  254. c.ServeFailJSONWithSGJErrorCode(code)
  255. return
  256. }
  257. advice.Status = 1
  258. advice.UpdatedTime = time.Now().Unix()
  259. advice.UserOrgId = adminUserInfo.Org.Id
  260. advice.Modifier = adminUserInfo.AdminUser.Id
  261. //处理修改医嘱开始时间逻辑(不包括子医嘱)
  262. //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
  263. //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
  264. var err error
  265. var isChangeGroup bool
  266. if advice.ParentId == 0 {
  267. adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  268. sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
  269. if len(adviceSlice) == 1 {
  270. // 查询信息规挡的设置天数
  271. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  272. if infor.ID > 0 && infor.WeekDay > 0 {
  273. var cha_time int64
  274. timeNowStr := time.Now().Format("2006-01-02")
  275. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  276. //今日的日期减去设置的日期
  277. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  278. if cha_time >= sourceAdvice.AdviceDate {
  279. //查询审核是否允许
  280. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id, 4)
  281. //申请状态不允许的情况 拒绝修改
  282. if infor.ApplicationStatus != 1 {
  283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  284. return
  285. }
  286. }
  287. }
  288. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  289. if advice.StartTime == sourceAdvice.StartTime {
  290. err = service.UpdateDoctorAdvice(&advice)
  291. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  292. defer redis.Close()
  293. redis.Set(key, "", time.Second)
  294. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":advice_list_all"
  295. redis.Set(keyOne, "", time.Second)
  296. isChangeGroup = false
  297. } else {
  298. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  299. isChangeGroup = false
  300. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  301. defer redis.Close()
  302. redis.Set(key, "", time.Second)
  303. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  304. redis.Set(keyOne, "", time.Second)
  305. }
  306. } else if len(adviceSlice) > 1 {
  307. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  308. if infor.ID > 0 {
  309. var cha_time int64
  310. timeNowStr := time.Now().Format("2006-01-02")
  311. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  312. //今日的日期减去设置的日期
  313. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  314. if cha_time >= sourceAdvice.AdviceDate {
  315. //查询审核是否允许
  316. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id, 4)
  317. //申请状态不允许的情况 拒绝修改
  318. if infor.ApplicationStatus != 1 {
  319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  320. return
  321. }
  322. }
  323. }
  324. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  325. if advice.StartTime == sourceAdvice.StartTime {
  326. err = service.UpdateDoctorAdvice(&advice)
  327. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  328. defer redis.Close()
  329. redis.Set(key, "", time.Second)
  330. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  331. redis.Set(keyOne, "", time.Second)
  332. isChangeGroup = false
  333. } else {
  334. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  335. gruopNo = gruopNo + 1
  336. advice.GroupNo = gruopNo
  337. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  338. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  339. defer redis.Close()
  340. redis.Set(key, "", time.Second)
  341. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  342. redis.Set(keyOne, "", time.Second)
  343. isChangeGroup = true
  344. }
  345. }
  346. } else {
  347. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  348. if infor.ID > 0 {
  349. var cha_time int64
  350. timeNowStr := time.Now().Format("2006-01-02")
  351. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  352. //今日的日期减去设置的日期
  353. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  354. if cha_time >= advice.AdviceDate {
  355. //查询审核是否允许
  356. infor, _ := service.GetDialysisInformationByRecordDate(id, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  357. //申请状态不允许的情况 拒绝修改
  358. if infor.ApplicationStatus != 1 {
  359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  360. return
  361. }
  362. }
  363. }
  364. isChangeGroup = false
  365. err = service.UpdateDoctorAdvice(&advice)
  366. redis := service.RedisClient()
  367. defer redis.Close()
  368. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  369. redis.Set(key, "", time.Second)
  370. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  371. redis.Set(keyOne, "", time.Second)
  372. }
  373. if err != nil {
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  375. return
  376. }
  377. if !isChangeGroup {
  378. c.ServeSuccessJSON(map[string]interface{}{
  379. "msg": "ok",
  380. "advice": advice,
  381. "isChange": isChangeGroup, //方便前端处理数据
  382. })
  383. } else {
  384. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  385. if err != nil {
  386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  387. return
  388. }
  389. c.ServeSuccessJSON(map[string]interface{}{
  390. "msg": "ok",
  391. "advice": newGroupAdvice,
  392. "isChange": isChangeGroup, //方便前端处理数据
  393. })
  394. }
  395. return
  396. }
  397. func (c *PatientApiController) StopDoctorAdvice() {
  398. id, _ := c.GetInt64("id", 0)
  399. if id <= 0 {
  400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  401. return
  402. }
  403. adminUserInfo := c.GetMobileAdminUserInfo()
  404. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  405. if advice.ID == 0 {
  406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  407. return
  408. }
  409. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  410. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  411. // return
  412. //}
  413. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  414. //
  415. //if appRole.UserType == 3 {
  416. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  417. // if getPermissionErr != nil {
  418. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  419. // return
  420. // } else if headNursePermission == nil {
  421. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  422. // return
  423. // }
  424. //}
  425. if advice.StopState == 1 {
  426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  427. return
  428. }
  429. dataBody := make(map[string]interface{}, 0)
  430. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  431. if err != nil {
  432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  433. return
  434. }
  435. timeLayout := "2006-01-02"
  436. loc, _ := time.LoadLocation("Local")
  437. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  438. utils.ErrorLog("stop_time")
  439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  440. return
  441. }
  442. stopTime, _ := dataBody["stop_time"].(string)
  443. if len(stopTime) == 0 {
  444. utils.ErrorLog("len(stop_time) == 0")
  445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  446. return
  447. }
  448. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  449. if err != nil {
  450. utils.ErrorLog(err.Error())
  451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  452. return
  453. }
  454. advice.StopTime = theTime.Unix()
  455. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  456. utils.ErrorLog("stop_reason")
  457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  458. return
  459. }
  460. stopReason, _ := dataBody["stop_reason"].(string)
  461. if len(stopReason) == 0 {
  462. utils.ErrorLog("len(stop_reason) == 0")
  463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  464. return
  465. }
  466. advice.StopReason = stopReason
  467. advice.Status = 1
  468. advice.UpdatedTime = time.Now().Unix()
  469. advice.StopDoctor = adminUserInfo.AdminUser.Id
  470. advice.StopState = 1
  471. advice.StopTime = time.Now().Unix()
  472. advice.Modifier = adminUserInfo.AdminUser.Id
  473. err = service.StopDoctorAdvice(&advice)
  474. if err != nil {
  475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  476. return
  477. }
  478. c.ServeSuccessJSON(map[string]interface{}{
  479. "msg": "ok",
  480. "advice": advice,
  481. })
  482. return
  483. }
  484. func (c *PatientApiController) DeleteDoctorAdvice() {
  485. id, _ := c.GetInt64("id", 0)
  486. if id <= 0 {
  487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  488. return
  489. }
  490. adminUserInfo := c.GetMobileAdminUserInfo()
  491. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  492. if advice.ID == 0 {
  493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  494. return
  495. }
  496. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  497. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  498. // return
  499. //}
  500. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  501. //
  502. //if appRole.UserType == 3 {
  503. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  504. // if getPermissionErr != nil {
  505. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  506. // return
  507. // } else if headNursePermission == nil {
  508. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  509. // return
  510. // }
  511. //}
  512. advice.UpdatedTime = time.Now().Unix()
  513. advice.Status = 0
  514. advice.Modifier = adminUserInfo.AdminUser.Id
  515. err := service.DeleteDoctorAdvice(&advice)
  516. if err != nil {
  517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  518. return
  519. }
  520. c.ServeSuccessJSON(map[string]interface{}{
  521. "msg": "ok",
  522. })
  523. return
  524. }
  525. func (c *PatientApiController) ExecDoctorAdvice() {
  526. execution_time := c.GetString("execution_time")
  527. origin, _ := c.GetInt64("origin", 0)
  528. groupno, _ := c.GetInt64("groupno", -1)
  529. record_date, _ := c.GetInt64("record_date")
  530. if origin != 2 {
  531. adminUserInfo := c.GetMobileAdminUserInfo()
  532. execution_staff := adminUserInfo.AdminUser.Id
  533. var ids []string
  534. advice_ids := c.GetString("advice_id")
  535. if groupno == 0 {
  536. ids = strings.Split(advice_ids, ",")
  537. }
  538. if groupno < 0 {
  539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  540. return
  541. }
  542. if len(execution_time) <= 0 {
  543. utils.ErrorLog("execution_time")
  544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  545. return
  546. }
  547. timeLayout2 := "2006-01-02 15:04:05"
  548. loc, _ := time.LoadLocation("Local")
  549. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  550. if errs != nil {
  551. utils.ErrorLog(errs.Error())
  552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  553. return
  554. }
  555. var advice models.DoctorAdvice
  556. if groupno > 0 {
  557. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  558. for _, item := range advices {
  559. //恒泰中医院
  560. if item.UserOrgId == 10490 || item.UserOrgId == 10602 {
  561. if item.DrugId == 0 || item.DrugNameId == 0 {
  562. //从字典里面查找
  563. drug, _ := service.GetBaseDrugByName(item.AdviceName, item.UserOrgId)
  564. service.UpdateDoctorAdviceByGoroupNo(item.ID, drug.ID)
  565. }
  566. }
  567. if item.ExecutionState == 2 {
  568. advice = item
  569. }
  570. //记录日志
  571. byterequest, _ := json.Marshal(item)
  572. adviceLog := models.XtDoctorAdviceLog{
  573. UserOrgId: item.UserOrgId,
  574. PatientId: item.PatientId,
  575. AdminUserId: adminUserInfo.AdminUser.Id,
  576. Module: 2,
  577. ErrLog: string(byterequest),
  578. Status: 1,
  579. Ctime: time.Now().Unix(),
  580. Mtime: 0,
  581. Source: "手机端执行医嘱",
  582. RecordDate: item.AdviceDate,
  583. }
  584. service.CreateDoctorAdviceLog(adviceLog)
  585. }
  586. } else {
  587. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  588. for _, item := range advices {
  589. //恒泰中医院
  590. if item.UserOrgId == 10490 || item.UserOrgId == 10602 {
  591. if item.DrugId == 0 || item.DrugNameId == 0 {
  592. //从字典里面查找
  593. drug, _ := service.GetBaseDrugByName(item.AdviceName, item.UserOrgId)
  594. service.UpdateDoctorAdviceByGoroupNo(item.ID, drug.ID)
  595. }
  596. }
  597. if item.ExecutionState == 2 {
  598. advice = item
  599. }
  600. }
  601. }
  602. if advice.ExecutionState == 1 {
  603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  604. return
  605. }
  606. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  608. return
  609. }
  610. //针对普宁
  611. if adminUserInfo.Org.Id != 10599 {
  612. if advice.StartTime > theTime.Unix() {
  613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  614. return
  615. }
  616. }
  617. advices := models.DoctorAdvice{
  618. ExecutionStaff: execution_staff,
  619. ExecutionTime: theTime.Unix(),
  620. UpdatedTime: time.Now().Unix(),
  621. }
  622. var err error
  623. if groupno > 0 {
  624. // 查询信息规挡的设置天数
  625. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  626. if infor.ID > 0 && infor.WeekDay > 0 {
  627. var cha_time int64
  628. timeNowStr := time.Now().Format("2006-01-02")
  629. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  630. //今日的日期减去设置的日期
  631. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  632. if cha_time >= record_date {
  633. //查询审核是否允许
  634. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  635. //申请状态不允许的情况 拒绝修改
  636. if infor.ApplicationStatus != 1 {
  637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  638. return
  639. }
  640. }
  641. }
  642. err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  643. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  644. redis := service.RedisClient()
  645. //清空key 值
  646. redis.Set(key, "", time.Second)
  647. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  648. redis.Set(keyTwo, "", time.Second)
  649. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  650. redis.Set(keyThree, "", time.Second)
  651. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  652. theTime := toTime.Format("2006-01-02")
  653. fmt.Println("theTIME", theTime)
  654. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  655. redis.Set(keyFour, "", time.Second)
  656. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  657. redis.Set(keyFive, "", time.Second)
  658. defer redis.Close()
  659. } else {
  660. // 查询信息规挡的设置天数
  661. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  662. if infor.ID > 0 {
  663. var cha_time int64
  664. timeNowStr := time.Now().Format("2006-01-02")
  665. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  666. //今日的日期减去设置的日期
  667. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  668. if cha_time >= record_date {
  669. //查询审核是否允许
  670. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  671. //申请状态不允许的情况 拒绝修改
  672. if infor.ApplicationStatus != 1 {
  673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  674. return
  675. }
  676. }
  677. }
  678. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  679. //记录日志
  680. byterequest, _ := json.Marshal(advice)
  681. adviceLog := models.XtDoctorAdviceLog{
  682. UserOrgId: advice.UserOrgId,
  683. PatientId: advice.PatientId,
  684. AdminUserId: adminUserInfo.AdminUser.Id,
  685. Module: 2,
  686. ErrLog: string(byterequest),
  687. Status: 1,
  688. Ctime: time.Now().Unix(),
  689. Mtime: 0,
  690. Source: "手机端执行医嘱",
  691. RecordDate: advices.RecordDate,
  692. }
  693. service.CreateDoctorAdviceLog(adviceLog)
  694. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  695. redis := service.RedisClient()
  696. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  697. redis.Set(keyTwo, "", time.Second)
  698. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  699. redis.Set(keyThree, "", time.Second)
  700. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  701. theTime := toTime.Format("2006-01-02")
  702. fmt.Println("theTIME", theTime)
  703. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  704. redis.Set(keyFour, "", time.Second)
  705. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  706. redis.Set(keySix, "", time.Second)
  707. defer redis.Close()
  708. //清空key 值
  709. redis.Set(key, "", time.Second)
  710. }
  711. if err != nil {
  712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  713. return
  714. }
  715. advice.ExecutionStaff = execution_staff
  716. advice.ExecutionTime = theTime.Unix()
  717. advice.ExecutionState = 1
  718. advice.Modifier = adminUserInfo.AdminUser.Id
  719. //处理出库相关逻辑
  720. //1.判断是否启用药品管理和自备药出库功能
  721. //药品管理信息
  722. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  723. //自备药信息
  724. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
  725. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.Org.Id)
  726. if drugStockConfig.IsOpen == 1 {
  727. if groupno > 0 {
  728. advices, _ := service.FindAllDoctorAdviceByGoroupNoTwety(adminUserInfo.Org.Id, groupno)
  729. if len(advices) > 0 {
  730. var total int64
  731. var prescribing_number_total int64
  732. //出库
  733. for _, item := range advices {
  734. if item.Way == 1 {
  735. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  736. //查询该药品的剩余库存
  737. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  738. //查询改药品信息
  739. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  740. //判断单位是否相等
  741. if medical.MaxUnit == item.PrescribingNumberUnit {
  742. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  743. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  744. //转化为最小单位
  745. total = list.Count * medical.MinNumber
  746. prescribing_number_total = count * medical.MinNumber
  747. }
  748. if medical.MinUnit == item.PrescribingNumberUnit {
  749. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  750. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  751. total = list.Count*medical.MinNumber + list.StockMinNumber
  752. prescribing_number_total = count
  753. }
  754. if medical.IsUse == 1 {
  755. c.ServeSuccessJSON(map[string]interface{}{
  756. "msg": "1",
  757. "advice": advice,
  758. "ids": ids,
  759. })
  760. return
  761. }
  762. if medical.IsUse != 1 {
  763. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  764. if advice.UserOrgId != 10278 {
  765. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  766. advice.ExecutionTime = 0
  767. advice.ExecutionState = 2
  768. advice.ExecutionStaff = 0
  769. }
  770. c.ServeSuccessJSON(map[string]interface{}{
  771. "msg": "3",
  772. "advice": advice,
  773. "ids": ids,
  774. })
  775. return
  776. }
  777. if prescribing_number_total > total {
  778. if advice.UserOrgId != 10278 {
  779. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  780. advice.ExecutionTime = 0
  781. advice.ExecutionState = 2
  782. advice.ExecutionStaff = 0
  783. }
  784. c.ServeSuccessJSON(map[string]interface{}{
  785. "msg": "2",
  786. "advice": advice,
  787. "ids": ids,
  788. })
  789. return
  790. }
  791. }
  792. //查询是否出库按钮开启
  793. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  794. if adviceSetting.IsAdviceOpen == 1 {
  795. //查询是否出库按钮开启
  796. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  797. //患者发药
  798. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  799. if prescriptionConfig.IsOpen == 1 {
  800. if medical.IsUse == 2 {
  801. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  802. //查询今日是否出库
  803. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  804. if drugOutInfo.ID == 0 {
  805. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  806. }
  807. }
  808. if pharmacyConfig.IsOpen != 1 {
  809. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  810. if drugOutInfo.ID == 0 {
  811. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  812. }
  813. }
  814. //更新字典里面的库存
  815. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  816. var sum_count int64
  817. for _, its := range stockInfo {
  818. if its.MaxUnit == medical.MaxUnit {
  819. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  820. }
  821. sum_count += its.StockMaxNumber + its.StockMinNumber
  822. }
  823. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  824. //剩余库存
  825. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  826. }
  827. }
  828. } else {
  829. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  830. if medical.IsUse == 2 {
  831. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  832. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  833. if drugOutInfo.ID == 0 {
  834. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  835. }
  836. }
  837. if pharmacyConfig.IsOpen != 1 {
  838. drugError := models.XtDrugError{
  839. ID: 0,
  840. UserOrgId: item.UserOrgId,
  841. DrugId: item.DrugId,
  842. RecordDate: item.AdviceDate,
  843. PatientId: item.PatientId,
  844. Remark: "恒泰中医院出库开始",
  845. Status: 1,
  846. Ctime: time.Now().Unix(),
  847. Mtime: 0,
  848. Prescribingnumber: item.PrescribingNumber,
  849. PrescribingNumberUnit: item.PrescribingNumberUnit,
  850. SumCount: 0,
  851. }
  852. service.CreateDrugError(drugError)
  853. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  854. if drugOutInfo.ID == 0 {
  855. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  856. }
  857. }
  858. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  859. var sum_count int64
  860. for _, its := range stockInfo {
  861. if its.MaxUnit == medical.MaxUnit {
  862. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  863. }
  864. sum_count += its.StockMaxNumber + its.StockMinNumber
  865. }
  866. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  867. //剩余库存
  868. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  869. }
  870. }
  871. }
  872. }
  873. }
  874. c.ServeSuccessJSON(map[string]interface{}{
  875. "msg": "1",
  876. "advice": advice,
  877. "ids": ids,
  878. })
  879. return
  880. } else {
  881. advices, _ := service.FindDoctorAdviceByIdsTwety(adminUserInfo.Org.Id, ids)
  882. if len(advices) > 0 {
  883. var total int64
  884. var prescribing_number_total int64
  885. for _, item := range advices {
  886. if item.Way == 1 {
  887. //查询改药品信息
  888. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  889. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  890. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  891. //查询该药品的剩余库存
  892. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  893. //判断单位是否相等
  894. if medical.MaxUnit == item.PrescribingNumberUnit {
  895. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  896. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  897. //转化为最小单位
  898. total = list.Count*medical.MinNumber + list.StockMinNumber
  899. prescribing_number_total = count * medical.MinNumber
  900. }
  901. if medical.MinUnit == item.PrescribingNumberUnit {
  902. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  903. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  904. total = list.Count*medical.MinNumber + list.StockMinNumber
  905. prescribing_number_total = count
  906. }
  907. if medical.IsUse == 1 {
  908. c.ServeSuccessJSON(map[string]interface{}{
  909. "msg": "1",
  910. "advice": advice,
  911. "ids": ids,
  912. })
  913. return
  914. }
  915. if medical.IsUse != 1 {
  916. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  917. if advice.UserOrgId != 10278 {
  918. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  919. advice.ExecutionTime = 0
  920. advice.ExecutionState = 2
  921. advice.ExecutionStaff = 0
  922. }
  923. c.ServeSuccessJSON(map[string]interface{}{
  924. "msg": "3",
  925. "advice": advice,
  926. "ids": ids,
  927. })
  928. return
  929. }
  930. if prescribing_number_total > total {
  931. if advice.UserOrgId != 10278 {
  932. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  933. advice.ExecutionTime = 0
  934. advice.ExecutionState = 2
  935. advice.ExecutionStaff = 0
  936. }
  937. c.ServeSuccessJSON(map[string]interface{}{
  938. "msg": "2",
  939. "advice": advice,
  940. "ids": ids,
  941. })
  942. return
  943. }
  944. }
  945. if medical.IsUse == 2 {
  946. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  947. //查询今日是否出库
  948. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  949. if drugOutInfo.ID == 0 {
  950. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  951. }
  952. }
  953. if pharmacyConfig.IsOpen != 1 {
  954. //查询今日是否出库
  955. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  956. if drugOutInfo.ID == 0 {
  957. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  958. }
  959. }
  960. //更新字典里面的库存
  961. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  962. var sum_count int64
  963. for _, its := range stockInfo {
  964. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  965. if its.MaxUnit == baseDrug.MaxUnit {
  966. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  967. }
  968. sum_count += its.StockMaxNumber + its.StockMinNumber
  969. }
  970. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  971. //剩余库存
  972. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  973. }
  974. if medical.IsUse == 1 {
  975. c.ServeSuccessJSON(map[string]interface{}{
  976. "msg": "1",
  977. "advice": advice,
  978. "ids": ids,
  979. })
  980. return
  981. }
  982. }
  983. }
  984. }
  985. c.ServeSuccessJSON(map[string]interface{}{
  986. "msg": "1",
  987. "advice": advice,
  988. "ids": ids,
  989. })
  990. return
  991. }
  992. }
  993. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  994. if groupno > 0 {
  995. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  996. for _, item := range advices {
  997. if item.ExecutionState == 1 && item.Way == 2 {
  998. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  999. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1000. timeStr := time.Now().Format("2006-01-02")
  1001. timeArr := strings.Split(timeStr, "-")
  1002. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  1003. total = total + 1
  1004. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1005. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1006. number = number + total
  1007. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1008. //插入自备药出库单
  1009. outStock := models.XtSelfOutStock{
  1010. DrugName: item.AdviceName,
  1011. DrugNameId: item.DrugNameId,
  1012. DrugSpec: item.AdviceDesc,
  1013. OutstoreNumber: count,
  1014. AdminUserId: adminUserInfo.AdminUser.Id,
  1015. StorckTime: item.AdviceDate,
  1016. UserOrgId: adminUserInfo.Org.Id,
  1017. CreatedTime: time.Now().Unix(),
  1018. Status: 1,
  1019. PatientId: item.PatientId,
  1020. ExitMode: 2,
  1021. MedicId: item.DrugId,
  1022. StockOutNumber: warehousing_out_order,
  1023. }
  1024. //查询 该患者是否已出库
  1025. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1026. if errcode == gorm.ErrRecordNotFound {
  1027. service.CreateOutStock(&outStock)
  1028. } else if errcode == nil {
  1029. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1030. fmt.Println("err", err)
  1031. }
  1032. }
  1033. }
  1034. } else {
  1035. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1036. for _, item := range advices {
  1037. if item.ExecutionState == 1 && item.Way == 2 {
  1038. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1039. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1040. timeStr := time.Now().Format("2006-01-02")
  1041. timeArr := strings.Split(timeStr, "-")
  1042. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  1043. total = total + 1
  1044. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1045. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1046. number = number + total
  1047. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1048. //插入自备药出库单
  1049. outStock := models.XtSelfOutStock{
  1050. DrugName: item.AdviceName,
  1051. DrugNameId: item.DrugNameId,
  1052. DrugSpec: item.AdviceDesc,
  1053. OutstoreNumber: count,
  1054. AdminUserId: adminUserInfo.AdminUser.Id,
  1055. StorckTime: item.AdviceDate,
  1056. UserOrgId: adminUserInfo.Org.Id,
  1057. CreatedTime: time.Now().Unix(),
  1058. Status: 1,
  1059. PatientId: item.PatientId,
  1060. ExitMode: 2,
  1061. MedicId: item.DrugId,
  1062. StockOutNumber: warehousing_out_order,
  1063. }
  1064. //查询 该患者是否已出库
  1065. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1066. if errcode == gorm.ErrRecordNotFound {
  1067. service.CreateOutStock(&outStock)
  1068. } else if errcode == nil {
  1069. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1070. fmt.Println("err", err)
  1071. }
  1072. }
  1073. }
  1074. c.ServeSuccessJSON(map[string]interface{}{
  1075. "msg": "1",
  1076. "advice": advice,
  1077. "ids": ids,
  1078. })
  1079. return
  1080. }
  1081. }
  1082. c.ServeSuccessJSON(map[string]interface{}{
  1083. "msg": "1",
  1084. "advice": advice,
  1085. "ids": ids,
  1086. })
  1087. return
  1088. } else if origin == 2 {
  1089. // 开始主事务
  1090. db := service.XTWriteDB()
  1091. tx := db.Begin()
  1092. // 在函数结束时处理事务回滚
  1093. defer func() {
  1094. if r := recover(); r != nil {
  1095. tx.Rollback()
  1096. }
  1097. }()
  1098. adminInfo := c.GetMobileAdminUserInfo()
  1099. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  1100. var ids []string
  1101. advice_ids := c.GetString("advice_id")
  1102. ids = strings.Split(advice_ids, ",")
  1103. if len(execution_time) <= 0 {
  1104. utils.ErrorLog("execution_time")
  1105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1106. return
  1107. }
  1108. timeLayout2 := "2006-01-02 15:04:05"
  1109. loc, _ := time.LoadLocation("Local")
  1110. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1111. if errs != nil {
  1112. utils.ErrorLog(errs.Error())
  1113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1114. return
  1115. }
  1116. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1117. var err error
  1118. for _, item := range advices {
  1119. if item.ExecutionState == 1 {
  1120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1121. return
  1122. }
  1123. if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
  1124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1125. return
  1126. }
  1127. if item.StartTime > theTime.Unix() {
  1128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1129. return
  1130. }
  1131. item.ExecutionState = 1
  1132. item.ExecutionStaff = adminInfo.AdminUser.Id
  1133. item.ExecutionTime = theTime.Unix()
  1134. item.IsMobile = 1
  1135. // 查询信息规挡的设置天数
  1136. infor, _ := service.GetDialysisInformationSetting(item.UserOrgId)
  1137. if infor.ID > 0 {
  1138. var cha_time int64
  1139. timeNowStr := time.Now().Format("2006-01-02")
  1140. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1141. //今日的日期减去设置的日期
  1142. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1143. if cha_time >= item.AdviceDate {
  1144. //查询审核是否允许
  1145. infor, _ := service.GetDialysisInformationByRecordDate(item.PatientId, item.AdviceDate, item.UserOrgId, 4)
  1146. //申请状态不允许的情况 拒绝修改
  1147. if infor.ApplicationStatus != 1 {
  1148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1149. return
  1150. }
  1151. }
  1152. }
  1153. //err = service.SaveHisDoctorAdvice(item)
  1154. service.SaveHisDoctorAdviceOne(item, tx)
  1155. //记录日志
  1156. byterequest, _ := json.Marshal(item)
  1157. adviceLog := models.XtDoctorAdviceLog{
  1158. UserOrgId: item.UserOrgId,
  1159. PatientId: item.PatientId,
  1160. AdminUserId: item.ExecutionStaff,
  1161. Module: 2,
  1162. ErrLog: string(byterequest),
  1163. Status: 1,
  1164. Ctime: time.Now().Unix(),
  1165. Mtime: 0,
  1166. Source: "手机端执行his医嘱",
  1167. RecordDate: item.AdviceDate,
  1168. }
  1169. service.CreateDoctorAdviceLog(adviceLog)
  1170. if err == nil {
  1171. drugError := models.XtDrugError{
  1172. UserOrgId: adminInfo.Org.Id,
  1173. DrugId: item.DrugId,
  1174. RecordDate: item.AdviceDate,
  1175. PatientId: item.PatientId,
  1176. Remark: "执行成功",
  1177. Status: 1,
  1178. Ctime: time.Now().Unix(),
  1179. Mtime: 0,
  1180. SumCount: 0,
  1181. Prescribingnumber: item.PrescribingNumber,
  1182. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1183. }
  1184. service.CreateDrugError(drugError)
  1185. }
  1186. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1187. redis := service.RedisClient()
  1188. //清空key 值
  1189. redis.Set(key, "", time.Second)
  1190. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1191. redis.Set(keyTwo, "", time.Second)
  1192. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1193. redis.Set(keyThree, "", time.Second)
  1194. recordDate := theTime.Format("2006-01-02")
  1195. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1196. redis.Set(keyFour, "", time.Second)
  1197. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1198. redis.Set(keyFive, "", time.Second)
  1199. defer redis.Close()
  1200. }
  1201. //药品管理信息
  1202. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  1203. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  1204. if drugStockConfig.IsOpen == 1 {
  1205. for _, item := range advices {
  1206. //查询改药品信息
  1207. medical, _ := service.GetBaseDrugMedicalOne(item.DrugId, tx)
  1208. //判断单位是否合格
  1209. if item.PrescribingNumberUnit != medical.MaxUnit && item.PrescribingNumberUnit != medical.MinUnit {
  1210. //查询该药品是否有出库记录
  1211. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate, tx)
  1212. if len(flowMap) == 0 {
  1213. errs := service.UpdateHisAdviceByIdOne(item.ID, tx)
  1214. if errs != nil {
  1215. drugError := models.XtDrugError{
  1216. UserOrgId: adminInfo.Org.Id,
  1217. DrugId: item.DrugId,
  1218. RecordDate: item.AdviceDate,
  1219. PatientId: item.PatientId,
  1220. Remark: "单位不统一,执行失败",
  1221. Status: 1,
  1222. Ctime: time.Now().Unix(),
  1223. Mtime: 0,
  1224. SumCount: 0,
  1225. Prescribingnumber: item.PrescribingNumber,
  1226. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1227. }
  1228. service.CreateDrugError(drugError)
  1229. }
  1230. }
  1231. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1232. tx.Commit()
  1233. c.ServeSuccessJSON(map[string]interface{}{
  1234. "msg": "7",
  1235. "advice": advice,
  1236. "ids": ids,
  1237. })
  1238. return
  1239. }
  1240. //查询这个患者这个患者这个药已经出库的所有数量
  1241. advicelist, _ := service.GetAllHisDoctorAdviceByIdOne(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId, tx)
  1242. drugoutlist, _ := service.GetAllDrugFlowByIdOne(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId, tx)
  1243. var total_count int64
  1244. var drug_count int64
  1245. for _, it := range advicelist {
  1246. if it.PrescribingNumberUnit == medical.MaxUnit {
  1247. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1248. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1249. total_count += prenumber * medical.MinNumber
  1250. }
  1251. if it.PrescribingNumberUnit == medical.MinUnit {
  1252. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1253. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1254. total_count += prenumber
  1255. }
  1256. }
  1257. for _, its := range drugoutlist {
  1258. if its.CountUnit == medical.MaxUnit {
  1259. drug_count += its.Count * medical.MinNumber
  1260. }
  1261. if its.CountUnit == medical.MinUnit {
  1262. drug_count += its.Count
  1263. }
  1264. }
  1265. if total_count == drug_count {
  1266. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1267. tx.Commit()
  1268. c.ServeSuccessJSON(map[string]interface{}{
  1269. "msg": "1",
  1270. "advice": advice,
  1271. "ids": ids,
  1272. })
  1273. return
  1274. }
  1275. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1276. var total int64
  1277. var prescribing_number_total int64
  1278. config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
  1279. if config.IsOpen != 1 {
  1280. //查询该药品是否有库存
  1281. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1282. list, _ := service.GetDrugTotalCountTwoTwety(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut, tx)
  1283. //判断单位是否相等
  1284. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1285. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1286. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1287. //转化为最小单位
  1288. total = list.Count*medical.MinNumber + list.StockMinNumber
  1289. prescribing_number_total = count * medical.MinNumber
  1290. }
  1291. //fmt.Println("医嘱开的数量", total)
  1292. if medical.MinUnit == advice.PrescribingNumberUnit {
  1293. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1294. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1295. total = list.Count*medical.MinNumber + list.StockMinNumber
  1296. prescribing_number_total = count
  1297. }
  1298. if medical.IsUse == 1 {
  1299. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1300. drugError := models.XtDrugError{
  1301. UserOrgId: adminInfo.Org.Id,
  1302. DrugId: item.DrugId,
  1303. RecordDate: item.AdviceDate,
  1304. PatientId: item.PatientId,
  1305. Remark: "零用药品库存不足",
  1306. Status: 1,
  1307. Ctime: time.Now().Unix(),
  1308. Mtime: 0,
  1309. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1310. Prescribingnumber: advice.PrescribingNumber,
  1311. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1312. }
  1313. service.CreateDrugError(drugError)
  1314. c.ServeSuccessJSON(map[string]interface{}{
  1315. "msg": "1",
  1316. "advice": advice,
  1317. "ids": ids,
  1318. })
  1319. return
  1320. }
  1321. }
  1322. if medical.IsUse != 1 {
  1323. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1324. drugError := models.XtDrugError{
  1325. UserOrgId: adminInfo.Org.Id,
  1326. DrugId: item.DrugId,
  1327. RecordDate: item.AdviceDate,
  1328. PatientId: item.PatientId,
  1329. Remark: "药品库存不足",
  1330. Status: 1,
  1331. Ctime: time.Now().Unix(),
  1332. Mtime: 0,
  1333. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1334. Prescribingnumber: advice.PrescribingNumber,
  1335. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1336. }
  1337. service.CreateDrugError(drugError)
  1338. tx.Commit()
  1339. c.ServeSuccessJSON(map[string]interface{}{
  1340. "msg": "3",
  1341. "advice": advice,
  1342. "ids": ids,
  1343. })
  1344. return
  1345. }
  1346. if prescribing_number_total > total {
  1347. drugError := models.XtDrugError{
  1348. UserOrgId: adminInfo.Org.Id,
  1349. DrugId: item.DrugId,
  1350. RecordDate: item.AdviceDate,
  1351. PatientId: item.PatientId,
  1352. Remark: "出库数量大于库存",
  1353. Status: 1,
  1354. Ctime: time.Now().Unix(),
  1355. Mtime: 0,
  1356. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1357. Prescribingnumber: advice.PrescribingNumber,
  1358. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1359. }
  1360. service.CreateDrugError(drugError)
  1361. tx.Commit()
  1362. c.ServeSuccessJSON(map[string]interface{}{
  1363. "msg": "2",
  1364. "advice": advice,
  1365. "ids": ids,
  1366. })
  1367. return
  1368. }
  1369. }
  1370. fmt.Println("hhahhahahahhhhhha", prescribing_number_total)
  1371. fmt.Println("total0000000000000", total)
  1372. fmt.Println("medical22222222222222", medical.IsUse)
  1373. fmt.Println("config.isp", config.IsOpen)
  1374. if prescribing_number_total <= total {
  1375. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1376. //判断药品是否零用
  1377. if medical.IsUse == 2 {
  1378. if config.IsOpen != 1 {
  1379. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1380. //service.NewHisDrugsDelivery(adminInfo.Org.Id, creater, &advice, tx)
  1381. //service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1382. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1383. //查询该药品是否有出库记录
  1384. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
  1385. if len(flowMap) == 0 {
  1386. errs := service.UpdateHisAdviceByIdOne(advice.ID, tx)
  1387. if errs != nil {
  1388. drugError := models.XtDrugError{
  1389. UserOrgId: adminInfo.Org.Id,
  1390. DrugId: item.DrugId,
  1391. RecordDate: item.AdviceDate,
  1392. PatientId: item.PatientId,
  1393. Remark: "出库记录为空,更新执行人失败",
  1394. Status: 1,
  1395. Ctime: time.Now().Unix(),
  1396. Mtime: 0,
  1397. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1398. Prescribingnumber: advice.PrescribingNumber,
  1399. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1400. }
  1401. service.CreateDrugError(drugError)
  1402. }
  1403. tx.Commit()
  1404. c.ServeSuccessJSON(map[string]interface{}{
  1405. "msg": "6",
  1406. "advice": advice,
  1407. "ids": ids,
  1408. })
  1409. return
  1410. }
  1411. }
  1412. }
  1413. if pharmacyConfig.IsOpen != 1 {
  1414. //service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1415. service.NewHisDrugsDelivery(adminInfo.Org.Id, creater, &advice, tx)
  1416. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1417. //查询该药品是否有出库记录
  1418. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
  1419. if len(flowMap) == 0 {
  1420. errs := service.UpdateHisAdviceByIdOne(advice.ID, tx)
  1421. if errs != nil {
  1422. drugError := models.XtDrugError{
  1423. UserOrgId: adminInfo.Org.Id,
  1424. DrugId: item.DrugId,
  1425. RecordDate: item.AdviceDate,
  1426. PatientId: item.PatientId,
  1427. Remark: "出库记录为空,更新执行人失败",
  1428. Status: 1,
  1429. Ctime: time.Now().Unix(),
  1430. Mtime: 0,
  1431. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1432. Prescribingnumber: advice.PrescribingNumber,
  1433. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1434. }
  1435. service.CreateDrugError(drugError)
  1436. }
  1437. tx.Commit()
  1438. c.ServeSuccessJSON(map[string]interface{}{
  1439. "msg": "6",
  1440. "advice": advice,
  1441. "ids": ids,
  1442. })
  1443. return
  1444. }
  1445. }
  1446. }
  1447. //更新字典里面的库存
  1448. stockInfo, _ := service.GetNewDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId, tx)
  1449. var sum_count int64
  1450. for _, its := range stockInfo {
  1451. if its.MaxUnit == medical.MaxUnit {
  1452. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1453. }
  1454. sum_count += its.StockMaxNumber + its.StockMinNumber
  1455. }
  1456. service.UpdateNewBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId, tx)
  1457. //剩余库存
  1458. service.UpdateNewDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count, tx)
  1459. }
  1460. }
  1461. }
  1462. }
  1463. //fmt.Println("config+++++++++++", config.IsOpen)
  1464. //fmt.Println("config+++++++++++", item.UserOrgId)
  1465. //
  1466. //if config.IsOpen == 1 && item.UserOrgId == 10210 {
  1467. //
  1468. // service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1469. // //更新字典里面的库存
  1470. // stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1471. // var sum_count int64
  1472. // for _, its := range stockInfo {
  1473. // if its.MaxUnit == medical.MaxUnit {
  1474. // its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1475. // }
  1476. // sum_count += its.StockMaxNumber + its.StockMinNumber
  1477. // }
  1478. // service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1479. // //剩余库存
  1480. // service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1481. //}
  1482. }
  1483. }
  1484. tx.Commit()
  1485. for _, item := range advices {
  1486. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1487. c.ServeSuccessJSON(map[string]interface{}{
  1488. "msg": "1",
  1489. "advice": advice,
  1490. "ids": ids,
  1491. })
  1492. }
  1493. }
  1494. }
  1495. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  1496. execution_time := c.GetString("execution_time")
  1497. fmt.Println("execution_time", execution_time)
  1498. groupno, _ := c.GetInt64("groupno", -1)
  1499. //patient_id, _ := c.GetInt64("patient_id")
  1500. advice_date, _ := c.GetInt64("advice_date")
  1501. var ids []string
  1502. if groupno == 0 {
  1503. advice_ids := c.GetString("advice_id")
  1504. ids = strings.Split(advice_ids, ",")
  1505. }
  1506. if groupno < 0 {
  1507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1508. return
  1509. }
  1510. if len(execution_time) <= 0 {
  1511. utils.ErrorLog("execution_time")
  1512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1513. return
  1514. }
  1515. timeLayout2 := "2006-01-02 15:04:05"
  1516. loc, _ := time.LoadLocation("Local")
  1517. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1518. if errs != nil {
  1519. utils.ErrorLog(errs.Error())
  1520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1521. return
  1522. }
  1523. adminUserInfo := c.GetMobileAdminUserInfo()
  1524. var advice models.DoctorAdvice
  1525. if groupno > 0 {
  1526. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1527. for _, item := range advices {
  1528. if item.ExecutionState == 1 {
  1529. advice = item
  1530. }
  1531. }
  1532. } else {
  1533. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1534. for _, item := range advices {
  1535. if item.ExecutionState == 1 {
  1536. advice = item
  1537. }
  1538. }
  1539. }
  1540. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  1541. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1542. // if getPermissionErr != nil {
  1543. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1544. // return
  1545. // } else if headNursePermission == nil {
  1546. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1547. // return
  1548. // }
  1549. //}
  1550. if advice.StartTime > theTime.Unix() {
  1551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1552. return
  1553. }
  1554. advices := models.DoctorAdvice{
  1555. ExecutionTime: theTime.Unix(),
  1556. UpdatedTime: time.Now().Unix(),
  1557. }
  1558. var err error
  1559. if groupno > 0 {
  1560. // 查询信息规挡的设置天数
  1561. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1562. if infor.ID > 0 {
  1563. var cha_time int64
  1564. timeNowStr := time.Now().Format("2006-01-02")
  1565. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1566. //今日的日期减去设置的日期
  1567. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1568. if cha_time >= advices.AdviceDate {
  1569. //查询审核是否允许
  1570. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1571. //申请状态不允许的情况 拒绝修改
  1572. if infor.ApplicationStatus != 1 {
  1573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1574. return
  1575. }
  1576. }
  1577. }
  1578. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1579. //记录日志
  1580. byterequest, _ := json.Marshal(advices)
  1581. adviceLog := models.XtDoctorAdviceLog{
  1582. UserOrgId: adminUserInfo.Org.Id,
  1583. PatientId: advices.PatientId,
  1584. AdminUserId: adminUserInfo.AdminUser.Id,
  1585. Module: 1,
  1586. ErrLog: string(byterequest),
  1587. Status: 1,
  1588. Ctime: time.Now().Unix(),
  1589. Mtime: 0,
  1590. Source: "手机端编辑医嘱",
  1591. RecordDate: advices.AdviceDate,
  1592. }
  1593. service.CreateDoctorAdviceLog(adviceLog)
  1594. redis := service.RedisClient()
  1595. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1596. redis.Set(key, "", time.Second)
  1597. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1598. redis.Set(keyOne, "", time.Second)
  1599. defer redis.Close()
  1600. } else {
  1601. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1602. if infor.ID > 0 {
  1603. var cha_time int64
  1604. timeNowStr := time.Now().Format("2006-01-02")
  1605. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1606. //今日的日期减去设置的日期
  1607. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1608. if cha_time >= advices.AdviceDate {
  1609. //查询审核是否允许
  1610. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1611. //申请状态不允许的情况 拒绝修改
  1612. if infor.ApplicationStatus != 1 {
  1613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1614. return
  1615. }
  1616. }
  1617. }
  1618. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  1619. err = service.ModifyExceDoctorAdviceByGroupNoOne(&advices, ids)
  1620. //记录日志
  1621. byterequest, _ := json.Marshal(advices)
  1622. adviceLog := models.XtDoctorAdviceLog{
  1623. UserOrgId: adminUserInfo.Org.Id,
  1624. PatientId: advices.PatientId,
  1625. AdminUserId: adminUserInfo.AdminUser.Id,
  1626. Module: 1,
  1627. ErrLog: string(byterequest),
  1628. Status: 1,
  1629. Ctime: time.Now().Unix(),
  1630. Mtime: 0,
  1631. Source: "手机端编辑执行医嘱",
  1632. RecordDate: advices.AdviceDate,
  1633. }
  1634. service.CreateDoctorAdviceLog(adviceLog)
  1635. redis := service.RedisClient()
  1636. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1637. redis.Set(key, "", time.Second)
  1638. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice_date, 10) + ":advice_list_all"
  1639. redis.Set(keyOne, "", time.Second)
  1640. defer redis.Close()
  1641. }
  1642. //判断是否开启his
  1643. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  1644. //如果开启去修改执行时间
  1645. if config.IsOpen == 1 {
  1646. advicesinfo := models.HisDoctorAdviceInfo{
  1647. ExecutionTime: theTime.Unix(),
  1648. UpdatedTime: time.Now().Unix(),
  1649. }
  1650. var advicehis models.HisDoctorAdviceInfo
  1651. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  1652. //记录日志
  1653. byterequest, _ := json.Marshal(advicesinfo)
  1654. adviceLog := models.XtDoctorAdviceLog{
  1655. UserOrgId: adminUserInfo.Org.Id,
  1656. PatientId: advices.PatientId,
  1657. AdminUserId: adminUserInfo.AdminUser.Id,
  1658. Module: 1,
  1659. ErrLog: string(byterequest),
  1660. Status: 1,
  1661. Ctime: time.Now().Unix(),
  1662. Mtime: 0,
  1663. Source: "手机端his编辑医嘱",
  1664. RecordDate: advices.AdviceDate,
  1665. }
  1666. service.CreateDoctorAdviceLog(adviceLog)
  1667. his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
  1668. for _, item := range his_advices {
  1669. if item.ExecutionState == 1 {
  1670. advicehis = item
  1671. }
  1672. }
  1673. redis := service.RedisClient()
  1674. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
  1675. redis.Set(keyThree, "", time.Second)
  1676. recordDate := theTime.Format("2006-01-02")
  1677. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1678. redis.Set(keyFour, "", time.Second)
  1679. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
  1680. redis.Set(keyFive, "", time.Second)
  1681. defer redis.Close()
  1682. project := models.HisPrescriptionProject{
  1683. ExecutionTime: theTime.Unix(),
  1684. Mtime: time.Now().Unix(),
  1685. }
  1686. service.ModifyHisPrescriptionProject(&project, ids)
  1687. //记录日志
  1688. projectquerst, _ := json.Marshal(project)
  1689. projectLog := models.XtDoctorAdviceLog{
  1690. UserOrgId: adminUserInfo.Org.Id,
  1691. PatientId: advices.PatientId,
  1692. AdminUserId: adminUserInfo.AdminUser.Id,
  1693. Module: 1,
  1694. ErrLog: string(projectquerst),
  1695. Status: 1,
  1696. Ctime: time.Now().Unix(),
  1697. Mtime: 0,
  1698. Source: "手机端his编辑项目医嘱",
  1699. RecordDate: advices.AdviceDate,
  1700. }
  1701. service.CreateDoctorAdviceLog(projectLog)
  1702. keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
  1703. redis.Set(keyEnd, "", time.Second)
  1704. keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1705. redis.Set(keyFours, "", time.Second)
  1706. keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
  1707. redis.Set(keyFives, "", time.Second)
  1708. defer redis.Close()
  1709. }
  1710. if err != nil {
  1711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1712. return
  1713. }
  1714. advice.ExecutionTime = theTime.Unix()
  1715. c.ServeSuccessJSON(map[string]interface{}{
  1716. "msg": "ok",
  1717. "advice": advice,
  1718. "ids": ids,
  1719. })
  1720. return
  1721. }
  1722. func (c *PatientApiController) CheckMobileDoctorAdvice() {
  1723. origin, _ := c.GetInt64("origin", 0)
  1724. record_date, _ := c.GetInt64("record_date")
  1725. patient_id, _ := c.GetInt64("patient_id")
  1726. check_time := c.GetString("check_time")
  1727. if len(check_time) <= 0 {
  1728. utils.ErrorLog("check_time")
  1729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1730. return
  1731. }
  1732. timeLayout2 := "2006-01-02 15:04:05"
  1733. loc, _ := time.LoadLocation("Local")
  1734. theTime, errs := time.ParseInLocation(timeLayout2, check_time, loc)
  1735. fmt.Println("theTimewowowow", theTime)
  1736. if errs != nil {
  1737. utils.ErrorLog(errs.Error())
  1738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1739. return
  1740. }
  1741. if origin != 2 {
  1742. groupno, _ := c.GetInt64("groupno", -1)
  1743. var ids []string
  1744. if groupno == 0 {
  1745. advice_ids := c.GetString("advice_id")
  1746. if advice_ids == "" {
  1747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1748. return
  1749. } else {
  1750. ids = strings.Split(advice_ids, ",")
  1751. if len(ids) <= 0 {
  1752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1753. return
  1754. }
  1755. }
  1756. }
  1757. if groupno < 0 {
  1758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1759. return
  1760. }
  1761. adminUserInfo := c.GetMobileAdminUserInfo()
  1762. var advice models.DoctorAdvice
  1763. if groupno > 0 {
  1764. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1765. for _, item := range advices {
  1766. if item.CheckState == 0 {
  1767. advice = item
  1768. }
  1769. //记录日志
  1770. byterequest, _ := json.Marshal(advices)
  1771. adviceLog := models.XtDoctorAdviceLog{
  1772. UserOrgId: adminUserInfo.Org.Id,
  1773. PatientId: item.PatientId,
  1774. AdminUserId: adminUserInfo.AdminUser.Id,
  1775. Module: 3,
  1776. ErrLog: string(byterequest),
  1777. Status: 1,
  1778. Ctime: time.Now().Unix(),
  1779. Mtime: 0,
  1780. Source: "手机端核对医嘱",
  1781. RecordDate: item.AdviceDate,
  1782. }
  1783. service.CreateDoctorAdviceLog(adviceLog)
  1784. }
  1785. if advice.CheckState == 1 {
  1786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1787. return
  1788. }
  1789. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1791. return
  1792. }
  1793. } else {
  1794. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1795. for _, item := range advices {
  1796. if item.CheckState == 0 {
  1797. advice = item
  1798. }
  1799. //记录日志
  1800. byterequest, _ := json.Marshal(advices)
  1801. adviceLog := models.XtDoctorAdviceLog{
  1802. UserOrgId: adminUserInfo.Org.Id,
  1803. PatientId: item.PatientId,
  1804. AdminUserId: adminUserInfo.AdminUser.Id,
  1805. Module: 3,
  1806. ErrLog: string(byterequest),
  1807. Status: 1,
  1808. Ctime: time.Now().Unix(),
  1809. Mtime: 0,
  1810. Source: "手机端核对医嘱",
  1811. RecordDate: item.AdviceDate,
  1812. }
  1813. service.CreateDoctorAdviceLog(adviceLog)
  1814. }
  1815. if advice.CheckState == 1 {
  1816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1817. return
  1818. }
  1819. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1821. return
  1822. }
  1823. }
  1824. checker := adminUserInfo.AdminUser.Id
  1825. advices := models.DoctorAdvice{
  1826. CheckTime: theTime.Unix(),
  1827. Checker: checker,
  1828. UpdatedTime: time.Now().Unix(),
  1829. }
  1830. fmt.Println("groupnowowowowoowowow", groupno)
  1831. var err error
  1832. if groupno > 0 {
  1833. // 查询信息规挡的设置天数
  1834. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1835. if infor.ID > 0 && infor.WeekDay > 0 {
  1836. var cha_time int64
  1837. timeNowStr := time.Now().Format("2006-01-02")
  1838. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1839. //今日的日期减去设置的日期
  1840. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1841. if cha_time >= record_date {
  1842. //查询审核是否允许
  1843. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  1844. //申请状态不允许的情况 拒绝修改
  1845. if infor.ApplicationStatus != 1 {
  1846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1847. return
  1848. }
  1849. }
  1850. }
  1851. err = service.CheckDoctorAdviceByGroupNoOne(&advices, groupno, adminUserInfo.Org.Id)
  1852. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1853. redis := service.RedisClient()
  1854. //清空key 值
  1855. redis.Set(key, "", time.Second)
  1856. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1857. redis.Set(keyTwo, "", time.Second)
  1858. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1859. redis.Set(keyThree, "", time.Second)
  1860. recordDate := theTime.Format("2006-01-02")
  1861. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1862. redis.Set(keyFour, "", time.Second)
  1863. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1864. redis.Set(keyFive, "", time.Second)
  1865. defer redis.Close()
  1866. } else {
  1867. if len(ids[0]) <= 0 {
  1868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1869. return
  1870. } else {
  1871. //t := time.Now().Format("2006-01-02")/**/
  1872. //timeLayout2 := "2006-01-02"
  1873. //loc, _ := time.LoadLocation("Local")
  1874. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  1875. // 查询信息规挡的设置天数
  1876. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1877. if infor.ID > 0 {
  1878. var cha_time int64
  1879. timeNowStr := time.Now().Format("2006-01-02")
  1880. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1881. //今日的日期减去设置的日期
  1882. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1883. if cha_time >= advices.AdviceDate {
  1884. //查询审核是否允许
  1885. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1886. //申请状态不允许的情况 拒绝修改
  1887. if infor.ApplicationStatus != 1 {
  1888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1889. return
  1890. }
  1891. }
  1892. }
  1893. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  1894. //记录日志
  1895. byterequest, _ := json.Marshal(advices)
  1896. adviceLog := models.XtDoctorAdviceLog{
  1897. UserOrgId: adminUserInfo.Org.Id,
  1898. PatientId: advices.PatientId,
  1899. AdminUserId: advices.Checker,
  1900. Module: 3,
  1901. ErrLog: string(byterequest),
  1902. Status: 1,
  1903. Ctime: time.Now().Unix(),
  1904. Mtime: 0,
  1905. Source: "手机端核对医嘱",
  1906. RecordDate: advices.AdviceDate,
  1907. }
  1908. service.CreateDoctorAdviceLog(adviceLog)
  1909. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1910. redis := service.RedisClient()
  1911. //清空key 值
  1912. redis.Set(key, "", time.Second)
  1913. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1914. redis.Set(keyTwo, "", time.Second)
  1915. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1916. redis.Set(keyThree, "", time.Second)
  1917. recordDate := theTime.Format("2006-01-02")
  1918. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1919. redis.Set(keyFour, "", time.Second)
  1920. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1921. redis.Set(keyFive, "", time.Second)
  1922. defer redis.Close()
  1923. }
  1924. }
  1925. if err != nil {
  1926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1927. return
  1928. }
  1929. advice.Checker = checker
  1930. advice.CheckTime = theTime.Unix()
  1931. advice.CheckState = 1
  1932. c.ServeSuccessJSON(map[string]interface{}{
  1933. "msg": "ok",
  1934. "advice": advice,
  1935. })
  1936. }
  1937. return
  1938. }
  1939. func (c *PatientApiController) CheckDoctorAdvice() {
  1940. origin, _ := c.GetInt64("origin", 0)
  1941. record_date, _ := c.GetInt64("record_date")
  1942. patient_id, _ := c.GetInt64("patient_id")
  1943. if origin != 2 {
  1944. groupno, _ := c.GetInt64("groupno", -1)
  1945. var ids []string
  1946. if groupno == 0 {
  1947. advice_ids := c.GetString("advice_id")
  1948. if advice_ids == "" {
  1949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1950. return
  1951. } else {
  1952. ids = strings.Split(advice_ids, ",")
  1953. if len(ids) <= 0 {
  1954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1955. return
  1956. }
  1957. }
  1958. }
  1959. if groupno < 0 {
  1960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1961. return
  1962. }
  1963. adminUserInfo := c.GetMobileAdminUserInfo()
  1964. var advice models.DoctorAdvice
  1965. if groupno > 0 {
  1966. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1967. for _, item := range advices {
  1968. if item.CheckState == 0 {
  1969. advice = item
  1970. }
  1971. //记录日志
  1972. byterequest, _ := json.Marshal(advices)
  1973. adviceLog := models.XtDoctorAdviceLog{
  1974. UserOrgId: adminUserInfo.Org.Id,
  1975. PatientId: item.PatientId,
  1976. AdminUserId: adminUserInfo.AdminUser.Id,
  1977. Module: 3,
  1978. ErrLog: string(byterequest),
  1979. Status: 1,
  1980. Ctime: time.Now().Unix(),
  1981. Mtime: 0,
  1982. Source: "手机端核对医嘱",
  1983. RecordDate: item.AdviceDate,
  1984. }
  1985. service.CreateDoctorAdviceLog(adviceLog)
  1986. }
  1987. if advice.CheckState == 1 {
  1988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1989. return
  1990. }
  1991. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1993. return
  1994. }
  1995. } else {
  1996. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1997. for _, item := range advices {
  1998. if item.CheckState == 0 {
  1999. advice = item
  2000. }
  2001. //记录日志
  2002. byterequest, _ := json.Marshal(advices)
  2003. adviceLog := models.XtDoctorAdviceLog{
  2004. UserOrgId: adminUserInfo.Org.Id,
  2005. PatientId: item.PatientId,
  2006. AdminUserId: adminUserInfo.AdminUser.Id,
  2007. Module: 3,
  2008. ErrLog: string(byterequest),
  2009. Status: 1,
  2010. Ctime: time.Now().Unix(),
  2011. Mtime: 0,
  2012. Source: "手机端核对医嘱",
  2013. RecordDate: item.AdviceDate,
  2014. }
  2015. service.CreateDoctorAdviceLog(adviceLog)
  2016. }
  2017. if advice.CheckState == 1 {
  2018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2019. return
  2020. }
  2021. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2023. return
  2024. }
  2025. }
  2026. checker := adminUserInfo.AdminUser.Id
  2027. theTime := time.Now()
  2028. advices := models.DoctorAdvice{
  2029. CheckTime: theTime.Unix(),
  2030. Checker: checker,
  2031. UpdatedTime: time.Now().Unix(),
  2032. }
  2033. var err error
  2034. if groupno > 0 {
  2035. // 查询信息规挡的设置天数
  2036. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2037. if infor.ID > 0 && infor.WeekDay > 0 {
  2038. var cha_time int64
  2039. timeNowStr := time.Now().Format("2006-01-02")
  2040. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2041. //今日的日期减去设置的日期
  2042. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2043. if cha_time >= record_date {
  2044. //查询审核是否允许
  2045. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  2046. //申请状态不允许的情况 拒绝修改
  2047. if infor.ApplicationStatus != 1 {
  2048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2049. return
  2050. }
  2051. }
  2052. }
  2053. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  2054. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2055. redis := service.RedisClient()
  2056. //清空key 值
  2057. redis.Set(key, "", time.Second)
  2058. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2059. redis.Set(keyTwo, "", time.Second)
  2060. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2061. redis.Set(keyThree, "", time.Second)
  2062. recordDate := theTime.Format("2006-01-02")
  2063. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2064. redis.Set(keyFour, "", time.Second)
  2065. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2066. redis.Set(keyFive, "", time.Second)
  2067. defer redis.Close()
  2068. } else {
  2069. if len(ids[0]) <= 0 {
  2070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2071. return
  2072. } else {
  2073. //t := time.Now().Format("2006-01-02")/**/
  2074. //timeLayout2 := "2006-01-02"
  2075. //loc, _ := time.LoadLocation("Local")
  2076. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  2077. // 查询信息规挡的设置天数
  2078. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2079. if infor.ID > 0 {
  2080. var cha_time int64
  2081. timeNowStr := time.Now().Format("2006-01-02")
  2082. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2083. //今日的日期减去设置的日期
  2084. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2085. if cha_time >= advices.AdviceDate {
  2086. //查询审核是否允许
  2087. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2088. //申请状态不允许的情况 拒绝修改
  2089. if infor.ApplicationStatus != 1 {
  2090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2091. return
  2092. }
  2093. }
  2094. }
  2095. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  2096. //记录日志
  2097. byterequest, _ := json.Marshal(advices)
  2098. adviceLog := models.XtDoctorAdviceLog{
  2099. UserOrgId: adminUserInfo.Org.Id,
  2100. PatientId: advices.PatientId,
  2101. AdminUserId: advices.Checker,
  2102. Module: 3,
  2103. ErrLog: string(byterequest),
  2104. Status: 1,
  2105. Ctime: time.Now().Unix(),
  2106. Mtime: 0,
  2107. Source: "手机端核对医嘱",
  2108. RecordDate: advices.AdviceDate,
  2109. }
  2110. service.CreateDoctorAdviceLog(adviceLog)
  2111. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2112. redis := service.RedisClient()
  2113. //清空key 值
  2114. redis.Set(key, "", time.Second)
  2115. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2116. redis.Set(keyTwo, "", time.Second)
  2117. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2118. redis.Set(keyThree, "", time.Second)
  2119. recordDate := theTime.Format("2006-01-02")
  2120. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2121. redis.Set(keyFour, "", time.Second)
  2122. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2123. redis.Set(keyFive, "", time.Second)
  2124. defer redis.Close()
  2125. }
  2126. }
  2127. if err != nil {
  2128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2129. return
  2130. }
  2131. advice.Checker = checker
  2132. advice.CheckTime = theTime.Unix()
  2133. advice.CheckState = 1
  2134. c.ServeSuccessJSON(map[string]interface{}{
  2135. "msg": "ok",
  2136. "advice": advice,
  2137. })
  2138. } else if origin == 2 {
  2139. adminInfo := c.GetMobileAdminUserInfo()
  2140. var ids []string
  2141. advice_ids := c.GetString("advice_id")
  2142. ids = strings.Split(advice_ids, ",")
  2143. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  2144. var err error
  2145. for _, item := range advices {
  2146. if item.CheckState == 1 {
  2147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2148. return
  2149. }
  2150. if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
  2151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2152. return
  2153. }
  2154. item.Checker = adminInfo.AdminUser.Id
  2155. item.CheckTime = time.Now().Unix()
  2156. item.CheckState = 1
  2157. // 查询信息规挡的设置天数
  2158. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  2159. if infor.ID > 0 {
  2160. var cha_time int64
  2161. timeNowStr := time.Now().Format("2006-01-02")
  2162. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2163. //今日的日期减去设置的日期
  2164. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2165. if cha_time >= record_date {
  2166. //查询审核是否允许
  2167. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminInfo.Org.Id, 4)
  2168. //申请状态不允许的情况 拒绝修改
  2169. if infor.ApplicationStatus != 1 {
  2170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2171. return
  2172. }
  2173. }
  2174. }
  2175. err = service.SaveHisDoctorAdvice(item)
  2176. //记录日志
  2177. byterequest, _ := json.Marshal(advices)
  2178. adviceLog := models.XtDoctorAdviceLog{
  2179. UserOrgId: adminInfo.Org.Id,
  2180. PatientId: item.PatientId,
  2181. AdminUserId: item.Checker,
  2182. Module: 3,
  2183. ErrLog: string(byterequest),
  2184. Status: 1,
  2185. Ctime: time.Now().Unix(),
  2186. Mtime: 0,
  2187. Source: "手机端核对His医嘱",
  2188. RecordDate: item.AdviceDate,
  2189. }
  2190. service.CreateDoctorAdviceLog(adviceLog)
  2191. redis := service.RedisClient()
  2192. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2193. //清空key 值
  2194. redis.Set(key, "", time.Second)
  2195. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2196. redis.Set(keyTwo, "", time.Second)
  2197. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2198. redis.Set(keyThree, "", time.Second)
  2199. theTime := time.Now()
  2200. recordDate := theTime.Format("2006-01-02")
  2201. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  2202. redis.Set(keyFour, "", time.Second)
  2203. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2204. redis.Set(keyFive, "", time.Second)
  2205. defer redis.Close()
  2206. }
  2207. if err == nil {
  2208. c.ServeSuccessJSON(map[string]interface{}{
  2209. "msg": "ok",
  2210. "advice": advices,
  2211. })
  2212. } else {
  2213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2214. return
  2215. }
  2216. }
  2217. return
  2218. }
  2219. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  2220. id, _ := c.GetInt64("patient", 0)
  2221. assessmentDate := c.GetString("assessment_date", "")
  2222. if id <= 0 || len(assessmentDate) != 10 {
  2223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2224. return
  2225. }
  2226. timeLayout := "2006-01-02"
  2227. loc, _ := time.LoadLocation("Local")
  2228. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  2229. if err != nil {
  2230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2231. return
  2232. }
  2233. theAssessmentDateTime := theTime.Unix()
  2234. adminUserInfo := c.GetMobileAdminUserInfo()
  2235. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2236. if patient.ID == 0 {
  2237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2238. return
  2239. }
  2240. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  2241. if getPEErr != nil {
  2242. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  2243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2244. return
  2245. }
  2246. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2247. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2248. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2249. var evaluation models.PredialysisEvaluation
  2250. if theEvaluation != nil {
  2251. evaluation = *theEvaluation
  2252. }
  2253. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  2254. if code > 0 {
  2255. c.ServeFailJSONWithSGJErrorCode(code)
  2256. return
  2257. }
  2258. if theEvaluation == nil {
  2259. evaluation.CreatedTime = time.Now().Unix()
  2260. evaluation.Status = 1
  2261. evaluation.AssessmentDate = theAssessmentDateTime
  2262. evaluation.PatientId = id
  2263. evaluation.UserOrgId = adminUserInfo.Org.Id
  2264. if appRole.UserType == 2 || appRole.UserType == 1 {
  2265. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2266. evaluation.AssessmentTime = time.Now().Unix()
  2267. } else {
  2268. evaluation.Creater = adminUserInfo.AdminUser.Id
  2269. }
  2270. } else {
  2271. evaluation.UpdatedTime = time.Now().Unix()
  2272. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  2273. if appRole.UserType == 2 || appRole.UserType == 1 {
  2274. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2275. evaluation.AssessmentTime = time.Now().Unix()
  2276. } else {
  2277. evaluation.Modifier = adminUserInfo.AdminUser.Id
  2278. if evaluation.Creater == 0 {
  2279. evaluation.Creater = adminUserInfo.AdminUser.Id
  2280. }
  2281. }
  2282. }
  2283. //新增逻辑
  2284. var dewater_amount float64
  2285. dewater_amount = 0
  2286. if evaluation.DryWeight > 0 {
  2287. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2288. if template.TemplateId == 17 || template.TemplateId == 22 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 34 || template.TemplateId == 32 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10551 || adminUserInfo.Org.Id == 10579 || adminUserInfo.Org.Id == 10580 || adminUserInfo.Org.Id == 10585 {
  2289. if adminUserInfo.Org.Id != 10551 && adminUserInfo.Org.Id != 10579 && adminUserInfo.Org.Id != 10580 && adminUserInfo.Org.Id != 10585 {
  2290. dewater_amount = dewater_amount * 1000
  2291. }
  2292. }
  2293. if dewater_amount <= 0 {
  2294. dewater_amount = 0
  2295. }
  2296. } else {
  2297. dewater_amount = 0
  2298. }
  2299. // 计算透析处方的相关超滤量
  2300. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  2301. lastDialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient.ID, adminUserInfo.Org.Id)
  2302. var lastDialysisPrescribe *models.DialysisPrescription
  2303. var dialysisSolution *models.DialysisSolution
  2304. var dialysisPrescribe *models.DialysisPrescription
  2305. var system_dialysisPrescribe *models.SystemPrescription
  2306. var mode_id int64
  2307. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  2308. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  2309. if schedual != nil {
  2310. // 获取透析模版
  2311. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  2312. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  2313. mode_id = schedual.ModeId
  2314. } else {
  2315. // 获取透析模版
  2316. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  2317. if dialysisPrescribe == nil && dialysisSolution != nil {
  2318. mode_id = dialysisSolution.ModeId
  2319. }
  2320. if dialysisPrescribe == nil && dialysisSolution == nil {
  2321. mode_id = 0
  2322. }
  2323. }
  2324. // 插入透析处方
  2325. if dialysisPrescribe == nil && dialysisSolution != nil {
  2326. var newprescribe models.DialysisPrescription
  2327. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2328. newprescribe.PatientId = id
  2329. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2330. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2331. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2332. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2333. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2334. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2335. newprescribe.ModeId = dialysisSolution.ModeId
  2336. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2337. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2338. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2339. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2340. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2341. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2342. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2343. newprescribe.Glucose = dialysisSolution.Glucose
  2344. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2345. newprescribe.Kalium = dialysisSolution.Kalium
  2346. newprescribe.Sodium = dialysisSolution.Sodium
  2347. newprescribe.Calcium = dialysisSolution.Calcium
  2348. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2349. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2350. newprescribe.Conductivity = dialysisSolution.Conductivity
  2351. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2352. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2353. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2354. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2355. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2356. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2357. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2358. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2359. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2360. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2361. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2362. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2363. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2364. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2365. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2366. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2367. newprescribe.CreatedTime = time.Now().Unix()
  2368. newprescribe.UpdatedTime = time.Now().Unix()
  2369. newprescribe.RecordDate = theAssessmentDateTime
  2370. newprescribe.DewaterAmount = dewater_amount
  2371. newprescribe.TargetUltrafiltration = dewater_amount
  2372. newprescribe.Status = 1
  2373. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  2374. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  2375. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2376. newprescribe.Remark = lastDialysisPrescription.Remark
  2377. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2378. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2379. newprescribe.ID = dialysisPrescription.ID
  2380. if dialysisPrescription.ID == 0 {
  2381. if adminUserInfo.Org.Id == 10340 {
  2382. newprescribe.Sodium = 138
  2383. newprescribe.Bicarbonate = 31.1
  2384. newprescribe.DialysateFlow = 500
  2385. newprescribe.PrescribingNumber = 1
  2386. }
  2387. err := service.AddSigleRecord(&newprescribe)
  2388. //记录日志
  2389. byterequest, _ := json.Marshal(newprescribe)
  2390. prescriptionLog := models.XtDialysisPrescriptionLog{
  2391. UserOrgId: adminUserInfo.Org.Id,
  2392. Ctime: time.Now().Unix(),
  2393. Mtime: 0,
  2394. ErrLog: string(byterequest),
  2395. AdminUserId: adminUserInfo.AdminUser.Id,
  2396. RecordDate: newprescribe.RecordDate,
  2397. PatientId: id,
  2398. Source: "手机端新增透前评估插入处方",
  2399. Status: 1,
  2400. }
  2401. service.CreatePrescriptionLog(prescriptionLog)
  2402. //获取key,清空redis
  2403. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2404. redis := service.RedisClient()
  2405. //清空key 值
  2406. redis.Set(key, "", time.Second)
  2407. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2408. //清空key 值
  2409. redis.Set(keyOne, "", time.Second)
  2410. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2411. //清空key 值
  2412. redis.Set(keyTwo, "", time.Second)
  2413. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2414. redis.Set(keySix, "", time.Second)
  2415. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2416. redis.Set(keySeven, "", time.Second)
  2417. if err != nil {
  2418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2419. }
  2420. } else {
  2421. if adminUserInfo.Org.Id == 10340 {
  2422. newprescribe.Sodium = 138
  2423. newprescribe.Bicarbonate = 31.1
  2424. newprescribe.DialysateFlow = 500
  2425. }
  2426. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2427. //
  2428. if appRole.UserType == 2 || appRole.UserType == 1 {
  2429. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2430. if adminUserInfo.Org.Id == 9882 {
  2431. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2432. }
  2433. }
  2434. err := service.UpDateDialysisPrescription(&newprescribe)
  2435. //记录日志
  2436. byterequest, _ := json.Marshal(newprescribe)
  2437. prescriptionLog := models.XtDialysisPrescriptionLog{
  2438. UserOrgId: adminUserInfo.Org.Id,
  2439. Ctime: time.Now().Unix(),
  2440. Mtime: 0,
  2441. ErrLog: string(byterequest),
  2442. AdminUserId: adminUserInfo.AdminUser.Id,
  2443. RecordDate: newprescribe.RecordDate,
  2444. PatientId: id,
  2445. Source: "手机端新增透前评估插入处方",
  2446. Status: 1,
  2447. }
  2448. service.CreatePrescriptionLog(prescriptionLog)
  2449. //获取key,清空redis
  2450. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2451. redis := service.RedisClient()
  2452. //清空key 值
  2453. redis.Set(key, "", time.Second)
  2454. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2455. //清空key 值
  2456. redis.Set(keyOne, "", time.Second)
  2457. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2458. //清空key 值
  2459. redis.Set(keyTwo, "", time.Second)
  2460. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2461. redis.Set(keySix, "", time.Second)
  2462. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2463. redis.Set(keySeven, "", time.Second)
  2464. if err != nil {
  2465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2466. }
  2467. }
  2468. }
  2469. if dialysisPrescribe == nil && dialysisSolution == nil {
  2470. if lastDialysisPrescribe != nil {
  2471. var newprescribe models.DialysisPrescription
  2472. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2473. newprescribe.PatientId = id
  2474. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2475. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2476. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2477. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2478. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2479. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2480. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2481. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2482. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2483. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2484. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2485. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2486. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2487. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2488. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2489. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2490. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2491. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2492. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2493. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2494. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2495. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2496. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2497. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2498. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2499. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2500. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2501. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2502. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2503. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2504. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2505. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2506. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2507. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2508. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2509. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2510. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2511. newprescribe.CreatedTime = time.Now().Unix()
  2512. newprescribe.UpdatedTime = time.Now().Unix()
  2513. newprescribe.RecordDate = theAssessmentDateTime
  2514. newprescribe.DewaterAmount = dewater_amount
  2515. newprescribe.TargetUltrafiltration = dewater_amount
  2516. newprescribe.Status = 1
  2517. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  2518. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  2519. if dialysisSolution != nil && dialysisSolution.DialysisStrainer != "" {
  2520. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2521. }
  2522. newprescribe.Remark = lastDialysisPrescription.Remark
  2523. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2524. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2525. newprescribe.ID = dialysisPrescription.ID
  2526. if dialysisPrescription.ID == 0 {
  2527. if adminUserInfo.Org.Id == 10340 {
  2528. newprescribe.Sodium = 138
  2529. newprescribe.Bicarbonate = 31.1
  2530. newprescribe.DialysateFlow = 500
  2531. }
  2532. err := service.AddSigleRecord(&newprescribe)
  2533. //记录日志
  2534. byterequest, _ := json.Marshal(newprescribe)
  2535. prescriptionLog := models.XtDialysisPrescriptionLog{
  2536. UserOrgId: adminUserInfo.Org.Id,
  2537. Ctime: time.Now().Unix(),
  2538. Mtime: 0,
  2539. ErrLog: string(byterequest),
  2540. AdminUserId: adminUserInfo.AdminUser.Id,
  2541. RecordDate: newprescribe.RecordDate,
  2542. PatientId: id,
  2543. Source: "手机端新增透前评估插入处方",
  2544. Status: 1,
  2545. }
  2546. service.CreatePrescriptionLog(prescriptionLog)
  2547. //获取key,清空redis
  2548. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2549. redis := service.RedisClient()
  2550. //清空key 值
  2551. redis.Set(key, "", time.Second)
  2552. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2553. //清空key 值
  2554. redis.Set(keyOne, "", time.Second)
  2555. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2556. //清空key 值
  2557. redis.Set(keyTwo, "", time.Second)
  2558. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2559. redis.Set(keySix, "", time.Second)
  2560. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2561. redis.Set(keySeven, "", time.Second)
  2562. if err != nil {
  2563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2564. }
  2565. } else {
  2566. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2567. //
  2568. if appRole.UserType == 2 || appRole.UserType == 1 {
  2569. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2570. if adminUserInfo.Org.Id == 9882 {
  2571. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2572. }
  2573. }
  2574. err := service.UpDateDialysisPrescription(&newprescribe)
  2575. //记录日志
  2576. byterequest, _ := json.Marshal(newprescribe)
  2577. prescriptionLog := models.XtDialysisPrescriptionLog{
  2578. UserOrgId: adminUserInfo.Org.Id,
  2579. Ctime: time.Now().Unix(),
  2580. Mtime: 0,
  2581. ErrLog: string(byterequest),
  2582. AdminUserId: adminUserInfo.AdminUser.Id,
  2583. RecordDate: newprescribe.RecordDate,
  2584. PatientId: id,
  2585. Source: "手机端新增透前评估插入处方",
  2586. Status: 1,
  2587. }
  2588. service.CreatePrescriptionLog(prescriptionLog)
  2589. //获取key,清空redis
  2590. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2591. redis := service.RedisClient()
  2592. //清空key 值
  2593. redis.Set(key, "", time.Second)
  2594. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2595. //清空key 值
  2596. redis.Set(keyOne, "", time.Second)
  2597. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2598. //清空key 值
  2599. redis.Set(keyTwo, "", time.Second)
  2600. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2601. redis.Set(keySix, "", time.Second)
  2602. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2603. redis.Set(keySeven, "", time.Second)
  2604. if err != nil {
  2605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2606. }
  2607. }
  2608. if err != nil {
  2609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2610. }
  2611. } else if system_dialysisPrescribe != nil {
  2612. var newprescribe models.DialysisPrescription
  2613. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2614. newprescribe.PatientId = id
  2615. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  2616. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  2617. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  2618. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  2619. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  2620. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  2621. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  2622. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  2623. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  2624. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  2625. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  2626. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  2627. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  2628. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  2629. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  2630. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  2631. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  2632. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  2633. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  2634. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  2635. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  2636. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  2637. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  2638. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  2639. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  2640. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  2641. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  2642. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  2643. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  2644. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  2645. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  2646. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  2647. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  2648. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  2649. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  2650. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  2651. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  2652. newprescribe.CreatedTime = time.Now().Unix()
  2653. newprescribe.UpdatedTime = time.Now().Unix()
  2654. newprescribe.RecordDate = theAssessmentDateTime
  2655. newprescribe.DewaterAmount = dewater_amount
  2656. newprescribe.TargetUltrafiltration = dewater_amount
  2657. newprescribe.Status = 1
  2658. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  2659. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  2660. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2661. newprescribe.Remark = lastDialysisPrescription.Remark
  2662. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2663. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2664. newprescribe.ID = dialysisPrescription.ID
  2665. if dialysisPrescription.ID == 0 {
  2666. if adminUserInfo.Org.Id == 10340 {
  2667. newprescribe.Sodium = 138
  2668. newprescribe.Bicarbonate = 31.1
  2669. newprescribe.DialysateFlow = 500
  2670. }
  2671. err := service.AddSigleRecord(&newprescribe)
  2672. //记录日志
  2673. byterequest, _ := json.Marshal(newprescribe)
  2674. prescriptionLog := models.XtDialysisPrescriptionLog{
  2675. UserOrgId: adminUserInfo.Org.Id,
  2676. Ctime: time.Now().Unix(),
  2677. Mtime: 0,
  2678. ErrLog: string(byterequest),
  2679. AdminUserId: adminUserInfo.AdminUser.Id,
  2680. RecordDate: newprescribe.RecordDate,
  2681. PatientId: id,
  2682. Source: "手机端新增透前评估插入处方",
  2683. Status: 1,
  2684. }
  2685. service.CreatePrescriptionLog(prescriptionLog)
  2686. //获取key,清空redis
  2687. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2688. redis := service.RedisClient()
  2689. //清空key 值
  2690. redis.Set(key, "", time.Second)
  2691. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2692. //清空key 值
  2693. redis.Set(keyOne, "", time.Second)
  2694. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2695. //清空key 值
  2696. redis.Set(keyTwo, "", time.Second)
  2697. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2698. redis.Set(keySix, "", time.Second)
  2699. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2700. redis.Set(keySeven, "", time.Second)
  2701. if err != nil {
  2702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2703. }
  2704. } else {
  2705. if adminUserInfo.Org.Id == 10340 {
  2706. newprescribe.Sodium = 138
  2707. newprescribe.Bicarbonate = 31.1
  2708. newprescribe.DialysateFlow = 500
  2709. }
  2710. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2711. //
  2712. if appRole.UserType == 2 || appRole.UserType == 1 {
  2713. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2714. if adminUserInfo.Org.Id == 9882 {
  2715. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2716. }
  2717. }
  2718. err := service.UpDateDialysisPrescription(&newprescribe)
  2719. //记录日志
  2720. byterequest, _ := json.Marshal(newprescribe)
  2721. prescriptionLog := models.XtDialysisPrescriptionLog{
  2722. UserOrgId: adminUserInfo.Org.Id,
  2723. Ctime: time.Now().Unix(),
  2724. Mtime: 0,
  2725. ErrLog: string(byterequest),
  2726. AdminUserId: adminUserInfo.AdminUser.Id,
  2727. RecordDate: newprescribe.RecordDate,
  2728. PatientId: id,
  2729. Source: "手机端新增透前评估插入处方",
  2730. Status: 1,
  2731. }
  2732. service.CreatePrescriptionLog(prescriptionLog)
  2733. //获取key,清空redis
  2734. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2735. redis := service.RedisClient()
  2736. //清空key 值
  2737. redis.Set(key, "", time.Second)
  2738. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2739. //清空key 值
  2740. redis.Set(keyOne, "", time.Second)
  2741. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2742. //清空key 值
  2743. redis.Set(keyTwo, "", time.Second)
  2744. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2745. redis.Set(keySix, "", time.Second)
  2746. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2747. redis.Set(keySeven, "", time.Second)
  2748. if err != nil {
  2749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2750. }
  2751. }
  2752. if err != nil {
  2753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2754. }
  2755. } else {
  2756. var newprescribe models.DialysisPrescription
  2757. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2758. newprescribe.PatientId = id
  2759. newprescribe.ModeId = mode_id
  2760. newprescribe.CreatedTime = time.Now().Unix()
  2761. newprescribe.UpdatedTime = time.Now().Unix()
  2762. newprescribe.RecordDate = theAssessmentDateTime
  2763. newprescribe.DewaterAmount = dewater_amount
  2764. newprescribe.TargetUltrafiltration = dewater_amount
  2765. newprescribe.Status = 1
  2766. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2767. if dialysisPrescription.ID > 0 {
  2768. newprescribe.ID = dialysisPrescription.ID
  2769. }
  2770. if dialysisPrescription.ID == 0 {
  2771. if adminUserInfo.Org.Id == 10340 {
  2772. newprescribe.Sodium = 138
  2773. newprescribe.Bicarbonate = 31.1
  2774. newprescribe.DialysateFlow = 500
  2775. }
  2776. err := service.AddSigleRecord(&newprescribe)
  2777. //获取key,清空redis
  2778. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2779. redis := service.RedisClient()
  2780. //清空key 值
  2781. redis.Set(key, "", time.Second)
  2782. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2783. //清空key 值
  2784. redis.Set(keyOne, "", time.Second)
  2785. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2786. //清空key 值
  2787. redis.Set(keyTwo, "", time.Second)
  2788. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2789. redis.Set(keySix, "", time.Second)
  2790. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2791. redis.Set(keySeven, "", time.Second)
  2792. if err != nil {
  2793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2794. }
  2795. } else {
  2796. if adminUserInfo.Org.Id == 10340 {
  2797. newprescribe.Sodium = 138
  2798. newprescribe.Bicarbonate = 31.1
  2799. newprescribe.DialysateFlow = 500
  2800. }
  2801. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2802. //
  2803. if appRole.UserType == 2 || appRole.UserType == 1 {
  2804. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2805. if adminUserInfo.Org.Id == 9882 {
  2806. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2807. }
  2808. }
  2809. err := service.UpDateDialysisPrescription(&newprescribe)
  2810. //记录日志
  2811. byterequest, _ := json.Marshal(newprescribe)
  2812. prescriptionLog := models.XtDialysisPrescriptionLog{
  2813. UserOrgId: adminUserInfo.Org.Id,
  2814. Ctime: time.Now().Unix(),
  2815. Mtime: 0,
  2816. ErrLog: string(byterequest),
  2817. AdminUserId: adminUserInfo.AdminUser.Id,
  2818. RecordDate: newprescribe.RecordDate,
  2819. PatientId: id,
  2820. Source: "手机端新增透前评估插入处方",
  2821. Status: 1,
  2822. }
  2823. service.CreatePrescriptionLog(prescriptionLog)
  2824. //获取key,清空redis
  2825. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2826. redis := service.RedisClient()
  2827. //清空key 值
  2828. redis.Set(key, "", time.Second)
  2829. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2830. //清空key 值
  2831. redis.Set(keyOne, "", time.Second)
  2832. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2833. //清空key 值
  2834. redis.Set(keyTwo, "", time.Second)
  2835. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2836. redis.Set(keySix, "", time.Second)
  2837. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2838. redis.Set(keySeven, "", time.Second)
  2839. if err != nil {
  2840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2841. }
  2842. }
  2843. if err != nil {
  2844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2845. }
  2846. }
  2847. }
  2848. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  2849. // if dialysisPrescribe != nil {
  2850. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  2851. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  2852. // dialysisPrescribe.DewaterAmount = dewater_amount
  2853. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  2854. // dialysisPrescribe.Status = 1
  2855. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  2856. // if updateErr != nil {
  2857. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2858. // }
  2859. // }
  2860. // 查询信息规挡的设置天数
  2861. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2862. if infor.ID > 0 && infor.WeekDay > 0 {
  2863. var cha_time int64
  2864. timeNowStr := time.Now().Format("2006-01-02")
  2865. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2866. //今日的日期减去设置的日期
  2867. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2868. if cha_time >= evaluation.AssessmentDate {
  2869. //查询审核是否允许
  2870. infor, _ := service.GetDialysisInformationByRecordDate(id, evaluation.AssessmentDate, adminUserInfo.Org.Id, 3)
  2871. //申请状态不允许的情况 拒绝修改
  2872. if infor.ApplicationStatus != 1 {
  2873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2874. return
  2875. }
  2876. }
  2877. }
  2878. //针对长沙南雅的问题
  2879. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10164 {
  2880. if len(evaluation.SymptomBeforeDialysis) == 0 {
  2881. predialysisEvaluation, _ := service.GetPredialysisEvaluation(id, adminUserInfo.Org.Id)
  2882. evaluation.SymptomBeforeDialysis = predialysisEvaluation.SymptomBeforeDialysis
  2883. }
  2884. }
  2885. err = service.UpadatePredialysisEvaluation(&evaluation)
  2886. //记录日志
  2887. byterequest, _ := json.Marshal(evaluation)
  2888. beforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  2889. UserOrgId: evaluation.UserOrgId,
  2890. AdminUserId: adminUserInfo.AdminUser.Id,
  2891. ErrLog: string(byterequest),
  2892. PatientId: evaluation.PatientId,
  2893. RecordDate: evaluation.AssessmentDate,
  2894. Ctime: time.Now().Unix(),
  2895. Mtime: 0,
  2896. Status: 1,
  2897. Source: "手机端保存透前评估",
  2898. }
  2899. service.CreateBeforLog(beforeDislysisLog)
  2900. finish := models.XtDialysisFinish{
  2901. IsFinish: 1,
  2902. UserOrgId: adminUserInfo.Org.Id,
  2903. Status: 1,
  2904. Ctime: time.Now().Unix(),
  2905. Mtime: 0,
  2906. Module: 3,
  2907. RecordDate: evaluation.AssessmentDate,
  2908. Sourse: 1,
  2909. PatientId: id,
  2910. }
  2911. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, evaluation.AssessmentDate, 3, id)
  2912. if dialysisFinish.ID == 0 {
  2913. service.CreateDialysisFinish(finish)
  2914. }
  2915. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  2916. redis := service.RedisClient()
  2917. defer redis.Close()
  2918. //清空key 值
  2919. redis.Set(key, "", time.Second)
  2920. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  2921. redis.Set(keyOne, "", time.Second)
  2922. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2923. redis.Set(keyTwo, "", time.Second)
  2924. if err != nil {
  2925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  2926. return
  2927. }
  2928. c.ServeSuccessJSON(map[string]interface{}{
  2929. "msg": "ok",
  2930. "evaluation": evaluation,
  2931. })
  2932. return
  2933. }
  2934. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2935. dataBody := make(map[string]interface{}, 0)
  2936. err := json.Unmarshal(data, &dataBody)
  2937. utils.InfoLog(string(data))
  2938. if err != nil {
  2939. utils.ErrorLog(err.Error())
  2940. code = enums.ErrorCodeParamWrong
  2941. return
  2942. }
  2943. // if method == "create" {
  2944. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  2945. utils.ErrorLog("mode")
  2946. code = enums.ErrorCodeParamWrong
  2947. return
  2948. }
  2949. mode := int64(dataBody["mode"].(float64))
  2950. if mode <= 0 {
  2951. utils.ErrorLog("mode <= 0")
  2952. code = enums.ErrorCodeParamWrong
  2953. return
  2954. }
  2955. solution.ModeId = mode
  2956. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  2957. utils.ErrorLog("mode_name")
  2958. code = enums.ErrorCodeParamWrong
  2959. return
  2960. }
  2961. modeName, _ := dataBody["mode_name"].(string)
  2962. if len(modeName) == 0 {
  2963. utils.ErrorLog("len(mode_name) == 0")
  2964. code = enums.ErrorCodeParamWrong
  2965. return
  2966. }
  2967. solution.ModeName = modeName
  2968. solution.Name = modeName
  2969. // }
  2970. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2971. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2972. solution.DialysisDuration = dialysisDuration
  2973. }
  2974. if dataBody["dialysis_duration"] != nil {
  2975. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2976. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2977. solution.DialysisDuration = dialysisDuration
  2978. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  2979. dialysisDuration := dataBody["dialysis_duration"].(float64)
  2980. solution.DialysisDuration = dialysisDuration
  2981. }
  2982. }
  2983. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  2984. dialyzer := int64(dataBody["dialyzer"].(float64))
  2985. solution.Dialyzer = dialyzer
  2986. }
  2987. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2988. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2989. solution.PerfusionApparatus = perfusionApparatus
  2990. }
  2991. if dataBody["blood_flow_volume"] != nil {
  2992. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2993. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2994. solution.BloodFlowVolume = bloodFlowVolume
  2995. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  2996. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  2997. solution.BloodFlowVolume = bloodFlowVolume
  2998. }
  2999. }
  3000. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3001. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3002. solution.HemodialysisMachine = hemodialysisMachine
  3003. }
  3004. if dataBody["dewater"] != nil {
  3005. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  3006. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  3007. solution.Dewater = dewater
  3008. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  3009. dewater := dataBody["dewater"].(float64)
  3010. solution.Dewater = dewater
  3011. }
  3012. }
  3013. if dataBody["replacement_total"] != nil {
  3014. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  3015. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  3016. solution.ReplacementTotal = replacementTotal
  3017. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  3018. replacementTotal := dataBody["replacement_total"].(float64)
  3019. solution.ReplacementTotal = replacementTotal
  3020. }
  3021. }
  3022. if dataBody["displace_liqui"] != nil {
  3023. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  3024. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  3025. solution.DisplaceLiqui = displaceLiqui
  3026. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  3027. displaceLiqui := dataBody["displace_liqui"].(float64)
  3028. solution.DisplaceLiqui = displaceLiqui
  3029. }
  3030. }
  3031. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3032. replacementWay := int64(dataBody["replacement_way"].(float64))
  3033. solution.ReplacementWay = replacementWay
  3034. }
  3035. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3036. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3037. solution.Anticoagulant = anticoagulant
  3038. }
  3039. if dataBody["anticoagulant_shouji"] != nil {
  3040. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3041. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3042. solution.AnticoagulantShouji = anticoagulantShouji
  3043. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  3044. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  3045. solution.AnticoagulantShouji = anticoagulantShouji
  3046. }
  3047. }
  3048. if dataBody["anticoagulant_weichi"] != nil {
  3049. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3050. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3051. solution.AnticoagulantWeichi = anticoagulantWeichi
  3052. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  3053. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  3054. solution.AnticoagulantWeichi = anticoagulantWeichi
  3055. }
  3056. }
  3057. if dataBody["anticoagulant_zongliang"] != nil {
  3058. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3059. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3060. solution.AnticoagulantZongliang = anticoagulantZongliang
  3061. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  3062. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  3063. solution.AnticoagulantZongliang = anticoagulantZongliang
  3064. }
  3065. }
  3066. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3067. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3068. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3069. }
  3070. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3071. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3072. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3073. }
  3074. if dataBody["kalium"] != nil {
  3075. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3076. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3077. solution.Kalium = kalium
  3078. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  3079. kalium := dataBody["kalium"].(float64)
  3080. solution.Kalium = kalium
  3081. }
  3082. }
  3083. if dataBody["sodium"] != nil {
  3084. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3085. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3086. solution.Sodium = sodium
  3087. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  3088. sodium := dataBody["sodium"].(float64)
  3089. solution.Sodium = sodium
  3090. }
  3091. }
  3092. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3093. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3094. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3095. solution.Calcium = calcium
  3096. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  3097. calcium := dataBody["calcium"].(float64)
  3098. solution.Calcium = calcium
  3099. }
  3100. }
  3101. if dataBody["bicarbonate"] != nil {
  3102. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3103. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3104. solution.Bicarbonate = bicarbonate
  3105. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  3106. bicarbonate := dataBody["bicarbonate"].(float64)
  3107. solution.Bicarbonate = bicarbonate
  3108. }
  3109. }
  3110. if dataBody["glucose"] != nil {
  3111. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  3112. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  3113. solution.Glucose = glucose
  3114. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  3115. glucose := dataBody["glucose"].(float64)
  3116. solution.Glucose = glucose
  3117. }
  3118. }
  3119. // if dataBody["dry_weight"] != nil {
  3120. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3121. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3122. // solution.DryWeight = dryWeight
  3123. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  3124. // dryWeight := dataBody["dry_weight"].(float64)
  3125. // solution.DryWeight = dryWeight
  3126. // }
  3127. // }
  3128. if dataBody["dialysate_flow"] != nil {
  3129. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3130. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3131. solution.DialysateFlow = dialysateFlow
  3132. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  3133. dialysateFlow := dataBody["dialysate_flow"].(float64)
  3134. solution.DialysateFlow = dialysateFlow
  3135. }
  3136. }
  3137. if dataBody["dialysate_temperature"] != nil {
  3138. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  3139. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  3140. solution.DialysateTemperature = dialysateTemperature
  3141. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  3142. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  3143. solution.DialysateTemperature = dialysateTemperature
  3144. }
  3145. }
  3146. if dataBody["conductivity"] != nil {
  3147. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  3148. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  3149. solution.Conductivity = conductivity
  3150. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  3151. conductivity := dataBody["conductivity"].(float64)
  3152. solution.Conductivity = conductivity
  3153. }
  3154. }
  3155. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3156. remark := dataBody["remark"].(string)
  3157. solution.Remark = remark
  3158. }
  3159. if dataBody["dialysis_duration_hour"] != nil {
  3160. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  3161. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  3162. solution.DialysisDurationHour = dialysisDurationHour
  3163. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  3164. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  3165. solution.DialysisDurationHour = int64(dialysisDurationHour)
  3166. }
  3167. }
  3168. if dataBody["dialysis_duration_minute"] != nil {
  3169. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  3170. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  3171. solution.DialysisDurationMinute = dialysisDurationMinute
  3172. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  3173. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  3174. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  3175. }
  3176. }
  3177. if dataBody["target_ultrafiltration"] != nil {
  3178. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  3179. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  3180. solution.TargetUltrafiltration = targetUltrafiltration
  3181. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  3182. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  3183. solution.TargetUltrafiltration = targetUltrafiltration
  3184. }
  3185. }
  3186. if dataBody["dialysate_formulation"] != nil {
  3187. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  3188. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  3189. solution.DialysateFormulation = dialysateFormulation
  3190. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  3191. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  3192. solution.DialysateFormulation = int64(dialysateFormulation)
  3193. }
  3194. }
  3195. return
  3196. }
  3197. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  3198. dataBody := make(map[string]interface{}, 0)
  3199. err := json.Unmarshal(data, &dataBody)
  3200. utils.InfoLog(string(data))
  3201. if err != nil {
  3202. utils.ErrorLog(err.Error())
  3203. code = enums.ErrorCodeParamWrong
  3204. return
  3205. }
  3206. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  3207. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  3208. evaluation.WeightBefore = weightVefore
  3209. }
  3210. // fmt.Println(dataBody["dry_weight"])
  3211. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  3212. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3213. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3214. fmt.Println(additionalWeight)
  3215. evaluation.DryWeight = additionalWeight
  3216. }
  3217. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  3218. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  3219. fmt.Println(additionalWeight)
  3220. evaluation.AdditionalWeight = additionalWeight
  3221. }
  3222. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  3223. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  3224. evaluation.Temperature = Temperature
  3225. }
  3226. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  3227. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  3228. evaluation.SystolicBloodPressure = systolicBloodPressure
  3229. }
  3230. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  3231. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  3232. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  3233. }
  3234. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  3235. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  3236. evaluation.PulseFrequency = pulseFrequency
  3237. }
  3238. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  3239. breathingRate := dataBody["breathing_rate"].(string)
  3240. evaluation.BreathingRate = breathingRate
  3241. }
  3242. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  3243. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  3244. evaluation.LastPostDialysis = lastPostDialysis
  3245. }
  3246. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  3247. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  3248. evaluation.DialysisInterphase = dialysisInterphase
  3249. }
  3250. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  3251. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  3252. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  3253. }
  3254. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  3255. catheter, _ := dataBody["catheter"].(string)
  3256. evaluation.Catheter = catheter
  3257. }
  3258. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  3259. catheter_bend := int(dataBody["catheter_bend"].(float64))
  3260. evaluation.CatheterBend = catheter_bend
  3261. }
  3262. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  3263. Complication, _ := dataBody["complication"].(string)
  3264. evaluation.Complication = Complication
  3265. }
  3266. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3267. remark := dataBody["remark"].(string)
  3268. evaluation.Remark = remark
  3269. }
  3270. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  3271. machine_type := dataBody["machine_type"].(string)
  3272. evaluation.MachineType = machine_type
  3273. }
  3274. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  3275. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  3276. evaluation.BloodAccessPartId = blood_access_part_id
  3277. }
  3278. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  3279. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  3280. // evaluation.BloodAccessPartId = blood_access_part_id
  3281. //}
  3282. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  3283. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  3284. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  3285. }
  3286. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  3287. internal_fistula, _ := dataBody["internal_fistula"].(string)
  3288. evaluation.InternalFistula = internal_fistula
  3289. }
  3290. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  3291. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  3292. evaluation.InternalFistulaSkin = internal_fistula_skin
  3293. }
  3294. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  3295. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  3296. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  3297. evaluation.IsHemorrhage = is_hemorrhage
  3298. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  3299. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  3300. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  3301. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  3302. is_hemorrhage = 0
  3303. }
  3304. evaluation.IsHemorrhage = is_hemorrhage
  3305. if is_hemorrhage == 1 {
  3306. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  3307. hemorrhage, _ := dataBody["hemorrhage"].(string)
  3308. evaluation.Hemorrhage = hemorrhage
  3309. }
  3310. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  3311. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  3312. evaluation.HemorrhageOther = hemorrhage_other
  3313. }
  3314. }
  3315. } else {
  3316. evaluation.IsHemorrhage = 0
  3317. }
  3318. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  3319. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  3320. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  3321. }
  3322. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  3323. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  3324. evaluation.InternalFistulaOther = internal_fistula_other
  3325. }
  3326. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  3327. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  3328. evaluation.BloodAccessNoise = blood_access_noise
  3329. }
  3330. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  3331. //puncture_way := int64(dataBody["puncture_way"].(float64))
  3332. puncture_way := dataBody["puncture_way"].(string)
  3333. evaluation.PunctureWay = puncture_way
  3334. }
  3335. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  3336. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  3337. evaluation.VenousCatheterization = venous_catheterization
  3338. }
  3339. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  3340. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  3341. evaluation.VenousCatheterizationPart = venous_catheterization_part
  3342. }
  3343. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  3344. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  3345. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  3346. }
  3347. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  3348. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  3349. evaluation.DuctusArantii = ductus_arantii
  3350. }
  3351. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  3352. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  3353. evaluation.EmergencyTreatment = emergency_treatment
  3354. }
  3355. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  3356. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  3357. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  3358. }
  3359. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  3360. dialysis_count, _ := dataBody["dialysis_count"].(string)
  3361. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  3362. evaluation.DialysisCount = dialysis_count
  3363. }
  3364. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  3365. is_infect, _ := dataBody["is_infect"].(string)
  3366. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  3367. evaluation.IsInfect = infect
  3368. }
  3369. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  3370. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  3371. evaluation.Exposed = exposed
  3372. }
  3373. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  3374. skin, _ := dataBody["skin"].(string)
  3375. //skins, _ := strconv.ParseInt(skin, 10, 64)
  3376. evaluation.Skin = skin
  3377. }
  3378. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  3379. skin_other, _ := dataBody["skin_other"].(string)
  3380. evaluation.SkinOther = skin_other
  3381. }
  3382. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  3383. infect_other, _ := dataBody["infect_other"].(string)
  3384. evaluation.InfectOther = infect_other
  3385. }
  3386. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  3387. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  3388. evaluation.DuctusArantiiOther = ductus_arantii_other
  3389. }
  3390. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  3391. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  3392. evaluation.PunctureNeedle = punctureNeedle
  3393. }
  3394. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  3395. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  3396. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  3397. }
  3398. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  3399. pinholing := dataBody["pinholing"].(string)
  3400. evaluation.Phinholing = pinholing
  3401. }
  3402. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  3403. catheter_suture := dataBody["catheter_suture"].(string)
  3404. evaluation.CatheterSuture = catheter_suture
  3405. }
  3406. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  3407. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  3408. evaluation.CatheterSutureOther = catheter_suture_other
  3409. }
  3410. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  3411. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  3412. evaluation.UrineVolume = urine_volume
  3413. }
  3414. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  3415. edema := dataBody["edema"].(string)
  3416. evaluation.Edema = edema
  3417. }
  3418. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  3419. specialTreatment := dataBody["special_treatment"].(string)
  3420. evaluation.SpecialTreatment = specialTreatment
  3421. }
  3422. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  3423. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  3424. evaluation.CatheterMaintenance = catheter_maintenance
  3425. }
  3426. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  3427. thromubusType := int64(dataBody["thromubus_type"].(float64))
  3428. evaluation.ThromubusType = thromubusType
  3429. }
  3430. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  3431. thrombus_av := dataBody["thrombus_av"].(string)
  3432. evaluation.ThrombusAv = thrombus_av
  3433. }
  3434. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  3435. thromubus_a := dataBody["thromubus_a"].(string)
  3436. evaluation.ThromubusA = thromubus_a
  3437. }
  3438. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  3439. thromubus_v := dataBody["thromubus_v"].(string)
  3440. evaluation.ThromubusV = thromubus_v
  3441. }
  3442. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  3443. dehydration := dataBody["dehydration"].(string)
  3444. evaluation.Dehydration = dehydration
  3445. }
  3446. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  3447. period := int64(dataBody["period"].(float64))
  3448. evaluation.Period = period
  3449. }
  3450. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  3451. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  3452. evaluation.EstimatedFoodIntake = estimated_food_intake
  3453. }
  3454. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  3455. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  3456. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  3457. }
  3458. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  3459. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  3460. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  3461. }
  3462. if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
  3463. urea_befor := dataBody["urea_befor"].(string)
  3464. evaluation.UreaBefor = urea_befor
  3465. }
  3466. if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
  3467. suction := dataBody["suction"].(string)
  3468. evaluation.Suction = suction
  3469. }
  3470. if dataBody["weight_befor_remake"] != nil && reflect.TypeOf(dataBody["weight_befor_remake"]).String() == "string" {
  3471. weight_befor_remake := dataBody["weight_befor_remake"].(string)
  3472. evaluation.WeightBeforRemake = weight_befor_remake
  3473. }
  3474. if dataBody["height"] != nil && reflect.TypeOf(dataBody["height"]).String() == "string" {
  3475. height := dataBody["height"].(string)
  3476. evaluation.Height = height
  3477. }
  3478. if dataBody["age"] != nil && reflect.TypeOf(dataBody["age"]).String() == "string" {
  3479. age := dataBody["age"].(string)
  3480. evaluation.Age = age
  3481. }
  3482. if dataBody["his_department"] != nil && reflect.TypeOf(dataBody["his_department"]).String() == "string" {
  3483. his_department := dataBody["his_department"].(string)
  3484. evaluation.HisDepartment = his_department
  3485. }
  3486. if dataBody["his_bed"] != nil && reflect.TypeOf(dataBody["his_bed"]).String() == "string" {
  3487. his_bed := dataBody["his_bed"].(string)
  3488. evaluation.HisBed = his_bed
  3489. }
  3490. if dataBody["point_puncture"] != nil && reflect.TypeOf(dataBody["point_puncture"]).String() == "string" {
  3491. point_puncture := dataBody["point_puncture"].(string)
  3492. evaluation.PointPuncture = point_puncture
  3493. }
  3494. if dataBody["catheter_evaluation_program"] != nil && reflect.TypeOf(dataBody["catheter_evaluation_program"]).String() == "string" {
  3495. catheter_evaluation_program := dataBody["catheter_evaluation_program"].(string)
  3496. evaluation.CatheterEvaluationProgram = catheter_evaluation_program
  3497. }
  3498. if dataBody["skin_site_catheterization"] != nil && reflect.TypeOf(dataBody["skin_site_catheterization"]).String() == "string" {
  3499. skin_site_catheterization := dataBody["skin_site_catheterization"].(string)
  3500. evaluation.SkinSiteCatheterization = skin_site_catheterization
  3501. }
  3502. if dataBody["whether_unobstructed"] != nil && reflect.TypeOf(dataBody["whether_unobstructed"]).String() == "float64" {
  3503. whether_unobstructed := int64(dataBody["whether_unobstructed"].(float64))
  3504. evaluation.WhetherUnobstructed = whether_unobstructed
  3505. }
  3506. if dataBody["lien_necessary"] != nil && reflect.TypeOf(dataBody["lien_necessary"]).String() == "float64" {
  3507. lien_necessary := int64(dataBody["lien_necessary"].(float64))
  3508. evaluation.LienNecessary = lien_necessary
  3509. }
  3510. if dataBody["pathway_formation_time"] != nil && reflect.TypeOf(dataBody["pathway_formation_time"]).String() == "string" {
  3511. pathway_formation_time := dataBody["pathway_formation_time"].(string)
  3512. timeLayout := "2006-01-02"
  3513. loc, _ := time.LoadLocation("Local")
  3514. var startTime int64
  3515. if len(pathway_formation_time) > 0 {
  3516. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  3517. startTime = theTime.Unix()
  3518. }
  3519. evaluation.PathwayFormationTime = startTime
  3520. }
  3521. if dataBody["befor_symptoms"] != nil && reflect.TypeOf(dataBody["befor_symptoms"]).String() == "string" {
  3522. befor_symptoms := dataBody["befor_symptoms"].(string)
  3523. evaluation.BeforSymptoms = befor_symptoms
  3524. }
  3525. if dataBody["washing_time"] != nil && reflect.TypeOf(dataBody["washing_time"]).String() == "string" {
  3526. washing_time, _ := dataBody["washing_time"].(string)
  3527. evaluation.WashingTime = washing_time
  3528. }
  3529. if dataBody["warsh_count"] != nil && reflect.TypeOf(dataBody["warsh_count"]).String() == "string" {
  3530. warsh_count, _ := dataBody["warsh_count"].(string)
  3531. evaluation.WarshCount = warsh_count
  3532. }
  3533. if dataBody["puncture_needle_direction"] != nil && reflect.TypeOf(dataBody["puncture_needle_direction"]).String() == "string" {
  3534. puncture_needle_direction, _ := dataBody["puncture_needle_direction"].(string)
  3535. evaluation.PunctureNeedleDirection = puncture_needle_direction
  3536. }
  3537. if dataBody["symptom_before_dialysis_other"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis_other"]).String() == "string" {
  3538. symptom_before_dialysis_other, _ := dataBody["symptom_before_dialysis_other"].(string)
  3539. evaluation.SymptomBeforeDialysisOther = symptom_before_dialysis_other
  3540. }
  3541. return
  3542. }
  3543. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  3544. dataBody := make(map[string]interface{}, 0)
  3545. err := json.Unmarshal(data, &dataBody)
  3546. if err != nil {
  3547. utils.ErrorLog(err.Error())
  3548. code = enums.ErrorCodeParamWrong
  3549. return
  3550. }
  3551. timeLayout := "2006-01-02"
  3552. loc, _ := time.LoadLocation("Local")
  3553. isChild := false
  3554. if action == "create" {
  3555. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3556. utils.ErrorLog("advice_type")
  3557. code = enums.ErrorCodeParamWrong
  3558. return
  3559. }
  3560. adviceType := int64(dataBody["advice_type"].(float64))
  3561. if adviceType != 1 && adviceType != 2 {
  3562. utils.ErrorLog("advice_type != 1&&2")
  3563. code = enums.ErrorCodeParamWrong
  3564. return
  3565. }
  3566. advice.AdviceType = adviceType
  3567. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3568. utils.ErrorLog("advice_date")
  3569. code = enums.ErrorCodeParamWrong
  3570. return
  3571. }
  3572. adviceDate, _ := dataBody["advice_date"].(string)
  3573. if len(adviceDate) == 0 {
  3574. utils.ErrorLog("len(adviceDate) == 0")
  3575. code = enums.ErrorCodeParamWrong
  3576. return
  3577. }
  3578. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3579. if err != nil {
  3580. utils.ErrorLog(err.Error())
  3581. code = enums.ErrorCodeParamWrong
  3582. return
  3583. }
  3584. advice.AdviceDate = theTime.Unix()
  3585. advice.RecordDate = theTime.Unix()
  3586. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  3587. parentId := int64(dataBody["parent_id"].(float64))
  3588. advice.ParentId = parentId
  3589. if parentId > 0 {
  3590. isChild = true
  3591. }
  3592. }
  3593. } else {
  3594. isChild = advice.ParentId > 0
  3595. }
  3596. if !isChild {
  3597. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3598. utils.ErrorLog("start_time")
  3599. code = enums.ErrorCodeParamWrong
  3600. return
  3601. }
  3602. startTime, _ := dataBody["start_time"].(string)
  3603. if len(startTime) == 0 {
  3604. utils.ErrorLog("len(start_time) == 0")
  3605. code = enums.ErrorCodeParamWrong
  3606. return
  3607. }
  3608. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  3609. if err != nil {
  3610. utils.ErrorLog(err.Error())
  3611. code = enums.ErrorCodeParamWrong
  3612. return
  3613. }
  3614. advice.StartTime = theTime.Unix()
  3615. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3616. deliveryWay, _ := dataBody["delivery_way"].(string)
  3617. advice.DeliveryWay = deliveryWay
  3618. }
  3619. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3620. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3621. advice.ExecutionFrequency = executionFrequency
  3622. }
  3623. }
  3624. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3625. deliveryWay, _ := dataBody["delivery_way"].(string)
  3626. advice.DeliveryWay = deliveryWay
  3627. }
  3628. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3629. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3630. advice.ExecutionFrequency = executionFrequency
  3631. }
  3632. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3633. utils.ErrorLog("advice_name")
  3634. code = enums.ErrorCodeParamWrong
  3635. return
  3636. }
  3637. adviceName, _ := dataBody["advice_name"].(string)
  3638. if len(adviceName) == 0 {
  3639. utils.ErrorLog("len(advice_name) == 0")
  3640. code = enums.ErrorCodeParamWrong
  3641. return
  3642. }
  3643. advice.AdviceName = adviceName
  3644. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3645. adviceDsc, _ := dataBody["advice_desc"].(string)
  3646. advice.AdviceDesc = adviceDsc
  3647. }
  3648. if dataBody["way"] == nil {
  3649. advice.Way = 0
  3650. } else {
  3651. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  3652. way := int64(dataBody["way"].(float64))
  3653. advice.Way = way
  3654. }
  3655. }
  3656. if dataBody["drug_id"] == nil {
  3657. advice.DrugId = 0
  3658. } else {
  3659. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  3660. drug_id := int64(dataBody["drug_id"].(float64))
  3661. advice.DrugId = drug_id
  3662. }
  3663. }
  3664. if dataBody["drug_name_id"] == nil {
  3665. advice.DrugNameId = 0
  3666. } else {
  3667. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  3668. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  3669. advice.DrugNameId = drug_name_id
  3670. }
  3671. }
  3672. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3673. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3674. advice.SingleDose = singleDose
  3675. }
  3676. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3677. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3678. advice.SingleDoseUnit = singleDoseUnit
  3679. }
  3680. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  3681. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  3682. advice.DrugSpec = drugSpec
  3683. }
  3684. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3685. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3686. advice.DrugSpecUnit = drugSpecUnit
  3687. }
  3688. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3689. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3690. advice.PrescribingNumber = prescribingNumber
  3691. }
  3692. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3693. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3694. advice.PrescribingNumberUnit = prescribingNumberUnit
  3695. }
  3696. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3697. remark, _ := dataBody["remark"].(string)
  3698. advice.Remark = remark
  3699. }
  3700. return
  3701. }
  3702. func (c *PatientApiController) GetPatientEducation() {
  3703. patientID, _ := c.GetInt64("patient_id", 0)
  3704. page, _ := c.GetInt64("page", 0)
  3705. limit, _ := c.GetInt64("limit", 0)
  3706. startTime := c.GetString("start_time", "")
  3707. endTime := c.GetString("end_time", "")
  3708. if page <= 0 {
  3709. page = 1
  3710. }
  3711. if limit <= 0 {
  3712. limit = 10
  3713. }
  3714. if patientID <= 0 {
  3715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3716. return
  3717. }
  3718. timeLayout := "2006-01-02"
  3719. loc, _ := time.LoadLocation("Local")
  3720. var theStartTIme int64
  3721. if len(startTime) > 0 {
  3722. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3723. if err != nil {
  3724. theStartTIme = 0
  3725. }
  3726. theStartTIme = theTime.Unix()
  3727. }
  3728. var theEndtTIme int64
  3729. if len(endTime) > 0 {
  3730. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3731. if err != nil {
  3732. theEndtTIme = 0
  3733. }
  3734. theEndtTIme = theTime.Unix()
  3735. }
  3736. adminUserInfo := c.GetMobileAdminUserInfo()
  3737. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  3738. c.ServeSuccessJSON(map[string]interface{}{
  3739. "total": total,
  3740. "edus": edus,
  3741. })
  3742. return
  3743. }
  3744. func (c *PatientApiController) GetPatientSchedulesList() {
  3745. patientID, _ := c.GetInt64("patient_id", 0)
  3746. page, _ := c.GetInt64("page", 0)
  3747. limit, _ := c.GetInt64("limit", 0)
  3748. if patientID <= 0 {
  3749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3750. return
  3751. }
  3752. adminUserInfo := c.GetMobileAdminUserInfo()
  3753. todayTime := time.Now().Format("2006-01-02")
  3754. timeLayout := "2006-01-02 15:04:05"
  3755. loc, _ := time.LoadLocation("Local")
  3756. var theStartTime int64
  3757. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  3758. theStartTime = theTime.Unix()
  3759. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  3760. if len(schedules) > 0 {
  3761. for index, item := range schedules {
  3762. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  3763. schedules[index].Week = int64(week)
  3764. }
  3765. }
  3766. c.ServeSuccessJSON(map[string]interface{}{
  3767. "schedules": schedules,
  3768. })
  3769. return
  3770. }
  3771. func (c *PatientApiController) GetRecords() {
  3772. patientID, _ := c.GetInt64("patient_id", 0)
  3773. page, _ := c.GetInt64("page", 0)
  3774. limit, _ := c.GetInt64("limit", 0)
  3775. startTime := c.GetString("start_time", "")
  3776. endTime := c.GetString("end_time", "")
  3777. mode_id, _ := c.GetInt64("mode_id", 0)
  3778. if page <= 0 {
  3779. page = 1
  3780. }
  3781. if limit <= 0 {
  3782. limit = 10
  3783. }
  3784. if patientID <= 0 {
  3785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3786. return
  3787. }
  3788. timeLayout := "2006-01-02"
  3789. loc, _ := time.LoadLocation("Local")
  3790. var theStartTIme int64
  3791. if len(startTime) > 0 {
  3792. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3793. if err != nil {
  3794. theStartTIme = 0
  3795. }
  3796. theStartTIme = theTime.Unix()
  3797. }
  3798. var theEndtTIme int64
  3799. if len(endTime) > 0 {
  3800. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3801. if err != nil {
  3802. theEndtTIme = 0
  3803. }
  3804. theEndtTIme = theTime.Unix()
  3805. }
  3806. adminUserInfo := c.GetMobileAdminUserInfo()
  3807. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  3808. c.ServeSuccessJSON(map[string]interface{}{
  3809. "total": total,
  3810. "records": records,
  3811. })
  3812. return
  3813. }
  3814. func (c *PatientApiController) GetPatientMonitor() {
  3815. partition, _ := c.GetInt64("partition")
  3816. monitorDate := c.GetString("date")
  3817. patient_id, _ := c.GetInt64("patient_id")
  3818. timeLayout := "2006-01-02"
  3819. loc, _ := time.LoadLocation("Local")
  3820. var theStartTime int64
  3821. if len(monitorDate) > 0 {
  3822. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  3823. if err != nil {
  3824. theStartTime = 0
  3825. }
  3826. theStartTime = theTime.Unix()
  3827. }
  3828. adminInfo := c.GetMobileAdminUserInfo()
  3829. orgID := adminInfo.Org.Id
  3830. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  3831. if err != nil {
  3832. c.ErrorLog("获取排班信息失败:%v", err)
  3833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3834. } else {
  3835. if len(monitor) > 0 {
  3836. //获取所有床位
  3837. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  3838. //获取所有分区
  3839. zoneList, _ := service.GetAllZoneByList(orgID)
  3840. //获取透析处方
  3841. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  3842. //获取透前评估
  3843. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  3844. //获取上机
  3845. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  3846. //获取透后
  3847. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  3848. //获取透后监测
  3849. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  3850. //获取所有的患者
  3851. patients, _ := service.GetAllPatientListByListOne(orgID)
  3852. for _, it := range patients {
  3853. if orgID == 10445 {
  3854. if theStartTime <= 1703952000 {
  3855. listOne, _ := service.GetDialysisOrderCountTwentyEight(orgID, it.ID, theStartTime)
  3856. it.TotalDialysis = listOne.Count
  3857. }
  3858. if theStartTime >= 1704038400 {
  3859. listOrder, _ := service.GetDialysisOrderCountTenEight(it.ID, theStartTime)
  3860. it.TotalDialysis = listOrder.Count
  3861. }
  3862. }
  3863. }
  3864. //获取所有透析模式
  3865. treatments, _ := service.GetAllTreatModeByList(orgID)
  3866. for key, item := range monitor {
  3867. // 获取床位信息
  3868. for _, it := range numberList {
  3869. if item.BedId == it.ID {
  3870. monitor[key].DeviceNumber = it
  3871. break
  3872. }
  3873. }
  3874. //获取分区信息
  3875. for _, it := range zoneList {
  3876. if item.PartitionId == it.ID {
  3877. monitor[key].DeviceZone = it
  3878. }
  3879. }
  3880. for _, prescription := range prescriptions {
  3881. if item.PatientId == prescription.PatientId {
  3882. monitor[key].Prescription = prescription
  3883. break
  3884. }
  3885. }
  3886. // 透前评估
  3887. for _, assessmentBefore := range assessmentBefores {
  3888. if item.PatientId == assessmentBefore.PatientId {
  3889. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  3890. break
  3891. }
  3892. }
  3893. // 透析上下机
  3894. for _, dialysisOrder := range dialysisOrders {
  3895. if item.PatientId == dialysisOrder.PatientId {
  3896. monitor[key].DialysisOrder = dialysisOrder
  3897. break
  3898. }
  3899. }
  3900. // 治疗小节
  3901. for _, afterDislysis := range AssessmentAfterDislysis {
  3902. if item.PatientId == afterDislysis.PatientId {
  3903. monitor[key].AssessmentAfterDislysis = afterDislysis
  3904. break
  3905. }
  3906. }
  3907. for _, it := range monitorlist {
  3908. if item.PatientId == it.PatientId {
  3909. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  3910. }
  3911. }
  3912. for _, patient := range patients {
  3913. if item.PatientId == patient.ID {
  3914. monitor[key].MonitorPatients = patient
  3915. break
  3916. }
  3917. }
  3918. for _, treatment := range treatments {
  3919. if item.ModeId == treatment.ID {
  3920. monitor[key].TreatmentMode = treatment
  3921. break
  3922. }
  3923. }
  3924. }
  3925. }
  3926. }
  3927. //获取患者的透析次数
  3928. //count, err := service.GetDialysisCount(orgID, partition)
  3929. patients, err := service.GetAllpatientFourty(orgID)
  3930. if err == nil {
  3931. c.ServeSuccessJSON(map[string]interface{}{
  3932. "monitor": monitor,
  3933. //"patientCount": count,
  3934. "patients": patients,
  3935. })
  3936. } else {
  3937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3938. }
  3939. }
  3940. // /m/api/monitor/patient [get] 搜索病人的测量记录
  3941. // @param keyword:string 病人姓名或透析号
  3942. // @param page:int
  3943. func (this *PatientApiController) SearchMonitorPatient() {
  3944. keyword := this.GetString("keyword")
  3945. page, _ := this.GetInt("page")
  3946. if page <= 0 {
  3947. page = 1
  3948. }
  3949. if len(keyword) == 0 {
  3950. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3951. return
  3952. }
  3953. adminUserInfo := this.GetMobileAdminUserInfo()
  3954. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  3955. if getMonitorErr != nil {
  3956. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3957. return
  3958. } else {
  3959. this.ServeSuccessJSON(map[string]interface{}{
  3960. "monitor": monitors,
  3961. })
  3962. }
  3963. }
  3964. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  3965. id, _ := c.GetInt64("id", 0)
  3966. page, _ := c.GetInt64("page", 0)
  3967. limit, _ := c.GetInt64("limit", 0)
  3968. if id <= 0 {
  3969. c.ServeSuccessJSON(map[string]interface{}{
  3970. "solutions": nil,
  3971. })
  3972. return
  3973. }
  3974. if page <= 0 {
  3975. page = 1
  3976. }
  3977. if limit <= 0 {
  3978. limit = 10
  3979. }
  3980. adminInfo := c.GetMobileAdminUserInfo()
  3981. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  3982. c.ServeSuccessJSON(map[string]interface{}{
  3983. "solutions": solutions,
  3984. "total": total,
  3985. })
  3986. return
  3987. }
  3988. // GetDoctorAdvices 医嘱列表
  3989. func (c *PatientApiController) GetDoctorAdvices() {
  3990. id, _ := c.GetInt64("id", 0)
  3991. adviceType, _ := c.GetInt64("advice_type", 0)
  3992. stopType, _ := c.GetInt64("stop_state", 0)
  3993. startTime := c.GetString("start_time", "")
  3994. endTime := c.GetString("end_time", "")
  3995. keywords := c.GetString("keywords", "")
  3996. need, _ := c.GetInt64("need_doctor", 0)
  3997. adminUserInfo := c.GetMobileAdminUserInfo()
  3998. timeLayout := "2006-01-02"
  3999. loc, _ := time.LoadLocation("Local")
  4000. var theStartTIme int64
  4001. if len(startTime) > 0 {
  4002. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4003. if err != nil {
  4004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4005. return
  4006. }
  4007. theStartTIme = theTime.Unix()
  4008. }
  4009. var theEndtTIme int64
  4010. if len(endTime) > 0 {
  4011. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4012. if err != nil {
  4013. utils.ErrorLog(err.Error())
  4014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4015. return
  4016. }
  4017. theEndtTIme = theTime.Unix()
  4018. }
  4019. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  4020. if need == 1 {
  4021. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4022. c.ServeSuccessJSON(map[string]interface{}{
  4023. "advices": advices,
  4024. "total": total,
  4025. "users": users,
  4026. })
  4027. } else {
  4028. c.ServeSuccessJSON(map[string]interface{}{
  4029. "advices": advices,
  4030. "total": total,
  4031. "users": []string{},
  4032. })
  4033. }
  4034. return
  4035. }
  4036. func (c *PatientApiController) GetPrintDialysisOrder() {
  4037. xtno := c.GetString("xtno")
  4038. xtdate := c.GetString("xtdate")
  4039. timeLayout := "2006-01-02"
  4040. loc, _ := time.LoadLocation("Local")
  4041. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  4042. if err != nil {
  4043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4044. return
  4045. }
  4046. xttime := theTime.Unix()
  4047. //获取当前日期月份的第一天
  4048. firstmonth := service.GetFirstDateOfMonth(theTime)
  4049. firstMonthDate := firstmonth.Unix()
  4050. operatorIDs := make([]int64, 0)
  4051. adminUserInfo := c.GetMobileAdminUserInfo()
  4052. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4053. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  4054. //透析单
  4055. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4056. if dialysisOrder != nil {
  4057. if dialysisOrder.FinishNurse > 0 {
  4058. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  4059. }
  4060. if dialysisOrder.StartNurse > 0 {
  4061. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  4062. }
  4063. }
  4064. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4065. //透前评估
  4066. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4067. //透后评估
  4068. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4069. if AssessmentAfterDislysis.Modifier > 0 {
  4070. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  4071. }
  4072. //透析处方
  4073. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4074. if dialysisPrescription.PrescriptionDoctor > 0 {
  4075. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  4076. }
  4077. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4078. patientInfo.TotalDialysis = dialysis_count
  4079. //临时医嘱
  4080. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4081. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4082. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  4083. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  4084. lastSchedule, _ := service.FindLastSchedule(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4085. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4086. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  4087. for _, item := range projects {
  4088. cnt, _ := strconv.ParseFloat(item.Count, 64)
  4089. var advice models.HisDoctorAdviceInfo
  4090. advice.ID = item.ID
  4091. advice.Checker = item.Checker
  4092. advice.CheckTime = item.CheckTime
  4093. advice.CheckState = item.CheckState
  4094. advice.ExecutionState = item.ExecutionState
  4095. advice.ExecutionStaff = item.ExecutionStaff
  4096. //advice.PrescribingNumber = float64(item.Count)
  4097. advice.PrescribingNumber = cnt
  4098. advice.PrescribingNumberUnit = item.Unit
  4099. advice.AdviceDoctor = item.Doctor
  4100. if item.Type == 3 {
  4101. advice.AdviceName = item.GoodInfo.GoodName
  4102. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  4103. } else if item.Type == 2 {
  4104. advice.AdviceName = item.HisProject.ProjectName
  4105. }
  4106. advice.StartTime = item.StartTime
  4107. hisAdvice = append(hisAdvice, &advice)
  4108. }
  4109. }
  4110. if len(DoctorAdvice) > 0 {
  4111. for _, item := range DoctorAdvice {
  4112. if item.AdviceDoctor > 0 {
  4113. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  4114. }
  4115. if item.ExecutionStaff > 0 {
  4116. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  4117. }
  4118. if item.Checker > 0 {
  4119. operatorIDs = append(operatorIDs, item.Checker)
  4120. }
  4121. }
  4122. }
  4123. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4124. //透析监测
  4125. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4126. //透析小结
  4127. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4128. //接诊评估
  4129. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4130. //相关操作对应的操作人
  4131. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  4132. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  4133. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4134. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4135. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  4136. lastWeight, _ := service.MobileGetLast(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4137. if config.IsOpen == 1 {
  4138. c.ServeSuccessJSON(map[string]interface{}{
  4139. "users": adminUser,
  4140. "patientInfo": patientInfo,
  4141. "PredialysisEvaluation": PredialysisEvaluation,
  4142. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4143. "dialysisPrescription": dialysisPrescription,
  4144. "advices": hisAdvice,
  4145. "monitors": Record,
  4146. "summary": TreatmentSummary,
  4147. "receiverTreatmentAccess": receiverTreatmentAccess,
  4148. "dialysisOrder": dialysisOrder,
  4149. "operators": operators,
  4150. "org_template_info": templateInfo,
  4151. "check": check,
  4152. "dialysiscount": dialysiscount,
  4153. "last_order": last_order,
  4154. "projects": projects,
  4155. "project_config": project_config,
  4156. "lastWeight": lastWeight,
  4157. "lastSchedule": lastSchedule,
  4158. })
  4159. }
  4160. if config.IsOpen == 0 || config.IsOpen == 2 {
  4161. c.ServeSuccessJSON(map[string]interface{}{
  4162. "users": adminUser,
  4163. "patientInfo": patientInfo,
  4164. "PredialysisEvaluation": PredialysisEvaluation,
  4165. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4166. "dialysisPrescription": dialysisPrescription,
  4167. "advices": DoctorAdvice,
  4168. "monitors": Record,
  4169. "summary": TreatmentSummary,
  4170. "receiverTreatmentAccess": receiverTreatmentAccess,
  4171. "dialysisOrder": dialysisOrder,
  4172. "operators": operators,
  4173. "org_template_info": templateInfo,
  4174. "check": check,
  4175. "dialysiscount": dialysiscount,
  4176. "last_order": last_order,
  4177. "projects": projects,
  4178. "project_config": project_config,
  4179. "lastWeight": lastWeight,
  4180. "lastSchedule": lastSchedule,
  4181. })
  4182. }
  4183. }
  4184. func (c *PatientApiController) CreateGroupAdvice() {
  4185. is_child, _ := c.GetInt64("is_child", 0)
  4186. if is_child == 1 {
  4187. patient, _ := c.GetInt64("id", 0)
  4188. if patient <= 0 {
  4189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4190. return
  4191. }
  4192. adminUserInfo := c.GetMobileAdminUserInfo()
  4193. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  4194. if patientInfo.ID == 0 {
  4195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4196. return
  4197. }
  4198. group_no, _ := c.GetInt64("group_no")
  4199. if group_no <= 0 {
  4200. group_no = 0
  4201. }
  4202. dataBody := make(map[string]interface{}, 0)
  4203. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4204. if err != nil {
  4205. utils.ErrorLog(err.Error())
  4206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4207. return
  4208. }
  4209. timeLayout := "2006-01-02"
  4210. loc, _ := time.LoadLocation("Local")
  4211. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4212. utils.ErrorLog("advice_type")
  4213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4214. return
  4215. }
  4216. adviceType := int64(dataBody["advice_type"].(float64))
  4217. if adviceType != 1 && adviceType != 2 {
  4218. utils.ErrorLog("advice_type != 1&&2")
  4219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4220. return
  4221. }
  4222. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4223. utils.ErrorLog("start_time")
  4224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4225. return
  4226. }
  4227. startTime2, _ := dataBody["start_time"].(string)
  4228. time_arr := strings.Split(startTime2, " ")
  4229. if len(time_arr) > 0 {
  4230. startTime2 = time_arr[0]
  4231. }
  4232. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4233. utils.ErrorLog("advice_date")
  4234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4235. return
  4236. }
  4237. advice_date, _ := dataBody["advice_date"].(string)
  4238. var advicedateunix int64
  4239. if len(advice_date) > 0 {
  4240. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  4241. if err != nil {
  4242. fmt.Println(err)
  4243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4244. return
  4245. }
  4246. advicedateunix = theTime.Unix()
  4247. }
  4248. adviceDate := startTime2
  4249. if len(adviceDate) == 0 {
  4250. utils.ErrorLog("len(adviceDate) == 0")
  4251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4252. return
  4253. }
  4254. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4255. if err != nil {
  4256. utils.ErrorLog(err.Error())
  4257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4258. return
  4259. }
  4260. AdviceDate := advicedateunix
  4261. RecordDate := advicedateunix
  4262. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4263. utils.ErrorLog("start_time")
  4264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4265. return
  4266. }
  4267. startTime, _ := dataBody["start_time"].(string)
  4268. if len(startTime) == 0 {
  4269. utils.ErrorLog("len(start_time) == 0")
  4270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4271. return
  4272. }
  4273. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  4274. theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
  4275. if err != nil {
  4276. utils.ErrorLog(err.Error())
  4277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4278. return
  4279. }
  4280. StartTime := theTime.Unix()
  4281. Remark := ""
  4282. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4283. remark, _ := dataBody["remark"].(string)
  4284. Remark = remark
  4285. }
  4286. Startdate := int64(dataBody["record_date"].(float64))
  4287. var advices []*models.GroupAdvice
  4288. // utils.TraceLog("%+v", dataBody["adviceNames"])
  4289. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  4290. utils.ErrorLog("adviceNames")
  4291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4292. return
  4293. }
  4294. adviceNames := dataBody["adviceNames"].([]interface{})
  4295. for _, adviceNameMap := range adviceNames {
  4296. adviceNameM := adviceNameMap.(map[string]interface{})
  4297. var advice models.GroupAdvice
  4298. advice.Remark = Remark
  4299. advice.AdviceType = adviceType
  4300. advice.StartTime = StartTime
  4301. if adminUserInfo.Org.Id == 10340 {
  4302. advice.AdviceDate = AdviceDate
  4303. advice.RecordDate = RecordDate
  4304. }
  4305. if adminUserInfo.Org.Id != 10340 {
  4306. advice.AdviceDate = theTimeOne.Unix()
  4307. advice.RecordDate = theTimeOne.Unix()
  4308. }
  4309. advice.Status = 1
  4310. advice.CreatedTime = time.Now().Unix()
  4311. advice.UpdatedTime = time.Now().Unix()
  4312. advice.StopState = 2
  4313. advice.ExecutionState = 2
  4314. advice.UserOrgId = adminUserInfo.Org.Id
  4315. advice.PatientId = patientInfo.ID
  4316. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4317. advice.IsSettle = 2
  4318. //入口
  4319. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  4320. if errcode > 0 {
  4321. c.ServeFailJSONWithSGJErrorCode(errcode)
  4322. return
  4323. }
  4324. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  4325. subdrugs := adviceNameM["subdrugs"].([]interface{})
  4326. if len(subdrugs) > 0 {
  4327. for _, subdrug := range subdrugs {
  4328. var s models.GroupAdvice
  4329. s.Remark = Remark
  4330. s.AdviceType = adviceType
  4331. s.StartTime = StartTime
  4332. s.AdviceDate = AdviceDate
  4333. s.RecordDate = RecordDate
  4334. s.Status = 1
  4335. s.CreatedTime = time.Now().Unix()
  4336. s.UpdatedTime = time.Now().Unix()
  4337. s.StopState = 2
  4338. s.ExecutionState = 2
  4339. s.UserOrgId = adminUserInfo.Org.Id
  4340. s.PatientId = patientInfo.ID
  4341. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  4342. s.IsSettle = 2
  4343. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  4344. if errcode > 0 {
  4345. c.ServeFailJSONWithSGJErrorCode(errcode)
  4346. return
  4347. }
  4348. advice.Children = append(advice.Children, &s)
  4349. }
  4350. }
  4351. }
  4352. //长沙南雅
  4353. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  4354. //查询该患者今日有没有双人核对
  4355. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, RecordDate)
  4356. if check.ID > 0 {
  4357. advice.Checker = check.Modifier
  4358. advice.CheckState = 1
  4359. advice.CheckTime = time.Now().Unix()
  4360. }
  4361. }
  4362. advices = append(advices, &advice)
  4363. }
  4364. // 查询信息规挡的设置天数
  4365. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4366. if infor.ID > 0 && infor.WeekDay > 0 {
  4367. var cha_time int64
  4368. timeNowStr := time.Now().Format("2006-01-02")
  4369. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4370. //今日的日期减去设置的日期
  4371. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4372. if cha_time >= Startdate {
  4373. //查询审核是否允许
  4374. infor, _ := service.GetDialysisInformationByRecordDate(patient, Startdate, adminUserInfo.Org.Id, 5)
  4375. //申请状态不允许的情况 拒绝修改
  4376. if infor.ApplicationStatus != 1 {
  4377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4378. return
  4379. }
  4380. }
  4381. }
  4382. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  4383. for _, item := range advices {
  4384. //记录日志
  4385. byterequest, _ := json.Marshal(item)
  4386. adviceLog := models.XtDoctorAdviceLog{
  4387. UserOrgId: item.UserOrgId,
  4388. PatientId: item.PatientId,
  4389. AdminUserId: adminUserInfo.AdminUser.Id,
  4390. Module: 1,
  4391. ErrLog: string(byterequest),
  4392. Status: 1,
  4393. Ctime: time.Now().Unix(),
  4394. Mtime: 0,
  4395. Source: "手机端新增医嘱",
  4396. RecordDate: item.AdviceDate,
  4397. }
  4398. service.CreateDoctorAdviceLog(adviceLog)
  4399. }
  4400. finish := models.XtDialysisFinish{
  4401. IsFinish: 1,
  4402. UserOrgId: adminUserInfo.Org.Id,
  4403. Status: 1,
  4404. Ctime: time.Now().Unix(),
  4405. Mtime: 0,
  4406. Module: 4,
  4407. RecordDate: advicedateunix,
  4408. Sourse: 1,
  4409. PatientId: patient,
  4410. }
  4411. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, advicedateunix, 4, patient)
  4412. if dialysisFinish.ID == 0 {
  4413. service.CreateDialysisFinish(finish)
  4414. }
  4415. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  4416. redis := service.RedisClient()
  4417. //清空key 值
  4418. redis.Set(key, "", time.Second)
  4419. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4420. redis.Set(keyOne, "", time.Second)
  4421. defer redis.Close()
  4422. if createErr != nil {
  4423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4424. return
  4425. }
  4426. c.ServeSuccessJSON(map[string]interface{}{
  4427. "msg": "ok",
  4428. "advices": newAdvices,
  4429. })
  4430. return
  4431. } else if is_child == 2 {
  4432. patient, _ := c.GetInt64("id", 0)
  4433. if patient <= 0 {
  4434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4435. return
  4436. }
  4437. adminUserInfo := c.GetMobileAdminUserInfo()
  4438. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  4439. if patientInfo.ID == 0 {
  4440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4441. return
  4442. }
  4443. var advice models.DoctorAdvice
  4444. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  4445. if code > 0 {
  4446. c.ServeFailJSONWithSGJErrorCode(code)
  4447. return
  4448. }
  4449. if advice.ParentId > 0 {
  4450. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  4451. if old.ID == 0 || old.PatientId != patient {
  4452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  4453. return
  4454. }
  4455. if old.StopState == 1 || old.ExecutionState == 1 {
  4456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  4457. return
  4458. }
  4459. if old.ParentId > 0 {
  4460. advice.ParentId = old.ParentId
  4461. }
  4462. advice.StartTime = old.StartTime
  4463. advice.AdviceDoctor = old.AdviceDoctor
  4464. advice.DeliveryWay = old.DeliveryWay
  4465. advice.ExecutionFrequency = old.ExecutionFrequency
  4466. advice.GroupNo = old.GroupNo
  4467. }
  4468. advice.Status = 1
  4469. advice.CreatedTime = time.Now().Unix()
  4470. advice.UpdatedTime = time.Now().Unix()
  4471. advice.StopState = 2
  4472. advice.ExecutionState = 2
  4473. advice.UserOrgId = adminUserInfo.Org.Id
  4474. advice.PatientId = patient
  4475. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4476. advice.IsSettle = 2
  4477. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  4478. if advice.PrescribingNumber == 0 {
  4479. advice.PrescribingNumber = 1
  4480. }
  4481. //查询该患者今日有没有双人核对
  4482. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, advice.AdviceDate)
  4483. if check.ID > 0 {
  4484. advice.Checker = check.Modifier
  4485. advice.CheckState = 1
  4486. advice.CheckTime = time.Now().Unix()
  4487. }
  4488. }
  4489. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4490. if infor.ID > 0 {
  4491. var cha_time int64
  4492. timeNowStr := time.Now().Format("2006-01-02")
  4493. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4494. //今日的日期减去设置的日期
  4495. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4496. if cha_time >= advice.RecordDate {
  4497. //查询审核是否允许
  4498. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.RecordDate, adminUserInfo.Org.Id, 4)
  4499. //申请状态不允许的情况 拒绝修改
  4500. if infor.ApplicationStatus != 1 {
  4501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4502. return
  4503. }
  4504. }
  4505. }
  4506. err := service.CreateDoctorAdvice(&advice)
  4507. //记录日志
  4508. byterequest, _ := json.Marshal(advice)
  4509. adviceLog := models.XtDoctorAdviceLog{
  4510. UserOrgId: advice.UserOrgId,
  4511. PatientId: advice.PatientId,
  4512. AdminUserId: adminUserInfo.Org.Id,
  4513. Module: 1,
  4514. ErrLog: string(byterequest),
  4515. Status: 1,
  4516. Ctime: time.Now().Unix(),
  4517. Mtime: 0,
  4518. Source: "手机端新增医嘱",
  4519. RecordDate: advice.AdviceDate,
  4520. }
  4521. service.CreateDoctorAdviceLog(adviceLog)
  4522. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  4523. redis := service.RedisClient()
  4524. //清空key 值
  4525. redis.Set(key, "", time.Second)
  4526. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  4527. redis.Set(keyOne, "", time.Second)
  4528. defer redis.Close()
  4529. if err != nil {
  4530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4531. return
  4532. }
  4533. c.ServeSuccessJSON(map[string]interface{}{
  4534. "msg": "ok",
  4535. "advice": advice,
  4536. })
  4537. return
  4538. }
  4539. }
  4540. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  4541. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  4542. utils.ErrorLog("advice_name")
  4543. return enums.ErrorCodeParamWrong
  4544. }
  4545. adviceName, _ := json["advice_name"].(string)
  4546. if len(adviceName) == 0 {
  4547. utils.ErrorLog("len(advice_name) == 0")
  4548. return enums.ErrorCodeParamWrong
  4549. }
  4550. advice.AdviceName = adviceName
  4551. adviceDesc, _ := json["advice_desc"].(string)
  4552. advice.AdviceDesc = adviceDesc
  4553. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4554. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4555. advice.DrugSpec = drugSpec
  4556. }
  4557. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4558. remark, _ := json["remark"].(string)
  4559. advice.Remark = remark
  4560. }
  4561. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  4562. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  4563. // advice.Way = src_type
  4564. //}
  4565. if json["way"] == nil {
  4566. advice.Way = 0
  4567. } else {
  4568. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  4569. way := int64(json["way"].(float64))
  4570. advice.Way = way
  4571. }
  4572. }
  4573. if json["drug_id"] == nil {
  4574. advice.DrugId = 0
  4575. } else {
  4576. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  4577. drug_id := int64(json["drug_id"].(float64))
  4578. advice.DrugId = drug_id
  4579. }
  4580. }
  4581. if json["drug_name_id"] == nil {
  4582. advice.DrugNameId = 0
  4583. } else {
  4584. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  4585. drug_name_id := int64(json["drug_name_id"].(float64))
  4586. advice.DrugNameId = drug_name_id
  4587. }
  4588. }
  4589. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  4590. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  4591. advice.DrugSpecUnit = drugSpecUnit
  4592. }
  4593. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4594. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4595. advice.SingleDose = singleDose
  4596. }
  4597. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4598. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4599. advice.SingleDoseUnit = singleDoseUnit
  4600. }
  4601. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4602. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4603. advice.PrescribingNumber = prescribingNumber
  4604. }
  4605. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4606. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4607. advice.PrescribingNumberUnit = prescribingNumberUnit
  4608. }
  4609. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4610. deliveryWay, _ := json["delivery_way"].(string)
  4611. advice.DeliveryWay = deliveryWay
  4612. }
  4613. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4614. executionFrequency, _ := json["execution_frequency"].(string)
  4615. advice.ExecutionFrequency = executionFrequency
  4616. }
  4617. return 0
  4618. }
  4619. func (c *PatientApiController) DelDoctorAdvice() {
  4620. groupno, _ := c.GetInt64("groupno", -1)
  4621. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  4622. patient_id, _ := c.GetInt64("patient_id")
  4623. doc_advice_date, _ := c.GetInt64("advice_date")
  4624. redis := service.RedisClient()
  4625. if is_sub == 1 { //是
  4626. advice_id, _ := c.GetInt64("advice_id")
  4627. adminUserInfo := c.GetMobileAdminUserInfo()
  4628. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  4629. if advice.ID == 0 {
  4630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4631. return
  4632. }
  4633. advice.Status = 0
  4634. advice.UpdatedTime = time.Now().Unix()
  4635. advice.Modifier = adminUserInfo.AdminUser.Id
  4636. // 查询信息规挡的设置天数
  4637. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4638. if infor.ID > 0 && infor.WeekDay > 0 {
  4639. var cha_time int64
  4640. timeNowStr := time.Now().Format("2006-01-02")
  4641. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4642. //今日的日期减去设置的日期
  4643. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4644. if cha_time >= advice.AdviceDate {
  4645. //查询审核是否允许
  4646. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  4647. //申请状态不允许的情况 拒绝修改
  4648. if infor.ApplicationStatus != 1 {
  4649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4650. return
  4651. }
  4652. }
  4653. }
  4654. err := service.DeleteDoctorAdvice(&advice)
  4655. //记录日志
  4656. byterequest, _ := json.Marshal(advice)
  4657. adviceLog := models.XtDoctorAdviceLog{
  4658. UserOrgId: advice.UserOrgId,
  4659. PatientId: advice.PatientId,
  4660. AdminUserId: adminUserInfo.AdminUser.Id,
  4661. Module: 4,
  4662. ErrLog: string(byterequest),
  4663. Status: 1,
  4664. Ctime: time.Now().Unix(),
  4665. Mtime: 0,
  4666. Source: "手机端删除医嘱",
  4667. RecordDate: advice.RecordDate,
  4668. }
  4669. service.CreateDoctorAdviceLog(adviceLog)
  4670. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4671. redis.Set(key, "", time.Second)
  4672. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4673. redis.Set(keyTwo, "", time.Second)
  4674. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4675. redis.Set(keyThree, "", time.Second)
  4676. redis.Close()
  4677. if err != nil {
  4678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4679. return
  4680. }
  4681. c.ServeSuccessJSON(map[string]interface{}{
  4682. "msg": "ok",
  4683. })
  4684. return
  4685. } else { //
  4686. var ids []string
  4687. if groupno == 0 {
  4688. advice_id := c.GetString("advice_id")
  4689. ids = strings.Split(advice_id, ",")
  4690. if len(ids) <= 0 {
  4691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4692. return
  4693. }
  4694. }
  4695. if groupno < 0 {
  4696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4697. return
  4698. }
  4699. adminUserInfo := c.GetMobileAdminUserInfo()
  4700. var advice models.DoctorAdvice
  4701. if groupno > 0 {
  4702. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  4703. if advice.ID == 0 {
  4704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4705. return
  4706. }
  4707. } else {
  4708. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  4709. for _, item := range advices {
  4710. if item.ID == 0 {
  4711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4712. return
  4713. }
  4714. }
  4715. }
  4716. advice.UpdatedTime = time.Now().Unix()
  4717. advice.Status = 0
  4718. advice.GroupNo = groupno
  4719. advice.Modifier = adminUserInfo.AdminUser.Id
  4720. var err error
  4721. if groupno > 0 {
  4722. // 查询信息规挡的设置天数
  4723. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4724. if infor.ID > 0 {
  4725. var cha_time int64
  4726. timeNowStr := time.Now().Format("2006-01-02")
  4727. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4728. //今日的日期减去设置的日期
  4729. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4730. if cha_time >= advice.AdviceDate {
  4731. //查询审核是否允许
  4732. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  4733. //申请状态不允许的情况 拒绝修改
  4734. if infor.ApplicationStatus != 1 {
  4735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4736. return
  4737. }
  4738. }
  4739. }
  4740. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  4741. //记录日志
  4742. byterequest, _ := json.Marshal(advice)
  4743. adviceLog := models.XtDoctorAdviceLog{
  4744. UserOrgId: advice.UserOrgId,
  4745. PatientId: advice.PatientId,
  4746. AdminUserId: adminUserInfo.AdminUser.Id,
  4747. Module: 4,
  4748. ErrLog: string(byterequest),
  4749. Status: 1,
  4750. Ctime: time.Now().Unix(),
  4751. Mtime: 0,
  4752. Source: "手机端删除医嘱",
  4753. RecordDate: advice.RecordDate,
  4754. }
  4755. service.CreateDoctorAdviceLog(adviceLog)
  4756. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4757. redis.Set(key, "", time.Second)
  4758. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4759. redis.Set(keyTwo, "", time.Second)
  4760. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4761. redis.Set(keyThree, "", time.Second)
  4762. } else {
  4763. // 查询信息规挡的设置天数
  4764. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4765. if infor.ID > 0 {
  4766. var cha_time int64
  4767. timeNowStr := time.Now().Format("2006-01-02")
  4768. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4769. //今日的日期减去设置的日期
  4770. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4771. if cha_time >= advice.AdviceDate {
  4772. //查询审核是否允许
  4773. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  4774. //申请状态不允许的情况 拒绝修改
  4775. if infor.ApplicationStatus != 1 {
  4776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4777. return
  4778. }
  4779. }
  4780. }
  4781. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  4782. advicelist, _ := service.GetBatchDoctorAdviceList(ids, adminUserInfo.Org.Id)
  4783. for _, item := range advicelist {
  4784. //记录日志
  4785. byterequest, _ := json.Marshal(item)
  4786. adviceLog := models.XtDoctorAdviceLog{
  4787. UserOrgId: item.UserOrgId,
  4788. PatientId: item.PatientId,
  4789. AdminUserId: adminUserInfo.AdminUser.Id,
  4790. Module: 4,
  4791. ErrLog: string(byterequest),
  4792. Status: 1,
  4793. Ctime: time.Now().Unix(),
  4794. Mtime: 0,
  4795. Source: "手机端批量删除医嘱",
  4796. RecordDate: item.RecordDate,
  4797. }
  4798. service.CreateDoctorAdviceLog(adviceLog)
  4799. }
  4800. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4801. redis.Set(key, "", time.Second)
  4802. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4803. redis.Set(keyTwo, "", time.Second)
  4804. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4805. redis.Set(keyThree, "", time.Second)
  4806. redis.Close()
  4807. }
  4808. if err != nil {
  4809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4810. return
  4811. }
  4812. c.ServeSuccessJSON(map[string]interface{}{
  4813. "msg": "ok",
  4814. })
  4815. return
  4816. }
  4817. }
  4818. // /m/api/advice/group/modify_starttime [post]
  4819. // @param group_no:int
  4820. // @param start_time:string yyyy-MM-dd hh:mm:ss
  4821. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  4822. group_no, _ := this.GetInt64("group_no")
  4823. start_time_str := this.GetString("start_time")
  4824. if group_no <= 0 || len(start_time_str) == 0 {
  4825. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4826. return
  4827. }
  4828. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  4829. if parseTimeErr != nil {
  4830. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  4831. return
  4832. }
  4833. adminUserInfo := this.GetMobileAdminUserInfo()
  4834. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  4835. if updateStartTimeErr != nil {
  4836. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  4837. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4838. return
  4839. }
  4840. this.ServeSuccessJSON(map[string]interface{}{
  4841. "start_time": startTime.Unix(),
  4842. })
  4843. }
  4844. func (this *PatientApiController) DelSubDoctorAdvice() {
  4845. advice_id, _ := this.GetInt64("advice_id")
  4846. adminUserInfo := this.GetMobileAdminUserInfo()
  4847. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  4848. if advice.ID == 0 {
  4849. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4850. return
  4851. }
  4852. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  4853. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  4854. // return
  4855. //}
  4856. advice.Status = 0
  4857. advice.UpdatedTime = time.Now().Unix()
  4858. advice.Modifier = adminUserInfo.AdminUser.Id
  4859. err := service.DeleteDoctorAdvice(&advice)
  4860. if err != nil {
  4861. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4862. return
  4863. }
  4864. this.ServeSuccessJSON(map[string]interface{}{
  4865. "msg": "ok",
  4866. })
  4867. return
  4868. }
  4869. func (this *PatientApiController) GetAdviceUnReadMessage() {
  4870. //adminUserInfo := this.GetMobileAdminUserInfo()
  4871. //service.FindUnReadDoctorAdviceMessage()
  4872. }
  4873. func (this *PatientApiController) GetPatientsByKeyWord() {
  4874. keyWord := this.GetString("keyword")
  4875. adminUserInfo := this.GetMobileAdminUserInfo()
  4876. today := utils.ZeroHourTimeOfDay(time.Now())
  4877. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  4878. if err != nil {
  4879. utils.ErrorLog(err.Error())
  4880. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4881. return
  4882. }
  4883. this.ServeSuccessJSON(map[string]interface{}{
  4884. "patient": patient,
  4885. })
  4886. }
  4887. func (this *PatientApiController) GetSearchPatient() {
  4888. keyWord := this.GetString("keyword")
  4889. adminUserInfo := this.GetMobileAdminUserInfo()
  4890. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  4891. if err != nil {
  4892. utils.ErrorLog(err.Error())
  4893. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4894. return
  4895. }
  4896. this.ServeSuccessJSON(map[string]interface{}{
  4897. "patient": patient,
  4898. })
  4899. }
  4900. func (c *PatientApiController) ExecProject() {
  4901. execution_time := c.GetString("execution_time")
  4902. project_id, _ := c.GetInt64("project_id")
  4903. team_id, _ := c.GetInt64("team_id")
  4904. is_check_team, _ := c.GetInt64("is_check_team")
  4905. if len(execution_time) <= 0 {
  4906. utils.ErrorLog("execution_time")
  4907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4908. return
  4909. }
  4910. timeLayout2 := "2006-01-02 15:04:05"
  4911. loc, _ := time.LoadLocation("Local")
  4912. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  4913. if errs != nil {
  4914. utils.ErrorLog(errs.Error())
  4915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4916. return
  4917. }
  4918. adminInfo := c.GetMobileAdminUserInfo()
  4919. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  4920. if project.Type == 3 {
  4921. good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
  4922. if good.IsUser != 1 {
  4923. //查询开关是否开启
  4924. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  4925. //开关已经开启
  4926. if stockSetting.IsType == 1 {
  4927. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  4928. scheduleDateStart := theTime.Format("2006-01-02")
  4929. timeLayout3 := "2006-01-02"
  4930. loc, _ := time.LoadLocation("Local")
  4931. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  4932. //查询该耗材是否已经出库
  4933. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  4934. if auto.ID == 0 {
  4935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  4936. return
  4937. }
  4938. }
  4939. }
  4940. if good.IsUser == 1 && good.IsWarehouse == 1 {
  4941. //查询开关是否开启
  4942. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  4943. //开关已经开启
  4944. if stockSetting.IsType == 1 {
  4945. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  4946. scheduleDateStart := theTime.Format("2006-01-02")
  4947. timeLayout3 := "2006-01-02"
  4948. loc, _ := time.LoadLocation("Local")
  4949. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  4950. //查询该耗材是否已经出库
  4951. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  4952. if auto.ID == 0 {
  4953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  4954. return
  4955. }
  4956. }
  4957. }
  4958. }
  4959. if project.ExecutionState == 1 {
  4960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  4961. return
  4962. }
  4963. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  4964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  4965. return
  4966. }
  4967. project.ExecutionState = 1
  4968. project.ExecutionStaff = adminInfo.AdminUser.Id
  4969. project.ExecutionTime = theTime.Unix()
  4970. if team_id == 0 {
  4971. // 查询信息规挡的设置天数
  4972. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4973. if infor.ID > 0 {
  4974. var cha_time int64
  4975. timeNowStr := time.Now().Format("2006-01-02")
  4976. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4977. //今日的日期减去设置的日期
  4978. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4979. if cha_time >= project.RecordDate {
  4980. //查询审核是否允许
  4981. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  4982. //申请状态不允许的情况 拒绝修改
  4983. if infor.ApplicationStatus != 1 {
  4984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4985. return
  4986. }
  4987. }
  4988. }
  4989. err := service.SaveHisProject(&project)
  4990. if err == nil {
  4991. c.ServeSuccessJSON(map[string]interface{}{
  4992. "project": project,
  4993. })
  4994. } else {
  4995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4996. return
  4997. }
  4998. } else {
  4999. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  5000. // 查询信息规挡的设置天数
  5001. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5002. if infor.ID > 0 {
  5003. var cha_time int64
  5004. timeNowStr := time.Now().Format("2006-01-02")
  5005. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5006. //今日的日期减去设置的日期
  5007. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5008. if cha_time >= project.RecordDate {
  5009. //查询审核是否允许
  5010. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5011. //申请状态不允许的情况 拒绝修改
  5012. if infor.ApplicationStatus != 1 {
  5013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5014. return
  5015. }
  5016. }
  5017. }
  5018. err := service.SaveHisProject(&project)
  5019. if err == nil {
  5020. c.ServeSuccessJSON(map[string]interface{}{
  5021. "project": project,
  5022. })
  5023. } else {
  5024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5025. return
  5026. }
  5027. } else {
  5028. // 查询信息规挡的设置天数
  5029. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5030. if infor.ID > 0 {
  5031. var cha_time int64
  5032. timeNowStr := time.Now().Format("2006-01-02")
  5033. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5034. //今日的日期减去设置的日期
  5035. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5036. if cha_time >= project.RecordDate {
  5037. //查询审核是否允许
  5038. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5039. //申请状态不允许的情况 拒绝修改
  5040. if infor.ApplicationStatus != 1 {
  5041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5042. return
  5043. }
  5044. }
  5045. }
  5046. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  5047. var ids []int64
  5048. for _, items := range ps {
  5049. ids = append(ids, items.ID)
  5050. }
  5051. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  5052. if err == nil {
  5053. c.ServeSuccessJSON(map[string]interface{}{
  5054. "project": project,
  5055. })
  5056. } else {
  5057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5058. return
  5059. }
  5060. }
  5061. }
  5062. }
  5063. func (c *PatientApiController) CheckProject() {
  5064. adminInfo := c.GetMobileAdminUserInfo()
  5065. project_id, _ := c.GetInt64("project_id")
  5066. team_id, _ := c.GetInt64("team_id")
  5067. is_check_team, _ := c.GetInt64("is_check_team")
  5068. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  5069. if project.CheckState == 1 {
  5070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  5071. return
  5072. }
  5073. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  5074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  5075. return
  5076. }
  5077. project.Checker = adminInfo.AdminUser.Id
  5078. project.CheckTime = time.Now().Unix()
  5079. project.CheckState = 1
  5080. if team_id == 0 {
  5081. // 查询信息规挡的设置天数
  5082. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5083. if infor.ID > 0 {
  5084. var cha_time int64
  5085. timeNowStr := time.Now().Format("2006-01-02")
  5086. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5087. //今日的日期减去设置的日期
  5088. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5089. if cha_time >= project.RecordDate {
  5090. //查询审核是否允许
  5091. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5092. //申请状态不允许的情况 拒绝修改
  5093. if infor.ApplicationStatus != 1 {
  5094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5095. return
  5096. }
  5097. }
  5098. }
  5099. err := service.SaveHisProject(&project)
  5100. if err == nil {
  5101. c.ServeSuccessJSON(map[string]interface{}{
  5102. "msg": "ok",
  5103. "project": project,
  5104. })
  5105. } else {
  5106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5107. return
  5108. }
  5109. } else {
  5110. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  5111. // 查询信息规挡的设置天数
  5112. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5113. if infor.ID > 0 {
  5114. var cha_time int64
  5115. timeNowStr := time.Now().Format("2006-01-02")
  5116. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5117. //今日的日期减去设置的日期
  5118. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5119. if cha_time >= project.RecordDate {
  5120. //查询审核是否允许
  5121. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5122. //申请状态不允许的情况 拒绝修改
  5123. if infor.ApplicationStatus != 1 {
  5124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5125. return
  5126. }
  5127. }
  5128. }
  5129. err := service.SaveHisProject(&project)
  5130. if err == nil {
  5131. c.ServeSuccessJSON(map[string]interface{}{
  5132. "msg": "ok",
  5133. "project": project,
  5134. })
  5135. } else {
  5136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5137. return
  5138. }
  5139. } else {
  5140. // 查询信息规挡的设置天数
  5141. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5142. if infor.ID > 0 {
  5143. var cha_time int64
  5144. timeNowStr := time.Now().Format("2006-01-02")
  5145. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5146. //今日的日期减去设置的日期
  5147. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5148. if cha_time >= project.RecordDate {
  5149. //查询审核是否允许
  5150. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5151. //申请状态不允许的情况 拒绝修改
  5152. if infor.ApplicationStatus != 1 {
  5153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5154. return
  5155. }
  5156. }
  5157. }
  5158. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  5159. var ids []int64
  5160. for _, items := range ps {
  5161. ids = append(ids, items.ID)
  5162. }
  5163. err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
  5164. if err == nil {
  5165. c.ServeSuccessJSON(map[string]interface{}{
  5166. "project": project,
  5167. })
  5168. } else {
  5169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5170. return
  5171. }
  5172. }
  5173. }
  5174. }