patient_api_controller.go 205KB

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