his_api_controller.go 244KB

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