patient_api_controller.go 204KB

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