patient_api_controller.go 221KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275
  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. tx.Rollback()
  1106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1107. return
  1108. }
  1109. timeLayout2 := "2006-01-02 15:04:05"
  1110. loc, _ := time.LoadLocation("Local")
  1111. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1112. if errs != nil {
  1113. utils.ErrorLog(errs.Error())
  1114. tx.Rollback()
  1115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1116. return
  1117. }
  1118. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1119. var err error
  1120. for _, item := range advices {
  1121. if item.ExecutionState == 1 {
  1122. tx.Rollback()
  1123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1124. return
  1125. }
  1126. if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
  1127. tx.Rollback()
  1128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1129. return
  1130. }
  1131. if item.StartTime > theTime.Unix() {
  1132. tx.Rollback()
  1133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1134. return
  1135. }
  1136. item.ExecutionState = 1
  1137. item.ExecutionStaff = adminInfo.AdminUser.Id
  1138. item.ExecutionTime = theTime.Unix()
  1139. item.IsMobile = 1
  1140. // 查询信息规挡的设置天数
  1141. infor, _ := service.GetDialysisInformationSetting(item.UserOrgId)
  1142. if infor.ID > 0 {
  1143. var cha_time int64
  1144. timeNowStr := time.Now().Format("2006-01-02")
  1145. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1146. //今日的日期减去设置的日期
  1147. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1148. if cha_time >= item.AdviceDate {
  1149. //查询审核是否允许
  1150. infor, _ := service.GetDialysisInformationByRecordDate(item.PatientId, item.AdviceDate, item.UserOrgId, 4)
  1151. //申请状态不允许的情况 拒绝修改
  1152. if infor.ApplicationStatus != 1 {
  1153. tx.Rollback()
  1154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1155. return
  1156. }
  1157. }
  1158. }
  1159. service.SaveHisDoctorAdviceOne(item, tx)
  1160. //记录日志
  1161. byterequest, _ := json.Marshal(item)
  1162. adviceLog := models.XtDoctorAdviceLog{
  1163. UserOrgId: item.UserOrgId,
  1164. PatientId: item.PatientId,
  1165. AdminUserId: item.ExecutionStaff,
  1166. Module: 2,
  1167. ErrLog: string(byterequest),
  1168. Status: 1,
  1169. Ctime: time.Now().Unix(),
  1170. Mtime: 0,
  1171. Source: "手机端执行his医嘱",
  1172. RecordDate: item.AdviceDate,
  1173. }
  1174. service.CreateDoctorAdviceLog(adviceLog)
  1175. if err == nil {
  1176. drugError := models.XtDrugError{
  1177. UserOrgId: adminInfo.Org.Id,
  1178. DrugId: item.DrugId,
  1179. RecordDate: item.AdviceDate,
  1180. PatientId: item.PatientId,
  1181. Remark: "执行成功",
  1182. Status: 1,
  1183. Ctime: time.Now().Unix(),
  1184. Mtime: 0,
  1185. SumCount: 0,
  1186. Prescribingnumber: item.PrescribingNumber,
  1187. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1188. }
  1189. service.CreateDrugError(drugError)
  1190. }
  1191. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1192. redis := service.RedisClient()
  1193. //清空key 值
  1194. redis.Set(key, "", time.Second)
  1195. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1196. redis.Set(keyTwo, "", time.Second)
  1197. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1198. redis.Set(keyThree, "", time.Second)
  1199. recordDate := theTime.Format("2006-01-02")
  1200. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1201. redis.Set(keyFour, "", time.Second)
  1202. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1203. redis.Set(keyFive, "", time.Second)
  1204. defer redis.Close()
  1205. }
  1206. //药品管理信息
  1207. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  1208. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  1209. if drugStockConfig.IsOpen == 1 {
  1210. for _, item := range advices {
  1211. //查询改药品信息
  1212. medical, _ := service.GetBaseDrugMedicalOne(item.DrugId, tx)
  1213. //判断单位是否合格
  1214. if item.PrescribingNumberUnit != medical.MaxUnit && item.PrescribingNumberUnit != medical.MinUnit {
  1215. //查询该药品是否有出库记录
  1216. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate, tx)
  1217. if len(flowMap) == 0 {
  1218. errs := service.UpdateHisAdviceByIdOne(item.ID, tx)
  1219. if errs != nil {
  1220. drugError := models.XtDrugError{
  1221. UserOrgId: adminInfo.Org.Id,
  1222. DrugId: item.DrugId,
  1223. RecordDate: item.AdviceDate,
  1224. PatientId: item.PatientId,
  1225. Remark: "单位不统一,执行失败",
  1226. Status: 1,
  1227. Ctime: time.Now().Unix(),
  1228. Mtime: 0,
  1229. SumCount: 0,
  1230. Prescribingnumber: item.PrescribingNumber,
  1231. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1232. }
  1233. service.CreateDrugError(drugError)
  1234. }
  1235. }
  1236. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1237. tx.Rollback()
  1238. c.ServeSuccessJSON(map[string]interface{}{
  1239. "msg": "7",
  1240. "advice": advice,
  1241. "ids": ids,
  1242. })
  1243. return
  1244. }
  1245. //查询这个患者这个患者这个药已经出库的所有数量
  1246. advicelist, _ := service.GetAllHisDoctorAdviceByIdOne(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId, tx)
  1247. drugoutlist, _ := service.GetAllDrugFlowByIdOne(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId, tx)
  1248. var total_count int64
  1249. var drug_count int64
  1250. for _, it := range advicelist {
  1251. if it.PrescribingNumberUnit == medical.MaxUnit {
  1252. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1253. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1254. total_count += prenumber * medical.MinNumber
  1255. }
  1256. if it.PrescribingNumberUnit == medical.MinUnit {
  1257. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1258. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1259. total_count += prenumber
  1260. }
  1261. }
  1262. for _, its := range drugoutlist {
  1263. if its.CountUnit == medical.MaxUnit {
  1264. drug_count += its.Count * medical.MinNumber
  1265. }
  1266. if its.CountUnit == medical.MinUnit {
  1267. drug_count += its.Count
  1268. }
  1269. }
  1270. fmt.Println("total_count-------------------------------", total_count)
  1271. fmt.Println("drug_count-------------------------------", drug_count)
  1272. if total_count == drug_count {
  1273. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1274. tx.Commit()
  1275. c.ServeSuccessJSON(map[string]interface{}{
  1276. "msg": "1",
  1277. "advice": advice,
  1278. "ids": ids,
  1279. })
  1280. return
  1281. }
  1282. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1283. var total int64
  1284. var prescribing_number_total int64
  1285. //保存处方出库
  1286. config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
  1287. fmt.Println("config============================================")
  1288. if config.IsOpen != 1 {
  1289. //查询该药品是否有库存
  1290. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1291. list, _ := service.GetDrugTotalCountTwoTwety(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut, tx)
  1292. //判断单位是否相等
  1293. if medical.MaxUnit == advice.PrescribingNumberUnit && medical.MaxUnit != medical.MinUnit {
  1294. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1295. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1296. //转化为最小单位
  1297. total = list.Count*medical.MinNumber + list.StockMinNumber
  1298. prescribing_number_total = count * medical.MinNumber
  1299. }
  1300. if medical.MinUnit == advice.PrescribingNumberUnit && medical.MaxUnit != medical.MinUnit {
  1301. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1302. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1303. total = list.Count*medical.MinNumber + list.StockMinNumber
  1304. prescribing_number_total = count
  1305. }
  1306. if medical.MinUnit == advice.PrescribingNumberUnit && medical.MaxUnit == medical.MinUnit {
  1307. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1308. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1309. total = list.Count*medical.MinNumber + list.StockMinNumber
  1310. prescribing_number_total = count
  1311. }
  1312. if medical.IsUse == 1 {
  1313. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1314. drugError := models.XtDrugError{
  1315. UserOrgId: adminInfo.Org.Id,
  1316. DrugId: item.DrugId,
  1317. RecordDate: item.AdviceDate,
  1318. PatientId: item.PatientId,
  1319. Remark: "零用药品库存不足",
  1320. Status: 1,
  1321. Ctime: time.Now().Unix(),
  1322. Mtime: 0,
  1323. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1324. Prescribingnumber: advice.PrescribingNumber,
  1325. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1326. }
  1327. service.CreateDrugError(drugError)
  1328. tx.Rollback()
  1329. c.ServeSuccessJSON(map[string]interface{}{
  1330. "msg": "1",
  1331. "advice": advice,
  1332. "ids": ids,
  1333. })
  1334. return
  1335. }
  1336. }
  1337. if medical.IsUse != 1 {
  1338. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1339. drugError := models.XtDrugError{
  1340. UserOrgId: adminInfo.Org.Id,
  1341. DrugId: item.DrugId,
  1342. RecordDate: item.AdviceDate,
  1343. PatientId: item.PatientId,
  1344. Remark: "药品库存不足",
  1345. Status: 1,
  1346. Ctime: time.Now().Unix(),
  1347. Mtime: 0,
  1348. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1349. Prescribingnumber: advice.PrescribingNumber,
  1350. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1351. }
  1352. service.CreateDrugError(drugError)
  1353. tx.Rollback()
  1354. c.ServeSuccessJSON(map[string]interface{}{
  1355. "msg": "3",
  1356. "advice": advice,
  1357. "ids": ids,
  1358. })
  1359. return
  1360. }
  1361. if prescribing_number_total > total {
  1362. drugError := models.XtDrugError{
  1363. UserOrgId: adminInfo.Org.Id,
  1364. DrugId: item.DrugId,
  1365. RecordDate: item.AdviceDate,
  1366. PatientId: item.PatientId,
  1367. Remark: "出库数量大于库存",
  1368. Status: 1,
  1369. Ctime: time.Now().Unix(),
  1370. Mtime: 0,
  1371. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1372. Prescribingnumber: advice.PrescribingNumber,
  1373. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1374. }
  1375. service.CreateDrugError(drugError)
  1376. tx.Rollback()
  1377. c.ServeSuccessJSON(map[string]interface{}{
  1378. "msg": "2",
  1379. "advice": advice,
  1380. "ids": ids,
  1381. })
  1382. return
  1383. }
  1384. }
  1385. if prescribing_number_total <= total {
  1386. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1387. //判断药品是否零用
  1388. if medical.IsUse == 2 {
  1389. if config.IsOpen != 1 {
  1390. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1391. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1392. //查询该药品是否有出库记录
  1393. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
  1394. if len(flowMap) == 0 {
  1395. errs := service.UpdateHisAdviceByIdOne(advice.ID, tx)
  1396. if errs != nil {
  1397. drugError := models.XtDrugError{
  1398. UserOrgId: adminInfo.Org.Id,
  1399. DrugId: item.DrugId,
  1400. RecordDate: item.AdviceDate,
  1401. PatientId: item.PatientId,
  1402. Remark: "出库记录为空,更新执行人失败",
  1403. Status: 1,
  1404. Ctime: time.Now().Unix(),
  1405. Mtime: 0,
  1406. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1407. Prescribingnumber: advice.PrescribingNumber,
  1408. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1409. }
  1410. service.CreateDrugError(drugError)
  1411. }
  1412. tx.Rollback()
  1413. c.ServeSuccessJSON(map[string]interface{}{
  1414. "msg": "6",
  1415. "advice": advice,
  1416. "ids": ids,
  1417. })
  1418. return
  1419. }
  1420. }
  1421. }
  1422. if pharmacyConfig.IsOpen != 1 {
  1423. //查询已经出库数量
  1424. outListExport, _ := service.GetWarehouseOutListExport(advice.DrugId, advice.PatientId, advice.AdviceDate, advice.ID)
  1425. var out_count int64
  1426. if len(outListExport) > 0 {
  1427. for _, item := range outListExport {
  1428. if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1429. out_count = item.Count * medical.MinNumber
  1430. }
  1431. if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1432. out_count = item.Count
  1433. }
  1434. if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  1435. out_count = item.Count * medical.MinNumber
  1436. }
  1437. }
  1438. }
  1439. newadviceInfo := &models.HisDoctorAdviceInfo{
  1440. ID: advice.ID,
  1441. UserOrgId: advice.UserOrgId,
  1442. PatientId: advice.PatientId,
  1443. HisPatientId: advice.HisPatientId,
  1444. AdviceType: advice.AdviceType,
  1445. AdviceDate: advice.AdviceDate,
  1446. StartTime: advice.StartTime,
  1447. AdviceName: advice.AdviceName,
  1448. AdviceDesc: advice.AdviceDesc,
  1449. ReminderDate: advice.ReminderDate,
  1450. SingleDose: advice.SingleDose,
  1451. SingleDoseUnit: advice.SingleDoseUnit,
  1452. PrescribingNumber: advice.PrescribingNumber,
  1453. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1454. DeliveryWay: advice.DeliveryWay,
  1455. ExecutionFrequency: advice.ExecutionFrequency,
  1456. AdviceDoctor: advice.AdviceDoctor,
  1457. Status: advice.Status,
  1458. CreatedTime: advice.CreatedTime,
  1459. UpdatedTime: advice.UpdatedTime,
  1460. AdviceAffirm: advice.AdviceAffirm,
  1461. Remark: advice.Remark,
  1462. StopTime: advice.StopTime,
  1463. StopReason: advice.StopReason,
  1464. StopDoctor: advice.StopDoctor,
  1465. StopState: advice.StopState,
  1466. ParentId: advice.ParentId,
  1467. ExecutionTime: advice.ExecutionTime,
  1468. ExecutionStaff: advice.ExecutionStaff,
  1469. ExecutionState: advice.ExecutionState,
  1470. Checker: advice.Checker,
  1471. RecordDate: advice.RecordDate,
  1472. DialysisOrderId: advice.DialysisOrderId,
  1473. CheckTime: advice.CheckTime,
  1474. CheckState: advice.CheckState,
  1475. DrugSpec: advice.DrugSpec,
  1476. DrugSpecUnit: advice.DrugSpecUnit,
  1477. Groupno: advice.Groupno,
  1478. RemindType: advice.RemindType,
  1479. FrequencyType: advice.FrequencyType,
  1480. DayCount: advice.DayCount,
  1481. WeekDay: advice.WeekDay,
  1482. TemplateId: advice.TemplateId,
  1483. Modifier: advice.Modifier,
  1484. DrugId: advice.DrugId,
  1485. Price: advice.Price,
  1486. PrescriptionId: advice.PrescriptionId,
  1487. MedListCodg: advice.MedListCodg,
  1488. FeedetlSn: advice.FeedetlSn,
  1489. Day: advice.DayCount,
  1490. ChildDoctorAdvice: nil,
  1491. Drug: models.Drug{},
  1492. Diagnosis: advice.Diagnosis,
  1493. Way: advice.Way,
  1494. HospApprFlag: advice.HospApprFlag,
  1495. LmtUsedFlag: advice.LmtUsedFlag,
  1496. HisOrderInfo: models.HisOrderInfo{},
  1497. IsMedicine: advice.IsMedicine,
  1498. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  1499. Child: nil,
  1500. IsSettle: advice.IsSettle,
  1501. IsMobile: advice.IsMobile,
  1502. IsSelfDrug: advice.IsSelfDrug,
  1503. DrugWayCount: advice.DrugWayCount,
  1504. }
  1505. //如果当前医嘱数量大于历史出库数据则需要出库
  1506. if prescribing_number_total > out_count {
  1507. //按最小单位出库
  1508. var cha_count = prescribing_number_total - out_count
  1509. newadviceInfo.PrescribingNumber = float64(cha_count)
  1510. newadviceInfo.PrescribingNumberUnit = medical.MinUnit
  1511. service.NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
  1512. }
  1513. //如果当前医嘱数量小于历史出库数据则需要退库
  1514. if prescribing_number_total < out_count {
  1515. var cha_count = out_count - prescribing_number_total
  1516. drug, _ := service.FindBaseDrugLibRecordSeven(advice.UserOrgId, advice.DrugId)
  1517. service.NewHisDrugCancelInfo(advice.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  1518. service.NewHisDrugAutoCancelInfo(advice.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  1519. }
  1520. if prescribing_number_total == out_count {
  1521. if out_count == 0 {
  1522. service.NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
  1523. }
  1524. }
  1525. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1526. //查询该药品是否有出库记录
  1527. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
  1528. if len(flowMap) == 0 {
  1529. errs := service.UpdateHisAdviceByIdOne(advice.ID, tx)
  1530. if errs != nil {
  1531. drugError := models.XtDrugError{
  1532. UserOrgId: adminInfo.Org.Id,
  1533. DrugId: item.DrugId,
  1534. RecordDate: item.AdviceDate,
  1535. PatientId: item.PatientId,
  1536. Remark: "出库记录为空,更新执行人失败",
  1537. Status: 1,
  1538. Ctime: time.Now().Unix(),
  1539. Mtime: 0,
  1540. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1541. Prescribingnumber: advice.PrescribingNumber,
  1542. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1543. }
  1544. service.CreateDrugError(drugError)
  1545. }
  1546. tx.Rollback()
  1547. c.ServeSuccessJSON(map[string]interface{}{
  1548. "msg": "6",
  1549. "advice": advice,
  1550. "ids": ids,
  1551. })
  1552. return
  1553. }
  1554. }
  1555. }
  1556. //更新字典里面的库存
  1557. stockInfo, _ := service.GetNewDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId, tx)
  1558. var sum_count int64
  1559. for _, its := range stockInfo {
  1560. if its.MaxUnit == medical.MaxUnit {
  1561. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1562. }
  1563. sum_count += its.StockMaxNumber + its.StockMinNumber
  1564. }
  1565. service.UpdateNewBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId, tx)
  1566. //剩余库存
  1567. service.UpdateNewDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count, tx)
  1568. }
  1569. }
  1570. }
  1571. }
  1572. fmt.Println("org_id =============================", adminInfo.Org.Id)
  1573. ////针对异常未出库问题的脚本
  1574. //if adminInfo.Org.Id == 10598 {
  1575. //
  1576. // newadviceInfo := &models.HisDoctorAdviceInfo{
  1577. // ID: advice.ID,
  1578. // UserOrgId: advice.UserOrgId,
  1579. // PatientId: advice.PatientId,
  1580. // HisPatientId: advice.HisPatientId,
  1581. // AdviceType: advice.AdviceType,
  1582. // AdviceDate: advice.AdviceDate,
  1583. // StartTime: advice.StartTime,
  1584. // AdviceName: advice.AdviceName,
  1585. // AdviceDesc: advice.AdviceDesc,
  1586. // ReminderDate: advice.ReminderDate,
  1587. // SingleDose: advice.SingleDose,
  1588. // SingleDoseUnit: advice.SingleDoseUnit,
  1589. // PrescribingNumber: advice.PrescribingNumber,
  1590. // PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1591. // DeliveryWay: advice.DeliveryWay,
  1592. // ExecutionFrequency: advice.ExecutionFrequency,
  1593. // AdviceDoctor: advice.AdviceDoctor,
  1594. // Status: advice.Status,
  1595. // CreatedTime: advice.CreatedTime,
  1596. // UpdatedTime: advice.UpdatedTime,
  1597. // AdviceAffirm: advice.AdviceAffirm,
  1598. // Remark: advice.Remark,
  1599. // StopTime: advice.StopTime,
  1600. // StopReason: advice.StopReason,
  1601. // StopDoctor: advice.StopDoctor,
  1602. // StopState: advice.StopState,
  1603. // ParentId: advice.ParentId,
  1604. // ExecutionTime: advice.ExecutionTime,
  1605. // ExecutionStaff: advice.ExecutionStaff,
  1606. // ExecutionState: advice.ExecutionState,
  1607. // Checker: advice.Checker,
  1608. // RecordDate: advice.RecordDate,
  1609. // DialysisOrderId: advice.DialysisOrderId,
  1610. // CheckTime: advice.CheckTime,
  1611. // CheckState: advice.CheckState,
  1612. // DrugSpec: advice.DrugSpec,
  1613. // DrugSpecUnit: advice.DrugSpecUnit,
  1614. // Groupno: advice.Groupno,
  1615. // RemindType: advice.RemindType,
  1616. // FrequencyType: advice.FrequencyType,
  1617. // DayCount: advice.DayCount,
  1618. // WeekDay: advice.WeekDay,
  1619. // TemplateId: advice.TemplateId,
  1620. // Modifier: advice.Modifier,
  1621. // DrugId: advice.DrugId,
  1622. // Price: advice.Price,
  1623. // PrescriptionId: advice.PrescriptionId,
  1624. // MedListCodg: advice.MedListCodg,
  1625. // FeedetlSn: advice.FeedetlSn,
  1626. // Day: advice.DayCount,
  1627. // ChildDoctorAdvice: nil,
  1628. // Drug: models.Drug{},
  1629. // Diagnosis: advice.Diagnosis,
  1630. // Way: advice.Way,
  1631. // HospApprFlag: advice.HospApprFlag,
  1632. // LmtUsedFlag: advice.LmtUsedFlag,
  1633. // HisOrderInfo: models.HisOrderInfo{},
  1634. // IsMedicine: advice.IsMedicine,
  1635. // ExecutionFrequencyId: advice.ExecutionFrequencyId,
  1636. // Child: nil,
  1637. // IsSettle: advice.IsSettle,
  1638. // IsMobile: advice.IsMobile,
  1639. // IsSelfDrug: advice.IsSelfDrug,
  1640. // DrugWayCount: advice.DrugWayCount,
  1641. // }
  1642. // outListExport, _ := service.GetWarehouseOutListExport(advice.DrugId, advice.PatientId, advice.AdviceDate, advice.ID)
  1643. //
  1644. // var out_count int64
  1645. // if len(outListExport) > 0 {
  1646. // for _, item := range outListExport {
  1647. // if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1648. // out_count = item.Count * medical.MinNumber
  1649. // }
  1650. // if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1651. // out_count = item.Count
  1652. // }
  1653. // if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  1654. // out_count = item.Count * medical.MinNumber
  1655. // }
  1656. //
  1657. // }
  1658. // }
  1659. // //按最小单位出库
  1660. // //var cha_count = total_count - out_count
  1661. // fmt.Println("cha_count--------------------------------------", out_count)
  1662. //
  1663. // var cha_count = 1
  1664. // newadviceInfo.PrescribingNumber = float64(cha_count)
  1665. // newadviceInfo.PrescribingNumberUnit = medical.MinUnit
  1666. // service.NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
  1667. //}
  1668. }
  1669. }
  1670. tx.Commit()
  1671. for _, item := range advices {
  1672. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1673. c.ServeSuccessJSON(map[string]interface{}{
  1674. "msg": "1",
  1675. "advice": advice,
  1676. "ids": ids,
  1677. })
  1678. }
  1679. }
  1680. }
  1681. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  1682. execution_time := c.GetString("execution_time")
  1683. fmt.Println("execution_time", execution_time)
  1684. groupno, _ := c.GetInt64("groupno", -1)
  1685. //patient_id, _ := c.GetInt64("patient_id")
  1686. advice_date, _ := c.GetInt64("advice_date")
  1687. var ids []string
  1688. if groupno == 0 {
  1689. advice_ids := c.GetString("advice_id")
  1690. ids = strings.Split(advice_ids, ",")
  1691. }
  1692. if groupno < 0 {
  1693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1694. return
  1695. }
  1696. if len(execution_time) <= 0 {
  1697. utils.ErrorLog("execution_time")
  1698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1699. return
  1700. }
  1701. timeLayout2 := "2006-01-02 15:04:05"
  1702. loc, _ := time.LoadLocation("Local")
  1703. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1704. if errs != nil {
  1705. utils.ErrorLog(errs.Error())
  1706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1707. return
  1708. }
  1709. adminUserInfo := c.GetMobileAdminUserInfo()
  1710. var advice models.DoctorAdvice
  1711. if groupno > 0 {
  1712. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1713. for _, item := range advices {
  1714. if item.ExecutionState == 1 {
  1715. advice = item
  1716. }
  1717. }
  1718. } else {
  1719. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1720. for _, item := range advices {
  1721. if item.ExecutionState == 1 {
  1722. advice = item
  1723. }
  1724. }
  1725. }
  1726. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  1727. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1728. // if getPermissionErr != nil {
  1729. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1730. // return
  1731. // } else if headNursePermission == nil {
  1732. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1733. // return
  1734. // }
  1735. //}
  1736. if advice.StartTime > theTime.Unix() {
  1737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1738. return
  1739. }
  1740. advices := models.DoctorAdvice{
  1741. ExecutionTime: theTime.Unix(),
  1742. UpdatedTime: time.Now().Unix(),
  1743. }
  1744. var err error
  1745. if groupno > 0 {
  1746. // 查询信息规挡的设置天数
  1747. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1748. if infor.ID > 0 {
  1749. var cha_time int64
  1750. timeNowStr := time.Now().Format("2006-01-02")
  1751. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1752. //今日的日期减去设置的日期
  1753. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1754. if cha_time >= advices.AdviceDate {
  1755. //查询审核是否允许
  1756. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1757. //申请状态不允许的情况 拒绝修改
  1758. if infor.ApplicationStatus != 1 {
  1759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1760. return
  1761. }
  1762. }
  1763. }
  1764. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1765. //记录日志
  1766. byterequest, _ := json.Marshal(advices)
  1767. adviceLog := models.XtDoctorAdviceLog{
  1768. UserOrgId: adminUserInfo.Org.Id,
  1769. PatientId: advices.PatientId,
  1770. AdminUserId: adminUserInfo.AdminUser.Id,
  1771. Module: 1,
  1772. ErrLog: string(byterequest),
  1773. Status: 1,
  1774. Ctime: time.Now().Unix(),
  1775. Mtime: 0,
  1776. Source: "手机端编辑医嘱",
  1777. RecordDate: advices.AdviceDate,
  1778. }
  1779. service.CreateDoctorAdviceLog(adviceLog)
  1780. redis := service.RedisClient()
  1781. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1782. redis.Set(key, "", time.Second)
  1783. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1784. redis.Set(keyOne, "", time.Second)
  1785. defer redis.Close()
  1786. } else {
  1787. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1788. if infor.ID > 0 {
  1789. var cha_time int64
  1790. timeNowStr := time.Now().Format("2006-01-02")
  1791. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1792. //今日的日期减去设置的日期
  1793. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1794. if cha_time >= advices.AdviceDate {
  1795. //查询审核是否允许
  1796. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1797. //申请状态不允许的情况 拒绝修改
  1798. if infor.ApplicationStatus != 1 {
  1799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1800. return
  1801. }
  1802. }
  1803. }
  1804. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  1805. err = service.ModifyExceDoctorAdviceByGroupNoOne(&advices, ids)
  1806. //记录日志
  1807. byterequest, _ := json.Marshal(advices)
  1808. adviceLog := models.XtDoctorAdviceLog{
  1809. UserOrgId: adminUserInfo.Org.Id,
  1810. PatientId: advices.PatientId,
  1811. AdminUserId: adminUserInfo.AdminUser.Id,
  1812. Module: 1,
  1813. ErrLog: string(byterequest),
  1814. Status: 1,
  1815. Ctime: time.Now().Unix(),
  1816. Mtime: 0,
  1817. Source: "手机端编辑执行医嘱",
  1818. RecordDate: advices.AdviceDate,
  1819. }
  1820. service.CreateDoctorAdviceLog(adviceLog)
  1821. redis := service.RedisClient()
  1822. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1823. redis.Set(key, "", time.Second)
  1824. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice_date, 10) + ":advice_list_all"
  1825. redis.Set(keyOne, "", time.Second)
  1826. defer redis.Close()
  1827. }
  1828. //判断是否开启his
  1829. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  1830. //如果开启去修改执行时间
  1831. if config.IsOpen == 1 {
  1832. advicesinfo := models.HisDoctorAdviceInfo{
  1833. ExecutionTime: theTime.Unix(),
  1834. UpdatedTime: time.Now().Unix(),
  1835. }
  1836. var advicehis models.HisDoctorAdviceInfo
  1837. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  1838. //记录日志
  1839. byterequest, _ := json.Marshal(advicesinfo)
  1840. adviceLog := models.XtDoctorAdviceLog{
  1841. UserOrgId: adminUserInfo.Org.Id,
  1842. PatientId: advices.PatientId,
  1843. AdminUserId: adminUserInfo.AdminUser.Id,
  1844. Module: 1,
  1845. ErrLog: string(byterequest),
  1846. Status: 1,
  1847. Ctime: time.Now().Unix(),
  1848. Mtime: 0,
  1849. Source: "手机端his编辑医嘱",
  1850. RecordDate: advices.AdviceDate,
  1851. }
  1852. service.CreateDoctorAdviceLog(adviceLog)
  1853. his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
  1854. for _, item := range his_advices {
  1855. if item.ExecutionState == 1 {
  1856. advicehis = item
  1857. }
  1858. }
  1859. redis := service.RedisClient()
  1860. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
  1861. redis.Set(keyThree, "", time.Second)
  1862. recordDate := theTime.Format("2006-01-02")
  1863. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1864. redis.Set(keyFour, "", time.Second)
  1865. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
  1866. redis.Set(keyFive, "", time.Second)
  1867. defer redis.Close()
  1868. project := models.HisPrescriptionProject{
  1869. ExecutionTime: theTime.Unix(),
  1870. Mtime: time.Now().Unix(),
  1871. }
  1872. service.ModifyHisPrescriptionProject(&project, ids)
  1873. //记录日志
  1874. projectquerst, _ := json.Marshal(project)
  1875. projectLog := models.XtDoctorAdviceLog{
  1876. UserOrgId: adminUserInfo.Org.Id,
  1877. PatientId: advices.PatientId,
  1878. AdminUserId: adminUserInfo.AdminUser.Id,
  1879. Module: 1,
  1880. ErrLog: string(projectquerst),
  1881. Status: 1,
  1882. Ctime: time.Now().Unix(),
  1883. Mtime: 0,
  1884. Source: "手机端his编辑项目医嘱",
  1885. RecordDate: advices.AdviceDate,
  1886. }
  1887. service.CreateDoctorAdviceLog(projectLog)
  1888. keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
  1889. redis.Set(keyEnd, "", time.Second)
  1890. keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1891. redis.Set(keyFours, "", time.Second)
  1892. keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
  1893. redis.Set(keyFives, "", time.Second)
  1894. defer redis.Close()
  1895. }
  1896. if err != nil {
  1897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1898. return
  1899. }
  1900. advice.ExecutionTime = theTime.Unix()
  1901. c.ServeSuccessJSON(map[string]interface{}{
  1902. "msg": "ok",
  1903. "advice": advice,
  1904. "ids": ids,
  1905. })
  1906. return
  1907. }
  1908. func (c *PatientApiController) CheckMobileDoctorAdvice() {
  1909. origin, _ := c.GetInt64("origin", 0)
  1910. record_date, _ := c.GetInt64("record_date")
  1911. patient_id, _ := c.GetInt64("patient_id")
  1912. check_time := c.GetString("check_time")
  1913. if len(check_time) <= 0 {
  1914. utils.ErrorLog("check_time")
  1915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1916. return
  1917. }
  1918. timeLayout2 := "2006-01-02 15:04:05"
  1919. loc, _ := time.LoadLocation("Local")
  1920. theTime, errs := time.ParseInLocation(timeLayout2, check_time, loc)
  1921. fmt.Println("theTimewowowow", theTime)
  1922. if errs != nil {
  1923. utils.ErrorLog(errs.Error())
  1924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1925. return
  1926. }
  1927. if origin != 2 {
  1928. groupno, _ := c.GetInt64("groupno", -1)
  1929. var ids []string
  1930. if groupno == 0 {
  1931. advice_ids := c.GetString("advice_id")
  1932. if advice_ids == "" {
  1933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1934. return
  1935. } else {
  1936. ids = strings.Split(advice_ids, ",")
  1937. if len(ids) <= 0 {
  1938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1939. return
  1940. }
  1941. }
  1942. }
  1943. if groupno < 0 {
  1944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1945. return
  1946. }
  1947. adminUserInfo := c.GetMobileAdminUserInfo()
  1948. var advice models.DoctorAdvice
  1949. if groupno > 0 {
  1950. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1951. for _, item := range advices {
  1952. if item.CheckState == 0 {
  1953. advice = item
  1954. }
  1955. //记录日志
  1956. byterequest, _ := json.Marshal(advices)
  1957. adviceLog := models.XtDoctorAdviceLog{
  1958. UserOrgId: adminUserInfo.Org.Id,
  1959. PatientId: item.PatientId,
  1960. AdminUserId: adminUserInfo.AdminUser.Id,
  1961. Module: 3,
  1962. ErrLog: string(byterequest),
  1963. Status: 1,
  1964. Ctime: time.Now().Unix(),
  1965. Mtime: 0,
  1966. Source: "手机端核对医嘱",
  1967. RecordDate: item.AdviceDate,
  1968. }
  1969. service.CreateDoctorAdviceLog(adviceLog)
  1970. }
  1971. if advice.CheckState == 1 {
  1972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1973. return
  1974. }
  1975. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1977. return
  1978. }
  1979. } else {
  1980. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1981. for _, item := range advices {
  1982. if item.CheckState == 0 {
  1983. advice = item
  1984. }
  1985. //记录日志
  1986. byterequest, _ := json.Marshal(advices)
  1987. adviceLog := models.XtDoctorAdviceLog{
  1988. UserOrgId: adminUserInfo.Org.Id,
  1989. PatientId: item.PatientId,
  1990. AdminUserId: adminUserInfo.AdminUser.Id,
  1991. Module: 3,
  1992. ErrLog: string(byterequest),
  1993. Status: 1,
  1994. Ctime: time.Now().Unix(),
  1995. Mtime: 0,
  1996. Source: "手机端核对医嘱",
  1997. RecordDate: item.AdviceDate,
  1998. }
  1999. service.CreateDoctorAdviceLog(adviceLog)
  2000. }
  2001. if advice.CheckState == 1 {
  2002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2003. return
  2004. }
  2005. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2007. return
  2008. }
  2009. }
  2010. checker := adminUserInfo.AdminUser.Id
  2011. advices := models.DoctorAdvice{
  2012. CheckTime: theTime.Unix(),
  2013. Checker: checker,
  2014. UpdatedTime: time.Now().Unix(),
  2015. }
  2016. fmt.Println("groupnowowowowoowowow", groupno)
  2017. var err error
  2018. if groupno > 0 {
  2019. // 查询信息规挡的设置天数
  2020. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2021. if infor.ID > 0 && infor.WeekDay > 0 {
  2022. var cha_time int64
  2023. timeNowStr := time.Now().Format("2006-01-02")
  2024. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2025. //今日的日期减去设置的日期
  2026. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2027. if cha_time >= record_date {
  2028. //查询审核是否允许
  2029. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  2030. //申请状态不允许的情况 拒绝修改
  2031. if infor.ApplicationStatus != 1 {
  2032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2033. return
  2034. }
  2035. }
  2036. }
  2037. err = service.CheckDoctorAdviceByGroupNoOne(&advices, groupno, adminUserInfo.Org.Id)
  2038. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2039. redis := service.RedisClient()
  2040. //清空key 值
  2041. redis.Set(key, "", time.Second)
  2042. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2043. redis.Set(keyTwo, "", time.Second)
  2044. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2045. redis.Set(keyThree, "", time.Second)
  2046. recordDate := theTime.Format("2006-01-02")
  2047. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2048. redis.Set(keyFour, "", time.Second)
  2049. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2050. redis.Set(keyFive, "", time.Second)
  2051. defer redis.Close()
  2052. } else {
  2053. if len(ids[0]) <= 0 {
  2054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2055. return
  2056. } else {
  2057. //t := time.Now().Format("2006-01-02")/**/
  2058. //timeLayout2 := "2006-01-02"
  2059. //loc, _ := time.LoadLocation("Local")
  2060. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  2061. // 查询信息规挡的设置天数
  2062. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2063. if infor.ID > 0 {
  2064. var cha_time int64
  2065. timeNowStr := time.Now().Format("2006-01-02")
  2066. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2067. //今日的日期减去设置的日期
  2068. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2069. if cha_time >= advices.AdviceDate {
  2070. //查询审核是否允许
  2071. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2072. //申请状态不允许的情况 拒绝修改
  2073. if infor.ApplicationStatus != 1 {
  2074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2075. return
  2076. }
  2077. }
  2078. }
  2079. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  2080. //记录日志
  2081. byterequest, _ := json.Marshal(advices)
  2082. adviceLog := models.XtDoctorAdviceLog{
  2083. UserOrgId: adminUserInfo.Org.Id,
  2084. PatientId: advices.PatientId,
  2085. AdminUserId: advices.Checker,
  2086. Module: 3,
  2087. ErrLog: string(byterequest),
  2088. Status: 1,
  2089. Ctime: time.Now().Unix(),
  2090. Mtime: 0,
  2091. Source: "手机端核对医嘱",
  2092. RecordDate: advices.AdviceDate,
  2093. }
  2094. service.CreateDoctorAdviceLog(adviceLog)
  2095. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2096. redis := service.RedisClient()
  2097. //清空key 值
  2098. redis.Set(key, "", time.Second)
  2099. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2100. redis.Set(keyTwo, "", time.Second)
  2101. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2102. redis.Set(keyThree, "", time.Second)
  2103. recordDate := theTime.Format("2006-01-02")
  2104. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2105. redis.Set(keyFour, "", time.Second)
  2106. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2107. redis.Set(keyFive, "", time.Second)
  2108. defer redis.Close()
  2109. }
  2110. }
  2111. if err != nil {
  2112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2113. return
  2114. }
  2115. advice.Checker = checker
  2116. advice.CheckTime = theTime.Unix()
  2117. advice.CheckState = 1
  2118. c.ServeSuccessJSON(map[string]interface{}{
  2119. "msg": "ok",
  2120. "advice": advice,
  2121. })
  2122. }
  2123. return
  2124. }
  2125. func (c *PatientApiController) CheckDoctorAdvice() {
  2126. origin, _ := c.GetInt64("origin", 0)
  2127. record_date, _ := c.GetInt64("record_date")
  2128. patient_id, _ := c.GetInt64("patient_id")
  2129. if origin != 2 {
  2130. groupno, _ := c.GetInt64("groupno", -1)
  2131. var ids []string
  2132. if groupno == 0 {
  2133. advice_ids := c.GetString("advice_id")
  2134. if advice_ids == "" {
  2135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2136. return
  2137. } else {
  2138. ids = strings.Split(advice_ids, ",")
  2139. if len(ids) <= 0 {
  2140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2141. return
  2142. }
  2143. }
  2144. }
  2145. if groupno < 0 {
  2146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2147. return
  2148. }
  2149. adminUserInfo := c.GetMobileAdminUserInfo()
  2150. var advice models.DoctorAdvice
  2151. if groupno > 0 {
  2152. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2153. for _, item := range advices {
  2154. if item.CheckState == 0 {
  2155. advice = item
  2156. }
  2157. //记录日志
  2158. byterequest, _ := json.Marshal(advices)
  2159. adviceLog := models.XtDoctorAdviceLog{
  2160. UserOrgId: adminUserInfo.Org.Id,
  2161. PatientId: item.PatientId,
  2162. AdminUserId: adminUserInfo.AdminUser.Id,
  2163. Module: 3,
  2164. ErrLog: string(byterequest),
  2165. Status: 1,
  2166. Ctime: time.Now().Unix(),
  2167. Mtime: 0,
  2168. Source: "手机端核对医嘱",
  2169. RecordDate: item.AdviceDate,
  2170. }
  2171. service.CreateDoctorAdviceLog(adviceLog)
  2172. }
  2173. if advice.CheckState == 1 {
  2174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2175. return
  2176. }
  2177. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2179. return
  2180. }
  2181. } else {
  2182. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2183. for _, item := range advices {
  2184. if item.CheckState == 0 {
  2185. advice = item
  2186. }
  2187. //记录日志
  2188. byterequest, _ := json.Marshal(advices)
  2189. adviceLog := models.XtDoctorAdviceLog{
  2190. UserOrgId: adminUserInfo.Org.Id,
  2191. PatientId: item.PatientId,
  2192. AdminUserId: adminUserInfo.AdminUser.Id,
  2193. Module: 3,
  2194. ErrLog: string(byterequest),
  2195. Status: 1,
  2196. Ctime: time.Now().Unix(),
  2197. Mtime: 0,
  2198. Source: "手机端核对医嘱",
  2199. RecordDate: item.AdviceDate,
  2200. }
  2201. service.CreateDoctorAdviceLog(adviceLog)
  2202. }
  2203. if advice.CheckState == 1 {
  2204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2205. return
  2206. }
  2207. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2209. return
  2210. }
  2211. }
  2212. checker := adminUserInfo.AdminUser.Id
  2213. theTime := time.Now()
  2214. advices := models.DoctorAdvice{
  2215. CheckTime: theTime.Unix(),
  2216. Checker: checker,
  2217. UpdatedTime: time.Now().Unix(),
  2218. }
  2219. var err error
  2220. if groupno > 0 {
  2221. // 查询信息规挡的设置天数
  2222. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2223. if infor.ID > 0 && infor.WeekDay > 0 {
  2224. var cha_time int64
  2225. timeNowStr := time.Now().Format("2006-01-02")
  2226. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2227. //今日的日期减去设置的日期
  2228. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2229. if cha_time >= record_date {
  2230. //查询审核是否允许
  2231. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  2232. //申请状态不允许的情况 拒绝修改
  2233. if infor.ApplicationStatus != 1 {
  2234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2235. return
  2236. }
  2237. }
  2238. }
  2239. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  2240. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2241. redis := service.RedisClient()
  2242. //清空key 值
  2243. redis.Set(key, "", time.Second)
  2244. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2245. redis.Set(keyTwo, "", time.Second)
  2246. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2247. redis.Set(keyThree, "", time.Second)
  2248. recordDate := theTime.Format("2006-01-02")
  2249. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2250. redis.Set(keyFour, "", time.Second)
  2251. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2252. redis.Set(keyFive, "", time.Second)
  2253. defer redis.Close()
  2254. } else {
  2255. if len(ids[0]) <= 0 {
  2256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2257. return
  2258. } else {
  2259. //t := time.Now().Format("2006-01-02")/**/
  2260. //timeLayout2 := "2006-01-02"
  2261. //loc, _ := time.LoadLocation("Local")
  2262. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  2263. // 查询信息规挡的设置天数
  2264. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2265. if infor.ID > 0 {
  2266. var cha_time int64
  2267. timeNowStr := time.Now().Format("2006-01-02")
  2268. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2269. //今日的日期减去设置的日期
  2270. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2271. if cha_time >= advices.AdviceDate {
  2272. //查询审核是否允许
  2273. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2274. //申请状态不允许的情况 拒绝修改
  2275. if infor.ApplicationStatus != 1 {
  2276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2277. return
  2278. }
  2279. }
  2280. }
  2281. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  2282. //记录日志
  2283. byterequest, _ := json.Marshal(advices)
  2284. adviceLog := models.XtDoctorAdviceLog{
  2285. UserOrgId: adminUserInfo.Org.Id,
  2286. PatientId: advices.PatientId,
  2287. AdminUserId: advices.Checker,
  2288. Module: 3,
  2289. ErrLog: string(byterequest),
  2290. Status: 1,
  2291. Ctime: time.Now().Unix(),
  2292. Mtime: 0,
  2293. Source: "手机端核对医嘱",
  2294. RecordDate: advices.AdviceDate,
  2295. }
  2296. service.CreateDoctorAdviceLog(adviceLog)
  2297. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2298. redis := service.RedisClient()
  2299. //清空key 值
  2300. redis.Set(key, "", time.Second)
  2301. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2302. redis.Set(keyTwo, "", time.Second)
  2303. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2304. redis.Set(keyThree, "", time.Second)
  2305. recordDate := theTime.Format("2006-01-02")
  2306. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2307. redis.Set(keyFour, "", time.Second)
  2308. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2309. redis.Set(keyFive, "", time.Second)
  2310. defer redis.Close()
  2311. }
  2312. }
  2313. if err != nil {
  2314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2315. return
  2316. }
  2317. advice.Checker = checker
  2318. advice.CheckTime = theTime.Unix()
  2319. advice.CheckState = 1
  2320. c.ServeSuccessJSON(map[string]interface{}{
  2321. "msg": "ok",
  2322. "advice": advice,
  2323. })
  2324. } else if origin == 2 {
  2325. adminInfo := c.GetMobileAdminUserInfo()
  2326. var ids []string
  2327. advice_ids := c.GetString("advice_id")
  2328. ids = strings.Split(advice_ids, ",")
  2329. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  2330. var err error
  2331. for _, item := range advices {
  2332. if item.CheckState == 1 {
  2333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2334. return
  2335. }
  2336. if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
  2337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2338. return
  2339. }
  2340. item.Checker = adminInfo.AdminUser.Id
  2341. item.CheckTime = time.Now().Unix()
  2342. item.CheckState = 1
  2343. // 查询信息规挡的设置天数
  2344. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  2345. if infor.ID > 0 {
  2346. var cha_time int64
  2347. timeNowStr := time.Now().Format("2006-01-02")
  2348. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2349. //今日的日期减去设置的日期
  2350. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2351. if cha_time >= record_date {
  2352. //查询审核是否允许
  2353. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminInfo.Org.Id, 4)
  2354. //申请状态不允许的情况 拒绝修改
  2355. if infor.ApplicationStatus != 1 {
  2356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2357. return
  2358. }
  2359. }
  2360. }
  2361. err = service.SaveHisDoctorAdvice(item)
  2362. //记录日志
  2363. byterequest, _ := json.Marshal(advices)
  2364. adviceLog := models.XtDoctorAdviceLog{
  2365. UserOrgId: adminInfo.Org.Id,
  2366. PatientId: item.PatientId,
  2367. AdminUserId: item.Checker,
  2368. Module: 3,
  2369. ErrLog: string(byterequest),
  2370. Status: 1,
  2371. Ctime: time.Now().Unix(),
  2372. Mtime: 0,
  2373. Source: "手机端核对His医嘱",
  2374. RecordDate: item.AdviceDate,
  2375. }
  2376. service.CreateDoctorAdviceLog(adviceLog)
  2377. redis := service.RedisClient()
  2378. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2379. //清空key 值
  2380. redis.Set(key, "", time.Second)
  2381. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2382. redis.Set(keyTwo, "", time.Second)
  2383. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2384. redis.Set(keyThree, "", time.Second)
  2385. theTime := time.Now()
  2386. recordDate := theTime.Format("2006-01-02")
  2387. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  2388. redis.Set(keyFour, "", time.Second)
  2389. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2390. redis.Set(keyFive, "", time.Second)
  2391. defer redis.Close()
  2392. }
  2393. if err == nil {
  2394. c.ServeSuccessJSON(map[string]interface{}{
  2395. "msg": "ok",
  2396. "advice": advices,
  2397. })
  2398. } else {
  2399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2400. return
  2401. }
  2402. }
  2403. return
  2404. }
  2405. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  2406. id, _ := c.GetInt64("patient", 0)
  2407. assessmentDate := c.GetString("assessment_date", "")
  2408. if id <= 0 || len(assessmentDate) != 10 {
  2409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2410. return
  2411. }
  2412. timeLayout := "2006-01-02"
  2413. loc, _ := time.LoadLocation("Local")
  2414. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  2415. if err != nil {
  2416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2417. return
  2418. }
  2419. theAssessmentDateTime := theTime.Unix()
  2420. adminUserInfo := c.GetMobileAdminUserInfo()
  2421. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2422. if patient.ID == 0 {
  2423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2424. return
  2425. }
  2426. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  2427. if getPEErr != nil {
  2428. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  2429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2430. return
  2431. }
  2432. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2433. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2434. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2435. var evaluation models.PredialysisEvaluation
  2436. if theEvaluation != nil {
  2437. evaluation = *theEvaluation
  2438. }
  2439. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  2440. if code > 0 {
  2441. c.ServeFailJSONWithSGJErrorCode(code)
  2442. return
  2443. }
  2444. if theEvaluation == nil {
  2445. evaluation.CreatedTime = time.Now().Unix()
  2446. evaluation.Status = 1
  2447. evaluation.AssessmentDate = theAssessmentDateTime
  2448. evaluation.PatientId = id
  2449. evaluation.UserOrgId = adminUserInfo.Org.Id
  2450. if appRole.UserType == 2 || appRole.UserType == 1 {
  2451. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2452. evaluation.AssessmentTime = time.Now().Unix()
  2453. } else {
  2454. evaluation.Creater = adminUserInfo.AdminUser.Id
  2455. }
  2456. } else {
  2457. evaluation.UpdatedTime = time.Now().Unix()
  2458. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  2459. if appRole.UserType == 2 || appRole.UserType == 1 {
  2460. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2461. evaluation.AssessmentTime = time.Now().Unix()
  2462. } else {
  2463. evaluation.Modifier = adminUserInfo.AdminUser.Id
  2464. if evaluation.Creater == 0 {
  2465. evaluation.Creater = adminUserInfo.AdminUser.Id
  2466. }
  2467. }
  2468. }
  2469. //新增逻辑
  2470. var dewater_amount float64
  2471. dewater_amount = 0
  2472. if evaluation.DryWeight > 0 {
  2473. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2474. 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 {
  2475. if adminUserInfo.Org.Id != 10551 && adminUserInfo.Org.Id != 10579 && adminUserInfo.Org.Id != 10580 && adminUserInfo.Org.Id != 10585 {
  2476. dewater_amount = dewater_amount * 1000
  2477. }
  2478. }
  2479. if dewater_amount <= 0 {
  2480. dewater_amount = 0
  2481. }
  2482. } else {
  2483. dewater_amount = 0
  2484. }
  2485. // 计算透析处方的相关超滤量
  2486. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  2487. lastDialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient.ID, adminUserInfo.Org.Id)
  2488. var lastDialysisPrescribe *models.DialysisPrescription
  2489. var dialysisSolution *models.DialysisSolution
  2490. var dialysisPrescribe *models.DialysisPrescription
  2491. var system_dialysisPrescribe *models.SystemPrescription
  2492. var mode_id int64
  2493. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  2494. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  2495. if schedual != nil {
  2496. // 获取透析模版
  2497. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  2498. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  2499. mode_id = schedual.ModeId
  2500. } else {
  2501. // 获取透析模版
  2502. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  2503. if dialysisPrescribe == nil && dialysisSolution != nil {
  2504. mode_id = dialysisSolution.ModeId
  2505. }
  2506. if dialysisPrescribe == nil && dialysisSolution == nil {
  2507. mode_id = 0
  2508. }
  2509. }
  2510. // 插入透析处方
  2511. if dialysisPrescribe == nil && dialysisSolution != nil {
  2512. var newprescribe models.DialysisPrescription
  2513. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2514. newprescribe.PatientId = id
  2515. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2516. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2517. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2518. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2519. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2520. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2521. newprescribe.ModeId = dialysisSolution.ModeId
  2522. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2523. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2524. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2525. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2526. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2527. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2528. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2529. newprescribe.Glucose = dialysisSolution.Glucose
  2530. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2531. newprescribe.Kalium = dialysisSolution.Kalium
  2532. newprescribe.Sodium = dialysisSolution.Sodium
  2533. newprescribe.Calcium = dialysisSolution.Calcium
  2534. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2535. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2536. newprescribe.Conductivity = dialysisSolution.Conductivity
  2537. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2538. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2539. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2540. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2541. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2542. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2543. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2544. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2545. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2546. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2547. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2548. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2549. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2550. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2551. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2552. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2553. newprescribe.CreatedTime = time.Now().Unix()
  2554. newprescribe.UpdatedTime = time.Now().Unix()
  2555. newprescribe.RecordDate = theAssessmentDateTime
  2556. newprescribe.DewaterAmount = dewater_amount
  2557. newprescribe.TargetUltrafiltration = dewater_amount
  2558. newprescribe.Status = 1
  2559. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  2560. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  2561. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2562. newprescribe.Remark = lastDialysisPrescription.Remark
  2563. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2564. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2565. newprescribe.ID = dialysisPrescription.ID
  2566. if dialysisPrescription.ID == 0 {
  2567. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  2568. newprescribe.Sodium = 138
  2569. newprescribe.Bicarbonate = 31.1
  2570. newprescribe.DialysateFlow = 500
  2571. newprescribe.PrescribingNumber = 1
  2572. }
  2573. if adminUserInfo.Org.Id == 10579 {
  2574. newprescribe.Modifier = 0
  2575. newprescribe.Creater = 0
  2576. newprescribe.PrescriptionDoctor = 0
  2577. }
  2578. err := service.AddSigleRecord(&newprescribe)
  2579. //记录日志
  2580. byterequest, _ := json.Marshal(newprescribe)
  2581. prescriptionLog := models.XtDialysisPrescriptionLog{
  2582. UserOrgId: adminUserInfo.Org.Id,
  2583. Ctime: time.Now().Unix(),
  2584. Mtime: 0,
  2585. ErrLog: string(byterequest),
  2586. AdminUserId: adminUserInfo.AdminUser.Id,
  2587. RecordDate: newprescribe.RecordDate,
  2588. PatientId: id,
  2589. Source: "手机端新增透前评估插入处方",
  2590. Status: 1,
  2591. }
  2592. service.CreatePrescriptionLog(prescriptionLog)
  2593. //获取key,清空redis
  2594. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2595. redis := service.RedisClient()
  2596. //清空key 值
  2597. redis.Set(key, "", time.Second)
  2598. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2599. //清空key 值
  2600. redis.Set(keyOne, "", time.Second)
  2601. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2602. //清空key 值
  2603. redis.Set(keyTwo, "", time.Second)
  2604. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2605. redis.Set(keySix, "", time.Second)
  2606. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2607. redis.Set(keySeven, "", time.Second)
  2608. if err != nil {
  2609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2610. }
  2611. } else {
  2612. if adminUserInfo.Org.Id == 10340 {
  2613. newprescribe.Sodium = 138
  2614. newprescribe.Bicarbonate = 31.1
  2615. newprescribe.DialysateFlow = 500
  2616. }
  2617. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2618. //
  2619. if appRole.UserType == 2 || appRole.UserType == 1 {
  2620. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2621. if adminUserInfo.Org.Id == 9882 {
  2622. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2623. }
  2624. }
  2625. err := service.UpDateDialysisPrescription(&newprescribe)
  2626. //记录日志
  2627. byterequest, _ := json.Marshal(newprescribe)
  2628. prescriptionLog := models.XtDialysisPrescriptionLog{
  2629. UserOrgId: adminUserInfo.Org.Id,
  2630. Ctime: time.Now().Unix(),
  2631. Mtime: 0,
  2632. ErrLog: string(byterequest),
  2633. AdminUserId: adminUserInfo.AdminUser.Id,
  2634. RecordDate: newprescribe.RecordDate,
  2635. PatientId: id,
  2636. Source: "手机端新增透前评估插入处方",
  2637. Status: 1,
  2638. }
  2639. service.CreatePrescriptionLog(prescriptionLog)
  2640. //获取key,清空redis
  2641. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2642. redis := service.RedisClient()
  2643. //清空key 值
  2644. redis.Set(key, "", time.Second)
  2645. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2646. //清空key 值
  2647. redis.Set(keyOne, "", time.Second)
  2648. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2649. //清空key 值
  2650. redis.Set(keyTwo, "", time.Second)
  2651. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2652. redis.Set(keySix, "", time.Second)
  2653. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2654. redis.Set(keySeven, "", time.Second)
  2655. if err != nil {
  2656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2657. }
  2658. }
  2659. }
  2660. if dialysisPrescribe == nil && dialysisSolution == nil {
  2661. if lastDialysisPrescribe != nil {
  2662. var newprescribe models.DialysisPrescription
  2663. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2664. newprescribe.PatientId = id
  2665. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2666. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2667. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2668. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2669. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2670. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2671. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2672. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2673. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2674. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2675. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2676. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2677. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2678. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2679. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2680. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2681. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2682. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2683. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2684. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2685. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2686. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2687. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2688. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2689. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2690. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2691. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2692. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2693. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2694. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2695. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2696. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2697. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2698. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2699. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2700. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2701. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2702. newprescribe.CreatedTime = time.Now().Unix()
  2703. newprescribe.UpdatedTime = time.Now().Unix()
  2704. newprescribe.RecordDate = theAssessmentDateTime
  2705. newprescribe.DewaterAmount = dewater_amount
  2706. newprescribe.TargetUltrafiltration = dewater_amount
  2707. newprescribe.Status = 1
  2708. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  2709. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  2710. if dialysisSolution != nil && dialysisSolution.DialysisStrainer != "" {
  2711. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2712. }
  2713. newprescribe.Remark = lastDialysisPrescription.Remark
  2714. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2715. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2716. newprescribe.ID = dialysisPrescription.ID
  2717. if dialysisPrescription.ID == 0 {
  2718. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  2719. newprescribe.Sodium = 138
  2720. newprescribe.Bicarbonate = 31.1
  2721. newprescribe.DialysateFlow = 500
  2722. }
  2723. if adminUserInfo.Org.Id == 10579 {
  2724. newprescribe.Modifier = 0
  2725. newprescribe.Creater = 0
  2726. newprescribe.PrescriptionDoctor = 0
  2727. }
  2728. err := service.AddSigleRecord(&newprescribe)
  2729. //记录日志
  2730. byterequest, _ := json.Marshal(newprescribe)
  2731. prescriptionLog := models.XtDialysisPrescriptionLog{
  2732. UserOrgId: adminUserInfo.Org.Id,
  2733. Ctime: time.Now().Unix(),
  2734. Mtime: 0,
  2735. ErrLog: string(byterequest),
  2736. AdminUserId: adminUserInfo.AdminUser.Id,
  2737. RecordDate: newprescribe.RecordDate,
  2738. PatientId: id,
  2739. Source: "手机端新增透前评估插入处方",
  2740. Status: 1,
  2741. }
  2742. service.CreatePrescriptionLog(prescriptionLog)
  2743. //获取key,清空redis
  2744. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2745. redis := service.RedisClient()
  2746. //清空key 值
  2747. redis.Set(key, "", time.Second)
  2748. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2749. //清空key 值
  2750. redis.Set(keyOne, "", time.Second)
  2751. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2752. //清空key 值
  2753. redis.Set(keyTwo, "", time.Second)
  2754. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2755. redis.Set(keySix, "", time.Second)
  2756. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2757. redis.Set(keySeven, "", time.Second)
  2758. if err != nil {
  2759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2760. }
  2761. } else {
  2762. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2763. //
  2764. if appRole.UserType == 2 || appRole.UserType == 1 {
  2765. if adminUserInfo.Org.Id == 10579 {
  2766. newprescribe.Modifier = 0
  2767. newprescribe.Creater = 0
  2768. newprescribe.PrescriptionDoctor = 0
  2769. } else {
  2770. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2771. }
  2772. if adminUserInfo.Org.Id == 9882 {
  2773. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2774. }
  2775. }
  2776. err := service.UpDateDialysisPrescription(&newprescribe)
  2777. //记录日志
  2778. byterequest, _ := json.Marshal(newprescribe)
  2779. prescriptionLog := models.XtDialysisPrescriptionLog{
  2780. UserOrgId: adminUserInfo.Org.Id,
  2781. Ctime: time.Now().Unix(),
  2782. Mtime: 0,
  2783. ErrLog: string(byterequest),
  2784. AdminUserId: adminUserInfo.AdminUser.Id,
  2785. RecordDate: newprescribe.RecordDate,
  2786. PatientId: id,
  2787. Source: "手机端新增透前评估插入处方",
  2788. Status: 1,
  2789. }
  2790. service.CreatePrescriptionLog(prescriptionLog)
  2791. //获取key,清空redis
  2792. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2793. redis := service.RedisClient()
  2794. //清空key 值
  2795. redis.Set(key, "", time.Second)
  2796. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2797. //清空key 值
  2798. redis.Set(keyOne, "", time.Second)
  2799. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2800. //清空key 值
  2801. redis.Set(keyTwo, "", time.Second)
  2802. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2803. redis.Set(keySix, "", time.Second)
  2804. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2805. redis.Set(keySeven, "", time.Second)
  2806. if err != nil {
  2807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2808. }
  2809. }
  2810. if err != nil {
  2811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2812. }
  2813. } else if system_dialysisPrescribe != nil {
  2814. var newprescribe models.DialysisPrescription
  2815. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2816. newprescribe.PatientId = id
  2817. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  2818. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  2819. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  2820. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  2821. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  2822. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  2823. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  2824. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  2825. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  2826. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  2827. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  2828. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  2829. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  2830. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  2831. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  2832. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  2833. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  2834. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  2835. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  2836. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  2837. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  2838. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  2839. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  2840. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  2841. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  2842. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  2843. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  2844. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  2845. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  2846. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  2847. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  2848. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  2849. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  2850. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  2851. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  2852. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  2853. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  2854. newprescribe.CreatedTime = time.Now().Unix()
  2855. newprescribe.UpdatedTime = time.Now().Unix()
  2856. newprescribe.RecordDate = theAssessmentDateTime
  2857. newprescribe.DewaterAmount = dewater_amount
  2858. newprescribe.TargetUltrafiltration = dewater_amount
  2859. newprescribe.Status = 1
  2860. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  2861. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  2862. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2863. newprescribe.Remark = lastDialysisPrescription.Remark
  2864. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2865. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2866. newprescribe.ID = dialysisPrescription.ID
  2867. if dialysisPrescription.ID == 0 {
  2868. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  2869. newprescribe.Sodium = 138
  2870. newprescribe.Bicarbonate = 31.1
  2871. newprescribe.DialysateFlow = 500
  2872. }
  2873. if adminUserInfo.Org.Id == 10579 {
  2874. newprescribe.Modifier = 0
  2875. newprescribe.Creater = 0
  2876. newprescribe.PrescriptionDoctor = 0
  2877. }
  2878. err := service.AddSigleRecord(&newprescribe)
  2879. //记录日志
  2880. byterequest, _ := json.Marshal(newprescribe)
  2881. prescriptionLog := models.XtDialysisPrescriptionLog{
  2882. UserOrgId: adminUserInfo.Org.Id,
  2883. Ctime: time.Now().Unix(),
  2884. Mtime: 0,
  2885. ErrLog: string(byterequest),
  2886. AdminUserId: adminUserInfo.AdminUser.Id,
  2887. RecordDate: newprescribe.RecordDate,
  2888. PatientId: id,
  2889. Source: "手机端新增透前评估插入处方",
  2890. Status: 1,
  2891. }
  2892. service.CreatePrescriptionLog(prescriptionLog)
  2893. //获取key,清空redis
  2894. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2895. redis := service.RedisClient()
  2896. //清空key 值
  2897. redis.Set(key, "", time.Second)
  2898. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2899. //清空key 值
  2900. redis.Set(keyOne, "", time.Second)
  2901. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2902. //清空key 值
  2903. redis.Set(keyTwo, "", time.Second)
  2904. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2905. redis.Set(keySix, "", time.Second)
  2906. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2907. redis.Set(keySeven, "", time.Second)
  2908. if err != nil {
  2909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2910. }
  2911. } else {
  2912. if adminUserInfo.Org.Id == 10340 {
  2913. newprescribe.Sodium = 138
  2914. newprescribe.Bicarbonate = 31.1
  2915. newprescribe.DialysateFlow = 500
  2916. }
  2917. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2918. //
  2919. if appRole.UserType == 2 || appRole.UserType == 1 {
  2920. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2921. if adminUserInfo.Org.Id == 9882 {
  2922. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2923. }
  2924. }
  2925. err := service.UpDateDialysisPrescription(&newprescribe)
  2926. //记录日志
  2927. byterequest, _ := json.Marshal(newprescribe)
  2928. prescriptionLog := models.XtDialysisPrescriptionLog{
  2929. UserOrgId: adminUserInfo.Org.Id,
  2930. Ctime: time.Now().Unix(),
  2931. Mtime: 0,
  2932. ErrLog: string(byterequest),
  2933. AdminUserId: adminUserInfo.AdminUser.Id,
  2934. RecordDate: newprescribe.RecordDate,
  2935. PatientId: id,
  2936. Source: "手机端新增透前评估插入处方",
  2937. Status: 1,
  2938. }
  2939. service.CreatePrescriptionLog(prescriptionLog)
  2940. //获取key,清空redis
  2941. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2942. redis := service.RedisClient()
  2943. //清空key 值
  2944. redis.Set(key, "", time.Second)
  2945. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2946. //清空key 值
  2947. redis.Set(keyOne, "", time.Second)
  2948. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2949. //清空key 值
  2950. redis.Set(keyTwo, "", time.Second)
  2951. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2952. redis.Set(keySix, "", time.Second)
  2953. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2954. redis.Set(keySeven, "", time.Second)
  2955. if err != nil {
  2956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2957. }
  2958. }
  2959. if err != nil {
  2960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2961. }
  2962. } else {
  2963. var newprescribe models.DialysisPrescription
  2964. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2965. newprescribe.PatientId = id
  2966. newprescribe.ModeId = mode_id
  2967. newprescribe.CreatedTime = time.Now().Unix()
  2968. newprescribe.UpdatedTime = time.Now().Unix()
  2969. newprescribe.RecordDate = theAssessmentDateTime
  2970. newprescribe.DewaterAmount = dewater_amount
  2971. newprescribe.TargetUltrafiltration = dewater_amount
  2972. newprescribe.Status = 1
  2973. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2974. if dialysisPrescription.ID > 0 {
  2975. newprescribe.ID = dialysisPrescription.ID
  2976. }
  2977. if dialysisPrescription.ID == 0 {
  2978. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  2979. newprescribe.Sodium = 138
  2980. newprescribe.Bicarbonate = 31.1
  2981. newprescribe.DialysateFlow = 500
  2982. }
  2983. if adminUserInfo.Org.Id == 10579 {
  2984. newprescribe.Modifier = 0
  2985. newprescribe.Creater = 0
  2986. newprescribe.PrescriptionDoctor = 0
  2987. }
  2988. err := service.AddSigleRecord(&newprescribe)
  2989. //获取key,清空redis
  2990. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2991. redis := service.RedisClient()
  2992. //清空key 值
  2993. redis.Set(key, "", time.Second)
  2994. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2995. //清空key 值
  2996. redis.Set(keyOne, "", time.Second)
  2997. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2998. //清空key 值
  2999. redis.Set(keyTwo, "", time.Second)
  3000. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3001. redis.Set(keySix, "", time.Second)
  3002. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3003. redis.Set(keySeven, "", time.Second)
  3004. if err != nil {
  3005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3006. }
  3007. } else {
  3008. if adminUserInfo.Org.Id == 10340 {
  3009. newprescribe.Sodium = 138
  3010. newprescribe.Bicarbonate = 31.1
  3011. newprescribe.DialysateFlow = 500
  3012. }
  3013. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3014. //
  3015. if appRole.UserType == 2 || appRole.UserType == 1 {
  3016. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3017. if adminUserInfo.Org.Id == 9882 {
  3018. newprescribe.Creater = adminUserInfo.AdminUser.Id
  3019. }
  3020. }
  3021. if adminUserInfo.Org.Id == 10579 {
  3022. newprescribe.Modifier = 0
  3023. newprescribe.Creater = 0
  3024. newprescribe.PrescriptionDoctor = 0
  3025. }
  3026. err := service.UpDateDialysisPrescription(&newprescribe)
  3027. //记录日志
  3028. byterequest, _ := json.Marshal(newprescribe)
  3029. prescriptionLog := models.XtDialysisPrescriptionLog{
  3030. UserOrgId: adminUserInfo.Org.Id,
  3031. Ctime: time.Now().Unix(),
  3032. Mtime: 0,
  3033. ErrLog: string(byterequest),
  3034. AdminUserId: adminUserInfo.AdminUser.Id,
  3035. RecordDate: newprescribe.RecordDate,
  3036. PatientId: id,
  3037. Source: "手机端新增透前评估插入处方",
  3038. Status: 1,
  3039. }
  3040. service.CreatePrescriptionLog(prescriptionLog)
  3041. //获取key,清空redis
  3042. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3043. redis := service.RedisClient()
  3044. //清空key 值
  3045. redis.Set(key, "", time.Second)
  3046. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3047. //清空key 值
  3048. redis.Set(keyOne, "", time.Second)
  3049. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3050. //清空key 值
  3051. redis.Set(keyTwo, "", time.Second)
  3052. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3053. redis.Set(keySix, "", time.Second)
  3054. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3055. redis.Set(keySeven, "", time.Second)
  3056. if err != nil {
  3057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3058. }
  3059. }
  3060. if err != nil {
  3061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3062. }
  3063. }
  3064. }
  3065. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  3066. // if dialysisPrescribe != nil {
  3067. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  3068. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  3069. // dialysisPrescribe.DewaterAmount = dewater_amount
  3070. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  3071. // dialysisPrescribe.Status = 1
  3072. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  3073. // if updateErr != nil {
  3074. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3075. // }
  3076. // }
  3077. // 查询信息规挡的设置天数
  3078. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3079. if infor.ID > 0 && infor.WeekDay > 0 {
  3080. var cha_time int64
  3081. timeNowStr := time.Now().Format("2006-01-02")
  3082. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3083. //今日的日期减去设置的日期
  3084. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3085. if cha_time >= evaluation.AssessmentDate {
  3086. //查询审核是否允许
  3087. infor, _ := service.GetDialysisInformationByRecordDate(id, evaluation.AssessmentDate, adminUserInfo.Org.Id, 3)
  3088. //申请状态不允许的情况 拒绝修改
  3089. if infor.ApplicationStatus != 1 {
  3090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3091. return
  3092. }
  3093. }
  3094. }
  3095. //针对长沙南雅的问题
  3096. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10164 {
  3097. if len(evaluation.SymptomBeforeDialysis) == 0 {
  3098. predialysisEvaluation, _ := service.GetPredialysisEvaluation(id, adminUserInfo.Org.Id)
  3099. evaluation.SymptomBeforeDialysis = predialysisEvaluation.SymptomBeforeDialysis
  3100. }
  3101. }
  3102. err = service.UpadatePredialysisEvaluation(&evaluation)
  3103. //记录日志
  3104. byterequest, _ := json.Marshal(evaluation)
  3105. beforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  3106. UserOrgId: evaluation.UserOrgId,
  3107. AdminUserId: adminUserInfo.AdminUser.Id,
  3108. ErrLog: string(byterequest),
  3109. PatientId: evaluation.PatientId,
  3110. RecordDate: evaluation.AssessmentDate,
  3111. Ctime: time.Now().Unix(),
  3112. Mtime: 0,
  3113. Status: 1,
  3114. Source: "手机端保存透前评估",
  3115. }
  3116. service.CreateBeforLog(beforeDislysisLog)
  3117. finish := models.XtDialysisFinish{
  3118. IsFinish: 1,
  3119. UserOrgId: adminUserInfo.Org.Id,
  3120. Status: 1,
  3121. Ctime: time.Now().Unix(),
  3122. Mtime: 0,
  3123. Module: 3,
  3124. RecordDate: evaluation.AssessmentDate,
  3125. Sourse: 1,
  3126. PatientId: id,
  3127. }
  3128. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, evaluation.AssessmentDate, 3, id)
  3129. if dialysisFinish.ID == 0 {
  3130. service.CreateDialysisFinish(finish)
  3131. }
  3132. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  3133. redis := service.RedisClient()
  3134. defer redis.Close()
  3135. //清空key 值
  3136. redis.Set(key, "", time.Second)
  3137. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  3138. redis.Set(keyOne, "", time.Second)
  3139. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3140. redis.Set(keyTwo, "", time.Second)
  3141. if err != nil {
  3142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  3143. return
  3144. }
  3145. c.ServeSuccessJSON(map[string]interface{}{
  3146. "msg": "ok",
  3147. "evaluation": evaluation,
  3148. })
  3149. return
  3150. }
  3151. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3152. dataBody := make(map[string]interface{}, 0)
  3153. err := json.Unmarshal(data, &dataBody)
  3154. utils.InfoLog(string(data))
  3155. if err != nil {
  3156. utils.ErrorLog(err.Error())
  3157. code = enums.ErrorCodeParamWrong
  3158. return
  3159. }
  3160. // if method == "create" {
  3161. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  3162. utils.ErrorLog("mode")
  3163. code = enums.ErrorCodeParamWrong
  3164. return
  3165. }
  3166. mode := int64(dataBody["mode"].(float64))
  3167. if mode <= 0 {
  3168. utils.ErrorLog("mode <= 0")
  3169. code = enums.ErrorCodeParamWrong
  3170. return
  3171. }
  3172. solution.ModeId = mode
  3173. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  3174. utils.ErrorLog("mode_name")
  3175. code = enums.ErrorCodeParamWrong
  3176. return
  3177. }
  3178. modeName, _ := dataBody["mode_name"].(string)
  3179. if len(modeName) == 0 {
  3180. utils.ErrorLog("len(mode_name) == 0")
  3181. code = enums.ErrorCodeParamWrong
  3182. return
  3183. }
  3184. solution.ModeName = modeName
  3185. solution.Name = modeName
  3186. // }
  3187. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3188. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3189. solution.DialysisDuration = dialysisDuration
  3190. }
  3191. if dataBody["dialysis_duration"] != nil {
  3192. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3193. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3194. solution.DialysisDuration = dialysisDuration
  3195. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  3196. dialysisDuration := dataBody["dialysis_duration"].(float64)
  3197. solution.DialysisDuration = dialysisDuration
  3198. }
  3199. }
  3200. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  3201. dialyzer := int64(dataBody["dialyzer"].(float64))
  3202. solution.Dialyzer = dialyzer
  3203. }
  3204. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3205. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3206. solution.PerfusionApparatus = perfusionApparatus
  3207. }
  3208. if dataBody["blood_flow_volume"] != nil {
  3209. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3210. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3211. solution.BloodFlowVolume = bloodFlowVolume
  3212. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  3213. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  3214. solution.BloodFlowVolume = bloodFlowVolume
  3215. }
  3216. }
  3217. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3218. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3219. solution.HemodialysisMachine = hemodialysisMachine
  3220. }
  3221. if dataBody["dewater"] != nil {
  3222. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  3223. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  3224. solution.Dewater = dewater
  3225. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  3226. dewater := dataBody["dewater"].(float64)
  3227. solution.Dewater = dewater
  3228. }
  3229. }
  3230. if dataBody["replacement_total"] != nil {
  3231. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  3232. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  3233. solution.ReplacementTotal = replacementTotal
  3234. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  3235. replacementTotal := dataBody["replacement_total"].(float64)
  3236. solution.ReplacementTotal = replacementTotal
  3237. }
  3238. }
  3239. if dataBody["displace_liqui"] != nil {
  3240. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  3241. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  3242. solution.DisplaceLiqui = displaceLiqui
  3243. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  3244. displaceLiqui := dataBody["displace_liqui"].(float64)
  3245. solution.DisplaceLiqui = displaceLiqui
  3246. }
  3247. }
  3248. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3249. replacementWay := int64(dataBody["replacement_way"].(float64))
  3250. solution.ReplacementWay = replacementWay
  3251. }
  3252. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3253. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3254. solution.Anticoagulant = anticoagulant
  3255. }
  3256. if dataBody["anticoagulant_shouji"] != nil {
  3257. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3258. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3259. solution.AnticoagulantShouji = anticoagulantShouji
  3260. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  3261. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  3262. solution.AnticoagulantShouji = anticoagulantShouji
  3263. }
  3264. }
  3265. if dataBody["anticoagulant_weichi"] != nil {
  3266. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3267. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3268. solution.AnticoagulantWeichi = anticoagulantWeichi
  3269. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  3270. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  3271. solution.AnticoagulantWeichi = anticoagulantWeichi
  3272. }
  3273. }
  3274. if dataBody["anticoagulant_zongliang"] != nil {
  3275. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3276. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3277. solution.AnticoagulantZongliang = anticoagulantZongliang
  3278. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  3279. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  3280. solution.AnticoagulantZongliang = anticoagulantZongliang
  3281. }
  3282. }
  3283. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3284. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3285. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3286. }
  3287. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3288. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3289. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3290. }
  3291. if dataBody["kalium"] != nil {
  3292. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3293. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3294. solution.Kalium = kalium
  3295. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  3296. kalium := dataBody["kalium"].(float64)
  3297. solution.Kalium = kalium
  3298. }
  3299. }
  3300. if dataBody["sodium"] != nil {
  3301. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3302. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3303. solution.Sodium = sodium
  3304. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  3305. sodium := dataBody["sodium"].(float64)
  3306. solution.Sodium = sodium
  3307. }
  3308. }
  3309. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3310. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3311. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3312. solution.Calcium = calcium
  3313. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  3314. calcium := dataBody["calcium"].(float64)
  3315. solution.Calcium = calcium
  3316. }
  3317. }
  3318. if dataBody["bicarbonate"] != nil {
  3319. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3320. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3321. solution.Bicarbonate = bicarbonate
  3322. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  3323. bicarbonate := dataBody["bicarbonate"].(float64)
  3324. solution.Bicarbonate = bicarbonate
  3325. }
  3326. }
  3327. if dataBody["glucose"] != nil {
  3328. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  3329. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  3330. solution.Glucose = glucose
  3331. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  3332. glucose := dataBody["glucose"].(float64)
  3333. solution.Glucose = glucose
  3334. }
  3335. }
  3336. // if dataBody["dry_weight"] != nil {
  3337. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3338. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3339. // solution.DryWeight = dryWeight
  3340. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  3341. // dryWeight := dataBody["dry_weight"].(float64)
  3342. // solution.DryWeight = dryWeight
  3343. // }
  3344. // }
  3345. if dataBody["dialysate_flow"] != nil {
  3346. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3347. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3348. solution.DialysateFlow = dialysateFlow
  3349. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  3350. dialysateFlow := dataBody["dialysate_flow"].(float64)
  3351. solution.DialysateFlow = dialysateFlow
  3352. }
  3353. }
  3354. if dataBody["dialysate_temperature"] != nil {
  3355. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  3356. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  3357. solution.DialysateTemperature = dialysateTemperature
  3358. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  3359. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  3360. solution.DialysateTemperature = dialysateTemperature
  3361. }
  3362. }
  3363. if dataBody["conductivity"] != nil {
  3364. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  3365. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  3366. solution.Conductivity = conductivity
  3367. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  3368. conductivity := dataBody["conductivity"].(float64)
  3369. solution.Conductivity = conductivity
  3370. }
  3371. }
  3372. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3373. remark := dataBody["remark"].(string)
  3374. solution.Remark = remark
  3375. }
  3376. if dataBody["dialysis_duration_hour"] != nil {
  3377. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  3378. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  3379. solution.DialysisDurationHour = dialysisDurationHour
  3380. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  3381. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  3382. solution.DialysisDurationHour = int64(dialysisDurationHour)
  3383. }
  3384. }
  3385. if dataBody["dialysis_duration_minute"] != nil {
  3386. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  3387. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  3388. solution.DialysisDurationMinute = dialysisDurationMinute
  3389. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  3390. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  3391. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  3392. }
  3393. }
  3394. if dataBody["target_ultrafiltration"] != nil {
  3395. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  3396. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  3397. solution.TargetUltrafiltration = targetUltrafiltration
  3398. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  3399. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  3400. solution.TargetUltrafiltration = targetUltrafiltration
  3401. }
  3402. }
  3403. if dataBody["dialysate_formulation"] != nil {
  3404. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  3405. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  3406. solution.DialysateFormulation = dialysateFormulation
  3407. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  3408. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  3409. solution.DialysateFormulation = int64(dialysateFormulation)
  3410. }
  3411. }
  3412. return
  3413. }
  3414. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  3415. dataBody := make(map[string]interface{}, 0)
  3416. err := json.Unmarshal(data, &dataBody)
  3417. utils.InfoLog(string(data))
  3418. if err != nil {
  3419. utils.ErrorLog(err.Error())
  3420. code = enums.ErrorCodeParamWrong
  3421. return
  3422. }
  3423. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  3424. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  3425. evaluation.WeightBefore = weightVefore
  3426. }
  3427. // fmt.Println(dataBody["dry_weight"])
  3428. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  3429. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3430. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3431. fmt.Println(additionalWeight)
  3432. evaluation.DryWeight = additionalWeight
  3433. }
  3434. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  3435. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  3436. fmt.Println(additionalWeight)
  3437. evaluation.AdditionalWeight = additionalWeight
  3438. }
  3439. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  3440. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  3441. evaluation.Temperature = Temperature
  3442. }
  3443. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  3444. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  3445. evaluation.SystolicBloodPressure = systolicBloodPressure
  3446. }
  3447. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  3448. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  3449. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  3450. }
  3451. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  3452. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  3453. evaluation.PulseFrequency = pulseFrequency
  3454. }
  3455. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  3456. breathingRate := dataBody["breathing_rate"].(string)
  3457. evaluation.BreathingRate = breathingRate
  3458. }
  3459. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  3460. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  3461. evaluation.LastPostDialysis = lastPostDialysis
  3462. }
  3463. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  3464. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  3465. evaluation.DialysisInterphase = dialysisInterphase
  3466. }
  3467. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  3468. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  3469. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  3470. }
  3471. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  3472. catheter, _ := dataBody["catheter"].(string)
  3473. evaluation.Catheter = catheter
  3474. }
  3475. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  3476. catheter_bend := int(dataBody["catheter_bend"].(float64))
  3477. evaluation.CatheterBend = catheter_bend
  3478. }
  3479. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  3480. Complication, _ := dataBody["complication"].(string)
  3481. evaluation.Complication = Complication
  3482. }
  3483. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3484. remark := dataBody["remark"].(string)
  3485. evaluation.Remark = remark
  3486. }
  3487. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  3488. machine_type := dataBody["machine_type"].(string)
  3489. evaluation.MachineType = machine_type
  3490. }
  3491. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  3492. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  3493. evaluation.BloodAccessPartId = blood_access_part_id
  3494. }
  3495. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  3496. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  3497. // evaluation.BloodAccessPartId = blood_access_part_id
  3498. //}
  3499. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  3500. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  3501. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  3502. }
  3503. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  3504. internal_fistula, _ := dataBody["internal_fistula"].(string)
  3505. evaluation.InternalFistula = internal_fistula
  3506. }
  3507. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  3508. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  3509. evaluation.InternalFistulaSkin = internal_fistula_skin
  3510. }
  3511. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  3512. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  3513. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  3514. evaluation.IsHemorrhage = is_hemorrhage
  3515. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  3516. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  3517. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  3518. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  3519. is_hemorrhage = 0
  3520. }
  3521. evaluation.IsHemorrhage = is_hemorrhage
  3522. if is_hemorrhage == 1 {
  3523. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  3524. hemorrhage, _ := dataBody["hemorrhage"].(string)
  3525. evaluation.Hemorrhage = hemorrhage
  3526. }
  3527. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  3528. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  3529. evaluation.HemorrhageOther = hemorrhage_other
  3530. }
  3531. }
  3532. } else {
  3533. evaluation.IsHemorrhage = 0
  3534. }
  3535. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  3536. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  3537. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  3538. }
  3539. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  3540. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  3541. evaluation.InternalFistulaOther = internal_fistula_other
  3542. }
  3543. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  3544. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  3545. evaluation.BloodAccessNoise = blood_access_noise
  3546. }
  3547. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  3548. //puncture_way := int64(dataBody["puncture_way"].(float64))
  3549. puncture_way := dataBody["puncture_way"].(string)
  3550. evaluation.PunctureWay = puncture_way
  3551. }
  3552. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  3553. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  3554. evaluation.VenousCatheterization = venous_catheterization
  3555. }
  3556. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  3557. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  3558. evaluation.VenousCatheterizationPart = venous_catheterization_part
  3559. }
  3560. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  3561. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  3562. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  3563. }
  3564. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  3565. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  3566. evaluation.DuctusArantii = ductus_arantii
  3567. }
  3568. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  3569. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  3570. evaluation.EmergencyTreatment = emergency_treatment
  3571. }
  3572. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  3573. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  3574. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  3575. }
  3576. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  3577. dialysis_count, _ := dataBody["dialysis_count"].(string)
  3578. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  3579. evaluation.DialysisCount = dialysis_count
  3580. }
  3581. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  3582. is_infect, _ := dataBody["is_infect"].(string)
  3583. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  3584. evaluation.IsInfect = infect
  3585. }
  3586. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  3587. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  3588. evaluation.Exposed = exposed
  3589. }
  3590. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  3591. skin, _ := dataBody["skin"].(string)
  3592. //skins, _ := strconv.ParseInt(skin, 10, 64)
  3593. evaluation.Skin = skin
  3594. }
  3595. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  3596. skin_other, _ := dataBody["skin_other"].(string)
  3597. evaluation.SkinOther = skin_other
  3598. }
  3599. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  3600. infect_other, _ := dataBody["infect_other"].(string)
  3601. evaluation.InfectOther = infect_other
  3602. }
  3603. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  3604. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  3605. evaluation.DuctusArantiiOther = ductus_arantii_other
  3606. }
  3607. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  3608. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  3609. evaluation.PunctureNeedle = punctureNeedle
  3610. }
  3611. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  3612. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  3613. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  3614. }
  3615. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  3616. pinholing := dataBody["pinholing"].(string)
  3617. evaluation.Phinholing = pinholing
  3618. }
  3619. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  3620. catheter_suture := dataBody["catheter_suture"].(string)
  3621. evaluation.CatheterSuture = catheter_suture
  3622. }
  3623. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  3624. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  3625. evaluation.CatheterSutureOther = catheter_suture_other
  3626. }
  3627. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  3628. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  3629. evaluation.UrineVolume = urine_volume
  3630. }
  3631. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  3632. edema := dataBody["edema"].(string)
  3633. evaluation.Edema = edema
  3634. }
  3635. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  3636. specialTreatment := dataBody["special_treatment"].(string)
  3637. evaluation.SpecialTreatment = specialTreatment
  3638. }
  3639. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  3640. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  3641. evaluation.CatheterMaintenance = catheter_maintenance
  3642. }
  3643. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  3644. thromubusType := int64(dataBody["thromubus_type"].(float64))
  3645. evaluation.ThromubusType = thromubusType
  3646. }
  3647. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  3648. thrombus_av := dataBody["thrombus_av"].(string)
  3649. evaluation.ThrombusAv = thrombus_av
  3650. }
  3651. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  3652. thromubus_a := dataBody["thromubus_a"].(string)
  3653. evaluation.ThromubusA = thromubus_a
  3654. }
  3655. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  3656. thromubus_v := dataBody["thromubus_v"].(string)
  3657. evaluation.ThromubusV = thromubus_v
  3658. }
  3659. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  3660. dehydration := dataBody["dehydration"].(string)
  3661. evaluation.Dehydration = dehydration
  3662. }
  3663. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  3664. period := int64(dataBody["period"].(float64))
  3665. evaluation.Period = period
  3666. }
  3667. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  3668. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  3669. evaluation.EstimatedFoodIntake = estimated_food_intake
  3670. }
  3671. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  3672. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  3673. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  3674. }
  3675. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  3676. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  3677. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  3678. }
  3679. if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
  3680. urea_befor := dataBody["urea_befor"].(string)
  3681. evaluation.UreaBefor = urea_befor
  3682. }
  3683. if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
  3684. suction := dataBody["suction"].(string)
  3685. evaluation.Suction = suction
  3686. }
  3687. if dataBody["weight_befor_remake"] != nil && reflect.TypeOf(dataBody["weight_befor_remake"]).String() == "string" {
  3688. weight_befor_remake := dataBody["weight_befor_remake"].(string)
  3689. evaluation.WeightBeforRemake = weight_befor_remake
  3690. }
  3691. if dataBody["height"] != nil && reflect.TypeOf(dataBody["height"]).String() == "string" {
  3692. height := dataBody["height"].(string)
  3693. evaluation.Height = height
  3694. }
  3695. if dataBody["age"] != nil && reflect.TypeOf(dataBody["age"]).String() == "string" {
  3696. age := dataBody["age"].(string)
  3697. evaluation.Age = age
  3698. }
  3699. if dataBody["his_department"] != nil && reflect.TypeOf(dataBody["his_department"]).String() == "string" {
  3700. his_department := dataBody["his_department"].(string)
  3701. evaluation.HisDepartment = his_department
  3702. }
  3703. if dataBody["his_bed"] != nil && reflect.TypeOf(dataBody["his_bed"]).String() == "string" {
  3704. his_bed := dataBody["his_bed"].(string)
  3705. evaluation.HisBed = his_bed
  3706. }
  3707. if dataBody["point_puncture"] != nil && reflect.TypeOf(dataBody["point_puncture"]).String() == "string" {
  3708. point_puncture := dataBody["point_puncture"].(string)
  3709. evaluation.PointPuncture = point_puncture
  3710. }
  3711. if dataBody["catheter_evaluation_program"] != nil && reflect.TypeOf(dataBody["catheter_evaluation_program"]).String() == "string" {
  3712. catheter_evaluation_program := dataBody["catheter_evaluation_program"].(string)
  3713. evaluation.CatheterEvaluationProgram = catheter_evaluation_program
  3714. }
  3715. if dataBody["skin_site_catheterization"] != nil && reflect.TypeOf(dataBody["skin_site_catheterization"]).String() == "string" {
  3716. skin_site_catheterization := dataBody["skin_site_catheterization"].(string)
  3717. evaluation.SkinSiteCatheterization = skin_site_catheterization
  3718. }
  3719. if dataBody["whether_unobstructed"] != nil && reflect.TypeOf(dataBody["whether_unobstructed"]).String() == "float64" {
  3720. whether_unobstructed := int64(dataBody["whether_unobstructed"].(float64))
  3721. evaluation.WhetherUnobstructed = whether_unobstructed
  3722. }
  3723. if dataBody["lien_necessary"] != nil && reflect.TypeOf(dataBody["lien_necessary"]).String() == "float64" {
  3724. lien_necessary := int64(dataBody["lien_necessary"].(float64))
  3725. evaluation.LienNecessary = lien_necessary
  3726. }
  3727. if dataBody["pathway_formation_time"] != nil && reflect.TypeOf(dataBody["pathway_formation_time"]).String() == "string" {
  3728. pathway_formation_time := dataBody["pathway_formation_time"].(string)
  3729. timeLayout := "2006-01-02"
  3730. loc, _ := time.LoadLocation("Local")
  3731. var startTime int64
  3732. if len(pathway_formation_time) > 0 {
  3733. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  3734. startTime = theTime.Unix()
  3735. }
  3736. evaluation.PathwayFormationTime = startTime
  3737. }
  3738. if dataBody["befor_symptoms"] != nil && reflect.TypeOf(dataBody["befor_symptoms"]).String() == "string" {
  3739. befor_symptoms := dataBody["befor_symptoms"].(string)
  3740. evaluation.BeforSymptoms = befor_symptoms
  3741. }
  3742. if dataBody["washing_time"] != nil && reflect.TypeOf(dataBody["washing_time"]).String() == "string" {
  3743. washing_time, _ := dataBody["washing_time"].(string)
  3744. evaluation.WashingTime = washing_time
  3745. }
  3746. if dataBody["warsh_count"] != nil && reflect.TypeOf(dataBody["warsh_count"]).String() == "string" {
  3747. warsh_count, _ := dataBody["warsh_count"].(string)
  3748. evaluation.WarshCount = warsh_count
  3749. }
  3750. if dataBody["puncture_needle_direction"] != nil && reflect.TypeOf(dataBody["puncture_needle_direction"]).String() == "string" {
  3751. puncture_needle_direction, _ := dataBody["puncture_needle_direction"].(string)
  3752. evaluation.PunctureNeedleDirection = puncture_needle_direction
  3753. }
  3754. if dataBody["symptom_before_dialysis_other"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis_other"]).String() == "string" {
  3755. symptom_before_dialysis_other, _ := dataBody["symptom_before_dialysis_other"].(string)
  3756. evaluation.SymptomBeforeDialysisOther = symptom_before_dialysis_other
  3757. }
  3758. return
  3759. }
  3760. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  3761. dataBody := make(map[string]interface{}, 0)
  3762. err := json.Unmarshal(data, &dataBody)
  3763. if err != nil {
  3764. utils.ErrorLog(err.Error())
  3765. code = enums.ErrorCodeParamWrong
  3766. return
  3767. }
  3768. timeLayout := "2006-01-02"
  3769. loc, _ := time.LoadLocation("Local")
  3770. isChild := false
  3771. if action == "create" {
  3772. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3773. utils.ErrorLog("advice_type")
  3774. code = enums.ErrorCodeParamWrong
  3775. return
  3776. }
  3777. adviceType := int64(dataBody["advice_type"].(float64))
  3778. if adviceType != 1 && adviceType != 2 {
  3779. utils.ErrorLog("advice_type != 1&&2")
  3780. code = enums.ErrorCodeParamWrong
  3781. return
  3782. }
  3783. advice.AdviceType = adviceType
  3784. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3785. utils.ErrorLog("advice_date")
  3786. code = enums.ErrorCodeParamWrong
  3787. return
  3788. }
  3789. adviceDate, _ := dataBody["advice_date"].(string)
  3790. if len(adviceDate) == 0 {
  3791. utils.ErrorLog("len(adviceDate) == 0")
  3792. code = enums.ErrorCodeParamWrong
  3793. return
  3794. }
  3795. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3796. if err != nil {
  3797. utils.ErrorLog(err.Error())
  3798. code = enums.ErrorCodeParamWrong
  3799. return
  3800. }
  3801. advice.AdviceDate = theTime.Unix()
  3802. advice.RecordDate = theTime.Unix()
  3803. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  3804. parentId := int64(dataBody["parent_id"].(float64))
  3805. advice.ParentId = parentId
  3806. if parentId > 0 {
  3807. isChild = true
  3808. }
  3809. }
  3810. } else {
  3811. isChild = advice.ParentId > 0
  3812. }
  3813. if !isChild {
  3814. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3815. utils.ErrorLog("start_time")
  3816. code = enums.ErrorCodeParamWrong
  3817. return
  3818. }
  3819. startTime, _ := dataBody["start_time"].(string)
  3820. if len(startTime) == 0 {
  3821. utils.ErrorLog("len(start_time) == 0")
  3822. code = enums.ErrorCodeParamWrong
  3823. return
  3824. }
  3825. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  3826. if err != nil {
  3827. utils.ErrorLog(err.Error())
  3828. code = enums.ErrorCodeParamWrong
  3829. return
  3830. }
  3831. advice.StartTime = theTime.Unix()
  3832. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3833. deliveryWay, _ := dataBody["delivery_way"].(string)
  3834. advice.DeliveryWay = deliveryWay
  3835. }
  3836. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3837. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3838. advice.ExecutionFrequency = executionFrequency
  3839. }
  3840. }
  3841. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3842. deliveryWay, _ := dataBody["delivery_way"].(string)
  3843. advice.DeliveryWay = deliveryWay
  3844. }
  3845. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3846. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3847. advice.ExecutionFrequency = executionFrequency
  3848. }
  3849. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3850. utils.ErrorLog("advice_name")
  3851. code = enums.ErrorCodeParamWrong
  3852. return
  3853. }
  3854. adviceName, _ := dataBody["advice_name"].(string)
  3855. if len(adviceName) == 0 {
  3856. utils.ErrorLog("len(advice_name) == 0")
  3857. code = enums.ErrorCodeParamWrong
  3858. return
  3859. }
  3860. advice.AdviceName = adviceName
  3861. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3862. adviceDsc, _ := dataBody["advice_desc"].(string)
  3863. advice.AdviceDesc = adviceDsc
  3864. }
  3865. if dataBody["way"] == nil {
  3866. advice.Way = 0
  3867. } else {
  3868. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  3869. way := int64(dataBody["way"].(float64))
  3870. advice.Way = way
  3871. }
  3872. }
  3873. if dataBody["drug_id"] == nil {
  3874. advice.DrugId = 0
  3875. } else {
  3876. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  3877. drug_id := int64(dataBody["drug_id"].(float64))
  3878. advice.DrugId = drug_id
  3879. }
  3880. }
  3881. if dataBody["drug_name_id"] == nil {
  3882. advice.DrugNameId = 0
  3883. } else {
  3884. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  3885. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  3886. advice.DrugNameId = drug_name_id
  3887. }
  3888. }
  3889. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3890. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3891. advice.SingleDose = singleDose
  3892. }
  3893. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3894. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3895. advice.SingleDoseUnit = singleDoseUnit
  3896. }
  3897. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  3898. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  3899. advice.DrugSpec = drugSpec
  3900. }
  3901. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3902. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3903. advice.DrugSpecUnit = drugSpecUnit
  3904. }
  3905. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3906. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3907. advice.PrescribingNumber = prescribingNumber
  3908. }
  3909. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3910. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3911. advice.PrescribingNumberUnit = prescribingNumberUnit
  3912. }
  3913. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3914. remark, _ := dataBody["remark"].(string)
  3915. advice.Remark = remark
  3916. }
  3917. return
  3918. }
  3919. func (c *PatientApiController) GetPatientEducation() {
  3920. patientID, _ := c.GetInt64("patient_id", 0)
  3921. page, _ := c.GetInt64("page", 0)
  3922. limit, _ := c.GetInt64("limit", 0)
  3923. startTime := c.GetString("start_time", "")
  3924. endTime := c.GetString("end_time", "")
  3925. if page <= 0 {
  3926. page = 1
  3927. }
  3928. if limit <= 0 {
  3929. limit = 10
  3930. }
  3931. if patientID <= 0 {
  3932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3933. return
  3934. }
  3935. timeLayout := "2006-01-02"
  3936. loc, _ := time.LoadLocation("Local")
  3937. var theStartTIme int64
  3938. if len(startTime) > 0 {
  3939. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3940. if err != nil {
  3941. theStartTIme = 0
  3942. }
  3943. theStartTIme = theTime.Unix()
  3944. }
  3945. var theEndtTIme int64
  3946. if len(endTime) > 0 {
  3947. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3948. if err != nil {
  3949. theEndtTIme = 0
  3950. }
  3951. theEndtTIme = theTime.Unix()
  3952. }
  3953. adminUserInfo := c.GetMobileAdminUserInfo()
  3954. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  3955. c.ServeSuccessJSON(map[string]interface{}{
  3956. "total": total,
  3957. "edus": edus,
  3958. })
  3959. return
  3960. }
  3961. func (c *PatientApiController) GetPatientSchedulesList() {
  3962. patientID, _ := c.GetInt64("patient_id", 0)
  3963. page, _ := c.GetInt64("page", 0)
  3964. limit, _ := c.GetInt64("limit", 0)
  3965. if patientID <= 0 {
  3966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3967. return
  3968. }
  3969. adminUserInfo := c.GetMobileAdminUserInfo()
  3970. todayTime := time.Now().Format("2006-01-02")
  3971. timeLayout := "2006-01-02 15:04:05"
  3972. loc, _ := time.LoadLocation("Local")
  3973. var theStartTime int64
  3974. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  3975. theStartTime = theTime.Unix()
  3976. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  3977. if len(schedules) > 0 {
  3978. for index, item := range schedules {
  3979. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  3980. schedules[index].Week = int64(week)
  3981. }
  3982. }
  3983. c.ServeSuccessJSON(map[string]interface{}{
  3984. "schedules": schedules,
  3985. })
  3986. return
  3987. }
  3988. func (c *PatientApiController) GetRecords() {
  3989. patientID, _ := c.GetInt64("patient_id", 0)
  3990. page, _ := c.GetInt64("page", 0)
  3991. limit, _ := c.GetInt64("limit", 0)
  3992. startTime := c.GetString("start_time", "")
  3993. endTime := c.GetString("end_time", "")
  3994. mode_id, _ := c.GetInt64("mode_id", 0)
  3995. if page <= 0 {
  3996. page = 1
  3997. }
  3998. if limit <= 0 {
  3999. limit = 10
  4000. }
  4001. if patientID <= 0 {
  4002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4003. return
  4004. }
  4005. timeLayout := "2006-01-02"
  4006. loc, _ := time.LoadLocation("Local")
  4007. var theStartTIme int64
  4008. if len(startTime) > 0 {
  4009. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4010. if err != nil {
  4011. theStartTIme = 0
  4012. }
  4013. theStartTIme = theTime.Unix()
  4014. }
  4015. var theEndtTIme int64
  4016. if len(endTime) > 0 {
  4017. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4018. if err != nil {
  4019. theEndtTIme = 0
  4020. }
  4021. theEndtTIme = theTime.Unix()
  4022. }
  4023. adminUserInfo := c.GetMobileAdminUserInfo()
  4024. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  4025. c.ServeSuccessJSON(map[string]interface{}{
  4026. "total": total,
  4027. "records": records,
  4028. })
  4029. return
  4030. }
  4031. func (c *PatientApiController) GetPatientMonitor() {
  4032. partition, _ := c.GetInt64("partition")
  4033. monitorDate := c.GetString("date")
  4034. patient_id, _ := c.GetInt64("patient_id")
  4035. timeLayout := "2006-01-02"
  4036. loc, _ := time.LoadLocation("Local")
  4037. var theStartTime int64
  4038. if len(monitorDate) > 0 {
  4039. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  4040. if err != nil {
  4041. theStartTime = 0
  4042. }
  4043. theStartTime = theTime.Unix()
  4044. }
  4045. adminInfo := c.GetMobileAdminUserInfo()
  4046. orgID := adminInfo.Org.Id
  4047. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  4048. if err != nil {
  4049. c.ErrorLog("获取排班信息失败:%v", err)
  4050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4051. } else {
  4052. if len(monitor) > 0 {
  4053. //获取所有床位
  4054. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  4055. //获取所有分区
  4056. zoneList, _ := service.GetAllZoneByList(orgID)
  4057. //获取透析处方
  4058. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  4059. //获取透前评估
  4060. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  4061. //获取上机
  4062. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  4063. //获取透后
  4064. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  4065. //获取透后监测
  4066. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  4067. //获取所有的患者
  4068. patients, _ := service.GetAllPatientListByListOne(orgID)
  4069. for _, it := range patients {
  4070. if orgID == 10445 {
  4071. if theStartTime <= 1703952000 {
  4072. listOne, _ := service.GetDialysisOrderCountTwentyEight(orgID, it.ID, theStartTime)
  4073. it.TotalDialysis = listOne.Count
  4074. }
  4075. if theStartTime >= 1704038400 {
  4076. listOrder, _ := service.GetDialysisOrderCountTenEight(it.ID, theStartTime)
  4077. it.TotalDialysis = listOrder.Count
  4078. }
  4079. }
  4080. }
  4081. //获取所有透析模式
  4082. treatments, _ := service.GetAllTreatModeByList(orgID)
  4083. for key, item := range monitor {
  4084. // 获取床位信息
  4085. for _, it := range numberList {
  4086. if item.BedId == it.ID {
  4087. monitor[key].DeviceNumber = it
  4088. break
  4089. }
  4090. }
  4091. //获取分区信息
  4092. for _, it := range zoneList {
  4093. if item.PartitionId == it.ID {
  4094. monitor[key].DeviceZone = it
  4095. }
  4096. }
  4097. for _, prescription := range prescriptions {
  4098. if item.PatientId == prescription.PatientId {
  4099. monitor[key].Prescription = prescription
  4100. break
  4101. }
  4102. }
  4103. // 透前评估
  4104. for _, assessmentBefore := range assessmentBefores {
  4105. if item.PatientId == assessmentBefore.PatientId {
  4106. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  4107. break
  4108. }
  4109. }
  4110. // 透析上下机
  4111. for _, dialysisOrder := range dialysisOrders {
  4112. if item.PatientId == dialysisOrder.PatientId {
  4113. monitor[key].DialysisOrder = dialysisOrder
  4114. break
  4115. }
  4116. }
  4117. // 治疗小节
  4118. for _, afterDislysis := range AssessmentAfterDislysis {
  4119. if item.PatientId == afterDislysis.PatientId {
  4120. monitor[key].AssessmentAfterDislysis = afterDislysis
  4121. break
  4122. }
  4123. }
  4124. for _, it := range monitorlist {
  4125. if item.PatientId == it.PatientId {
  4126. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  4127. }
  4128. }
  4129. for _, patient := range patients {
  4130. if item.PatientId == patient.ID {
  4131. monitor[key].MonitorPatients = patient
  4132. break
  4133. }
  4134. }
  4135. for _, treatment := range treatments {
  4136. if item.ModeId == treatment.ID {
  4137. monitor[key].TreatmentMode = treatment
  4138. break
  4139. }
  4140. }
  4141. }
  4142. }
  4143. }
  4144. //获取患者的透析次数
  4145. //count, err := service.GetDialysisCount(orgID, partition)
  4146. patients, err := service.GetAllpatientFourty(orgID)
  4147. if err == nil {
  4148. c.ServeSuccessJSON(map[string]interface{}{
  4149. "monitor": monitor,
  4150. //"patientCount": count,
  4151. "patients": patients,
  4152. })
  4153. } else {
  4154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4155. }
  4156. }
  4157. // /m/api/monitor/patient [get] 搜索病人的测量记录
  4158. // @param keyword:string 病人姓名或透析号
  4159. // @param page:int
  4160. func (this *PatientApiController) SearchMonitorPatient() {
  4161. keyword := this.GetString("keyword")
  4162. page, _ := this.GetInt("page")
  4163. if page <= 0 {
  4164. page = 1
  4165. }
  4166. if len(keyword) == 0 {
  4167. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4168. return
  4169. }
  4170. adminUserInfo := this.GetMobileAdminUserInfo()
  4171. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  4172. if getMonitorErr != nil {
  4173. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4174. return
  4175. } else {
  4176. this.ServeSuccessJSON(map[string]interface{}{
  4177. "monitor": monitors,
  4178. })
  4179. }
  4180. }
  4181. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  4182. id, _ := c.GetInt64("id", 0)
  4183. page, _ := c.GetInt64("page", 0)
  4184. limit, _ := c.GetInt64("limit", 0)
  4185. if id <= 0 {
  4186. c.ServeSuccessJSON(map[string]interface{}{
  4187. "solutions": nil,
  4188. })
  4189. return
  4190. }
  4191. if page <= 0 {
  4192. page = 1
  4193. }
  4194. if limit <= 0 {
  4195. limit = 10
  4196. }
  4197. adminInfo := c.GetMobileAdminUserInfo()
  4198. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  4199. c.ServeSuccessJSON(map[string]interface{}{
  4200. "solutions": solutions,
  4201. "total": total,
  4202. })
  4203. return
  4204. }
  4205. // GetDoctorAdvices 医嘱列表
  4206. func (c *PatientApiController) GetDoctorAdvices() {
  4207. id, _ := c.GetInt64("id", 0)
  4208. adviceType, _ := c.GetInt64("advice_type", 0)
  4209. stopType, _ := c.GetInt64("stop_state", 0)
  4210. startTime := c.GetString("start_time", "")
  4211. endTime := c.GetString("end_time", "")
  4212. keywords := c.GetString("keywords", "")
  4213. need, _ := c.GetInt64("need_doctor", 0)
  4214. adminUserInfo := c.GetMobileAdminUserInfo()
  4215. timeLayout := "2006-01-02"
  4216. loc, _ := time.LoadLocation("Local")
  4217. var theStartTIme int64
  4218. if len(startTime) > 0 {
  4219. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4220. if err != nil {
  4221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4222. return
  4223. }
  4224. theStartTIme = theTime.Unix()
  4225. }
  4226. var theEndtTIme int64
  4227. if len(endTime) > 0 {
  4228. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4229. if err != nil {
  4230. utils.ErrorLog(err.Error())
  4231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4232. return
  4233. }
  4234. theEndtTIme = theTime.Unix()
  4235. }
  4236. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  4237. if need == 1 {
  4238. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4239. c.ServeSuccessJSON(map[string]interface{}{
  4240. "advices": advices,
  4241. "total": total,
  4242. "users": users,
  4243. })
  4244. } else {
  4245. c.ServeSuccessJSON(map[string]interface{}{
  4246. "advices": advices,
  4247. "total": total,
  4248. "users": []string{},
  4249. })
  4250. }
  4251. return
  4252. }
  4253. func (c *PatientApiController) GetPrintDialysisOrder() {
  4254. xtno := c.GetString("xtno")
  4255. xtdate := c.GetString("xtdate")
  4256. timeLayout := "2006-01-02"
  4257. loc, _ := time.LoadLocation("Local")
  4258. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  4259. if err != nil {
  4260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4261. return
  4262. }
  4263. xttime := theTime.Unix()
  4264. //获取当前日期月份的第一天
  4265. firstmonth := service.GetFirstDateOfMonth(theTime)
  4266. firstMonthDate := firstmonth.Unix()
  4267. operatorIDs := make([]int64, 0)
  4268. adminUserInfo := c.GetMobileAdminUserInfo()
  4269. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4270. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  4271. //透析单
  4272. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4273. if dialysisOrder != nil {
  4274. if dialysisOrder.FinishNurse > 0 {
  4275. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  4276. }
  4277. if dialysisOrder.StartNurse > 0 {
  4278. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  4279. }
  4280. }
  4281. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4282. //透前评估
  4283. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4284. //透后评估
  4285. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4286. if AssessmentAfterDislysis.Modifier > 0 {
  4287. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  4288. }
  4289. //透析处方
  4290. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4291. if dialysisPrescription.PrescriptionDoctor > 0 {
  4292. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  4293. }
  4294. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4295. patientInfo.TotalDialysis = dialysis_count
  4296. //临时医嘱
  4297. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4298. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4299. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  4300. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  4301. lastSchedule, _ := service.FindLastSchedule(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4302. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4303. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  4304. for _, item := range projects {
  4305. cnt, _ := strconv.ParseFloat(item.Count, 64)
  4306. var advice models.HisDoctorAdviceInfo
  4307. advice.ID = item.ID
  4308. advice.Checker = item.Checker
  4309. advice.CheckTime = item.CheckTime
  4310. advice.CheckState = item.CheckState
  4311. advice.ExecutionState = item.ExecutionState
  4312. advice.ExecutionStaff = item.ExecutionStaff
  4313. //advice.PrescribingNumber = float64(item.Count)
  4314. advice.PrescribingNumber = cnt
  4315. advice.PrescribingNumberUnit = item.Unit
  4316. advice.AdviceDoctor = item.Doctor
  4317. if item.Type == 3 {
  4318. advice.AdviceName = item.GoodInfo.GoodName
  4319. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  4320. } else if item.Type == 2 {
  4321. advice.AdviceName = item.HisProject.ProjectName
  4322. }
  4323. advice.StartTime = item.StartTime
  4324. hisAdvice = append(hisAdvice, &advice)
  4325. }
  4326. }
  4327. if len(DoctorAdvice) > 0 {
  4328. for _, item := range DoctorAdvice {
  4329. if item.AdviceDoctor > 0 {
  4330. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  4331. }
  4332. if item.ExecutionStaff > 0 {
  4333. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  4334. }
  4335. if item.Checker > 0 {
  4336. operatorIDs = append(operatorIDs, item.Checker)
  4337. }
  4338. }
  4339. }
  4340. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4341. //透析监测
  4342. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4343. //透析小结
  4344. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4345. //接诊评估
  4346. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4347. //相关操作对应的操作人
  4348. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  4349. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  4350. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4351. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4352. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  4353. lastWeight, _ := service.MobileGetLast(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4354. if config.IsOpen == 1 {
  4355. c.ServeSuccessJSON(map[string]interface{}{
  4356. "users": adminUser,
  4357. "patientInfo": patientInfo,
  4358. "PredialysisEvaluation": PredialysisEvaluation,
  4359. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4360. "dialysisPrescription": dialysisPrescription,
  4361. "advices": hisAdvice,
  4362. "monitors": Record,
  4363. "summary": TreatmentSummary,
  4364. "receiverTreatmentAccess": receiverTreatmentAccess,
  4365. "dialysisOrder": dialysisOrder,
  4366. "operators": operators,
  4367. "org_template_info": templateInfo,
  4368. "check": check,
  4369. "dialysiscount": dialysiscount,
  4370. "last_order": last_order,
  4371. "projects": projects,
  4372. "project_config": project_config,
  4373. "lastWeight": lastWeight,
  4374. "lastSchedule": lastSchedule,
  4375. "DoctorAdvice": DoctorAdvice,
  4376. "hisAdvice": hisAdvice,
  4377. })
  4378. }
  4379. if config.IsOpen == 0 || config.IsOpen == 2 {
  4380. c.ServeSuccessJSON(map[string]interface{}{
  4381. "users": adminUser,
  4382. "patientInfo": patientInfo,
  4383. "PredialysisEvaluation": PredialysisEvaluation,
  4384. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4385. "dialysisPrescription": dialysisPrescription,
  4386. "advices": DoctorAdvice,
  4387. "monitors": Record,
  4388. "summary": TreatmentSummary,
  4389. "receiverTreatmentAccess": receiverTreatmentAccess,
  4390. "dialysisOrder": dialysisOrder,
  4391. "operators": operators,
  4392. "org_template_info": templateInfo,
  4393. "check": check,
  4394. "dialysiscount": dialysiscount,
  4395. "last_order": last_order,
  4396. "projects": projects,
  4397. "project_config": project_config,
  4398. "lastWeight": lastWeight,
  4399. "lastSchedule": lastSchedule,
  4400. "DoctorAdvice": DoctorAdvice,
  4401. "hisAdvice": hisAdvice,
  4402. })
  4403. }
  4404. }
  4405. func (c *PatientApiController) CreateGroupAdvice() {
  4406. is_child, _ := c.GetInt64("is_child", 0)
  4407. if is_child == 1 {
  4408. patient, _ := c.GetInt64("id", 0)
  4409. if patient <= 0 {
  4410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4411. return
  4412. }
  4413. adminUserInfo := c.GetMobileAdminUserInfo()
  4414. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  4415. if patientInfo.ID == 0 {
  4416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4417. return
  4418. }
  4419. group_no, _ := c.GetInt64("group_no")
  4420. if group_no <= 0 {
  4421. group_no = 0
  4422. }
  4423. dataBody := make(map[string]interface{}, 0)
  4424. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4425. if err != nil {
  4426. utils.ErrorLog(err.Error())
  4427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4428. return
  4429. }
  4430. timeLayout := "2006-01-02"
  4431. loc, _ := time.LoadLocation("Local")
  4432. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4433. utils.ErrorLog("advice_type")
  4434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4435. return
  4436. }
  4437. adviceType := int64(dataBody["advice_type"].(float64))
  4438. if adviceType != 1 && adviceType != 2 {
  4439. utils.ErrorLog("advice_type != 1&&2")
  4440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4441. return
  4442. }
  4443. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4444. utils.ErrorLog("start_time")
  4445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4446. return
  4447. }
  4448. startTime2, _ := dataBody["start_time"].(string)
  4449. time_arr := strings.Split(startTime2, " ")
  4450. if len(time_arr) > 0 {
  4451. startTime2 = time_arr[0]
  4452. }
  4453. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4454. utils.ErrorLog("advice_date")
  4455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4456. return
  4457. }
  4458. advice_date, _ := dataBody["advice_date"].(string)
  4459. var advicedateunix int64
  4460. if len(advice_date) > 0 {
  4461. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  4462. if err != nil {
  4463. fmt.Println(err)
  4464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4465. return
  4466. }
  4467. advicedateunix = theTime.Unix()
  4468. }
  4469. adviceDate := startTime2
  4470. if len(adviceDate) == 0 {
  4471. utils.ErrorLog("len(adviceDate) == 0")
  4472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4473. return
  4474. }
  4475. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4476. if err != nil {
  4477. utils.ErrorLog(err.Error())
  4478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4479. return
  4480. }
  4481. AdviceDate := advicedateunix
  4482. RecordDate := advicedateunix
  4483. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4484. utils.ErrorLog("start_time")
  4485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4486. return
  4487. }
  4488. startTime, _ := dataBody["start_time"].(string)
  4489. if len(startTime) == 0 {
  4490. utils.ErrorLog("len(start_time) == 0")
  4491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4492. return
  4493. }
  4494. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  4495. theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
  4496. if err != nil {
  4497. utils.ErrorLog(err.Error())
  4498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4499. return
  4500. }
  4501. StartTime := theTime.Unix()
  4502. Remark := ""
  4503. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4504. remark, _ := dataBody["remark"].(string)
  4505. Remark = remark
  4506. }
  4507. Startdate := int64(dataBody["record_date"].(float64))
  4508. var advices []*models.GroupAdvice
  4509. // utils.TraceLog("%+v", dataBody["adviceNames"])
  4510. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  4511. utils.ErrorLog("adviceNames")
  4512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4513. return
  4514. }
  4515. adviceNames := dataBody["adviceNames"].([]interface{})
  4516. for _, adviceNameMap := range adviceNames {
  4517. adviceNameM := adviceNameMap.(map[string]interface{})
  4518. var advice models.GroupAdvice
  4519. advice.Remark = Remark
  4520. advice.AdviceType = adviceType
  4521. advice.StartTime = StartTime
  4522. if adminUserInfo.Org.Id == 10340 {
  4523. advice.AdviceDate = AdviceDate
  4524. advice.RecordDate = RecordDate
  4525. }
  4526. if adminUserInfo.Org.Id != 10340 {
  4527. advice.AdviceDate = theTimeOne.Unix()
  4528. advice.RecordDate = theTimeOne.Unix()
  4529. }
  4530. advice.Status = 1
  4531. advice.CreatedTime = time.Now().Unix()
  4532. advice.UpdatedTime = time.Now().Unix()
  4533. advice.StopState = 2
  4534. advice.ExecutionState = 2
  4535. advice.UserOrgId = adminUserInfo.Org.Id
  4536. advice.PatientId = patientInfo.ID
  4537. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4538. advice.IsSettle = 2
  4539. //入口
  4540. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  4541. if errcode > 0 {
  4542. c.ServeFailJSONWithSGJErrorCode(errcode)
  4543. return
  4544. }
  4545. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  4546. subdrugs := adviceNameM["subdrugs"].([]interface{})
  4547. if len(subdrugs) > 0 {
  4548. for _, subdrug := range subdrugs {
  4549. var s models.GroupAdvice
  4550. s.Remark = Remark
  4551. s.AdviceType = adviceType
  4552. s.StartTime = StartTime
  4553. s.AdviceDate = AdviceDate
  4554. s.RecordDate = RecordDate
  4555. s.Status = 1
  4556. s.CreatedTime = time.Now().Unix()
  4557. s.UpdatedTime = time.Now().Unix()
  4558. s.StopState = 2
  4559. s.ExecutionState = 2
  4560. s.UserOrgId = adminUserInfo.Org.Id
  4561. s.PatientId = patientInfo.ID
  4562. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  4563. s.IsSettle = 2
  4564. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  4565. if errcode > 0 {
  4566. c.ServeFailJSONWithSGJErrorCode(errcode)
  4567. return
  4568. }
  4569. advice.Children = append(advice.Children, &s)
  4570. }
  4571. }
  4572. }
  4573. //长沙南雅
  4574. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  4575. //查询该患者今日有没有双人核对
  4576. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, RecordDate)
  4577. if check.ID > 0 {
  4578. advice.Checker = check.Modifier
  4579. advice.CheckState = 1
  4580. advice.CheckTime = time.Now().Unix()
  4581. }
  4582. }
  4583. advices = append(advices, &advice)
  4584. }
  4585. // 查询信息规挡的设置天数
  4586. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4587. if infor.ID > 0 && infor.WeekDay > 0 {
  4588. var cha_time int64
  4589. timeNowStr := time.Now().Format("2006-01-02")
  4590. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4591. //今日的日期减去设置的日期
  4592. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4593. if cha_time >= Startdate {
  4594. //查询审核是否允许
  4595. infor, _ := service.GetDialysisInformationByRecordDate(patient, Startdate, adminUserInfo.Org.Id, 5)
  4596. //申请状态不允许的情况 拒绝修改
  4597. if infor.ApplicationStatus != 1 {
  4598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4599. return
  4600. }
  4601. }
  4602. }
  4603. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  4604. for _, item := range advices {
  4605. //记录日志
  4606. byterequest, _ := json.Marshal(item)
  4607. adviceLog := models.XtDoctorAdviceLog{
  4608. UserOrgId: item.UserOrgId,
  4609. PatientId: item.PatientId,
  4610. AdminUserId: adminUserInfo.AdminUser.Id,
  4611. Module: 1,
  4612. ErrLog: string(byterequest),
  4613. Status: 1,
  4614. Ctime: time.Now().Unix(),
  4615. Mtime: 0,
  4616. Source: "手机端新增医嘱",
  4617. RecordDate: item.AdviceDate,
  4618. }
  4619. service.CreateDoctorAdviceLog(adviceLog)
  4620. }
  4621. finish := models.XtDialysisFinish{
  4622. IsFinish: 1,
  4623. UserOrgId: adminUserInfo.Org.Id,
  4624. Status: 1,
  4625. Ctime: time.Now().Unix(),
  4626. Mtime: 0,
  4627. Module: 4,
  4628. RecordDate: advicedateunix,
  4629. Sourse: 1,
  4630. PatientId: patient,
  4631. }
  4632. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, advicedateunix, 4, patient)
  4633. if dialysisFinish.ID == 0 {
  4634. service.CreateDialysisFinish(finish)
  4635. }
  4636. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  4637. redis := service.RedisClient()
  4638. //清空key 值
  4639. redis.Set(key, "", time.Second)
  4640. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4641. redis.Set(keyOne, "", time.Second)
  4642. defer redis.Close()
  4643. if createErr != nil {
  4644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4645. return
  4646. }
  4647. c.ServeSuccessJSON(map[string]interface{}{
  4648. "msg": "ok",
  4649. "advices": newAdvices,
  4650. })
  4651. return
  4652. } else if is_child == 2 {
  4653. patient, _ := c.GetInt64("id", 0)
  4654. if patient <= 0 {
  4655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4656. return
  4657. }
  4658. adminUserInfo := c.GetMobileAdminUserInfo()
  4659. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  4660. if patientInfo.ID == 0 {
  4661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4662. return
  4663. }
  4664. var advice models.DoctorAdvice
  4665. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  4666. if code > 0 {
  4667. c.ServeFailJSONWithSGJErrorCode(code)
  4668. return
  4669. }
  4670. if advice.ParentId > 0 {
  4671. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  4672. if old.ID == 0 || old.PatientId != patient {
  4673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  4674. return
  4675. }
  4676. if old.StopState == 1 || old.ExecutionState == 1 {
  4677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  4678. return
  4679. }
  4680. if old.ParentId > 0 {
  4681. advice.ParentId = old.ParentId
  4682. }
  4683. advice.StartTime = old.StartTime
  4684. advice.AdviceDoctor = old.AdviceDoctor
  4685. advice.DeliveryWay = old.DeliveryWay
  4686. advice.ExecutionFrequency = old.ExecutionFrequency
  4687. advice.GroupNo = old.GroupNo
  4688. }
  4689. advice.Status = 1
  4690. advice.CreatedTime = time.Now().Unix()
  4691. advice.UpdatedTime = time.Now().Unix()
  4692. advice.StopState = 2
  4693. advice.ExecutionState = 2
  4694. advice.UserOrgId = adminUserInfo.Org.Id
  4695. advice.PatientId = patient
  4696. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4697. advice.IsSettle = 2
  4698. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  4699. if advice.PrescribingNumber == 0 {
  4700. advice.PrescribingNumber = 1
  4701. }
  4702. //查询该患者今日有没有双人核对
  4703. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, advice.AdviceDate)
  4704. if check.ID > 0 {
  4705. advice.Checker = check.Modifier
  4706. advice.CheckState = 1
  4707. advice.CheckTime = time.Now().Unix()
  4708. }
  4709. }
  4710. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4711. if infor.ID > 0 {
  4712. var cha_time int64
  4713. timeNowStr := time.Now().Format("2006-01-02")
  4714. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4715. //今日的日期减去设置的日期
  4716. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4717. if cha_time >= advice.RecordDate {
  4718. //查询审核是否允许
  4719. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.RecordDate, adminUserInfo.Org.Id, 4)
  4720. //申请状态不允许的情况 拒绝修改
  4721. if infor.ApplicationStatus != 1 {
  4722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4723. return
  4724. }
  4725. }
  4726. }
  4727. err := service.CreateDoctorAdvice(&advice)
  4728. //记录日志
  4729. byterequest, _ := json.Marshal(advice)
  4730. adviceLog := models.XtDoctorAdviceLog{
  4731. UserOrgId: advice.UserOrgId,
  4732. PatientId: advice.PatientId,
  4733. AdminUserId: adminUserInfo.Org.Id,
  4734. Module: 1,
  4735. ErrLog: string(byterequest),
  4736. Status: 1,
  4737. Ctime: time.Now().Unix(),
  4738. Mtime: 0,
  4739. Source: "手机端新增医嘱",
  4740. RecordDate: advice.AdviceDate,
  4741. }
  4742. service.CreateDoctorAdviceLog(adviceLog)
  4743. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  4744. redis := service.RedisClient()
  4745. //清空key 值
  4746. redis.Set(key, "", time.Second)
  4747. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  4748. redis.Set(keyOne, "", time.Second)
  4749. defer redis.Close()
  4750. if err != nil {
  4751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4752. return
  4753. }
  4754. c.ServeSuccessJSON(map[string]interface{}{
  4755. "msg": "ok",
  4756. "advice": advice,
  4757. })
  4758. return
  4759. }
  4760. }
  4761. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  4762. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  4763. utils.ErrorLog("advice_name")
  4764. return enums.ErrorCodeParamWrong
  4765. }
  4766. adviceName, _ := json["advice_name"].(string)
  4767. if len(adviceName) == 0 {
  4768. utils.ErrorLog("len(advice_name) == 0")
  4769. return enums.ErrorCodeParamWrong
  4770. }
  4771. advice.AdviceName = adviceName
  4772. adviceDesc, _ := json["advice_desc"].(string)
  4773. advice.AdviceDesc = adviceDesc
  4774. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4775. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4776. advice.DrugSpec = drugSpec
  4777. }
  4778. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4779. remark, _ := json["remark"].(string)
  4780. advice.Remark = remark
  4781. }
  4782. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  4783. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  4784. // advice.Way = src_type
  4785. //}
  4786. if json["way"] == nil {
  4787. advice.Way = 0
  4788. } else {
  4789. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  4790. way := int64(json["way"].(float64))
  4791. advice.Way = way
  4792. }
  4793. }
  4794. if json["drug_id"] == nil {
  4795. advice.DrugId = 0
  4796. } else {
  4797. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  4798. drug_id := int64(json["drug_id"].(float64))
  4799. advice.DrugId = drug_id
  4800. }
  4801. }
  4802. if json["drug_name_id"] == nil {
  4803. advice.DrugNameId = 0
  4804. } else {
  4805. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  4806. drug_name_id := int64(json["drug_name_id"].(float64))
  4807. advice.DrugNameId = drug_name_id
  4808. }
  4809. }
  4810. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  4811. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  4812. advice.DrugSpecUnit = drugSpecUnit
  4813. }
  4814. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4815. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4816. advice.SingleDose = singleDose
  4817. }
  4818. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4819. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4820. advice.SingleDoseUnit = singleDoseUnit
  4821. }
  4822. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4823. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4824. advice.PrescribingNumber = prescribingNumber
  4825. }
  4826. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4827. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4828. advice.PrescribingNumberUnit = prescribingNumberUnit
  4829. }
  4830. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4831. deliveryWay, _ := json["delivery_way"].(string)
  4832. advice.DeliveryWay = deliveryWay
  4833. }
  4834. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4835. executionFrequency, _ := json["execution_frequency"].(string)
  4836. advice.ExecutionFrequency = executionFrequency
  4837. }
  4838. return 0
  4839. }
  4840. func (c *PatientApiController) DelDoctorAdvice() {
  4841. groupno, _ := c.GetInt64("groupno", -1)
  4842. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  4843. patient_id, _ := c.GetInt64("patient_id")
  4844. doc_advice_date, _ := c.GetInt64("advice_date")
  4845. redis := service.RedisClient()
  4846. if is_sub == 1 { //是
  4847. advice_id, _ := c.GetInt64("advice_id")
  4848. adminUserInfo := c.GetMobileAdminUserInfo()
  4849. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  4850. if advice.ID == 0 {
  4851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4852. return
  4853. }
  4854. advice.Status = 0
  4855. advice.UpdatedTime = time.Now().Unix()
  4856. advice.Modifier = adminUserInfo.AdminUser.Id
  4857. // 查询信息规挡的设置天数
  4858. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4859. if infor.ID > 0 && infor.WeekDay > 0 {
  4860. var cha_time int64
  4861. timeNowStr := time.Now().Format("2006-01-02")
  4862. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4863. //今日的日期减去设置的日期
  4864. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4865. if cha_time >= advice.AdviceDate {
  4866. //查询审核是否允许
  4867. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  4868. //申请状态不允许的情况 拒绝修改
  4869. if infor.ApplicationStatus != 1 {
  4870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4871. return
  4872. }
  4873. }
  4874. }
  4875. err := service.DeleteDoctorAdvice(&advice)
  4876. //记录日志
  4877. byterequest, _ := json.Marshal(advice)
  4878. adviceLog := models.XtDoctorAdviceLog{
  4879. UserOrgId: advice.UserOrgId,
  4880. PatientId: advice.PatientId,
  4881. AdminUserId: adminUserInfo.AdminUser.Id,
  4882. Module: 4,
  4883. ErrLog: string(byterequest),
  4884. Status: 1,
  4885. Ctime: time.Now().Unix(),
  4886. Mtime: 0,
  4887. Source: "手机端删除医嘱",
  4888. RecordDate: advice.RecordDate,
  4889. }
  4890. service.CreateDoctorAdviceLog(adviceLog)
  4891. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4892. redis.Set(key, "", time.Second)
  4893. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4894. redis.Set(keyTwo, "", time.Second)
  4895. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4896. redis.Set(keyThree, "", time.Second)
  4897. redis.Close()
  4898. if err != nil {
  4899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4900. return
  4901. }
  4902. c.ServeSuccessJSON(map[string]interface{}{
  4903. "msg": "ok",
  4904. })
  4905. return
  4906. } else { //
  4907. var ids []string
  4908. if groupno == 0 {
  4909. advice_id := c.GetString("advice_id")
  4910. ids = strings.Split(advice_id, ",")
  4911. if len(ids) <= 0 {
  4912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4913. return
  4914. }
  4915. }
  4916. if groupno < 0 {
  4917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4918. return
  4919. }
  4920. adminUserInfo := c.GetMobileAdminUserInfo()
  4921. var advice models.DoctorAdvice
  4922. if groupno > 0 {
  4923. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  4924. if advice.ID == 0 {
  4925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4926. return
  4927. }
  4928. } else {
  4929. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  4930. for _, item := range advices {
  4931. if item.ID == 0 {
  4932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4933. return
  4934. }
  4935. }
  4936. }
  4937. advice.UpdatedTime = time.Now().Unix()
  4938. advice.Status = 0
  4939. advice.GroupNo = groupno
  4940. advice.Modifier = adminUserInfo.AdminUser.Id
  4941. var err error
  4942. if groupno > 0 {
  4943. // 查询信息规挡的设置天数
  4944. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4945. if infor.ID > 0 {
  4946. var cha_time int64
  4947. timeNowStr := time.Now().Format("2006-01-02")
  4948. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4949. //今日的日期减去设置的日期
  4950. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4951. if cha_time >= advice.AdviceDate {
  4952. //查询审核是否允许
  4953. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  4954. //申请状态不允许的情况 拒绝修改
  4955. if infor.ApplicationStatus != 1 {
  4956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4957. return
  4958. }
  4959. }
  4960. }
  4961. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  4962. //记录日志
  4963. byterequest, _ := json.Marshal(advice)
  4964. adviceLog := models.XtDoctorAdviceLog{
  4965. UserOrgId: advice.UserOrgId,
  4966. PatientId: advice.PatientId,
  4967. AdminUserId: adminUserInfo.AdminUser.Id,
  4968. Module: 4,
  4969. ErrLog: string(byterequest),
  4970. Status: 1,
  4971. Ctime: time.Now().Unix(),
  4972. Mtime: 0,
  4973. Source: "手机端删除医嘱",
  4974. RecordDate: advice.RecordDate,
  4975. }
  4976. service.CreateDoctorAdviceLog(adviceLog)
  4977. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4978. redis.Set(key, "", time.Second)
  4979. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4980. redis.Set(keyTwo, "", time.Second)
  4981. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4982. redis.Set(keyThree, "", time.Second)
  4983. } else {
  4984. // 查询信息规挡的设置天数
  4985. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4986. if infor.ID > 0 {
  4987. var cha_time int64
  4988. timeNowStr := time.Now().Format("2006-01-02")
  4989. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4990. //今日的日期减去设置的日期
  4991. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4992. if cha_time >= advice.AdviceDate {
  4993. //查询审核是否允许
  4994. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  4995. //申请状态不允许的情况 拒绝修改
  4996. if infor.ApplicationStatus != 1 {
  4997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4998. return
  4999. }
  5000. }
  5001. }
  5002. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  5003. advicelist, _ := service.GetBatchDoctorAdviceList(ids, adminUserInfo.Org.Id)
  5004. for _, item := range advicelist {
  5005. //记录日志
  5006. byterequest, _ := json.Marshal(item)
  5007. adviceLog := models.XtDoctorAdviceLog{
  5008. UserOrgId: item.UserOrgId,
  5009. PatientId: item.PatientId,
  5010. AdminUserId: adminUserInfo.AdminUser.Id,
  5011. Module: 4,
  5012. ErrLog: string(byterequest),
  5013. Status: 1,
  5014. Ctime: time.Now().Unix(),
  5015. Mtime: 0,
  5016. Source: "手机端批量删除医嘱",
  5017. RecordDate: item.RecordDate,
  5018. }
  5019. service.CreateDoctorAdviceLog(adviceLog)
  5020. }
  5021. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5022. redis.Set(key, "", time.Second)
  5023. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5024. redis.Set(keyTwo, "", time.Second)
  5025. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5026. redis.Set(keyThree, "", time.Second)
  5027. redis.Close()
  5028. }
  5029. if err != nil {
  5030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5031. return
  5032. }
  5033. c.ServeSuccessJSON(map[string]interface{}{
  5034. "msg": "ok",
  5035. })
  5036. return
  5037. }
  5038. }
  5039. // /m/api/advice/group/modify_starttime [post]
  5040. // @param group_no:int
  5041. // @param start_time:string yyyy-MM-dd hh:mm:ss
  5042. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  5043. group_no, _ := this.GetInt64("group_no")
  5044. start_time_str := this.GetString("start_time")
  5045. if group_no <= 0 || len(start_time_str) == 0 {
  5046. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5047. return
  5048. }
  5049. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  5050. if parseTimeErr != nil {
  5051. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  5052. return
  5053. }
  5054. adminUserInfo := this.GetMobileAdminUserInfo()
  5055. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  5056. if updateStartTimeErr != nil {
  5057. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  5058. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5059. return
  5060. }
  5061. this.ServeSuccessJSON(map[string]interface{}{
  5062. "start_time": startTime.Unix(),
  5063. })
  5064. }
  5065. func (this *PatientApiController) DelSubDoctorAdvice() {
  5066. advice_id, _ := this.GetInt64("advice_id")
  5067. adminUserInfo := this.GetMobileAdminUserInfo()
  5068. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  5069. if advice.ID == 0 {
  5070. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5071. return
  5072. }
  5073. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  5074. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  5075. // return
  5076. //}
  5077. advice.Status = 0
  5078. advice.UpdatedTime = time.Now().Unix()
  5079. advice.Modifier = adminUserInfo.AdminUser.Id
  5080. err := service.DeleteDoctorAdvice(&advice)
  5081. if err != nil {
  5082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5083. return
  5084. }
  5085. this.ServeSuccessJSON(map[string]interface{}{
  5086. "msg": "ok",
  5087. })
  5088. return
  5089. }
  5090. func (this *PatientApiController) GetAdviceUnReadMessage() {
  5091. //adminUserInfo := this.GetMobileAdminUserInfo()
  5092. //service.FindUnReadDoctorAdviceMessage()
  5093. }
  5094. func (this *PatientApiController) GetPatientsByKeyWord() {
  5095. keyWord := this.GetString("keyword")
  5096. adminUserInfo := this.GetMobileAdminUserInfo()
  5097. today := utils.ZeroHourTimeOfDay(time.Now())
  5098. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  5099. if err != nil {
  5100. utils.ErrorLog(err.Error())
  5101. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5102. return
  5103. }
  5104. this.ServeSuccessJSON(map[string]interface{}{
  5105. "patient": patient,
  5106. })
  5107. }
  5108. func (this *PatientApiController) GetSearchPatient() {
  5109. keyWord := this.GetString("keyword")
  5110. adminUserInfo := this.GetMobileAdminUserInfo()
  5111. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  5112. if err != nil {
  5113. utils.ErrorLog(err.Error())
  5114. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5115. return
  5116. }
  5117. this.ServeSuccessJSON(map[string]interface{}{
  5118. "patient": patient,
  5119. })
  5120. }
  5121. func (c *PatientApiController) ExecProject() {
  5122. execution_time := c.GetString("execution_time")
  5123. project_id, _ := c.GetInt64("project_id")
  5124. team_id, _ := c.GetInt64("team_id")
  5125. is_check_team, _ := c.GetInt64("is_check_team")
  5126. if len(execution_time) <= 0 {
  5127. utils.ErrorLog("execution_time")
  5128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5129. return
  5130. }
  5131. timeLayout2 := "2006-01-02 15:04:05"
  5132. loc, _ := time.LoadLocation("Local")
  5133. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  5134. if errs != nil {
  5135. utils.ErrorLog(errs.Error())
  5136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5137. return
  5138. }
  5139. adminInfo := c.GetMobileAdminUserInfo()
  5140. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  5141. if project.Type == 3 {
  5142. good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
  5143. if good.IsUser != 1 {
  5144. //查询开关是否开启
  5145. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  5146. //开关已经开启
  5147. if stockSetting.IsType == 1 {
  5148. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  5149. scheduleDateStart := theTime.Format("2006-01-02")
  5150. timeLayout3 := "2006-01-02"
  5151. loc, _ := time.LoadLocation("Local")
  5152. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  5153. //查询该耗材是否已经出库
  5154. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  5155. if auto.ID == 0 {
  5156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  5157. return
  5158. }
  5159. }
  5160. }
  5161. if good.IsUser == 1 && good.IsWarehouse == 1 {
  5162. //查询开关是否开启
  5163. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  5164. //开关已经开启
  5165. if stockSetting.IsType == 1 {
  5166. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  5167. scheduleDateStart := theTime.Format("2006-01-02")
  5168. timeLayout3 := "2006-01-02"
  5169. loc, _ := time.LoadLocation("Local")
  5170. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  5171. //查询该耗材是否已经出库
  5172. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  5173. if auto.ID == 0 {
  5174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  5175. return
  5176. }
  5177. }
  5178. }
  5179. }
  5180. if project.ExecutionState == 1 {
  5181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  5182. return
  5183. }
  5184. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  5185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  5186. return
  5187. }
  5188. project.ExecutionState = 1
  5189. project.ExecutionStaff = adminInfo.AdminUser.Id
  5190. project.ExecutionTime = theTime.Unix()
  5191. if team_id == 0 {
  5192. // 查询信息规挡的设置天数
  5193. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5194. if infor.ID > 0 {
  5195. var cha_time int64
  5196. timeNowStr := time.Now().Format("2006-01-02")
  5197. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5198. //今日的日期减去设置的日期
  5199. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5200. if cha_time >= project.RecordDate {
  5201. //查询审核是否允许
  5202. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5203. //申请状态不允许的情况 拒绝修改
  5204. if infor.ApplicationStatus != 1 {
  5205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5206. return
  5207. }
  5208. }
  5209. }
  5210. err := service.SaveHisProject(&project)
  5211. if err == nil {
  5212. c.ServeSuccessJSON(map[string]interface{}{
  5213. "project": project,
  5214. })
  5215. } else {
  5216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5217. return
  5218. }
  5219. } else {
  5220. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  5221. // 查询信息规挡的设置天数
  5222. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5223. if infor.ID > 0 {
  5224. var cha_time int64
  5225. timeNowStr := time.Now().Format("2006-01-02")
  5226. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5227. //今日的日期减去设置的日期
  5228. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5229. if cha_time >= project.RecordDate {
  5230. //查询审核是否允许
  5231. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5232. //申请状态不允许的情况 拒绝修改
  5233. if infor.ApplicationStatus != 1 {
  5234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5235. return
  5236. }
  5237. }
  5238. }
  5239. err := service.SaveHisProject(&project)
  5240. if err == nil {
  5241. c.ServeSuccessJSON(map[string]interface{}{
  5242. "project": project,
  5243. })
  5244. } else {
  5245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5246. return
  5247. }
  5248. } else {
  5249. // 查询信息规挡的设置天数
  5250. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5251. if infor.ID > 0 {
  5252. var cha_time int64
  5253. timeNowStr := time.Now().Format("2006-01-02")
  5254. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5255. //今日的日期减去设置的日期
  5256. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5257. if cha_time >= project.RecordDate {
  5258. //查询审核是否允许
  5259. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5260. //申请状态不允许的情况 拒绝修改
  5261. if infor.ApplicationStatus != 1 {
  5262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5263. return
  5264. }
  5265. }
  5266. }
  5267. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  5268. var ids []int64
  5269. for _, items := range ps {
  5270. ids = append(ids, items.ID)
  5271. }
  5272. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  5273. if err == nil {
  5274. c.ServeSuccessJSON(map[string]interface{}{
  5275. "project": project,
  5276. })
  5277. } else {
  5278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5279. return
  5280. }
  5281. }
  5282. }
  5283. }
  5284. func (c *PatientApiController) CheckProject() {
  5285. adminInfo := c.GetMobileAdminUserInfo()
  5286. project_id, _ := c.GetInt64("project_id")
  5287. team_id, _ := c.GetInt64("team_id")
  5288. is_check_team, _ := c.GetInt64("is_check_team")
  5289. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  5290. if project.CheckState == 1 {
  5291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  5292. return
  5293. }
  5294. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  5295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  5296. return
  5297. }
  5298. project.Checker = adminInfo.AdminUser.Id
  5299. project.CheckTime = time.Now().Unix()
  5300. project.CheckState = 1
  5301. if team_id == 0 {
  5302. // 查询信息规挡的设置天数
  5303. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5304. if infor.ID > 0 {
  5305. var cha_time int64
  5306. timeNowStr := time.Now().Format("2006-01-02")
  5307. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5308. //今日的日期减去设置的日期
  5309. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5310. if cha_time >= project.RecordDate {
  5311. //查询审核是否允许
  5312. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5313. //申请状态不允许的情况 拒绝修改
  5314. if infor.ApplicationStatus != 1 {
  5315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5316. return
  5317. }
  5318. }
  5319. }
  5320. err := service.SaveHisProject(&project)
  5321. if err == nil {
  5322. c.ServeSuccessJSON(map[string]interface{}{
  5323. "msg": "ok",
  5324. "project": project,
  5325. })
  5326. } else {
  5327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5328. return
  5329. }
  5330. } else {
  5331. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  5332. // 查询信息规挡的设置天数
  5333. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5334. if infor.ID > 0 {
  5335. var cha_time int64
  5336. timeNowStr := time.Now().Format("2006-01-02")
  5337. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5338. //今日的日期减去设置的日期
  5339. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5340. if cha_time >= project.RecordDate {
  5341. //查询审核是否允许
  5342. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5343. //申请状态不允许的情况 拒绝修改
  5344. if infor.ApplicationStatus != 1 {
  5345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5346. return
  5347. }
  5348. }
  5349. }
  5350. err := service.SaveHisProject(&project)
  5351. if err == nil {
  5352. c.ServeSuccessJSON(map[string]interface{}{
  5353. "msg": "ok",
  5354. "project": project,
  5355. })
  5356. } else {
  5357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5358. return
  5359. }
  5360. } else {
  5361. // 查询信息规挡的设置天数
  5362. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5363. if infor.ID > 0 {
  5364. var cha_time int64
  5365. timeNowStr := time.Now().Format("2006-01-02")
  5366. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5367. //今日的日期减去设置的日期
  5368. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5369. if cha_time >= project.RecordDate {
  5370. //查询审核是否允许
  5371. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5372. //申请状态不允许的情况 拒绝修改
  5373. if infor.ApplicationStatus != 1 {
  5374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5375. return
  5376. }
  5377. }
  5378. }
  5379. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  5380. var ids []int64
  5381. for _, items := range ps {
  5382. ids = append(ids, items.ID)
  5383. }
  5384. err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
  5385. if err == nil {
  5386. c.ServeSuccessJSON(map[string]interface{}{
  5387. "project": project,
  5388. })
  5389. } else {
  5390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5391. return
  5392. }
  5393. }
  5394. }
  5395. }