his_api_controller.go 243KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828
  1. package controllers
  2. import "C"
  3. import (
  4. "XT_New/enums"
  5. "XT_New/models"
  6. "XT_New/service"
  7. "XT_New/utils"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "github.com/shopspring/decimal"
  13. "math/rand"
  14. "reflect"
  15. "strconv"
  16. "strings"
  17. "syscall"
  18. "time"
  19. "unsafe"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. //beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  27. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  28. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  29. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  30. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  31. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  32. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  33. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  34. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  35. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  36. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  37. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  38. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  41. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  42. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  43. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  44. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  45. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  46. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  47. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  48. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  49. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  51. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  52. //新增附加费用
  53. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  54. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  55. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  56. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  57. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  58. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  59. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  60. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  61. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  62. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  63. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  64. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  65. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  66. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  67. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  68. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  69. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  70. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  71. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  72. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  73. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  74. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  75. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  76. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  77. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  78. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  79. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  80. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. }
  83. func (c *PublicApiController) GetBaiLinExportData() {
  84. data := service.GetBaiLinOrderData()
  85. fmt.Println(len(data))
  86. var new_data []*models.NewCustomHisOrder
  87. for _, item := range data {
  88. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  89. new_data = append(new_data, item)
  90. }
  91. }
  92. fmt.Println(len(new_data))
  93. c.ServeSuccessJSON(map[string]interface{}{
  94. "list": new_data,
  95. })
  96. }
  97. func (c *HisApiController) GetHisUnChargePatientList() {
  98. record_date := c.GetString("record_date")
  99. timeLayout := "2006-01-02"
  100. loc, _ := time.LoadLocation("Local")
  101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  102. if err != nil {
  103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  104. return
  105. }
  106. recordDateTime := theTime.Unix()
  107. adminInfo := c.GetAdminUserInfo()
  108. var tempPatients []*service.NewTempPatients
  109. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  110. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  111. var patients []*service.NewTempPatients
  112. var patients_two []*service.NewTempPatients
  113. for _, item := range tempPatients {
  114. //过滤掉没挂号的和没开处方的
  115. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  116. patients = append(patients, item)
  117. }
  118. //过滤掉没挂号的
  119. if len(item.HisPatient) > 0 {
  120. patients_two = append(patients_two, item)
  121. }
  122. }
  123. c.ServeSuccessJSON(map[string]interface{}{
  124. "list": patients,
  125. "list_two": patients_two,
  126. })
  127. }
  128. func (c *HisApiController) GetPrivateExpensesOrder() {
  129. //id, _ := c.GetInt64("id")
  130. //record_time := c.GetString("record_time")
  131. order_id, _ := c.GetInt64("order_id")
  132. admin_user_id, _ := c.GetInt64("admin_user_id")
  133. //timeLayout := "2006-01-02"
  134. //loc, _ := time.LoadLocation("Local")
  135. //
  136. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  137. //if err != nil {
  138. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. // return
  140. //}
  141. //recordDateTime := theTime.Unix()
  142. adminUser := c.GetAdminUserInfo()
  143. order, _ := service.GetHisOrderByID(order_id)
  144. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  145. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  146. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  147. //var config []*models.HisXtDiagnoseConfig
  148. var name string
  149. for _, item := range diagnosis_ids {
  150. id, _ := strconv.ParseInt(item, 10, 64)
  151. diagnosisConfig, _ := service.FindDiagnoseById(id)
  152. if len(name) == 0 {
  153. name = diagnosisConfig.ClassName
  154. } else {
  155. name = name + "," + diagnosisConfig.ClassName
  156. }
  157. }
  158. decimal.DivisionPrecision = 2
  159. for _, item := range orderInfos {
  160. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  161. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  162. item.MedChrgitmType = "09"
  163. }
  164. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  165. if item.HisPrescriptionProject.Type == 2 {
  166. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  167. case 1:
  168. item.MedChrgitmType = "14"
  169. break
  170. case 2:
  171. item.MedChrgitmType = "05"
  172. break
  173. case 3:
  174. item.MedChrgitmType = "04"
  175. break
  176. case 4:
  177. item.MedChrgitmType = "14"
  178. break
  179. case 5:
  180. item.MedChrgitmType = "08"
  181. break
  182. case 6:
  183. item.MedChrgitmType = "14"
  184. break
  185. case 7:
  186. item.MedChrgitmType = "14"
  187. break
  188. case 8:
  189. item.MedChrgitmType = "03"
  190. break
  191. case 9:
  192. item.MedChrgitmType = "14"
  193. break
  194. }
  195. } else if item.HisPrescriptionProject.Type == 3 {
  196. item.MedChrgitmType = "08"
  197. }
  198. }
  199. }
  200. order.PsnCashPay = order.MedfeeSumamt
  201. //var user_name string
  202. //role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  203. //if role.ID == 0 {
  204. // user_name = "管理员"
  205. //} else {
  206. // user_name = role.UserName
  207. //}
  208. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  209. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  210. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  211. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  212. c.ServeSuccessJSON(map[string]interface{}{
  213. "org_name": org.OrgName,
  214. "name": patient.Name,
  215. "order_infos": orderInfos,
  216. "number": order.MdtrtId,
  217. "date": order.SettleAccountsDate,
  218. "charge_admin": charge_admin,
  219. "printor_admin": printor_admin,
  220. "info": order,
  221. })
  222. }
  223. func (c *HisApiController) RefudDetail() {
  224. order_id, _ := c.GetInt64("order_id")
  225. order, _ := service.GetHisOrderByID(order_id)
  226. adminUser := c.GetAdminUserInfo()
  227. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  228. c.ServeSuccessJSON(map[string]interface{}{
  229. "msg": "撤销成功",
  230. })
  231. }
  232. func (c *HisApiController) Sscard() {
  233. //r := CardInit()
  234. //if r == 0 {
  235. // GetBaseInfo()
  236. //}
  237. //c.ServeSuccessJSON(map[string]interface{}{
  238. // "list": "11",
  239. //})
  240. }
  241. func GetBaseInfo() error {
  242. //handle := syscall.MustLoadDLL("SSCard.dll")
  243. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  244. //
  245. //str := make([]byte, 256)
  246. //str1 := make([]byte, 256)
  247. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  248. //if ferr != nil {
  249. // fmt.Println("ReadCardBas 报错", ferr.Error())
  250. // return ferr
  251. //}
  252. //
  253. //fmt.Println(string(str))
  254. //
  255. //fmt.Println(r)
  256. return nil
  257. }
  258. func CardInit() int {
  259. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  260. //add := DllTestDef.MustFindProc("Init")
  261. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  262. //if err != nil {
  263. // fmt.Println("SSCard的运算结果为:", ret)
  264. //}
  265. //result := int(ret)
  266. return 0
  267. }
  268. func IntPtr(n int) uintptr {
  269. return uintptr(n)
  270. }
  271. func StrPtr(s string) uintptr {
  272. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  273. }
  274. func (c *HisApiController) GetHisPatientList() {
  275. //types, _ := c.GetInt64("type", 0)
  276. record_date := c.GetString("record_date")
  277. sch_type, _ := c.GetInt64("sch_type")
  278. timeLayout := "2006-01-02"
  279. loc, _ := time.LoadLocation("Local")
  280. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  281. if err != nil {
  282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  283. return
  284. }
  285. recordDateTime := theTime.Unix()
  286. adminInfo := c.GetAdminUserInfo()
  287. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  288. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  289. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  290. //获取当前用户的信息
  291. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  292. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  293. //获取所有科室信息
  294. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  295. c.ServeSuccessJSON(map[string]interface{}{
  296. "list": patients,
  297. "list_two": patients_two,
  298. "info": adminUserInfo,
  299. "doctors": doctors,
  300. "department": department,
  301. })
  302. }
  303. type CustomTemplate struct {
  304. ID int64 `gorm:"column:id" json:"id" form:"id"`
  305. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  306. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  307. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  308. Status int64 `gorm:"column:status" json:"status" form:"status"`
  309. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  310. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  311. Type int64 `gorm:"column:type" json:"type" form:"type"`
  312. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  313. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  314. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  315. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  316. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  317. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  318. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  319. }
  320. func (c *HisApiController) GetHisPatientInfo() {
  321. patient_id, _ := c.GetInt64("patient_id")
  322. his_patient_id, _ := c.GetInt64("his_patient_id")
  323. record_date := c.GetString("record_date")
  324. number := c.GetString("number")
  325. //start_time := c.GetString("start_time")
  326. //end_time := c.GetString("end_time")
  327. p_type, _ := c.GetInt64("p_type")
  328. timeLayout := "2006-01-02"
  329. loc, _ := time.LoadLocation("Local")
  330. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  331. if err != nil {
  332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  333. return
  334. }
  335. recordDateTime := theTime.Unix()
  336. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  337. //if err != nil {
  338. //
  339. //}
  340. //startRecordDateTime := startTime.Unix()
  341. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  342. //if err != nil {
  343. //
  344. //}
  345. //endRecordDateTime := endTime.Unix()
  346. admin := c.GetAdminUserInfo()
  347. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  348. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  349. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  350. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  351. var prescriptions []*models.HisPrescription
  352. var last_prescriptions []*models.HisPrescription
  353. var sch_prescriptions []CustomTemplate
  354. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  355. if p_type == 1 { //住院
  356. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  357. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  358. } else { //门诊
  359. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  360. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  361. }
  362. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  363. if sch.ID > 0 {
  364. var week string
  365. t := time.Now()
  366. switch t.Weekday().String() {
  367. case "Monday":
  368. week = "周一"
  369. break
  370. case "Tuesday":
  371. week = "周二"
  372. break
  373. case "Wednesday":
  374. week = "周三"
  375. break
  376. case "Thursday":
  377. week = "周四"
  378. break
  379. case "Friday":
  380. week = "周五"
  381. break
  382. case "Saturday":
  383. week = "周六"
  384. break
  385. case "Sunday":
  386. week = "周日"
  387. break
  388. }
  389. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  390. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  391. //根据推送频率组装新的数组
  392. for _, item := range temp_sch_prescriptions {
  393. var cus CustomTemplate
  394. cus.ID = item.ID
  395. cus.UserOrgId = item.UserOrgId
  396. cus.PatientId = item.PatientId
  397. cus.MedType = item.MedType
  398. cus.RecordDate = item.RecordDate
  399. cus.Type = item.Type
  400. cus.PType = item.PType
  401. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  402. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  403. if subItem.FrequencyType == 1 { //每次必推
  404. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  405. }
  406. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  407. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  408. }
  409. if subItem.FrequencyType == 2 { //按照天数频率
  410. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  411. now := p.Unix()
  412. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  413. dayStr2 := "-" + dayStr
  414. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  415. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  416. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  417. if len(advices) == 0 {
  418. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  419. }
  420. }
  421. }
  422. }
  423. for _, subItem := range item.HisPrescriptionProjectTemplate {
  424. if subItem.Type == 2 {
  425. if subItem.XtHisProject.MedicalStatus != 1 {
  426. if subItem.FrequencyType == 1 {
  427. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  428. }
  429. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  430. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  431. }
  432. if subItem.FrequencyType == 2 {
  433. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  434. now := p.Unix()
  435. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  436. dayStr2 := "-" + dayStr
  437. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  438. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  439. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  440. if len(projects) == 0 {
  441. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  442. }
  443. }
  444. }
  445. } else if subItem.Type == 3 {
  446. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  447. if subItem.FrequencyType == 1 {
  448. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  449. }
  450. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  451. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  452. }
  453. if subItem.FrequencyType == 2 {
  454. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  455. now := p.Unix()
  456. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  457. dayStr2 := "-" + dayStr
  458. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  459. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  460. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  461. if len(projects) == 0 {
  462. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  463. }
  464. }
  465. }
  466. }
  467. }
  468. sch_prescriptions = append(sch_prescriptions, cus)
  469. }
  470. for _, item := range sch_prescriptions {
  471. if len(item.HisPrescriptionProjectTemplate) == 0 {
  472. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  473. }
  474. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  475. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  476. }
  477. }
  478. }
  479. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  480. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  481. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  482. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  483. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  484. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  485. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  486. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  487. //获取所有科室信息
  488. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  489. c.ServeSuccessJSON(map[string]interface{}{
  490. "his_info": his_patient_info,
  491. "xt_info": xt_patient_info,
  492. "prescription": prescriptions,
  493. "case_history": case_history,
  494. "info": patientPrescriptionInfo,
  495. //"month_prescriptions": monthPrescriptions,
  496. "order": order,
  497. "doctors": doctors,
  498. "department": department,
  499. "sch_prescriptions": sch_prescriptions,
  500. "last_prescriptions": last_prescriptions,
  501. "schedule": sch,
  502. "count": count,
  503. "drugStockConfig": drugStockConfig,
  504. "last_info": lastPatientPrescriptionInfo,
  505. })
  506. return
  507. }
  508. func (c *HisApiController) GetHisPrescriptionConfig() {
  509. adminInfo := c.GetAdminUserInfo()
  510. //获取医嘱模版
  511. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  512. //获取所有基础药
  513. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  514. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  515. if config.ID > 0 && config.IsOpen == 1 {
  516. for _, item := range drugs {
  517. var index = 0
  518. for _, subItem := range item.OtherDrugWarehouseInfo {
  519. if index == 0 {
  520. if subItem.StockMaxNumber*item.MinNumber+subItem.StockMinNumber > 0 {
  521. index = index + 1
  522. item.MinPrice = subItem.Price
  523. }
  524. }
  525. }
  526. }
  527. }
  528. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  529. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  530. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  531. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  532. //获取所有科室信息
  533. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  534. //获取诊断信息
  535. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  536. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  537. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  538. c.ServeSuccessJSON(map[string]interface{}{
  539. "drugs": drugs,
  540. "advices_template": advices,
  541. "drugways": drugways,
  542. "efs": efs,
  543. "doctors": doctors,
  544. "department": department,
  545. "sick": sick,
  546. "additions": additions,
  547. "diagnose": diagnose,
  548. "manufacturers": manufacturers,
  549. })
  550. }
  551. func (c *HisApiController) CreateHisPrescription() {
  552. record_date := c.GetString("record_date")
  553. patient_id, _ := c.GetInt64("patient_id")
  554. reg_type, _ := c.GetInt64("reg_type")
  555. diagnose := c.GetString("diagnose")
  556. sick_type, _ := c.GetInt64("sick_type")
  557. sick_history := c.GetString("sick_history")
  558. doctor_id, _ := c.GetInt64("doctor", 0)
  559. department, _ := c.GetInt64("department", 0)
  560. his_patient_id, _ := c.GetInt64("his_patient_id")
  561. p_type, _ := c.GetInt64("p_type")
  562. dataBody := make(map[string]interface{}, 0)
  563. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  564. if err != nil {
  565. utils.ErrorLog(err.Error())
  566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  567. return
  568. }
  569. timeLayout := "2006-01-02"
  570. loc, _ := time.LoadLocation("Local")
  571. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  572. if err != nil {
  573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  574. return
  575. }
  576. adminInfo := c.GetAdminUserInfo()
  577. recordDateTime := theTime.Unix()
  578. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  579. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  580. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  581. if len(lists) == 1 {
  582. his_patient_id = lists[0].ID
  583. }
  584. }
  585. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  586. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  587. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  588. if drugStockConfig.IsOpen == 1 {
  589. //校验库存总量
  590. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  591. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  592. if len(prescriptions) > 0 {
  593. for _, item := range prescriptions {
  594. items := item.(map[string]interface{})
  595. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  596. advices := items["advices"].([]interface{})
  597. if len(advices) > 0 {
  598. for _, advice := range advices {
  599. var drug_id int64
  600. var prescribing_number float64
  601. var prescribingNumberUnit string
  602. var prescribingNumber string
  603. var adviceId int64
  604. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  605. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  606. }
  607. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  608. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  609. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  610. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  611. }
  612. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  613. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  614. }
  615. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  616. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  617. }
  618. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  619. if drug.ID == 0 {
  620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  621. return
  622. }
  623. //查询药品的所有库存
  624. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId)
  625. var total_count int64
  626. for _, it := range list {
  627. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  628. }
  629. totals := strconv.FormatInt(total_count, 10)
  630. //查询该药品是否存在开药记录
  631. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  632. //新增处方
  633. if advicelist.ID == 0 {
  634. all_count, _ := strconv.ParseFloat(totals, 64)
  635. if prescribingNumberUnit == drug.MinUnit {
  636. if prescribing_number > all_count {
  637. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  638. return
  639. }
  640. } else {
  641. if prescribingNumberUnit == drug.MaxUnit {
  642. num := prescribing_number * float64(drug.MinNumber)
  643. if num > all_count {
  644. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  645. return
  646. }
  647. }
  648. }
  649. }
  650. //修改处方
  651. if advicelist.ID > 0 {
  652. var device_number int64
  653. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  654. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  655. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  656. device_number = prescribingNumberInt * drug.MinNumber
  657. }
  658. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  659. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  660. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  661. device_number = prescribingNumberInt
  662. }
  663. var number_count int64
  664. if prescribingNumberUnit == drug.MaxUnit {
  665. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  666. number_count = prescribingNumberInt * drug.MinNumber
  667. }
  668. if prescribingNumberUnit == drug.MinUnit {
  669. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  670. number_count = prescribingNumberInt
  671. }
  672. fmt.Println("以前出库数量23323232322332323223233223232332", device_number)
  673. fmt.Println("现在出库数量", number_count)
  674. //如果修改的数量大于之前修改的数量
  675. if (number_count - device_number) > 0 {
  676. //如果修改的差数量 大于库存数量
  677. if (number_count - device_number) > total_count {
  678. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  679. return
  680. }
  681. }
  682. if device_number != number_count {
  683. // 查询该药品最后一次出库记录
  684. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  685. fmt.Println("以前出库数量23323232322332323223233223232332", device_number)
  686. fmt.Println("现在出库数量", number_count)
  687. //回退库存
  688. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  689. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  690. }
  691. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  692. var stock_max_number int64
  693. var stock_min_number int64
  694. if number_count >= drug.MinNumber {
  695. fmt.Println("尽力啊了吗332323322332233232332233223232323")
  696. stock_max_number = device_number / drug.MinNumber
  697. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  698. stock_min_number = device_number % drug.MinNumber
  699. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  700. } else {
  701. fmt.Println("99999999999999999999")
  702. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  703. }
  704. }
  705. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  706. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  707. }
  708. //删除记录
  709. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  710. }
  711. }
  712. }
  713. }
  714. }
  715. }
  716. }
  717. }
  718. }
  719. if stockConfig.IsOpen == 1 {
  720. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  721. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  722. if len(prescriptions) > 0 {
  723. for _, item := range prescriptions {
  724. items := item.(map[string]interface{})
  725. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  726. projects := items["project"].([]interface{})
  727. if len(projects) > 0 {
  728. for _, project := range projects {
  729. var project_id int64
  730. var project_type int64
  731. var totals float64
  732. var project_name string
  733. var parsetotal int64
  734. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  735. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  736. }
  737. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  738. project_type = int64(project.(map[string]interface{})["type"].(float64))
  739. }
  740. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  741. total, _ := project.(map[string]interface{})["total"].(string)
  742. totals, _ = strconv.ParseFloat(total, 64)
  743. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  744. }
  745. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  746. project_name = project.(map[string]interface{})["project_name"].(string)
  747. }
  748. if project_type == 3 {
  749. //查找该耗材的出库记录
  750. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  751. var total_count int64
  752. for _, it := range goodWarehouseInfo {
  753. total_count += it.Count
  754. }
  755. if len(goodWarehouseInfo) == 0 {
  756. //查询耗材库存
  757. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  758. var stock_count int64
  759. for _, it := range list {
  760. stock_count += it.StockCount
  761. }
  762. stock_counts := strconv.FormatInt(stock_count, 10)
  763. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  764. if totals > stock_total_count {
  765. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  766. return
  767. }
  768. }
  769. if len(goodWarehouseInfo) > 0 {
  770. //查询该患者耗材的历史数据
  771. ordProject, _ := service.GetHisProjectPrescriptionByPatientId(patient_id, recordDateTime)
  772. if total_count > 0 {
  773. //数量发生改变
  774. if parsetotal != total_count || len(ordProject) != len(projects) {
  775. //查找今日该患者已经出库的所有耗材
  776. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  777. fmt.Println("goodList3323223232323232323", goodList)
  778. for _, item := range goodList {
  779. //回退库存
  780. service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  781. }
  782. //删除记录
  783. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  784. }
  785. }
  786. }
  787. }
  788. }
  789. }
  790. }
  791. }
  792. }
  793. }
  794. }
  795. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  796. var hpInfo models.HisPrescriptionInfo
  797. if info.ID == 0 {
  798. var randNum int
  799. randNum = rand.Intn(10000) + 1000
  800. timestamp := time.Now().Unix()
  801. tempTime := time.Unix(timestamp, 0)
  802. timeFormat := tempTime.Format("20060102150405")
  803. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  804. hpInfo = models.HisPrescriptionInfo{
  805. HisPatientId: his_patient_id,
  806. UserOrgId: adminInfo.CurrentOrgId,
  807. RecordDate: theTime.Unix(),
  808. PatientId: patient_id,
  809. Status: 1,
  810. Ctime: time.Now().Unix(),
  811. Mtime: time.Now().Unix(),
  812. Creator: adminInfo.AdminUser.Id,
  813. Modifier: adminInfo.AdminUser.Id,
  814. Diagnosis: diagnose,
  815. SickHistory: sick_history,
  816. Departments: department,
  817. RegisterType: reg_type,
  818. PrescriptionNumber: p_number,
  819. PrescriptionStatus: 1,
  820. Doctor: role.UserName,
  821. DoctorId: doctor_id,
  822. SickType: sick_type,
  823. PType: p_type,
  824. }
  825. service.SavePatientPrescriptionInfo(hpInfo)
  826. redis := service.RedisClient()
  827. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  828. redis.Set(key, "", time.Second)
  829. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  830. redis.Set(keyOne, "", time.Second)
  831. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  832. redis.Set(keySeven, "", time.Second)
  833. defer redis.Close()
  834. } else {
  835. hpInfo = models.HisPrescriptionInfo{
  836. ID: info.ID,
  837. UserOrgId: adminInfo.CurrentOrgId,
  838. RecordDate: info.RecordDate,
  839. PatientId: info.PatientId,
  840. Status: 1,
  841. Ctime: info.Ctime,
  842. Mtime: time.Now().Unix(),
  843. Creator: info.Creator,
  844. Modifier: adminInfo.AdminUser.Id,
  845. Diagnosis: diagnose,
  846. SickHistory: sick_history,
  847. Departments: department,
  848. RegisterType: reg_type,
  849. PrescriptionNumber: info.PrescriptionNumber,
  850. Doctor: role.UserName,
  851. PrescriptionStatus: info.PrescriptionStatus,
  852. DoctorId: doctor_id,
  853. SickType: sick_type,
  854. PType: info.PType,
  855. HisPatientId: info.HisPatientId,
  856. }
  857. service.SavePatientPrescriptionInfo(hpInfo)
  858. redis := service.RedisClient()
  859. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  860. redis.Set(key, "", time.Second)
  861. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  862. redis.Set(keyOne, "", time.Second)
  863. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  864. redis.Set(keySeven, "", time.Second)
  865. defer redis.Close()
  866. }
  867. //定义切片
  868. var adviceList []models.HisDoctorAdviceInfo
  869. var projectList []models.HisPrescriptionProject
  870. //var hisLis []models.HisList
  871. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  872. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  873. var tempPrescription *models.HisPrescription
  874. if len(prescriptions) > 0 {
  875. for _, item := range prescriptions {
  876. items := item.(map[string]interface{})
  877. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  878. utils.ErrorLog("id")
  879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  880. return
  881. }
  882. id := int64(items["id"].(float64))
  883. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  884. tempPrescription = &new_prescription
  885. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  886. utils.ErrorLog("type")
  887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  888. return
  889. }
  890. types := int64(items["type"].(float64))
  891. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  892. utils.ErrorLog("med_type")
  893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  894. return
  895. }
  896. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  897. if med_type == "0" {
  898. med_type = "14"
  899. }
  900. //if order_status == 0 {
  901. // order_status = 1
  902. //}
  903. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  904. utils.ErrorLog("pre_time")
  905. }
  906. preTime, _ := items["pre_time"].(string)
  907. timeLayout := "2006-01-02"
  908. loc, _ := time.LoadLocation("Local")
  909. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  910. if err != nil {
  911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  912. return
  913. }
  914. pTime := theTime2.Unix()
  915. ctime := time.Now().Unix()
  916. if tempPrescription.ID == 0 {
  917. prescription := &models.HisPrescription{
  918. ID: 0,
  919. PatientId: patient_id,
  920. UserOrgId: adminInfo.CurrentOrgId,
  921. RecordDate: recordDateTime,
  922. Ctime: ctime,
  923. Mtime: ctime,
  924. Type: types,
  925. Modifier: adminInfo.AdminUser.Id,
  926. Creator: adminInfo.AdminUser.Id,
  927. Status: 1,
  928. Doctor: role.UserName,
  929. HisPatientId: his_patient_id,
  930. OrderStatus: 1,
  931. BatchNumber: "",
  932. PrescriptionNumber: hpInfo.PrescriptionNumber,
  933. PreTime: pTime,
  934. PType: p_type,
  935. MedType: med_type,
  936. }
  937. tempPrescription = prescription
  938. service.SaveHisPrescription(tempPrescription)
  939. redis := service.RedisClient()
  940. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  941. redis.Set(key, "", time.Second)
  942. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  943. redis.Set(keyOne, "", time.Second)
  944. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  945. redis.Set(keySeven, "", time.Second)
  946. defer redis.Close()
  947. } else {
  948. tempPrescription.ID = id
  949. tempPrescription.Type = types
  950. tempPrescription.Modifier = adminInfo.AdminUser.Id
  951. tempPrescription.Mtime = time.Now().Unix()
  952. tempPrescription.Doctor = role.UserName
  953. //tempPrescription.OrderStatus = order_status
  954. tempPrescription.PreTime = pTime
  955. tempPrescription.MedType = med_type
  956. service.SaveHisPrescription(tempPrescription)
  957. redis := service.RedisClient()
  958. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  959. redis.Set(key, "", time.Second)
  960. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  961. redis.Set(keyOne, "", time.Second)
  962. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  963. redis.Set(keySeven, "", time.Second)
  964. defer redis.Close()
  965. }
  966. //service.SaveHisPrescription(prescription)
  967. //更改患者挂号状态
  968. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  969. fmt.Println("更改失败", err2)
  970. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  971. advices := items["advices"].([]interface{})
  972. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  973. groupNo := int64(0)
  974. ctime := time.Now().Unix()
  975. mtime := ctime
  976. if len(advices) > 0 {
  977. for _, advice := range advices {
  978. var s models.HisDoctorAdviceInfo
  979. s.PrescriptionId = tempPrescription.ID
  980. s.AdviceType = 2
  981. s.AdviceDoctor = doctor_id
  982. s.StopState = 2
  983. s.ExecutionState = 2
  984. s.AdviceDate = recordDateTime
  985. s.Status = 1
  986. s.UserOrgId = adminInfo.CurrentOrgId
  987. s.RecordDate = recordDateTime
  988. s.StartTime = tempPrescription.PreTime
  989. s.Groupno = groupNo
  990. s.CreatedTime = ctime
  991. s.UpdatedTime = mtime
  992. s.PatientId = patient_id
  993. s.HisPatientId = his_patient_id
  994. s.StartTime = pTime
  995. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  996. if errcode > 0 {
  997. c.ServeFailJSONWithSGJErrorCode(errcode)
  998. return
  999. }
  1000. s.StartTime = pTime
  1001. service.CreateHisDoctorAdvice(&s)
  1002. //存储切片中
  1003. adviceList = append(adviceList, s)
  1004. redis := service.RedisClient()
  1005. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1006. redis.Set(key, "", time.Second)
  1007. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1008. redis.Set(keyOne, "", time.Second)
  1009. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1010. redis.Set(keySeven, "", time.Second)
  1011. var randNum int
  1012. randNum = rand.Intn(10000) + 1000
  1013. timestamp := time.Now().Unix()
  1014. tempTime := time.Unix(timestamp, 0)
  1015. timeFormat := tempTime.Format("20060102150405")
  1016. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  1017. service.CreateHisDoctorAdvice(&s)
  1018. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1019. redis.Set(keySix, "", time.Second)
  1020. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1021. redis.Set(keyFive, "", time.Second)
  1022. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1023. redis.Set(keyEight, "", time.Second)
  1024. defer redis.Close()
  1025. }
  1026. }
  1027. }
  1028. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1029. projects := items["project"].([]interface{})
  1030. if len(projects) > 0 {
  1031. for _, project := range projects {
  1032. var p models.HisPrescriptionProject
  1033. p.PrescriptionId = tempPrescription.ID
  1034. p.Ctime = time.Now().Unix()
  1035. p.Mtime = time.Now().Unix()
  1036. p.PatientId = patient_id
  1037. p.RecordDate = recordDateTime
  1038. p.Doctor = doctor_id
  1039. p.UserOrgId = adminInfo.CurrentOrgId
  1040. p.HisPatientId = his_patient_id
  1041. p.Status = 1
  1042. p.StartTime = pTime
  1043. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  1044. if errcode > 0 {
  1045. c.ServeFailJSONWithSGJErrorCode(errcode)
  1046. return
  1047. }
  1048. service.CreateHisProjectTwo(&p)
  1049. projectList = append(projectList, p)
  1050. var randNum int
  1051. randNum = rand.Intn(10000) + 1000
  1052. timestamp := time.Now().Unix()
  1053. tempTime := time.Unix(timestamp, 0)
  1054. timeFormat := tempTime.Format("20060102150405")
  1055. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  1056. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  1057. //新增或者编辑项目,修改对应的标签数据
  1058. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  1059. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  1060. var label models.HisLabelPrintInfo
  1061. project, _ := service.GetProjectDetail(p.ProjectId)
  1062. if project.CostClassify == 3 { //类别为检验检查
  1063. if p.TeamId > 0 { //检验检查组套
  1064. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  1065. if tempLabel.ID == 0 {
  1066. team, _ := service.GetProjectTeamDetail(p.TeamId)
  1067. label.Number = tempPrescription.PrescriptionNumber
  1068. label.ProjectId = project.ID
  1069. label.Status = 1
  1070. label.IsPrint = 2
  1071. label.DoctorId = info.DoctorId
  1072. label.UserOrgId = p.UserOrgId
  1073. label.PatientId = patient_id
  1074. label.RecordDate = recordDateTime
  1075. label.Ctime = time.Now().Unix()
  1076. label.Mtime = time.Now().Unix()
  1077. label.ItemId = p.TeamId
  1078. label.FeedetlSn = p.FeedetlSn
  1079. label.PProjectId = p.ID
  1080. label.ProjectName = team.ProjectTeam
  1081. label.PatientName = patient.Name
  1082. service.CreateHisLabelRecord(&label)
  1083. }
  1084. } else { //单条检验检查项目
  1085. label.Number = tempPrescription.PrescriptionNumber
  1086. label.ProjectId = project.ID
  1087. label.Status = 1
  1088. label.DoctorId = info.DoctorId
  1089. label.UserOrgId = p.UserOrgId
  1090. label.PatientId = patient_id
  1091. label.RecordDate = recordDateTime
  1092. label.IsPrint = 2
  1093. label.Ctime = time.Now().Unix()
  1094. label.Mtime = time.Now().Unix()
  1095. label.FeedetlSn = p.FeedetlSn
  1096. label.PProjectId = p.ID
  1097. label.ItemId = p.TeamId
  1098. label.ProjectName = project.ProjectName
  1099. label.PatientName = patient.Name
  1100. service.CreateHisLabelRecord(&label)
  1101. }
  1102. }
  1103. }
  1104. }
  1105. service.SaveHisProjectTwo(&p)
  1106. //if p.Type == 3 { //处理透前准备耗材数量数据
  1107. // consumables, _ := service.FindHisConsumablesByID(adminInfo.CurrentOrgId, patient_id, recordDateTime, p.ProjectId)
  1108. // if consumables.ID > 0 {
  1109. // cnt, _ := strconv.ParseInt(p.Count, 10, 64)
  1110. // consumables.Count = cnt
  1111. // service.UpdateConsumables(&consumables)
  1112. // }
  1113. //}
  1114. }
  1115. }
  1116. }
  1117. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1118. // addition := items["addition"].([]interface{})
  1119. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1120. // ctime := time.Now().Unix()
  1121. // mtime := ctime
  1122. // if len(addition) > 0 {
  1123. // for _, item := range addition {
  1124. // var s models.HisAdditionalCharge
  1125. // s.PrescriptionId = tempPrescription.ID
  1126. // s.Status = 1
  1127. // s.UserOrgId = adminInfo.CurrentOrgId
  1128. // s.RecordDate = recordDateTime
  1129. // s.CreatedTime = ctime
  1130. // s.UpdatedTime = mtime
  1131. // s.PatientId = patient_id
  1132. // s.HisPatientId = his_patient_id
  1133. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1134. // if errcode > 0 {
  1135. // c.ServeFailJSONWithSGJErrorCode(errcode)
  1136. // return
  1137. // }
  1138. // service.CreateAdditionalCharge(&s)
  1139. // var randNum int
  1140. // randNum = rand.Intn(10000) + 1000
  1141. // timestamp := time.Now().Unix()
  1142. // tempTime := time.Unix(timestamp, 0)
  1143. // timeFormat := tempTime.Format("20060102150405")
  1144. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  1145. // service.CreateAdditionalCharge(&s)
  1146. //
  1147. // }
  1148. // }
  1149. //}
  1150. }
  1151. }
  1152. }
  1153. //redisClient := service.RedisClient()
  1154. //defer redisClient.Close()
  1155. //
  1156. //list := models.HisList{
  1157. // Patient_id: patient_id,
  1158. // Advice_id:0,
  1159. // Record_date: 0,
  1160. // Advice: adviceList,
  1161. // Project: nil,
  1162. //}
  1163. //hisLis = append(hisLis, list)
  1164. //
  1165. //advice_json, _ := json.Marshal(&hisLis)
  1166. //redisClient.RPush("111", advice_json).Result()
  1167. //result, _ := redisClient.RPop("111").Result()
  1168. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  1169. //
  1170. //var dat []map[string]interface{}
  1171. //json.Unmarshal([]byte(result), &dat)
  1172. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  1173. //
  1174. //for k,v:=range dat{
  1175. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  1176. //}
  1177. //project_json, _ := json.Marshal(&projectList)
  1178. //redisClient.LPush("222", project_json).Result()
  1179. if err == nil {
  1180. c.ServeSuccessJSON(map[string]interface{}{
  1181. "msg": "保存成功",
  1182. })
  1183. return
  1184. } else {
  1185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1186. return
  1187. }
  1188. }
  1189. func (c *HisApiController) EditHisPrescription() {
  1190. record_date := c.GetString("record_date")
  1191. patient_id, _ := c.GetInt64("patient_id")
  1192. reg_type, _ := c.GetInt64("reg_type")
  1193. //diagnose, _ := c.GetInt64("diagnose", 0)
  1194. diagnose := c.GetString("diagnose")
  1195. sick_type, _ := c.GetInt64("sick_type")
  1196. sick_history := c.GetString("sick_history")
  1197. doctor_id, _ := c.GetInt64("doctor", 0)
  1198. department, _ := c.GetInt64("department", 0)
  1199. his_patient_id, _ := c.GetInt64("his_patient_id")
  1200. p_type, _ := c.GetInt64("p_type")
  1201. dataBody := make(map[string]interface{}, 0)
  1202. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1203. if err != nil {
  1204. utils.ErrorLog(err.Error())
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. timeLayout := "2006-01-02"
  1209. loc, _ := time.LoadLocation("Local")
  1210. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1211. if err != nil {
  1212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1213. return
  1214. }
  1215. adminInfo := c.GetAdminUserInfo()
  1216. recordDateTime := theTime.Unix()
  1217. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1218. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1219. var hpInfo models.HisPrescriptionInfo
  1220. if info.ID == 0 {
  1221. var randNum int
  1222. randNum = rand.Intn(10000) + 1000
  1223. timestamp := time.Now().Unix()
  1224. tempTime := time.Unix(timestamp, 0)
  1225. timeFormat := tempTime.Format("20060102150405")
  1226. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1227. hpInfo = models.HisPrescriptionInfo{
  1228. UserOrgId: adminInfo.CurrentOrgId,
  1229. RecordDate: theTime.Unix(),
  1230. PatientId: patient_id,
  1231. Status: 1,
  1232. Ctime: time.Now().Unix(),
  1233. Mtime: time.Now().Unix(),
  1234. Creator: adminInfo.AdminUser.Id,
  1235. Modifier: adminInfo.AdminUser.Id,
  1236. Diagnosis: diagnose,
  1237. SickHistory: sick_history,
  1238. Departments: department,
  1239. RegisterType: reg_type,
  1240. PrescriptionNumber: p_number,
  1241. PrescriptionStatus: 1,
  1242. Doctor: role.UserName,
  1243. DoctorId: doctor_id,
  1244. SickType: sick_type,
  1245. PType: p_type,
  1246. }
  1247. service.SavePatientPrescriptionInfo(hpInfo)
  1248. } else {
  1249. hpInfo = models.HisPrescriptionInfo{
  1250. ID: info.ID,
  1251. UserOrgId: adminInfo.CurrentOrgId,
  1252. RecordDate: info.RecordDate,
  1253. PatientId: info.PatientId,
  1254. Status: 1,
  1255. Ctime: info.Ctime,
  1256. Mtime: time.Now().Unix(),
  1257. Creator: info.Creator,
  1258. Modifier: adminInfo.AdminUser.Id,
  1259. Diagnosis: diagnose,
  1260. SickHistory: sick_history,
  1261. Departments: department,
  1262. RegisterType: reg_type,
  1263. PrescriptionNumber: info.PrescriptionNumber,
  1264. Doctor: role.UserName,
  1265. PrescriptionStatus: info.PrescriptionStatus,
  1266. DoctorId: doctor_id,
  1267. SickType: sick_type,
  1268. PType: info.PType,
  1269. }
  1270. service.SavePatientPrescriptionInfo(hpInfo)
  1271. }
  1272. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1273. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1274. if len(prescriptions) > 0 {
  1275. for _, item := range prescriptions {
  1276. items := item.(map[string]interface{})
  1277. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1278. utils.ErrorLog("id")
  1279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1280. return
  1281. }
  1282. id := int64(items["id"].(float64))
  1283. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1284. utils.ErrorLog("type")
  1285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1286. return
  1287. }
  1288. types := int64(items["type"].(float64))
  1289. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1290. utils.ErrorLog("med_type")
  1291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1292. return
  1293. }
  1294. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1295. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  1296. ctime := time.Now().Unix()
  1297. prescription := &models.HisPrescription{
  1298. ID: id,
  1299. PatientId: patient_id,
  1300. UserOrgId: adminInfo.CurrentOrgId,
  1301. RecordDate: recordDateTime,
  1302. Ctime: ctime,
  1303. Mtime: ctime,
  1304. Type: types,
  1305. Modifier: adminInfo.AdminUser.Id,
  1306. Creator: adminInfo.AdminUser.Id,
  1307. Status: 1,
  1308. Doctor: role.UserName,
  1309. HisPatientId: his_patient_id,
  1310. OrderStatus: 1,
  1311. BatchNumber: "",
  1312. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1313. PType: hpInfo.PType,
  1314. MedType: med_type,
  1315. }
  1316. if historyPrescription.ID > 0 {
  1317. prescription.PreTime = historyPrescription.PreTime
  1318. }
  1319. service.SaveHisPrescription(prescription)
  1320. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1321. advices := items["advices"].([]interface{})
  1322. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1323. groupNo := int64(0)
  1324. ctime := time.Now().Unix()
  1325. mtime := ctime
  1326. if len(advices) > 0 {
  1327. for _, advice := range advices {
  1328. var s models.HisDoctorAdviceInfo
  1329. s.PrescriptionId = prescription.ID
  1330. s.AdviceType = 2
  1331. s.AdviceDoctor = adminInfo.AdminUser.Id
  1332. s.StopState = 2
  1333. s.ExecutionState = 2
  1334. s.AdviceDate = recordDateTime
  1335. s.Status = 1
  1336. s.UserOrgId = adminInfo.CurrentOrgId
  1337. s.RecordDate = recordDateTime
  1338. s.StartTime = prescription.PreTime
  1339. s.Groupno = groupNo
  1340. s.CreatedTime = ctime
  1341. s.UpdatedTime = mtime
  1342. s.PatientId = patient_id
  1343. s.HisPatientId = his_patient_id
  1344. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  1345. if errcode > 0 {
  1346. c.ServeFailJSONWithSGJErrorCode(errcode)
  1347. return
  1348. }
  1349. service.CreateHisDoctorAdvice(&s)
  1350. redis := service.RedisClient()
  1351. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1352. redis.Set(key, "", time.Second)
  1353. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1354. fmt.Println("keyOne", keyOne)
  1355. redis.Set(keyOne, "", time.Second)
  1356. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1357. redis.Set(keySeven, "", time.Second)
  1358. redis.Close()
  1359. }
  1360. }
  1361. }
  1362. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1363. projects := items["project"].([]interface{})
  1364. if len(projects) > 0 {
  1365. for _, project := range projects {
  1366. var p models.HisPrescriptionProject
  1367. p.PrescriptionId = prescription.ID
  1368. p.Ctime = time.Now().Unix()
  1369. p.Mtime = time.Now().Unix()
  1370. p.PatientId = patient_id
  1371. p.RecordDate = recordDateTime
  1372. p.UserOrgId = adminInfo.CurrentOrgId
  1373. p.HisPatientId = his_patient_id
  1374. p.Status = 1
  1375. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  1376. if errcode > 0 {
  1377. c.ServeFailJSONWithSGJErrorCode(errcode)
  1378. return
  1379. }
  1380. service.CreateHisProjectTwo(&p)
  1381. }
  1382. }
  1383. }
  1384. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1385. addition := items["addition"].([]interface{})
  1386. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1387. ctime := time.Now().Unix()
  1388. mtime := ctime
  1389. if len(addition) > 0 {
  1390. for _, item := range addition {
  1391. var s models.HisAdditionalCharge
  1392. s.PrescriptionId = prescription.ID
  1393. s.Status = 1
  1394. s.UserOrgId = adminInfo.CurrentOrgId
  1395. s.RecordDate = recordDateTime
  1396. s.CreatedTime = ctime
  1397. s.UpdatedTime = mtime
  1398. s.PatientId = patient_id
  1399. s.HisPatientId = his_patient_id
  1400. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1401. if errcode > 0 {
  1402. c.ServeFailJSONWithSGJErrorCode(errcode)
  1403. return
  1404. }
  1405. service.CreateAdditionalCharge(&s)
  1406. }
  1407. }
  1408. }
  1409. }
  1410. }
  1411. }
  1412. if err == nil {
  1413. c.ServeSuccessJSON(map[string]interface{}{
  1414. "msg": "保存成功",
  1415. })
  1416. return
  1417. } else {
  1418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1419. return
  1420. }
  1421. }
  1422. func (c *HisApiController) DeletePrescription() {
  1423. prescription_id, _ := c.GetInt64("id")
  1424. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  1425. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  1426. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1427. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1428. if len(projects) > 0 {
  1429. for _, item := range projects {
  1430. service.DeletePrintInfo(item.ID) //删除打印信息
  1431. if stockConfig.IsOpen == 1 {
  1432. if item.Type == 3 {
  1433. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  1434. f_count, _ := strconv.ParseFloat(item.Count, 64)
  1435. good.Total = good.Total + f_count
  1436. service.UpdateGoodInfo(&good)
  1437. operation_time := time.Now().Unix()
  1438. creater := c.GetAdminUserInfo().AdminUser.Id
  1439. //创建退库单
  1440. timeStr := time.Now().Format("2006-01-02")
  1441. timeArr := strings.Split(timeStr, "-")
  1442. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  1443. total = total + 1
  1444. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1445. cancelStock := models.CancelStock{
  1446. OrderNumber: orderNumber,
  1447. OperaTime: operation_time,
  1448. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1449. Creater: creater,
  1450. Ctime: time.Now().Unix(),
  1451. Status: 1,
  1452. ReturnTime: item.RecordDate,
  1453. Type: 1,
  1454. }
  1455. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  1456. if msgerrkonde == gorm.ErrRecordNotFound {
  1457. service.AddSigleCancelStock(&cancelStock)
  1458. }
  1459. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  1460. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  1461. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1462. //查询该耗材是否出库
  1463. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  1464. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  1465. deaerler, _ := service.GetDealerById(info.Dealer)
  1466. if info.ID > 0 {
  1467. cancelStockInfo := models.CancelStockInfo{
  1468. GoodId: item.ProjectId,
  1469. CancelStockId: cancel.ID,
  1470. GoodTypeId: info.GoodTypeId,
  1471. Count: prescribingNumber,
  1472. Price: info.Price,
  1473. Total: 0,
  1474. ProductDate: info.ProductDate,
  1475. ExpiryDate: info.ExpiryDate,
  1476. Ctime: time.Now().Unix(),
  1477. Status: 1,
  1478. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1479. OrderNumber: cancel.OrderNumber,
  1480. Type: 0,
  1481. Dealer: deaerler.DealerName,
  1482. Manufacturer: manufacturer.ManufacturerName,
  1483. Number: info.Number,
  1484. RegisterAccount: "",
  1485. Remark: "",
  1486. WarehouseInfoId: info.WarehouseInfotId,
  1487. PatientId: info.PatientId,
  1488. RecordDate: info.SysRecordTime,
  1489. }
  1490. service.CreateCancelStockInfoOne(&cancelStockInfo)
  1491. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  1492. flow := models.VmStockFlow{
  1493. WarehousingId: 0,
  1494. GoodId: item.ProjectId,
  1495. Number: info.Number,
  1496. LicenseNumber: info.LicenseNumber,
  1497. Count: prescribingNumber,
  1498. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1499. PatientId: item.PatientId,
  1500. SystemTime: info.SysRecordTime,
  1501. ConsumableType: 7,
  1502. IsSys: 0,
  1503. WarehousingOrder: "",
  1504. WarehouseOutId: 0,
  1505. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1506. IsEdit: 0,
  1507. CancelStockId: cancel.ID,
  1508. CancelOrderNumber: cancel.OrderNumber,
  1509. Manufacturer: manufacturer.ID,
  1510. Dealer: 0,
  1511. Creator: c.GetAdminUserInfo().CurrentOrgId,
  1512. UpdateCreator: 0,
  1513. Status: 1,
  1514. Ctime: time.Now().Unix(),
  1515. Mtime: 0,
  1516. Price: info.Price,
  1517. WarehousingDetailId: info.WarehouseInfotId,
  1518. WarehouseOutDetailId: 0,
  1519. CancelOutDetailId: cancelInfo.ID,
  1520. ProductDate: info.ProductDate,
  1521. ExpireDate: info.ExpiryDate,
  1522. }
  1523. service.CreateStockFlowOne(flow)
  1524. //删除出库表
  1525. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  1526. //查询今日该患者开了多少耗材
  1527. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1528. var total_count int64
  1529. var cha_count int64
  1530. for _, item := range projectList {
  1531. count, _ := strconv.ParseInt(item.Count, 10, 64)
  1532. total_count += count
  1533. }
  1534. //回退库存
  1535. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  1536. //查询今日该耗材退库数量
  1537. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1538. var cancel_Count int64
  1539. for _, items := range cancelInfoOne {
  1540. cancel_Count += items.Count
  1541. }
  1542. cha_count = total_count - cancel_Count
  1543. if total_count > cancel_Count {
  1544. out, err := service.FindStockOutByIsSys(c.GetAdminUserInfo().CurrentOrgId, 1, info.SysRecordTime)
  1545. if err == gorm.ErrRecordNotFound {
  1546. //没有记录,则创建出库单
  1547. timeStr := time.Now().Format("2006-01-02")
  1548. timeArr := strings.Split(timeStr, "-")
  1549. total, _ := service.FindAllWarehouseOut(c.GetAdminUserInfo().CurrentOrgId)
  1550. total = total + 1
  1551. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1552. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1553. number = number + total
  1554. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1555. warehouseOut := models.WarehouseOut{
  1556. WarehouseOutOrderNumber: warehousing_out_order,
  1557. OperationTime: time.Now().Unix(),
  1558. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1559. Creater: creater,
  1560. Ctime: time.Now().Unix(),
  1561. Status: 1,
  1562. WarehouseOutTime: info.SysRecordTime,
  1563. Dealer: 0,
  1564. Manufacturer: 0,
  1565. Type: 1,
  1566. IsSys: 1,
  1567. }
  1568. err := service.AddSigleWarehouseOut(&warehouseOut)
  1569. if err != nil {
  1570. utils.TraceLog("创建出库单失败 err = %v", err)
  1571. return
  1572. }
  1573. prepare := &models.DialysisBeforePrepare{
  1574. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1575. PatientId: info.PatientId,
  1576. RecordDate: info.SysRecordTime,
  1577. GoodId: item.ProjectId,
  1578. GoodTypeId: info.GoodTypeId,
  1579. Count: cha_count,
  1580. }
  1581. //出库
  1582. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  1583. } else if err == nil {
  1584. prepare := &models.DialysisBeforePrepare{
  1585. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1586. PatientId: info.PatientId,
  1587. RecordDate: info.SysRecordTime,
  1588. GoodId: item.ProjectId,
  1589. GoodTypeId: info.GoodTypeId,
  1590. Count: cha_count,
  1591. }
  1592. //出库
  1593. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  1594. }
  1595. }
  1596. }
  1597. }
  1598. }
  1599. }
  1600. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1601. fmt.Println(err)
  1602. }
  1603. if drugStockConfig.IsOpen == 1 {
  1604. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1605. fmt.Println(err)
  1606. if len(advices) > 0 {
  1607. for _, item := range advices {
  1608. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, item.DrugId)
  1609. redis := service.RedisClient()
  1610. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1611. redis.Set(keyFive, "", time.Second)
  1612. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1613. redis.Set(keyOne, "", time.Second)
  1614. redis.Close()
  1615. //查询该药品是否存在出库记录
  1616. info, errcode := service.GetDrugAutoWarehouseOutSeven(item.PatientId, item.AdviceDate, item.DrugId, item.ID)
  1617. if errcode == gorm.ErrRecordNotFound {
  1618. } else if errcode == nil {
  1619. if item.PrescribingNumberUnit == drug.MinUnit {
  1620. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  1621. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1622. //退库
  1623. warehouseInfo := models.DrugWarehouseInfo{
  1624. StockMinNumber: prescribingNumber,
  1625. }
  1626. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  1627. adminUserInfo := c.GetAdminUserInfo()
  1628. operation_time := time.Now().Unix()
  1629. creater := adminUserInfo.AdminUser.Id
  1630. ctime := time.Now().Unix()
  1631. timeStr := time.Now().Format("2006-01-02")
  1632. timeArr := strings.Split(timeStr, "-")
  1633. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1634. total = total + 1
  1635. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1636. cancelStock := models.DrugCancelStock{
  1637. OrderNumber: orderNumber,
  1638. OperaTime: operation_time,
  1639. OrgId: adminUserInfo.CurrentOrgId,
  1640. Creater: creater,
  1641. Ctime: ctime,
  1642. Status: 1,
  1643. ReturnTime: item.AdviceDate,
  1644. Dealer: info.Dealer,
  1645. Manufacturer: info.Manufacturer,
  1646. Type: 1,
  1647. }
  1648. service.AddSigleDrugCancelStock(&cancelStock)
  1649. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1650. dealer, _ := service.GetDealerById(info.Dealer)
  1651. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1652. cancelStockInfo := models.DrugCancelStockInfo{
  1653. OrderNumber: cancelInfo.OrderNumber,
  1654. CancelStockId: cancelInfo.ID,
  1655. DrugId: info.DrugId,
  1656. Count: prescribingNumber,
  1657. Status: 1,
  1658. Ctime: ctime,
  1659. OrgId: adminUserInfo.CurrentOrgId,
  1660. Type: 1,
  1661. Manufacturer: manufactureName.ManufacturerName,
  1662. Dealer: dealer.DealerName,
  1663. Total: 0,
  1664. RetailPrice: info.RetailPrice,
  1665. RetailTotalPrice: info.RetailTotalPrice,
  1666. Price: info.Price,
  1667. RegisterAccount: "",
  1668. Remark: info.Remark,
  1669. BatchNumber: info.BatchNumber,
  1670. MaxUnit: info.CountUnit,
  1671. ProductDate: info.ProductDate,
  1672. ExpiryDate: info.ExpiryDate,
  1673. BatchNumberId: info.WarehouseInfoId,
  1674. }
  1675. flow := models.DrugFlow{
  1676. WarehousingId: 0,
  1677. DrugId: info.DrugId,
  1678. Number: "",
  1679. BatchNumber: info.BatchNumber,
  1680. Count: prescribingNumber,
  1681. UserOrgId: adminUserInfo.CurrentOrgId,
  1682. PatientId: 0,
  1683. SystemTime: info.SysRecordTime,
  1684. ConsumableType: 7,
  1685. IsSys: 0,
  1686. WarehousingOrder: "",
  1687. WarehouseOutId: 0,
  1688. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1689. IsEdit: 0,
  1690. CancelStockId: cancelStock.ID,
  1691. CancelOrderNumber: cancelStock.OrderNumber,
  1692. Manufacturer: info.Manufacturer,
  1693. Dealer: info.Dealer,
  1694. Creator: adminUserInfo.AdminUser.Id,
  1695. UpdateCreator: 0,
  1696. Status: 1,
  1697. Ctime: time.Now().Unix(),
  1698. Mtime: 0,
  1699. Price: info.Price,
  1700. WarehousingDetailId: 0,
  1701. WarehouseOutDetailId: 0,
  1702. CancelOutDetailId: 0,
  1703. ExpireDate: info.ExpiryDate,
  1704. ProductDate: info.ProductDate,
  1705. MaxUnit: info.CountUnit,
  1706. MinUnit: "",
  1707. AdviceId: info.AdviceId,
  1708. }
  1709. service.CreatedCancelStock(cancelStockInfo)
  1710. service.CreateDrugFlowOne(flow)
  1711. //删除出库记录
  1712. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  1713. //删除流水
  1714. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  1715. } else {
  1716. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  1717. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1718. if item.PrescribingNumberUnit == drug.MaxUnit {
  1719. warehouseInfo := models.DrugWarehouseInfo{
  1720. StockMaxNumber: prescribingNumber,
  1721. }
  1722. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  1723. }
  1724. adminUserInfo := c.GetAdminUserInfo()
  1725. operation_time := time.Now().Unix()
  1726. creater := adminUserInfo.AdminUser.Id
  1727. ctime := time.Now().Unix()
  1728. timeStr := time.Now().Format("2006-01-02")
  1729. timeArr := strings.Split(timeStr, "-")
  1730. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1731. total = total + 1
  1732. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1733. cancelStock := models.DrugCancelStock{
  1734. OrderNumber: orderNumber,
  1735. OperaTime: operation_time,
  1736. OrgId: adminUserInfo.CurrentOrgId,
  1737. Creater: creater,
  1738. Ctime: ctime,
  1739. Status: 1,
  1740. ReturnTime: item.AdviceDate,
  1741. Dealer: info.Dealer,
  1742. Manufacturer: info.Manufacturer,
  1743. Type: 1,
  1744. }
  1745. service.AddSigleDrugCancelStock(&cancelStock)
  1746. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1747. dealer, _ := service.GetDealerById(info.Dealer)
  1748. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1749. cancelStockInfo := models.DrugCancelStockInfo{
  1750. OrderNumber: cancelInfo.OrderNumber,
  1751. CancelStockId: cancelInfo.ID,
  1752. DrugId: info.DrugId,
  1753. // Count: info.Count,
  1754. Count: prescribingNumber,
  1755. Status: 1,
  1756. Ctime: ctime,
  1757. OrgId: adminUserInfo.CurrentOrgId,
  1758. Type: 1,
  1759. Manufacturer: manufactureName.ManufacturerName,
  1760. Dealer: dealer.DealerName,
  1761. Total: 0,
  1762. RetailPrice: info.RetailPrice,
  1763. RetailTotalPrice: info.RetailTotalPrice,
  1764. Price: info.Price,
  1765. RegisterAccount: "",
  1766. Remark: info.Remark,
  1767. BatchNumber: info.BatchNumber,
  1768. MaxUnit: info.CountUnit,
  1769. ProductDate: info.ProductDate,
  1770. ExpiryDate: info.ExpiryDate,
  1771. BatchNumberId: info.WarehouseInfoId,
  1772. }
  1773. flow := models.DrugFlow{
  1774. WarehousingId: 0,
  1775. DrugId: info.DrugId,
  1776. Number: "",
  1777. BatchNumber: info.BatchNumber,
  1778. //Count: info.Count,
  1779. Count: prescribingNumber,
  1780. UserOrgId: adminUserInfo.CurrentOrgId,
  1781. PatientId: 0,
  1782. SystemTime: info.SysRecordTime,
  1783. ConsumableType: 7,
  1784. IsSys: 0,
  1785. WarehousingOrder: "",
  1786. WarehouseOutId: 0,
  1787. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1788. IsEdit: 0,
  1789. CancelStockId: cancelStock.ID,
  1790. CancelOrderNumber: cancelStock.OrderNumber,
  1791. Manufacturer: info.Manufacturer,
  1792. Dealer: info.Dealer,
  1793. Creator: adminUserInfo.AdminUser.Id,
  1794. UpdateCreator: 0,
  1795. Status: 1,
  1796. Ctime: time.Now().Unix(),
  1797. Mtime: 0,
  1798. Price: info.Price,
  1799. WarehousingDetailId: 0,
  1800. WarehouseOutDetailId: 0,
  1801. CancelOutDetailId: 0,
  1802. ExpireDate: info.ExpiryDate,
  1803. ProductDate: info.ProductDate,
  1804. MaxUnit: info.CountUnit,
  1805. MinUnit: "",
  1806. AdviceId: info.AdviceId,
  1807. }
  1808. service.CreatedCancelStock(cancelStockInfo)
  1809. service.CreateDrugFlowOne(flow)
  1810. //删除出库记录
  1811. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  1812. //删除流水
  1813. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  1814. }
  1815. }
  1816. if item.PrescribingNumberUnit == drug.MinUnit {
  1817. drug.Total = drug.Total + item.PrescribingNumber
  1818. service.UpdateBaseDrugLib(&drug)
  1819. } else {
  1820. if item.PrescribingNumberUnit == drug.MaxUnit {
  1821. item.PrescribingNumber = item.PrescribingNumber * float64(drug.MinNumber)
  1822. drug.Total = drug.Total + item.PrescribingNumber
  1823. service.UpdateBaseDrugLib(&drug)
  1824. }
  1825. }
  1826. }
  1827. }
  1828. }
  1829. c.ServeSuccessJSON(map[string]interface{}{
  1830. "msg": "删除成功",
  1831. })
  1832. return
  1833. }
  1834. func (c *HisApiController) DeleteDoctorAdvice() {
  1835. id, _ := c.GetInt64("id")
  1836. advice, _ := service.GetHisDoctorAdvicesById(id)
  1837. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1838. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  1839. redis := service.RedisClient()
  1840. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1841. redis.Set(keyFive, "", time.Second)
  1842. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1843. redis.Set(keyOne, "", time.Second)
  1844. defer redis.Close()
  1845. if err == nil {
  1846. if drugStockConfig.IsOpen == 1 {
  1847. //判断该医嘱是否执行了
  1848. if advice.ExecutionState == 1 {
  1849. //查询该病人该药品是否有库存记录
  1850. info, errcode := service.GetDrugAutoWarehouseOutSeven(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
  1851. if errcode == gorm.ErrRecordNotFound {
  1852. } else {
  1853. //退库
  1854. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, advice.DrugId)
  1855. if advice.PrescribingNumberUnit == drug.MinUnit {
  1856. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  1857. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1858. //退库
  1859. warehouseInfo := models.DrugWarehouseInfo{
  1860. StockMinNumber: prescribingNumber,
  1861. }
  1862. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  1863. adminUserInfo := c.GetAdminUserInfo()
  1864. operation_time := time.Now().Unix()
  1865. creater := adminUserInfo.AdminUser.Id
  1866. ctime := time.Now().Unix()
  1867. timeStr := time.Now().Format("2006-01-02")
  1868. timeArr := strings.Split(timeStr, "-")
  1869. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1870. total = total + 1
  1871. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1872. cancelStock := models.DrugCancelStock{
  1873. OrderNumber: orderNumber,
  1874. OperaTime: operation_time,
  1875. OrgId: adminUserInfo.CurrentOrgId,
  1876. Creater: creater,
  1877. Ctime: ctime,
  1878. Status: 1,
  1879. ReturnTime: advice.AdviceDate,
  1880. Dealer: info.Dealer,
  1881. Manufacturer: info.Manufacturer,
  1882. Type: 1,
  1883. }
  1884. service.AddSigleDrugCancelStock(&cancelStock)
  1885. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1886. dealer, _ := service.GetDealerById(info.Dealer)
  1887. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1888. cancelStockInfo := models.DrugCancelStockInfo{
  1889. OrderNumber: cancelInfo.OrderNumber,
  1890. CancelStockId: cancelInfo.ID,
  1891. DrugId: info.DrugId,
  1892. Count: info.Count,
  1893. Status: 1,
  1894. Ctime: ctime,
  1895. OrgId: adminUserInfo.CurrentOrgId,
  1896. Type: 1,
  1897. Manufacturer: manufactureName.ManufacturerName,
  1898. Dealer: dealer.DealerName,
  1899. Total: 0,
  1900. RetailPrice: info.RetailPrice,
  1901. RetailTotalPrice: info.RetailTotalPrice,
  1902. Price: info.Price,
  1903. RegisterAccount: "",
  1904. Remark: info.Remark,
  1905. BatchNumber: info.BatchNumber,
  1906. MaxUnit: info.CountUnit,
  1907. ProductDate: info.ProductDate,
  1908. ExpiryDate: info.ExpiryDate,
  1909. BatchNumberId: info.WarehouseInfoId,
  1910. }
  1911. flow := models.DrugFlow{
  1912. WarehousingId: 0,
  1913. DrugId: info.DrugId,
  1914. Number: "",
  1915. BatchNumber: info.BatchNumber,
  1916. Count: info.Count,
  1917. UserOrgId: adminUserInfo.CurrentOrgId,
  1918. PatientId: 0,
  1919. SystemTime: info.SysRecordTime,
  1920. ConsumableType: 7,
  1921. IsSys: 0,
  1922. WarehousingOrder: "",
  1923. WarehouseOutId: 0,
  1924. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1925. IsEdit: 0,
  1926. CancelStockId: cancelStock.ID,
  1927. CancelOrderNumber: cancelStock.OrderNumber,
  1928. Manufacturer: info.Manufacturer,
  1929. Dealer: info.Dealer,
  1930. Creator: adminUserInfo.AdminUser.Id,
  1931. UpdateCreator: 0,
  1932. Status: 1,
  1933. Ctime: time.Now().Unix(),
  1934. Mtime: 0,
  1935. Price: info.Price,
  1936. WarehousingDetailId: 0,
  1937. WarehouseOutDetailId: 0,
  1938. CancelOutDetailId: 0,
  1939. ExpireDate: info.ExpiryDate,
  1940. ProductDate: info.ProductDate,
  1941. MaxUnit: info.CountUnit,
  1942. MinUnit: "",
  1943. AdviceId: info.AdviceId,
  1944. }
  1945. service.CreatedCancelStock(cancelStockInfo)
  1946. service.CreateDrugFlowOne(flow)
  1947. //删除出库记录
  1948. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  1949. //删除流水
  1950. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  1951. } else {
  1952. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  1953. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1954. if advice.PrescribingNumberUnit == drug.MaxUnit {
  1955. warehouseInfo := models.DrugWarehouseInfo{
  1956. StockMaxNumber: prescribingNumber,
  1957. }
  1958. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  1959. }
  1960. adminUserInfo := c.GetAdminUserInfo()
  1961. operation_time := time.Now().Unix()
  1962. creater := adminUserInfo.AdminUser.Id
  1963. ctime := time.Now().Unix()
  1964. timeStr := time.Now().Format("2006-01-02")
  1965. timeArr := strings.Split(timeStr, "-")
  1966. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1967. total = total + 1
  1968. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1969. cancelStock := models.DrugCancelStock{
  1970. OrderNumber: orderNumber,
  1971. OperaTime: operation_time,
  1972. OrgId: adminUserInfo.CurrentOrgId,
  1973. Creater: creater,
  1974. Ctime: ctime,
  1975. Status: 1,
  1976. ReturnTime: advice.AdviceDate,
  1977. Dealer: info.Dealer,
  1978. Manufacturer: info.Manufacturer,
  1979. Type: 1,
  1980. }
  1981. service.AddSigleDrugCancelStock(&cancelStock)
  1982. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1983. dealer, _ := service.GetDealerById(info.Dealer)
  1984. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1985. cancelStockInfo := models.DrugCancelStockInfo{
  1986. OrderNumber: cancelInfo.OrderNumber,
  1987. CancelStockId: cancelInfo.ID,
  1988. DrugId: info.DrugId,
  1989. Count: info.Count,
  1990. Status: 1,
  1991. Ctime: ctime,
  1992. OrgId: adminUserInfo.CurrentOrgId,
  1993. Type: 1,
  1994. Manufacturer: manufactureName.ManufacturerName,
  1995. Dealer: dealer.DealerName,
  1996. Total: 0,
  1997. RetailPrice: info.RetailPrice,
  1998. RetailTotalPrice: info.RetailTotalPrice,
  1999. Price: info.Price,
  2000. RegisterAccount: "",
  2001. Remark: info.Remark,
  2002. BatchNumber: info.BatchNumber,
  2003. MaxUnit: info.CountUnit,
  2004. ProductDate: info.ProductDate,
  2005. ExpiryDate: info.ExpiryDate,
  2006. BatchNumberId: info.WarehouseInfoId,
  2007. }
  2008. flow := models.DrugFlow{
  2009. WarehousingId: 0,
  2010. DrugId: info.DrugId,
  2011. Number: "",
  2012. BatchNumber: info.BatchNumber,
  2013. Count: info.Count,
  2014. UserOrgId: adminUserInfo.CurrentOrgId,
  2015. PatientId: 0,
  2016. SystemTime: info.SysRecordTime,
  2017. ConsumableType: 7,
  2018. IsSys: 0,
  2019. WarehousingOrder: "",
  2020. WarehouseOutId: 0,
  2021. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2022. IsEdit: 0,
  2023. CancelStockId: cancelStock.ID,
  2024. CancelOrderNumber: cancelStock.OrderNumber,
  2025. Manufacturer: info.Manufacturer,
  2026. Dealer: info.Dealer,
  2027. Creator: adminUserInfo.AdminUser.Id,
  2028. UpdateCreator: 0,
  2029. Status: 1,
  2030. Ctime: time.Now().Unix(),
  2031. Mtime: 0,
  2032. Price: info.Price,
  2033. WarehousingDetailId: 0,
  2034. WarehouseOutDetailId: 0,
  2035. CancelOutDetailId: 0,
  2036. ExpireDate: info.ExpiryDate,
  2037. ProductDate: info.ProductDate,
  2038. MaxUnit: info.CountUnit,
  2039. MinUnit: "",
  2040. AdviceId: info.AdviceId,
  2041. }
  2042. service.CreatedCancelStock(cancelStockInfo)
  2043. service.CreateDrugFlowOne(flow)
  2044. //删除出库记录
  2045. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  2046. //删除流水
  2047. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  2048. }
  2049. }
  2050. }
  2051. }
  2052. c.ServeSuccessJSON(map[string]interface{}{
  2053. "msg": "删除成功",
  2054. })
  2055. return
  2056. } else {
  2057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2058. return
  2059. }
  2060. }
  2061. func (c *HisApiController) DeleteProject() {
  2062. id, _ := c.GetInt64("id")
  2063. adminInfo := c.GetAdminUserInfo()
  2064. project, _ := service.GetHisProjectByID(id)
  2065. // var consumable models.DialysisBeforePrepare
  2066. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2067. service.DeletePrintInfo(id)
  2068. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  2069. label.Status = 0
  2070. service.CreateHisLabelRecord(&label)
  2071. if stockConfig.IsOpen == 1 {
  2072. if project.Type == 3 {
  2073. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  2074. f_count, _ := strconv.ParseFloat(project.Count, 64)
  2075. good.Total = good.Total + f_count
  2076. service.UpdateGoodInfo(&good)
  2077. operation_time := time.Now().Unix()
  2078. creater := adminInfo.AdminUser.Id
  2079. //创建退库单
  2080. timeStr := time.Now().Format("2006-01-02")
  2081. timeArr := strings.Split(timeStr, "-")
  2082. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  2083. total = total + 1
  2084. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2085. cancelStock := models.CancelStock{
  2086. OrderNumber: orderNumber,
  2087. OperaTime: operation_time,
  2088. OrgId: adminInfo.CurrentOrgId,
  2089. Creater: creater,
  2090. Ctime: time.Now().Unix(),
  2091. Status: 1,
  2092. ReturnTime: project.RecordDate,
  2093. Type: 1,
  2094. }
  2095. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  2096. if msgerrkonde == gorm.ErrRecordNotFound {
  2097. service.AddSigleCancelStock(&cancelStock)
  2098. }
  2099. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  2100. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2101. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2102. //获取该耗材有库存的第一条数据
  2103. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  2104. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2105. deaerler, _ := service.GetDealerById(info.Dealer)
  2106. if info.ID > 0 {
  2107. cancelStockInfo := models.CancelStockInfo{
  2108. GoodId: project.ProjectId,
  2109. CancelStockId: cancel.ID,
  2110. GoodTypeId: info.GoodTypeId,
  2111. Count: prescribingNumber,
  2112. Price: info.Price,
  2113. Total: 0,
  2114. ProductDate: info.ProductDate,
  2115. ExpiryDate: info.ExpiryDate,
  2116. Ctime: time.Now().Unix(),
  2117. Status: 1,
  2118. OrgId: adminInfo.CurrentOrgId,
  2119. OrderNumber: cancel.OrderNumber,
  2120. Type: 0,
  2121. Dealer: deaerler.DealerName,
  2122. Manufacturer: manufacturer.ManufacturerName,
  2123. Number: info.Number,
  2124. RegisterAccount: "",
  2125. Remark: "",
  2126. WarehouseInfoId: info.WarehouseInfotId,
  2127. PatientId: info.PatientId,
  2128. RecordDate: info.SysRecordTime,
  2129. }
  2130. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2131. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  2132. flow := models.VmStockFlow{
  2133. WarehousingId: 0,
  2134. GoodId: project.ProjectId,
  2135. Number: info.Number,
  2136. LicenseNumber: info.LicenseNumber,
  2137. Count: prescribingNumber,
  2138. UserOrgId: adminInfo.CurrentOrgId,
  2139. PatientId: project.PatientId,
  2140. SystemTime: time.Now().Unix(),
  2141. ConsumableType: 7,
  2142. IsSys: 0,
  2143. WarehousingOrder: "",
  2144. WarehouseOutId: 0,
  2145. WarehouseOutOrderNumber: "",
  2146. IsEdit: 0,
  2147. CancelStockId: cancel.ID,
  2148. CancelOrderNumber: cancel.OrderNumber,
  2149. Manufacturer: manufacturer.ID,
  2150. Dealer: 0,
  2151. Creator: adminInfo.AdminUser.Id,
  2152. UpdateCreator: 0,
  2153. Status: 1,
  2154. Ctime: time.Now().Unix(),
  2155. Mtime: 0,
  2156. Price: info.Price,
  2157. WarehousingDetailId: info.WarehouseInfotId,
  2158. WarehouseOutDetailId: 0,
  2159. CancelOutDetailId: cancelInfo.ID,
  2160. ProductDate: info.ProductDate,
  2161. ExpireDate: info.ExpiryDate,
  2162. }
  2163. service.CreateStockFlowOne(flow)
  2164. //删除出库表
  2165. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  2166. //查询今日该患者开了多少耗材
  2167. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2168. var total_count int64
  2169. var cha_count int64
  2170. for _, item := range projectList {
  2171. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2172. total_count += count
  2173. }
  2174. //回退库存
  2175. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  2176. //查询今日该耗材退库数量
  2177. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2178. var cancel_count int64
  2179. for _, items := range cancelInfoOne {
  2180. cancel_count += items.Count
  2181. }
  2182. cha_count = total_count - cancel_count
  2183. if total_count > cancel_count {
  2184. out, err := service.FindStockOutByIsSys(adminInfo.CurrentOrgId, 1, info.SysRecordTime)
  2185. if err == gorm.ErrRecordNotFound {
  2186. //没有记录,则创建出库单
  2187. timeStr := time.Now().Format("2006-01-02")
  2188. timeArr := strings.Split(timeStr, "-")
  2189. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2190. total = total + 1
  2191. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2192. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2193. number = number + total
  2194. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2195. warehouseOut := models.WarehouseOut{
  2196. WarehouseOutOrderNumber: warehousing_out_order,
  2197. OperationTime: time.Now().Unix(),
  2198. OrgId: adminInfo.CurrentOrgId,
  2199. Creater: creater,
  2200. Ctime: time.Now().Unix(),
  2201. Status: 1,
  2202. WarehouseOutTime: info.SysRecordTime,
  2203. Dealer: 0,
  2204. Manufacturer: 0,
  2205. Type: 1,
  2206. IsSys: 1,
  2207. }
  2208. err := service.AddSigleWarehouseOut(&warehouseOut)
  2209. if err != nil {
  2210. utils.TraceLog("创建出库单失败 err = %v", err)
  2211. return
  2212. }
  2213. prepare := &models.DialysisBeforePrepare{
  2214. UserOrgId: adminInfo.CurrentOrgId,
  2215. PatientId: info.PatientId,
  2216. RecordDate: info.SysRecordTime,
  2217. GoodId: project.ProjectId,
  2218. GoodTypeId: info.GoodTypeId,
  2219. Count: cha_count,
  2220. }
  2221. //出库
  2222. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2223. } else if err == nil {
  2224. prepare := &models.DialysisBeforePrepare{
  2225. UserOrgId: adminInfo.CurrentOrgId,
  2226. PatientId: info.PatientId,
  2227. RecordDate: info.SysRecordTime,
  2228. GoodId: project.ProjectId,
  2229. GoodTypeId: info.GoodTypeId,
  2230. Count: cha_count,
  2231. }
  2232. //出库
  2233. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2234. }
  2235. }
  2236. }
  2237. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2238. fmt.Println(err)
  2239. }
  2240. }
  2241. c.ServeSuccessJSON(map[string]interface{}{
  2242. "msg": "删除成功",
  2243. })
  2244. return
  2245. }
  2246. func (c *HisApiController) CreateHisAdditionalCharge() {
  2247. his_patient_id, _ := c.GetInt64("his_patient_id")
  2248. patient_id, _ := c.GetInt64("patient_id")
  2249. record_date := c.GetString("record_date")
  2250. timeLayout := "2006-01-02"
  2251. loc, _ := time.LoadLocation("Local")
  2252. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2253. if err != nil {
  2254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2255. return
  2256. }
  2257. adminInfo := c.GetAdminUserInfo()
  2258. recordDateTime := theTime.Unix()
  2259. dataBody := make(map[string]interface{}, 0)
  2260. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2261. if err != nil {
  2262. utils.ErrorLog(err.Error())
  2263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2264. return
  2265. }
  2266. var additions []*models.HisAdditionalCharge
  2267. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  2268. additions, _ := dataBody["addition"].([]interface{})
  2269. if len(additions) > 0 {
  2270. for _, item := range additions {
  2271. items := item.(map[string]interface{})
  2272. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  2273. utils.ErrorLog("item_id")
  2274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2275. return
  2276. }
  2277. item_id := int64(items["item_id"].(float64))
  2278. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  2279. utils.ErrorLog("item_name")
  2280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2281. return
  2282. }
  2283. item_name := items["item_name"].(string)
  2284. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2285. utils.ErrorLog("price")
  2286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2287. return
  2288. }
  2289. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2290. ctime := time.Now().Unix()
  2291. additional := &models.HisAdditionalCharge{
  2292. PatientId: patient_id,
  2293. HisPatientId: his_patient_id,
  2294. UserOrgId: adminInfo.CurrentOrgId,
  2295. RecordDate: recordDateTime,
  2296. CreatedTime: ctime,
  2297. UpdatedTime: ctime,
  2298. Modifier: adminInfo.AdminUser.Id,
  2299. Creator: adminInfo.AdminUser.Id,
  2300. Price: price,
  2301. ItemName: item_name,
  2302. ItemId: item_id,
  2303. Status: 1,
  2304. }
  2305. additions = append(additions, additional)
  2306. }
  2307. }
  2308. }
  2309. for _, item := range additions {
  2310. service.CreateAddtionalCharge(item)
  2311. }
  2312. c.ServeSuccessJSON(map[string]interface{}{
  2313. "msg": "创建成功",
  2314. })
  2315. }
  2316. func (c *HisApiController) CreateHisPatientCaseHistory() {
  2317. blood_fat := c.GetString("blood_fat")
  2318. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  2319. blood_sugar := c.GetString("blood_sugar")
  2320. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  2321. fmt.Println(bloodsugarfloat)
  2322. chief_conplaint := c.GetString("chief_conplaint")
  2323. dbp := c.GetString("dbp")
  2324. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  2325. delivery_way, _ := c.GetInt64("delivery_way")
  2326. diagnostic := c.GetString("diagnostic")
  2327. family_history := c.GetString("family_history")
  2328. height := c.GetString("height")
  2329. history_of_present_illness := c.GetString("history_of_present_illness")
  2330. is_infect, _ := c.GetInt64("is_infect")
  2331. fmt.Println("is", is_infect)
  2332. past_history := c.GetString("past_history")
  2333. patient_id, _ := c.GetInt64("patient_id")
  2334. his_patient_id, _ := c.GetInt64("his_patient_id")
  2335. fmt.Println("patient_id", patient_id)
  2336. personal_history := c.GetString("personal_history")
  2337. pulse := c.GetString("pulse")
  2338. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  2339. sbp := c.GetString("sbp")
  2340. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  2341. heightfloat, _ := strconv.ParseFloat(height, 64)
  2342. sicktype := c.GetString("sick_type")
  2343. fmt.Println("sicketype", sicktype)
  2344. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  2345. symptom := c.GetString("symptom")
  2346. sick_date := c.GetString("sick_date")
  2347. temperatures := c.GetString("temperature")
  2348. fmt.Println("temperatures", temperatures)
  2349. temperature, _ := strconv.ParseFloat(temperatures, 64)
  2350. record_date := c.GetString("record_date")
  2351. breathing := c.GetString("breathing")
  2352. doctor_advice := c.GetString("doctor_advice")
  2353. remark := c.GetString("remark")
  2354. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  2355. sick, _ := c.GetInt64("sick")
  2356. diagnose, _ := c.GetInt64("diagnose")
  2357. id, _ := c.GetInt64("id")
  2358. timeLayout := "2006-01-02"
  2359. loc, _ := time.LoadLocation("Local")
  2360. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2361. allergic_history := c.GetString("allergic_history")
  2362. if err != nil {
  2363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2364. return
  2365. }
  2366. recordDateTime := theTime.Unix()
  2367. fmt.Println("recordDataTime", recordDateTime)
  2368. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  2369. if err != nil {
  2370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2371. return
  2372. }
  2373. sickTimes := sickTime.Unix()
  2374. ctime := time.Now().Unix()
  2375. caseHistory := models.HisPatientCaseHistory{
  2376. HisPatientId: his_patient_id,
  2377. PatientId: patient_id,
  2378. Temperature: temperature,
  2379. BloodSugar: bloodsugarfloat,
  2380. Pulse: pulsefloat,
  2381. Sbp: sbpfloat,
  2382. Dbp: dbpfloat,
  2383. Height: heightfloat,
  2384. BloodFat: bloodfatfloat,
  2385. SickType: sick_type,
  2386. Symptom: symptom,
  2387. SickDate: sickTimes,
  2388. IsInfect: is_infect,
  2389. HistoryOfPresentIllness: history_of_present_illness,
  2390. PastHistory: past_history,
  2391. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  2392. ChiefConplaint: chief_conplaint,
  2393. PersonalHistory: personal_history,
  2394. FamilyHistory: family_history,
  2395. Diagnostic: diagnostic,
  2396. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2397. Status: 1,
  2398. Ctime: ctime,
  2399. Mtime: ctime,
  2400. RecordDate: recordDateTime,
  2401. DeliveryWay: delivery_way,
  2402. Breathing: breathingfloat,
  2403. DoctorAdvice: doctor_advice,
  2404. Remark: remark,
  2405. Sick: sick,
  2406. Diagnose: diagnose,
  2407. AllergicHistory: allergic_history,
  2408. }
  2409. //查询该患者是否有病历
  2410. _, errcodes := service.GetHisPatientCaseHistoryById(id)
  2411. if errcodes == gorm.ErrRecordNotFound {
  2412. err = service.SaveHisPatientCaseHistory(&caseHistory)
  2413. if err != nil {
  2414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2415. return
  2416. }
  2417. c.ServeSuccessJSON(map[string]interface{}{
  2418. "caseHistory": caseHistory,
  2419. })
  2420. return
  2421. } else if errcodes == nil {
  2422. err := service.UpdatePatientCaseHistory(id, &caseHistory)
  2423. if err != nil {
  2424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2425. return
  2426. }
  2427. c.ServeSuccessJSON(map[string]interface{}{
  2428. "caseHistory": caseHistory,
  2429. })
  2430. }
  2431. //查询该患者是否有病历
  2432. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  2433. //if errcode == gorm.ErrRecordNotFound {
  2434. // err = service.SaveHisPatientCaseHistory(caseHistory)
  2435. // if err != nil {
  2436. // c.ServeSuccessJSON(map[string]interface{}{
  2437. // "msg": "保存成功",
  2438. // })
  2439. // }
  2440. //} else if errcode == nil {
  2441. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2442. // return
  2443. //}
  2444. }
  2445. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  2446. patient_id, _ := c.GetInt64("patient_id", 0)
  2447. adminUser := c.GetAdminUserInfo()
  2448. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  2449. c.ServeSuccessJSON(map[string]interface{}{
  2450. "list": caseHistorys,
  2451. })
  2452. }
  2453. func (c *HisApiController) GetHisPatientCaseHistory() {
  2454. record_date, _ := c.GetInt64("record_date", 0)
  2455. patient_id, _ := c.GetInt64("patient_id", 0)
  2456. admin := c.GetAdminUserInfo()
  2457. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  2458. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  2459. c.ServeSuccessJSON(map[string]interface{}{
  2460. "info": info,
  2461. "case_history": case_history,
  2462. })
  2463. }
  2464. func (c *HisApiController) CreateCaseHistoryTemplate() {
  2465. template_name := c.GetString("template_name")
  2466. template_remark := c.GetString("template_remark")
  2467. doctor := c.GetAdminUserInfo().AdminUser.Id
  2468. diagnostic := c.GetString("diagnostic")
  2469. chief_conplaint := c.GetString("chief_conplain")
  2470. history_of_present_illness := c.GetString("history_of_present_illness")
  2471. past_history := c.GetString("past_history")
  2472. personal_history := c.GetString("personal_history")
  2473. family_history := c.GetString("family_history")
  2474. user_name := c.GetString("user_name")
  2475. doctor_advice := c.GetString("doctor_advice")
  2476. remark := c.GetString("remark")
  2477. //record_date := c.GetString("record_date")
  2478. //fmt.Println("record_date--------",record_date)
  2479. //timeLayout := "2006-01-02"
  2480. //loc, _ := time.LoadLocation("Local")
  2481. //
  2482. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2483. //if err != nil {
  2484. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2485. // return
  2486. //}
  2487. //recordDateTime := theTime.Unix()
  2488. ctime := time.Now().Unix()
  2489. template := models.HisCaseHistoryTemplate{
  2490. HistoryOfPresentIllness: history_of_present_illness,
  2491. PastHistory: past_history,
  2492. ChiefConplaint: chief_conplaint,
  2493. PersonalHistory: personal_history,
  2494. FamilyHistory: family_history,
  2495. Diagnostic: diagnostic,
  2496. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2497. Status: 1,
  2498. Ctime: ctime,
  2499. Mtime: ctime,
  2500. RecordDate: time.Now().Unix(),
  2501. TemplateName: template_name,
  2502. TemplateRemark: template_remark,
  2503. Creator: doctor,
  2504. Modifier: doctor,
  2505. UserName: user_name,
  2506. DoctorAdvice: doctor_advice,
  2507. Remark: remark,
  2508. }
  2509. err := service.SaveHisPatientCaseHistoryTemplate(template)
  2510. if err == nil {
  2511. c.ServeSuccessJSON(map[string]interface{}{
  2512. "msg": "保存成功",
  2513. })
  2514. } else {
  2515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2516. return
  2517. }
  2518. }
  2519. func (c *HisApiController) GetCaseHistoryTemplate() {
  2520. timeLayout := "2006-01-02"
  2521. loc, _ := time.LoadLocation("Local")
  2522. keyword := c.GetString("keyword")
  2523. start_time := c.GetString("start_time")
  2524. end_time := c.GetString("end_time")
  2525. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2526. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2527. admin := c.GetAdminUserInfo()
  2528. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  2529. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  2530. c.ServeSuccessJSON(map[string]interface{}{
  2531. "template": template,
  2532. //"history": history,
  2533. })
  2534. }
  2535. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  2536. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2537. utils.ErrorLog("drug_name")
  2538. return enums.ErrorCodeParamWrong
  2539. }
  2540. adviceName, _ := json["drug_name"].(string)
  2541. if len(adviceName) == 0 {
  2542. utils.ErrorLog("len(advice_name) == 0")
  2543. return enums.ErrorCodeParamWrong
  2544. }
  2545. advice.AdviceName = adviceName
  2546. adviceDesc, _ := json["advice_desc"].(string)
  2547. advice.AdviceDesc = adviceDesc
  2548. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2549. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2550. advice.DrugSpec = drugSpec
  2551. }
  2552. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2553. remark, _ := json["remark"].(string)
  2554. advice.Remark = remark
  2555. }
  2556. if json["id"] == nil {
  2557. advice.DrugId = 0
  2558. } else {
  2559. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2560. drug_id := int64(json["id"].(float64))
  2561. advice.DrugId = drug_id
  2562. }
  2563. }
  2564. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  2565. advice_id := int64(json["advice_id"].(float64))
  2566. advice.ID = advice_id
  2567. if advice.ID > 0 {
  2568. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  2569. if err == nil {
  2570. if hisAdvice.ID > 0 {
  2571. advice.ExecutionTime = hisAdvice.ExecutionTime
  2572. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  2573. advice.ExecutionState = hisAdvice.ExecutionState
  2574. advice.CheckTime = hisAdvice.CheckTime
  2575. advice.Checker = hisAdvice.Checker
  2576. advice.CheckState = hisAdvice.CheckState
  2577. advice.StartTime = hisAdvice.StartTime
  2578. advice.FeedetlSn = hisAdvice.FeedetlSn
  2579. }
  2580. }
  2581. }
  2582. }
  2583. //
  2584. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  2585. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  2586. // advice.ExecutionTime = execution_time
  2587. //}
  2588. //
  2589. //
  2590. //
  2591. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  2592. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  2593. // advice.ExecutionStaff = execution_staff
  2594. //}
  2595. //
  2596. //
  2597. //
  2598. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  2599. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  2600. // advice.ExecutionState = execution_state
  2601. //}
  2602. //
  2603. //
  2604. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  2605. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  2606. // advice.CheckTime = check_time
  2607. //}
  2608. //
  2609. //
  2610. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  2611. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  2612. // advice.CheckState = check_state
  2613. //}
  2614. //
  2615. //
  2616. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  2617. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  2618. // advice.Checker = checker
  2619. //}
  2620. //
  2621. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  2622. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  2623. // advice.StartTime = start_time
  2624. //}
  2625. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  2626. drugSpecUnit, _ := json["min_unit"].(string)
  2627. advice.DrugSpecUnit = drugSpecUnit
  2628. }
  2629. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2630. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2631. advice.SingleDose = singleDose
  2632. }
  2633. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2634. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2635. advice.SingleDoseUnit = singleDoseUnit
  2636. }
  2637. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2638. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2639. advice.PrescribingNumber = prescribingNumber
  2640. }
  2641. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2642. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2643. advice.PrescribingNumberUnit = prescribingNumberUnit
  2644. }
  2645. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2646. deliveryWay, _ := json["delivery_way"].(string)
  2647. advice.DeliveryWay = deliveryWay
  2648. }
  2649. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2650. executionFrequency, _ := json["execution_frequency"].(string)
  2651. advice.ExecutionFrequency = executionFrequency
  2652. }
  2653. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  2654. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  2655. advice.Price = price
  2656. }
  2657. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  2658. med_list_codg, _ := json["medical_insurance_number"].(string)
  2659. advice.MedListCodg = med_list_codg
  2660. }
  2661. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  2662. day := int64(json["day"].(float64))
  2663. advice.Day = day
  2664. }
  2665. return 0
  2666. }
  2667. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  2668. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2669. id := int64(json["id"].(float64))
  2670. project.ID = id
  2671. historyProject, _ := service.GetHisProjectByID(id)
  2672. project.FeedetlSn = historyProject.FeedetlSn
  2673. }
  2674. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  2675. project_id := int64(json["project_id"].(float64))
  2676. project.ProjectId = project_id
  2677. }
  2678. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2679. // price := int64(json["price"].(float64))
  2680. // formatInt_price := strconv.FormatInt(price, 10)
  2681. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2682. // project.Price = float_price
  2683. // }
  2684. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  2685. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2686. project.Price = price
  2687. }
  2688. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  2689. total, _ := json["total"].(string)
  2690. project.Count = total
  2691. }
  2692. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  2693. medical_code, _ := json["medical_code"].(string)
  2694. project.MedListCodg = medical_code
  2695. }
  2696. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2697. single_dose, _ := json["single_dose"].(string)
  2698. project.SingleDose = single_dose
  2699. }
  2700. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2701. delivery_way, _ := json["delivery_way"].(string)
  2702. project.DeliveryWay = delivery_way
  2703. }
  2704. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2705. execution_frequency, _ := json["execution_frequency"].(string)
  2706. project.ExecutionFrequency = execution_frequency
  2707. }
  2708. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2709. remark, _ := json["remark"].(string)
  2710. project.Remark = remark
  2711. }
  2712. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  2713. day, _ := json["number_days"].(string)
  2714. project.Day = day
  2715. }
  2716. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  2717. unit, _ := json["unit"].(string)
  2718. project.Unit = unit
  2719. }
  2720. return 0
  2721. }
  2722. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  2723. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2724. id := int64(json["id"].(float64))
  2725. historyAddtions, _ := service.GetHisAdditionByID(id)
  2726. additionalCharge.ID = id
  2727. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  2728. }
  2729. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  2730. item_id := int64(json["item_id"].(float64))
  2731. additionalCharge.ItemId = item_id
  2732. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  2733. if config.ID > 0 {
  2734. if len(config.Code) > 0 {
  2735. additionalCharge.MedListCodg = config.Code
  2736. }
  2737. }
  2738. }
  2739. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2740. // price := int64(json["price"].(float64))
  2741. // formatInt_price := strconv.FormatInt(price, 10)
  2742. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2743. // additionalCharge.Price = float_price
  2744. // }
  2745. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2746. // price := int64(json["price"].(float64))
  2747. // formatInt_price := strconv.FormatInt(price, 10)
  2748. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2749. // additionalCharge.Price = float_price
  2750. //}
  2751. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  2752. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2753. additionalCharge.Price = price
  2754. }
  2755. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  2756. count, _ := json["count"].(string)
  2757. counts, _ := strconv.ParseInt(count, 10, 64)
  2758. additionalCharge.Count = counts
  2759. }
  2760. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  2761. item_name, _ := json["item_name"].(string)
  2762. additionalCharge.ItemName = item_name
  2763. }
  2764. return 0
  2765. }
  2766. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  2767. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2768. utils.ErrorLog("drug_name")
  2769. return enums.ErrorCodeParamWrong
  2770. }
  2771. adviceName, _ := json["drug_name"].(string)
  2772. if len(adviceName) == 0 {
  2773. utils.ErrorLog("len(advice_name) == 0")
  2774. return enums.ErrorCodeParamWrong
  2775. }
  2776. advice.AdviceName = adviceName
  2777. adviceDesc, _ := json["advice_desc"].(string)
  2778. advice.AdviceDesc = adviceDesc
  2779. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2780. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2781. advice.DrugSpec = drugSpec
  2782. }
  2783. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2784. remark, _ := json["remark"].(string)
  2785. advice.Remark = remark
  2786. }
  2787. if json["id"] == nil {
  2788. advice.DrugId = 0
  2789. } else {
  2790. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2791. drug_id := int64(json["id"].(float64))
  2792. advice.DrugId = drug_id
  2793. }
  2794. }
  2795. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  2796. groupno := int64(json["groupno"].(float64))
  2797. advice.Groupno = groupno
  2798. }
  2799. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  2800. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  2801. advice.HospApprFlag = hosp_appr_flag
  2802. }
  2803. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2804. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2805. advice.PrescribingNumber = prescribingNumber
  2806. }
  2807. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  2808. // frequency_type := int64(json["frequency_type"].(float64))
  2809. // advice.FrequencyType = frequency_type
  2810. //}
  2811. //
  2812. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  2813. // day_count := int64(json["day_count"].(float64))
  2814. // advice.DayCount = day_count
  2815. //}
  2816. //
  2817. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  2818. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  2819. // week_day, _ := json["week_day"].(string)
  2820. // advice.WeekDay = week_day
  2821. //}
  2822. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  2823. drugSpecUnit, _ := json["min_unit"].(string)
  2824. advice.DrugSpecUnit = drugSpecUnit
  2825. }
  2826. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2827. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2828. advice.SingleDose = singleDose
  2829. }
  2830. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2831. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2832. advice.SingleDoseUnit = singleDoseUnit
  2833. }
  2834. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2835. deliveryWay, _ := json["delivery_way"].(string)
  2836. advice.DeliveryWay = deliveryWay
  2837. }
  2838. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2839. executionFrequency, _ := json["execution_frequency"].(string)
  2840. advice.ExecutionFrequency = executionFrequency
  2841. }
  2842. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  2843. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  2844. advice.Price = price
  2845. }
  2846. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  2847. med_list_codg, _ := json["medical_insurance_number"].(string)
  2848. advice.MedListCodg = med_list_codg
  2849. }
  2850. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  2851. day := int64(json["day"].(float64))
  2852. advice.Day = day
  2853. }
  2854. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2855. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2856. advice.PrescribingNumberUnit = prescribingNumberUnit
  2857. }
  2858. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  2859. advice_id := int64(json["advice_id"].(float64))
  2860. advice.ID = advice_id
  2861. if advice.ID > 0 {
  2862. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  2863. if err == nil {
  2864. if hisAdvice.ID > 0 {
  2865. advice.ExecutionTime = hisAdvice.ExecutionTime
  2866. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  2867. advice.ExecutionState = hisAdvice.ExecutionState
  2868. advice.CheckTime = hisAdvice.CheckTime
  2869. advice.Checker = hisAdvice.Checker
  2870. advice.CheckState = hisAdvice.CheckState
  2871. advice.StartTime = hisAdvice.StartTime
  2872. advice.HospApprFlag = hisAdvice.HospApprFlag
  2873. if hisAdvice.SingleDose != advice.SingleDose || hisAdvice.DeliveryWay != advice.DeliveryWay || hisAdvice.ExecutionFrequency != advice.ExecutionFrequency || hisAdvice.Day != advice.Day || hisAdvice.PrescribingNumber != advice.PrescribingNumber || hisAdvice.Price != advice.Price || hisAdvice.Remark != advice.Remark || hisAdvice.PrescribingNumberUnit != advice.PrescribingNumberUnit {
  2874. advice.ExecutionTime = 0
  2875. advice.ExecutionStaff = 0
  2876. advice.ExecutionState = 2
  2877. advice.CheckTime = 0
  2878. advice.Checker = 0
  2879. advice.CheckState = 2
  2880. }
  2881. //advice.Groupno = hisAdvice.Groupno
  2882. }
  2883. }
  2884. }
  2885. }
  2886. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  2887. //
  2888. //if drugStockConfig.IsOpen == 1 {
  2889. //
  2890. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  2891. // if advice.ID == 0 { //医嘱不存在
  2892. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  2893. // drug.Total = drug.Total - advice.PrescribingNumber
  2894. // service.UpdateBaseDrugLib(&drug)
  2895. //
  2896. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  2897. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  2898. // drug.Total = drug.Total - num
  2899. // service.UpdateBaseDrugLib(&drug)
  2900. // }
  2901. //
  2902. // } else if advice.ID > 0 { //医嘱存在
  2903. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  2904. // var num float64
  2905. //
  2906. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  2907. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  2908. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  2909. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  2910. // drug.Total = drug.Total + num
  2911. // service.UpdateBaseDrugLib(&drug)
  2912. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  2913. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  2914. // drug.Total = drug.Total - num
  2915. // service.UpdateBaseDrugLib(&drug)
  2916. // }
  2917. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  2918. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  2919. // if num2 > advice.PrescribingNumber {
  2920. // num = num2 - advice.PrescribingNumber
  2921. // drug.Total = drug.Total + num
  2922. // service.UpdateBaseDrugLib(&drug)
  2923. // } else if num2 < advice.PrescribingNumber {
  2924. // num = advice.PrescribingNumber - num2
  2925. // drug.Total = drug.Total - num
  2926. // service.UpdateBaseDrugLib(&drug)
  2927. // }
  2928. //
  2929. // }
  2930. //
  2931. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  2932. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  2933. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  2934. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  2935. // if num1 > num2 {
  2936. // num = num1 - num2
  2937. // drug.Total = drug.Total + num
  2938. // service.UpdateBaseDrugLib(&drug)
  2939. // } else if num1 < num2 {
  2940. // num = num2 - num1
  2941. // drug.Total = drug.Total - num
  2942. // service.UpdateBaseDrugLib(&drug)
  2943. // }
  2944. //
  2945. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  2946. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  2947. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  2948. // if hisAdvice.PrescribingNumber > num2 {
  2949. // num = hisAdvice.PrescribingNumber - num2
  2950. // drug.Total = drug.Total + num
  2951. // service.UpdateBaseDrugLib(&drug)
  2952. // } else if num2 < advice.PrescribingNumber {
  2953. // num = num2 - hisAdvice.PrescribingNumber
  2954. // drug.Total = drug.Total - num
  2955. // service.UpdateBaseDrugLib(&drug)
  2956. // }
  2957. //
  2958. // }
  2959. // }
  2960. // }
  2961. //}
  2962. //
  2963. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  2964. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  2965. // advice.ExecutionTime = execution_time
  2966. //}
  2967. //
  2968. //
  2969. //
  2970. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  2971. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  2972. // advice.ExecutionStaff = execution_staff
  2973. //}
  2974. //
  2975. //
  2976. //
  2977. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  2978. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  2979. // advice.ExecutionState = execution_state
  2980. //}
  2981. //
  2982. //
  2983. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  2984. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  2985. // advice.CheckTime = check_time
  2986. //}
  2987. //
  2988. //
  2989. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  2990. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  2991. // advice.CheckState = check_state
  2992. //}
  2993. //
  2994. //
  2995. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  2996. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  2997. // advice.Checker = checker
  2998. //}
  2999. //
  3000. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3001. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3002. // advice.StartTime = start_time
  3003. //}
  3004. return 0
  3005. }
  3006. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3007. project.ExecutionStaff = 0
  3008. project.ExecutionState = 2
  3009. project.ExecutionTime = 0
  3010. project.Checker = 0
  3011. project.CheckState = 2
  3012. project.CheckTime = 0
  3013. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3014. id := int64(json["id"].(float64))
  3015. project.ID = id
  3016. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  3017. project.ExecutionStaff = temp_project.ExecutionStaff
  3018. project.ExecutionState = temp_project.ExecutionState
  3019. project.ExecutionTime = temp_project.ExecutionTime
  3020. project.Checker = temp_project.Checker
  3021. project.CheckState = temp_project.CheckState
  3022. project.CheckTime = temp_project.CheckTime
  3023. project.TeamId = temp_project.TeamId
  3024. }
  3025. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3026. types := int64(json["type"].(float64))
  3027. project.Type = types
  3028. }
  3029. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3030. project_id := int64(json["project_id"].(float64))
  3031. project.ProjectId = project_id
  3032. fmt.Println(project_id)
  3033. fmt.Println(project.ProjectId)
  3034. }
  3035. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  3036. team_id := int64(json["team_id"].(float64))
  3037. project.TeamId = team_id
  3038. }
  3039. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3040. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3041. project.Price = price
  3042. }
  3043. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3044. total, _ := json["total"].(string)
  3045. //totals, _ := strconv.ParseInt(total, 10, 64)
  3046. project.Count = total
  3047. }
  3048. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3049. medical_code, _ := json["medical_code"].(string)
  3050. project.MedListCodg = medical_code
  3051. }
  3052. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3053. single_dose, _ := json["single_dose"].(string)
  3054. project.SingleDose = single_dose
  3055. }
  3056. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3057. delivery_way, _ := json["delivery_way"].(string)
  3058. project.DeliveryWay = delivery_way
  3059. }
  3060. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3061. execution_frequency, _ := json["execution_frequency"].(string)
  3062. project.ExecutionFrequency = execution_frequency
  3063. }
  3064. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3065. remark, _ := json["remark"].(string)
  3066. project.Remark = remark
  3067. }
  3068. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3069. day, _ := json["number_days"].(string)
  3070. project.Day = day
  3071. }
  3072. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3073. unit, _ := json["unit"].(string)
  3074. project.Unit = unit
  3075. }
  3076. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3077. // frequency_type := int64(json["frequency_type"].(float64))
  3078. // project.FrequencyType = frequency_type
  3079. //}
  3080. //
  3081. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3082. // day_count := int64(json["day_count"].(float64))
  3083. // project.DayCount = day_count
  3084. //}
  3085. //
  3086. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3087. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3088. // week_day, _ := json["week_day"].(string)
  3089. // project.WeekDay = week_day
  3090. //}
  3091. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  3092. //
  3093. //if project.ID == 0 {
  3094. // if stockConfig.IsOpen == 1 {
  3095. // if project.Type == 3 {
  3096. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3097. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  3098. // good.Total = good.Total - f_count
  3099. // service.UpdateGoodInfo(&good)
  3100. // }
  3101. // }
  3102. //
  3103. //} else {
  3104. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  3105. //
  3106. // if stockConfig.IsOpen == 1 {
  3107. // if project.Type == 3 {
  3108. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3109. // if project.Count < temp_project.Count {
  3110. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3111. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3112. //
  3113. // other_count := f_count_two - f_count_one
  3114. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3115. // good.Total = good.Total + other_count_two
  3116. // service.UpdateGoodInfo(&good)
  3117. // } else if project.Count > temp_project.Count {
  3118. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3119. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3120. //
  3121. // other_count := f_count_one - f_count_two
  3122. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3123. // good.Total = good.Total - other_count_two
  3124. // service.UpdateGoodInfo(&good)
  3125. // }
  3126. //
  3127. // }
  3128. // }
  3129. //
  3130. //}
  3131. return 0
  3132. }
  3133. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3134. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3135. id := int64(json["id"].(float64))
  3136. additionalCharge.ID = id
  3137. }
  3138. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3139. item_id := int64(json["item_id"].(float64))
  3140. additionalCharge.ItemId = item_id
  3141. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3142. if config.ID > 0 {
  3143. if len(config.Code) > 0 {
  3144. additionalCharge.MedListCodg = config.Code
  3145. }
  3146. }
  3147. }
  3148. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3149. // price := int64(json["price"].(float64))
  3150. // formatInt_price := strconv.FormatInt(price, 10)
  3151. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3152. // additionalCharge.Price = float_price
  3153. // }
  3154. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3155. // price := int64(json["price"].(float64))
  3156. // formatInt_price := strconv.FormatInt(price, 10)
  3157. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3158. // additionalCharge.Price = float_price
  3159. //}
  3160. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3161. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3162. additionalCharge.Price = price
  3163. }
  3164. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3165. count, _ := json["count"].(string)
  3166. counts, _ := strconv.ParseInt(count, 10, 64)
  3167. additionalCharge.Count = counts
  3168. }
  3169. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3170. item_name, _ := json["item_name"].(string)
  3171. additionalCharge.ItemName = item_name
  3172. }
  3173. return 0
  3174. }
  3175. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  3176. fmt.Println("~~~~~~")
  3177. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3178. utils.ErrorLog("drug_name")
  3179. return enums.ErrorCodeParamWrong
  3180. }
  3181. adviceName, _ := json["drug_name"].(string)
  3182. if len(adviceName) == 0 {
  3183. utils.ErrorLog("len(advice_name) == 0")
  3184. return enums.ErrorCodeParamWrong
  3185. }
  3186. advice.AdviceName = adviceName
  3187. adviceDesc, _ := json["advice_desc"].(string)
  3188. advice.AdviceDesc = adviceDesc
  3189. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3190. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3191. advice.DrugSpec = drugSpec
  3192. }
  3193. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3194. remark, _ := json["remark"].(string)
  3195. advice.Remark = remark
  3196. }
  3197. if json["id"] == nil {
  3198. advice.DrugId = 0
  3199. } else {
  3200. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3201. drug_id := int64(json["id"].(float64))
  3202. advice.DrugId = drug_id
  3203. }
  3204. }
  3205. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3206. drugSpecUnit, _ := json["min_unit"].(string)
  3207. advice.DrugSpecUnit = drugSpecUnit
  3208. }
  3209. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3210. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3211. advice.SingleDose = singleDose
  3212. }
  3213. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3214. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3215. advice.SingleDoseUnit = singleDoseUnit
  3216. }
  3217. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3218. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3219. advice.PrescribingNumber = prescribingNumber
  3220. }
  3221. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3222. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3223. advice.PrescribingNumberUnit = prescribingNumberUnit
  3224. }
  3225. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3226. deliveryWay, _ := json["delivery_way"].(string)
  3227. advice.DeliveryWay = deliveryWay
  3228. }
  3229. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3230. executionFrequency, _ := json["execution_frequency"].(string)
  3231. advice.ExecutionFrequency = executionFrequency
  3232. }
  3233. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3234. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3235. advice.Price = price
  3236. }
  3237. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3238. med_list_codg, _ := json["medical_insurance_number"].(string)
  3239. advice.MedListCodg = med_list_codg
  3240. }
  3241. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3242. day := int64(json["day"].(float64))
  3243. advice.Day = day
  3244. }
  3245. return 0
  3246. }
  3247. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  3248. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3249. types := int64(json["type"].(float64))
  3250. project.Type = types
  3251. }
  3252. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3253. project_id := int64(json["project_id"].(float64))
  3254. project.ProjectId = project_id
  3255. }
  3256. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3257. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3258. project.Price = price
  3259. }
  3260. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3261. total, _ := json["total"].(string)
  3262. //totals, _ := strconv.ParseInt(total, 10, 64)
  3263. project.Count = total
  3264. }
  3265. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3266. medical_code, _ := json["medical_code"].(string)
  3267. project.MedListCodg = medical_code
  3268. }
  3269. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3270. single_dose, _ := json["single_dose"].(string)
  3271. project.SingleDose = single_dose
  3272. }
  3273. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3274. delivery_way, _ := json["delivery_way"].(string)
  3275. project.DeliveryWay = delivery_way
  3276. }
  3277. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3278. execution_frequency, _ := json["execution_frequency"].(string)
  3279. project.ExecutionFrequency = execution_frequency
  3280. }
  3281. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3282. remark, _ := json["remark"].(string)
  3283. project.Remark = remark
  3284. }
  3285. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3286. day, _ := json["number_days"].(string)
  3287. project.Day = day
  3288. }
  3289. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3290. unit, _ := json["unit"].(string)
  3291. project.Unit = unit
  3292. }
  3293. return 0
  3294. }
  3295. func (c *HisApiController) GetHisOrderList() {
  3296. page, _ := c.GetInt64("page", -1)
  3297. limit, _ := c.GetInt64("limit", -1)
  3298. start_time := c.GetString("start_time")
  3299. end_time := c.GetString("end_time")
  3300. types, _ := c.GetInt64("type", 0)
  3301. keywords := c.GetString("keywords")
  3302. p_type, _ := c.GetInt64("p_type", 0)
  3303. timeLayout := "2006-01-02"
  3304. loc, _ := time.LoadLocation("Local")
  3305. var startTime int64
  3306. if len(start_time) > 0 {
  3307. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3308. if err != nil {
  3309. fmt.Println(err)
  3310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3311. return
  3312. }
  3313. startTime = theTime.Unix()
  3314. }
  3315. var endTime int64
  3316. if len(end_time) > 0 {
  3317. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3318. if err != nil {
  3319. utils.ErrorLog(err.Error())
  3320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3321. return
  3322. }
  3323. endTime = theTime.Unix()
  3324. }
  3325. adminUser := c.GetAdminUserInfo()
  3326. org_id := adminUser.CurrentOrgId
  3327. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type)
  3328. for _, item := range order {
  3329. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  3330. item.DoctorName = info.Doctor
  3331. item.DepartmentName = info.XtHisDepartment.Name
  3332. }
  3333. if err == nil {
  3334. c.ServeSuccessJSON(map[string]interface{}{
  3335. "order": order,
  3336. "total": total,
  3337. })
  3338. } else {
  3339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3340. return
  3341. }
  3342. }
  3343. func (c *HisApiController) GetHisOrder() {
  3344. patient_id, _ := c.GetInt64("patient_id", 0)
  3345. number := c.GetString("number")
  3346. adminInfo := c.GetAdminUserInfo()
  3347. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  3348. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  3349. if err == nil {
  3350. c.ServeSuccessJSON(map[string]interface{}{
  3351. "order": order,
  3352. "prescription": prescriptions,
  3353. })
  3354. } else {
  3355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3356. return
  3357. }
  3358. }
  3359. func (c *HisApiController) GetHisPrescriptionList() {
  3360. record_date := c.GetString("record_date")
  3361. keywords := c.GetString("keywords")
  3362. page, _ := c.GetInt64("page")
  3363. limit, _ := c.GetInt64("limit")
  3364. timeLayout := "2006-01-02"
  3365. loc, _ := time.LoadLocation("Local")
  3366. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3367. if err != nil {
  3368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3369. return
  3370. }
  3371. recordDateTime := theTime.Unix()
  3372. adminInfo := c.GetAdminUserInfo()
  3373. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  3374. //adminInfo := c.GetAdminUserInfo()
  3375. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  3376. //fmt.Println(prescriptionOrder)
  3377. if err == nil {
  3378. c.ServeSuccessJSON(map[string]interface{}{
  3379. "order": prescriptionOrder,
  3380. "total": total,
  3381. })
  3382. } else {
  3383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3384. return
  3385. }
  3386. }
  3387. func (c *HisApiController) GetHisPrescriptionInfo() {
  3388. id, _ := c.GetInt64("id")
  3389. adminInfo := c.GetAdminUserInfo()
  3390. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  3391. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  3392. if err == nil {
  3393. c.ServeSuccessJSON(map[string]interface{}{
  3394. "order": prescriptionOrder,
  3395. "prescription": prescription,
  3396. })
  3397. } else {
  3398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3399. return
  3400. }
  3401. }
  3402. func (c *HisApiController) GetMedicalInsuranceConfig() {
  3403. adminUser := c.GetAdminUserInfo()
  3404. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3405. c.ServeSuccessJSON(map[string]interface{}{
  3406. "config": config,
  3407. })
  3408. }
  3409. type ResultTwo struct {
  3410. ErrMsg interface{} `json:"err_msg"`
  3411. InfRefmsgid string `json:"inf_refmsgid"`
  3412. Infcode int64 `json:"infcode"`
  3413. Output struct {
  3414. Baseinfo struct {
  3415. Age float64 `json:"age"`
  3416. Brdy string `json:"brdy"`
  3417. Certno string `json:"certno"`
  3418. Gend string `json:"gend"`
  3419. Naty string `json:"naty"`
  3420. PsnCertType string `json:"psn_cert_type"`
  3421. PsnName string `json:"psn_name"`
  3422. PsnNo string `json:"psn_no"`
  3423. } `json:"baseinfo"`
  3424. Idetinfo []interface{} `json:"idetinfo"`
  3425. Iinfo []struct {
  3426. Balc float64 `json:"balc"`
  3427. CvlservFlag string `json:"cvlserv_flag"`
  3428. EmpName string `json:"emp_name"`
  3429. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  3430. Insutype string `json:"insutype"`
  3431. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  3432. PausInsuDate interface{} `json:"paus_insu_date"`
  3433. PsnInsuDate string `json:"psn_insu_date"`
  3434. PsnInsuStas string `json:"psn_insu_stas"`
  3435. PsnType string `json:"psn_type"`
  3436. } `json:"insuinfo"`
  3437. } `json:"output"`
  3438. RefmsgTime string `json:"refmsg_time"`
  3439. RespondTime string `json:"respond_time"`
  3440. Signtype interface{} `json:"signtype"`
  3441. WarnInfo interface{} `json:"warn_info"`
  3442. }
  3443. type ResultThree struct {
  3444. Cainfo interface{} `json:"cainfo"`
  3445. ErrMsg interface{} `json:"err_msg"`
  3446. InfRefmsgid string `json:"inf_refmsgid"`
  3447. Infcode int64 `json:"infcode"`
  3448. Output struct {
  3449. Data struct {
  3450. IptOtpNo string `json:"ipt_otp_no"`
  3451. MdtrtID string `json:"mdtrt_id"`
  3452. PsnNo string `json:"psn_no"`
  3453. } `json:"data"`
  3454. } `json:"output"`
  3455. RefmsgTime string `json:"refmsg_time"`
  3456. RespondTime string `json:"respond_time"`
  3457. Signtype interface{} `json:"signtype"`
  3458. WarnMsg interface{} `json:"warn_msg"`
  3459. }
  3460. type ResultFour struct {
  3461. Cainfo string `json:"cainfo"`
  3462. ErrMsg string `json:"err_msg"`
  3463. InfRefmsgid string `json:"inf_refmsgid"`
  3464. Infcode int64 `json:"infcode"`
  3465. Output struct {
  3466. Result []struct {
  3467. BasMednFlag string `json:"bas_medn_flag"`
  3468. ChldMedcFlag string `json:"chld_medc_flag"`
  3469. ChrgitmLv string `json:"chrgitm_lv"`
  3470. Cnt float64 `json:"cnt"`
  3471. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  3472. DrtReimFlag string `json:"drt_reim_flag"`
  3473. FeedetlSn string `json:"feedetl_sn"`
  3474. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3475. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  3476. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3477. ListSpItemFlag string `json:"list_sp_item_flag"`
  3478. LmtUsedFlag string `json:"lmt_used_flag"`
  3479. MedChrgitmType string `json:"med_chrgitm_type"`
  3480. Memo string `json:"memo"`
  3481. OverlmtAmt float64 `json:"overlmt_amt"`
  3482. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3483. Pric float64 `json:"pric"`
  3484. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  3485. SelfpayProp float64 `json:"selfpay_prop"`
  3486. } `json:"result"`
  3487. } `json:"output"`
  3488. RefmsgTime string `json:"refmsg_time"`
  3489. RespondTime string `json:"respond_time"`
  3490. Signtype string `json:"signtype"`
  3491. WarnMsg string `json:"warn_msg"`
  3492. }
  3493. type ResultFive struct {
  3494. Insutype string `json:"insutype"`
  3495. }
  3496. type ResultSix struct {
  3497. Cainfo interface{} `json:"cainfo"`
  3498. ErrMsg interface{} `json:"err_msg"`
  3499. InfRefmsgid string `json:"inf_refmsgid"`
  3500. Infcode int64 `json:"infcode"`
  3501. Output struct {
  3502. } `json:"output"`
  3503. RefmsgTime string `json:"refmsg_time"`
  3504. RespondTime string `json:"respond_time"`
  3505. Signtype interface{} `json:"signtype"`
  3506. WarnMsg interface{} `json:"warn_msg"`
  3507. }
  3508. type ResultSeven struct {
  3509. Cainfo string `json:"cainfo"`
  3510. ErrMsg string `json:"err_msg"`
  3511. InfRefmsgid string `json:"inf_refmsgid"`
  3512. Infcode int64 `json:"infcode"`
  3513. Output struct {
  3514. Setldetail []interface{} `json:"setldetail"`
  3515. Setlinfo struct {
  3516. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3517. AcctPay float64 `json:"acct_pay"`
  3518. ActPayDedc float64 `json:"act_pay_dedc"`
  3519. Age float64 `json:"age"`
  3520. Balc float64 `json:"balc"`
  3521. Brdy string `json:"brdy"`
  3522. Certno string `json:"certno"`
  3523. ClrOptins string `json:"clr_optins"`
  3524. ClrType string `json:"clr_type"`
  3525. ClrWay string `json:"clr_way"`
  3526. CvlservFlag string `json:"cvlserv_flag"`
  3527. CvlservPay float64 `json:"cvlserv_pay"`
  3528. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3529. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3530. Gend string `json:"gend"`
  3531. HifesPay float64 `json:"hifes_pay"`
  3532. HifmiPay float64 `json:"hifmi_pay"`
  3533. HifobPay float64 `json:"hifob_pay"`
  3534. HifpPay float64 `json:"hifp_pay"`
  3535. HospPartAmt float64 `json:"hosp_part_amt"`
  3536. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3537. Insutype string `json:"insutype"`
  3538. MafPay float64 `json:"maf_pay"`
  3539. MdtrtCertType string `json:"mdtrt_cert_type"`
  3540. MdtrtID string `json:"mdtrt_id"`
  3541. MedType string `json:"med_type"`
  3542. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3543. MedinsSetlID string `json:"medins_setl_id"`
  3544. Naty string `json:"naty"`
  3545. OthPay float64 `json:"oth_pay"`
  3546. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3547. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3548. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3549. PsnCashPay float64 `json:"psn_cash_pay"`
  3550. PsnCertType string `json:"psn_cert_type"`
  3551. PsnName string `json:"psn_name"`
  3552. PsnNo string `json:"psn_no"`
  3553. PsnPartAmt float64 `json:"psn_part_amt"`
  3554. PsnType string `json:"psn_type"`
  3555. SetlID string `json:"setl_id"`
  3556. SetlTime string `json:"setl_time"`
  3557. } `json:"setlinfo"`
  3558. } `json:"output"`
  3559. RefmsgTime string `json:"refmsg_time"`
  3560. RespondTime string `json:"respond_time"`
  3561. Signtype interface{} `json:"signtype"`
  3562. WarnMsg interface{} `json:"warn_msg"`
  3563. }
  3564. type ResultEight struct {
  3565. Cainfo string `json:"cainfo"`
  3566. ErrMsg string `json:"err_msg"`
  3567. InfRefmsgid string `json:"inf_refmsgid"`
  3568. Infcode int64 `json:"infcode"`
  3569. Output struct {
  3570. Stmtinfo struct {
  3571. SetlOptins string `json:"setl_optins"`
  3572. StmtRslt string `json:"stmt_rslt"`
  3573. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  3574. } `json:"stmtinfo"`
  3575. } `json:"output"`
  3576. RefmsgTime string `json:"refmsg_time"`
  3577. RespondTime string `json:"respond_time"`
  3578. Signtype interface{} `json:"signtype"`
  3579. WarnMsg interface{} `json:"warn_msg"`
  3580. }
  3581. type ResultNine struct {
  3582. Cainfo string `json:"cainfo"`
  3583. ErrMsg string `json:"err_msg"`
  3584. InfRefmsgid string `json:"inf_refmsgid"`
  3585. Infcode int64 `json:"infcode"`
  3586. Output struct {
  3587. FileQuryNo string `json:"file_qury_no"`
  3588. } `json:"output"`
  3589. RefmsgTime string `json:"refmsg_time"`
  3590. RespondTime string `json:"respond_time"`
  3591. Signtype interface{} `json:"signtype"`
  3592. WarnMsg interface{} `json:"warn_msg"`
  3593. }
  3594. type ResultTen struct {
  3595. Cainfo string `json:"cainfo"`
  3596. ErrMsg string `json:"err_msg"`
  3597. InfRefmsgid string `json:"inf_refmsgid"`
  3598. Infcode int64 `json:"infcode"`
  3599. Output struct {
  3600. DldEndtime string `json:"dld_endtime"`
  3601. FileQuryNo string `json:"file_qury_no"`
  3602. Filename string `json:"filename"`
  3603. } `json:"output"`
  3604. RefmsgTime string `json:"refmsg_time"`
  3605. RespondTime string `json:"respond_time"`
  3606. Signtype interface{} `json:"signtype"`
  3607. WarnMsg interface{} `json:"warn_msg"`
  3608. }
  3609. type ResultEleven struct {
  3610. Cainfo string `json:"cainfo"`
  3611. ErrMsg string `json:"err_msg"`
  3612. InfRefmsgid string `json:"inf_refmsgid"`
  3613. Infcode int64 `json:"infcode"`
  3614. Output struct {
  3615. Setlinfo struct {
  3616. FixmedinsName string `json:"fixmedins_name"`
  3617. FixmedinsCode string `json:"fixmedins_code"`
  3618. PsnNo string `json:"psn_no"`
  3619. PsnName string `json:"psn_name"`
  3620. HifobPay float64 `json:"hifob_pay"`
  3621. Gend string `json:"gend"`
  3622. Brdy string `json:"brdy"`
  3623. PsnCertType string `json:"psn_cert_type"`
  3624. PsnType string `json:"psn_type"`
  3625. EmpName string `json:"emp_name"`
  3626. Certno string `json:"certno"`
  3627. Insutype string `json:"insutype"`
  3628. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3629. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3630. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3631. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3632. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3633. ActPayDedc float64 `json:"act_pay_dedc"`
  3634. HifpPay float64 `json:"hifp_pay"`
  3635. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3636. CvlservPay float64 `json:"cvlserv_pay"`
  3637. HifesPay float64 `json:"hifes_pay"`
  3638. HifmiPay float64 `json:"hifmi_pay"`
  3639. MafPay float64 `json:"maf_pay"`
  3640. OthPay float64 `json:"oth_pay"`
  3641. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3642. PsnPay float64 `json:"psn_pay"`
  3643. AcctPay float64 `json:"acct_pay"`
  3644. CashPayamt float64 `json:"cash_payamt"`
  3645. Balc float64 `json:"balc"`
  3646. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3647. MedinsSetlId string `json:"medins_setl_id"`
  3648. RefdSetlFlag string `json:"refd_setl_flag"`
  3649. SetlTime string `json:"setl_time"`
  3650. MedType string `json:"med_type"`
  3651. } `json:"setlinfo"`
  3652. } `json:"output"`
  3653. RefmsgTime string `json:"refmsg_time"`
  3654. RespondTime string `json:"respond_time"`
  3655. Signtype interface{} `json:"signtype"`
  3656. WarnMsg interface{} `json:"warn_msg"`
  3657. }
  3658. type Custom struct {
  3659. DetItemFeeSumamt string
  3660. Cut string
  3661. FeedetlSn string
  3662. Price string
  3663. MedListCodg string
  3664. Type int64
  3665. AdviceId int64
  3666. ProjectId int64
  3667. ItemId int64
  3668. }
  3669. //获取个人信息----挂号-----上传就诊信息
  3670. func (c *HisApiController) GetRegisterInfo() {
  3671. id, _ := c.GetInt64("id")
  3672. record_time := c.GetString("record_time")
  3673. settlementValue, _ := c.GetInt64("settlement_value")
  3674. medical_insurance_card := c.GetString("medical_insurance_card")
  3675. name := c.GetString("name")
  3676. id_card_type, _ := c.GetInt64("id_card_type")
  3677. certificates, _ := c.GetInt64("certificates")
  3678. medical_care, _ := c.GetInt64("medical_care")
  3679. birthday := c.GetString("birthday")
  3680. age, _ := c.GetInt64("age")
  3681. id_card := c.GetString("id_card")
  3682. register_type, _ := c.GetInt64("register")
  3683. doctor, _ := c.GetInt64("doctor")
  3684. department, _ := c.GetInt64("department")
  3685. gender, _ := c.GetInt64("sex")
  3686. phone := c.GetString("phone")
  3687. registration_fee, _ := c.GetFloat("registration_fee")
  3688. medical_expenses, _ := c.GetFloat("medical_expenses")
  3689. social_type, _ := c.GetInt64("social_type")
  3690. //diagnosis_id, _ := c.GetInt64("diagnosis")
  3691. diagnosis_ids := c.GetString("diagnosis")
  3692. sick_type, _ := c.GetInt64("sick_type")
  3693. reg_type := c.GetString("p_type")
  3694. timeLayout := "2006-01-02"
  3695. loc, _ := time.LoadLocation("Local")
  3696. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  3697. birthUnix := birthdays.Unix()
  3698. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3699. if err != nil {
  3700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3701. return
  3702. }
  3703. recordDateTime := theTime.Unix()
  3704. adminInfo := c.GetAdminUserInfo()
  3705. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  3706. if tempPatient.ID == 0 {
  3707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  3708. return
  3709. }
  3710. var patient service.Patients
  3711. if id == 0 {
  3712. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  3713. } else {
  3714. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  3715. }
  3716. if patient.ID == 0 {
  3717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3718. return
  3719. }
  3720. if len(patient.IdCardNo) == 0 {
  3721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  3722. return
  3723. }
  3724. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  3725. if len(his) >= 1 {
  3726. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  3727. if len(his) >= 1 && order.ID == 0 {
  3728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  3729. return
  3730. }
  3731. }
  3732. timeStr := time.Now().Format("2006-01-02 15:04:05")
  3733. fmt.Println(timeStr)
  3734. timeArr := strings.Split(timeStr, " ")
  3735. fmt.Println(timeArr)
  3736. timeArrTwo := strings.Split(timeArr[0], "-")
  3737. timeArrThree := strings.Split(timeArr[1], ":")
  3738. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  3739. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  3740. if len(lists) == 0 {
  3741. var hisPatient models.XtHisPatient
  3742. hisPatient = models.XtHisPatient{
  3743. Name: name,
  3744. Age: age,
  3745. Gender: gender,
  3746. Birthday: birthUnix,
  3747. Phone: phone,
  3748. MedicalTreatmentType: medical_care,
  3749. IdType: certificates,
  3750. IdCardNo: id_card,
  3751. BalanceAccountsType: settlementValue,
  3752. SocialType: social_type,
  3753. MedicalInsuranceNumber: medical_insurance_card,
  3754. RegisterType: register_type,
  3755. RegisterCost: registration_fee,
  3756. TreatmentCost: medical_expenses,
  3757. AdminUserId: adminInfo.AdminUser.Id,
  3758. UserOrgId: adminInfo.CurrentOrgId,
  3759. Status: 1,
  3760. RecordDate: recordDateTime,
  3761. IsReturn: 1,
  3762. PatientId: patient.ID,
  3763. Ctime: time.Now().Unix(),
  3764. Mtime: time.Now().Unix(),
  3765. Number: str,
  3766. IdCardType: id_card_type,
  3767. Departments: department,
  3768. Doctor: doctor,
  3769. PType: reg_type,
  3770. Diagnosis: diagnosis_ids,
  3771. SickType: sick_type,
  3772. }
  3773. service.CreateHisPatient(&hisPatient)
  3774. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  3775. c.ServeSuccessJSON(map[string]interface{}{
  3776. "his_info": hisPatient,
  3777. })
  3778. } else {
  3779. //chrgBchno := rand.Intn(1000000) + 10000
  3780. var hisPatient models.XtHisPatient
  3781. hisPatient = models.XtHisPatient{
  3782. Name: name,
  3783. Age: age,
  3784. Gender: gender,
  3785. Birthday: birthUnix,
  3786. Phone: phone,
  3787. MedicalTreatmentType: medical_care,
  3788. IdType: certificates,
  3789. IdCardNo: id_card,
  3790. BalanceAccountsType: settlementValue,
  3791. SocialType: social_type,
  3792. MedicalInsuranceNumber: medical_insurance_card,
  3793. RegisterType: register_type,
  3794. RegisterCost: registration_fee,
  3795. TreatmentCost: medical_expenses,
  3796. AdminUserId: adminInfo.AdminUser.Id,
  3797. UserOrgId: adminInfo.CurrentOrgId,
  3798. Status: 1,
  3799. RecordDate: recordDateTime,
  3800. IsReturn: 1,
  3801. PatientId: patient.ID,
  3802. Ctime: time.Now().Unix(),
  3803. Mtime: time.Now().Unix(),
  3804. Number: str,
  3805. IdCardType: id_card_type,
  3806. Departments: department,
  3807. Doctor: doctor,
  3808. PType: reg_type,
  3809. Diagnosis: diagnosis_ids,
  3810. SickType: sick_type,
  3811. }
  3812. service.CreateHisPatient(&hisPatient)
  3813. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  3814. c.ServeSuccessJSON(map[string]interface{}{
  3815. "his_info": hisPatient,
  3816. })
  3817. }
  3818. }
  3819. //上传明细----结算
  3820. func (c *HisApiController) GetUploadInfo() {
  3821. id, _ := c.GetInt64("id")
  3822. record_time := c.GetString("record_time")
  3823. his_patient_id, _ := c.GetInt64("his_patient_id")
  3824. pay_way, _ := c.GetInt64("pay_way")
  3825. pay_price, _ := c.GetFloat("pay_price")
  3826. pay_card_no := c.GetString("pay_card_no")
  3827. discount_price, _ := c.GetFloat("discount_price")
  3828. preferential_price, _ := c.GetFloat("preferential_price")
  3829. reality_price, _ := c.GetFloat("reality_price")
  3830. found_price, _ := c.GetFloat("found_price")
  3831. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  3832. private_price, _ := c.GetFloat("private_price")
  3833. timeLayout := "2006-01-02"
  3834. loc, _ := time.LoadLocation("Local")
  3835. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3836. fapiao_code := c.GetString("fapiao_code")
  3837. fapiao_number := c.GetString("fapiao_number")
  3838. diagnosis_id := c.GetString("diagnosis")
  3839. sick_type, _ := c.GetInt64("sick_type")
  3840. reg_type, _ := c.GetInt64("p_type")
  3841. order_id, _ := c.GetInt64("order_id")
  3842. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  3843. tempOrder, _ := service.GetHisOrderByID(order_id)
  3844. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3845. if err != nil {
  3846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3847. return
  3848. }
  3849. recordDateTime := theTime.Unix()
  3850. adminUser := c.GetAdminUserInfo()
  3851. var prescriptions []*models.HisPrescription
  3852. var start_time int64
  3853. var end_time int64
  3854. ids_str := c.GetString("ids")
  3855. ids_arr := strings.Split(ids_str, ",")
  3856. if tempOrder.ID == 0 {
  3857. if settle_accounts_type == 1 { //日结
  3858. fmt.Println(reg_type)
  3859. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  3860. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  3861. } else {
  3862. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  3863. }
  3864. } else { //月结
  3865. start_time_str := c.GetString("start_time")
  3866. end_time_str := c.GetString("end_time")
  3867. timeLayout := "2006-01-02"
  3868. loc, _ := time.LoadLocation("Local")
  3869. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3870. if err != nil {
  3871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3872. return
  3873. }
  3874. recordStartTime := theStartTime.Unix()
  3875. start_time = recordStartTime
  3876. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3877. if err != nil {
  3878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3879. return
  3880. }
  3881. recordEndTime := theEndTime.Unix()
  3882. end_time = recordEndTime
  3883. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  3884. }
  3885. timestamp := time.Now().Unix()
  3886. tempTime := time.Unix(timestamp, 0)
  3887. timeFormat := tempTime.Format("20060102150405")
  3888. chrgBchno := rand.Intn(100000) + 10000
  3889. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  3890. strconv.FormatInt(his.PatientId, 10)
  3891. var ids []int64
  3892. fmt.Println(prescriptions)
  3893. for _, item := range prescriptions {
  3894. ids = append(ids, item.ID)
  3895. }
  3896. var total float64
  3897. fmt.Println(prescriptions)
  3898. for _, item := range prescriptions {
  3899. fmt.Println(item)
  3900. if item.Type == 1 { //药品
  3901. for _, subItem := range item.HisDoctorAdviceInfo {
  3902. total = total + (subItem.Price * subItem.PrescribingNumber)
  3903. }
  3904. }
  3905. if item.Type == 2 { //项目
  3906. for _, subItem := range item.HisPrescriptionProject {
  3907. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  3908. total = total + (subItem.Price * cnt)
  3909. }
  3910. }
  3911. for _, subItem := range item.HisAdditionalCharge {
  3912. total = total + (subItem.Price * float64(subItem.Count))
  3913. }
  3914. }
  3915. if reg_type == 1111 || reg_type == 1112 {
  3916. reg_type = 11
  3917. }
  3918. allTotal := fmt.Sprintf("%.4f", total)
  3919. totals, _ := strconv.ParseFloat(allTotal, 64)
  3920. order := &models.HisOrder{
  3921. UserOrgId: adminUser.CurrentOrgId,
  3922. HisPatientId: his.ID,
  3923. PatientId: id,
  3924. SettleAccountsDate: recordDateTime,
  3925. Ctime: time.Now().Unix(),
  3926. Mtime: time.Now().Unix(),
  3927. Status: 1,
  3928. OrderStatus: 2,
  3929. MdtrtId: his.Number,
  3930. Number: chrg_bchno,
  3931. MedfeeSumamt: totals,
  3932. PayWay: pay_way,
  3933. PayPrice: pay_price,
  3934. MedType: strconv.Itoa(int(reg_type)),
  3935. PayCardNo: pay_card_no,
  3936. DiscountPrice: discount_price,
  3937. PreferentialPrice: preferential_price,
  3938. RealityPrice: reality_price,
  3939. FoundPrice: found_price,
  3940. MedicalInsurancePrice: medical_insurance_price,
  3941. PrivatePrice: private_price,
  3942. SettleEndTime: end_time,
  3943. SettleStartTime: start_time,
  3944. SettleType: settle_accounts_type,
  3945. FaPiaoCode: fapiao_code,
  3946. FaPiaoNumber: fapiao_number,
  3947. Diagnosis: diagnosis_id,
  3948. PType: 2,
  3949. }
  3950. err = service.CreateOrder(order)
  3951. if err != nil {
  3952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  3953. return
  3954. }
  3955. var customs []*Custom
  3956. for _, item := range prescriptions {
  3957. if item.Type == 1 { //药品
  3958. for _, subItem := range item.HisDoctorAdviceInfo {
  3959. cus := &Custom{
  3960. AdviceId: subItem.ID,
  3961. ProjectId: 0,
  3962. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  3963. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  3964. FeedetlSn: subItem.FeedetlSn,
  3965. Price: fmt.Sprintf("%.2f", subItem.Price),
  3966. MedListCodg: subItem.MedListCodg,
  3967. Type: 1,
  3968. }
  3969. customs = append(customs, cus)
  3970. }
  3971. }
  3972. if item.Type == 2 { //项目
  3973. for _, subItem := range item.HisPrescriptionProject {
  3974. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  3975. cus := &Custom{
  3976. AdviceId: 0,
  3977. ProjectId: subItem.ID,
  3978. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  3979. Cut: fmt.Sprintf("%.4f", cnt),
  3980. FeedetlSn: subItem.FeedetlSn,
  3981. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  3982. MedListCodg: subItem.MedListCodg,
  3983. Type: 2,
  3984. }
  3985. customs = append(customs, cus)
  3986. }
  3987. }
  3988. for _, item := range item.HisAdditionalCharge {
  3989. cus := &Custom{
  3990. ItemId: item.ID,
  3991. AdviceId: 0,
  3992. ProjectId: 0,
  3993. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  3994. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  3995. FeedetlSn: item.FeedetlSn,
  3996. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  3997. MedListCodg: item.XtHisAddtionConfig.Code,
  3998. Type: 3,
  3999. }
  4000. customs = append(customs, cus)
  4001. }
  4002. }
  4003. for _, item := range customs {
  4004. var advice_id int64 = 0
  4005. var project_id int64 = 0
  4006. var item_id int64 = 0
  4007. var types int64 = 0
  4008. if item.Type == 1 {
  4009. advice_id = item.AdviceId
  4010. project_id = 0
  4011. item_id = 0
  4012. } else if item.Type == 2 {
  4013. advice_id = 0
  4014. item_id = 0
  4015. project_id = item.ProjectId
  4016. } else if item.Type == 3 {
  4017. advice_id = 0
  4018. item_id = item.ItemId
  4019. project_id = 0
  4020. }
  4021. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  4022. cut, _ := strconv.ParseFloat(item.Cut, 32)
  4023. pric, _ := strconv.ParseFloat(item.Price, 32)
  4024. info := &models.HisOrderInfo{
  4025. OrderNumber: order.Number,
  4026. UploadDate: time.Now().Unix(),
  4027. AdviceId: advice_id,
  4028. DetItemFeeSumamt: detItemFeeSumamt,
  4029. Cnt: cut,
  4030. Pric: pric,
  4031. PatientId: id,
  4032. Status: 1,
  4033. Mtime: time.Now().Unix(),
  4034. Ctime: time.Now().Unix(),
  4035. UserOrgId: adminUser.CurrentOrgId,
  4036. HisPatientId: his.ID,
  4037. OrderId: order.ID,
  4038. ProjectId: project_id,
  4039. Type: types,
  4040. ItemId: item_id,
  4041. }
  4042. service.CreateOrderInfo(info)
  4043. }
  4044. his.Diagnosis = diagnosis_id
  4045. his.SickType = sick_type
  4046. his.RegisterType = reg_type
  4047. his.MedicalTreatmentType = reg_type
  4048. service.UpdataHisPateint(&his)
  4049. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  4050. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  4051. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  4052. if err == nil {
  4053. c.ServeSuccessJSON(map[string]interface{}{
  4054. "msg": "结算成功",
  4055. })
  4056. }
  4057. } else {
  4058. if tempOrder.IsPre > 0 {
  4059. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  4060. totals, _ := strconv.ParseFloat(allTotal, 64)
  4061. tempOrder.OrderStatus = 2
  4062. tempOrder.PayWay = pay_way
  4063. tempOrder.PayPrice = pay_price
  4064. tempOrder.PayCardNo = pay_card_no
  4065. tempOrder.DiscountPrice = discount_price
  4066. tempOrder.PreferentialPrice = preferential_price
  4067. tempOrder.RealityPrice = reality_price
  4068. tempOrder.FoundPrice = found_price
  4069. tempOrder.MedicalInsurancePrice = medical_insurance_price
  4070. tempOrder.PrivatePrice = private_price
  4071. tempOrder.FaPiaoCode = fapiao_code
  4072. tempOrder.FaPiaoNumber = fapiao_number
  4073. tempOrder.PType = 2
  4074. tempOrder.MedfeeSumamt = totals
  4075. tempOrder.Diagnosis = diagnosis_id
  4076. err = service.SaveHisOrder(&tempOrder)
  4077. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  4078. if err != nil {
  4079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4080. return
  4081. }
  4082. if err == nil {
  4083. c.ServeSuccessJSON(map[string]interface{}{
  4084. "msg": "结算成功",
  4085. })
  4086. }
  4087. }
  4088. }
  4089. }
  4090. //退款
  4091. func (c *HisApiController) Refund() {
  4092. order_id, _ := c.GetInt64("order_id")
  4093. order, _ := service.GetHisOrderByID(order_id)
  4094. adminUser := c.GetAdminUserInfo()
  4095. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  4096. if err == nil {
  4097. c.ServeSuccessJSON(map[string]interface{}{
  4098. "msg": "退费成功",
  4099. })
  4100. } else {
  4101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4102. return
  4103. }
  4104. }
  4105. func (c *HisApiController) RefundNumber() {
  4106. his_patient_id, _ := c.GetInt64("id")
  4107. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4108. info.Status = 0
  4109. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  4110. if count > 0 {
  4111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  4112. return
  4113. }
  4114. err := service.SaveHisPatient(info)
  4115. if err == nil {
  4116. c.ServeSuccessJSON(map[string]interface{}{
  4117. "msg": "退号成功",
  4118. })
  4119. } else {
  4120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4121. return
  4122. }
  4123. }
  4124. func (this *HisApiController) AdditionalCharge() {
  4125. dataBody := make(map[string]interface{}, 0)
  4126. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4127. fmt.Println(err)
  4128. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  4129. patient_id := int64(dataBody["patient_id"].(float64))
  4130. medicineData, _ := dataBody["medicineData"].([]interface{})
  4131. adminUserInfo := this.GetAdminUserInfo()
  4132. orgId := adminUserInfo.CurrentOrgId
  4133. admin_user_id := adminUserInfo.AdminUser.Id
  4134. timeStr := time.Now().Format("2006-01-02")
  4135. timeLayout := "2006-01-02 15:04:05"
  4136. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  4137. timenow := timeStringToTime.Unix()
  4138. var additionalCharges []*models.HisAdditionalCharge
  4139. for _, item := range medicineData {
  4140. var randNum int
  4141. randNum = rand.Intn(10000) + 1000
  4142. timestamp := time.Now().Unix()
  4143. tempTime := time.Unix(timestamp, 0)
  4144. timeFormat := tempTime.Format("20060102150405")
  4145. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4146. items := item.(map[string]interface{})
  4147. money := items["price"].(string)
  4148. item_id_str := items["item_id"].(string)
  4149. name := items["name"].(string)
  4150. id_str := items["id"].(string)
  4151. moneys, _ := strconv.ParseInt(money, 10, 64)
  4152. monStr := strconv.FormatInt(moneys, 10)
  4153. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  4154. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  4155. id, _ := strconv.ParseInt(id_str, 10, 64)
  4156. additionalCharge := &models.HisAdditionalCharge{
  4157. ID: id,
  4158. HisPatientId: his_patient_id,
  4159. UserOrgId: orgId,
  4160. PatientId: patient_id,
  4161. RecordDate: timenow,
  4162. Price: monneyStr,
  4163. Status: 1,
  4164. ItemName: name,
  4165. ItemId: item_id,
  4166. AdminUserId: admin_user_id,
  4167. CreatedTime: time.Now().Unix(),
  4168. OrderStatus: 0,
  4169. PrescriptionNumber: "",
  4170. BatchNumber: "",
  4171. FeedetlSn: p_number,
  4172. }
  4173. service.CreateAdditionalCharge(additionalCharge)
  4174. additionalCharges = append(additionalCharges, additionalCharge)
  4175. }
  4176. this.ServeSuccessJSON(map[string]interface{}{
  4177. "msg": "添加成功",
  4178. "additional_charges": additionalCharges,
  4179. })
  4180. }
  4181. func (this *HisApiController) DeleteAddition() {
  4182. id, _ := this.GetInt64("id")
  4183. //TODO 需要判断是否已经结算
  4184. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  4185. if err == nil {
  4186. this.ServeSuccessJSON(map[string]interface{}{
  4187. "msg": "删除成功",
  4188. })
  4189. return
  4190. } else {
  4191. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4192. return
  4193. }
  4194. }
  4195. func (this *HisApiController) GetAdminUsers() {
  4196. adminUser := this.GetAdminUserInfo()
  4197. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  4198. this.ServeSuccessJSON(map[string]interface{}{
  4199. "doctors": doctors,
  4200. })
  4201. }
  4202. func (this *HisApiController) GetLastOrNextHisPrescription() {
  4203. change_type, _ := this.GetInt64("type", 0)
  4204. record_date := this.GetString("record_time")
  4205. patient_id, _ := this.GetInt64("patient_id", 0)
  4206. p_type, _ := this.GetInt64("p_type", 0)
  4207. timeLayout := "2006-01-02"
  4208. loc, _ := time.LoadLocation("Local")
  4209. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4210. record_time := theAdviceRecordTime.Unix()
  4211. adminUserInfo := this.GetAdminUserInfo()
  4212. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  4213. if err == nil {
  4214. if len(prescriptions) == 0 {
  4215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4216. return
  4217. } else {
  4218. this.ServeSuccessJSON(map[string]interface{}{
  4219. "prescriptions": prescriptions,
  4220. })
  4221. return
  4222. }
  4223. } else {
  4224. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4225. return
  4226. }
  4227. }
  4228. func (this *HisApiController) GetCallHisPrescription() {
  4229. patient_id, _ := this.GetInt64("patient_id", 0)
  4230. timeLayout := "2006-01-02"
  4231. loc, _ := time.LoadLocation("Local")
  4232. start_time := this.GetString("start_time")
  4233. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4234. end_time := this.GetString("end_time")
  4235. p_type, _ := this.GetInt64("p_type")
  4236. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4237. adminUserInfo := this.GetAdminUserInfo()
  4238. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  4239. if err == nil {
  4240. this.ServeSuccessJSON(map[string]interface{}{
  4241. "prescriptions": prescriptions,
  4242. })
  4243. return
  4244. } else {
  4245. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4246. return
  4247. }
  4248. }
  4249. func (this *HisApiController) GetHisDayPrescription() {
  4250. timeLayout := "2006-01-02"
  4251. loc, _ := time.LoadLocation("Local")
  4252. start_time := this.GetString("start_time")
  4253. patient_id, _ := this.GetInt64("patient_id", 0)
  4254. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4255. end_time := this.GetString("end_time")
  4256. p_type, _ := this.GetInt64("p_type")
  4257. order_status, _ := this.GetInt64("type")
  4258. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4259. adminUserInfo := this.GetAdminUserInfo()
  4260. var dayHisPrescription []*models.HisPrescription
  4261. var err error
  4262. if order_status == 1 || order_status == 0 {
  4263. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4264. } else if order_status == 2 {
  4265. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4266. }
  4267. if err == nil {
  4268. this.ServeSuccessJSON(map[string]interface{}{
  4269. "day_prescription": dayHisPrescription,
  4270. })
  4271. return
  4272. } else {
  4273. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4274. return
  4275. }
  4276. }
  4277. func (c *HisApiController) GetHisChargePatientList() {
  4278. record_date := c.GetString("record_date")
  4279. order_status, _ := c.GetInt64("type")
  4280. timeLayout := "2006-01-02"
  4281. loc, _ := time.LoadLocation("Local")
  4282. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4283. if err != nil {
  4284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4285. return
  4286. }
  4287. recordDateTime := theTime.Unix()
  4288. adminInfo := c.GetAdminUserInfo()
  4289. var tempPatients []*service.NewTempPatients
  4290. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4291. if order_status != 2 {
  4292. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4293. } else {
  4294. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4295. }
  4296. var patients []*service.NewTempPatients
  4297. var patients_two []*service.NewTempPatients
  4298. for _, item := range tempPatients {
  4299. //过滤掉没挂号的和没开处方的
  4300. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  4301. patients = append(patients, item)
  4302. }
  4303. //过滤掉没挂号的
  4304. if len(item.HisPatient) > 0 {
  4305. patients_two = append(patients_two, item)
  4306. }
  4307. }
  4308. c.ServeSuccessJSON(map[string]interface{}{
  4309. "list": patients,
  4310. "list_two": patients_two,
  4311. })
  4312. }
  4313. func (c *HisApiController) GetHisUnRegisterPatientList() {
  4314. record_date := c.GetString("record_date")
  4315. timeLayout := "2006-01-02"
  4316. loc, _ := time.LoadLocation("Local")
  4317. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4318. if err != nil {
  4319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4320. return
  4321. }
  4322. recordDateTime := theTime.Unix()
  4323. adminUser := c.GetAdminUserInfo()
  4324. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  4325. var patients []*service.Patients
  4326. for _, item := range tempPatients {
  4327. if item.HisPatient.ID == 0 {
  4328. patients = append(patients, item)
  4329. }
  4330. }
  4331. c.ServeSuccessJSON(map[string]interface{}{
  4332. "list": patients,
  4333. //"list_two": patients_two,
  4334. })
  4335. }
  4336. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  4337. newArr = make([]*service.Patients, 0)
  4338. for i := 0; i < len(patient); i++ {
  4339. repeat := false
  4340. for j := i + 1; j < len(patient); j++ {
  4341. if patient[i].ID == patient[j].ID {
  4342. repeat = true
  4343. break
  4344. }
  4345. }
  4346. if !repeat {
  4347. newArr = append(newArr, patient[i])
  4348. }
  4349. }
  4350. return
  4351. }
  4352. func (c *HisApiController) GetHisChargePatientInfo() {
  4353. patient_id, _ := c.GetInt64("patient_id")
  4354. his_patient_id, _ := c.GetInt64("his_patient_id")
  4355. record_date := c.GetString("record_date")
  4356. //start_time := c.GetString("start_time")
  4357. //end_time := c.GetString("end_time")
  4358. order_status, _ := c.GetInt64("type", 0)
  4359. p_type, _ := c.GetInt64("p_type", 0)
  4360. order_id, _ := c.GetInt64("order_id", 0)
  4361. timeLayout := "2006-01-02"
  4362. loc, _ := time.LoadLocation("Local")
  4363. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4364. if err != nil {
  4365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4366. return
  4367. }
  4368. recordDateTime := theTime.Unix()
  4369. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4370. //if err != nil {
  4371. //
  4372. //}
  4373. //startRecordDateTime := startTime.Unix()
  4374. //
  4375. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4376. //if err != nil {
  4377. //
  4378. //}
  4379. //endRecordDateTime := endTime.Unix()
  4380. admin := c.GetAdminUserInfo()
  4381. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4382. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  4383. var prescriptions []*models.HisPrescription
  4384. order, _ := service.GetHisOrderByID(order_id)
  4385. if order_status == 1 || order_status == 0 {
  4386. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  4387. } else if order_status == 2 {
  4388. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  4389. }
  4390. //var monthPrescriptions []*models.HisPrescription
  4391. //if order_status == 1 || order_status == 0 {
  4392. // monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  4393. //} else if order_status == 2 {
  4394. // monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  4395. //}
  4396. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  4397. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4398. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4399. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  4400. //获取所有科室信息
  4401. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  4402. c.ServeSuccessJSON(map[string]interface{}{
  4403. "his_info": his_patient_info,
  4404. "xt_info": xt_patient_info,
  4405. "prescription": prescriptions,
  4406. "case_history": case_history,
  4407. "info": patientPrescriptionInfo,
  4408. "last_info": lastPatientPrescriptionInfo,
  4409. //"month_prescriptions": monthPrescriptions,
  4410. "order": order,
  4411. "doctors": doctors,
  4412. "department": department,
  4413. })
  4414. return
  4415. }
  4416. func (c *HisApiController) GetAllOrderDetail() {
  4417. order_id, _ := c.GetInt64("id", 0)
  4418. order, _ := service.GetHisOrderByID(order_id)
  4419. if order.ID == 0 {
  4420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4421. return
  4422. }
  4423. org_id := c.GetAdminUserInfo().CurrentOrgId
  4424. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4425. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4426. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4427. c.ServeSuccessJSON(map[string]interface{}{
  4428. "order": order,
  4429. "order_info": order_info,
  4430. "patient": patient,
  4431. "admin_info": adminInfo,
  4432. })
  4433. return
  4434. }
  4435. func (c *HisApiController) GetAllOrderDetailCollect() {
  4436. order_id, _ := c.GetInt64("id", 0)
  4437. order, _ := service.GetHisOrderByID(order_id)
  4438. if order.ID == 0 {
  4439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4440. return
  4441. }
  4442. org_id := c.GetAdminUserInfo().CurrentOrgId
  4443. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4444. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4445. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4446. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  4447. if his.BalanceAccountsType != 2 {
  4448. c.ServeSuccessJSON(map[string]interface{}{
  4449. "order": order,
  4450. "order_info": order_info,
  4451. "patient": patient,
  4452. "admin_info": adminInfo,
  4453. })
  4454. } else {
  4455. for _, item := range order_info {
  4456. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  4457. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  4458. item.MedChrgitmType = "09"
  4459. }
  4460. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  4461. if item.HisPrescriptionProject.Type == 2 {
  4462. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  4463. case 1:
  4464. item.MedChrgitmType = "14"
  4465. break
  4466. case 2:
  4467. item.MedChrgitmType = "05"
  4468. break
  4469. case 3:
  4470. item.MedChrgitmType = "04"
  4471. break
  4472. case 4:
  4473. item.MedChrgitmType = "14"
  4474. break
  4475. case 5:
  4476. item.MedChrgitmType = "08"
  4477. break
  4478. case 6:
  4479. item.MedChrgitmType = "14"
  4480. break
  4481. case 7:
  4482. item.MedChrgitmType = "14"
  4483. break
  4484. case 8:
  4485. item.MedChrgitmType = "03"
  4486. break
  4487. case 9:
  4488. item.MedChrgitmType = "14"
  4489. break
  4490. }
  4491. } else if item.HisPrescriptionProject.Type == 3 {
  4492. item.MedChrgitmType = "08"
  4493. }
  4494. }
  4495. }
  4496. c.ServeSuccessJSON(map[string]interface{}{
  4497. "order": order,
  4498. "order_info": order_info,
  4499. "patient": patient,
  4500. "admin_info": adminInfo,
  4501. })
  4502. }
  4503. return
  4504. }
  4505. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  4506. page, _ := c.GetInt64("page")
  4507. limit, _ := c.GetInt64("limit")
  4508. keywords := c.GetString("keywords")
  4509. start_time := c.GetString("start_time")
  4510. end_time := c.GetString("end_time")
  4511. //clr_type := c.GetString("clr_type")
  4512. insutype := c.GetString("insutype")
  4513. timeLayout := "2006-01-02"
  4514. loc, _ := time.LoadLocation("Local")
  4515. var theStartTIme int64
  4516. if len(start_time) > 0 {
  4517. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4518. theStartTIme = theTime.Unix()
  4519. }
  4520. var theEndtTIme int64
  4521. if len(end_time) > 0 {
  4522. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4523. theEndtTIme = theTime.Unix()
  4524. }
  4525. if page <= 0 {
  4526. page = 1
  4527. }
  4528. if limit <= 0 {
  4529. limit = 10
  4530. }
  4531. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  4532. c.ServeSuccessJSON(map[string]interface{}{
  4533. "total": total,
  4534. "list": list,
  4535. })
  4536. return
  4537. }
  4538. func (c *HisApiController) GetPutOnRecordList() {
  4539. page, _ := c.GetInt64("page")
  4540. limit, _ := c.GetInt64("limit")
  4541. keywords := c.GetString("keywords")
  4542. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  4543. if page <= 0 {
  4544. page = 1
  4545. }
  4546. if limit <= 0 {
  4547. limit = 10
  4548. }
  4549. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  4550. c.ServeSuccessJSON(map[string]interface{}{
  4551. "total": total,
  4552. "list": list,
  4553. })
  4554. return
  4555. }
  4556. func (c *HisApiController) GetCompareData() {
  4557. start_time := c.GetString("start_time")
  4558. end_time := c.GetString("end_time")
  4559. insutype := c.GetString("insutype")
  4560. timeLayout := "2006-01-02"
  4561. loc, _ := time.LoadLocation("Local")
  4562. var theStartTIme int64
  4563. if len(start_time) > 0 {
  4564. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4565. if err != nil {
  4566. theStartTIme = 0
  4567. }
  4568. theStartTIme = theTime.Unix()
  4569. }
  4570. var theEndtTIme int64
  4571. if len(end_time) > 0 {
  4572. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4573. if err != nil {
  4574. theEndtTIme = 0
  4575. }
  4576. theEndtTIme = theTime.Unix()
  4577. }
  4578. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype)
  4579. fmt.Println(err)
  4580. if err == nil {
  4581. c.ServeSuccessJSON(map[string]interface{}{
  4582. "list": formData,
  4583. })
  4584. } else {
  4585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4586. return
  4587. }
  4588. }
  4589. func (c *HisApiController) GetFaPiaoData() {
  4590. order_id, _ := c.GetInt64("order_id")
  4591. patient_id, _ := c.GetInt64("patient_id")
  4592. number := c.GetString("number")
  4593. adminUser := c.GetAdminUserInfo()
  4594. order, _ := service.GetHisOrderByID(order_id)
  4595. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4596. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  4597. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4598. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  4599. //prescriptions, _ := service.GetHisPrescriptionThree(adminUser.CurrentOrgId, patient_id, order.Number)
  4600. var bedCostTotal float64 = 0 //床位总费
  4601. var bedCostSelfTotal float64 = 0 //床位自费
  4602. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  4603. var operationCostTotal float64 = 0 //手术费
  4604. var operationCostSelfTotal float64 = 0 //手术费
  4605. var operationCostPartSelfTotal float64 = 0 //手术费
  4606. var otherCostTotal float64 = 0 //其他费用
  4607. var otherCostSelfTotal float64 = 0 //其他费用
  4608. var otherCostPartSelfTotal float64 = 0 //其他费用
  4609. var materialCostTotal float64 = 0 //材料费
  4610. var materialCostSelfTotal float64 = 0 //材料费
  4611. var materialCostPartSelfTotal float64 = 0 //材料费
  4612. var westernMedicineCostTotal float64 = 0 //西药费
  4613. var westernMedicineCostSelfTotal float64 = 0 //西药费
  4614. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  4615. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  4616. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  4617. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  4618. var checkCostTotal float64 = 0 //检查费
  4619. var checkCostSelfTotal float64 = 0 //检查费
  4620. var checkCostPartSelfTotal float64 = 0 //检查费
  4621. var laboratoryCostTotal float64 = 0 //化验费
  4622. var laboratoryCostSelfTotal float64 = 0 //化验费
  4623. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  4624. var treatCostTotal float64 = 0 //治疗费用
  4625. var treatCostSelfTotal float64 = 0 //治疗费用
  4626. var treatCostPartSelfTotal float64 = 0 //治疗费用
  4627. decimal.DivisionPrecision = 2
  4628. if his.BalanceAccountsType == 2 {
  4629. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  4630. for _, item := range orderInfos_two {
  4631. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  4632. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  4633. item.MedChrgitmType = "09"
  4634. }
  4635. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  4636. if item.HisPrescriptionProject.Type == 2 {
  4637. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  4638. case 1:
  4639. item.MedChrgitmType = "14"
  4640. break
  4641. case 2:
  4642. item.MedChrgitmType = "05"
  4643. break
  4644. case 3:
  4645. item.MedChrgitmType = "04"
  4646. break
  4647. case 4:
  4648. item.MedChrgitmType = "14"
  4649. break
  4650. case 5:
  4651. item.MedChrgitmType = "08"
  4652. break
  4653. case 6:
  4654. item.MedChrgitmType = "14"
  4655. break
  4656. case 7:
  4657. item.MedChrgitmType = "14"
  4658. break
  4659. case 8:
  4660. item.MedChrgitmType = "03"
  4661. break
  4662. case 9:
  4663. item.MedChrgitmType = "14"
  4664. break
  4665. }
  4666. } else if item.HisPrescriptionProject.Type == 3 {
  4667. item.MedChrgitmType = "08"
  4668. }
  4669. }
  4670. }
  4671. for _, item := range orderInfos_two {
  4672. if item.MedChrgitmType == "01" { //床位费
  4673. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4674. bedCostSelfTotal = bedCostTotal
  4675. }
  4676. if item.MedChrgitmType == "03" { //检查费
  4677. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4678. checkCostSelfTotal = checkCostTotal
  4679. }
  4680. if item.MedChrgitmType == "04" { //化验费
  4681. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4682. laboratoryCostSelfTotal = laboratoryCostTotal
  4683. }
  4684. if item.MedChrgitmType == "05" { //治疗费
  4685. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4686. treatCostSelfTotal = treatCostTotal
  4687. }
  4688. if item.MedChrgitmType == "06" { //手术费
  4689. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4690. operationCostSelfTotal = treatCostTotal
  4691. }
  4692. if item.MedChrgitmType == "08" { //材料费
  4693. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4694. materialCostSelfTotal = materialCostTotal
  4695. }
  4696. if item.MedChrgitmType == "09" { //西药费
  4697. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4698. westernMedicineCostSelfTotal = westernMedicineCostTotal
  4699. }
  4700. if item.MedChrgitmType == "11" { //中成费
  4701. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4702. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  4703. }
  4704. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  4705. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4706. otherCostSelfTotal = otherCostTotal
  4707. }
  4708. }
  4709. } else {
  4710. for _, item := range orderInfos {
  4711. if item.MedChrgitmType == "01" { //床位费
  4712. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4713. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4714. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4715. }
  4716. if item.MedChrgitmType == "03" { //检查费
  4717. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4718. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4719. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4720. }
  4721. if item.MedChrgitmType == "04" { //化验费
  4722. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4723. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4724. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4725. }
  4726. if item.MedChrgitmType == "05" { //治疗费
  4727. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4728. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4729. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4730. }
  4731. if item.MedChrgitmType == "06" { //手术费
  4732. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4733. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4734. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4735. }
  4736. if item.MedChrgitmType == "08" { //材料费
  4737. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4738. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4739. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4740. }
  4741. if item.MedChrgitmType == "09" { //西药费
  4742. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4743. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4744. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4745. }
  4746. if item.MedChrgitmType == "11" { //中成费
  4747. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4748. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4749. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4750. }
  4751. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  4752. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4753. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4754. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4755. }
  4756. }
  4757. }
  4758. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  4759. c.ServeSuccessJSON(map[string]interface{}{
  4760. "order_number": order.Number, //业务流水号
  4761. "id_card_no": his.IdCardNo, //社会保障号
  4762. "department_name": department.Name, //科室
  4763. "number": his.Number, //门诊号
  4764. "date": order.SettleEndTime, //结算日期
  4765. "name": order.PsnName, //姓名
  4766. "gender": order.Gend, //性别
  4767. "psn_cash_money": order.PsnCashPay, //个人支付
  4768. "pay_way": "门诊", //结算方式
  4769. "medfee_sumamt": order.MedfeeSumamt, //总费用
  4770. "admin_user_name": admin.UserName, //收款员
  4771. "bedCostTotal": bedCostTotal,
  4772. "bedCostSelfTotal": bedCostSelfTotal,
  4773. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  4774. "operationCostTotal": operationCostTotal,
  4775. "operationCostSelfTotal": operationCostSelfTotal,
  4776. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  4777. "otherCostTotal": otherCostTotal,
  4778. "otherCostSelfTotal": otherCostSelfTotal,
  4779. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  4780. "materialCostTotal": materialCostTotal,
  4781. "materialCostSelfTotal": materialCostSelfTotal,
  4782. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  4783. "westernMedicineCostTotal": westernMedicineCostTotal,
  4784. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  4785. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  4786. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  4787. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  4788. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  4789. "checkCostTotal": checkCostTotal,
  4790. "checkCostSelfTotal": checkCostSelfTotal,
  4791. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  4792. "laboratoryCostTotal": laboratoryCostTotal,
  4793. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  4794. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  4795. "treatCostTotal": treatCostTotal,
  4796. "treatCostSelfTotal": treatCostSelfTotal,
  4797. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  4798. })
  4799. }
  4800. func (this *HisApiController) GetIncomeStatisticsData() {
  4801. start_time := this.GetString("start_time")
  4802. end_time := this.GetString("end_time")
  4803. key_words := this.GetString("key_words")
  4804. limit, _ := this.GetInt64("limit")
  4805. page, _ := this.GetInt64("page")
  4806. if page <= 0 {
  4807. page = 1
  4808. }
  4809. if limit <= 0 {
  4810. limit = 10
  4811. }
  4812. statistics_type, _ := this.GetInt64("statistics_type")
  4813. admin := this.GetAdminUserInfo()
  4814. timeLayout := "2006-01-02"
  4815. loc, _ := time.LoadLocation("Local")
  4816. var theStartTIme int64
  4817. if len(start_time) > 0 {
  4818. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4819. if err != nil {
  4820. theStartTIme = 0
  4821. }
  4822. theStartTIme = theTime.Unix()
  4823. }
  4824. var theEndtTIme int64
  4825. if len(end_time) > 0 {
  4826. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4827. if err != nil {
  4828. theEndtTIme = 0
  4829. }
  4830. theEndtTIme = theTime.Unix()
  4831. }
  4832. if statistics_type == 1 {
  4833. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  4834. this.ServeSuccessJSON(map[string]interface{}{
  4835. "list": list,
  4836. "total": total,
  4837. })
  4838. } else {
  4839. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  4840. this.ServeSuccessJSON(map[string]interface{}{
  4841. "list": list,
  4842. "total": total,
  4843. })
  4844. }
  4845. }
  4846. func (c *HisApiController) PostProjectInformation() {
  4847. adminUser := c.GetAdminUserInfo()
  4848. orgId := adminUser.CurrentOrgId
  4849. dataBody := make(map[string]interface{}, 0)
  4850. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4851. if err != nil {
  4852. utils.ErrorLog(err.Error())
  4853. return
  4854. }
  4855. utils.ErrorLog("%v", dataBody)
  4856. var projectList []*models.HisProject
  4857. var total_goods []interface{}
  4858. tempProjects := dataBody["projects"].([]interface{})
  4859. total_goods = tempProjects
  4860. for index, projectMap := range tempProjects {
  4861. projectM := projectMap.(map[string]interface{})
  4862. var project models.HisProject
  4863. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  4864. utils.ErrorLog("project_name")
  4865. return
  4866. }
  4867. project_name, _ := projectM["project_name"].(string)
  4868. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  4869. err_log := models.ExportErrLog{
  4870. LogType: 6,
  4871. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4872. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  4873. Status: 1,
  4874. CreateTime: time.Now().Unix(),
  4875. UpdateTime: time.Now().Unix(),
  4876. ExportTime: time.Now().Unix(),
  4877. }
  4878. service.CreateExportErrLog(&err_log)
  4879. continue
  4880. }
  4881. project.ProjectName = project_name
  4882. prices := projectM["price"].(string)
  4883. price, _ := strconv.ParseFloat(prices, 64)
  4884. if price <= 0 { //名字为空则生成一条导入错误日志
  4885. err_log := models.ExportErrLog{
  4886. LogType: 6,
  4887. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4888. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  4889. Status: 1,
  4890. CreateTime: time.Now().Unix(),
  4891. UpdateTime: time.Now().Unix(),
  4892. ExportTime: time.Now().Unix(),
  4893. }
  4894. service.CreateExportErrLog(&err_log)
  4895. continue
  4896. }
  4897. project.Price = price
  4898. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  4899. utils.ErrorLog("unit_id")
  4900. return
  4901. }
  4902. unit := projectM["unit"].(string)
  4903. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  4904. err_log := models.ExportErrLog{
  4905. LogType: 6,
  4906. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4907. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  4908. Status: 1,
  4909. CreateTime: time.Now().Unix(),
  4910. UpdateTime: time.Now().Unix(),
  4911. ExportTime: time.Now().Unix(),
  4912. }
  4913. service.CreateExportErrLog(&err_log)
  4914. continue
  4915. }
  4916. project.Unit = unit
  4917. cost_classify := projectM["cost_classify"].(string)
  4918. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  4919. err_log := models.ExportErrLog{
  4920. LogType: 6,
  4921. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4922. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  4923. Status: 1,
  4924. CreateTime: time.Now().Unix(),
  4925. UpdateTime: time.Now().Unix(),
  4926. ExportTime: time.Now().Unix(),
  4927. }
  4928. service.CreateExportErrLog(&err_log)
  4929. continue
  4930. }
  4931. var costClassify = "费用类别"
  4932. var cost_classify_id int64
  4933. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  4934. if len(cost_classify) != 0 {
  4935. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  4936. if errcode == gorm.ErrRecordNotFound {
  4937. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  4938. dataconfig := models.DictDataconfig{
  4939. ParentId: costClassifyConfig.ID,
  4940. Module: "system",
  4941. OrgId: orgId,
  4942. Name: cost_classify,
  4943. FieldName: "",
  4944. Value: costConfig.Value + 1,
  4945. CreatedTime: "",
  4946. UpdatedTime: "",
  4947. CreateUserId: adminUser.AdminUser.Id,
  4948. Status: 1,
  4949. Remark: "",
  4950. DeleteIdSystem: 0,
  4951. Title: "",
  4952. Content: "",
  4953. Order: 0,
  4954. Code: "",
  4955. }
  4956. service.CreatedDicConfig(&dataconfig)
  4957. }
  4958. }
  4959. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  4960. for _, it := range costClassList {
  4961. if cost_classify == it.Name {
  4962. cost_classify_id = int64(it.Value)
  4963. }
  4964. }
  4965. project.CostClassify = cost_classify_id
  4966. executive_section := projectM["executive_section"].(string)
  4967. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  4968. err_log := models.ExportErrLog{
  4969. LogType: 6,
  4970. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4971. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  4972. Status: 1,
  4973. CreateTime: time.Now().Unix(),
  4974. UpdateTime: time.Now().Unix(),
  4975. ExportTime: time.Now().Unix(),
  4976. }
  4977. service.CreateExportErrLog(&err_log)
  4978. continue
  4979. }
  4980. if len(executive_section) != 0 {
  4981. //查找科室是否有内容
  4982. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  4983. if errcodedepart == gorm.ErrRecordNotFound {
  4984. department := models.XtHisDepartment{
  4985. Name: executive_section,
  4986. Status: 1,
  4987. UserOrgId: adminUser.CurrentOrgId,
  4988. CreatedTime: time.Now().Unix(),
  4989. }
  4990. service.CreateDePartment(&department)
  4991. }
  4992. }
  4993. var executive_section_id int64
  4994. departMentList, _ := service.GetAllDepartMent(orgId)
  4995. for _, it := range departMentList {
  4996. if executive_section == it.Name {
  4997. executive_section_id = it.ID
  4998. }
  4999. }
  5000. project.ExecutiveSection = executive_section_id
  5001. medical_coverage := projectM["medical_coverage"].(string)
  5002. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  5003. err_log := models.ExportErrLog{
  5004. LogType: 6,
  5005. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5006. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5007. Status: 1,
  5008. CreateTime: time.Now().Unix(),
  5009. UpdateTime: time.Now().Unix(),
  5010. ExportTime: time.Now().Unix(),
  5011. }
  5012. service.CreateExportErrLog(&err_log)
  5013. continue
  5014. }
  5015. var medicalCoverage = "医保等级"
  5016. var medical_coverage_id int64
  5017. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  5018. if len(medical_coverage) != 0 {
  5019. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  5020. if errormedicalcoverage == gorm.ErrRecordNotFound {
  5021. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  5022. dataconfig := models.DictDataconfig{
  5023. ParentId: medicalCoverageConfig.ID,
  5024. Module: "system",
  5025. OrgId: orgId,
  5026. Name: medical_coverage,
  5027. FieldName: "",
  5028. Value: medicalCoverageConfig.Value + 1,
  5029. CreatedTime: "",
  5030. UpdatedTime: "",
  5031. CreateUserId: adminUser.AdminUser.Id,
  5032. Status: 1,
  5033. Remark: "",
  5034. DeleteIdSystem: 0,
  5035. Title: "",
  5036. Content: "",
  5037. Order: 0,
  5038. Code: "",
  5039. }
  5040. service.CreatedDicConfig(&dataconfig)
  5041. }
  5042. }
  5043. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  5044. for _, it := range medicalCoverageList {
  5045. if medical_coverage == it.Name {
  5046. medical_coverage_id = int64(it.Value)
  5047. }
  5048. }
  5049. project.MedicalCoverage = medical_coverage_id
  5050. pinyin := projectM["pinyin"].(string)
  5051. project.Pinyin = pinyin
  5052. wubi := projectM["wubi"].(string)
  5053. project.Wubi = wubi
  5054. statistical_classification := projectM["statistical_classification"].(string)
  5055. var statisticalClassification = "统计分类"
  5056. var statistical_classification_id int64
  5057. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  5058. if len(statistical_classification) != 0 {
  5059. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  5060. if classificationerrcodes == gorm.ErrRecordNotFound {
  5061. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  5062. dataconfig := models.DictDataconfig{
  5063. ParentId: classiFication.ID,
  5064. Module: "system",
  5065. OrgId: orgId,
  5066. Name: statistical_classification,
  5067. FieldName: "",
  5068. Value: classiFicationConfig.Value + 1,
  5069. CreatedTime: "",
  5070. UpdatedTime: "",
  5071. CreateUserId: adminUser.AdminUser.Id,
  5072. Status: 1,
  5073. Remark: "",
  5074. DeleteIdSystem: 0,
  5075. Title: "",
  5076. Content: "",
  5077. Order: 0,
  5078. Code: "",
  5079. }
  5080. service.CreatedDicConfig(&dataconfig)
  5081. }
  5082. }
  5083. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  5084. for _, it := range classiFicationList {
  5085. if statistical_classification == it.Name {
  5086. statistical_classification_id = int64(it.Value)
  5087. }
  5088. }
  5089. project.StatisticalClassification = statistical_classification_id
  5090. disease_directory := int64(projectM["disease_directory"].(float64))
  5091. project.DiseaseDirectory = disease_directory
  5092. is_record := int64(projectM["is_record"].(float64))
  5093. project.IsRecord = is_record
  5094. medical_code := projectM["medical_code"].(string)
  5095. project.MedicalCode = medical_code
  5096. tube_color := projectM["tube_color"].(string)
  5097. var tubeColor = "试管颜色"
  5098. var tube_color_id int64
  5099. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  5100. if len(tube_color) != 0 {
  5101. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  5102. if errcodetube == gorm.ErrRecordNotFound {
  5103. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  5104. dataconfig := models.DictDataconfig{
  5105. ParentId: tubeColorConfig.ID,
  5106. Module: "system",
  5107. OrgId: orgId,
  5108. Name: tube_color,
  5109. FieldName: "",
  5110. Value: tubeConfig.Value + 1,
  5111. CreatedTime: "",
  5112. UpdatedTime: "",
  5113. CreateUserId: adminUser.AdminUser.Id,
  5114. Status: 1,
  5115. Remark: "",
  5116. DeleteIdSystem: 0,
  5117. Title: "",
  5118. Content: "",
  5119. Order: 0,
  5120. Code: "",
  5121. }
  5122. service.CreatedDicConfig(&dataconfig)
  5123. }
  5124. }
  5125. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  5126. for _, it := range tubeColorList {
  5127. if tube_color == it.Name {
  5128. tube_color_id = int64(it.Value)
  5129. }
  5130. }
  5131. project.TubeColor = tube_color_id
  5132. single_dose := projectM["single_dose"].(string)
  5133. project.SingleDose = single_dose
  5134. execution_frequency := projectM["execution_frequency"].(string)
  5135. project.ExecutionFrequency = execution_frequency
  5136. delivery_way := projectM["delivery_way"].(string)
  5137. project.DeliveryWay = delivery_way
  5138. number_days := projectM["number_days"].(string)
  5139. project.NumberDays = number_days
  5140. total := projectM["total"].(string)
  5141. project.Total = total
  5142. medical_status := int64(projectM["medical_status"].(float64))
  5143. project.MedicalStatus = medical_status
  5144. category := int64(projectM["category"].(float64))
  5145. project.Category = category
  5146. specail_project := int64(projectM["specail_project"].(float64))
  5147. project.SpecailProject = specail_project
  5148. social_security_directory_code := projectM["social_security_directory_code"].(string)
  5149. project.SocialSecurityDirectoryCode = social_security_directory_code
  5150. remark := projectM["remark"].(string)
  5151. project.Remark = remark
  5152. record_date := projectM["record_date"].(string)
  5153. timeLayout := "2006-01-02"
  5154. loc, _ := time.LoadLocation("Local")
  5155. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5156. project.RecordDate = theTime.Unix()
  5157. projectList = append(projectList, &project)
  5158. }
  5159. export_time := time.Now().Unix()
  5160. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  5161. if len(projectList) > 0 {
  5162. for _, item := range projectList {
  5163. project := models.HisProject{
  5164. ProjectName: item.ProjectName,
  5165. Price: item.Price,
  5166. Unit: item.Unit,
  5167. CostClassify: item.CostClassify,
  5168. ExecutiveSection: item.ExecutiveSection,
  5169. MedicalCoverage: item.MedicalCoverage,
  5170. UserOrgId: orgId,
  5171. Status: 1,
  5172. CreatedTime: time.Now().Unix(),
  5173. Pinyin: item.Pinyin,
  5174. Wubi: item.Wubi,
  5175. StatisticalClassification: item.StatisticalClassification,
  5176. DiseaseDirectory: item.DiseaseDirectory,
  5177. IsRecord: item.IsRecord,
  5178. MedicalCode: item.MedicalCode,
  5179. TubeColor: item.TubeColor,
  5180. SingleDose: item.SingleDose,
  5181. DeliveryWay: item.DeliveryWay,
  5182. NumberDays: item.NumberDays,
  5183. Total: item.Total,
  5184. Category: item.Category,
  5185. MedicalStatus: item.MedicalStatus,
  5186. SpecailProject: item.SpecailProject,
  5187. RecordDate: item.RecordDate,
  5188. Remark: item.Remark,
  5189. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5190. ExecutionFrequency: item.ExecutionFrequency,
  5191. }
  5192. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  5193. if errcodeproject == gorm.ErrRecordNotFound {
  5194. service.CreateProjectInfomation(&project)
  5195. } else if errcodeproject == nil {
  5196. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  5197. }
  5198. log := models.ExportLog{
  5199. LogType: 6,
  5200. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5201. TotalNum: int64(len(total_goods)),
  5202. FailNum: int64(len(errLogs)),
  5203. SuccessNum: int64(len(projectList)),
  5204. CreateTime: time.Now().Unix(),
  5205. UpdateTime: time.Now().Unix(),
  5206. ExportTime: export_time,
  5207. Status: 1,
  5208. }
  5209. service.CreateExportLog(&log)
  5210. c.ServeSuccessJSON(map[string]interface{}{
  5211. "msg": "导入成功",
  5212. "total_num": len(total_goods),
  5213. "success_num": len(projectList),
  5214. "fail_num": int64(len(errLogs)),
  5215. })
  5216. }
  5217. } else {
  5218. log := models.ExportLog{
  5219. LogType: 6,
  5220. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5221. TotalNum: int64(len(total_goods)),
  5222. FailNum: int64(len(errLogs)),
  5223. SuccessNum: int64(len(projectList)),
  5224. CreateTime: time.Now().Unix(),
  5225. UpdateTime: time.Now().Unix(),
  5226. ExportTime: export_time,
  5227. Status: 1,
  5228. }
  5229. service.CreateExportLog(&log)
  5230. c.ServeSuccessJSON(map[string]interface{}{
  5231. "msg": "导入成功",
  5232. "total_num": len(total_goods),
  5233. "success_num": len(projectList),
  5234. "fail_num": int64(len(errLogs)),
  5235. })
  5236. }
  5237. }
  5238. //func (this *HisApiController) EditProjectInformation(){
  5239. //
  5240. // id, _ := this.GetInt64("id")
  5241. // project_team := this.GetString("project_team")
  5242. // price := this.GetString("price")
  5243. // price_float, _ := strconv.ParseFloat(price, 64)
  5244. // pinyin := this.GetString("pinyin")
  5245. // wubi := this.GetString("wubi")
  5246. // tube_color, _ := this.GetInt64("tube_color")
  5247. // team_type, _ := this.GetInt64("team_type")
  5248. // remark := this.GetString("remark")
  5249. // ids := this.GetString("ids")
  5250. // item_id := this.GetString("item_id")
  5251. // projectTeam := models.XtHisProjectTeam{
  5252. // ProjectTeam: project_team,
  5253. // Price: price_float,
  5254. // Pinyin: pinyin,
  5255. // Wubi: wubi,
  5256. // TubeColor: tube_color,
  5257. // TeamType: team_type,
  5258. // Remark: remark,
  5259. // ProjectId: ids,
  5260. // ItemId: item_id,
  5261. // }
  5262. //
  5263. //
  5264. // dataBody := make(map[string]interface{}, 0)
  5265. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5266. // if err != nil {
  5267. // utils.ErrorLog(err.Error())
  5268. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5269. // return
  5270. // }
  5271. //
  5272. // err = service.UpdatedProjectTeam(id, &projectTeam)
  5273. //
  5274. //
  5275. // if err != nil {
  5276. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5277. // return
  5278. // }
  5279. //
  5280. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  5281. // infos, _ := dataBody["info"].([]interface{})
  5282. // if len(infos) > 0 {
  5283. // var ids []string
  5284. //
  5285. // for _, item := range infos {
  5286. // items := item.(map[string]interface{})
  5287. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5288. // utils.ErrorLog("id")
  5289. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5290. // return
  5291. // }
  5292. // id := int64(items["id"].(float64))
  5293. //
  5294. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5295. // utils.ErrorLog("type")
  5296. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5297. // return
  5298. // }
  5299. // types := int64(items["type"].(float64))
  5300. //
  5301. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5302. // utils.ErrorLog("number")
  5303. // }
  5304. //
  5305. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  5306. //
  5307. // projectList := models.XtHisProjectList{
  5308. // Number: number,
  5309. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  5310. // ProjectId: id,
  5311. // Status: 1,
  5312. // CreatedTime: time.Now().Unix(),
  5313. // UpdatedTime: time.Now().Unix(),
  5314. // TeamId: projectTeam.ID,
  5315. // Type: types,
  5316. // }
  5317. // list := projectList
  5318. //
  5319. // service.CreateProjectList(&list)
  5320. //
  5321. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  5322. //
  5323. // }
  5324. // ids_str := strings.Join(ids, ",")
  5325. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  5326. // service.SaveProjectTeam(&projectTeam)
  5327. // this.ServeSuccessJSON(map[string]interface{}{
  5328. // "projectTeam": projectTeam,
  5329. // })
  5330. // }
  5331. // }
  5332. //}
  5333. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  5334. name := c.GetString("name")
  5335. mode_id, _ := c.GetInt64("mode", 0)
  5336. types, _ := c.GetInt64("type", 0)
  5337. patient_id, _ := c.GetInt64("patient_id", 0)
  5338. types = 1
  5339. adminInfo := c.GetAdminUserInfo()
  5340. template := &models.HisPrescriptionTemplate{
  5341. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5342. PatientId: patient_id,
  5343. Type: types,
  5344. Status: 1,
  5345. Ctime: time.Now().Unix(),
  5346. Mtime: time.Now().Unix(),
  5347. Name: name,
  5348. Mode: mode_id,
  5349. }
  5350. dataBody := make(map[string]interface{}, 0)
  5351. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5352. if err != nil {
  5353. utils.ErrorLog(err.Error())
  5354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5355. return
  5356. }
  5357. err = service.CreateHisPrescriptionTemplate(template)
  5358. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5359. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5360. if len(prescriptions) > 0 {
  5361. for _, item := range prescriptions {
  5362. items := item.(map[string]interface{})
  5363. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5364. utils.ErrorLog("type")
  5365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5366. return
  5367. }
  5368. types := int64(items["type"].(float64))
  5369. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5370. utils.ErrorLog("med_type")
  5371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5372. return
  5373. }
  5374. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5375. ctime := time.Now().Unix()
  5376. prescription := &models.HisPrescriptionInfoTemplate{
  5377. PatientId: patient_id,
  5378. UserOrgId: adminInfo.CurrentOrgId,
  5379. Ctime: ctime,
  5380. Mtime: ctime,
  5381. Type: types,
  5382. Modifier: adminInfo.AdminUser.Id,
  5383. Creator: adminInfo.AdminUser.Id,
  5384. Status: 1,
  5385. PTemplateId: template.ID,
  5386. MedType: med_type,
  5387. }
  5388. service.CreateHisPrescriptionInfoTemplate(prescription)
  5389. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5390. advices := items["advices"].([]interface{})
  5391. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5392. ctime := time.Now().Unix()
  5393. mtime := ctime
  5394. if len(advices) > 0 {
  5395. for _, advice := range advices {
  5396. var s models.HisPrescriptionAdviceTemplate
  5397. s.PrescriptionId = prescription.ID
  5398. s.AdviceType = 2
  5399. s.StopState = 2
  5400. s.ExecutionState = 2
  5401. s.Status = 1
  5402. s.UserOrgId = adminInfo.CurrentOrgId
  5403. s.CreatedTime = ctime
  5404. s.UpdatedTime = mtime
  5405. s.PatientId = patient_id
  5406. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  5407. if errcode > 0 {
  5408. c.ServeFailJSONWithSGJErrorCode(errcode)
  5409. return
  5410. }
  5411. service.CreateHisPrescriptionAdviceTemplate(&s)
  5412. }
  5413. }
  5414. }
  5415. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5416. projects := items["project"].([]interface{})
  5417. if len(projects) > 0 {
  5418. for _, project := range projects {
  5419. var p models.HisPrescriptionProjectTemplate
  5420. p.PrescriptionId = prescription.ID
  5421. p.Ctime = time.Now().Unix()
  5422. p.Mtime = time.Now().Unix()
  5423. p.PatientId = patient_id
  5424. p.UserOrgId = adminInfo.CurrentOrgId
  5425. p.Status = 1
  5426. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  5427. if errcode > 0 {
  5428. c.ServeFailJSONWithSGJErrorCode(errcode)
  5429. return
  5430. }
  5431. service.CreateHisPrescriptionProjectTemplate(&p)
  5432. }
  5433. }
  5434. }
  5435. }
  5436. c.ServeSuccessJSON(map[string]interface{}{
  5437. "msg": "创建成功",
  5438. })
  5439. }
  5440. }
  5441. }
  5442. func (c *HisApiController) PreSettle() {
  5443. id, _ := c.GetInt64("id")
  5444. record_time := c.GetString("record_time")
  5445. his_patient_id, _ := c.GetInt64("his_patient_id")
  5446. timeLayout := "2006-01-02"
  5447. loc, _ := time.LoadLocation("Local")
  5448. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5449. diagnosis_id := c.GetString("diagnosis")
  5450. sick_type, _ := c.GetInt64("sick_type")
  5451. reg_type, _ := c.GetInt64("p_type")
  5452. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  5453. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5454. if err != nil {
  5455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5456. return
  5457. }
  5458. recordDateTime := theTime.Unix()
  5459. adminUser := c.GetAdminUserInfo()
  5460. var prescriptions []*models.HisPrescription
  5461. var start_time int64
  5462. var end_time int64
  5463. ids_str := c.GetString("ids")
  5464. ids_arr := strings.Split(ids_str, ",")
  5465. fmt.Println(reg_type)
  5466. if settle_accounts_type == 1 { //日结
  5467. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5468. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  5469. } else {
  5470. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  5471. }
  5472. fmt.Println(prescriptions)
  5473. } else { //月结
  5474. start_time_str := c.GetString("start_time")
  5475. end_time_str := c.GetString("end_time")
  5476. timeLayout := "2006-01-02"
  5477. loc, _ := time.LoadLocation("Local")
  5478. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5479. if err != nil {
  5480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5481. return
  5482. }
  5483. recordStartTime := theStartTime.Unix()
  5484. start_time = recordStartTime
  5485. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5486. if err != nil {
  5487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5488. return
  5489. }
  5490. recordEndTime := theEndTime.Unix()
  5491. end_time = recordEndTime
  5492. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  5493. }
  5494. if reg_type == 1111 || reg_type == 1112 {
  5495. reg_type = 11
  5496. }
  5497. timestamp := time.Now().Unix()
  5498. tempTime := time.Unix(timestamp, 0)
  5499. timeFormat := tempTime.Format("20060102150405")
  5500. chrgBchno := rand.Intn(100000) + 10000
  5501. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  5502. strconv.FormatInt(his.PatientId, 10)
  5503. var ids []int64
  5504. for _, item := range prescriptions {
  5505. ids = append(ids, item.ID)
  5506. }
  5507. fmt.Println(ids)
  5508. var total float64
  5509. for _, item := range prescriptions {
  5510. fmt.Println(item)
  5511. if item.Type == 1 { //药品
  5512. for _, subItem := range item.HisDoctorAdviceInfo {
  5513. total = total + (subItem.Price * subItem.PrescribingNumber)
  5514. }
  5515. }
  5516. if item.Type == 2 { //项目
  5517. for _, subItem := range item.HisPrescriptionProject {
  5518. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5519. total = total + (subItem.Price * cnt)
  5520. }
  5521. }
  5522. for _, subItem := range item.HisAdditionalCharge {
  5523. total = total + (subItem.Price * float64(subItem.Count))
  5524. }
  5525. }
  5526. allTotal := fmt.Sprintf("%.2f", total)
  5527. totals, _ := strconv.ParseFloat(allTotal, 64)
  5528. order := &models.HisOrder{
  5529. UserOrgId: adminUser.CurrentOrgId,
  5530. HisPatientId: his.ID,
  5531. PatientId: id,
  5532. SettleAccountsDate: recordDateTime,
  5533. Ctime: time.Now().Unix(),
  5534. Mtime: time.Now().Unix(),
  5535. Status: 1,
  5536. OrderStatus: 1,
  5537. MdtrtId: his.Number,
  5538. Number: chrg_bchno,
  5539. MedfeeSumamt: totals,
  5540. SettleEndTime: end_time,
  5541. SettleStartTime: start_time,
  5542. SettleType: settle_accounts_type,
  5543. PType: 2,
  5544. IsPre: 1,
  5545. MedType: strconv.Itoa(int(reg_type)),
  5546. Diagnosis: diagnosis_id,
  5547. }
  5548. err = service.CreateOrder(order)
  5549. if err != nil {
  5550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5551. return
  5552. }
  5553. var customs []*Custom
  5554. for _, item := range prescriptions {
  5555. fmt.Println(item.Type)
  5556. if item.Type == 1 { //药品
  5557. for _, subItem := range item.HisDoctorAdviceInfo {
  5558. cus := &Custom{
  5559. AdviceId: subItem.ID,
  5560. ProjectId: 0,
  5561. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  5562. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  5563. FeedetlSn: subItem.FeedetlSn,
  5564. Price: fmt.Sprintf("%.2f", subItem.Price),
  5565. MedListCodg: subItem.MedListCodg,
  5566. Type: 1,
  5567. }
  5568. customs = append(customs, cus)
  5569. }
  5570. }
  5571. if item.Type == 2 { //项目
  5572. for _, subItem := range item.HisPrescriptionProject {
  5573. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5574. cus := &Custom{
  5575. AdviceId: 0,
  5576. ProjectId: subItem.ID,
  5577. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  5578. Cut: fmt.Sprintf("%.2f", cnt),
  5579. FeedetlSn: subItem.FeedetlSn,
  5580. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  5581. MedListCodg: subItem.MedListCodg,
  5582. Type: 2,
  5583. }
  5584. customs = append(customs, cus)
  5585. }
  5586. }
  5587. for _, item := range item.HisAdditionalCharge {
  5588. cus := &Custom{
  5589. ItemId: item.ID,
  5590. AdviceId: 0,
  5591. ProjectId: 0,
  5592. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  5593. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  5594. FeedetlSn: item.FeedetlSn,
  5595. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  5596. MedListCodg: item.XtHisAddtionConfig.Code,
  5597. Type: 3,
  5598. }
  5599. customs = append(customs, cus)
  5600. }
  5601. }
  5602. fmt.Println(customs)
  5603. for _, item := range customs {
  5604. var advice_id int64 = 0
  5605. var project_id int64 = 0
  5606. var item_id int64 = 0
  5607. var types int64 = 0
  5608. if item.Type == 1 {
  5609. advice_id = item.AdviceId
  5610. project_id = 0
  5611. item_id = 0
  5612. } else if item.Type == 2 {
  5613. advice_id = 0
  5614. item_id = 0
  5615. project_id = item.ProjectId
  5616. } else if item.Type == 3 {
  5617. advice_id = 0
  5618. item_id = item.ItemId
  5619. project_id = 0
  5620. }
  5621. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  5622. cut, _ := strconv.ParseFloat(item.Cut, 32)
  5623. pric, _ := strconv.ParseFloat(item.Price, 32)
  5624. info := &models.HisOrderInfo{
  5625. OrderNumber: order.Number,
  5626. UploadDate: time.Now().Unix(),
  5627. AdviceId: advice_id,
  5628. DetItemFeeSumamt: detItemFeeSumamt,
  5629. Cnt: cut,
  5630. Pric: pric,
  5631. PatientId: id,
  5632. Status: 1,
  5633. Mtime: time.Now().Unix(),
  5634. Ctime: time.Now().Unix(),
  5635. UserOrgId: adminUser.CurrentOrgId,
  5636. HisPatientId: his.ID,
  5637. OrderId: order.ID,
  5638. ProjectId: project_id,
  5639. Type: types,
  5640. ItemId: item_id,
  5641. }
  5642. service.CreateOrderInfo(info)
  5643. }
  5644. his.SickType = sick_type
  5645. service.UpdataHisPateint(&his)
  5646. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  5647. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  5648. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  5649. if err == nil {
  5650. c.ServeSuccessJSON(map[string]interface{}{
  5651. "msg": "结算成功",
  5652. })
  5653. }
  5654. }
  5655. type CustomOrderInfo struct {
  5656. Name string
  5657. Spec string
  5658. Unit string
  5659. Count float64
  5660. Price float64
  5661. Total float64
  5662. }
  5663. func (c *HisApiController) GetPrivateExpensesInfo() {
  5664. order_id, _ := c.GetInt64("id", 0)
  5665. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  5666. order, _ := service.GetHisOrderByID(order_id)
  5667. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  5668. if order.ID == 0 {
  5669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  5670. return
  5671. }
  5672. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  5673. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  5674. org_id := c.GetAdminUserInfo().CurrentOrgId
  5675. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  5676. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  5677. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  5678. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  5679. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  5680. var orderInfos_four []*models.HisOrderInfoTwo
  5681. for _, item := range orderInfos_three {
  5682. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  5683. item.HisPrescriptionProject.IsCheckTeam = 1
  5684. orderInfos_four = append(orderInfos_four, item)
  5685. }
  5686. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  5687. item.HisPrescriptionProject.IsCheckTeam = 2
  5688. orderInfos_two = append(orderInfos_two, item)
  5689. }
  5690. }
  5691. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  5692. var cus_slice []CustomOrderInfo
  5693. for _, item := range new_order_info {
  5694. var cus CustomOrderInfo
  5695. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  5696. cus.Unit = ""
  5697. cus.Spec = ""
  5698. var total float64
  5699. for _, subItem := range orderInfos_four {
  5700. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  5701. total = total + subItem.DetItemFeeSumamt
  5702. fmt.Println(subItem.DetItemFeeSumamt)
  5703. }
  5704. }
  5705. cus.Count = 1
  5706. cus.Total = total
  5707. cus_slice = append(cus_slice, cus)
  5708. }
  5709. orderInfos = append(orderInfos, orderInfos_two...)
  5710. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  5711. orderInfos = append(orderInfos, orderInfos_three...)
  5712. }
  5713. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  5714. c.ServeSuccessJSON(map[string]interface{}{
  5715. "order": order,
  5716. "order_info": orderInfos,
  5717. "patient": patient,
  5718. "admin_info": adminInfo,
  5719. "his": his,
  5720. "current_admin": role,
  5721. "org_config": miConfig,
  5722. "new_order_info": cus_slice,
  5723. })
  5724. }
  5725. func (this *HisApiController) ChangeMedType() {
  5726. med_type := this.GetString("med_type")
  5727. id, _ := this.GetInt64("id")
  5728. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  5729. prescription.MedType = med_type
  5730. err := service.SaveHisPrescription(&prescription)
  5731. if err == nil {
  5732. this.ServeSuccessJSON(map[string]interface{}{
  5733. "msg": "修改成功",
  5734. })
  5735. } else {
  5736. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5737. return
  5738. }
  5739. }
  5740. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  5741. patient_id, _ := c.GetInt64("patient_id")
  5742. his_patient_id, _ := c.GetInt64("his_patient_id")
  5743. record_date := c.GetString("record_date")
  5744. start_time := c.GetString("start_time")
  5745. end_time := c.GetString("end_time")
  5746. order_status, _ := c.GetInt64("type", 0)
  5747. p_type, _ := c.GetInt64("p_type", 0)
  5748. order_id, _ := c.GetInt64("order_id", 0)
  5749. timeLayout := "2006-01-02"
  5750. loc, _ := time.LoadLocation("Local")
  5751. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5752. if err != nil {
  5753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5754. return
  5755. }
  5756. recordDateTime := theTime.Unix()
  5757. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5758. if err != nil {
  5759. }
  5760. startRecordDateTime := startTime.Unix()
  5761. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5762. if err != nil {
  5763. }
  5764. endRecordDateTime := endTime.Unix()
  5765. admin := c.GetAdminUserInfo()
  5766. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  5767. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  5768. order, _ := service.GetHisOrderByID(order_id)
  5769. var monthPrescriptions []*models.HisPrescription
  5770. if order_status == 1 || order_status == 0 {
  5771. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  5772. } else if order_status == 2 {
  5773. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  5774. }
  5775. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  5776. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5777. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  5778. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  5779. //获取所有科室信息
  5780. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  5781. c.ServeSuccessJSON(map[string]interface{}{
  5782. "his_info": his_patient_info,
  5783. "xt_info": xt_patient_info,
  5784. "case_history": case_history,
  5785. "info": patientPrescriptionInfo,
  5786. "last_info": lastPatientPrescriptionInfo,
  5787. "month_prescriptions": monthPrescriptions,
  5788. "order": order,
  5789. "doctors": doctors,
  5790. "department": department,
  5791. })
  5792. return
  5793. }
  5794. func (c *HisApiController) GetHisMonthPatientInfo() {
  5795. patient_id, _ := c.GetInt64("patient_id")
  5796. his_patient_id, _ := c.GetInt64("his_patient_id")
  5797. record_date := c.GetString("record_date")
  5798. number := c.GetString("number")
  5799. start_time := c.GetString("start_time")
  5800. end_time := c.GetString("end_time")
  5801. p_type, _ := c.GetInt64("p_type")
  5802. timeLayout := "2006-01-02"
  5803. loc, _ := time.LoadLocation("Local")
  5804. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5805. if err != nil {
  5806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5807. return
  5808. }
  5809. recordDateTime := theTime.Unix()
  5810. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5811. if err != nil {
  5812. }
  5813. startRecordDateTime := startTime.Unix()
  5814. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5815. if err != nil {
  5816. }
  5817. endRecordDateTime := endTime.Unix()
  5818. admin := c.GetAdminUserInfo()
  5819. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  5820. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  5821. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  5822. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  5823. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  5824. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5825. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  5826. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  5827. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  5828. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  5829. //获取所有科室信息
  5830. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  5831. c.ServeSuccessJSON(map[string]interface{}{
  5832. "his_info": his_patient_info,
  5833. "xt_info": xt_patient_info,
  5834. "case_history": case_history,
  5835. "info": patientPrescriptionInfo,
  5836. "month_prescriptions": monthPrescriptions,
  5837. "order": order,
  5838. "doctors": doctors,
  5839. "department": department,
  5840. "count": count,
  5841. "drugStockConfig": drugStockConfig,
  5842. "last_info": lastPatientPrescriptionInfo,
  5843. })
  5844. return
  5845. }
  5846. func (c *HisApiController) GetAllOrder() {
  5847. org_id := c.GetAdminUserInfo().CurrentOrgId
  5848. orders, _ := service.GetNewHisOrderList(org_id)
  5849. c.ServeSuccessJSON(map[string]interface{}{
  5850. "order": orders,
  5851. })
  5852. return
  5853. }
  5854. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  5855. newArr = make([]*models.HisOrderInfoTwo, 0)
  5856. for i := 0; i < len(arr); i++ {
  5857. repeat := false
  5858. for j := i + 1; j < len(arr); j++ {
  5859. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  5860. repeat = true
  5861. break
  5862. }
  5863. }
  5864. if !repeat {
  5865. newArr = append(newArr, arr[i])
  5866. }
  5867. }
  5868. return
  5869. }
  5870. //修改处方退库操作 参数传修改之前的处方数据
  5871. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  5872. if advice.ExecutionState == 1 {
  5873. //查询该病人该药品是否有库存记录
  5874. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  5875. if errcode == gorm.ErrRecordNotFound {
  5876. } else {
  5877. //退库
  5878. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5879. if advice.PrescribingNumberUnit == drug.MinUnit {
  5880. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  5881. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5882. //退库
  5883. warehouseInfo := models.DrugWarehouseInfo{
  5884. StockMinNumber: prescribingNumber,
  5885. }
  5886. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  5887. operation_time := time.Now().Unix()
  5888. creater := advice.AdviceDoctor
  5889. ctime := time.Now().Unix()
  5890. timeStr := time.Now().Format("2006-01-02")
  5891. timeArr := strings.Split(timeStr, "-")
  5892. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  5893. total = total + 1
  5894. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5895. cancelStock := models.DrugCancelStock{
  5896. OrderNumber: orderNumber,
  5897. OperaTime: operation_time,
  5898. OrgId: advice.UserOrgId,
  5899. Creater: creater,
  5900. Ctime: ctime,
  5901. Status: 1,
  5902. ReturnTime: advice.AdviceDate,
  5903. Dealer: info.Dealer,
  5904. Manufacturer: info.Manufacturer,
  5905. Type: 1,
  5906. }
  5907. service.AddSigleDrugCancelStock(&cancelStock)
  5908. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  5909. dealer, _ := service.GetDealerById(info.Dealer)
  5910. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  5911. cancelStockInfo := models.DrugCancelStockInfo{
  5912. OrderNumber: cancelInfo.OrderNumber,
  5913. CancelStockId: cancelInfo.ID,
  5914. DrugId: info.DrugId,
  5915. Count: info.Count,
  5916. Status: 1,
  5917. Ctime: ctime,
  5918. OrgId: advice.UserOrgId,
  5919. Type: 1,
  5920. Manufacturer: manufactureName.ManufacturerName,
  5921. Dealer: dealer.DealerName,
  5922. Total: 0,
  5923. RetailPrice: info.RetailPrice,
  5924. RetailTotalPrice: info.RetailTotalPrice,
  5925. Price: info.Price,
  5926. RegisterAccount: "",
  5927. Remark: info.Remark,
  5928. BatchNumber: info.BatchNumber,
  5929. MaxUnit: info.CountUnit,
  5930. ProductDate: info.ProductDate,
  5931. ExpiryDate: info.ExpiryDate,
  5932. BatchNumberId: info.WarehouseInfoId,
  5933. }
  5934. flow := models.DrugFlow{
  5935. WarehousingId: 0,
  5936. DrugId: info.DrugId,
  5937. Number: "",
  5938. BatchNumber: info.BatchNumber,
  5939. Count: info.Count,
  5940. UserOrgId: advice.UserOrgId,
  5941. PatientId: 0,
  5942. SystemTime: ctime,
  5943. ConsumableType: 4,
  5944. IsSys: 0,
  5945. WarehousingOrder: "",
  5946. WarehouseOutId: 0,
  5947. WarehouseOutOrderNumber: "",
  5948. IsEdit: 0,
  5949. CancelStockId: cancelStock.ID,
  5950. CancelOrderNumber: cancelStock.OrderNumber,
  5951. Manufacturer: info.Manufacturer,
  5952. Dealer: info.Dealer,
  5953. Creator: advice.UserOrgId,
  5954. UpdateCreator: 0,
  5955. Status: 1,
  5956. Ctime: time.Now().Unix(),
  5957. Mtime: 0,
  5958. Price: info.Price,
  5959. WarehousingDetailId: 0,
  5960. WarehouseOutDetailId: 0,
  5961. CancelOutDetailId: 0,
  5962. ExpireDate: info.ExpiryDate,
  5963. ProductDate: info.ProductDate,
  5964. MaxUnit: info.CountUnit,
  5965. MinUnit: "",
  5966. }
  5967. service.CreatedCancelStock(cancelStockInfo)
  5968. service.CreateDrugFlowOne(flow)
  5969. } else {
  5970. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  5971. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5972. fmt.Println("PrescribingNumber", prescribingNumber)
  5973. if advice.PrescribingNumberUnit == drug.MaxUnit {
  5974. warehouseInfo := models.DrugWarehouseInfo{
  5975. StockMinNumber: prescribingNumber,
  5976. }
  5977. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  5978. }
  5979. operation_time := time.Now().Unix()
  5980. creater := advice.AdviceDoctor
  5981. ctime := time.Now().Unix()
  5982. timeStr := time.Now().Format("2006-01-02")
  5983. timeArr := strings.Split(timeStr, "-")
  5984. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  5985. total = total + 1
  5986. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5987. cancelStock := models.DrugCancelStock{
  5988. OrderNumber: orderNumber,
  5989. OperaTime: operation_time,
  5990. OrgId: advice.UserOrgId,
  5991. Creater: creater,
  5992. Ctime: ctime,
  5993. Status: 1,
  5994. ReturnTime: advice.AdviceDate,
  5995. Dealer: info.Dealer,
  5996. Manufacturer: info.Manufacturer,
  5997. Type: 1,
  5998. }
  5999. service.AddSigleDrugCancelStock(&cancelStock)
  6000. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6001. dealer, _ := service.GetDealerById(info.Dealer)
  6002. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6003. cancelStockInfo := models.DrugCancelStockInfo{
  6004. OrderNumber: cancelInfo.OrderNumber,
  6005. CancelStockId: cancelInfo.ID,
  6006. DrugId: info.DrugId,
  6007. Count: info.Count,
  6008. Status: 1,
  6009. Ctime: ctime,
  6010. OrgId: advice.UserOrgId,
  6011. Type: 1,
  6012. Manufacturer: manufactureName.ManufacturerName,
  6013. Dealer: dealer.DealerName,
  6014. Total: 0,
  6015. RetailPrice: info.RetailPrice,
  6016. RetailTotalPrice: info.RetailTotalPrice,
  6017. Price: info.Price,
  6018. RegisterAccount: "",
  6019. Remark: info.Remark,
  6020. BatchNumber: info.BatchNumber,
  6021. MaxUnit: info.CountUnit,
  6022. ProductDate: info.ProductDate,
  6023. ExpiryDate: info.ExpiryDate,
  6024. BatchNumberId: info.WarehouseInfoId,
  6025. }
  6026. flow := models.DrugFlow{
  6027. WarehousingId: 0,
  6028. DrugId: info.DrugId,
  6029. Number: "",
  6030. BatchNumber: info.BatchNumber,
  6031. Count: info.Count,
  6032. UserOrgId: advice.UserOrgId,
  6033. PatientId: 0,
  6034. SystemTime: ctime,
  6035. ConsumableType: 4,
  6036. IsSys: 0,
  6037. WarehousingOrder: "",
  6038. WarehouseOutId: 0,
  6039. WarehouseOutOrderNumber: "",
  6040. IsEdit: 0,
  6041. CancelStockId: cancelStock.ID,
  6042. CancelOrderNumber: cancelStock.OrderNumber,
  6043. Manufacturer: info.Manufacturer,
  6044. Dealer: info.Dealer,
  6045. Creator: advice.AdviceDoctor,
  6046. UpdateCreator: 0,
  6047. Status: 1,
  6048. Ctime: time.Now().Unix(),
  6049. Mtime: 0,
  6050. Price: info.Price,
  6051. WarehousingDetailId: 0,
  6052. WarehouseOutDetailId: 0,
  6053. CancelOutDetailId: 0,
  6054. ExpireDate: info.ExpiryDate,
  6055. ProductDate: info.ProductDate,
  6056. MaxUnit: info.CountUnit,
  6057. MinUnit: "",
  6058. }
  6059. service.CreatedCancelStock(cancelStockInfo)
  6060. service.CreateDrugFlowOne(flow)
  6061. }
  6062. }
  6063. }
  6064. return err
  6065. }
  6066. func (this *HisApiController) DeleteNCDS() {
  6067. id, _ := this.GetInt64("id", 0)
  6068. if id > 0 {
  6069. service.DeletePsnNCDSRecordById(id)
  6070. this.ServeSuccessJSON(map[string]interface{}{
  6071. "msg": "删除成功",
  6072. })
  6073. } else {
  6074. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  6075. return
  6076. }
  6077. }
  6078. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  6079. id, _ := c.GetInt64("id")
  6080. advice, _ := service.GetHisDoctorAdviceInfo(id)
  6081. c.ServeSuccessJSON(map[string]interface{}{
  6082. "advice": advice,
  6083. })
  6084. return
  6085. }