his_api_controller.go 607KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  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/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  91. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  92. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  93. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  94. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  95. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  96. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  97. }
  98. func (c *HisApiController) CheckHisPatient() {
  99. record_date := c.GetString("record_date")
  100. patient_id, _ := c.GetInt64("patient_id")
  101. timeLayout := "2006-01-02"
  102. loc, _ := time.LoadLocation("Local")
  103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  104. if err != nil {
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. recordDateTime := theTime.Unix()
  109. adminInfo := c.GetAdminUserInfo()
  110. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  111. if len(patients) > 1 {
  112. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  113. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "status": 1,
  116. "msg": "关联",
  117. "ps": ps,
  118. "his_patient_id": patients[len(patients)-1].ID,
  119. "patient_id": patients[len(patients)-1].PatientId,
  120. })
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. }
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. return
  133. }
  134. }
  135. func (c *HisApiController) AssociationHisPrescription() {
  136. record_date := c.GetString("record_date")
  137. his_patient_id, _ := c.GetInt64("his_patient_id")
  138. patient_id, _ := c.GetInt64("patient_id")
  139. p_ids := c.GetString("p_ids")
  140. p_ids_arr := strings.Split(p_ids, ",")
  141. timeLayout := "2006-01-02"
  142. loc, _ := time.LoadLocation("Local")
  143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  144. if err != nil {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. recordDateTime := theTime.Unix()
  149. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  150. if his_patient_id == 0 || his_patient.ID == 0 {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  155. if err == nil {
  156. c.ServeSuccessJSON(map[string]interface{}{
  157. "msg": "关联处方成功",
  158. })
  159. return
  160. } else {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  162. return
  163. }
  164. }
  165. //func (c *HisApiController) AssociationHisPrescription() {
  166. // record_date, _ := c.GetInt64("record_date")
  167. // his_patient_id, _ := c.GetInt64("his_patient_id")
  168. // patient_id, _ := c.GetInt64("patient_id")
  169. // p_ids := c.GetString("p_ids")
  170. // p_ids_arr := strings.Split(p_ids, ",")
  171. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  172. // if his_patient_id == 0 || his_patient.ID == 0 {
  173. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. // return
  175. // }
  176. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  177. // if err == nil {
  178. // c.ServeSuccessJSON(map[string]interface{}{
  179. // "msg": "关联处方成功",
  180. // })
  181. // return
  182. // } else {
  183. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  184. // return
  185. // }
  186. //}
  187. func (c *HisApiController) GetFaPiaoNumber() {
  188. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  189. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  190. fmt.Println(count)
  191. var zero string
  192. number := count + 1
  193. //if number >= 1000 {
  194. // zero = "0000" + strconv.FormatInt(number, 10)
  195. //} else if number >= 10000 {
  196. // zero = "000" + strconv.FormatInt(number, 10)
  197. //} else if number >= 100000 {
  198. // zero = "00" + strconv.FormatInt(number, 10)
  199. //} else if number >= 1000000 {
  200. // zero = "0" + strconv.FormatInt(number, 10)
  201. //} else {
  202. zero = "0" + strconv.FormatInt(number, 10)
  203. //}
  204. c.ServeSuccessJSON(map[string]interface{}{
  205. "fapiao_number": zero,
  206. })
  207. return
  208. }
  209. func (c *HisApiController) ChangeOrderDesc() {
  210. id, _ := c.GetInt64("id")
  211. desc := c.GetString("desc")
  212. change_type := c.GetString("change_type")
  213. order, _ := service.GetHisOrderByID(id)
  214. if order.ID == 0 {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  216. return
  217. }
  218. switch change_type {
  219. case "oth_desc":
  220. order.OthDesc = desc
  221. break
  222. case "cash_pay":
  223. order.CashPay = desc
  224. break
  225. case "jifen_pay":
  226. order.JifenPay = desc
  227. break
  228. case "card_desc":
  229. order.CardDesc = desc
  230. break
  231. case "band_card_pay":
  232. order.BandCardPay = desc
  233. break
  234. case "ali_pay":
  235. order.AliPay = desc
  236. break
  237. case "wechat_pay":
  238. order.WechatPay = desc
  239. break
  240. case "fa_piao_number":
  241. order.FaPiaoNumber = desc
  242. break
  243. case "fa_piao_code":
  244. order.FaPiaoCode = desc
  245. break
  246. }
  247. err := service.SaveHisOrder(&order)
  248. if err == nil {
  249. c.ServeSuccessJSON(map[string]interface{}{
  250. "msg": "修改成功",
  251. })
  252. return
  253. } else {
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  255. return
  256. }
  257. }
  258. func (c *HisApiController) GetMonthHisPatient() {
  259. record_date := c.GetString("record_date")
  260. //order_status, _ := c.GetInt64("type")
  261. timeLayout := "2006-01-02"
  262. loc, _ := time.LoadLocation("Local")
  263. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  264. if err != nil {
  265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  266. return
  267. }
  268. recordDateTime := theTime.Unix()
  269. adminInfo := c.GetAdminUserInfo()
  270. var tempPatients []service.NewTempPatients
  271. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  272. // 获取当前时间
  273. now := time.Now()
  274. // 获取本月的第一天
  275. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  276. // 获取下个月的第一天
  277. nextMonth := firstDay.AddDate(0, 1, 0)
  278. // 获取本月的最后一天
  279. lastDay := nextMonth.Add(-time.Nanosecond)
  280. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  281. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  282. var patients []service.NewTempPatients
  283. var patients_two []service.NewTempPatients
  284. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  285. for _, item := range tempPatients {
  286. //过滤掉没挂号的和没开处方的
  287. if len(item.HisPrescription) > 0 {
  288. patients = append(patients, item)
  289. patients_two = append(patients_two, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. //}
  294. }
  295. } else {
  296. for _, item := range tempPatients {
  297. //过滤掉没挂号的和没开处方的
  298. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  299. patients = append(patients, item)
  300. }
  301. ////过滤掉没挂号的
  302. //if len(item.HisPatient) > 0 {
  303. // patients_two = append(patients_two, item)
  304. //}
  305. }
  306. }
  307. c.ServeSuccessJSON(map[string]interface{}{
  308. "list": patients,
  309. "list_two": patients_two,
  310. "chargePatients": chargePatients,
  311. })
  312. }
  313. func (c *HisApiController) GetBatchSettleAccounts() {
  314. order_ids := c.GetString("order_ids")
  315. admin_user_id, _ := c.GetInt64("admin_user_id")
  316. adminUser := c.GetAdminUserInfo()
  317. orders := strings.Split(order_ids, ",")
  318. var newOrders []models.Orders
  319. for _, item := range orders {
  320. order, _ := service.GetHisOrderByIDTenOne(item)
  321. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  322. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  323. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  324. orderInfos = append(orderInfos, orderInfos_two...)
  325. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  326. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  327. var diagnosis_ids []string
  328. if his.ID > 0 {
  329. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  330. } else {
  331. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  332. }
  333. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  334. var dia_config []*models.HisXtDiagnoseConfig
  335. var name string
  336. for _, item := range diagnosis_ids {
  337. id, _ := strconv.ParseInt(item, 10, 64)
  338. diagnosisConfig, _ := service.FindDiagnoseById(id)
  339. dia_config = append(dia_config, diagnosisConfig)
  340. if len(name) == 0 {
  341. name = diagnosisConfig.ClassName
  342. } else {
  343. name = name + "," + diagnosisConfig.ClassName
  344. }
  345. }
  346. var bedCostTotal float64 = 0 //床位总费
  347. var bedCostSelfTotal float64 = 0 //床位自费
  348. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  349. var bedSelfTotal float64 = 0 //床位部分项目自费
  350. var bedInscpTotal float64 = 0 //床位部分项目自费
  351. var operationCostTotal float64 = 0 //手术费
  352. var operationCostSelfTotal float64 = 0 //手术费
  353. var operationCostPartSelfTotal float64 = 0 //手术费
  354. var operationSelfTotal float64 = 0 //床位部分项目自费
  355. var operationInscpTotal float64 = 0 //床位部分项目自费
  356. var otherCostTotal float64 = 0 //其他费用
  357. var otherCostSelfTotal float64 = 0 //其他费用
  358. var otherCostPartSelfTotal float64 = 0 //其他费用
  359. var otherSelfTotal float64 = 0 //床位部分项目自费
  360. var otherInscpTotal float64 = 0 //床位部分项目自费
  361. var materialCostTotal float64 = 0 //材料费
  362. var materialCostSelfTotal float64 = 0 //材料费
  363. var materialCostPartSelfTotal float64 = 0 //材料费
  364. var materialSelfTotal float64 = 0 //床位部分项目自费
  365. var materialInscpTotal float64 = 0 //床位部分项目自费
  366. var westernMedicineCostTotal float64 = 0 //西药费
  367. var westernMedicineCostSelfTotal float64 = 0 //西药费
  368. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  369. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  370. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  371. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  372. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  373. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  374. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  375. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  376. var checkCostTotal float64 = 0 //检查费
  377. var checkCostSelfTotal float64 = 0 //检查费
  378. var checkCostPartSelfTotal float64 = 0 //检查费
  379. var checkSelfTotal float64 = 0 //床位部分项目自费
  380. var checkInscpTotal float64 = 0 //床位部分项目自费
  381. var laboratoryCostTotal float64 = 0 //化验费
  382. var laboratoryCostSelfTotal float64 = 0 //化验费
  383. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  384. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  385. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  386. var treatCostTotal float64 = 0 //治疗费用
  387. var treatCostSelfTotal float64 = 0 //治疗费用
  388. var treatCostPartSelfTotal float64 = 0 //治疗费用
  389. var treatSelfTotal float64 = 0 //床位部分项目自费
  390. var treatInscpTotal float64 = 0 //床位部分项目自费
  391. decimal.DivisionPrecision = 2
  392. for _, item := range orderInfos {
  393. if item.MedChrgitmType == "01" { //床位费
  394. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  395. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  396. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  397. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  398. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  399. }
  400. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  401. if item.MedChrgitmType == "03" { //检查费
  402. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  403. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  404. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  405. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  406. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  407. }
  408. } else {
  409. if item.MedChrgitmType == "03" { //检查费
  410. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  411. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  412. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  413. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  414. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  415. }
  416. }
  417. if item.MedChrgitmType == "04" { //化验费
  418. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  419. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  420. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  421. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  422. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  423. }
  424. if item.MedChrgitmType == "05" { //治疗费
  425. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  426. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  427. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  428. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  429. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  430. }
  431. if item.MedChrgitmType == "06" { //手术费
  432. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  433. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  434. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  435. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  436. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  437. }
  438. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  439. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  440. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  441. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  442. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  443. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  444. }
  445. if item.MedChrgitmType == "09" { //西药费
  446. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  447. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  448. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  449. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  450. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  451. }
  452. if item.MedChrgitmType == "11" { //中成费
  453. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  454. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  455. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  456. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  457. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  458. }
  459. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  460. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  461. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  462. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  463. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  464. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  465. }
  466. }
  467. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  468. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  469. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  470. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  471. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  472. var doctor_name string
  473. if roles.ID == 0 {
  474. doctor_name = "管理员"
  475. } else {
  476. doctor_name = roles.UserName
  477. }
  478. yiliao_leibie := ""
  479. switch order.MedType {
  480. case "11":
  481. yiliao_leibie = "普通门诊"
  482. break
  483. case "12":
  484. yiliao_leibie = "门诊挂号"
  485. break
  486. case "13":
  487. yiliao_leibie = "急诊"
  488. break
  489. case "14":
  490. yiliao_leibie = "门诊特殊病"
  491. break
  492. case "15":
  493. yiliao_leibie = "门诊统筹"
  494. break
  495. case "16":
  496. yiliao_leibie = "门诊慢性病"
  497. break
  498. case "21":
  499. yiliao_leibie = "普通住院"
  500. break
  501. }
  502. var newOrder models.Orders
  503. newOrder.Diagnosis = name
  504. newOrder.OrderInfos = orderInfos
  505. newOrder.Number = order.MdtrtId
  506. newOrder.Date = order.SettleAccountsDate
  507. newOrder.ChargeAdmin = charge_admin
  508. newOrder.PrintorAdmin = printor_admin
  509. newOrder.Order = order
  510. newOrder.BedCostTotal = bedCostTotal
  511. newOrder.BedCostSelfTotal = bedCostSelfTotal
  512. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  513. newOrder.BedSelfTotal = bedSelfTotal
  514. newOrder.BedInscpTotal = bedInscpTotal
  515. newOrder.OperationCostTotal = operationCostTotal
  516. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  517. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  518. newOrder.OperationSelfTotal = operationSelfTotal
  519. newOrder.OperationInscpTotal = operationInscpTotal
  520. newOrder.OtherCostTotal = otherCostTotal
  521. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  522. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  523. newOrder.OtherSelfTotal = otherSelfTotal
  524. newOrder.OtherInscpTotal = otherInscpTotal
  525. newOrder.MaterialCostTotal = materialCostTotal
  526. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  527. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  528. newOrder.MaterialSelfTotal = materialSelfTotal
  529. newOrder.MaterialInscpTotal = materialInscpTotal
  530. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  531. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  532. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  533. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  534. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  535. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  536. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  537. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  538. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  539. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  540. newOrder.CheckCostTotal = checkCostTotal
  541. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  542. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  543. newOrder.CheckSelfTotal = checkSelfTotal
  544. newOrder.CheckInscpTotal = checkInscpTotal
  545. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  546. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  547. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  548. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  549. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  550. newOrder.TreatCostTotal = treatCostTotal
  551. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  552. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  553. newOrder.TreatSelfTotal = treatSelfTotal
  554. newOrder.TreatInscpTotal = treatInscpTotal
  555. newOrder.DoctorInfo = doctor_info
  556. newOrder.DoctorName = doctor_name
  557. newOrder.HealthCardNo = order.PsnNo
  558. newOrder.YiliaoLeibie = yiliao_leibie
  559. newOrder.Patient = patient
  560. newOrder.OrgName = miConfig.OrgName
  561. newOrder.OrgCode = miConfig.Code
  562. newOrder.OrderNumber = order.Number
  563. newOrder.HisPatient = his
  564. newOrder.DiaConfig = dia_config
  565. newOrders = append(newOrders, newOrder)
  566. }
  567. c.ServeSuccessJSON(map[string]interface{}{
  568. "orders": newOrders,
  569. })
  570. }
  571. func (c *HisApiController) GetTestOrder() {
  572. order_id, _ := c.GetInt64("order_id")
  573. admin_user_id, _ := c.GetInt64("admin_user_id")
  574. adminUser := c.GetAdminUserInfo()
  575. order, _ := service.GetHisOrderByID(order_id)
  576. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  577. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  578. orderInfos = append(orderInfos, orderInfos_two...)
  579. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  580. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  581. var dia_config []*models.HisXtDiagnoseConfig
  582. var name string
  583. var bedCostTotal float64 = 0 //床位总费
  584. var bedCostSelfTotal float64 = 0 //床位自费
  585. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  586. var bedSelfTotal float64 = 0 //床位部分项目自费
  587. var bedInscpTotal float64 = 0 //床位部分项目自费
  588. var operationCostTotal float64 = 0 //手术费
  589. var operationCostSelfTotal float64 = 0 //手术费
  590. var operationCostPartSelfTotal float64 = 0 //手术费
  591. var operationSelfTotal float64 = 0 //床位部分项目自费
  592. var operationInscpTotal float64 = 0 //床位部分项目自费
  593. var otherCostTotal float64 = 0 //其他费用
  594. var otherCostSelfTotal float64 = 0 //其他费用
  595. var otherCostPartSelfTotal float64 = 0 //其他费用
  596. var otherSelfTotal float64 = 0 //床位部分项目自费
  597. var otherInscpTotal float64 = 0 //床位部分项目自费
  598. var materialCostTotal float64 = 0 //材料费
  599. var materialCostSelfTotal float64 = 0 //材料费
  600. var materialCostPartSelfTotal float64 = 0 //材料费
  601. var materialSelfTotal float64 = 0 //床位部分项目自费
  602. var materialInscpTotal float64 = 0 //床位部分项目自费
  603. var westernMedicineCostTotal float64 = 0 //西药费
  604. var westernMedicineCostSelfTotal float64 = 0 //西药费
  605. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  606. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  607. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  608. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  609. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  610. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  611. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  612. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  613. var checkCostTotal float64 = 0 //检查费
  614. var checkCostSelfTotal float64 = 0 //检查费
  615. var checkCostPartSelfTotal float64 = 0 //检查费
  616. var checkSelfTotal float64 = 0 //床位部分项目自费
  617. var checkInscpTotal float64 = 0 //床位部分项目自费
  618. var laboratoryCostTotal float64 = 0 //化验费
  619. var laboratoryCostSelfTotal float64 = 0 //化验费
  620. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  621. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  622. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  623. var treatCostTotal float64 = 0 //治疗费用
  624. var treatCostSelfTotal float64 = 0 //治疗费用
  625. var treatCostPartSelfTotal float64 = 0 //治疗费用
  626. var treatSelfTotal float64 = 0 //床位部分项目自费
  627. var treatInscpTotal float64 = 0 //床位部分项目自费
  628. decimal.DivisionPrecision = 2
  629. for _, item := range orderInfos {
  630. if item.MedChrgitmType == "01" { //床位费
  631. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  632. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  633. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  634. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  635. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  636. }
  637. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  638. if item.MedChrgitmType == "03" { //检查费
  639. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  640. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  641. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  642. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  643. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  644. }
  645. } else {
  646. if item.MedChrgitmType == "03" { //检查费
  647. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  648. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  649. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  650. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  651. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  652. }
  653. }
  654. if item.MedChrgitmType == "04" { //化验费
  655. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  656. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  657. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  658. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  659. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  660. }
  661. if item.MedChrgitmType == "05" { //治疗费
  662. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  663. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  664. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  665. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  666. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  667. }
  668. if item.MedChrgitmType == "06" { //手术费
  669. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  670. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  671. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  672. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  673. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  674. }
  675. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  676. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  677. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  678. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  679. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  680. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  681. }
  682. if item.MedChrgitmType == "09" { //西药费
  683. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  684. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  685. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  686. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  687. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  688. }
  689. if item.MedChrgitmType == "11" { //中成费
  690. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  691. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  692. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  693. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  694. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  695. }
  696. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  697. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  698. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  699. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  700. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  701. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  702. }
  703. }
  704. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  705. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  706. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  707. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  708. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  709. var doctor_name string
  710. if roles.ID == 0 {
  711. doctor_name = "管理员"
  712. } else {
  713. doctor_name = roles.UserName
  714. }
  715. yiliao_leibie := ""
  716. switch order.MedType {
  717. case "11":
  718. yiliao_leibie = "普通门诊"
  719. break
  720. case "12":
  721. yiliao_leibie = "门诊挂号"
  722. break
  723. case "13":
  724. yiliao_leibie = "急诊"
  725. break
  726. case "14":
  727. yiliao_leibie = "门诊特殊病"
  728. break
  729. case "15":
  730. yiliao_leibie = "门诊统筹"
  731. break
  732. case "16":
  733. yiliao_leibie = "门诊慢性病"
  734. break
  735. case "21":
  736. yiliao_leibie = "普通住院"
  737. break
  738. }
  739. c.ServeSuccessJSON(map[string]interface{}{
  740. "diagnosis": name,
  741. "order_infos": orderInfos,
  742. "number": order.MdtrtId,
  743. "date": order.SettleAccountsDate,
  744. "charge_admin": charge_admin,
  745. "printor_admin": printor_admin,
  746. "info": order,
  747. "order": order,
  748. "bedCostTotal": bedCostTotal,
  749. "bedCostSelfTotal": bedCostSelfTotal,
  750. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  751. "bedSelfTotal": bedSelfTotal,
  752. "bedInscpTotal": bedInscpTotal,
  753. "operationCostTotal": operationCostTotal,
  754. "operationCostSelfTotal": operationCostSelfTotal,
  755. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  756. "operationSelfTotal": operationSelfTotal,
  757. "operationInscpTotal": operationInscpTotal,
  758. "otherCostTotal": otherCostTotal,
  759. "otherCostSelfTotal": otherCostSelfTotal,
  760. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  761. "otherSelfTotal": otherSelfTotal,
  762. "otherInscpTotal": otherInscpTotal,
  763. "materialCostTotal": materialCostTotal,
  764. "materialCostSelfTotal": materialCostSelfTotal,
  765. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  766. "materialSelfTotal": materialSelfTotal,
  767. "materialInscpTotal": materialInscpTotal,
  768. "westernMedicineCostTotal": westernMedicineCostTotal,
  769. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  770. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  771. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  772. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  773. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  774. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  775. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  776. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  777. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  778. "checkCostTotal": checkCostTotal,
  779. "checkCostSelfTotal": checkCostSelfTotal,
  780. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  781. "checkSelfTotal": checkSelfTotal,
  782. "checkInscpTotal": checkInscpTotal,
  783. "laboratoryCostTotal": laboratoryCostTotal,
  784. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  785. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  786. "laboratorySelfTotal": laboratorySelfTotal,
  787. "laboratoryInscpTotal": laboratoryInscpTotal,
  788. "treatCostTotal": treatCostTotal,
  789. "treatCostSelfTotal": treatCostSelfTotal,
  790. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  791. "treatSelfTotal": treatSelfTotal,
  792. "treatInscpTotal": treatInscpTotal,
  793. "doctor_info": doctor_info,
  794. "doctor_name": doctor_name,
  795. "health_card_no": order.PsnNo,
  796. "yiliao_leibie": yiliao_leibie,
  797. "patient": patient,
  798. "org_name": miConfig.OrgName,
  799. "org_code": miConfig.Code,
  800. "order_number": order.Number,
  801. "his_hospital": his_hospital,
  802. "dia_config": dia_config,
  803. })
  804. }
  805. type CustomFundPay struct {
  806. FundPayType string `json:"fund_pay_type"`
  807. FundPayamt float64 `json:"fund_payamt"`
  808. InscpScpAmt float64 `json:"inscp_scp_amt"`
  809. }
  810. func (c *PublicApiController) GetBaiLinExportData() {
  811. data := service.GetBaiLinOrderData()
  812. fmt.Println(len(data))
  813. var new_data []*models.NewCustomHisOrder
  814. for _, item := range data {
  815. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  816. new_data = append(new_data, item)
  817. }
  818. }
  819. fmt.Println(len(new_data))
  820. c.ServeSuccessJSON(map[string]interface{}{
  821. "list": new_data,
  822. })
  823. }
  824. func (c *HisApiController) GetHisUnChargePatientList() {
  825. record_date := c.GetString("record_date")
  826. sch_type, _ := c.GetInt64("sch_type")
  827. timeLayout := "2006-01-02"
  828. loc, _ := time.LoadLocation("Local")
  829. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  830. if err != nil {
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  832. return
  833. }
  834. recordDateTime := theTime.Unix()
  835. adminInfo := c.GetAdminUserInfo()
  836. var tempPatients []*service.NewTempPatients
  837. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  838. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  839. var patients []*service.NewTempPatients
  840. var patients_two []*service.NewTempPatients
  841. for _, item := range tempPatients {
  842. //过滤掉没挂号的和没开处方的
  843. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  844. patients = append(patients, item)
  845. }
  846. //过滤掉没挂号的
  847. if len(item.HisPatient) > 0 {
  848. patients_two = append(patients_two, item)
  849. }
  850. }
  851. c.ServeSuccessJSON(map[string]interface{}{
  852. "list": patients,
  853. "list_two": patients_two,
  854. })
  855. }
  856. func (c *HisApiController) GetPrivateExpensesOrder() {
  857. //id, _ := c.GetInt64("id")
  858. //record_time := c.GetString("record_time")
  859. order_id, _ := c.GetInt64("order_id")
  860. admin_user_id, _ := c.GetInt64("admin_user_id")
  861. //timeLayout := "2006-01-02"
  862. //loc, _ := time.LoadLocation("Local")
  863. //
  864. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  865. //if err != nil {
  866. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  867. // return
  868. //}
  869. //recordDateTime := theTime.Unix()
  870. adminUser := c.GetAdminUserInfo()
  871. order, _ := service.GetHisOrderByID(order_id)
  872. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  873. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  874. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  875. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  876. //var config []*models.HisXtDiagnoseConfig
  877. var name string
  878. if order.PType == 1 {
  879. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  880. for _, item := range diagnosis_ids {
  881. id, _ := strconv.ParseInt(item, 10, 64)
  882. diagnosisConfig, _ := service.FindDiagnoseById(id)
  883. if len(name) == 0 {
  884. name = diagnosisConfig.ClassName
  885. } else {
  886. name = name + "," + diagnosisConfig.ClassName
  887. }
  888. }
  889. } else {
  890. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  891. for _, item := range diagnosis_ids {
  892. id, _ := strconv.ParseInt(item, 10, 64)
  893. diagnosisConfig, _ := service.FindDiagnoseById(id)
  894. if len(name) == 0 {
  895. name = diagnosisConfig.ClassName
  896. } else {
  897. name = name + "," + diagnosisConfig.ClassName
  898. }
  899. }
  900. }
  901. var bedCostTotal float64 = 0 //床位总费
  902. var bedCostSelfTotal float64 = 0 //床位自费
  903. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  904. var bedSelfTotal float64 = 0 //床位部分项目自费
  905. var bedInscpTotal float64 = 0 //床位部分项目自费
  906. var operationCostTotal float64 = 0 //手术费
  907. var operationCostSelfTotal float64 = 0 //手术费
  908. var operationCostPartSelfTotal float64 = 0 //手术费
  909. var operationSelfTotal float64 = 0 //床位部分项目自费
  910. var operationInscpTotal float64 = 0 //床位部分项目自费
  911. var otherCostTotal float64 = 0 //其他费用
  912. //var otherCostSelfTotal float64 = 0 //其他费用
  913. var otherCostPartSelfTotal float64 = 0 //其他费用
  914. //var otherSelfTotal float64 = 0 //床位部分项目自费
  915. //var otherInscpTotal float64 = 0 //床位部分项目自费
  916. var materialCostTotal float64 = 0 //材料费
  917. var materialCostSelfTotal float64 = 0 //材料费
  918. var materialCostPartSelfTotal float64 = 0 //材料费
  919. var materialSelfTotal float64 = 0 //床位部分项目自费
  920. var materialInscpTotal float64 = 0 //床位部分项目自费
  921. var westernMedicineCostTotal float64 = 0 //西药费
  922. var westernMedicineCostSelfTotal float64 = 0 //西药费
  923. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  924. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  925. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  926. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  927. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  928. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  929. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  930. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  931. var checkCostTotal float64 = 0 //检查费
  932. var checkCostSelfTotal float64 = 0 //检查费
  933. var checkCostPartSelfTotal float64 = 0 //检查费
  934. var checkSelfTotal float64 = 0 //床位部分项目自费
  935. var checkInscpTotal float64 = 0 //床位部分项目自费
  936. var laboratoryCostTotal float64 = 0 //化验费
  937. var laboratoryCostSelfTotal float64 = 0 //化验费
  938. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  939. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  940. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  941. var treatCostTotal float64 = 0 //治疗费用
  942. var treatCostSelfTotal float64 = 0 //治疗费用
  943. var treatCostPartSelfTotal float64 = 0 //治疗费用
  944. var treatSelfTotal float64 = 0 //床位部分项目自费
  945. var treatInscpTotal float64 = 0 //床位部分项目自费
  946. var zhenChaCostTotal float64 = 0 //其他费用
  947. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  948. decimal.DivisionPrecision = 2
  949. for _, item := range orderInfos {
  950. //item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  951. if c.GetAdminUserInfo().CurrentOrgId != 10726 {
  952. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  953. item.MedChrgitmType = "09"
  954. }
  955. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  956. if item.HisPrescriptionProject.Type == 2 {
  957. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  958. fmt.Println("CostClassify")
  959. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  960. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  961. case 0:
  962. item.MedChrgitmType = "0"
  963. break
  964. case 1:
  965. item.MedChrgitmType = "14"
  966. break
  967. case 2:
  968. item.MedChrgitmType = "05"
  969. break
  970. case 3:
  971. item.MedChrgitmType = "03"
  972. break
  973. case 4:
  974. item.MedChrgitmType = "03"
  975. break
  976. case 5:
  977. item.MedChrgitmType = "08"
  978. break
  979. case 6:
  980. item.MedChrgitmType = "14"
  981. break
  982. case 7:
  983. item.MedChrgitmType = "14"
  984. break
  985. case 8:
  986. item.MedChrgitmType = "03"
  987. break
  988. case 9:
  989. item.MedChrgitmType = "14"
  990. break
  991. case 10:
  992. item.MedChrgitmType = "14"
  993. break
  994. case 11:
  995. item.MedChrgitmType = "06"
  996. break
  997. case 12:
  998. item.MedChrgitmType = "12"
  999. break
  1000. case 13:
  1001. item.MedChrgitmType = "01"
  1002. break
  1003. case 14:
  1004. item.MedChrgitmType = "04"
  1005. break
  1006. case 15:
  1007. item.MedChrgitmType = "14"
  1008. break
  1009. case 101:
  1010. item.MedChrgitmType = "04"
  1011. break
  1012. }
  1013. } else {
  1014. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  1015. case 1:
  1016. item.MedChrgitmType = "14"
  1017. break
  1018. case 2:
  1019. item.MedChrgitmType = "05"
  1020. break
  1021. case 3:
  1022. item.MedChrgitmType = "04"
  1023. break
  1024. case 4:
  1025. item.MedChrgitmType = "14"
  1026. break
  1027. case 5:
  1028. item.MedChrgitmType = "08"
  1029. break
  1030. case 6:
  1031. item.MedChrgitmType = "14"
  1032. break
  1033. case 7:
  1034. item.MedChrgitmType = "14"
  1035. break
  1036. case 8:
  1037. item.MedChrgitmType = "03"
  1038. break
  1039. case 9:
  1040. item.MedChrgitmType = "14"
  1041. break
  1042. case 101:
  1043. item.MedChrgitmType = "04"
  1044. break
  1045. default:
  1046. item.MedChrgitmType = "14"
  1047. break
  1048. }
  1049. }
  1050. } else if item.HisPrescriptionProject.Type == 3 {
  1051. item.MedChrgitmType = "08"
  1052. }
  1053. }
  1054. }
  1055. }
  1056. if order.IsMedicineInsurance != 1 {
  1057. order.PsnCashPay = order.MedfeeSumamt
  1058. }
  1059. for _, item := range orderInfos {
  1060. if item.MedChrgitmType == "01" { //床位费
  1061. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1062. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1063. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1064. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1065. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1066. }
  1067. if item.MedChrgitmType == "02" { //诊察费
  1068. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1069. //zhenChaCostSelfTotal = zhenChaCostTotal
  1070. }
  1071. if item.MedChrgitmType == "03" { //检查费
  1072. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1073. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1074. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1075. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1076. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1077. }
  1078. if item.MedChrgitmType == "02" { //检查费
  1079. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1080. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1081. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1082. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1083. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1084. }
  1085. if item.MedChrgitmType == "04" { //化验费
  1086. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1087. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1088. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1089. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1090. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1091. }
  1092. if item.MedChrgitmType == "05" { //治疗费
  1093. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1094. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1095. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1096. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1097. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1098. }
  1099. if item.MedChrgitmType == "06" { //手术费
  1100. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1101. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1102. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1103. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1104. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1105. }
  1106. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1107. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1108. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1109. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1110. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1111. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1112. }
  1113. if item.MedChrgitmType == "09" { //西药费
  1114. fmt.Println("FulamtOwnpayAmt")
  1115. fmt.Println(item.FulamtOwnpayAmt)
  1116. fmt.Println("FulamtOwnpayAmt")
  1117. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1118. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1119. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1120. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1121. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1122. }
  1123. if item.MedChrgitmType == "11" { //中成费
  1124. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1125. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1126. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1127. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1128. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1129. }
  1130. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1131. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1132. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1133. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1134. }
  1135. }
  1136. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1137. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1138. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1139. var dia_config []*models.HisXtDiagnoseConfig
  1140. var diagnosis_ids []string
  1141. if his.ID > 0 {
  1142. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1143. } else {
  1144. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1145. }
  1146. for _, item := range diagnosis_ids {
  1147. id, _ := strconv.ParseInt(item, 10, 64)
  1148. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1149. dia_config = append(dia_config, diagnosisConfig)
  1150. }
  1151. var rf []CustomFundPay
  1152. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1153. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1154. c.ServeSuccessJSON(map[string]interface{}{
  1155. "patient": patient,
  1156. "order_infos": orderInfos,
  1157. "diagnosis": name,
  1158. "bedCostTotal": bedCostTotal,
  1159. "bedCostSelfTotal": bedCostSelfTotal,
  1160. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1161. "bedSelfTotal": bedSelfTotal,
  1162. "bedInscpTotal": bedInscpTotal,
  1163. "operationCostTotal": operationCostTotal,
  1164. "operationCostSelfTotal": operationCostSelfTotal,
  1165. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1166. "operationInscpTotal": operationInscpTotal,
  1167. "operationSelfTotal": operationSelfTotal,
  1168. "otherCostTotal": otherCostTotal,
  1169. //"otherCostSelfTotal": otherCostSelfTotal,
  1170. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1171. "materialCostTotal": materialCostTotal,
  1172. "materialCostSelfTotal": materialCostSelfTotal,
  1173. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1174. "materialSelfTotal": materialSelfTotal,
  1175. "materialInscpTotal": materialInscpTotal,
  1176. "westernMedicineCostTotal": westernMedicineCostTotal,
  1177. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  1178. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1179. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  1180. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  1181. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1182. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  1183. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1184. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  1185. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  1186. "checkCostTotal": checkCostTotal,
  1187. "checkCostSelfTotal": checkCostSelfTotal,
  1188. "checkSelfTotal": checkSelfTotal,
  1189. "checkInscpTotal": checkInscpTotal,
  1190. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1191. "zhenChaCostTotal": zhenChaCostTotal,
  1192. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1193. "laboratoryCostTotal": laboratoryCostTotal,
  1194. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  1195. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1196. "laboratorySelfTotal": laboratorySelfTotal,
  1197. "laboratoryInscpTotal": laboratoryInscpTotal,
  1198. "treatCostTotal": treatCostTotal,
  1199. "treatCostSelfTotal": treatCostSelfTotal,
  1200. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1201. "treatSelfTotal": treatSelfTotal,
  1202. "treatInscpTotal": treatInscpTotal,
  1203. "charge_admin": charge_admin,
  1204. "printor_admin": printor_admin,
  1205. "org_name": org.OrgName,
  1206. "org_code": miConfig.Code,
  1207. "name": patient.Name,
  1208. "number": order.MdtrtId,
  1209. "date": order.SettleAccountsDate,
  1210. "info": order,
  1211. "new_order": order,
  1212. "his_hospital": his_hospital,
  1213. "his": his,
  1214. "funds": rf,
  1215. "dia_config": dia_config,
  1216. })
  1217. }
  1218. func (c *HisApiController) RefudDetail() {
  1219. order_id, _ := c.GetInt64("order_id")
  1220. order, _ := service.GetHisOrderByID(order_id)
  1221. adminUser := c.GetAdminUserInfo()
  1222. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1223. c.ServeSuccessJSON(map[string]interface{}{
  1224. "msg": "撤销成功",
  1225. })
  1226. }
  1227. func (c *HisApiController) Sscard() {
  1228. //r := CardInit()
  1229. //if r == 0 {
  1230. // GetBaseInfo()
  1231. //}
  1232. //c.ServeSuccessJSON(map[string]interface{}{
  1233. // "list": "11",
  1234. //})
  1235. }
  1236. func GetBaseInfo() error {
  1237. //handle := syscall.MustLoadDLL("SSCard.dll")
  1238. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1239. //
  1240. //str := make([]byte, 256)
  1241. //str1 := make([]byte, 256)
  1242. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1243. //if ferr != nil {
  1244. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1245. // return ferr
  1246. //}
  1247. //
  1248. //fmt.Println(string(str))
  1249. //
  1250. //fmt.Println(r)
  1251. return nil
  1252. }
  1253. func CardInit() int {
  1254. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1255. //add := DllTestDef.MustFindProc("Init")
  1256. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1257. //if err != nil {
  1258. // fmt.Println("SSCard的运算结果为:", ret)
  1259. //}
  1260. //result := int(ret)
  1261. return 0
  1262. }
  1263. func IntPtr(n int) uintptr {
  1264. return uintptr(n)
  1265. }
  1266. func StrPtr(s string) uintptr {
  1267. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1268. }
  1269. func (c *HisApiController) GetHisPatientList() {
  1270. record_date := c.GetString("record_date")
  1271. sch_type, _ := c.GetInt64("sch_type")
  1272. patient_type, _ := c.GetInt64("patient_type")
  1273. fmt.Println("patient_type")
  1274. fmt.Println(patient_type)
  1275. timeLayout := "2006-01-02"
  1276. loc, _ := time.LoadLocation("Local")
  1277. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1278. if err != nil {
  1279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1280. return
  1281. }
  1282. recordDateTime := theTime.Unix()
  1283. adminInfo := c.GetAdminUserInfo()
  1284. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1285. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1286. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1287. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1288. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1289. fmt.Println(patients_three)
  1290. //获取当前用户的信息
  1291. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1292. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1293. //获取所有科室信息
  1294. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1295. //var aa []service.PatientThree
  1296. noElementsSlice := make([]service.PatientThree, 0)
  1297. c.ServeSuccessJSON(map[string]interface{}{
  1298. "list": patients_three,
  1299. "list_two": patients_four,
  1300. "list_three": noElementsSlice,
  1301. "info": adminUserInfo,
  1302. "doctors": doctors,
  1303. "department": department,
  1304. })
  1305. } else {
  1306. //获取当前用户的信息
  1307. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1308. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1309. //获取所有科室信息
  1310. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1311. //var aa []service.PatientThree
  1312. noElementsSlice := make([]service.PatientThree, 0)
  1313. c.ServeSuccessJSON(map[string]interface{}{
  1314. "list": patients,
  1315. "list_two": patients_two,
  1316. "list_three": noElementsSlice,
  1317. "info": adminUserInfo,
  1318. "doctors": doctors,
  1319. "department": department,
  1320. })
  1321. }
  1322. }
  1323. type CustomTemplate struct {
  1324. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1325. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1326. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1327. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1328. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1329. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1330. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1331. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1332. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1333. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1334. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1335. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1336. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1337. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1338. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1339. }
  1340. func (c *HisApiController) GetHisPatientInfo() {
  1341. patient_id, _ := c.GetInt64("patient_id")
  1342. his_patient_id, _ := c.GetInt64("his_patient_id")
  1343. record_date := c.GetString("record_date")
  1344. number := c.GetString("number")
  1345. //start_time := c.GetString("start_time")
  1346. //end_time := c.GetString("end_time")
  1347. p_type, _ := c.GetInt64("p_type")
  1348. timeLayout := "2006-01-02"
  1349. loc, _ := time.LoadLocation("Local")
  1350. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1351. if err != nil {
  1352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1353. return
  1354. }
  1355. recordDateTime := theTime.Unix()
  1356. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1357. //if err != nil {
  1358. //
  1359. //}
  1360. //startRecordDateTime := startTime.Unix()
  1361. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1362. //if err != nil {
  1363. //
  1364. //}
  1365. //endRecordDateTime := endTime.Unix()
  1366. admin := c.GetAdminUserInfo()
  1367. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1368. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1369. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1370. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1371. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1372. var prescriptions []*models.HisPrescription
  1373. var last_prescriptions []*models.HisPrescription
  1374. var sch_prescriptions []CustomTemplate
  1375. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1376. if p_type == 1 { //住院
  1377. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1378. for _, item := range prescriptions {
  1379. for _, subItem := range item.HisDoctorAdviceInfo {
  1380. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1381. if info.RetailPrice > 0 {
  1382. subItem.Drug.MinPrice = info.RetailPrice
  1383. }
  1384. }
  1385. }
  1386. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1387. } else { //门诊
  1388. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1389. for _, item := range prescriptions {
  1390. for _, subItem := range item.HisDoctorAdviceInfo {
  1391. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1392. if info.RetailPrice > 0 {
  1393. subItem.Drug.MinPrice = info.RetailPrice
  1394. }
  1395. }
  1396. }
  1397. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1398. }
  1399. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1400. if sch.ID > 0 {
  1401. var week string
  1402. t := time.Now()
  1403. switch t.Weekday().String() {
  1404. case "Monday":
  1405. week = "周一"
  1406. break
  1407. case "Tuesday":
  1408. week = "周二"
  1409. break
  1410. case "Wednesday":
  1411. week = "周三"
  1412. break
  1413. case "Thursday":
  1414. week = "周四"
  1415. break
  1416. case "Friday":
  1417. week = "周五"
  1418. break
  1419. case "Saturday":
  1420. week = "周六"
  1421. break
  1422. case "Sunday":
  1423. week = "周日"
  1424. break
  1425. }
  1426. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1427. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1428. //根据推送频率组装新的数组
  1429. for _, item := range temp_sch_prescriptions {
  1430. var cus CustomTemplate
  1431. cus.ID = item.ID
  1432. cus.UserOrgId = item.UserOrgId
  1433. cus.PatientId = item.PatientId
  1434. cus.MedType = item.MedType
  1435. cus.RecordDate = item.RecordDate
  1436. cus.Type = item.Type
  1437. cus.PType = item.PType
  1438. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1439. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1440. if subItem.FrequencyType == 1 { //每次必推
  1441. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1442. }
  1443. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1444. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1445. }
  1446. if subItem.FrequencyType == 2 { //按照天数频率
  1447. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1448. now := p.Unix()
  1449. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1450. dayStr2 := "-" + dayStr
  1451. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1452. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1453. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1454. if len(advices) == 0 {
  1455. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1456. }
  1457. }
  1458. }
  1459. }
  1460. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1461. if subItem.Type == 2 {
  1462. if subItem.XtHisProject.MedicalStatus != 1 {
  1463. if subItem.FrequencyType == 1 {
  1464. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1465. }
  1466. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1467. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1468. }
  1469. if subItem.FrequencyType == 2 {
  1470. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1471. now := p.Unix()
  1472. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1473. dayStr2 := "-" + dayStr
  1474. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1475. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1476. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1477. if len(projects) == 0 {
  1478. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1479. }
  1480. }
  1481. }
  1482. } else if subItem.Type == 3 {
  1483. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1484. if subItem.FrequencyType == 1 {
  1485. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1486. }
  1487. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1488. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1489. }
  1490. if subItem.FrequencyType == 2 {
  1491. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1492. now := p.Unix()
  1493. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1494. dayStr2 := "-" + dayStr
  1495. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1496. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1497. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1498. if len(projects) == 0 {
  1499. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1500. }
  1501. }
  1502. }
  1503. }
  1504. }
  1505. sch_prescriptions = append(sch_prescriptions, cus)
  1506. }
  1507. for _, item := range sch_prescriptions {
  1508. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1509. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1510. }
  1511. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1512. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1513. }
  1514. }
  1515. }
  1516. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1517. if config.ID > 0 && config.IsOpen == 1 {
  1518. for _, item := range sch_prescriptions {
  1519. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1520. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1521. if info.RetailPrice > 0 {
  1522. subItem.Drug.MinPrice = info.RetailPrice
  1523. if admin.CurrentOrgId != 10598 {
  1524. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1525. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1526. }
  1527. }
  1528. }
  1529. }
  1530. }
  1531. if config.ID > 0 && config.IsOpen == 1 {
  1532. for _, item := range sch_prescriptions {
  1533. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1534. if subItem.Type == 3 {
  1535. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1536. if info.Price > 0 {
  1537. subItem.GoodInfo.PackingPrice = info.Price
  1538. if admin.CurrentOrgId != 10598 {
  1539. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1540. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1541. }
  1542. }
  1543. }
  1544. }
  1545. }
  1546. }
  1547. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1548. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1549. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1550. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1551. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1552. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1553. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1554. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1555. //获取所有科室信息
  1556. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1557. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1558. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1559. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1560. fmt.Println(prescriptions)
  1561. fmt.Println(sch_prescriptions)
  1562. fmt.Println(last_prescriptions)
  1563. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1564. if len(sch_prescriptions) > 0 {
  1565. var index = 0
  1566. for subindex, item := range sch_prescriptions {
  1567. if item.Type == 2 {
  1568. index = subindex
  1569. }
  1570. }
  1571. fmt.Println(index)
  1572. fmt.Println(len(sch_prescriptions))
  1573. if index >= 0 && index < len(sch_prescriptions) {
  1574. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1575. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1576. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1577. if one.ID > 0 {
  1578. var hpt models.HisPrescriptionProjectTemplate
  1579. hpt.Type = 3
  1580. hpt.ID = 0
  1581. hpt.PatientId = sch_prescriptions[index].PatientId
  1582. hpt.Status = 1
  1583. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1584. hpt.Mtime = time.Now().Unix()
  1585. hpt.Ctime = time.Now().Unix()
  1586. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1587. hpt.Count = "1"
  1588. hpt.Price = one.RetailPrice
  1589. hpt.ProjectId = one.ID
  1590. hpt.FeedetlSn = ""
  1591. hpt.PrescriptionId = sch_prescriptions[index].ID
  1592. hpt.Unit = one.PackingUnit
  1593. hpt.Day = "1"
  1594. hpt.SingleDose = "1"
  1595. hpt.GoodInfo = one
  1596. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1597. }
  1598. if two.ID > 0 {
  1599. var hpt models.HisPrescriptionProjectTemplate
  1600. hpt.Type = 3
  1601. hpt.ID = 0
  1602. hpt.PatientId = sch_prescriptions[index].PatientId
  1603. hpt.Status = 1
  1604. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1605. hpt.Mtime = time.Now().Unix()
  1606. hpt.Ctime = time.Now().Unix()
  1607. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1608. hpt.Count = "1"
  1609. hpt.Price = two.RetailPrice
  1610. hpt.ProjectId = two.ID
  1611. hpt.FeedetlSn = ""
  1612. hpt.PrescriptionId = sch_prescriptions[index].ID
  1613. hpt.Unit = two.PackingUnit
  1614. hpt.Day = "1"
  1615. hpt.SingleDose = "1"
  1616. hpt.GoodInfo = two
  1617. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1618. }
  1619. //if three.ID > 0 {
  1620. // var hpt models.HisPrescriptionProjectTemplate
  1621. // hpt.Type = 3
  1622. // hpt.ID = 0
  1623. // hpt.PatientId = sch_prescriptions[index].PatientId
  1624. // hpt.Status = 1
  1625. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1626. // hpt.Mtime = time.Now().Unix()
  1627. // hpt.Ctime = time.Now().Unix()
  1628. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1629. // hpt.Count = "1"
  1630. // hpt.Price = three.RetailPrice
  1631. // hpt.ProjectId = three.ID
  1632. // hpt.FeedetlSn = ""
  1633. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1634. // hpt.Unit = three.PackingUnit
  1635. // hpt.Day = "1"
  1636. // hpt.SingleDose = "1"
  1637. // hpt.GoodInfo = three
  1638. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1639. //}
  1640. fmt.Println(sch_prescriptions)
  1641. }
  1642. } else {
  1643. if len(last_prescriptions) > 0 {
  1644. var index = 0
  1645. for subindex, item := range last_prescriptions {
  1646. if item.Type == 2 {
  1647. index = subindex
  1648. }
  1649. }
  1650. if index >= 0 && index < len(last_prescriptions) {
  1651. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1652. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1653. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1654. if one.ID > 0 {
  1655. var hpt models.HisPrescriptionProject
  1656. hpt.Type = 3
  1657. hpt.ID = 0
  1658. hpt.PatientId = last_prescriptions[index].PatientId
  1659. hpt.Status = 1
  1660. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1661. hpt.Mtime = time.Now().Unix()
  1662. hpt.Ctime = time.Now().Unix()
  1663. hpt.RecordDate = last_prescriptions[index].RecordDate
  1664. hpt.Count = "1"
  1665. hpt.Price = one.RetailPrice
  1666. hpt.ProjectId = one.ID
  1667. hpt.FeedetlSn = ""
  1668. hpt.PrescriptionId = last_prescriptions[index].ID
  1669. hpt.Unit = one.PackingUnit
  1670. hpt.Day = "1"
  1671. hpt.SingleDose = "1"
  1672. hpt.GoodInfo = one
  1673. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1674. }
  1675. if two.ID > 0 {
  1676. var hpt models.HisPrescriptionProject
  1677. hpt.Type = 3
  1678. hpt.ID = 0
  1679. hpt.PatientId = last_prescriptions[index].PatientId
  1680. hpt.Status = 1
  1681. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1682. hpt.Mtime = time.Now().Unix()
  1683. hpt.Ctime = time.Now().Unix()
  1684. hpt.RecordDate = last_prescriptions[index].RecordDate
  1685. hpt.Count = "1"
  1686. hpt.Price = two.RetailPrice
  1687. hpt.ProjectId = two.ID
  1688. hpt.FeedetlSn = ""
  1689. hpt.PrescriptionId = last_prescriptions[index].ID
  1690. hpt.Unit = two.PackingUnit
  1691. hpt.Day = "1"
  1692. hpt.SingleDose = "1"
  1693. hpt.GoodInfo = two
  1694. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1695. }
  1696. //if three.ID > 0 {
  1697. // var hpt models.HisPrescriptionProject
  1698. // hpt.Type = 3
  1699. // hpt.ID = 0
  1700. // hpt.PatientId = last_prescriptions[index].PatientId
  1701. // hpt.Status = 1
  1702. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1703. // hpt.Mtime = time.Now().Unix()
  1704. // hpt.Ctime = time.Now().Unix()
  1705. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1706. // hpt.Count = "1"
  1707. // hpt.Price = three.RetailPrice
  1708. // hpt.ProjectId = three.ID
  1709. // hpt.FeedetlSn = ""
  1710. // hpt.PrescriptionId = last_prescriptions[index].ID
  1711. // hpt.Unit = three.PackingUnit
  1712. // hpt.Day = "1"
  1713. // hpt.SingleDose = "1"
  1714. // hpt.GoodInfo = three
  1715. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1716. //}
  1717. }
  1718. }
  1719. }
  1720. }
  1721. c.ServeSuccessJSON(map[string]interface{}{
  1722. "his_info": his_patient_info,
  1723. "xt_info": xt_patient_info,
  1724. "prescription": prescriptions,
  1725. "case_history": case_history,
  1726. "info": patientPrescriptionInfo,
  1727. //"month_prescriptions": monthPrescriptions,
  1728. "order": order,
  1729. "doctors": doctors,
  1730. "department": department,
  1731. "sch_prescriptions": sch_prescriptions,
  1732. "last_prescriptions": last_prescriptions,
  1733. "schedule": sch,
  1734. "count": count,
  1735. "drugStockConfig": drugStockConfig,
  1736. "last_info": lastPatientPrescriptionInfo,
  1737. "befor": beforThrity,
  1738. "LastCaseHistory": LastCaseHistory,
  1739. "prescriptionInfo": prescriptionInfo,
  1740. })
  1741. return
  1742. }
  1743. func (c *HisApiController) GetHisPrescriptionConfig() {
  1744. adminInfo := c.GetAdminUserInfo()
  1745. //获取医嘱模版
  1746. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1747. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1748. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1749. //获取所有基础药
  1750. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1751. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1752. if config.ID > 0 && config.IsOpen == 1 {
  1753. for _, item := range drugs {
  1754. var index = 0
  1755. for _, subItem := range item.OtherDrugWarehouseInfo {
  1756. if index == 0 {
  1757. index = index + 1
  1758. if subItem.RetailPrice > 0 {
  1759. item.MinPrice = subItem.RetailPrice
  1760. }
  1761. }
  1762. }
  1763. }
  1764. }
  1765. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1766. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1767. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1768. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1769. //获取所有科室信息
  1770. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1771. //获取诊断信息
  1772. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1773. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1774. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1775. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1776. //获取是否开启保存耗材出库的开关
  1777. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1778. c.ServeSuccessJSON(map[string]interface{}{
  1779. "drugs": drugs,
  1780. "advices_template": advices,
  1781. "drugways": drugways,
  1782. "efs": efs,
  1783. "doctors": doctors,
  1784. "department": department,
  1785. "sick": sick,
  1786. "additions": additions,
  1787. "diagnose": diagnose,
  1788. "manufacturers": manufacturers,
  1789. "goodOutOpen": goodOutOpen,
  1790. "patientDiagnose": patientDiagnose,
  1791. })
  1792. }
  1793. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1794. //获取所有基础药
  1795. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1796. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1797. if config.ID > 0 && config.IsOpen == 1 {
  1798. for _, item := range drugs {
  1799. var index = 0
  1800. for _, subItem := range item.OtherDrugWarehouseInfo {
  1801. if index == 0 {
  1802. index = index + 1
  1803. if subItem.RetailPrice > 0 {
  1804. item.MinPrice = subItem.RetailPrice
  1805. }
  1806. }
  1807. }
  1808. }
  1809. }
  1810. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1811. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1812. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1813. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1814. //获取所有科室信息
  1815. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1816. //获取诊断信息
  1817. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1818. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1819. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1820. //获取是否开启保存耗材出库的开关
  1821. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1822. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1823. c.ServeSuccessJSON(map[string]interface{}{
  1824. "drugs": drugs,
  1825. "advices_template": advices,
  1826. "drugways": drugways,
  1827. "efs": efs,
  1828. "doctors": doctors,
  1829. "department": department,
  1830. "sick": sick,
  1831. "additions": additions,
  1832. "diagnose": diagnose,
  1833. "manufacturers": manufacturers,
  1834. "goodOutOpen": goodOutOpen,
  1835. "patientDiagnose": patientDiagnose,
  1836. })
  1837. }
  1838. }
  1839. func (c *HisApiController) CreateHisPrescription() {
  1840. record_date := c.GetString("record_date")
  1841. patient_id, _ := c.GetInt64("patient_id")
  1842. reg_type, _ := c.GetInt64("reg_type")
  1843. diagnose := c.GetString("diagnose")
  1844. sick_type, _ := c.GetInt64("sick_type")
  1845. sick_history := c.GetString("sick_history")
  1846. doctor_id, _ := c.GetInt64("doctor", 0)
  1847. department, _ := c.GetInt64("department", 0)
  1848. his_patient_id, _ := c.GetInt64("his_patient_id")
  1849. p_type, _ := c.GetInt64("p_type")
  1850. patient_diagnose := c.GetString("patient_diagnose")
  1851. dataBody := make(map[string]interface{}, 0)
  1852. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1853. if err != nil {
  1854. utils.ErrorLog(err.Error())
  1855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1856. return
  1857. }
  1858. //edit, src := GetCompareData(dataBody)
  1859. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1860. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1861. //fmt.Println(drugResult)
  1862. //fmt.Println(goodResult)
  1863. timeLayout := "2006-01-02"
  1864. loc, _ := time.LoadLocation("Local")
  1865. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1866. if err != nil {
  1867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1868. return
  1869. }
  1870. adminInfo := c.GetAdminUserInfo()
  1871. recordDateTime := theTime.Unix()
  1872. //查询默认出库仓库库存
  1873. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1874. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1875. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1876. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1877. if len(lists) == 1 {
  1878. his_patient_id = lists[0].ID
  1879. }
  1880. }
  1881. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1882. //自动出库的开关开启
  1883. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1884. //自动出库
  1885. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1886. //耗材保存处方出库
  1887. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1888. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1889. //已发药和已收费限制逻辑
  1890. isMidicine := false
  1891. isCharge := false
  1892. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1893. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1894. if len(prescriptions) > 0 {
  1895. for _, item := range prescriptions {
  1896. items := item.(map[string]interface{})
  1897. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1898. utils.ErrorLog("id")
  1899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1900. return
  1901. }
  1902. id := int64(items["id"].(float64))
  1903. if id > 0 {
  1904. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1905. if err != nil {
  1906. if new_prescription.OrderStatus == 4 {
  1907. isCharge = true
  1908. }
  1909. }
  1910. }
  1911. }
  1912. }
  1913. }
  1914. if isMidicine == true {
  1915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1916. return
  1917. }
  1918. if isCharge == true {
  1919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1920. return
  1921. }
  1922. // 开始主事务
  1923. db := service.XTWriteDB()
  1924. tx := db.Begin()
  1925. // 在函数结束时处理事务回滚
  1926. defer func() {
  1927. if r := recover(); r != nil {
  1928. tx.Rollback()
  1929. }
  1930. }()
  1931. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1932. //药品发药出库
  1933. if pharmacyConfig.IsOpen == 1 {
  1934. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1935. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1936. if len(prescriptions) > 0 {
  1937. for _, item := range prescriptions {
  1938. items := item.(map[string]interface{})
  1939. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1940. advices := items["advices"].([]interface{})
  1941. if len(advices) > 0 {
  1942. for _, advice := range advices {
  1943. var drug_id int64
  1944. var prescribing_number float64
  1945. var prescribingNumberUnit string
  1946. var adviceId int64
  1947. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1948. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1949. }
  1950. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1951. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1952. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1953. }
  1954. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1955. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1956. }
  1957. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1958. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1959. }
  1960. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1961. if drug.ID == 0 {
  1962. tx.Rollback()
  1963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1964. return
  1965. }
  1966. //查询药品的所有库存
  1967. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1968. var total_count int64
  1969. for _, it := range list {
  1970. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1971. }
  1972. totals := strconv.FormatInt(total_count, 10)
  1973. //查询该药品是否存在开药记录
  1974. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1975. //新增处方盘点库存是否充足
  1976. if advicelist.ID == 0 {
  1977. all_count, _ := strconv.ParseFloat(totals, 64)
  1978. if prescribingNumberUnit == drug.MinUnit {
  1979. if drug.IsUse != 1 {
  1980. if drug.IsProject == 0 || drug.IsProject == 2 {
  1981. if all_count == 0 {
  1982. tx.Rollback()
  1983. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1984. return
  1985. }
  1986. if prescribing_number > all_count {
  1987. tx.Rollback()
  1988. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1989. return
  1990. }
  1991. }
  1992. }
  1993. }
  1994. if prescribingNumberUnit == drug.MaxUnit {
  1995. num := prescribing_number * float64(drug.MinNumber)
  1996. if drug.IsUse != 1 {
  1997. if drug.IsProject == 0 || drug.IsProject == 2 {
  1998. if all_count == 0 {
  1999. tx.Rollback()
  2000. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2001. return
  2002. }
  2003. if num > all_count {
  2004. tx.Rollback()
  2005. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2006. return
  2007. }
  2008. }
  2009. }
  2010. }
  2011. }
  2012. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2013. //不使用保存处方出库
  2014. if drugOutConfig.IsOpen != 1 {
  2015. //修改处方
  2016. for _, advice := range advices {
  2017. var drug_id int64
  2018. var prescribing_number float64
  2019. var prescribingNumberUnit string
  2020. var prescribingNumber string
  2021. var adviceId int64
  2022. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2023. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2024. }
  2025. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2026. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2027. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2028. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2029. }
  2030. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2031. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2032. }
  2033. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2034. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2035. }
  2036. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2037. if drug.ID == 0 {
  2038. tx.Rollback()
  2039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2040. return
  2041. }
  2042. //查询药品的所有库存
  2043. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2044. var total_count int64
  2045. for _, it := range list {
  2046. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2047. }
  2048. totals := strconv.FormatInt(total_count, 10)
  2049. //查询该药品是否存在开药记录
  2050. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2051. //新增处方
  2052. if advicelist.ID == 0 {
  2053. all_count, _ := strconv.ParseFloat(totals, 64)
  2054. if prescribingNumberUnit == drug.MinUnit {
  2055. if drug.IsUse != 1 {
  2056. if drug.IsProject == 0 || drug.IsProject == 2 {
  2057. if all_count == 0 {
  2058. tx.Rollback()
  2059. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2060. return
  2061. }
  2062. if prescribing_number > all_count {
  2063. tx.Rollback()
  2064. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2065. return
  2066. }
  2067. }
  2068. }
  2069. } else {
  2070. if prescribingNumberUnit == drug.MaxUnit {
  2071. num := prescribing_number * float64(drug.MinNumber)
  2072. if drug.IsUse != 1 {
  2073. if drug.IsProject == 0 || drug.IsProject == 2 {
  2074. if all_count == 0 {
  2075. tx.Rollback()
  2076. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2077. return
  2078. }
  2079. if num > all_count {
  2080. tx.Rollback()
  2081. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2082. return
  2083. }
  2084. }
  2085. }
  2086. }
  2087. }
  2088. }
  2089. //修改处方
  2090. if advicelist.ID > 0 {
  2091. var device_number int64
  2092. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2093. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2094. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2095. device_number = prescribingNumberInt * drug.MinNumber
  2096. }
  2097. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2098. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2099. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2100. device_number = prescribingNumberInt
  2101. }
  2102. var number_count int64
  2103. if prescribingNumberUnit == drug.MaxUnit {
  2104. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2105. number_count = prescribingNumberInt * drug.MinNumber
  2106. }
  2107. if prescribingNumberUnit == drug.MinUnit {
  2108. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2109. number_count = prescribingNumberInt
  2110. }
  2111. //如果修改的数量大于之前修改的数量
  2112. if (number_count - device_number) > 0 {
  2113. //如果修改的差数量 大于库存数量
  2114. if drug.IsUse != 1 {
  2115. if (number_count - device_number) > total_count {
  2116. tx.Rollback()
  2117. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2118. return
  2119. }
  2120. }
  2121. }
  2122. }
  2123. }
  2124. }
  2125. }
  2126. }
  2127. }
  2128. }
  2129. }
  2130. }
  2131. }
  2132. //已发药和已收费限制逻辑
  2133. //执行出库的逻辑
  2134. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2135. //校验库存总量
  2136. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2137. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2138. if len(prescriptions) > 0 {
  2139. for _, item := range prescriptions {
  2140. items := item.(map[string]interface{})
  2141. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2142. advices := items["advices"].([]interface{})
  2143. if len(advices) > 0 {
  2144. for _, advice := range advices {
  2145. var drug_id int64
  2146. var prescribing_number float64
  2147. var prescribingNumberUnit string
  2148. var adviceId int64
  2149. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2150. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2151. }
  2152. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2153. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2154. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2155. }
  2156. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2157. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2158. }
  2159. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2160. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2161. }
  2162. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2163. if drug.ID == 0 {
  2164. tx.Rollback()
  2165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2166. return
  2167. }
  2168. //查询药品的所有库存
  2169. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2170. var total_count int64
  2171. for _, it := range list {
  2172. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2173. }
  2174. totals := strconv.FormatInt(total_count, 10)
  2175. //查询该药品是否存在开药记录
  2176. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2177. //查询最新批次库存
  2178. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2179. var batch_number_count int64
  2180. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2181. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2182. //新增处方
  2183. if advicelist.ID == 0 {
  2184. all_count, _ := strconv.ParseFloat(totals, 64)
  2185. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2186. if prescribingNumberUnit == drug.MinUnit {
  2187. if drug.IsUse != 1 {
  2188. if drug.IsProject == 0 || drug.IsProject == 2 {
  2189. if all_count == 0 {
  2190. tx.Rollback()
  2191. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2192. return
  2193. }
  2194. if prescribing_number > all_count {
  2195. tx.Rollback()
  2196. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2197. return
  2198. }
  2199. }
  2200. if adminInfo.CurrentOrgId == 10215 {
  2201. if prescribing_number > batch_number_all_count {
  2202. tx.Rollback()
  2203. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2204. return
  2205. }
  2206. }
  2207. }
  2208. }
  2209. if prescribingNumberUnit == drug.MaxUnit {
  2210. num := prescribing_number * float64(drug.MinNumber)
  2211. if drug.IsUse != 1 {
  2212. if drug.IsProject == 0 || drug.IsProject == 2 {
  2213. if all_count == 0 {
  2214. tx.Rollback()
  2215. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2216. return
  2217. }
  2218. if num > all_count {
  2219. tx.Rollback()
  2220. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2221. return
  2222. }
  2223. }
  2224. if adminInfo.CurrentOrgId == 10215 {
  2225. if num > batch_number_all_count {
  2226. tx.Rollback()
  2227. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2228. return
  2229. }
  2230. }
  2231. }
  2232. }
  2233. }
  2234. //不是保存处方出库
  2235. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2236. if drugOutConfig.IsOpen != 1 {
  2237. //修改处方
  2238. for _, advice := range advices {
  2239. var drug_id int64
  2240. var prescribing_number float64
  2241. var prescribingNumberUnit string
  2242. var prescribingNumber string
  2243. var adviceId int64
  2244. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2245. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2246. }
  2247. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2248. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2249. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2250. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2251. }
  2252. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2253. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2254. }
  2255. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2256. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2257. }
  2258. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2259. if drug.ID == 0 {
  2260. tx.Rollback()
  2261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2262. return
  2263. }
  2264. //查询药品的所有库存
  2265. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2266. var total_count int64
  2267. for _, it := range list {
  2268. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2269. }
  2270. totals := strconv.FormatInt(total_count, 10)
  2271. //查询该药品是否存在开药记录
  2272. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2273. //新增处方
  2274. if advicelist.ID == 0 {
  2275. //查询最新批次库存
  2276. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2277. var batch_number_count int64
  2278. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2279. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2280. all_count, _ := strconv.ParseFloat(totals, 64)
  2281. if all_count == 0 {
  2282. tx.Rollback()
  2283. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2284. return
  2285. }
  2286. if prescribingNumberUnit == drug.MinUnit {
  2287. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2288. if drug.IsUse != 1 {
  2289. if drug.IsProject == 0 || drug.IsProject == 2 {
  2290. if all_count == 0 {
  2291. tx.Rollback()
  2292. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2293. return
  2294. }
  2295. if prescribing_number > all_count {
  2296. tx.Rollback()
  2297. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2298. return
  2299. }
  2300. }
  2301. if adminInfo.CurrentOrgId == 10215 {
  2302. if prescribing_number > batch_number_all_count {
  2303. tx.Rollback()
  2304. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2305. return
  2306. }
  2307. }
  2308. }
  2309. } else {
  2310. if prescribingNumberUnit == drug.MaxUnit {
  2311. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2312. num := prescribing_number * float64(drug.MinNumber)
  2313. if drug.IsUse != 1 {
  2314. if drug.IsProject == 0 || drug.IsProject == 2 {
  2315. if all_count == 0 {
  2316. tx.Rollback()
  2317. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2318. return
  2319. }
  2320. if num > all_count {
  2321. tx.Rollback()
  2322. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2323. return
  2324. }
  2325. }
  2326. if adminInfo.CurrentOrgId == 10215 {
  2327. if prescribing_number > batch_number_all_count {
  2328. tx.Rollback()
  2329. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2330. return
  2331. }
  2332. }
  2333. }
  2334. }
  2335. }
  2336. }
  2337. //修改处方
  2338. if advicelist.ID > 0 {
  2339. //查询最新批次库存
  2340. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2341. var batch_number_count int64
  2342. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2343. var device_number int64
  2344. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2345. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2346. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2347. device_number = prescribingNumberInt * drug.MinNumber
  2348. }
  2349. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2350. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2351. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2352. device_number = prescribingNumberInt
  2353. //回退库存
  2354. }
  2355. var number_count int64
  2356. if prescribingNumberUnit == drug.MaxUnit {
  2357. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2358. number_count = prescribingNumberInt * drug.MinNumber
  2359. //回退库存
  2360. }
  2361. if prescribingNumberUnit == drug.MinUnit {
  2362. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2363. number_count = prescribingNumberInt
  2364. //回退库存
  2365. }
  2366. //如果修改的数量大于之前修改的数量
  2367. if (number_count - device_number) > 0 {
  2368. //如果修改的差数量 大于库存数量
  2369. if drug.IsUse != 1 {
  2370. if drug.IsProject == 0 || drug.IsProject == 2 {
  2371. if total_count == 0 {
  2372. tx.Rollback()
  2373. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2374. return
  2375. }
  2376. if (number_count - device_number) > total_count {
  2377. tx.Rollback()
  2378. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2379. return
  2380. }
  2381. if (number_count - device_number) > batch_number_count {
  2382. tx.Rollback()
  2383. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2384. return
  2385. }
  2386. }
  2387. if adminInfo.CurrentOrgId == 10215 {
  2388. // 查询该药品最后一次出库记录
  2389. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2390. var out_count int64
  2391. var in_count int64
  2392. var stock_max_number int64
  2393. var stock_min_number int64
  2394. for _, it := range outInfo {
  2395. if it.CountUnit == drug.MaxUnit {
  2396. it.Count = it.Count * drug.MinNumber
  2397. }
  2398. out_count += it.Count
  2399. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2400. stock_max_number = warehouseInfoList.StockMaxNumber
  2401. stock_min_number = warehouseInfoList.StockMinNumber
  2402. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2403. }
  2404. if out_count > 0 {
  2405. if (number_count - device_number) > in_count {
  2406. tx.Rollback()
  2407. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2408. return
  2409. }
  2410. }
  2411. // 未出库
  2412. if out_count == 0 {
  2413. var sum_in_count int64
  2414. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2415. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2416. //如果修改的数量大于有库存的第一个批次
  2417. if number_count > sum_in_count {
  2418. tx.Rollback()
  2419. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2420. return
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }
  2426. //药品发药
  2427. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2428. //不使用药品发药的功能
  2429. //if pharmacyConfig.IsOpen != 1 {
  2430. // if device_number != number_count {
  2431. //
  2432. // //查询该药品的出库记录
  2433. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2434. // if len(outListExport) > 0 {
  2435. // //
  2436. // for _, item := range outListExport {
  2437. // //回退库存
  2438. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2439. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2440. // }
  2441. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2442. // var stock_max_number int64
  2443. // var stock_min_number int64
  2444. //
  2445. // if number_count >= drug.MinNumber {
  2446. //
  2447. // stock_max_number = device_number / drug.MinNumber
  2448. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2449. //
  2450. // stock_min_number = device_number % drug.MinNumber
  2451. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2452. //
  2453. // } else {
  2454. //
  2455. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2456. //
  2457. // }
  2458. // }
  2459. //
  2460. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2461. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2462. // }
  2463. // }
  2464. // }
  2465. //
  2466. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2467. // var sum_count int64
  2468. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2469. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2470. // for _, its := range stockInfo {
  2471. // if its.MaxUnit == drug.MaxUnit {
  2472. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2473. // }
  2474. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2475. // }
  2476. // //更新字典里面的库存
  2477. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2478. //
  2479. // //剩余库存
  2480. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2481. //
  2482. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2483. // //减少出库数量
  2484. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2485. //
  2486. // }
  2487. //}
  2488. }
  2489. }
  2490. }
  2491. //保存处方开药
  2492. if drugOutConfig.IsOpen == 1 {
  2493. //修改处方
  2494. for _, advice := range advices {
  2495. var drug_id int64
  2496. var prescribing_number float64
  2497. var prescribingNumberUnit string
  2498. var prescribingNumber string
  2499. var adviceId int64
  2500. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2501. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2502. }
  2503. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2504. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2505. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2506. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2507. }
  2508. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2509. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2510. }
  2511. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2512. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2513. }
  2514. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2515. if drug.ID == 0 {
  2516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2517. return
  2518. }
  2519. //查询药品的所有库存
  2520. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2521. var total_count int64
  2522. for _, it := range list {
  2523. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2524. }
  2525. totals := strconv.FormatInt(total_count, 10)
  2526. //查询该药品是否存在开药记录
  2527. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2528. //新增处方
  2529. if advicelist.ID == 0 {
  2530. //查询最新批次库存
  2531. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2532. var batch_number_count int64
  2533. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2534. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2535. all_count, _ := strconv.ParseFloat(totals, 64)
  2536. if prescribingNumberUnit == drug.MinUnit {
  2537. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2538. if drug.IsUse != 1 {
  2539. if drug.IsProject == 0 || drug.IsProject == 2 {
  2540. if all_count == 0 {
  2541. tx.Rollback()
  2542. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2543. return
  2544. }
  2545. if prescribing_number > all_count {
  2546. tx.Rollback()
  2547. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2548. return
  2549. }
  2550. }
  2551. if adminInfo.CurrentOrgId == 10215 {
  2552. if prescribing_number > batch_number_all_count {
  2553. tx.Rollback()
  2554. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2555. return
  2556. }
  2557. }
  2558. }
  2559. } else {
  2560. if prescribingNumberUnit == drug.MaxUnit {
  2561. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2562. num := prescribing_number * float64(drug.MinNumber)
  2563. if drug.IsUse != 1 {
  2564. if drug.IsProject == 0 || drug.IsProject == 2 {
  2565. if all_count == 0 {
  2566. tx.Rollback()
  2567. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2568. return
  2569. }
  2570. if num > all_count {
  2571. tx.Rollback()
  2572. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2573. return
  2574. }
  2575. }
  2576. if adminInfo.CurrentOrgId == 10215 {
  2577. if prescribing_number > batch_number_all_count {
  2578. tx.Rollback()
  2579. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2580. return
  2581. }
  2582. }
  2583. }
  2584. }
  2585. }
  2586. }
  2587. //修改处方
  2588. if advicelist.ID > 0 {
  2589. //查询最新批次库存
  2590. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2591. var batch_number_count int64
  2592. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2593. var device_number int64
  2594. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2595. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2596. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2597. device_number = prescribingNumberInt * drug.MinNumber
  2598. }
  2599. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2600. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2601. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2602. device_number = prescribingNumberInt
  2603. }
  2604. var number_count int64
  2605. if prescribingNumberUnit == drug.MaxUnit {
  2606. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2607. number_count = prescribingNumberInt * drug.MinNumber
  2608. }
  2609. if prescribingNumberUnit == drug.MinUnit {
  2610. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2611. number_count = prescribingNumberInt
  2612. }
  2613. //如果修改的数量大于之前修改的数量
  2614. if (number_count - device_number) > 0 {
  2615. //如果修改的差数量 大于库存数量
  2616. if drug.IsUse != 1 {
  2617. if drug.IsProject == 0 || drug.IsProject == 2 {
  2618. if total_count == 0 {
  2619. tx.Rollback()
  2620. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2621. return
  2622. }
  2623. if (number_count - device_number) > total_count {
  2624. tx.Rollback()
  2625. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2626. return
  2627. }
  2628. }
  2629. if adminInfo.CurrentOrgId == 10215 {
  2630. if (number_count - device_number) > batch_number_count {
  2631. tx.Rollback()
  2632. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2633. return
  2634. }
  2635. }
  2636. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2637. //查询历史出库数据总批次
  2638. // 查询该药品最后一次出库记录
  2639. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2640. var out_count int64
  2641. var in_count int64
  2642. var stock_max_number int64
  2643. var stock_min_number int64
  2644. for _, it := range outInfo {
  2645. if it.CountUnit == drug.MaxUnit {
  2646. it.Count = it.Count * drug.MinNumber
  2647. }
  2648. out_count += it.Count
  2649. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2650. stock_max_number = warehouseInfoList.StockMaxNumber
  2651. stock_min_number = warehouseInfoList.StockMinNumber
  2652. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2653. }
  2654. if out_count > 0 {
  2655. if (number_count - device_number) > in_count {
  2656. tx.Rollback()
  2657. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2658. return
  2659. }
  2660. }
  2661. // 未出库
  2662. if out_count == 0 {
  2663. var sum_in_count int64
  2664. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2665. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2666. if sum_in_count == 0 {
  2667. tx.Rollback()
  2668. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2669. return
  2670. }
  2671. //如果修改的数量大于有库存的第一个批次
  2672. if number_count > sum_in_count {
  2673. tx.Rollback()
  2674. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2675. return
  2676. }
  2677. }
  2678. }
  2679. }
  2680. }
  2681. }
  2682. }
  2683. }
  2684. }
  2685. }
  2686. }
  2687. }
  2688. }
  2689. }
  2690. }
  2691. //校验耗材库存
  2692. if goodOutConfig.IsOpen == 1 {
  2693. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2694. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2695. if len(prescriptions) > 0 {
  2696. for _, item := range prescriptions {
  2697. items := item.(map[string]interface{})
  2698. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2699. projects := items["project"].([]interface{})
  2700. if len(projects) > 0 {
  2701. for _, project := range projects {
  2702. var project_id int64
  2703. var project_type int64
  2704. var totals float64
  2705. var project_name string
  2706. var parsetotal int64
  2707. var id int64
  2708. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2709. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2710. }
  2711. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2712. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2713. }
  2714. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2715. total, _ := project.(map[string]interface{})["total"].(string)
  2716. totals, _ = strconv.ParseFloat(total, 64)
  2717. }
  2718. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2719. project_name = project.(map[string]interface{})["project_name"].(string)
  2720. }
  2721. if project_type == 3 {
  2722. //查找该耗材的出库记录
  2723. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2724. if len(goodWarehouseInfo) == 0 {
  2725. //查询耗材库存
  2726. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2727. var stock_count int64
  2728. for _, it := range list {
  2729. stock_count += it.StockCount
  2730. }
  2731. stock_counts := strconv.FormatInt(stock_count, 10)
  2732. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2733. if stock_total_count == 0 {
  2734. tx.Rollback()
  2735. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2736. return
  2737. }
  2738. if totals > stock_total_count {
  2739. tx.Rollback()
  2740. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2741. return
  2742. }
  2743. }
  2744. if len(goodWarehouseInfo) > 0 {
  2745. //查询该患者耗材的历史数据
  2746. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2747. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2748. //数量发生改变
  2749. if parsetotal != count {
  2750. //如果现在的数量大于历史数量,就要看库存是否足够
  2751. if parsetotal > count {
  2752. //查询耗材所有库存
  2753. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2754. var stock_count int64
  2755. for _, it := range list {
  2756. stock_count += it.StockCount
  2757. }
  2758. //库存不足
  2759. if stock_count == 0 {
  2760. tx.Rollback()
  2761. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2762. return
  2763. }
  2764. if (parsetotal - count) > stock_count {
  2765. tx.Rollback()
  2766. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2767. return
  2768. }
  2769. }
  2770. }
  2771. }
  2772. }
  2773. }
  2774. }
  2775. }
  2776. }
  2777. }
  2778. }
  2779. }
  2780. //不使用耗材保存处方出库
  2781. if goodOutConfig.IsOpen != 1 {
  2782. if stockConfig.IsOpen == 1 {
  2783. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2784. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2785. if len(prescriptions) > 0 {
  2786. for _, item := range prescriptions {
  2787. items := item.(map[string]interface{})
  2788. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2789. projects := items["project"].([]interface{})
  2790. if len(projects) > 0 {
  2791. for _, project := range projects {
  2792. var project_id int64
  2793. var project_type int64
  2794. var totals float64
  2795. var project_name string
  2796. var parsetotal int64
  2797. var id int64
  2798. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2799. id = int64(project.(map[string]interface{})["id"].(float64))
  2800. }
  2801. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2802. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2803. }
  2804. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2805. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2806. }
  2807. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2808. total, _ := project.(map[string]interface{})["total"].(string)
  2809. totals, _ = strconv.ParseFloat(total, 64)
  2810. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2811. }
  2812. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2813. project_name = project.(map[string]interface{})["project_name"].(string)
  2814. }
  2815. if project_type == 3 {
  2816. //查找该耗材的出库记录
  2817. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2818. //没有出库记录
  2819. if len(goodWarehouseInfo) == 0 {
  2820. //查询耗材库存
  2821. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2822. var stock_count int64
  2823. for _, it := range list {
  2824. stock_count += it.StockCount
  2825. }
  2826. stock_counts := strconv.FormatInt(stock_count, 10)
  2827. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2828. if stock_total_count == 0 {
  2829. tx.Rollback()
  2830. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2831. return
  2832. }
  2833. if totals > stock_total_count {
  2834. tx.Rollback()
  2835. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2836. return
  2837. }
  2838. //查找今日该患者已经出库的所有耗材
  2839. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2840. for _, item := range goodList {
  2841. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2842. var flush_count int64
  2843. for _, it := range goodListSix {
  2844. flush_count += it.StockCount
  2845. }
  2846. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2847. creater := adminInfo.AdminUser.Id
  2848. if errs != nil {
  2849. goodErrcode := models.XtGoodErrcode{
  2850. UserOrgId: item.OrgId,
  2851. Errcode: "手动出库更新剩余出库失败",
  2852. GoodId: item.GoodId,
  2853. Status: 1,
  2854. Ctime: time.Now().Unix(),
  2855. Mtime: 0,
  2856. Count: 0,
  2857. StockCount: 0,
  2858. Creater: creater,
  2859. BatchNumberId: 0,
  2860. WarehouseOutId: 0,
  2861. }
  2862. service.CreateGoodErrcode(goodErrcode)
  2863. }
  2864. }
  2865. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2866. }
  2867. //有出库记录
  2868. if len(goodWarehouseInfo) > 0 {
  2869. //查询该患者耗材的历史数据
  2870. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2871. fmt.Println("ordProject-----------------------", ordProject.ProjectId)
  2872. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2873. //数量发生改变
  2874. if parsetotal != count {
  2875. //查找今日该患者已经出库的所有耗材
  2876. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2877. for _, item := range goodList {
  2878. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2879. var flush_count int64
  2880. for _, it := range goodListSix {
  2881. flush_count += it.StockCount
  2882. }
  2883. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2884. //减少出库数量
  2885. creater := adminInfo.AdminUser.Id
  2886. if errs != nil {
  2887. goodErrcode := models.XtGoodErrcode{
  2888. UserOrgId: item.OrgId,
  2889. Errcode: "手动出库更新剩余出库失败",
  2890. GoodId: item.GoodId,
  2891. Status: 1,
  2892. Ctime: time.Now().Unix(),
  2893. Mtime: 0,
  2894. Count: 0,
  2895. StockCount: 0,
  2896. Creater: creater,
  2897. BatchNumberId: 0,
  2898. WarehouseOutId: 0,
  2899. }
  2900. service.CreateGoodErrcode(goodErrcode)
  2901. }
  2902. //查询默认仓库
  2903. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2904. var total_count int64
  2905. for _, it := range stockList {
  2906. total_count += it.StockCount
  2907. }
  2908. //基础库插入数据
  2909. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2910. }
  2911. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2912. }
  2913. }
  2914. }
  2915. }
  2916. }
  2917. }
  2918. }
  2919. }
  2920. }
  2921. }
  2922. }
  2923. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2924. var hpInfo models.HisPrescriptionInfo
  2925. if info.ID == 0 {
  2926. var randNum int
  2927. randNum = rand.Intn(10000) + 1000
  2928. timestamp := time.Now().Unix()
  2929. tempTime := time.Unix(timestamp, 0)
  2930. timeFormat := tempTime.Format("20060102150405")
  2931. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2932. hpInfo = models.HisPrescriptionInfo{
  2933. HisPatientId: his_patient_id,
  2934. UserOrgId: adminInfo.CurrentOrgId,
  2935. RecordDate: theTime.Unix(),
  2936. PatientId: patient_id,
  2937. Status: 1,
  2938. Ctime: time.Now().Unix(),
  2939. Mtime: time.Now().Unix(),
  2940. Creator: adminInfo.AdminUser.Id,
  2941. Modifier: adminInfo.AdminUser.Id,
  2942. Diagnosis: diagnose,
  2943. SickHistory: sick_history,
  2944. Departments: department,
  2945. RegisterType: reg_type,
  2946. PrescriptionNumber: p_number,
  2947. PrescriptionStatus: 1,
  2948. Doctor: role.UserName,
  2949. DoctorId: doctor_id,
  2950. SickType: sick_type,
  2951. PType: p_type,
  2952. PatientDiagnosis: patient_diagnose,
  2953. }
  2954. service.SavePatientPrescriptionInfo(hpInfo)
  2955. //创建步骤表
  2956. finish := models.XtDialysisFinish{
  2957. IsFinish: 1,
  2958. UserOrgId: adminInfo.CurrentOrgId,
  2959. Status: 1,
  2960. Ctime: time.Now().Unix(),
  2961. Mtime: 0,
  2962. Module: 4,
  2963. RecordDate: theTime.Unix(),
  2964. Sourse: 1,
  2965. PatientId: patient_id,
  2966. }
  2967. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2968. if dialysisFinish.ID == 0 {
  2969. service.CreateDialysisFinish(finish)
  2970. }
  2971. redis := service.RedisClient()
  2972. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2973. redis.Set(key, "", time.Second)
  2974. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2975. redis.Set(keyOne, "", time.Second)
  2976. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2977. redis.Set(keySeven, "", time.Second)
  2978. defer redis.Close()
  2979. } else {
  2980. hpInfo = models.HisPrescriptionInfo{
  2981. ID: info.ID,
  2982. UserOrgId: adminInfo.CurrentOrgId,
  2983. RecordDate: info.RecordDate,
  2984. PatientId: info.PatientId,
  2985. Status: 1,
  2986. Ctime: info.Ctime,
  2987. Mtime: time.Now().Unix(),
  2988. Creator: info.Creator,
  2989. Modifier: adminInfo.AdminUser.Id,
  2990. Diagnosis: diagnose,
  2991. SickHistory: sick_history,
  2992. Departments: department,
  2993. RegisterType: reg_type,
  2994. PrescriptionNumber: info.PrescriptionNumber,
  2995. Doctor: role.UserName,
  2996. PrescriptionStatus: info.PrescriptionStatus,
  2997. DoctorId: doctor_id,
  2998. SickType: sick_type,
  2999. PType: info.PType,
  3000. HisPatientId: info.HisPatientId,
  3001. PatientDiagnosis: patient_diagnose,
  3002. }
  3003. service.SavePatientPrescriptionInfo(hpInfo)
  3004. //创建步骤表
  3005. finish := models.XtDialysisFinish{
  3006. IsFinish: 1,
  3007. UserOrgId: adminInfo.CurrentOrgId,
  3008. Status: 1,
  3009. Ctime: time.Now().Unix(),
  3010. Mtime: 0,
  3011. Module: 4,
  3012. RecordDate: info.RecordDate,
  3013. Sourse: 1,
  3014. PatientId: info.PatientId,
  3015. }
  3016. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  3017. if dialysisFinish.ID == 0 {
  3018. service.CreateDialysisFinish(finish)
  3019. }
  3020. redis := service.RedisClient()
  3021. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3022. redis.Set(key, "", time.Second)
  3023. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3024. redis.Set(keyOne, "", time.Second)
  3025. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3026. redis.Set(keySeven, "", time.Second)
  3027. defer redis.Close()
  3028. }
  3029. //定义切片
  3030. var adviceList []models.HisDoctorAdviceInfo
  3031. var projectList []models.HisPrescriptionProject
  3032. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10644 || adminInfo.CurrentOrgId == 10635 || adminInfo.CurrentOrgId == 10598 || adminInfo.CurrentOrgId == 10028 || adminInfo.CurrentOrgId == 10721 || adminInfo.CurrentOrgId == 10726 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10571 || adminInfo.CurrentOrgId == 10724 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10653 || adminInfo.CurrentOrgId == 10567 || adminInfo.CurrentOrgId == 10751 || adminInfo.CurrentOrgId == 10752 {
  3033. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3034. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3035. var tempPrescription *models.HisPrescription
  3036. if len(prescriptions) > 0 {
  3037. for _, item := range prescriptions {
  3038. // 开始外部循环的事务
  3039. tx := db.Begin()
  3040. // 在函数结束时处理事务回滚
  3041. defer func() {
  3042. if r := recover(); r != nil {
  3043. tx.Rollback()
  3044. }
  3045. }()
  3046. items := item.(map[string]interface{})
  3047. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3048. utils.ErrorLog("id")
  3049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3050. return
  3051. }
  3052. id := int64(items["id"].(float64))
  3053. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3054. tempPrescription = &new_prescription
  3055. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3056. utils.ErrorLog("type")
  3057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3058. return
  3059. }
  3060. types := int64(items["type"].(float64))
  3061. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3062. utils.ErrorLog("med_type")
  3063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3064. return
  3065. }
  3066. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3067. if med_type == "0" {
  3068. med_type = "14"
  3069. }
  3070. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3071. // utils.ErrorLog("diagnoses")
  3072. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3073. // return
  3074. //}
  3075. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3076. diagnoses, _ := items["diagnoses"].(string)
  3077. //if order_status == 0 {
  3078. // order_status = 1
  3079. //}
  3080. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3081. utils.ErrorLog("pre_time")
  3082. }
  3083. preTime, _ := items["pre_time"].(string)
  3084. fmt.Println("preTime", preTime)
  3085. timeLayout := "2006-01-02"
  3086. loc, _ := time.LoadLocation("Local")
  3087. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3088. //result := strings.Split(preTime, " ")
  3089. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3090. if err != nil {
  3091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3092. return
  3093. }
  3094. pTime := theTime2.Unix()
  3095. ctime := time.Now().Unix()
  3096. if tempPrescription.ID == 0 {
  3097. prescription := &models.HisPrescription{
  3098. ID: 0,
  3099. PatientId: patient_id,
  3100. UserOrgId: adminInfo.CurrentOrgId,
  3101. RecordDate: recordDateTime,
  3102. Ctime: ctime,
  3103. Mtime: ctime,
  3104. Type: types,
  3105. Modifier: adminInfo.AdminUser.Id,
  3106. Creator: adminInfo.AdminUser.Id,
  3107. Status: 1,
  3108. Doctor: role.UserName,
  3109. HisPatientId: his_patient_id,
  3110. OrderStatus: 1,
  3111. BatchNumber: "",
  3112. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3113. PreTime: pTime,
  3114. PType: p_type,
  3115. MedType: med_type,
  3116. Diagnose: diagnoses,
  3117. }
  3118. tempPrescription = prescription
  3119. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3120. redis := service.RedisClient()
  3121. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3122. redis.Set(key, "", time.Second)
  3123. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3124. redis.Set(keyOne, "", time.Second)
  3125. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3126. redis.Set(keySeven, "", time.Second)
  3127. defer redis.Close()
  3128. } else {
  3129. tempPrescription.ID = id
  3130. tempPrescription.Type = types
  3131. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3132. tempPrescription.Mtime = time.Now().Unix()
  3133. tempPrescription.Doctor = role.UserName
  3134. //tempPrescription.OrderStatus = order_status
  3135. tempPrescription.PreTime = pTime
  3136. tempPrescription.MedType = med_type
  3137. tempPrescription.Diagnose = diagnoses
  3138. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3139. redis := service.RedisClient()
  3140. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3141. redis.Set(key, "", time.Second)
  3142. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3143. redis.Set(keyOne, "", time.Second)
  3144. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3145. redis.Set(keySeven, "", time.Second)
  3146. defer redis.Close()
  3147. }
  3148. //service.SaveHisPrescription(prescription)
  3149. //更改患者挂号状态
  3150. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3151. fmt.Println("更改失败", err2)
  3152. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3153. advices := items["advices"].([]interface{})
  3154. groupNo := int64(0)
  3155. if len(advices) > 0 {
  3156. for _, advice := range advices {
  3157. tx := db.Begin()
  3158. // 在函数结束时处理事务回滚
  3159. defer func() {
  3160. if r := recover(); r != nil {
  3161. tx.Rollback()
  3162. }
  3163. }()
  3164. var s models.HisDoctorAdviceInfo
  3165. s.PrescriptionId = tempPrescription.ID
  3166. s.AdviceType = 2
  3167. s.AdviceDoctor = doctor_id
  3168. s.StopState = 2
  3169. s.ExecutionState = 2
  3170. s.AdviceDate = theTime3.Unix()
  3171. s.Status = 1
  3172. s.UserOrgId = adminInfo.CurrentOrgId
  3173. s.RecordDate = theTime3.Unix()
  3174. s.StartTime = tempPrescription.PreTime
  3175. s.Groupno = groupNo
  3176. s.PatientId = patient_id
  3177. s.HisPatientId = his_patient_id
  3178. s.StartTime = pTime
  3179. s.IsSettle = 2
  3180. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3181. if errcode > 0 {
  3182. c.ServeFailJSONWithSGJErrorCode(errcode)
  3183. return
  3184. }
  3185. s.StartTime = pTime
  3186. var total_count int64 //处方总库存
  3187. //查询改药品信息
  3188. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3189. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3190. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3191. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3192. total_count += prescribingNumberSeven * medical.MinNumber
  3193. }
  3194. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3195. total_count += prescribingNumberSeven
  3196. }
  3197. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3198. total_count += prescribingNumberSeven
  3199. }
  3200. //if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3201. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3202. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3203. // if s.Price != lastWarehouse.RetailPrice {
  3204. // s.Price = lastWarehouse.RetailPrice
  3205. // }
  3206. // if s.Price == 0 {
  3207. // if lastWarehouse.ID == 0 {
  3208. // lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3209. // s.Price = lastWarehouseTwo.RetailPrice
  3210. // }
  3211. //
  3212. // }
  3213. //}
  3214. //查询保存处方出库开关是否打开
  3215. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3216. if s.PatientId != 30038 {
  3217. if drugOutConfig.IsOpen == 1 {
  3218. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3219. // 查询该药品最后一次出库记录
  3220. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3221. var is_user_total int64
  3222. var no_user_total int64
  3223. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3224. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3225. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3226. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3227. }
  3228. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3229. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3230. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3231. no_user_total += prescribingNumberSevenTy
  3232. }
  3233. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3234. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3235. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3236. no_user_total += prescribingNumberSevenTy
  3237. }
  3238. if len(druginfo) > 0 {
  3239. for _, it := range druginfo {
  3240. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3241. it.Count = it.Count * drug.MinNumber
  3242. is_user_total += it.Count
  3243. }
  3244. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3245. is_user_total += it.Count
  3246. }
  3247. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3248. is_user_total += it.Count
  3249. }
  3250. }
  3251. }
  3252. //库存不足
  3253. if s.UserOrgId != 10206 {
  3254. //判断库存不足的地方
  3255. if s.ID == 0 {
  3256. //查询改药品是否已经停用
  3257. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3258. if base.ID > 0 {
  3259. tx.Rollback()
  3260. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3261. return
  3262. }
  3263. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3264. if drugMedical.SumCount == 0 {
  3265. tx.Rollback()
  3266. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3267. return
  3268. }
  3269. list, _ := service.GetLastDrugWarehouseInfoList(s.DrugId)
  3270. if len(list) == 0 {
  3271. tx.Rollback()
  3272. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3273. return
  3274. }
  3275. //针对康德
  3276. //if s.UserOrgId == 10402 || s.UserOrgId == 10164 {
  3277. // //获取该药品的总入库数量
  3278. // drugWarehouseinfo, _ := service.GetAllDrugInfoList(s.DrugId, s.UserOrgId)
  3279. //
  3280. // //获取该药品总共开了多少支医嘱
  3281. // hisDocInfoList, _ := service.GetHisDocInfoList(s.DrugId, s.UserOrgId)
  3282. // var in_count int64
  3283. // var in_prescription_number_total int64
  3284. // if len(drugWarehouseinfo) > 0 {
  3285. // for _, item := range drugWarehouseinfo {
  3286. // if item.MaxUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3287. //
  3288. // in_count += item.WarehousingCount * drugMedical.MinNumber
  3289. // }
  3290. //
  3291. // if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3292. //
  3293. // in_count += item.WarehousingCount
  3294. // }
  3295. //
  3296. // if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3297. //
  3298. // in_count += item.WarehousingCount
  3299. // }
  3300. //
  3301. // }
  3302. // }
  3303. //
  3304. // if len(hisDocInfoList) > 0 {
  3305. //
  3306. // for _, item := range hisDocInfoList {
  3307. // if item.PrescribingNumberUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3308. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3309. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3310. //
  3311. // in_prescription_number_total += prescribingNumberSevenTy * drug.MinNumber
  3312. // }
  3313. //
  3314. // if item.PrescribingNumberUnit == drugMedical.MinUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3315. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3316. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3317. // in_prescription_number_total += prescribingNumberSevenTy
  3318. // }
  3319. //
  3320. // if item.PrescribingNumberUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3321. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3322. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3323. // in_prescription_number_total += prescribingNumberSevenTy
  3324. // }
  3325. // }
  3326. // }
  3327. // //
  3328. // //fmt.Println("no_user_total------------------------------", no_user_total)
  3329. // //fmt.Println("in_prescription_number_total---------------------------", in_prescription_number_total)
  3330. // //fmt.Println("in_count----------------------------------", in_count)
  3331. //
  3332. // //如果已经开过的医嘱 加上未开的医嘱数量 大于 入库总数量则提示库存不足
  3333. // if no_user_total+in_prescription_number_total > in_count {
  3334. // tx.Rollback()
  3335. // c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3336. // return
  3337. // }
  3338. //
  3339. //}
  3340. //查询该药品所有入库数量
  3341. }
  3342. fmt.Println("s.ID==========================", s.ID)
  3343. if s.ID > 0 {
  3344. //查询改药品是否已经停用
  3345. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3346. if base.ID > 0 {
  3347. tx.Rollback()
  3348. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3349. return
  3350. }
  3351. }
  3352. }
  3353. //fmt.Println("药品名称----------------------", drug.DrugName)
  3354. //fmt.Println("药品名称----------------------", drug.IsUse)
  3355. //fmt.Println("drug_iiiiiiiiiiiiiiiiiiii", drug.ID)
  3356. //fmt.Println("is_user_total-------------------------", is_user_total)
  3357. //fmt.Println("no_user_total-------------------------", no_user_total)
  3358. //fmt.Println("drug.IsUse---------------", drug.IsUse)
  3359. //fmt.Println("00000000000000000000", s.UserOrgId)
  3360. if is_user_total != no_user_total {
  3361. //出库
  3362. //针对御享天源
  3363. if drug.IsUse == 1 && s.UserOrgId == 10635 {
  3364. //查询改药品是否已经停用
  3365. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3366. if base.ID > 0 {
  3367. tx.Rollback()
  3368. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3369. return
  3370. }
  3371. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3372. if drugMedical.SumCount == 0 {
  3373. tx.Rollback()
  3374. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3375. return
  3376. }
  3377. creater := adminInfo.AdminUser.Id
  3378. newadviceInfo := &models.HisDoctorAdviceInfo{
  3379. ID: s.ID,
  3380. UserOrgId: s.UserOrgId,
  3381. PatientId: s.PatientId,
  3382. HisPatientId: s.HisPatientId,
  3383. AdviceType: s.AdviceType,
  3384. AdviceDate: s.AdviceDate,
  3385. StartTime: s.StartTime,
  3386. AdviceName: s.AdviceName,
  3387. AdviceDesc: s.AdviceDesc,
  3388. ReminderDate: s.ReminderDate,
  3389. SingleDose: s.SingleDose,
  3390. SingleDoseUnit: s.SingleDoseUnit,
  3391. PrescribingNumber: s.PrescribingNumber,
  3392. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3393. DeliveryWay: s.DeliveryWay,
  3394. ExecutionFrequency: s.ExecutionFrequency,
  3395. AdviceDoctor: s.AdviceDoctor,
  3396. Status: s.Status,
  3397. CreatedTime: s.CreatedTime,
  3398. UpdatedTime: s.UpdatedTime,
  3399. AdviceAffirm: s.AdviceAffirm,
  3400. Remark: s.Remark,
  3401. StopTime: s.StopTime,
  3402. StopReason: s.StopReason,
  3403. StopDoctor: s.StopDoctor,
  3404. StopState: s.StopState,
  3405. ParentId: s.ParentId,
  3406. ExecutionTime: s.ExecutionTime,
  3407. ExecutionStaff: s.ExecutionStaff,
  3408. ExecutionState: s.ExecutionState,
  3409. Checker: s.Checker,
  3410. RecordDate: s.RecordDate,
  3411. DialysisOrderId: s.DialysisOrderId,
  3412. CheckTime: s.CheckTime,
  3413. CheckState: s.CheckState,
  3414. DrugSpec: s.DrugSpec,
  3415. DrugSpecUnit: s.DrugSpecUnit,
  3416. Groupno: s.Groupno,
  3417. RemindType: s.RemindType,
  3418. FrequencyType: s.FrequencyType,
  3419. DayCount: s.DayCount,
  3420. WeekDay: s.WeekDay,
  3421. TemplateId: s.TemplateId,
  3422. Modifier: s.Modifier,
  3423. DrugId: s.DrugId,
  3424. Price: s.Price,
  3425. PrescriptionId: s.PrescriptionId,
  3426. MedListCodg: s.MedListCodg,
  3427. FeedetlSn: s.FeedetlSn,
  3428. Day: s.DayCount,
  3429. ChildDoctorAdvice: nil,
  3430. Drug: models.Drug{},
  3431. Diagnosis: s.Diagnosis,
  3432. Way: s.Way,
  3433. HospApprFlag: s.HospApprFlag,
  3434. LmtUsedFlag: s.LmtUsedFlag,
  3435. HisOrderInfo: models.HisOrderInfo{},
  3436. IsMedicine: s.IsMedicine,
  3437. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3438. Child: nil,
  3439. IsSettle: s.IsSettle,
  3440. IsMobile: s.IsMobile,
  3441. IsSelfDrug: s.IsSelfDrug,
  3442. DrugWayCount: s.DrugWayCount,
  3443. }
  3444. var history_count int64
  3445. var local_count int64
  3446. //查找已经开过的医嘱信息
  3447. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3448. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3449. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3450. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3451. local_count += prescribingNumberSevenTy * drug.MinNumber
  3452. }
  3453. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3454. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3455. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3456. local_count += prescribingNumberSevenTy
  3457. }
  3458. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3459. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3460. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3461. local_count += prescribingNumberSevenTy
  3462. }
  3463. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3464. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3465. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3466. history_count += prescribingNumberSevenTy * drug.MinNumber
  3467. }
  3468. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3469. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3470. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3471. history_count += prescribingNumberSevenTy
  3472. }
  3473. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3474. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3475. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3476. history_count += prescribingNumberSevenTy
  3477. }
  3478. //fmt.Println("local_count---------------", local_count)
  3479. //fmt.Println("history_count---------------", history_count)
  3480. //如果当前出库数量大于历史出库数量则需要出库
  3481. if local_count > history_count {
  3482. //按最小单位出库
  3483. var cha_count = local_count - history_count
  3484. newadviceInfo.PrescribingNumber = float64(cha_count)
  3485. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3486. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3487. }
  3488. //如果当前出库数量小于历史出库数量则需要退库
  3489. if local_count < history_count {
  3490. var cha_count = history_count - local_count
  3491. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3492. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3493. }
  3494. if local_count == history_count {
  3495. if is_user_total == 0 {
  3496. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3497. }
  3498. }
  3499. }
  3500. if drug.IsUse == 2 {
  3501. creater := adminInfo.AdminUser.Id
  3502. newadviceInfo := &models.HisDoctorAdviceInfo{
  3503. ID: s.ID,
  3504. UserOrgId: s.UserOrgId,
  3505. PatientId: s.PatientId,
  3506. HisPatientId: s.HisPatientId,
  3507. AdviceType: s.AdviceType,
  3508. AdviceDate: s.AdviceDate,
  3509. StartTime: s.StartTime,
  3510. AdviceName: s.AdviceName,
  3511. AdviceDesc: s.AdviceDesc,
  3512. ReminderDate: s.ReminderDate,
  3513. SingleDose: s.SingleDose,
  3514. SingleDoseUnit: s.SingleDoseUnit,
  3515. PrescribingNumber: s.PrescribingNumber,
  3516. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3517. DeliveryWay: s.DeliveryWay,
  3518. ExecutionFrequency: s.ExecutionFrequency,
  3519. AdviceDoctor: s.AdviceDoctor,
  3520. Status: s.Status,
  3521. CreatedTime: s.CreatedTime,
  3522. UpdatedTime: s.UpdatedTime,
  3523. AdviceAffirm: s.AdviceAffirm,
  3524. Remark: s.Remark,
  3525. StopTime: s.StopTime,
  3526. StopReason: s.StopReason,
  3527. StopDoctor: s.StopDoctor,
  3528. StopState: s.StopState,
  3529. ParentId: s.ParentId,
  3530. ExecutionTime: s.ExecutionTime,
  3531. ExecutionStaff: s.ExecutionStaff,
  3532. ExecutionState: s.ExecutionState,
  3533. Checker: s.Checker,
  3534. RecordDate: s.RecordDate,
  3535. DialysisOrderId: s.DialysisOrderId,
  3536. CheckTime: s.CheckTime,
  3537. CheckState: s.CheckState,
  3538. DrugSpec: s.DrugSpec,
  3539. DrugSpecUnit: s.DrugSpecUnit,
  3540. Groupno: s.Groupno,
  3541. RemindType: s.RemindType,
  3542. FrequencyType: s.FrequencyType,
  3543. DayCount: s.DayCount,
  3544. WeekDay: s.WeekDay,
  3545. TemplateId: s.TemplateId,
  3546. Modifier: s.Modifier,
  3547. DrugId: s.DrugId,
  3548. Price: s.Price,
  3549. PrescriptionId: s.PrescriptionId,
  3550. MedListCodg: s.MedListCodg,
  3551. FeedetlSn: s.FeedetlSn,
  3552. Day: s.DayCount,
  3553. ChildDoctorAdvice: nil,
  3554. Drug: models.Drug{},
  3555. Diagnosis: s.Diagnosis,
  3556. Way: s.Way,
  3557. HospApprFlag: s.HospApprFlag,
  3558. LmtUsedFlag: s.LmtUsedFlag,
  3559. HisOrderInfo: models.HisOrderInfo{},
  3560. IsMedicine: s.IsMedicine,
  3561. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3562. Child: nil,
  3563. IsSettle: s.IsSettle,
  3564. IsMobile: s.IsMobile,
  3565. IsSelfDrug: s.IsSelfDrug,
  3566. DrugWayCount: s.DrugWayCount,
  3567. }
  3568. var history_count int64
  3569. var local_count int64
  3570. //查找已经开过的医嘱信息
  3571. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3572. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3573. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3574. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3575. local_count += prescribingNumberSevenTy * drug.MinNumber
  3576. }
  3577. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3578. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3579. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3580. local_count += prescribingNumberSevenTy
  3581. }
  3582. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3583. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3584. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3585. local_count += prescribingNumberSevenTy
  3586. }
  3587. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3588. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3589. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3590. history_count += prescribingNumberSevenTy * drug.MinNumber
  3591. }
  3592. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3593. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3594. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3595. history_count += prescribingNumberSevenTy
  3596. }
  3597. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3598. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3599. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3600. history_count += prescribingNumberSevenTy
  3601. }
  3602. fmt.Println("local_count---------------", local_count)
  3603. fmt.Println("history_count---------------", history_count)
  3604. //如果当前出库数量大于历史出库数量则需要出库
  3605. if local_count > history_count {
  3606. //按最小单位出库
  3607. var cha_count = local_count - history_count
  3608. newadviceInfo.PrescribingNumber = float64(cha_count)
  3609. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3610. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3611. }
  3612. //如果当前出库数量小于历史出库数量则需要退库
  3613. if local_count < history_count {
  3614. var cha_count = history_count - local_count
  3615. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3616. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3617. }
  3618. if local_count == history_count {
  3619. if is_user_total == 0 {
  3620. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3621. }
  3622. }
  3623. }
  3624. //更新字典里面的库存
  3625. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3626. var sum_count int64
  3627. for _, its := range stockInfo {
  3628. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3629. if its.MaxUnit == baseDrug.MaxUnit {
  3630. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3631. }
  3632. sum_count += its.StockMaxNumber + its.StockMinNumber
  3633. }
  3634. //更新基础库存
  3635. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3636. //剩余库存
  3637. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3638. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3639. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3640. //创建医嘱
  3641. service.CreateHisDoctorAdviceOne(&s, tx)
  3642. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3643. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3644. if len(outInfoTwo) > 0 {
  3645. for _, item := range outInfoTwo {
  3646. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3647. }
  3648. }
  3649. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3650. if len(drugAutoDetail) > 0 {
  3651. for _, item := range drugAutoDetail {
  3652. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3653. }
  3654. }
  3655. }
  3656. }
  3657. }
  3658. //记录日志
  3659. byterequest, _ := json.Marshal(s)
  3660. adviceLog := models.XtDoctorAdviceLog{
  3661. UserOrgId: s.UserOrgId,
  3662. PatientId: s.PatientId,
  3663. AdminUserId: adminInfo.AdminUser.Id,
  3664. Module: 1,
  3665. ErrLog: string(byterequest),
  3666. Status: 1,
  3667. Ctime: time.Now().Unix(),
  3668. Mtime: 0,
  3669. Source: "电脑端新建his医嘱",
  3670. RecordDate: s.AdviceDate,
  3671. }
  3672. service.CreateDoctorAdviceLog(adviceLog)
  3673. //存储切片中
  3674. adviceList = append(adviceList, s)
  3675. redis := service.RedisClient()
  3676. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3677. redis.Set(key, "", time.Second)
  3678. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3679. redis.Set(keyOne, "", time.Second)
  3680. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3681. redis.Set(keySeven, "", time.Second)
  3682. var randNum int
  3683. randNum = rand.Intn(10000) + 1000
  3684. timestamp := time.Now().Unix()
  3685. tempTime := time.Unix(timestamp, 0)
  3686. timeFormat := tempTime.Format("20060102150405")
  3687. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3688. //赤峰
  3689. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3690. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3691. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3692. if info.RetailPrice > 0 {
  3693. if s.DeliveryWay == "口服" {
  3694. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3695. s.Price = drug.RetailPrice
  3696. }
  3697. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3698. s.Price = info.RetailPrice
  3699. }
  3700. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3701. s.Price = info.RetailPrice
  3702. }
  3703. }
  3704. }
  3705. }
  3706. service.CreateHisDoctorAdviceOne(&s, tx)
  3707. tx.Commit()
  3708. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3709. redis.Set(keySix, "", time.Second)
  3710. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3711. redis.Set(keyFive, "", time.Second)
  3712. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3713. redis.Set(keyEight, "", time.Second)
  3714. defer redis.Close()
  3715. }
  3716. }
  3717. }
  3718. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3719. projects := items["project"].([]interface{})
  3720. if len(projects) > 0 {
  3721. for _, project := range projects {
  3722. tx := db.Begin()
  3723. // 在函数结束时处理事务回滚
  3724. defer func() {
  3725. if r := recover(); r != nil {
  3726. tx.Rollback()
  3727. }
  3728. }()
  3729. var p models.HisPrescriptionProject
  3730. p.PrescriptionId = tempPrescription.ID
  3731. p.PatientId = patient_id
  3732. p.RecordDate = theTime3.Unix()
  3733. p.Doctor = doctor_id
  3734. p.UserOrgId = adminInfo.CurrentOrgId
  3735. p.HisPatientId = his_patient_id
  3736. p.Status = 1
  3737. p.StartTime = pTime
  3738. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3739. if errcode > 0 {
  3740. tx.Rollback()
  3741. c.ServeFailJSONWithSGJErrorCode(errcode)
  3742. return
  3743. }
  3744. if p.ID == 0 {
  3745. p.IsOut = 2
  3746. }
  3747. if p.ID > 0 {
  3748. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3749. p.IsOut = projectDetail.IsOut
  3750. }
  3751. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3752. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3753. if p.Type == 3 {
  3754. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3755. if p.Price != lastWarehouse.PackingPrice {
  3756. p.Price = lastWarehouse.PackingPrice
  3757. }
  3758. if p.Price == 0 {
  3759. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3760. p.Price = lastWarehouseTwo.PackingPrice
  3761. }
  3762. if p.Unit == "" {
  3763. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3764. p.Unit = goodInfoOne.PackingUnit
  3765. }
  3766. }
  3767. }
  3768. if adminInfo.CurrentOrgId != 10206 {
  3769. if p.Type == 3 {
  3770. //判断耗材库存充不充足
  3771. if p.ID == 0 {
  3772. //查询该耗材是否停用
  3773. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3774. //表示该耗材已经停用,不能保存
  3775. if goodInfoSeven.ID == 0 {
  3776. tx.Rollback()
  3777. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3778. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3779. return
  3780. }
  3781. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3782. if goodInfoOne.SumCount == 0 {
  3783. tx.Rollback()
  3784. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3785. return
  3786. }
  3787. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3788. if len(goodListOne) == 0 {
  3789. tx.Rollback()
  3790. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3791. return
  3792. }
  3793. }
  3794. if p.ID > 0 {
  3795. //查询该耗材是否停用
  3796. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3797. //表示该耗材已经停用,不能保存
  3798. if goodInfoSeven.ID == 0 {
  3799. tx.Rollback()
  3800. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3801. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3802. return
  3803. }
  3804. //查询该耗材今日是否已经出过库
  3805. goodOutList, _ := service.GetGoodWareHouseOutInfoByGood(p.ProjectId, p.RecordDate, p.UserOrgId)
  3806. var his_count int64
  3807. if len(goodOutList) > 0 {
  3808. for _, item := range goodOutList {
  3809. his_count += item.Count
  3810. }
  3811. }
  3812. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3813. //如果当前的处方数量大于 历史出库数量 要判断库存够不够
  3814. if nowCount > his_count {
  3815. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3816. if goodInfoOne.SumCount == 0 {
  3817. tx.Rollback()
  3818. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3819. return
  3820. }
  3821. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3822. if len(goodListOne) == 0 {
  3823. tx.Rollback()
  3824. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3825. return
  3826. }
  3827. }
  3828. if len(goodOutList) == 0 {
  3829. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3830. if goodInfoOne.SumCount == 0 {
  3831. tx.Rollback()
  3832. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3833. return
  3834. }
  3835. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3836. if len(goodListOne) == 0 {
  3837. tx.Rollback()
  3838. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3839. return
  3840. }
  3841. }
  3842. }
  3843. }
  3844. }
  3845. //查询保存耗材出库开关是否打开
  3846. if p.PatientId != 30038 {
  3847. //用机构ID区分
  3848. if adminInfo.CurrentOrgId != 9671 {
  3849. if goodOutConfig.IsOpen == 1 {
  3850. //耗材出库
  3851. if p.Type == 3 {
  3852. //对比当前数据和历史出库数据
  3853. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3854. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3855. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3856. ////针对康德
  3857. //if p.UserOrgId == 10164 || p.UserOrgId == 10402 {
  3858. //
  3859. // //查询耗材的总入库数量
  3860. // warehouseInfo, _ := service.GetAllWarehouseInfo(p.ProjectId, adminInfo.CurrentOrgId)
  3861. //
  3862. // //查询该耗材的总出库数量
  3863. // prescriptionGood, _ := service.GetHisPrescriptionByGoodId(p.ProjectId, adminInfo.CurrentOrgId)
  3864. //
  3865. // var all_good_count int64
  3866. //
  3867. // var prescription_count int64
  3868. // if len(warehouseInfo) > 0 {
  3869. //
  3870. // for _, item := range warehouseInfo {
  3871. // all_good_count += item.WarehousingCount
  3872. // }
  3873. // }
  3874. // if len(prescriptionGood) > 0 {
  3875. // for _, item := range prescriptionGood {
  3876. //
  3877. // hisCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3878. // prescription_count += hisCount
  3879. // }
  3880. // }
  3881. //
  3882. // //fmt.Println("prescription_count-------------------------", prescription_count)
  3883. // //fmt.Println("nowCount-------------------------", nowCount)
  3884. // //fmt.Println("all_good_count-------------------------", all_good_count)
  3885. //
  3886. // if prescription_count+nowCount > all_good_count {
  3887. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3888. // tx.Rollback()
  3889. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3890. // return
  3891. // }
  3892. //}
  3893. fmt.Println("nowCount222=================", nowCount)
  3894. fmt.Println("historyCount-333----------------", historyCount)
  3895. //如果当前处方数量大于历史数据,则需要出库
  3896. if nowCount > historyCount {
  3897. var cha_count int64
  3898. cha_count = nowCount - historyCount
  3899. timeStr := time.Now().Format("2006-01-02")
  3900. timeArr := strings.Split(timeStr, "-")
  3901. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3902. total = total + 1
  3903. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3904. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3905. number = number + total
  3906. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3907. operation_time := time.Now().Unix()
  3908. creater := c.GetAdminUserInfo().AdminUser.Id
  3909. recordDateStr := time.Now().Format("2006-01-02")
  3910. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3911. nowtime := recordDate.Unix()
  3912. warehouseOut := models.WarehouseOut{
  3913. WarehouseOutOrderNumber: warehousing_out_order,
  3914. OperationTime: operation_time,
  3915. OrgId: adminInfo.CurrentOrgId,
  3916. Creater: creater,
  3917. Ctime: time.Now().Unix(),
  3918. Status: 1,
  3919. WarehouseOutTime: nowtime,
  3920. Type: 1,
  3921. StorehouseId: storeConfig.StorehouseOutInfo,
  3922. IsCheck: 1,
  3923. IsSys: 1,
  3924. }
  3925. //查询是否生成出库单
  3926. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3927. if out.ID == 0 {
  3928. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3929. }
  3930. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3931. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3932. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3933. dialyPrepareOne := models.DialysisBeforePrepare{
  3934. GoodTypeId: goodObj.GoodTypeId,
  3935. GoodId: p.ProjectId,
  3936. PatientId: p.PatientId,
  3937. RecordDate: p.RecordDate,
  3938. UserOrgId: adminInfo.CurrentOrgId,
  3939. Count: cha_count,
  3940. Ctime: time.Now().Unix(),
  3941. Creater: creater,
  3942. Status: 1,
  3943. StorehouseId: houseConfig.StorehouseOutInfo,
  3944. ProjectId: p.ID,
  3945. }
  3946. //出库
  3947. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3948. }
  3949. //如果当前处方数量小于历史数据,怎需要退库
  3950. if nowCount < historyCount {
  3951. var cha_count int64
  3952. cha_count = historyCount - nowCount
  3953. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3954. creater := c.GetAdminUserInfo().AdminUser.Id
  3955. newPrescriptionProject := &models.HisPrescriptionProject{
  3956. ID: p.ID,
  3957. ProjectId: p.ProjectId,
  3958. Price: p.Price,
  3959. UserOrgId: p.UserOrgId,
  3960. Status: 1,
  3961. Ctime: time.Now().Unix(),
  3962. Mtime: time.Now().Unix(),
  3963. PatientId: p.PatientId,
  3964. HisPatientId: p.HisPatientId,
  3965. RecordDate: p.RecordDate,
  3966. PrescriptionId: p.PrescriptionId,
  3967. Count: p.Count,
  3968. FeedetlSn: p.FeedetlSn,
  3969. MedListCodg: p.MedListCodg,
  3970. SingleDose: p.SingleDose,
  3971. DeliveryWay: p.DeliveryWay,
  3972. ExecutionFrequency: p.ExecutionFrequency,
  3973. Day: p.Day,
  3974. HisProject: models.HisProject{},
  3975. GoodInfo: models.GoodInfo{},
  3976. Remark: p.Remark,
  3977. Unit: p.Unit,
  3978. Type: p.Type,
  3979. Doctor: p.Doctor,
  3980. ExecutionTime: p.ExecutionTime,
  3981. ExecutionStaff: p.ExecutionStaff,
  3982. ExecutionState: p.ExecutionState,
  3983. CheckTime: p.CheckTime,
  3984. CheckState: p.CheckState,
  3985. Checker: p.Checker,
  3986. StartTime: p.StartTime,
  3987. TeamId: p.TeamId,
  3988. XtHisProjectTeam: models.XtHisProjectTeam{},
  3989. FrequencyType: p.FrequencyType,
  3990. DayCount: p.DayCount,
  3991. WeekDay: p.WeekDay,
  3992. IsCheckTeam: p.IsCheckTeam,
  3993. HisOrderInfo: models.HisOrderInfo{},
  3994. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3995. IsOut: p.IsOut,
  3996. YbSyncStatus: p.YbSyncStatus,
  3997. }
  3998. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3999. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4000. }
  4001. if nowCount == historyCount {
  4002. if historyCount == 0 {
  4003. recordDateStr := time.Now().Format("2006-01-02")
  4004. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4005. nowtime := recordDate.Unix()
  4006. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4007. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4008. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4009. creater := c.GetAdminUserInfo().AdminUser.Id
  4010. dialyPrepareOne := models.DialysisBeforePrepare{
  4011. GoodTypeId: goodObj.GoodTypeId,
  4012. GoodId: p.ProjectId,
  4013. PatientId: p.PatientId,
  4014. RecordDate: p.RecordDate,
  4015. UserOrgId: adminInfo.CurrentOrgId,
  4016. Count: nowCount,
  4017. Ctime: time.Now().Unix(),
  4018. Creater: creater,
  4019. Status: 1,
  4020. StorehouseId: houseConfig.StorehouseOutInfo,
  4021. ProjectId: p.ID,
  4022. }
  4023. //出库
  4024. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4025. }
  4026. }
  4027. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4028. //查询历史出库数据
  4029. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4030. var out_count_five int64
  4031. for _, item := range flowGood {
  4032. out_count_five += item.Count
  4033. }
  4034. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4035. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4036. if out_count_five != parseIntCount {
  4037. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4038. detail := models.AutomaticReduceDetail{
  4039. WarehouseOutId: 0,
  4040. WarehouseOutOrderNumber: "",
  4041. PatientId: p.PatientId,
  4042. Ctime: time.Now().Unix(),
  4043. Mtime: 0,
  4044. Status: 1,
  4045. RecordTime: p.RecordDate,
  4046. OrgId: p.UserOrgId,
  4047. GoodId: p.ProjectId,
  4048. GoodTypeId: 0,
  4049. Count: parseIntCount,
  4050. Type: 0,
  4051. ProjectId: lastHisProject.ID,
  4052. StorehouseId: 0,
  4053. }
  4054. service.CreateNewAutoDetail(detail, tx)
  4055. }
  4056. // //查询耗材最后一次出库记录
  4057. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4058. // //查询默认出库仓库库存
  4059. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4060. // if len(wareOut) > 0 {
  4061. //
  4062. // for _, it := range wareOut {
  4063. // //回退库存
  4064. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4065. //
  4066. // //删除出库记录
  4067. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4068. //
  4069. // }
  4070. // }
  4071. //
  4072. // timeStr := time.Now().Format("2006-01-02")
  4073. // timeArr := strings.Split(timeStr, "-")
  4074. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4075. //
  4076. // total = total + 1
  4077. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4078. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4079. // number = number + total
  4080. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4081. //
  4082. // operation_time := time.Now().Unix()
  4083. // creater := c.GetAdminUserInfo().AdminUser.Id
  4084. //
  4085. // recordDateStr := time.Now().Format("2006-01-02")
  4086. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4087. // nowtime := recordDate.Unix()
  4088. // warehouseOut := models.WarehouseOut{
  4089. // WarehouseOutOrderNumber: warehousing_out_order,
  4090. // OperationTime: operation_time,
  4091. // OrgId: adminInfo.CurrentOrgId,
  4092. // Creater: creater,
  4093. // Ctime: time.Now().Unix(),
  4094. // Status: 1,
  4095. // WarehouseOutTime: nowtime,
  4096. // Type: 1,
  4097. // StorehouseId: storeConfig.StorehouseOutInfo,
  4098. // IsCheck: 1,
  4099. // IsSys: 1,
  4100. // }
  4101. // //查询是否生成出库单
  4102. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4103. // if out.ID == 0 {
  4104. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4105. // }
  4106. //
  4107. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4108. //
  4109. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4110. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4111. //
  4112. // dialyPrepareOne := models.DialysisBeforePrepare{
  4113. // GoodTypeId: goodObj.GoodTypeId,
  4114. // GoodId: p.ProjectId,
  4115. // PatientId: p.PatientId,
  4116. // RecordDate: p.RecordDate,
  4117. // UserOrgId: adminInfo.CurrentOrgId,
  4118. // Count: parseIntCount,
  4119. // Ctime: time.Now().Unix(),
  4120. // Creater: creater,
  4121. // Status: 1,
  4122. // StorehouseId: houseConfig.StorehouseOutInfo,
  4123. // ProjectId: lastHisProject.ID,
  4124. // }
  4125. // //判断是否是零用耗材(非零用)
  4126. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4127. //
  4128. // //查询历史出库数据
  4129. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4130. // var out_count int64
  4131. // for _, item := range flowGood {
  4132. // out_count += item.Count
  4133. // }
  4134. // //如果历史数和当前数据不想等才进行退库出库
  4135. // if out_count != parseIntCount {
  4136. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4137. //
  4138. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4139. // detail := models.AutomaticReduceDetail{
  4140. // WarehouseOutId: 0,
  4141. // WarehouseOutOrderNumber: "",
  4142. // PatientId: p.PatientId,
  4143. // Ctime: time.Now().Unix(),
  4144. // Mtime: 0,
  4145. // Status: 1,
  4146. // RecordTime: p.RecordDate,
  4147. // OrgId: p.UserOrgId,
  4148. // GoodId: p.ProjectId,
  4149. // GoodTypeId: 0,
  4150. // Count: parseIntCount,
  4151. // Type: 0,
  4152. // ProjectId: lastHisProject.ID,
  4153. // StorehouseId: 0,
  4154. // }
  4155. //
  4156. // service.CreateNewAutoDetail(detail, tx)
  4157. //
  4158. // //查询剩余库存
  4159. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4160. // var sum_count int64
  4161. // for _, item := range goodList {
  4162. // sum_count += item.StockCount
  4163. // }
  4164. //
  4165. // //更新剩余库存
  4166. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4167. //
  4168. // //耗材
  4169. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4170. //
  4171. // }
  4172. // //判断是否是零用耗材(零用但是是出库耗材)
  4173. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4174. //
  4175. // //查询历史出库数据
  4176. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4177. // var out_count int64
  4178. // for _, item := range flowGood {
  4179. // out_count += item.Count
  4180. // }
  4181. // //如果历史数和当前数据不想等才进行退库出库
  4182. // if out_count != parseIntCount {
  4183. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4184. //
  4185. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4186. // detail := models.AutomaticReduceDetail{
  4187. // WarehouseOutId: 0,
  4188. // WarehouseOutOrderNumber: "",
  4189. // PatientId: p.PatientId,
  4190. // Ctime: time.Now().Unix(),
  4191. // Mtime: 0,
  4192. // Status: 1,
  4193. // RecordTime: p.RecordDate,
  4194. // OrgId: p.UserOrgId,
  4195. // GoodId: p.ProjectId,
  4196. // GoodTypeId: 0,
  4197. // Count: parseIntCount,
  4198. // Type: 0,
  4199. // ProjectId: p.ID,
  4200. // StorehouseId: 0,
  4201. // }
  4202. //
  4203. // service.CreateNewAutoDetail(detail, tx)
  4204. //
  4205. // //查询剩余库存
  4206. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4207. // var sum_count int64
  4208. // for _, item := range goodList {
  4209. // sum_count += item.StockCount
  4210. // }
  4211. //
  4212. // //更新剩余库存
  4213. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4214. //
  4215. // //耗材
  4216. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4217. // }
  4218. //
  4219. // }
  4220. //
  4221. // }
  4222. //
  4223. //}
  4224. //记录日志
  4225. byterequest, _ := json.Marshal(p)
  4226. adviceLog := models.XtDoctorAdviceLog{
  4227. UserOrgId: p.UserOrgId,
  4228. PatientId: p.PatientId,
  4229. AdminUserId: adminInfo.AdminUser.Id,
  4230. Module: 1,
  4231. ErrLog: string(byterequest),
  4232. Status: 1,
  4233. Ctime: time.Now().Unix(),
  4234. Mtime: 0,
  4235. Source: "电脑端新建his项目",
  4236. RecordDate: p.RecordDate,
  4237. }
  4238. service.CreateDoctorAdviceLog(adviceLog)
  4239. projectList = append(projectList, p)
  4240. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4241. //新增或者编辑项目,修改对应的标签数据
  4242. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4243. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4244. var label models.HisLabelPrintInfo
  4245. project, _ := service.GetProjectDetail(p.ProjectId)
  4246. if project.CostClassify == 3 { //类别为检验检查
  4247. if p.TeamId > 0 { //检验检查组套
  4248. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4249. if tempLabel.ID == 0 {
  4250. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4251. label.Number = tempPrescription.PrescriptionNumber
  4252. label.ProjectId = project.ID
  4253. label.Status = 1
  4254. label.IsPrint = 2
  4255. label.DoctorId = info.DoctorId
  4256. label.UserOrgId = p.UserOrgId
  4257. label.PatientId = patient_id
  4258. label.RecordDate = recordDateTime
  4259. label.Ctime = time.Now().Unix()
  4260. label.Mtime = time.Now().Unix()
  4261. label.ItemId = p.TeamId
  4262. label.FeedetlSn = p.FeedetlSn
  4263. label.PProjectId = p.ID
  4264. label.ProjectName = team.ProjectTeam
  4265. label.PatientName = patient.Name
  4266. service.CreateNewHisLabelRecord(&label, tx)
  4267. }
  4268. } else { //单条检验检查项目
  4269. label.Number = tempPrescription.PrescriptionNumber
  4270. label.ProjectId = project.ID
  4271. label.Status = 1
  4272. label.DoctorId = info.DoctorId
  4273. label.UserOrgId = p.UserOrgId
  4274. label.PatientId = patient_id
  4275. label.RecordDate = recordDateTime
  4276. label.IsPrint = 2
  4277. label.Ctime = time.Now().Unix()
  4278. label.Mtime = time.Now().Unix()
  4279. label.FeedetlSn = p.FeedetlSn
  4280. label.PProjectId = p.ID
  4281. label.ItemId = p.TeamId
  4282. label.ProjectName = project.ProjectName
  4283. label.PatientName = patient.Name
  4284. service.CreateNewHisLabelRecord(&label, tx)
  4285. }
  4286. }
  4287. }
  4288. }
  4289. }
  4290. }
  4291. }
  4292. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  4293. //
  4294. // //耗材出库
  4295. // if p.Type == 3 {
  4296. //
  4297. // //对比当前数据和历史出库数据
  4298. //
  4299. // historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  4300. //
  4301. // historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  4302. //
  4303. // nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4304. //
  4305. // //如果当前处方数量大于历史数据,则需要出库
  4306. // if nowCount > historyCount {
  4307. //
  4308. // var cha_count int64
  4309. // cha_count = nowCount - historyCount
  4310. //
  4311. // timeStr := time.Now().Format("2006-01-02")
  4312. // timeArr := strings.Split(timeStr, "-")
  4313. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4314. //
  4315. // total = total + 1
  4316. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4317. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4318. // number = number + total
  4319. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4320. //
  4321. // operation_time := time.Now().Unix()
  4322. // creater := c.GetAdminUserInfo().AdminUser.Id
  4323. //
  4324. // recordDateStr := time.Now().Format("2006-01-02")
  4325. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4326. // nowtime := recordDate.Unix()
  4327. // warehouseOut := models.WarehouseOut{
  4328. // WarehouseOutOrderNumber: warehousing_out_order,
  4329. // OperationTime: operation_time,
  4330. // OrgId: adminInfo.CurrentOrgId,
  4331. // Creater: creater,
  4332. // Ctime: time.Now().Unix(),
  4333. // Status: 1,
  4334. // WarehouseOutTime: nowtime,
  4335. // Type: 1,
  4336. // StorehouseId: storeConfig.StorehouseOutInfo,
  4337. // IsCheck: 1,
  4338. // IsSys: 1,
  4339. // }
  4340. // //查询是否生成出库单
  4341. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4342. // if out.ID == 0 {
  4343. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4344. // }
  4345. //
  4346. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4347. //
  4348. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4349. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4350. //
  4351. // dialyPrepareOne := models.DialysisBeforePrepare{
  4352. // GoodTypeId: goodObj.GoodTypeId,
  4353. // GoodId: p.ProjectId,
  4354. // PatientId: p.PatientId,
  4355. // RecordDate: p.RecordDate,
  4356. // UserOrgId: adminInfo.CurrentOrgId,
  4357. // Count: cha_count,
  4358. // Ctime: time.Now().Unix(),
  4359. // Creater: creater,
  4360. // Status: 1,
  4361. // StorehouseId: houseConfig.StorehouseOutInfo,
  4362. // ProjectId: p.ID,
  4363. // }
  4364. // //出库
  4365. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4366. //
  4367. // }
  4368. //
  4369. // //如果当前处方数量小于历史数据,怎需要退库
  4370. // if nowCount < historyCount {
  4371. //
  4372. // var cha_count int64
  4373. // cha_count = historyCount - nowCount
  4374. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4375. // creater := c.GetAdminUserInfo().AdminUser.Id
  4376. //
  4377. // newPrescriptionProject := &models.HisPrescriptionProject{
  4378. // ID: p.ID,
  4379. // ProjectId: p.ProjectId,
  4380. // Price: p.Price,
  4381. // UserOrgId: p.UserOrgId,
  4382. // Status: 1,
  4383. // Ctime: time.Now().Unix(),
  4384. // Mtime: time.Now().Unix(),
  4385. // PatientId: p.PatientId,
  4386. // HisPatientId: p.HisPatientId,
  4387. // RecordDate: p.RecordDate,
  4388. // PrescriptionId: p.PrescriptionId,
  4389. // Count: p.Count,
  4390. // FeedetlSn: p.FeedetlSn,
  4391. // MedListCodg: p.MedListCodg,
  4392. // SingleDose: p.SingleDose,
  4393. // DeliveryWay: p.DeliveryWay,
  4394. // ExecutionFrequency: p.ExecutionFrequency,
  4395. // Day: p.Day,
  4396. // HisProject: models.HisProject{},
  4397. // GoodInfo: models.GoodInfo{},
  4398. // Remark: p.Remark,
  4399. // Unit: p.Unit,
  4400. // Type: p.Type,
  4401. // Doctor: p.Doctor,
  4402. // ExecutionTime: p.ExecutionTime,
  4403. // ExecutionStaff: p.ExecutionStaff,
  4404. // ExecutionState: p.ExecutionState,
  4405. // CheckTime: p.CheckTime,
  4406. // CheckState: p.CheckState,
  4407. // Checker: p.Checker,
  4408. // StartTime: p.StartTime,
  4409. // TeamId: p.TeamId,
  4410. // XtHisProjectTeam: models.XtHisProjectTeam{},
  4411. // FrequencyType: p.FrequencyType,
  4412. // DayCount: p.DayCount,
  4413. // WeekDay: p.WeekDay,
  4414. // IsCheckTeam: p.IsCheckTeam,
  4415. // HisOrderInfo: models.HisOrderInfo{},
  4416. // ExecutionFrequencyId: p.ExecutionFrequencyId,
  4417. // IsOut: p.IsOut,
  4418. // YbSyncStatus: p.YbSyncStatus,
  4419. // }
  4420. //
  4421. // service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4422. //
  4423. // service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4424. //
  4425. // }
  4426. //
  4427. // if nowCount == historyCount {
  4428. // if historyCount == 0 {
  4429. // recordDateStr := time.Now().Format("2006-01-02")
  4430. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4431. // nowtime := recordDate.Unix()
  4432. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4433. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4434. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4435. // creater := c.GetAdminUserInfo().AdminUser.Id
  4436. // dialyPrepareOne := models.DialysisBeforePrepare{
  4437. // GoodTypeId: goodObj.GoodTypeId,
  4438. // GoodId: p.ProjectId,
  4439. // PatientId: p.PatientId,
  4440. // RecordDate: p.RecordDate,
  4441. // UserOrgId: adminInfo.CurrentOrgId,
  4442. // Count: nowCount,
  4443. // Ctime: time.Now().Unix(),
  4444. // Creater: creater,
  4445. // Status: 1,
  4446. // StorehouseId: houseConfig.StorehouseOutInfo,
  4447. // ProjectId: p.ID,
  4448. // }
  4449. // //出库
  4450. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4451. // }
  4452. // }
  4453. //
  4454. // lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4455. // //查询历史出库数据
  4456. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4457. //
  4458. // var out_count_five int64
  4459. // for _, item := range flowGood {
  4460. // out_count_five += item.Count
  4461. // }
  4462. // parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4463. //
  4464. // //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4465. // if out_count_five != parseIntCount {
  4466. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4467. // detail := models.AutomaticReduceDetail{
  4468. // WarehouseOutId: 0,
  4469. // WarehouseOutOrderNumber: "",
  4470. // PatientId: p.PatientId,
  4471. // Ctime: time.Now().Unix(),
  4472. // Mtime: 0,
  4473. // Status: 1,
  4474. // RecordTime: p.RecordDate,
  4475. // OrgId: p.UserOrgId,
  4476. // GoodId: p.ProjectId,
  4477. // GoodTypeId: 0,
  4478. // Count: parseIntCount,
  4479. // Type: 0,
  4480. // ProjectId: lastHisProject.ID,
  4481. // StorehouseId: 0,
  4482. // }
  4483. //
  4484. // service.CreateNewAutoDetail(detail, tx)
  4485. // }
  4486. // // //查询耗材最后一次出库记录
  4487. // // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4488. // // //查询默认出库仓库库存
  4489. // // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4490. // // if len(wareOut) > 0 {
  4491. // //
  4492. // // for _, it := range wareOut {
  4493. // // //回退库存
  4494. // // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4495. // //
  4496. // // //删除出库记录
  4497. // // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4498. // //
  4499. // // }
  4500. // // }
  4501. // //
  4502. // // timeStr := time.Now().Format("2006-01-02")
  4503. // // timeArr := strings.Split(timeStr, "-")
  4504. // // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4505. // //
  4506. // // total = total + 1
  4507. // // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4508. // // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4509. // // number = number + total
  4510. // // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4511. // //
  4512. // // operation_time := time.Now().Unix()
  4513. // // creater := c.GetAdminUserInfo().AdminUser.Id
  4514. // //
  4515. // // recordDateStr := time.Now().Format("2006-01-02")
  4516. // // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4517. // // nowtime := recordDate.Unix()
  4518. // // warehouseOut := models.WarehouseOut{
  4519. // // WarehouseOutOrderNumber: warehousing_out_order,
  4520. // // OperationTime: operation_time,
  4521. // // OrgId: adminInfo.CurrentOrgId,
  4522. // // Creater: creater,
  4523. // // Ctime: time.Now().Unix(),
  4524. // // Status: 1,
  4525. // // WarehouseOutTime: nowtime,
  4526. // // Type: 1,
  4527. // // StorehouseId: storeConfig.StorehouseOutInfo,
  4528. // // IsCheck: 1,
  4529. // // IsSys: 1,
  4530. // // }
  4531. // // //查询是否生成出库单
  4532. // // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4533. // // if out.ID == 0 {
  4534. // // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4535. // // }
  4536. // //
  4537. // // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4538. // //
  4539. // // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4540. // // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4541. // //
  4542. // // dialyPrepareOne := models.DialysisBeforePrepare{
  4543. // // GoodTypeId: goodObj.GoodTypeId,
  4544. // // GoodId: p.ProjectId,
  4545. // // PatientId: p.PatientId,
  4546. // // RecordDate: p.RecordDate,
  4547. // // UserOrgId: adminInfo.CurrentOrgId,
  4548. // // Count: parseIntCount,
  4549. // // Ctime: time.Now().Unix(),
  4550. // // Creater: creater,
  4551. // // Status: 1,
  4552. // // StorehouseId: houseConfig.StorehouseOutInfo,
  4553. // // ProjectId: lastHisProject.ID,
  4554. // // }
  4555. // // //判断是否是零用耗材(非零用)
  4556. // // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4557. // //
  4558. // // //查询历史出库数据
  4559. // // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4560. // // var out_count int64
  4561. // // for _, item := range flowGood {
  4562. // // out_count += item.Count
  4563. // // }
  4564. // // //如果历史数和当前数据不想等才进行退库出库
  4565. // // if out_count != parseIntCount {
  4566. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4567. // //
  4568. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4569. // // detail := models.AutomaticReduceDetail{
  4570. // // WarehouseOutId: 0,
  4571. // // WarehouseOutOrderNumber: "",
  4572. // // PatientId: p.PatientId,
  4573. // // Ctime: time.Now().Unix(),
  4574. // // Mtime: 0,
  4575. // // Status: 1,
  4576. // // RecordTime: p.RecordDate,
  4577. // // OrgId: p.UserOrgId,
  4578. // // GoodId: p.ProjectId,
  4579. // // GoodTypeId: 0,
  4580. // // Count: parseIntCount,
  4581. // // Type: 0,
  4582. // // ProjectId: lastHisProject.ID,
  4583. // // StorehouseId: 0,
  4584. // // }
  4585. // //
  4586. // // service.CreateNewAutoDetail(detail, tx)
  4587. // //
  4588. // // //查询剩余库存
  4589. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4590. // // var sum_count int64
  4591. // // for _, item := range goodList {
  4592. // // sum_count += item.StockCount
  4593. // // }
  4594. // //
  4595. // // //更新剩余库存
  4596. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4597. // //
  4598. // // //耗材
  4599. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4600. // //
  4601. // // }
  4602. // // //判断是否是零用耗材(零用但是是出库耗材)
  4603. // // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4604. // //
  4605. // // //查询历史出库数据
  4606. // // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4607. // // var out_count int64
  4608. // // for _, item := range flowGood {
  4609. // // out_count += item.Count
  4610. // // }
  4611. // // //如果历史数和当前数据不想等才进行退库出库
  4612. // // if out_count != parseIntCount {
  4613. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4614. // //
  4615. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4616. // // detail := models.AutomaticReduceDetail{
  4617. // // WarehouseOutId: 0,
  4618. // // WarehouseOutOrderNumber: "",
  4619. // // PatientId: p.PatientId,
  4620. // // Ctime: time.Now().Unix(),
  4621. // // Mtime: 0,
  4622. // // Status: 1,
  4623. // // RecordTime: p.RecordDate,
  4624. // // OrgId: p.UserOrgId,
  4625. // // GoodId: p.ProjectId,
  4626. // // GoodTypeId: 0,
  4627. // // Count: parseIntCount,
  4628. // // Type: 0,
  4629. // // ProjectId: p.ID,
  4630. // // StorehouseId: 0,
  4631. // // }
  4632. // //
  4633. // // service.CreateNewAutoDetail(detail, tx)
  4634. // //
  4635. // // //查询剩余库存
  4636. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4637. // // var sum_count int64
  4638. // // for _, item := range goodList {
  4639. // // sum_count += item.StockCount
  4640. // // }
  4641. // //
  4642. // // //更新剩余库存
  4643. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4644. // //
  4645. // // //耗材
  4646. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4647. // // }
  4648. // //
  4649. // // }
  4650. // //
  4651. // // }
  4652. // //
  4653. // //}
  4654. //
  4655. // //记录日志
  4656. // byterequest, _ := json.Marshal(p)
  4657. // adviceLog := models.XtDoctorAdviceLog{
  4658. // UserOrgId: p.UserOrgId,
  4659. // PatientId: p.PatientId,
  4660. // AdminUserId: adminInfo.AdminUser.Id,
  4661. // Module: 1,
  4662. // ErrLog: string(byterequest),
  4663. // Status: 1,
  4664. // Ctime: time.Now().Unix(),
  4665. // Mtime: 0,
  4666. // Source: "电脑端新建his项目",
  4667. // RecordDate: p.RecordDate,
  4668. // }
  4669. // service.CreateDoctorAdviceLog(adviceLog)
  4670. //
  4671. // projectList = append(projectList, p)
  4672. //
  4673. // if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4674. // //新增或者编辑项目,修改对应的标签数据
  4675. // labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4676. // if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4677. // var label models.HisLabelPrintInfo
  4678. // project, _ := service.GetProjectDetail(p.ProjectId)
  4679. // if project.CostClassify == 3 { //类别为检验检查
  4680. // if p.TeamId > 0 { //检验检查组套
  4681. // tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4682. // if tempLabel.ID == 0 {
  4683. // team, _ := service.GetProjectTeamDetail(p.TeamId)
  4684. // label.Number = tempPrescription.PrescriptionNumber
  4685. // label.ProjectId = project.ID
  4686. // label.Status = 1
  4687. // label.IsPrint = 2
  4688. // label.DoctorId = info.DoctorId
  4689. // label.UserOrgId = p.UserOrgId
  4690. // label.PatientId = patient_id
  4691. // label.RecordDate = recordDateTime
  4692. // label.Ctime = time.Now().Unix()
  4693. // label.Mtime = time.Now().Unix()
  4694. // label.ItemId = p.TeamId
  4695. // label.FeedetlSn = p.FeedetlSn
  4696. // label.PProjectId = p.ID
  4697. // label.ProjectName = team.ProjectTeam
  4698. // label.PatientName = patient.Name
  4699. // service.CreateNewHisLabelRecord(&label, tx)
  4700. // }
  4701. // } else { //单条检验检查项目
  4702. // label.Number = tempPrescription.PrescriptionNumber
  4703. // label.ProjectId = project.ID
  4704. // label.Status = 1
  4705. // label.DoctorId = info.DoctorId
  4706. // label.UserOrgId = p.UserOrgId
  4707. // label.PatientId = patient_id
  4708. // label.RecordDate = recordDateTime
  4709. // label.IsPrint = 2
  4710. // label.Ctime = time.Now().Unix()
  4711. // label.Mtime = time.Now().Unix()
  4712. // label.FeedetlSn = p.FeedetlSn
  4713. // label.PProjectId = p.ID
  4714. // label.ItemId = p.TeamId
  4715. // label.ProjectName = project.ProjectName
  4716. // label.PatientName = patient.Name
  4717. // service.CreateNewHisLabelRecord(&label, tx)
  4718. // }
  4719. // }
  4720. // }
  4721. // }
  4722. //
  4723. // }
  4724. //}
  4725. }
  4726. //插入检验数据
  4727. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4728. //新增或者编辑项目,修改对应的标签数据
  4729. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4730. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4731. var label models.HisLabelPrintInfo
  4732. project, _ := service.GetProjectDetail(p.ProjectId)
  4733. if project.CostClassify == 3 { //类别为检验检查
  4734. if p.TeamId > 0 { //检验检查组套
  4735. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4736. if tempLabel.ID == 0 {
  4737. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4738. label.Number = tempPrescription.PrescriptionNumber
  4739. label.ProjectId = project.ID
  4740. label.Status = 1
  4741. label.IsPrint = 2
  4742. label.DoctorId = info.DoctorId
  4743. label.UserOrgId = p.UserOrgId
  4744. label.PatientId = patient_id
  4745. label.RecordDate = recordDateTime
  4746. label.Ctime = time.Now().Unix()
  4747. label.Mtime = time.Now().Unix()
  4748. label.ItemId = p.TeamId
  4749. label.FeedetlSn = p.FeedetlSn
  4750. label.PProjectId = p.ID
  4751. label.ProjectName = team.ProjectTeam
  4752. label.PatientName = patient.Name
  4753. service.CreateHisLabelRecord(&label)
  4754. }
  4755. } else { //单条检验检查项目
  4756. label.Number = tempPrescription.PrescriptionNumber
  4757. label.ProjectId = project.ID
  4758. label.Status = 1
  4759. label.DoctorId = info.DoctorId
  4760. label.UserOrgId = p.UserOrgId
  4761. label.PatientId = patient_id
  4762. label.RecordDate = recordDateTime
  4763. label.IsPrint = 2
  4764. label.Ctime = time.Now().Unix()
  4765. label.Mtime = time.Now().Unix()
  4766. label.FeedetlSn = p.FeedetlSn
  4767. label.PProjectId = p.ID
  4768. label.ItemId = p.TeamId
  4769. label.ProjectName = project.ProjectName
  4770. label.PatientName = patient.Name
  4771. service.CreateHisLabelRecord(&label)
  4772. }
  4773. }
  4774. }
  4775. }
  4776. service.CreateNewHisProjectTwo(&p, tx)
  4777. var randNum int
  4778. randNum = rand.Intn(10000) + 1000
  4779. timestamp := time.Now().Unix()
  4780. tempTime := time.Unix(timestamp, 0)
  4781. timeFormat := tempTime.Format("20060102150405")
  4782. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4783. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4784. if goodBase.ID > 0 {
  4785. tx.Rollback()
  4786. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4787. return
  4788. }
  4789. service.CreateNewHisProjectTwo(&p, tx)
  4790. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4791. //查询剩余库存
  4792. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4793. var sum_count int64
  4794. for _, item := range goodList {
  4795. sum_count += item.StockCount
  4796. }
  4797. //更新剩余库存
  4798. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4799. //耗材
  4800. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4801. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4802. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4803. if len(outInfoTwo) > 0 {
  4804. for _, item := range outInfoTwo {
  4805. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4806. }
  4807. }
  4808. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4809. if len(drugAutoDetail) > 0 {
  4810. for _, item := range drugAutoDetail {
  4811. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4812. }
  4813. }
  4814. tx.Commit()
  4815. }
  4816. }
  4817. }
  4818. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4819. // addition := items["addition"].([]interface{})
  4820. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4821. // ctime := time.Now().Unix()
  4822. // mtime := ctime
  4823. // if len(addition) > 0 {
  4824. // for _, item := range addition {
  4825. // var s models.HisAdditionalCharge
  4826. // s.PrescriptionId = tempPrescription.ID
  4827. // s.Status = 1
  4828. // s.UserOrgId = adminInfo.CurrentOrgId
  4829. // s.RecordDate = recordDateTime
  4830. // s.CreatedTime = ctime
  4831. // s.UpdatedTime = mtime
  4832. // s.PatientId = patient_id
  4833. // s.HisPatientId = his_patient_id
  4834. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4835. // if errcode > 0 {
  4836. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4837. // return
  4838. // }
  4839. // service.CreateAdditionalCharge(&s)
  4840. // var randNum int
  4841. // randNum = rand.Intn(10000) + 1000
  4842. // timestamp := time.Now().Unix()
  4843. // tempTime := time.Unix(timestamp, 0)
  4844. // timeFormat := tempTime.Format("20060102150405")
  4845. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4846. // service.CreateAdditionalCharge(&s)
  4847. //
  4848. // }
  4849. // }
  4850. //}
  4851. }
  4852. }
  4853. }
  4854. tx.Commit()
  4855. if err == nil {
  4856. c.ServeSuccessJSON(map[string]interface{}{
  4857. "msg": "保存成功",
  4858. })
  4859. return
  4860. } else {
  4861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4862. return
  4863. }
  4864. } else {
  4865. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4866. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4867. var tempPrescription *models.HisPrescription
  4868. if len(prescriptions) > 0 {
  4869. for _, item := range prescriptions {
  4870. items := item.(map[string]interface{})
  4871. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4872. utils.ErrorLog("id")
  4873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4874. return
  4875. }
  4876. id := int64(items["id"].(float64))
  4877. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4878. tempPrescription = &new_prescription
  4879. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4880. utils.ErrorLog("type")
  4881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4882. return
  4883. }
  4884. types := int64(items["type"].(float64))
  4885. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4886. utils.ErrorLog("med_type")
  4887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4888. return
  4889. }
  4890. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4891. if med_type == "0" {
  4892. med_type = "14"
  4893. }
  4894. //if order_status == 0 {
  4895. // order_status = 1
  4896. //}
  4897. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4898. // utils.ErrorLog("diagnoses")
  4899. //}
  4900. diagnoses, _ := items["diagnoses"].(string)
  4901. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4902. utils.ErrorLog("pre_time")
  4903. }
  4904. preTime, _ := items["pre_time"].(string)
  4905. timeLayout := "2006-01-02"
  4906. loc, _ := time.LoadLocation("Local")
  4907. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4908. //result := strings.Split(preTime, " ")
  4909. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4910. if err != nil {
  4911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4912. return
  4913. }
  4914. pTime := theTime2.Unix()
  4915. ctime := time.Now().Unix()
  4916. if tempPrescription.ID == 0 {
  4917. prescription := &models.HisPrescription{
  4918. ID: 0,
  4919. PatientId: patient_id,
  4920. UserOrgId: adminInfo.CurrentOrgId,
  4921. RecordDate: recordDateTime,
  4922. Ctime: ctime,
  4923. Mtime: ctime,
  4924. Type: types,
  4925. Modifier: adminInfo.AdminUser.Id,
  4926. Creator: adminInfo.AdminUser.Id,
  4927. Status: 1,
  4928. Doctor: role.UserName,
  4929. HisPatientId: his_patient_id,
  4930. OrderStatus: 1,
  4931. BatchNumber: "",
  4932. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4933. PreTime: pTime,
  4934. PType: p_type,
  4935. MedType: med_type,
  4936. Diagnose: diagnoses,
  4937. }
  4938. tempPrescription = prescription
  4939. service.SaveHisPrescription(tempPrescription)
  4940. redis := service.RedisClient()
  4941. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4942. redis.Set(key, "", time.Second)
  4943. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4944. redis.Set(keyOne, "", time.Second)
  4945. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4946. redis.Set(keySeven, "", time.Second)
  4947. defer redis.Close()
  4948. } else {
  4949. tempPrescription.ID = id
  4950. tempPrescription.Type = types
  4951. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4952. tempPrescription.Mtime = time.Now().Unix()
  4953. tempPrescription.Doctor = role.UserName
  4954. //tempPrescription.OrderStatus = order_status
  4955. tempPrescription.PreTime = pTime
  4956. tempPrescription.MedType = med_type
  4957. tempPrescription.Diagnose = diagnoses
  4958. service.SaveHisPrescription(tempPrescription)
  4959. redis := service.RedisClient()
  4960. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4961. redis.Set(key, "", time.Second)
  4962. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4963. redis.Set(keyOne, "", time.Second)
  4964. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4965. redis.Set(keySeven, "", time.Second)
  4966. defer redis.Close()
  4967. }
  4968. //service.SaveHisPrescription(prescription)
  4969. //更改患者挂号状态
  4970. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4971. fmt.Println("更改失败", err2)
  4972. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4973. advices := items["advices"].([]interface{})
  4974. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4975. groupNo := int64(0)
  4976. if len(advices) > 0 {
  4977. for _, advice := range advices {
  4978. var s models.HisDoctorAdviceInfo
  4979. s.PrescriptionId = tempPrescription.ID
  4980. s.AdviceType = 2
  4981. s.AdviceDoctor = doctor_id
  4982. s.StopState = 2
  4983. s.ExecutionState = 2
  4984. s.AdviceDate = theTime3.Unix()
  4985. s.Status = 1
  4986. s.UserOrgId = adminInfo.CurrentOrgId
  4987. s.RecordDate = theTime3.Unix()
  4988. s.StartTime = tempPrescription.PreTime
  4989. s.Groupno = groupNo
  4990. s.PatientId = patient_id
  4991. s.HisPatientId = his_patient_id
  4992. s.StartTime = pTime
  4993. s.IsSettle = 2
  4994. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4995. if errcode > 0 {
  4996. c.ServeFailJSONWithSGJErrorCode(errcode)
  4997. return
  4998. }
  4999. s.StartTime = pTime
  5000. var total_count int64 //处方总库存
  5001. //查询改药品信息
  5002. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  5003. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  5004. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5005. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5006. total_count += prescribingNumberSeven * medical.MinNumber
  5007. }
  5008. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5009. total_count += prescribingNumberSeven
  5010. }
  5011. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  5012. total_count += prescribingNumberSeven
  5013. }
  5014. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5015. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5016. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5017. if s.Price != lastWarehouse.RetailPrice {
  5018. s.Price = lastWarehouse.RetailPrice
  5019. }
  5020. if s.Price == 0 {
  5021. if lastWarehouse.ID == 0 {
  5022. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  5023. s.Price = lastWarehouseTwo.RetailPrice
  5024. }
  5025. }
  5026. }
  5027. if adminInfo.CurrentOrgId != 10206 {
  5028. if s.ID == 0 {
  5029. //查询改药品是否已经停用
  5030. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  5031. if base.ID > 0 {
  5032. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  5033. return
  5034. }
  5035. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  5036. if drugMedical.SumCount == 0 {
  5037. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  5038. return
  5039. }
  5040. }
  5041. }
  5042. //赤峰
  5043. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  5044. drug, _ := service.GetDrugByGoodId(s.DrugId)
  5045. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  5046. if info.RetailPrice > 0 {
  5047. if s.DeliveryWay == "口服" {
  5048. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5049. s.Price = drug.RetailPrice
  5050. }
  5051. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5052. s.Price = info.RetailPrice
  5053. }
  5054. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5055. s.Price = info.RetailPrice
  5056. }
  5057. }
  5058. }
  5059. }
  5060. service.CreateHisDoctorAdvice(&s)
  5061. //记录日志
  5062. byterequest, _ := json.Marshal(s)
  5063. adviceLog := models.XtDoctorAdviceLog{
  5064. UserOrgId: s.UserOrgId,
  5065. PatientId: s.PatientId,
  5066. AdminUserId: adminInfo.AdminUser.Id,
  5067. Module: 1,
  5068. ErrLog: string(byterequest),
  5069. Status: 1,
  5070. Ctime: time.Now().Unix(),
  5071. Mtime: 0,
  5072. Source: "电脑端新建his医嘱",
  5073. RecordDate: s.AdviceDate,
  5074. }
  5075. service.CreateDoctorAdviceLog(adviceLog)
  5076. //存储切片中
  5077. adviceList = append(adviceList, s)
  5078. redis := service.RedisClient()
  5079. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5080. redis.Set(key, "", time.Second)
  5081. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5082. redis.Set(keyOne, "", time.Second)
  5083. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5084. redis.Set(keySeven, "", time.Second)
  5085. var randNum int
  5086. randNum = rand.Intn(10000) + 1000
  5087. timestamp := time.Now().Unix()
  5088. tempTime := time.Unix(timestamp, 0)
  5089. timeFormat := tempTime.Format("20060102150405")
  5090. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  5091. service.CreateHisDoctorAdvice(&s)
  5092. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5093. redis.Set(keySix, "", time.Second)
  5094. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5095. redis.Set(keyFive, "", time.Second)
  5096. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5097. redis.Set(keyEight, "", time.Second)
  5098. defer redis.Close()
  5099. }
  5100. }
  5101. }
  5102. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5103. projects := items["project"].([]interface{})
  5104. if len(projects) > 0 {
  5105. for _, project := range projects {
  5106. var p models.HisPrescriptionProject
  5107. p.PrescriptionId = tempPrescription.ID
  5108. p.PatientId = patient_id
  5109. p.RecordDate = theTime3.Unix()
  5110. p.Doctor = doctor_id
  5111. p.UserOrgId = adminInfo.CurrentOrgId
  5112. p.HisPatientId = his_patient_id
  5113. p.Status = 1
  5114. p.StartTime = pTime
  5115. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  5116. if errcode > 0 {
  5117. c.ServeFailJSONWithSGJErrorCode(errcode)
  5118. return
  5119. }
  5120. if p.ID == 0 {
  5121. p.IsOut = 2
  5122. }
  5123. if p.ID > 0 {
  5124. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  5125. p.IsOut = projectDetail.IsOut
  5126. }
  5127. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5128. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5129. if p.Type == 3 {
  5130. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  5131. if p.Price != lastWarehouse.PackingPrice {
  5132. p.Price = lastWarehouse.PackingPrice
  5133. }
  5134. if p.Price == 0 {
  5135. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  5136. p.Price = lastWarehouseTwo.PackingPrice
  5137. }
  5138. if p.Unit == "" {
  5139. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5140. p.Unit = goodInfoOne.PackingUnit
  5141. }
  5142. }
  5143. }
  5144. if adminInfo.CurrentOrgId != 10206 {
  5145. if p.Type == 3 {
  5146. if p.ID == 0 {
  5147. //查询该耗材是否停用
  5148. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  5149. //表示该耗材已经停用,不能保存
  5150. if goodInfoSeven.ID == 0 {
  5151. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5152. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  5153. return
  5154. }
  5155. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5156. if goodInfoOne.SumCount == 0 {
  5157. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  5158. return
  5159. }
  5160. }
  5161. }
  5162. }
  5163. service.CreateHisProjectTwo(&p)
  5164. //记录日志
  5165. byterequest, _ := json.Marshal(p)
  5166. adviceLog := models.XtDoctorAdviceLog{
  5167. UserOrgId: p.UserOrgId,
  5168. PatientId: p.PatientId,
  5169. AdminUserId: adminInfo.AdminUser.Id,
  5170. Module: 1,
  5171. ErrLog: string(byterequest),
  5172. Status: 1,
  5173. Ctime: time.Now().Unix(),
  5174. Mtime: 0,
  5175. Source: "电脑端新建his项目",
  5176. RecordDate: p.RecordDate,
  5177. }
  5178. service.CreateDoctorAdviceLog(adviceLog)
  5179. projectList = append(projectList, p)
  5180. var randNum int
  5181. randNum = rand.Intn(10000) + 1000
  5182. timestamp := time.Now().Unix()
  5183. tempTime := time.Unix(timestamp, 0)
  5184. timeFormat := tempTime.Format("20060102150405")
  5185. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  5186. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  5187. //新增或者编辑项目,修改对应的标签数据
  5188. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  5189. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  5190. var label models.HisLabelPrintInfo
  5191. project, _ := service.GetProjectDetail(p.ProjectId)
  5192. if project.CostClassify == 3 { //类别为检验检查
  5193. if p.TeamId > 0 { //检验检查组套
  5194. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  5195. if tempLabel.ID == 0 {
  5196. team, _ := service.GetProjectTeamDetail(p.TeamId)
  5197. label.Number = tempPrescription.PrescriptionNumber
  5198. label.ProjectId = project.ID
  5199. label.Status = 1
  5200. label.IsPrint = 2
  5201. label.DoctorId = info.DoctorId
  5202. label.UserOrgId = p.UserOrgId
  5203. label.PatientId = patient_id
  5204. label.RecordDate = recordDateTime
  5205. label.Ctime = time.Now().Unix()
  5206. label.Mtime = time.Now().Unix()
  5207. label.ItemId = p.TeamId
  5208. label.FeedetlSn = p.FeedetlSn
  5209. label.PProjectId = p.ID
  5210. label.ProjectName = team.ProjectTeam
  5211. label.PatientName = patient.Name
  5212. service.CreateHisLabelRecord(&label)
  5213. }
  5214. } else { //单条检验检查项目
  5215. label.Number = tempPrescription.PrescriptionNumber
  5216. label.ProjectId = project.ID
  5217. label.Status = 1
  5218. label.DoctorId = info.DoctorId
  5219. label.UserOrgId = p.UserOrgId
  5220. label.PatientId = patient_id
  5221. label.RecordDate = recordDateTime
  5222. label.IsPrint = 2
  5223. label.Ctime = time.Now().Unix()
  5224. label.Mtime = time.Now().Unix()
  5225. label.FeedetlSn = p.FeedetlSn
  5226. label.PProjectId = p.ID
  5227. label.ItemId = p.TeamId
  5228. label.ProjectName = project.ProjectName
  5229. label.PatientName = patient.Name
  5230. service.CreateHisLabelRecord(&label)
  5231. }
  5232. }
  5233. }
  5234. }
  5235. service.SaveHisProjectTwo(&p)
  5236. }
  5237. }
  5238. }
  5239. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5240. // addition := items["addition"].([]interface{})
  5241. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5242. // ctime := time.Now().Unix()
  5243. // mtime := ctime
  5244. // if len(addition) > 0 {
  5245. // for _, item := range addition {
  5246. // var s models.HisAdditionalCharge
  5247. // s.PrescriptionId = tempPrescription.ID
  5248. // s.Status = 1
  5249. // s.UserOrgId = adminInfo.CurrentOrgId
  5250. // s.RecordDate = recordDateTime
  5251. // s.CreatedTime = ctime
  5252. // s.UpdatedTime = mtime
  5253. // s.PatientId = patient_id
  5254. // s.HisPatientId = his_patient_id
  5255. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5256. // if errcode > 0 {
  5257. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5258. // return
  5259. // }
  5260. // service.CreateAdditionalCharge(&s)
  5261. // var randNum int
  5262. // randNum = rand.Intn(10000) + 1000
  5263. // timestamp := time.Now().Unix()
  5264. // tempTime := time.Unix(timestamp, 0)
  5265. // timeFormat := tempTime.Format("20060102150405")
  5266. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  5267. // service.CreateAdditionalCharge(&s)
  5268. //
  5269. // }
  5270. // }
  5271. //}
  5272. }
  5273. }
  5274. //查询今日该患者开的药品处方
  5275. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5276. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  5277. //药品出库
  5278. if drugOutConfig.IsOpen == 1 {
  5279. for _, item := range hisdoctorlist {
  5280. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  5281. // 查询该药品最后一次出库记录
  5282. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  5283. if len(druginfo) > 0 {
  5284. //回退库存
  5285. for _, it := range druginfo {
  5286. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5287. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5288. }
  5289. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5290. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5291. }
  5292. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5293. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5294. }
  5295. }
  5296. }
  5297. //删除记录
  5298. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  5299. //查询最后一次数据
  5300. if drugOutConfig.IsOpen == 1 {
  5301. //出库
  5302. if drug.IsUse == 2 {
  5303. creater := adminInfo.AdminUser.Id
  5304. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  5305. }
  5306. //更新字典里面的库存
  5307. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5308. var sum_count int64
  5309. for _, its := range stockInfo {
  5310. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5311. if its.MaxUnit == baseDrug.MaxUnit {
  5312. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5313. }
  5314. sum_count += its.StockMaxNumber + its.StockMinNumber
  5315. }
  5316. //更新基础库存
  5317. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5318. //剩余库存
  5319. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  5320. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  5321. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  5322. }
  5323. }
  5324. }
  5325. fmt.Println("耗材----------------------------------", goodOutConfig.IsOpen)
  5326. //耗材保存处方出库
  5327. if goodOutConfig.IsOpen == 1 {
  5328. //查询今日耗材出库数量
  5329. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5330. for _, item := range hisgoodlist {
  5331. //查询历史出库数据
  5332. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5333. var out_count_five int64
  5334. for _, item := range flowGood {
  5335. out_count_five += item.Count
  5336. }
  5337. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  5338. fmt.Println("out_count_five-------------------", out_count_five)
  5339. fmt.Println("parseIntCount---------------", parseIntCount)
  5340. if out_count_five != parseIntCount {
  5341. //查询耗材最后一次出库记录
  5342. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  5343. //查询默认出库仓库库存
  5344. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5345. if len(wareOut) > 0 {
  5346. for _, it := range wareOut {
  5347. //回退库存
  5348. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  5349. //删除出库记录
  5350. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  5351. }
  5352. }
  5353. timeStr := time.Now().Format("2006-01-02")
  5354. timeArr := strings.Split(timeStr, "-")
  5355. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  5356. total = total + 1
  5357. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5358. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5359. number = number + total
  5360. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5361. operation_time := time.Now().Unix()
  5362. creater := c.GetAdminUserInfo().AdminUser.Id
  5363. recordDateStr := time.Now().Format("2006-01-02")
  5364. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5365. nowtime := recordDate.Unix()
  5366. warehouseOut := models.WarehouseOut{
  5367. WarehouseOutOrderNumber: warehousing_out_order,
  5368. OperationTime: operation_time,
  5369. OrgId: adminInfo.CurrentOrgId,
  5370. Creater: creater,
  5371. Ctime: time.Now().Unix(),
  5372. Status: 1,
  5373. WarehouseOutTime: nowtime,
  5374. Type: 1,
  5375. StorehouseId: storeConfig.StorehouseOutInfo,
  5376. IsCheck: 1,
  5377. IsSys: 1,
  5378. }
  5379. //查询是否生成出库单
  5380. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5381. if out.ID == 0 {
  5382. service.AddSigleWarehouseOutOne(&warehouseOut)
  5383. }
  5384. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5385. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5386. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5387. dialyPrepareOne := models.DialysisBeforePrepare{
  5388. GoodTypeId: goodObj.GoodTypeId,
  5389. GoodId: item.ProjectId,
  5390. PatientId: item.PatientId,
  5391. RecordDate: item.RecordDate,
  5392. UserOrgId: adminInfo.CurrentOrgId,
  5393. Count: parseIntCount,
  5394. Ctime: time.Now().Unix(),
  5395. Creater: creater,
  5396. Status: 1,
  5397. StorehouseId: houseConfig.StorehouseOutInfo,
  5398. ProjectId: item.ID,
  5399. }
  5400. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5401. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5402. //查询历史出库数据
  5403. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5404. var out_count int64
  5405. for _, item := range flowGood {
  5406. out_count += item.Count
  5407. }
  5408. //如果历史数和当前数据不想等才进行退库出库
  5409. if out_count != parseIntCount {
  5410. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5411. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5412. detail := models.AutomaticReduceDetail{
  5413. WarehouseOutId: 0,
  5414. WarehouseOutOrderNumber: "",
  5415. PatientId: item.PatientId,
  5416. Ctime: time.Now().Unix(),
  5417. Mtime: 0,
  5418. Status: 1,
  5419. RecordTime: item.RecordDate,
  5420. OrgId: item.UserOrgId,
  5421. GoodId: item.ProjectId,
  5422. GoodTypeId: 0,
  5423. Count: parseIntCount,
  5424. Type: 0,
  5425. ProjectId: item.ID,
  5426. StorehouseId: 0,
  5427. }
  5428. service.CreateAutoDetail(detail)
  5429. //查询剩余库存
  5430. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5431. var sum_count int64
  5432. for _, item := range goodList {
  5433. sum_count += item.StockCount
  5434. }
  5435. //更新剩余库存
  5436. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5437. //耗材
  5438. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5439. }
  5440. }
  5441. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5442. //查询历史出库数据
  5443. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5444. var out_count int64
  5445. for _, item := range flowGood {
  5446. out_count += item.Count
  5447. }
  5448. //如果历史数和当前数据不想等才进行退库出库
  5449. if out_count != parseIntCount {
  5450. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5451. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5452. detail := models.AutomaticReduceDetail{
  5453. WarehouseOutId: 0,
  5454. WarehouseOutOrderNumber: "",
  5455. PatientId: item.PatientId,
  5456. Ctime: time.Now().Unix(),
  5457. Mtime: 0,
  5458. Status: 1,
  5459. RecordTime: item.RecordDate,
  5460. OrgId: item.UserOrgId,
  5461. GoodId: item.ProjectId,
  5462. GoodTypeId: 0,
  5463. Count: parseIntCount,
  5464. Type: 0,
  5465. ProjectId: item.ID,
  5466. StorehouseId: 0,
  5467. }
  5468. service.CreateAutoDetail(detail)
  5469. //查询剩余库存
  5470. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5471. var sum_count int64
  5472. for _, item := range goodList {
  5473. sum_count += item.StockCount
  5474. }
  5475. //更新剩余库存
  5476. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5477. //耗材
  5478. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5479. }
  5480. }
  5481. }
  5482. }
  5483. }
  5484. ////同步到自备药
  5485. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5486. if selfPrescriptionOpen.IsOpen == 1 {
  5487. timeStr := time.Now().Format("2006-01-02")
  5488. timeArr := strings.Split(timeStr, "-")
  5489. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5490. total = total + 1
  5491. operation_time := time.Now().Unix()
  5492. creater := adminInfo.AdminUser.Id
  5493. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5494. warehousing := models.XtSelfDrugWarehouse{
  5495. WarehousingOrder: warehousing_order,
  5496. OperationTime: operation_time,
  5497. OrgId: adminInfo.CurrentOrgId,
  5498. Creater: creater,
  5499. Ctime: time.Now().Unix(),
  5500. Status: 1,
  5501. WarehousingTime: recordDateTime,
  5502. Type: 0,
  5503. StorehouseId: 0,
  5504. IsCheck: 1,
  5505. PatientId: patient_id,
  5506. IsSys: 1,
  5507. }
  5508. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5509. if selfDrugWarehouse.ID == 0 {
  5510. service.AddSelfDrugWarehouse(&warehousing, tx)
  5511. }
  5512. if selfDrugWarehouse.ID > 0 {
  5513. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5514. }
  5515. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5516. fmt.Println(info)
  5517. for _, item := range hisdoctorlist {
  5518. //查询该病人的该药品是否已经入库
  5519. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5520. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5521. var in_count int64
  5522. if len(selfdruginfo) > 0 {
  5523. for _, item := range selfdruginfo {
  5524. var in_count_one int64
  5525. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5526. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5527. }
  5528. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5529. in_count_one = item.WarehousingCount
  5530. }
  5531. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5532. in_count_one = item.WarehousingCount
  5533. }
  5534. in_count += in_count_one
  5535. }
  5536. }
  5537. if selfBasedrug.IsSelfDrug == 1 {
  5538. var total_count int64
  5539. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5540. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5541. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5542. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5543. }
  5544. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5545. total_count += prescribingNumberSeven
  5546. }
  5547. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5548. total_count += prescribingNumberSeven
  5549. }
  5550. //入库
  5551. if total_count > in_count {
  5552. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5553. WarehousingOrder: warehousing_order,
  5554. WarehousingId: info.ID,
  5555. DrugId: item.DrugId,
  5556. Number: "",
  5557. ProductDate: 0,
  5558. ExpiryDate: 0,
  5559. WarehousingCount: total_count - in_count,
  5560. WarehouseingUnit: selfBasedrug.MinUnit,
  5561. Price: 0,
  5562. TotalPrice: 0,
  5563. Status: 1,
  5564. Ctime: time.Now().Unix(),
  5565. Remark: "",
  5566. OrgId: adminInfo.CurrentOrgId,
  5567. Type: 0,
  5568. Manufacturer: selfBasedrug.Manufacturer,
  5569. Dealer: selfBasedrug.Dealer,
  5570. StockMaxNumber: total_count - in_count,
  5571. RetailTotalPrice: 0,
  5572. BatchNumber: "",
  5573. MaxUnit: selfBasedrug.MinUnit,
  5574. MinUnit: selfBasedrug.MinUnit,
  5575. RetailPrice: 0,
  5576. StorehouseId: 0,
  5577. IsCheck: 1,
  5578. StockMinNumber: 0,
  5579. PatientId: patient_id,
  5580. IsSys: 1,
  5581. RecordDate: item.RecordDate,
  5582. AdviceId: item.ID,
  5583. }
  5584. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5585. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5586. Creator := adminInfo.AdminUser.Id
  5587. //查询默认仓库剩余多少库存
  5588. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5589. var sum_count int64
  5590. for _, it := range list {
  5591. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5592. if it.MaxUnit == baseDrug.MaxUnit {
  5593. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5594. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5595. }
  5596. sum_count += it.StockMaxNumber + it.StockMinNumber
  5597. }
  5598. flow := &models.XtSelfDrugFlow{
  5599. WarehousingId: info.ID,
  5600. DrugId: item.DrugId,
  5601. Number: "",
  5602. BatchNumber: "",
  5603. Count: total_count - in_count,
  5604. UserOrgId: adminInfo.CurrentOrgId,
  5605. PatientId: item.PatientId,
  5606. SystemTime: time.Now().Unix(),
  5607. ConsumableType: 1,
  5608. IsSys: 1,
  5609. WarehousingOrder: warehousing_order,
  5610. WarehouseOutId: 0,
  5611. WarehouseOutOrderNumber: "",
  5612. IsEdit: 0,
  5613. CancelStockId: 0,
  5614. CancelOrderNumber: "",
  5615. Manufacturer: selfBasedrug.Manufacturer,
  5616. Dealer: selfBasedrug.Dealer,
  5617. Creator: Creator,
  5618. UpdateCreator: Creator,
  5619. Status: 1,
  5620. Ctime: item.AdviceDate,
  5621. Mtime: 0,
  5622. Price: item.Price,
  5623. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5624. WarehouseOutDetailId: 0,
  5625. CancelOutDetailId: 0,
  5626. ExpireDate: 0,
  5627. ProductDate: 0,
  5628. MaxUnit: selfBasedrug.MinUnit,
  5629. MinUnit: selfBasedrug.MinUnit,
  5630. StorehouseId: 0,
  5631. OverCount: sum_count,
  5632. OperateTime: time.Now().Unix(),
  5633. AdviceId: item.ID,
  5634. }
  5635. service.CreateSelfDrugFlow(flow, tx)
  5636. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5637. var total_count int64 // 入库总数量
  5638. var over_count int64 //剩余库存
  5639. for _, it := range drugInfolist {
  5640. if it.MaxUnit == selfBasedrug.MaxUnit {
  5641. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5642. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5643. }
  5644. }
  5645. for _, it := range drugInfolist {
  5646. total_count += it.WarehousingCount
  5647. over_count += it.StockMaxNumber + it.StockMinNumber
  5648. }
  5649. //查询该仓库是否有默认数据
  5650. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5651. if selfDrugStock.ID == 0 {
  5652. drugStock := models.XtSelfDrugStockCount{
  5653. UserOrgId: item.UserOrgId,
  5654. PatientId: item.PatientId,
  5655. SumInCount: total_count,
  5656. SumOutCount: 0,
  5657. SumCancelCount: 0,
  5658. DrugId: item.DrugId,
  5659. Ctime: time.Now().Unix(),
  5660. Mtime: 0,
  5661. Status: 1,
  5662. FlushCount: over_count,
  5663. SumActOutCount: 0,
  5664. }
  5665. service.CreateSelfDrugStockSum(drugStock, tx)
  5666. }
  5667. if selfDrugStock.ID > 0 {
  5668. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5669. }
  5670. }
  5671. //查询这个单据的出库数量
  5672. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5673. var his_out_count int64
  5674. for _, item := range drugFlowList {
  5675. his_out_count += item.Count
  5676. }
  5677. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5678. if (total_count + his_out_count) <= in_count {
  5679. // 出库
  5680. if total_count < in_count {
  5681. var cha_count int64
  5682. cha_count = in_count - total_count
  5683. var stock_number int64 = 0
  5684. //查询库存是否充足
  5685. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5686. // 将该批次的剩余库存数量转换为拆零数量
  5687. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5688. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5689. }
  5690. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5691. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5692. }
  5693. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5694. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5695. }
  5696. if stock_number >= cha_count {
  5697. var maxNumber int64 = 0
  5698. var minNumber int64 = 0
  5699. maxNumber = cha_count / selfBasedrug.MinNumber
  5700. minNumber = cha_count % selfBasedrug.MinNumber
  5701. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5702. minNumber = maxNumber
  5703. }
  5704. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5705. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5707. return
  5708. }
  5709. }
  5710. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5711. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5712. }
  5713. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5714. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5715. }
  5716. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5717. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5718. }
  5719. if warehouse.StockMaxNumber < 0 {
  5720. warehouse.StockMaxNumber = 0
  5721. }
  5722. if warehouse.StockMinNumber < 0 {
  5723. warehouse.StockMinNumber = 0
  5724. }
  5725. warehouse.Mtime = time.Now().Unix()
  5726. if warehouse.StockMinNumber < minNumber {
  5727. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5728. if warehouse.MaxUnit != warehouse.MinUnit {
  5729. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5730. }
  5731. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5732. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5733. }
  5734. } else {
  5735. if minNumber > 0 {
  5736. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5737. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5738. }
  5739. }
  5740. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5741. if warehouse.StockMinNumber > 0 {
  5742. if warehouse.StockMinNumber-cha_count >= 0 {
  5743. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5744. }
  5745. }
  5746. }
  5747. }
  5748. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5749. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5750. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5751. }
  5752. }
  5753. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5754. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5756. return
  5757. }
  5758. }
  5759. if warehouse.StockMinNumber <= 0 {
  5760. warehouse.StockMinNumber = 0
  5761. }
  5762. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5763. //查询该药品剩余库存
  5764. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5765. var over_count int64
  5766. for _, its := range infolist {
  5767. if its.MaxUnit == selfBasedrug.MaxUnit {
  5768. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5769. }
  5770. over_count += its.StockMaxNumber + its.StockMinNumber
  5771. }
  5772. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5773. drugflow := models.XtSelfDrugFlow{
  5774. WarehouseOutId: 0,
  5775. WarehouseOutOrderNumber: warehousing_order,
  5776. WarehousingOrder: warehousing_order,
  5777. DrugId: item.DrugId,
  5778. Number: warehouse.Number,
  5779. ProductDate: warehouse.ProductDate,
  5780. ExpireDate: warehouse.ExpiryDate,
  5781. Count: cha_count,
  5782. Price: warehouse.RetailPrice,
  5783. Status: 1,
  5784. Ctime: item.AdviceDate,
  5785. Mtime: time.Now().Unix(),
  5786. UserOrgId: item.UserOrgId,
  5787. Manufacturer: warehouse.Manufacturer,
  5788. Dealer: warehouse.Dealer,
  5789. BatchNumber: warehouse.BatchNumber,
  5790. MaxUnit: selfBasedrug.MinUnit,
  5791. ConsumableType: 20,
  5792. IsEdit: 1,
  5793. Creator: 0,
  5794. IsSys: 3,
  5795. WarehouseOutDetailId: drugWareInfo.ID,
  5796. AdviceId: item.ID,
  5797. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5798. StorehouseId: 0,
  5799. AdminUserId: creater,
  5800. LastPrice: warehouse.Price,
  5801. StockCount: "",
  5802. WarehousingDetailId: 0,
  5803. OverCount: over_count,
  5804. RetailPrice: item.Price, //手动出库出库价格
  5805. WarehousingId: warehouse.ID,
  5806. SystemTime: item.AdviceDate,
  5807. PatientId: item.PatientId,
  5808. Remark: "保存处方入库数据差",
  5809. OperateTime: time.Now().Unix(),
  5810. }
  5811. if warehouse.RetailPrice == 0 {
  5812. drugflow.Price = item.Price
  5813. }
  5814. service.CreateSelfDrugFlowOne(drugflow, tx)
  5815. var out_count int64
  5816. out_count = in_count - total_count
  5817. //
  5818. //fmt.Println("in_count------------------", in_count)
  5819. //fmt.Println("total_count------------------", total_count)
  5820. //添加出库数量
  5821. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5822. //查询剩余库存
  5823. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5824. var sum_count int64
  5825. for _, its := range stockInfo {
  5826. if its.MaxUnit == selfBasedrug.MaxUnit {
  5827. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5828. }
  5829. sum_count += its.StockMaxNumber + its.StockMinNumber
  5830. }
  5831. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5832. } else {
  5833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5834. return
  5835. }
  5836. }
  5837. }
  5838. }
  5839. }
  5840. }
  5841. }
  5842. tx.Commit()
  5843. if err == nil {
  5844. c.ServeSuccessJSON(map[string]interface{}{
  5845. "msg": "保存成功",
  5846. })
  5847. return
  5848. } else {
  5849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5850. return
  5851. }
  5852. }
  5853. }
  5854. //func (c *HisApiController) EditHisPrescription() {
  5855. // record_date := c.GetString("record_date")
  5856. // patient_id, _ := c.GetInt64("patient_id")
  5857. // reg_type, _ := c.GetInt64("reg_type")
  5858. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5859. // diagnose := c.GetString("diagnose")
  5860. // sick_type, _ := c.GetInt64("sick_type")
  5861. // sick_history := c.GetString("sick_history")
  5862. // doctor_id, _ := c.GetInt64("doctor", 0)
  5863. // department, _ := c.GetInt64("department", 0)
  5864. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5865. // p_type, _ := c.GetInt64("p_type")
  5866. //
  5867. // dataBody := make(map[string]interface{}, 0)
  5868. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5869. // if err != nil {
  5870. // utils.ErrorLog(err.Error())
  5871. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5872. // return
  5873. // }
  5874. //
  5875. // timeLayout := "2006-01-02"
  5876. // loc, _ := time.LoadLocation("Local")
  5877. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5878. // if err != nil {
  5879. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5880. // return
  5881. // }
  5882. // adminInfo := c.GetAdminUserInfo()
  5883. // recordDateTime := theTime.Unix()
  5884. //
  5885. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5886. //
  5887. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5888. // var hpInfo models.HisPrescriptionInfo
  5889. // if info.ID == 0 {
  5890. // var randNum int
  5891. // randNum = rand.Intn(10000) + 1000
  5892. // timestamp := time.Now().Unix()
  5893. // tempTime := time.Unix(timestamp, 0)
  5894. // timeFormat := tempTime.Format("20060102150405")
  5895. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5896. //
  5897. // hpInfo = models.HisPrescriptionInfo{
  5898. // UserOrgId: adminInfo.CurrentOrgId,
  5899. // RecordDate: theTime.Unix(),
  5900. // PatientId: patient_id,
  5901. // Status: 1,
  5902. // Ctime: time.Now().Unix(),
  5903. // Mtime: time.Now().Unix(),
  5904. // Creator: adminInfo.AdminUser.Id,
  5905. // Modifier: adminInfo.AdminUser.Id,
  5906. // Diagnosis: diagnose,
  5907. // SickHistory: sick_history,
  5908. // Departments: department,
  5909. // RegisterType: reg_type,
  5910. // PrescriptionNumber: p_number,
  5911. // PrescriptionStatus: 1,
  5912. // Doctor: role.UserName,
  5913. // DoctorId: doctor_id,
  5914. // SickType: sick_type,
  5915. // PType: p_type,
  5916. // }
  5917. // service.SavePatientPrescriptionInfo(hpInfo)
  5918. //
  5919. // } else {
  5920. // hpInfo = models.HisPrescriptionInfo{
  5921. // ID: info.ID,
  5922. // UserOrgId: adminInfo.CurrentOrgId,
  5923. // RecordDate: info.RecordDate,
  5924. // PatientId: info.PatientId,
  5925. // Status: 1,
  5926. // Ctime: info.Ctime,
  5927. // Mtime: time.Now().Unix(),
  5928. // Creator: info.Creator,
  5929. // Modifier: adminInfo.AdminUser.Id,
  5930. // Diagnosis: diagnose,
  5931. // SickHistory: sick_history,
  5932. // Departments: department,
  5933. // RegisterType: reg_type,
  5934. // PrescriptionNumber: info.PrescriptionNumber,
  5935. // Doctor: role.UserName,
  5936. // PrescriptionStatus: info.PrescriptionStatus,
  5937. // DoctorId: doctor_id,
  5938. // SickType: sick_type,
  5939. // PType: info.PType,
  5940. // }
  5941. // service.SavePatientPrescriptionInfo(hpInfo)
  5942. // }
  5943. //
  5944. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5945. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5946. //
  5947. // if len(prescriptions) > 0 {
  5948. // for _, item := range prescriptions {
  5949. // items := item.(map[string]interface{})
  5950. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5951. // utils.ErrorLog("id")
  5952. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5953. // return
  5954. // }
  5955. // id := int64(items["id"].(float64))
  5956. //
  5957. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5958. // utils.ErrorLog("type")
  5959. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5960. // return
  5961. // }
  5962. // types := int64(items["type"].(float64))
  5963. //
  5964. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5965. // utils.ErrorLog("med_type")
  5966. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5967. // return
  5968. // }
  5969. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5970. //
  5971. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5972. //
  5973. // ctime := time.Now().Unix()
  5974. //
  5975. // prescription := &models.HisPrescription{
  5976. // ID: id,
  5977. // PatientId: patient_id,
  5978. // UserOrgId: adminInfo.CurrentOrgId,
  5979. // RecordDate: recordDateTime,
  5980. // Ctime: ctime,
  5981. // Mtime: ctime,
  5982. // Type: types,
  5983. // Modifier: adminInfo.AdminUser.Id,
  5984. // Creator: adminInfo.AdminUser.Id,
  5985. // Status: 1,
  5986. // Doctor: role.UserName,
  5987. // HisPatientId: his_patient_id,
  5988. // OrderStatus: 1,
  5989. // BatchNumber: "",
  5990. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5991. // PType: hpInfo.PType,
  5992. // MedType: med_type,
  5993. // }
  5994. //
  5995. // if historyPrescription.ID > 0 {
  5996. // prescription.PreTime = historyPrescription.PreTime
  5997. //
  5998. // }
  5999. //
  6000. // service.SaveHisPrescription(prescription)
  6001. //
  6002. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  6003. // advices := items["advices"].([]interface{})
  6004. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6005. // groupNo := int64(0)
  6006. // ctime := time.Now().Unix()
  6007. // mtime := ctime
  6008. // if len(advices) > 0 {
  6009. // for _, advice := range advices {
  6010. // var s models.HisDoctorAdviceInfo
  6011. // s.PrescriptionId = prescription.ID
  6012. // s.AdviceType = 2
  6013. // s.AdviceDoctor = adminInfo.AdminUser.Id
  6014. // s.StopState = 2
  6015. // s.ExecutionState = 2
  6016. // s.AdviceDate = recordDateTime
  6017. // s.Status = 1
  6018. // s.UserOrgId = adminInfo.CurrentOrgId
  6019. // s.RecordDate = recordDateTime
  6020. // s.StartTime = prescription.PreTime
  6021. // s.Groupno = groupNo
  6022. // s.CreatedTime = ctime
  6023. // s.UpdatedTime = mtime
  6024. // s.PatientId = patient_id
  6025. // s.HisPatientId = his_patient_id
  6026. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  6027. // if errcode > 0 {
  6028. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6029. // return
  6030. // }
  6031. //
  6032. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  6033. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  6034. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  6035. // if s.Price == 0 {
  6036. // s.Price = lastWarehouse.RetailPrice
  6037. // }
  6038. // }
  6039. //
  6040. // service.CreateHisDoctorAdvice(&s)
  6041. // //记录日志
  6042. // byterequest, _ := json.Marshal(s)
  6043. // adviceLog := models.XtDoctorAdviceLog{
  6044. // UserOrgId: s.UserOrgId,
  6045. // PatientId: s.PatientId,
  6046. // AdminUserId: adminInfo.AdminUser.Id,
  6047. // Module: 1,
  6048. // ErrLog: string(byterequest),
  6049. // Status: 1,
  6050. // Ctime: time.Now().Unix(),
  6051. // Mtime: 0,
  6052. // Source: "电脑端his医嘱修改",
  6053. // RecordDate: s.AdviceDate,
  6054. // }
  6055. // service.CreateDoctorAdviceLog(adviceLog)
  6056. // redis := service.RedisClient()
  6057. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  6058. // redis.Set(key, "", time.Second)
  6059. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  6060. // fmt.Println("keyOne", keyOne)
  6061. // redis.Set(keyOne, "", time.Second)
  6062. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  6063. // redis.Set(keySeven, "", time.Second)
  6064. // redis.Close()
  6065. //
  6066. // }
  6067. // }
  6068. // }
  6069. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  6070. // projects := items["project"].([]interface{})
  6071. // if len(projects) > 0 {
  6072. // for _, project := range projects {
  6073. // var p models.HisPrescriptionProject
  6074. // p.PrescriptionId = prescription.ID
  6075. // p.Ctime = time.Now().Unix()
  6076. // p.Mtime = time.Now().Unix()
  6077. // p.PatientId = patient_id
  6078. // p.RecordDate = recordDateTime
  6079. // p.UserOrgId = adminInfo.CurrentOrgId
  6080. // p.HisPatientId = his_patient_id
  6081. // p.Status = 1
  6082. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  6083. // if errcode > 0 {
  6084. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6085. // return
  6086. // }
  6087. // service.CreateHisProjectTwo(&p)
  6088. //
  6089. // //记录日志
  6090. // byterequest, _ := json.Marshal(p)
  6091. // adviceLog := models.XtDoctorAdviceLog{
  6092. // UserOrgId: p.UserOrgId,
  6093. // PatientId: p.PatientId,
  6094. // AdminUserId: adminInfo.AdminUser.Id,
  6095. // Module: 1,
  6096. // ErrLog: string(byterequest),
  6097. // Status: 1,
  6098. // Ctime: time.Now().Unix(),
  6099. // Mtime: 0,
  6100. // Source: "电脑端his项目修改",
  6101. // RecordDate: p.RecordDate,
  6102. // }
  6103. // service.CreateDoctorAdviceLog(adviceLog)
  6104. // }
  6105. // }
  6106. // }
  6107. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  6108. // addition := items["addition"].([]interface{})
  6109. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6110. // ctime := time.Now().Unix()
  6111. // mtime := ctime
  6112. // if len(addition) > 0 {
  6113. // for _, item := range addition {
  6114. // var s models.HisAdditionalCharge
  6115. // s.PrescriptionId = prescription.ID
  6116. // s.Status = 1
  6117. // s.UserOrgId = adminInfo.CurrentOrgId
  6118. // s.RecordDate = recordDateTime
  6119. // s.CreatedTime = ctime
  6120. // s.UpdatedTime = mtime
  6121. // s.PatientId = patient_id
  6122. // s.HisPatientId = his_patient_id
  6123. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  6124. // if errcode > 0 {
  6125. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6126. // return
  6127. // }
  6128. // service.CreateAdditionalCharge(&s)
  6129. // }
  6130. // }
  6131. // }
  6132. //
  6133. // }
  6134. // }
  6135. // }
  6136. // if err == nil {
  6137. // c.ServeSuccessJSON(map[string]interface{}{
  6138. // "msg": "保存成功",
  6139. // })
  6140. // return
  6141. //
  6142. // } else {
  6143. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6144. // return
  6145. // }
  6146. //}
  6147. func (c *HisApiController) DeletePrescription() {
  6148. prescription_id, _ := c.GetInt64("id")
  6149. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  6150. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  6151. ////同步到自备药
  6152. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6153. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6154. if selfPrescriptionOpen.IsOpen == 1 {
  6155. // 在函数结束时处理事务回滚
  6156. db := service.XTWriteDB()
  6157. tx := db.Begin()
  6158. defer func() {
  6159. if r := recover(); r != nil {
  6160. tx.Rollback()
  6161. } else {
  6162. tx.Commit()
  6163. }
  6164. }()
  6165. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  6166. for _, item := range advicesList {
  6167. timeStr := time.Now().Format("2006-01-02")
  6168. timeArr := strings.Split(timeStr, "-")
  6169. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6170. total = total + 1
  6171. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6172. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6173. number = number + total
  6174. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6175. operation_time := time.Now().Unix()
  6176. creater := c.GetAdminUserInfo().AdminUser.Id
  6177. //创建一个出库单
  6178. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6179. WarehouseOutOrderNumber: warehousing_out_order,
  6180. OperationTime: operation_time,
  6181. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6182. Creater: creater,
  6183. Ctime: time.Now().Unix(),
  6184. Status: 1,
  6185. WarehouseOutTime: item.AdviceDate,
  6186. Type: 0,
  6187. PatientId: item.PatientId,
  6188. IsCheck: 1,
  6189. }
  6190. //查询今日是否有出库数据
  6191. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  6192. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  6193. if lastWarehouseOut.ID == 0 {
  6194. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6195. }
  6196. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  6197. var total_count int64
  6198. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  6199. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6200. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6201. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6202. }
  6203. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6204. total_count += prescribingNumberSeven
  6205. }
  6206. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6207. total_count += prescribingNumberSeven
  6208. }
  6209. //出库
  6210. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6211. WarehouseOutOrderNumber: warehousing_out_order,
  6212. WarehouseOutId: lastWarehouseOut.ID,
  6213. DrugId: item.DrugId,
  6214. Count: total_count,
  6215. Price: 0,
  6216. TotalPrice: 0,
  6217. Status: 1,
  6218. Ctime: item.AdviceDate,
  6219. Mtime: item.AdviceDate,
  6220. Remark: "",
  6221. OrgId: item.UserOrgId,
  6222. Type: 0,
  6223. Manufacturer: selfBasedrug.Manufacturer,
  6224. Dealer: selfBasedrug.Dealer,
  6225. RetailPrice: 0,
  6226. RetailTotalPrice: 0,
  6227. CountUnit: selfBasedrug.MinUnit,
  6228. ExpiryDate: 0,
  6229. ProductDate: 0,
  6230. Number: "",
  6231. BatchNumber: "",
  6232. IsSys: 1,
  6233. WarehouseInfoId: 0,
  6234. AdminUserId: 0,
  6235. StockCount: "",
  6236. IsCheck: 1,
  6237. SysRecordTime: item.AdviceDate,
  6238. PatientId: item.PatientId,
  6239. ClassType: "",
  6240. AdviceId: item.ID,
  6241. }
  6242. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6243. }
  6244. fmt.Println("长度-------------------------------", warehousingOutInfo)
  6245. for _, it := range warehousingOutInfo {
  6246. //查询今日是否有出库数据
  6247. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  6248. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6249. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6250. //出库逻辑
  6251. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  6252. //查询剩余库存
  6253. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6254. var sum_count int64
  6255. for _, its := range stockInfo {
  6256. if its.MaxUnit == medical.MaxUnit {
  6257. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6258. }
  6259. sum_count += its.StockMaxNumber + its.StockMinNumber
  6260. }
  6261. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6262. }
  6263. }
  6264. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6265. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6266. //耗材保存处方出库
  6267. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6268. //已收费和已发药限制逻辑
  6269. isCharge := false
  6270. isMedicine := false
  6271. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6272. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6273. if new_prescription.IsMedicine == 1 {
  6274. isMedicine = true
  6275. }
  6276. for _, item := range new_prescriptions {
  6277. if item.OrderStatus == 4 {
  6278. isCharge = true
  6279. }
  6280. }
  6281. if p_err != nil {
  6282. if new_prescription.ID > 0 {
  6283. if new_prescription.OrderStatus == 2 {
  6284. isCharge = true
  6285. }
  6286. }
  6287. }
  6288. for _, item := range advices {
  6289. if item.IsMedicine == 1 {
  6290. isMedicine = true
  6291. }
  6292. }
  6293. if isCharge {
  6294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6295. return
  6296. }
  6297. if isMedicine {
  6298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6299. return
  6300. }
  6301. //已收费和已发药限制逻辑
  6302. if len(projects) > 0 {
  6303. for _, item := range projects {
  6304. service.DeletePrintInfo(item.ID) //删除打印信息
  6305. if goodOutConfig.IsOpen != 1 {
  6306. if stockConfig.IsOpen == 1 {
  6307. if item.Type == 3 && item.IsOut == 1 {
  6308. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6309. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6310. good.Total = good.Total + f_count
  6311. service.UpdateGoodInfo(&good)
  6312. operation_time := time.Now().Unix()
  6313. creater := c.GetAdminUserInfo().AdminUser.Id
  6314. //创建退库单
  6315. timeStr := time.Now().Format("2006-01-02")
  6316. timeArr := strings.Split(timeStr, "-")
  6317. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6318. total = total + 1
  6319. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6320. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6321. cancelStock := models.CancelStock{
  6322. OrderNumber: orderNumber,
  6323. OperaTime: operation_time,
  6324. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6325. Creater: creater,
  6326. Ctime: time.Now().Unix(),
  6327. Status: 1,
  6328. ReturnTime: item.RecordDate,
  6329. Type: 1,
  6330. StorehouseId: houseConfig.StorehouseOutInfo,
  6331. IsCheck: 1,
  6332. }
  6333. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6334. if msgerrkonde == gorm.ErrRecordNotFound {
  6335. service.AddSigleCancelStock(&cancelStock)
  6336. }
  6337. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6338. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6339. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6340. //查询该耗材是否出库
  6341. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6342. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6343. deaerler, _ := service.GetDealerById(info.Dealer)
  6344. var total_count int64
  6345. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6346. total_count += count
  6347. if info.ID > 0 {
  6348. if info.Count >= total_count {
  6349. //回退库存
  6350. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6351. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6352. var flush_count int64
  6353. for _, it := range goodList {
  6354. flush_count += it.StockCount
  6355. }
  6356. cancelStockInfo := models.CancelStockInfo{
  6357. GoodId: item.ProjectId,
  6358. CancelStockId: cancel.ID,
  6359. GoodTypeId: good.GoodTypeId,
  6360. Count: prescribingNumber,
  6361. Price: info.Price,
  6362. Total: 0,
  6363. ProductDate: info.ProductDate,
  6364. ExpiryDate: info.ExpiryDate,
  6365. Ctime: time.Now().Unix(),
  6366. Status: 1,
  6367. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6368. OrderNumber: cancel.OrderNumber,
  6369. Type: 0,
  6370. Dealer: deaerler.DealerName,
  6371. Manufacturer: manufacturer.ManufacturerName,
  6372. Number: info.Number,
  6373. RegisterAccount: "",
  6374. Remark: "",
  6375. WarehouseInfoId: info.WarehouseInfotId,
  6376. PatientId: info.PatientId,
  6377. RecordDate: info.SysRecordTime,
  6378. StorehouseId: houseConfig.StorehouseOutInfo,
  6379. IsCheck: 1,
  6380. }
  6381. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6382. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6383. flow := models.VmStockFlow{
  6384. WarehousingId: info.WarehouseInfotId,
  6385. GoodId: item.ProjectId,
  6386. Number: info.Number,
  6387. LicenseNumber: info.LicenseNumber,
  6388. Count: prescribingNumber,
  6389. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6390. PatientId: item.PatientId,
  6391. SystemTime: info.SysRecordTime,
  6392. ConsumableType: 7,
  6393. IsSys: 0,
  6394. WarehousingOrder: "",
  6395. WarehouseOutId: info.WarehouseOutId,
  6396. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6397. IsEdit: 0,
  6398. CancelStockId: cancel.ID,
  6399. CancelOrderNumber: cancel.OrderNumber,
  6400. Manufacturer: manufacturer.ID,
  6401. Dealer: 0,
  6402. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6403. UpdateCreator: 0,
  6404. Status: 1,
  6405. Ctime: time.Now().Unix(),
  6406. Mtime: 0,
  6407. Price: info.Price,
  6408. WarehousingDetailId: info.WarehouseInfotId,
  6409. WarehouseOutDetailId: info.ID,
  6410. CancelOutDetailId: cancelInfo.ID,
  6411. ProductDate: info.ProductDate,
  6412. ExpireDate: info.ExpiryDate,
  6413. StorehouseId: houseConfig.StorehouseOutInfo,
  6414. OverCount: flush_count,
  6415. OperateTime: time.Now().Unix(),
  6416. }
  6417. service.CreateStockFlowOne(flow)
  6418. //退库数量增加
  6419. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6420. //出库数量减少
  6421. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6422. }
  6423. if info.Count < total_count {
  6424. //回退库存
  6425. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6426. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6427. var flush_count int64
  6428. for _, it := range goodList {
  6429. flush_count += it.StockCount
  6430. }
  6431. cancelStockInfo := models.CancelStockInfo{
  6432. GoodId: item.ProjectId,
  6433. CancelStockId: cancel.ID,
  6434. GoodTypeId: good.GoodTypeId,
  6435. Count: info.Count,
  6436. Price: info.Price,
  6437. Total: 0,
  6438. ProductDate: info.ProductDate,
  6439. ExpiryDate: info.ExpiryDate,
  6440. Ctime: time.Now().Unix(),
  6441. Status: 1,
  6442. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6443. OrderNumber: cancel.OrderNumber,
  6444. Type: 0,
  6445. Dealer: deaerler.DealerName,
  6446. Manufacturer: manufacturer.ManufacturerName,
  6447. Number: info.Number,
  6448. RegisterAccount: "",
  6449. Remark: "",
  6450. WarehouseInfoId: info.WarehouseInfotId,
  6451. PatientId: info.PatientId,
  6452. RecordDate: info.SysRecordTime,
  6453. StorehouseId: houseConfig.StorehouseOutInfo,
  6454. IsCheck: 1,
  6455. }
  6456. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6457. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6458. flow := models.VmStockFlow{
  6459. WarehousingId: info.WarehouseInfotId,
  6460. GoodId: item.ProjectId,
  6461. Number: info.Number,
  6462. LicenseNumber: info.LicenseNumber,
  6463. Count: info.Count,
  6464. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6465. PatientId: item.PatientId,
  6466. SystemTime: info.SysRecordTime,
  6467. ConsumableType: 7,
  6468. IsSys: 0,
  6469. WarehousingOrder: "",
  6470. WarehouseOutId: info.WarehouseOutId,
  6471. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6472. IsEdit: 0,
  6473. CancelStockId: cancel.ID,
  6474. CancelOrderNumber: cancel.OrderNumber,
  6475. Manufacturer: manufacturer.ID,
  6476. Dealer: 0,
  6477. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6478. UpdateCreator: 0,
  6479. Status: 1,
  6480. Ctime: time.Now().Unix(),
  6481. Mtime: 0,
  6482. Price: info.Price,
  6483. WarehousingDetailId: info.WarehouseInfotId,
  6484. WarehouseOutDetailId: info.ID,
  6485. CancelOutDetailId: cancelInfo.ID,
  6486. ProductDate: info.ProductDate,
  6487. ExpireDate: info.ExpiryDate,
  6488. StorehouseId: houseConfig.StorehouseOutInfo,
  6489. OverCount: flush_count,
  6490. OperateTime: time.Now().Unix(),
  6491. }
  6492. service.CreateStockFlowOne(flow)
  6493. //退库数量增加
  6494. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6495. //出库数量减少
  6496. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6497. }
  6498. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6499. var flush_count int64
  6500. for _, it := range goodList {
  6501. flush_count += it.StockCount
  6502. }
  6503. //查询已出库数量
  6504. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6505. if prescribingNumber < dialysisInfo.Count {
  6506. //改变数量
  6507. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6508. }
  6509. if prescribingNumber >= dialysisInfo.Count {
  6510. //删除出库表
  6511. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6512. }
  6513. //更新库存
  6514. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6515. //更新基础库库存
  6516. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6517. }
  6518. }
  6519. }
  6520. }
  6521. //保存耗材出库
  6522. if goodOutConfig.IsOpen == 1 {
  6523. if item.Type == 3 {
  6524. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6525. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6526. good.Total = good.Total + f_count
  6527. service.UpdateGoodInfo(&good)
  6528. operation_time := time.Now().Unix()
  6529. creater := c.GetAdminUserInfo().AdminUser.Id
  6530. //创建退库单
  6531. timeStr := time.Now().Format("2006-01-02")
  6532. timeArr := strings.Split(timeStr, "-")
  6533. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6534. total = total + 1
  6535. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6536. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6537. cancelStock := models.CancelStock{
  6538. OrderNumber: orderNumber,
  6539. OperaTime: operation_time,
  6540. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6541. Creater: creater,
  6542. Ctime: time.Now().Unix(),
  6543. Status: 1,
  6544. ReturnTime: item.RecordDate,
  6545. Type: 1,
  6546. StorehouseId: houseConfig.StorehouseOutInfo,
  6547. IsCheck: 1,
  6548. }
  6549. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6550. if msgerrkonde == gorm.ErrRecordNotFound {
  6551. service.AddSigleCancelStock(&cancelStock)
  6552. }
  6553. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6554. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6555. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6556. //查询该耗材是否出库
  6557. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6558. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6559. deaerler, _ := service.GetDealerById(info.Dealer)
  6560. var total_count int64
  6561. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6562. total_count += count
  6563. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6564. var flush_count int64
  6565. for _, it := range goodList {
  6566. flush_count += it.StockCount
  6567. }
  6568. fmt.Println("历史出库数据", info.Count)
  6569. fmt.Println("出库数量", total_count)
  6570. if info.ID > 0 {
  6571. cancelStockInfo := models.CancelStockInfo{
  6572. GoodId: item.ProjectId,
  6573. CancelStockId: cancel.ID,
  6574. GoodTypeId: good.GoodTypeId,
  6575. Count: prescribingNumber,
  6576. Price: info.Price,
  6577. Total: 0,
  6578. ProductDate: info.ProductDate,
  6579. ExpiryDate: info.ExpiryDate,
  6580. Ctime: time.Now().Unix(),
  6581. Status: 1,
  6582. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6583. OrderNumber: cancel.OrderNumber,
  6584. Type: 0,
  6585. Dealer: deaerler.DealerName,
  6586. Manufacturer: manufacturer.ManufacturerName,
  6587. Number: info.Number,
  6588. RegisterAccount: "",
  6589. Remark: "",
  6590. WarehouseInfoId: info.WarehouseInfotId,
  6591. PatientId: info.PatientId,
  6592. RecordDate: info.SysRecordTime,
  6593. StorehouseId: houseConfig.StorehouseOutInfo,
  6594. IsCheck: 1,
  6595. }
  6596. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6597. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6598. //查询出库数量
  6599. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6600. //出库数据 大于 退库数量
  6601. if len(list) > 0 {
  6602. for _, it := range list {
  6603. //回退库存
  6604. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6605. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6606. var flush_count_one int64
  6607. for _, it := range goodList {
  6608. flush_count_one += it.StockCount
  6609. }
  6610. //查询该批次是否有退库数据
  6611. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6612. creater := c.GetAdminUserInfo().AdminUser.Id
  6613. flow := models.VmStockFlow{
  6614. WarehousingId: it.WarehouseInfotId,
  6615. GoodId: it.GoodId,
  6616. Number: it.Number,
  6617. LicenseNumber: it.LicenseNumber,
  6618. Count: it.Count,
  6619. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6620. PatientId: it.PatientId,
  6621. SystemTime: it.SysRecordTime,
  6622. ConsumableType: 7,
  6623. IsSys: 0,
  6624. WarehousingOrder: "",
  6625. WarehouseOutId: it.WarehouseOutId,
  6626. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6627. IsEdit: 0,
  6628. CancelStockId: cancel.ID,
  6629. CancelOrderNumber: cancel.OrderNumber,
  6630. Manufacturer: manufacturer.ID,
  6631. Dealer: 0,
  6632. Creator: creater,
  6633. UpdateCreator: 0,
  6634. Status: 1,
  6635. Ctime: time.Now().Unix(),
  6636. Mtime: 0,
  6637. Price: it.Price,
  6638. WarehousingDetailId: it.WarehouseInfotId,
  6639. WarehouseOutDetailId: it.ID,
  6640. CancelOutDetailId: cancelInfo.ID,
  6641. ProductDate: it.ProductDate,
  6642. ExpireDate: it.ExpiryDate,
  6643. StorehouseId: houseConfig.StorehouseOutInfo,
  6644. OverCount: flush_count_one,
  6645. OperateTime: time.Now().Unix(),
  6646. }
  6647. service.CreateStockFlowOne(flow)
  6648. //if flow.ID > 0 {
  6649. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6650. //}
  6651. }
  6652. }
  6653. //flow := models.VmStockFlow{
  6654. // WarehousingId: info.WarehouseInfotId,
  6655. // GoodId: item.ProjectId,
  6656. // Number: info.Number,
  6657. // LicenseNumber: info.LicenseNumber,
  6658. // Count: prescribingNumber,
  6659. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6660. // PatientId: item.PatientId,
  6661. // SystemTime: info.SysRecordTime,
  6662. // ConsumableType: 7,
  6663. // IsSys: 0,
  6664. // WarehousingOrder: "",
  6665. // WarehouseOutId: info.WarehouseOutId,
  6666. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6667. // IsEdit: 0,
  6668. // CancelStockId: cancel.ID,
  6669. // CancelOrderNumber: cancel.OrderNumber,
  6670. // Manufacturer: manufacturer.ID,
  6671. // Dealer: 0,
  6672. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6673. // UpdateCreator: 0,
  6674. // Status: 1,
  6675. // Ctime: time.Now().Unix(),
  6676. // Mtime: 0,
  6677. // Price: info.Price,
  6678. // WarehousingDetailId: info.WarehouseInfotId,
  6679. // WarehouseOutDetailId: info.ID,
  6680. // CancelOutDetailId: cancelInfo.ID,
  6681. // ProductDate: info.ProductDate,
  6682. // ExpireDate: info.ExpiryDate,
  6683. // StorehouseId: houseConfig.StorehouseOutInfo,
  6684. // OverCount: flush_count,
  6685. //}
  6686. //service.CreateStockFlowOne(flow)
  6687. //退库数量增加
  6688. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6689. //出库数量减少
  6690. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6691. //查询已出库数量
  6692. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6693. if prescribingNumber < dialysisInfo.Count {
  6694. //改变数量
  6695. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6696. }
  6697. if prescribingNumber >= dialysisInfo.Count {
  6698. //删除出库表
  6699. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6700. }
  6701. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6702. var flush_count_one int64
  6703. for _, it := range goodList {
  6704. flush_count_one += it.StockCount
  6705. }
  6706. //更新库存
  6707. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6708. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6709. //更新基础库库存
  6710. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6711. }
  6712. }
  6713. }
  6714. }
  6715. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6716. fmt.Println(err)
  6717. }
  6718. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6719. fmt.Println(err)
  6720. if len(advices) > 0 {
  6721. for _, item := range advices {
  6722. redis := service.RedisClient()
  6723. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6724. redis.Set(keyFive, "", time.Second)
  6725. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6726. redis.Set(keyOne, "", time.Second)
  6727. redis.Close()
  6728. }
  6729. }
  6730. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6731. if len(advices) > 0 {
  6732. for _, item := range advices {
  6733. creater := c.GetAdminUserInfo().AdminUser.Id
  6734. service.DrugAutoAddCancelInfo(item, creater)
  6735. }
  6736. }
  6737. } else {
  6738. if drugOutConfig.IsOpen == 1 {
  6739. if len(advices) > 0 {
  6740. for _, item := range advices {
  6741. creater := c.GetAdminUserInfo().AdminUser.Id
  6742. service.DrugAutoAddCancelInfo(item, creater)
  6743. }
  6744. }
  6745. } else {
  6746. if len(advices) > 0 {
  6747. for _, item := range advices {
  6748. creater := c.GetAdminUserInfo().AdminUser.Id
  6749. service.DrugAutoAddCancelInfo(item, creater)
  6750. }
  6751. }
  6752. }
  6753. }
  6754. c.ServeSuccessJSON(map[string]interface{}{
  6755. "msg": "删除成功",
  6756. })
  6757. return
  6758. }
  6759. func (c *HisApiController) DeleteDoctorAdvice() {
  6760. id, _ := c.GetInt64("id")
  6761. advice, _ := service.GetHisDoctorAdvicesById(id)
  6762. ////同步到自备药
  6763. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6764. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6765. if selfPrescriptionOpen.IsOpen == 1 {
  6766. db := service.XTWriteDB()
  6767. tx := db.Begin()
  6768. defer func() {
  6769. if r := recover(); r != nil {
  6770. tx.Rollback()
  6771. } else {
  6772. tx.Commit()
  6773. }
  6774. }()
  6775. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6776. var total_count int64
  6777. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6778. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6779. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6780. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6781. }
  6782. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6783. total_count += prescribingNumberSeven
  6784. }
  6785. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6786. total_count += prescribingNumberSeven
  6787. }
  6788. timeStr := time.Now().Format("2006-01-02")
  6789. timeArr := strings.Split(timeStr, "-")
  6790. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6791. total = total + 1
  6792. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6793. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6794. number = number + total
  6795. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6796. operation_time := time.Now().Unix()
  6797. creater := c.GetAdminUserInfo().AdminUser.Id
  6798. //创建一个出库单
  6799. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6800. WarehouseOutOrderNumber: warehousing_out_order,
  6801. OperationTime: operation_time,
  6802. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6803. Creater: creater,
  6804. Ctime: time.Now().Unix(),
  6805. Status: 1,
  6806. WarehouseOutTime: advice.AdviceDate,
  6807. Type: 0,
  6808. PatientId: advice.PatientId,
  6809. IsCheck: 1,
  6810. }
  6811. //查询今日是否有出库数据
  6812. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6813. if lastWarehouseOut.ID == 0 {
  6814. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6815. }
  6816. //出库
  6817. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6818. WarehouseOutId: lastWarehouseOut.ID,
  6819. WarehouseOutOrderNumber: warehousing_out_order,
  6820. DrugId: advice.DrugId,
  6821. Count: total_count,
  6822. Price: 0,
  6823. TotalPrice: 0,
  6824. Status: 1,
  6825. Ctime: advice.AdviceDate,
  6826. Mtime: advice.AdviceDate,
  6827. Remark: "",
  6828. OrgId: advice.UserOrgId,
  6829. Type: 0,
  6830. Manufacturer: selfBasedrug.Manufacturer,
  6831. Dealer: selfBasedrug.Dealer,
  6832. RetailPrice: 0,
  6833. RetailTotalPrice: 0,
  6834. CountUnit: advice.PrescribingNumberUnit,
  6835. ExpiryDate: 0,
  6836. ProductDate: 0,
  6837. Number: "",
  6838. BatchNumber: "",
  6839. IsSys: 0,
  6840. WarehouseInfoId: 0,
  6841. AdminUserId: 0,
  6842. StockCount: "",
  6843. IsCheck: 1,
  6844. SysRecordTime: advice.AdviceDate,
  6845. PatientId: advice.PatientId,
  6846. AdviceId: advice.ID,
  6847. ClassType: "",
  6848. }
  6849. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6850. for _, it := range warehousingOutInfo {
  6851. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6852. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6853. //出库逻辑
  6854. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6855. //查询剩余库存
  6856. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6857. var sum_count int64
  6858. for _, its := range stockInfo {
  6859. if its.MaxUnit == medical.MaxUnit {
  6860. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6861. }
  6862. sum_count += its.StockMaxNumber + its.StockMinNumber
  6863. }
  6864. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6865. }
  6866. }
  6867. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6868. //已收费和已发药的限制逻辑
  6869. isCharge := false
  6870. isMedicine := false
  6871. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6872. //获取今天该患者所有处方,判断是否发药或者收费
  6873. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6874. //for _, item := range new_prescriptions {
  6875. if new_prescription.IsMedicine == 1 {
  6876. isMedicine = true
  6877. }
  6878. //}
  6879. for _, item := range new_prescriptions {
  6880. if item.OrderStatus == 4 {
  6881. isCharge = true
  6882. }
  6883. }
  6884. if isMedicine {
  6885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6886. return
  6887. }
  6888. if isCharge {
  6889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6890. return
  6891. }
  6892. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6893. creater := c.GetAdminUserInfo().AdminUser.Id
  6894. for _, item := range advices {
  6895. if item.IsMedicine == 1 {
  6896. isMedicine = true
  6897. }
  6898. byterequest, _ := json.Marshal(item)
  6899. adviceLog := models.XtDoctorAdviceLog{
  6900. UserOrgId: item.UserOrgId,
  6901. PatientId: item.PatientId,
  6902. AdminUserId: creater,
  6903. Module: 1,
  6904. ErrLog: string(byterequest),
  6905. Status: 1,
  6906. Ctime: time.Now().Unix(),
  6907. Mtime: 0,
  6908. Source: "电脑端删除医嘱",
  6909. RecordDate: item.AdviceDate,
  6910. }
  6911. service.CreateDoctorAdviceLog(adviceLog)
  6912. }
  6913. if isMedicine {
  6914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6915. return
  6916. }
  6917. if new_prescription.ID > 0 {
  6918. if new_prescription.OrderStatus == 2 {
  6919. isCharge = true
  6920. }
  6921. }
  6922. if isCharge {
  6923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6924. return
  6925. }
  6926. //已收费和已发药的限制逻辑
  6927. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6928. redis := service.RedisClient()
  6929. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6930. redis.Set(keyFive, "", time.Second)
  6931. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6932. redis.Set(keyOne, "", time.Second)
  6933. defer redis.Close()
  6934. if err == nil {
  6935. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6936. //查询是否在处方中出库
  6937. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6938. if openConfig.IsOpen != 1 {
  6939. //判断该医嘱是否执行了
  6940. if advice.ExecutionState == 1 {
  6941. creater := c.GetAdminUserInfo().AdminUser.Id
  6942. service.DrugAutoAddCancelInfo(&advice, creater)
  6943. }
  6944. }
  6945. //开启保存处方扣减功能
  6946. if openConfig.IsOpen == 1 {
  6947. creater := c.GetAdminUserInfo().AdminUser.Id
  6948. service.DrugAutoAddCancelInfo(&advice, creater)
  6949. }
  6950. } else {
  6951. if drugOutConfig.IsOpen == 1 {
  6952. //查询是否在处方中出库
  6953. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6954. if openConfig.IsOpen != 1 {
  6955. //判断该医嘱是否执行了
  6956. if advice.ExecutionState == 1 {
  6957. creater := c.GetAdminUserInfo().AdminUser.Id
  6958. service.DrugAutoAddCancelInfo(&advice, creater)
  6959. }
  6960. }
  6961. //开启保存处方扣减功能
  6962. if openConfig.IsOpen == 1 {
  6963. creater := c.GetAdminUserInfo().AdminUser.Id
  6964. service.DrugAutoAddCancelInfo(&advice, creater)
  6965. }
  6966. } else {
  6967. //判断该医嘱是否执行了
  6968. if advice.ExecutionState == 1 {
  6969. creater := c.GetAdminUserInfo().AdminUser.Id
  6970. service.DrugAutoAddCancelInfo(&advice, creater)
  6971. }
  6972. }
  6973. }
  6974. c.ServeSuccessJSON(map[string]interface{}{
  6975. "msg": "删除成功",
  6976. })
  6977. return
  6978. } else {
  6979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6980. return
  6981. }
  6982. }
  6983. func (c *HisApiController) DeleteProject() {
  6984. id, _ := c.GetInt64("id")
  6985. adminInfo := c.GetAdminUserInfo()
  6986. project, _ := service.GetHisProjectByID(id)
  6987. // var consumable models.DialysisBeforePrepare
  6988. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6989. //耗材保存处方出库
  6990. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6991. isCharge := false
  6992. isMedicine := false
  6993. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6994. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6995. creater := c.GetAdminUserInfo().AdminUser.Id
  6996. for _, item := range new_prescriptions {
  6997. if item.IsMedicine == 1 {
  6998. isMedicine = true
  6999. }
  7000. byterequest, _ := json.Marshal(item)
  7001. adviceLog := models.XtDoctorAdviceLog{
  7002. UserOrgId: item.UserOrgId,
  7003. PatientId: item.PatientId,
  7004. AdminUserId: creater,
  7005. Module: 1,
  7006. ErrLog: string(byterequest),
  7007. Status: 1,
  7008. Ctime: time.Now().Unix(),
  7009. Mtime: 0,
  7010. Source: "电脑端删除医嘱",
  7011. RecordDate: item.RecordDate,
  7012. }
  7013. service.CreateDoctorAdviceLog(adviceLog)
  7014. }
  7015. for _, item := range new_prescriptions {
  7016. if item.OrderStatus == 4 {
  7017. isCharge = true
  7018. }
  7019. }
  7020. if isMedicine {
  7021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  7022. return
  7023. }
  7024. if isCharge {
  7025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  7026. return
  7027. }
  7028. if new_prescription.ID > 0 {
  7029. if new_prescription.OrderStatus == 2 {
  7030. isCharge = true
  7031. }
  7032. }
  7033. if isCharge {
  7034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  7035. return
  7036. }
  7037. service.DeletePrintInfo(id)
  7038. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  7039. label.Status = 0
  7040. service.CreateHisLabelRecordTwo(&label)
  7041. fmt.Println(goodOutConfig.IsOpen)
  7042. if goodOutConfig.IsOpen != 1 {
  7043. if stockConfig.IsOpen == 1 {
  7044. if project.Type == 2 {
  7045. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7046. fmt.Println(err)
  7047. }
  7048. if project.Type == 3 && project.IsOut == 1 {
  7049. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7050. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7051. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7052. operation_time := time.Now().Unix()
  7053. creater := adminInfo.AdminUser.Id
  7054. //创建退库单
  7055. timeStr := time.Now().Format("2006-01-02")
  7056. timeArr := strings.Split(timeStr, "-")
  7057. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7058. total = total + 1
  7059. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7060. cancelStock := models.CancelStock{
  7061. OrderNumber: orderNumber,
  7062. OperaTime: operation_time,
  7063. OrgId: adminInfo.CurrentOrgId,
  7064. Creater: creater,
  7065. Ctime: time.Now().Unix(),
  7066. Status: 1,
  7067. ReturnTime: project.RecordDate,
  7068. Type: 1,
  7069. StorehouseId: houseConfig.StorehouseOutInfo,
  7070. IsCheck: 1,
  7071. }
  7072. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7073. if msgerrkonde == gorm.ErrRecordNotFound {
  7074. service.AddSigleCancelStock(&cancelStock)
  7075. }
  7076. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7077. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7078. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7079. //查询是否有出库
  7080. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7081. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7082. deaerler, _ := service.GetDealerById(info.Dealer)
  7083. if info.ID > 0 {
  7084. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7085. if info.Count >= prescribingNumber {
  7086. cancelStockInfo := models.CancelStockInfo{
  7087. GoodId: project.ProjectId,
  7088. CancelStockId: cancel.ID,
  7089. GoodTypeId: good.GoodTypeId,
  7090. Count: prescribingNumber,
  7091. Price: info.Price,
  7092. Total: 0,
  7093. ProductDate: info.ProductDate,
  7094. ExpiryDate: info.ExpiryDate,
  7095. Ctime: time.Now().Unix(),
  7096. Status: 1,
  7097. OrgId: adminInfo.CurrentOrgId,
  7098. OrderNumber: cancel.OrderNumber,
  7099. Type: 0,
  7100. Dealer: deaerler.DealerName,
  7101. Manufacturer: manufacturer.ManufacturerName,
  7102. Number: info.Number,
  7103. RegisterAccount: "",
  7104. Remark: "",
  7105. WarehouseInfoId: info.WarehouseInfotId,
  7106. PatientId: info.PatientId,
  7107. RecordDate: info.SysRecordTime,
  7108. StorehouseId: houseConfig.StorehouseOutInfo,
  7109. IsCheck: 1,
  7110. }
  7111. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7112. //回退库存
  7113. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  7114. //退库数量增加
  7115. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7116. //出库数量减少
  7117. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7118. }
  7119. if info.Count < prescribingNumber {
  7120. cancelStockInfo := models.CancelStockInfo{
  7121. GoodId: project.ProjectId,
  7122. CancelStockId: cancel.ID,
  7123. GoodTypeId: good.GoodTypeId,
  7124. Count: info.Count,
  7125. Price: info.Price,
  7126. Total: 0,
  7127. ProductDate: info.ProductDate,
  7128. ExpiryDate: info.ExpiryDate,
  7129. Ctime: time.Now().Unix(),
  7130. Status: 1,
  7131. OrgId: adminInfo.CurrentOrgId,
  7132. OrderNumber: cancel.OrderNumber,
  7133. Type: 0,
  7134. Dealer: deaerler.DealerName,
  7135. Manufacturer: manufacturer.ManufacturerName,
  7136. Number: info.Number,
  7137. RegisterAccount: "",
  7138. Remark: "",
  7139. WarehouseInfoId: info.WarehouseInfotId,
  7140. PatientId: info.PatientId,
  7141. RecordDate: info.SysRecordTime,
  7142. StorehouseId: houseConfig.StorehouseOutInfo,
  7143. IsCheck: 1,
  7144. }
  7145. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7146. //回退库存
  7147. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7148. //退库数量增加
  7149. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  7150. //出库数量减少
  7151. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  7152. }
  7153. //查询剩余库存
  7154. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7155. var over_count int64
  7156. for _, it := range goodList {
  7157. over_count += it.StockCount
  7158. }
  7159. //出库数据 大于 退库数量
  7160. if info.Count >= prescribingNumber {
  7161. flow := models.VmStockFlow{
  7162. WarehousingId: info.WarehouseInfotId,
  7163. GoodId: project.ProjectId,
  7164. Number: info.Number,
  7165. LicenseNumber: info.LicenseNumber,
  7166. Count: prescribingNumber,
  7167. UserOrgId: adminInfo.CurrentOrgId,
  7168. PatientId: project.PatientId,
  7169. SystemTime: info.SysRecordTime,
  7170. ConsumableType: 7,
  7171. IsSys: 0,
  7172. WarehousingOrder: "",
  7173. WarehouseOutId: info.WarehouseOutId,
  7174. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7175. IsEdit: 0,
  7176. CancelStockId: cancel.ID,
  7177. CancelOrderNumber: cancel.OrderNumber,
  7178. Manufacturer: manufacturer.ID,
  7179. Dealer: 0,
  7180. Creator: adminInfo.AdminUser.Id,
  7181. UpdateCreator: 0,
  7182. Status: 1,
  7183. Ctime: time.Now().Unix(),
  7184. Mtime: 0,
  7185. Price: info.Price,
  7186. WarehousingDetailId: info.WarehouseInfotId,
  7187. WarehouseOutDetailId: info.ID,
  7188. CancelOutDetailId: cancelInfo.ID,
  7189. ProductDate: info.ProductDate,
  7190. ExpireDate: info.ExpiryDate,
  7191. StorehouseId: houseConfig.StorehouseOutInfo,
  7192. OverCount: over_count,
  7193. OperateTime: time.Now().Unix(),
  7194. }
  7195. service.CreateStockFlowOne(flow)
  7196. }
  7197. //出库数据小于退库数据
  7198. if info.Count < prescribingNumber {
  7199. flow := models.VmStockFlow{
  7200. WarehousingId: info.WarehouseInfotId,
  7201. GoodId: project.ProjectId,
  7202. Number: info.Number,
  7203. LicenseNumber: info.LicenseNumber,
  7204. Count: info.Count,
  7205. UserOrgId: adminInfo.CurrentOrgId,
  7206. PatientId: project.PatientId,
  7207. SystemTime: info.SysRecordTime,
  7208. ConsumableType: 7,
  7209. IsSys: 0,
  7210. WarehousingOrder: "",
  7211. WarehouseOutId: info.WarehouseOutId,
  7212. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7213. IsEdit: 0,
  7214. CancelStockId: cancel.ID,
  7215. CancelOrderNumber: cancel.OrderNumber,
  7216. Manufacturer: manufacturer.ID,
  7217. Dealer: 0,
  7218. Creator: adminInfo.AdminUser.Id,
  7219. UpdateCreator: 0,
  7220. Status: 1,
  7221. Ctime: time.Now().Unix(),
  7222. Mtime: 0,
  7223. Price: info.Price,
  7224. WarehousingDetailId: info.WarehouseInfotId,
  7225. WarehouseOutDetailId: info.ID,
  7226. CancelOutDetailId: cancelInfo.ID,
  7227. ProductDate: info.ProductDate,
  7228. ExpireDate: info.ExpiryDate,
  7229. StorehouseId: houseConfig.StorehouseOutInfo,
  7230. OverCount: over_count,
  7231. OperateTime: time.Now().Unix(),
  7232. }
  7233. service.CreateStockFlowOne(flow)
  7234. }
  7235. //查询已出库数量
  7236. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7237. if prescribingNumber < dialysisInfo.Count {
  7238. //改变数量
  7239. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7240. }
  7241. if prescribingNumber >= dialysisInfo.Count {
  7242. //删除出库表
  7243. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7244. }
  7245. //更新剩余库存
  7246. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7247. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7248. var total_count_one int64
  7249. for _, it := range stockList {
  7250. total_count_one += it.StockCount
  7251. }
  7252. //基础库插入数据
  7253. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7254. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7255. var flush_count int64
  7256. for _, it := range goodListOne {
  7257. flush_count += it.StockCount
  7258. }
  7259. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7260. if errs != nil {
  7261. goodErrcode := models.XtGoodErrcode{
  7262. UserOrgId: project.UserOrgId,
  7263. Errcode: "手动出库更新剩余出库失败",
  7264. GoodId: project.ProjectId,
  7265. Status: 1,
  7266. Ctime: time.Now().Unix(),
  7267. Mtime: 0,
  7268. Count: 0,
  7269. StockCount: 0,
  7270. Creater: creater,
  7271. BatchNumberId: 0,
  7272. WarehouseOutId: 0,
  7273. }
  7274. service.CreateGoodErrcode(goodErrcode)
  7275. }
  7276. }
  7277. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7278. fmt.Println(err)
  7279. } else {
  7280. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7281. fmt.Println(err)
  7282. }
  7283. } else {
  7284. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7285. fmt.Println(err)
  7286. }
  7287. }
  7288. //保存处方出库
  7289. if goodOutConfig.IsOpen == 1 {
  7290. if project.Type == 3 {
  7291. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7292. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7293. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7294. operation_time := time.Now().Unix()
  7295. creater := adminInfo.AdminUser.Id
  7296. //创建退库单
  7297. timeStr := time.Now().Format("2006-01-02")
  7298. timeArr := strings.Split(timeStr, "-")
  7299. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7300. total = total + 1
  7301. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7302. cancelStock := models.CancelStock{
  7303. OrderNumber: orderNumber,
  7304. OperaTime: operation_time,
  7305. OrgId: adminInfo.CurrentOrgId,
  7306. Creater: creater,
  7307. Ctime: time.Now().Unix(),
  7308. Status: 1,
  7309. ReturnTime: project.RecordDate,
  7310. Type: 1,
  7311. StorehouseId: houseConfig.StorehouseOutInfo,
  7312. IsCheck: 1,
  7313. }
  7314. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7315. if msgerrkonde == gorm.ErrRecordNotFound {
  7316. service.AddSigleCancelStock(&cancelStock)
  7317. }
  7318. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7319. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7320. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7321. //获取出库数据
  7322. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7323. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7324. deaerler, _ := service.GetDealerById(info.Dealer)
  7325. if info.ID > 0 {
  7326. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7327. if info.Count >= prescribingNumber {
  7328. cancelStockInfo := models.CancelStockInfo{
  7329. GoodId: project.ProjectId,
  7330. CancelStockId: cancel.ID,
  7331. GoodTypeId: good.GoodTypeId,
  7332. Count: prescribingNumber,
  7333. Price: info.Price,
  7334. Total: 0,
  7335. ProductDate: info.ProductDate,
  7336. ExpiryDate: info.ExpiryDate,
  7337. Ctime: time.Now().Unix(),
  7338. Status: 1,
  7339. OrgId: adminInfo.CurrentOrgId,
  7340. OrderNumber: cancel.OrderNumber,
  7341. Type: 0,
  7342. Dealer: deaerler.DealerName,
  7343. Manufacturer: manufacturer.ManufacturerName,
  7344. Number: info.Number,
  7345. RegisterAccount: "",
  7346. Remark: "",
  7347. WarehouseInfoId: info.WarehouseInfotId,
  7348. PatientId: info.PatientId,
  7349. RecordDate: info.SysRecordTime,
  7350. StorehouseId: houseConfig.StorehouseOutInfo,
  7351. IsCheck: 1,
  7352. }
  7353. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7354. //退库数量增加
  7355. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7356. //出库数量减少
  7357. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7358. }
  7359. if info.Count < prescribingNumber {
  7360. cancelStockInfo := models.CancelStockInfo{
  7361. GoodId: project.ProjectId,
  7362. CancelStockId: cancel.ID,
  7363. GoodTypeId: good.GoodTypeId,
  7364. Count: prescribingNumber,
  7365. Price: info.Price,
  7366. Total: 0,
  7367. ProductDate: info.ProductDate,
  7368. ExpiryDate: info.ExpiryDate,
  7369. Ctime: time.Now().Unix(),
  7370. Status: 1,
  7371. OrgId: adminInfo.CurrentOrgId,
  7372. OrderNumber: cancel.OrderNumber,
  7373. Type: 0,
  7374. Dealer: deaerler.DealerName,
  7375. Manufacturer: manufacturer.ManufacturerName,
  7376. Number: info.Number,
  7377. RegisterAccount: "",
  7378. Remark: "",
  7379. WarehouseInfoId: info.WarehouseInfotId,
  7380. PatientId: info.PatientId,
  7381. RecordDate: info.SysRecordTime,
  7382. StorehouseId: houseConfig.StorehouseOutInfo,
  7383. IsCheck: 1,
  7384. }
  7385. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7386. //回退库存
  7387. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7388. }
  7389. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7390. var over_count int64
  7391. for _, it := range goodList {
  7392. over_count += it.StockCount
  7393. }
  7394. //查询出库数量
  7395. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  7396. //出库数据 大于 退库数量
  7397. if len(list) > 0 {
  7398. for _, it := range list {
  7399. //回退库存
  7400. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  7401. //退库数量增加
  7402. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  7403. //出库数量减少
  7404. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  7405. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7406. var over_count_one int64
  7407. for _, it := range goodList {
  7408. over_count_one += it.StockCount
  7409. }
  7410. //查询该批次是否有退库数据
  7411. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  7412. flow := models.VmStockFlow{
  7413. WarehousingId: it.WarehouseInfotId,
  7414. GoodId: it.GoodId,
  7415. Number: it.Number,
  7416. LicenseNumber: it.LicenseNumber,
  7417. Count: it.Count,
  7418. UserOrgId: adminInfo.CurrentOrgId,
  7419. PatientId: it.PatientId,
  7420. SystemTime: it.SysRecordTime,
  7421. ConsumableType: 7,
  7422. IsSys: 0,
  7423. WarehousingOrder: "",
  7424. WarehouseOutId: it.WarehouseOutId,
  7425. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7426. IsEdit: 0,
  7427. CancelStockId: cancel.ID,
  7428. CancelOrderNumber: cancel.OrderNumber,
  7429. Manufacturer: manufacturer.ID,
  7430. Dealer: 0,
  7431. Creator: adminInfo.AdminUser.Id,
  7432. UpdateCreator: 0,
  7433. Status: 1,
  7434. Ctime: time.Now().Unix(),
  7435. Mtime: 0,
  7436. Price: it.Price,
  7437. WarehousingDetailId: it.WarehouseInfotId,
  7438. WarehouseOutDetailId: it.ID,
  7439. CancelOutDetailId: cancelInfo.ID,
  7440. ProductDate: it.ProductDate,
  7441. ExpireDate: it.ExpiryDate,
  7442. StorehouseId: houseConfig.StorehouseOutInfo,
  7443. OverCount: over_count_one,
  7444. OperateTime: time.Now().Unix(),
  7445. }
  7446. service.CreateStockFlowOne(flow)
  7447. }
  7448. }
  7449. //查询已出库数量
  7450. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7451. if prescribingNumber < dialysisInfo.Count {
  7452. //改变数量
  7453. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7454. }
  7455. if prescribingNumber >= dialysisInfo.Count {
  7456. //删除出库表
  7457. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7458. }
  7459. //更新剩余库存
  7460. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7461. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7462. var total_count_one int64
  7463. for _, it := range stockList {
  7464. total_count_one += it.StockCount
  7465. }
  7466. //基础库插入数据
  7467. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7468. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7469. var flush_count int64
  7470. for _, it := range goodListOne {
  7471. flush_count += it.StockCount
  7472. }
  7473. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7474. if errs != nil {
  7475. goodErrcode := models.XtGoodErrcode{
  7476. UserOrgId: project.UserOrgId,
  7477. Errcode: "手动出库更新剩余出库失败",
  7478. GoodId: project.ProjectId,
  7479. Status: 1,
  7480. Ctime: time.Now().Unix(),
  7481. Mtime: 0,
  7482. Count: 0,
  7483. StockCount: 0,
  7484. Creater: creater,
  7485. BatchNumberId: 0,
  7486. WarehouseOutId: 0,
  7487. }
  7488. service.CreateGoodErrcode(goodErrcode)
  7489. }
  7490. }
  7491. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7492. fmt.Println(err)
  7493. } else {
  7494. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7495. fmt.Println(err)
  7496. }
  7497. }
  7498. c.ServeSuccessJSON(map[string]interface{}{
  7499. "msg": "删除成功",
  7500. })
  7501. return
  7502. }
  7503. func (c *HisApiController) CreateHisAdditionalCharge() {
  7504. his_patient_id, _ := c.GetInt64("his_patient_id")
  7505. patient_id, _ := c.GetInt64("patient_id")
  7506. record_date := c.GetString("record_date")
  7507. timeLayout := "2006-01-02"
  7508. loc, _ := time.LoadLocation("Local")
  7509. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7510. if err != nil {
  7511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7512. return
  7513. }
  7514. adminInfo := c.GetAdminUserInfo()
  7515. recordDateTime := theTime.Unix()
  7516. dataBody := make(map[string]interface{}, 0)
  7517. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7518. if err != nil {
  7519. utils.ErrorLog(err.Error())
  7520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7521. return
  7522. }
  7523. var additions []*models.HisAdditionalCharge
  7524. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7525. additions, _ := dataBody["addition"].([]interface{})
  7526. if len(additions) > 0 {
  7527. for _, item := range additions {
  7528. items := item.(map[string]interface{})
  7529. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7530. utils.ErrorLog("item_id")
  7531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7532. return
  7533. }
  7534. item_id := int64(items["item_id"].(float64))
  7535. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7536. utils.ErrorLog("item_name")
  7537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7538. return
  7539. }
  7540. item_name := items["item_name"].(string)
  7541. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7542. utils.ErrorLog("price")
  7543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7544. return
  7545. }
  7546. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7547. ctime := time.Now().Unix()
  7548. additional := &models.HisAdditionalCharge{
  7549. PatientId: patient_id,
  7550. HisPatientId: his_patient_id,
  7551. UserOrgId: adminInfo.CurrentOrgId,
  7552. RecordDate: recordDateTime,
  7553. CreatedTime: ctime,
  7554. UpdatedTime: ctime,
  7555. Modifier: adminInfo.AdminUser.Id,
  7556. Creator: adminInfo.AdminUser.Id,
  7557. Price: price,
  7558. ItemName: item_name,
  7559. ItemId: item_id,
  7560. Status: 1,
  7561. }
  7562. additions = append(additions, additional)
  7563. }
  7564. }
  7565. }
  7566. for _, item := range additions {
  7567. service.CreateAddtionalCharge(item)
  7568. }
  7569. c.ServeSuccessJSON(map[string]interface{}{
  7570. "msg": "创建成功",
  7571. })
  7572. }
  7573. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7574. blood_fat := c.GetString("blood_fat")
  7575. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7576. blood_sugar := c.GetString("blood_sugar")
  7577. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7578. chief_conplaint := c.GetString("chief_conplaint")
  7579. dbp := c.GetString("dbp")
  7580. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7581. delivery_way, _ := c.GetInt64("delivery_way")
  7582. diagnostic := c.GetString("diagnostic")
  7583. family_history := c.GetString("family_history")
  7584. height := c.GetString("height")
  7585. history_of_present_illness := c.GetString("history_of_present_illness")
  7586. is_infect, _ := c.GetInt64("is_infect")
  7587. past_history := c.GetString("past_history")
  7588. patient_id, _ := c.GetInt64("patient_id")
  7589. his_patient_id, _ := c.GetInt64("his_patient_id")
  7590. personal_history := c.GetString("personal_history")
  7591. pulse := c.GetString("pulse")
  7592. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7593. sbp := c.GetString("sbp")
  7594. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7595. heightfloat, _ := strconv.ParseFloat(height, 64)
  7596. sicktype := c.GetString("sick_type")
  7597. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7598. symptom := c.GetString("symptom")
  7599. sick_date := c.GetString("sick_date")
  7600. temperatures := c.GetString("temperature")
  7601. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7602. record_date := c.GetString("record_date")
  7603. breathing := c.GetString("breathing")
  7604. doctor_advice := c.GetString("doctor_advice")
  7605. remark := c.GetString("remark")
  7606. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7607. sick, _ := c.GetInt64("sick")
  7608. diagnose, _ := c.GetInt64("diagnose")
  7609. //id, _ := c.GetInt64("id")
  7610. timeLayout := "2006-01-02"
  7611. loc, _ := time.LoadLocation("Local")
  7612. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7613. allergic_history := c.GetString("allergic_history")
  7614. if err != nil {
  7615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7616. return
  7617. }
  7618. recordDateTime := theTime.Unix()
  7619. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7620. if err != nil {
  7621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7622. return
  7623. }
  7624. sickTimes := sickTime.Unix()
  7625. ctime := time.Now().Unix()
  7626. primary_disease := c.GetString("primary_disease")
  7627. confirm_failure_date := c.GetString("confirm_failure_date")
  7628. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7629. drug_allergy_history := c.GetString("drug_allergy_history")
  7630. physical_examination := c.GetString("physical_examination")
  7631. special_inspection := c.GetString("special_inspection")
  7632. lab_apparatus := c.GetString("lab_apparatus")
  7633. caseHistory := models.HisPatientCaseHistory{
  7634. HisPatientId: his_patient_id,
  7635. PatientId: patient_id,
  7636. Temperature: temperature,
  7637. BloodSugar: bloodsugarfloat,
  7638. Pulse: pulsefloat,
  7639. Sbp: sbpfloat,
  7640. Dbp: dbpfloat,
  7641. Height: heightfloat,
  7642. BloodFat: bloodfatfloat,
  7643. SickType: sick_type,
  7644. Symptom: symptom,
  7645. SickDate: sickTimes,
  7646. IsInfect: is_infect,
  7647. HistoryOfPresentIllness: history_of_present_illness,
  7648. PastHistory: past_history,
  7649. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7650. ChiefConplaint: chief_conplaint,
  7651. PersonalHistory: personal_history,
  7652. FamilyHistory: family_history,
  7653. Diagnostic: diagnostic,
  7654. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7655. Status: 1,
  7656. Ctime: ctime,
  7657. Mtime: ctime,
  7658. RecordDate: recordDateTime,
  7659. DeliveryWay: delivery_way,
  7660. Breathing: breathingfloat,
  7661. DoctorAdvice: doctor_advice,
  7662. Remark: remark,
  7663. Sick: sick,
  7664. Diagnose: diagnose,
  7665. AllergicHistory: allergic_history,
  7666. PrimaryDisease: primary_disease,
  7667. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7668. DrugAllergyHistory: drug_allergy_history,
  7669. PhysicalExamination: physical_examination,
  7670. SpecialInspection: special_inspection,
  7671. LabApparatus: lab_apparatus,
  7672. }
  7673. //查询该患者是否有病历
  7674. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7675. if errcodes == gorm.ErrRecordNotFound {
  7676. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7677. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7678. if err != nil {
  7679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7680. return
  7681. }
  7682. c.ServeSuccessJSON(map[string]interface{}{
  7683. "caseHistory": caseHistory,
  7684. "historyInfo": historyInfo,
  7685. })
  7686. return
  7687. } else if errcodes == nil {
  7688. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7689. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7690. if err != nil {
  7691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7692. return
  7693. }
  7694. c.ServeSuccessJSON(map[string]interface{}{
  7695. "caseHistory": caseHistory,
  7696. "historyInfo": historyInfo,
  7697. })
  7698. }
  7699. //查询该患者是否有病历
  7700. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7701. //if errcode == gorm.ErrRecordNotFound {
  7702. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7703. // if err != nil {
  7704. // c.ServeSuccessJSON(map[string]interface{}{
  7705. // "msg": "保存成功",
  7706. // })
  7707. // }
  7708. //} else if errcode == nil {
  7709. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7710. // return
  7711. //}
  7712. }
  7713. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7714. patient_id, _ := c.GetInt64("patient_id", 0)
  7715. adminUser := c.GetAdminUserInfo()
  7716. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7717. c.ServeSuccessJSON(map[string]interface{}{
  7718. "list": caseHistorys,
  7719. })
  7720. }
  7721. func (c *HisApiController) GetHisPatientCaseHistory() {
  7722. record_date, _ := c.GetInt64("record_date", 0)
  7723. patient_id, _ := c.GetInt64("patient_id", 0)
  7724. admin := c.GetAdminUserInfo()
  7725. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7726. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7727. c.ServeSuccessJSON(map[string]interface{}{
  7728. "info": info,
  7729. "case_history": case_history,
  7730. })
  7731. }
  7732. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7733. template_name := c.GetString("template_name")
  7734. template_remark := c.GetString("template_remark")
  7735. doctor := c.GetAdminUserInfo().AdminUser.Id
  7736. diagnostic := c.GetString("diagnostic")
  7737. chief_conplaint := c.GetString("chief_conplain")
  7738. history_of_present_illness := c.GetString("history_of_present_illness")
  7739. past_history := c.GetString("past_history")
  7740. personal_history := c.GetString("personal_history")
  7741. family_history := c.GetString("family_history")
  7742. user_name := c.GetString("user_name")
  7743. doctor_advice := c.GetString("doctor_advice")
  7744. remark := c.GetString("remark")
  7745. //record_date := c.GetString("record_date")
  7746. //fmt.Println("record_date--------",record_date)
  7747. //timeLayout := "2006-01-02"
  7748. //loc, _ := time.LoadLocation("Local")
  7749. //
  7750. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7751. //if err != nil {
  7752. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7753. // return
  7754. //}
  7755. //recordDateTime := theTime.Unix()
  7756. ctime := time.Now().Unix()
  7757. template := models.HisCaseHistoryTemplate{
  7758. HistoryOfPresentIllness: history_of_present_illness,
  7759. PastHistory: past_history,
  7760. ChiefConplaint: chief_conplaint,
  7761. PersonalHistory: personal_history,
  7762. FamilyHistory: family_history,
  7763. Diagnostic: diagnostic,
  7764. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7765. Status: 1,
  7766. Ctime: ctime,
  7767. Mtime: ctime,
  7768. RecordDate: time.Now().Unix(),
  7769. TemplateName: template_name,
  7770. TemplateRemark: template_remark,
  7771. Creator: doctor,
  7772. Modifier: doctor,
  7773. UserName: user_name,
  7774. DoctorAdvice: doctor_advice,
  7775. Remark: remark,
  7776. }
  7777. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7778. if err == nil {
  7779. c.ServeSuccessJSON(map[string]interface{}{
  7780. "msg": "保存成功",
  7781. })
  7782. } else {
  7783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7784. return
  7785. }
  7786. }
  7787. func (c *HisApiController) GetCaseHistoryTemplate() {
  7788. timeLayout := "2006-01-02"
  7789. loc, _ := time.LoadLocation("Local")
  7790. keyword := c.GetString("keyword")
  7791. start_time := c.GetString("start_time")
  7792. end_time := c.GetString("end_time")
  7793. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7794. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7795. admin := c.GetAdminUserInfo()
  7796. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7797. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7798. c.ServeSuccessJSON(map[string]interface{}{
  7799. "template": template,
  7800. //"history": history,
  7801. })
  7802. }
  7803. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7804. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7805. utils.ErrorLog("drug_name")
  7806. return enums.ErrorCodeParamWrong
  7807. }
  7808. adviceName, _ := json["drug_name"].(string)
  7809. if len(adviceName) == 0 {
  7810. utils.ErrorLog("len(advice_name) == 0")
  7811. return enums.ErrorCodeParamWrong
  7812. }
  7813. advice.AdviceName = adviceName
  7814. adviceDesc, _ := json["advice_desc"].(string)
  7815. advice.AdviceDesc = adviceDesc
  7816. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7817. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7818. advice.DrugSpec = drugSpec
  7819. }
  7820. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7821. remark, _ := json["remark"].(string)
  7822. advice.Remark = remark
  7823. }
  7824. if json["id"] == nil {
  7825. advice.DrugId = 0
  7826. } else {
  7827. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7828. drug_id := int64(json["id"].(float64))
  7829. advice.DrugId = drug_id
  7830. }
  7831. }
  7832. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7833. advice_id := int64(json["advice_id"].(float64))
  7834. advice.ID = advice_id
  7835. if advice.ID > 0 {
  7836. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7837. if err == nil {
  7838. if hisAdvice.ID > 0 {
  7839. advice.ExecutionTime = hisAdvice.ExecutionTime
  7840. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7841. advice.ExecutionState = hisAdvice.ExecutionState
  7842. advice.CheckTime = hisAdvice.CheckTime
  7843. advice.Checker = hisAdvice.Checker
  7844. advice.CheckState = hisAdvice.CheckState
  7845. advice.StartTime = hisAdvice.StartTime
  7846. advice.FeedetlSn = hisAdvice.FeedetlSn
  7847. }
  7848. }
  7849. }
  7850. }
  7851. //
  7852. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7853. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7854. // advice.ExecutionTime = execution_time
  7855. //}
  7856. //
  7857. //
  7858. //
  7859. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7860. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7861. // advice.ExecutionStaff = execution_staff
  7862. //}
  7863. //
  7864. //
  7865. //
  7866. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7867. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7868. // advice.ExecutionState = execution_state
  7869. //}
  7870. //
  7871. //
  7872. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7873. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7874. // advice.CheckTime = check_time
  7875. //}
  7876. //
  7877. //
  7878. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7879. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7880. // advice.CheckState = check_state
  7881. //}
  7882. //
  7883. //
  7884. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7885. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7886. // advice.Checker = checker
  7887. //}
  7888. //
  7889. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7890. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7891. // advice.StartTime = start_time
  7892. //}
  7893. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7894. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7895. advice.IsSelfDrug = is_self_drug
  7896. }
  7897. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7898. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7899. drug_way_count, _ := json["drug_way_count"].(string)
  7900. advice.DrugWayCount = drug_way_count
  7901. }
  7902. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7903. drugSpecUnit, _ := json["min_unit"].(string)
  7904. advice.DrugSpecUnit = drugSpecUnit
  7905. }
  7906. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7907. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7908. advice.SingleDose = singleDose
  7909. }
  7910. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7911. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7912. advice.SingleDoseUnit = singleDoseUnit
  7913. }
  7914. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7915. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7916. advice.PrescribingNumber = prescribingNumber
  7917. }
  7918. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7919. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7920. advice.PrescribingNumberUnit = prescribingNumberUnit
  7921. }
  7922. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7923. deliveryWay, _ := json["delivery_way"].(string)
  7924. advice.DeliveryWay = deliveryWay
  7925. }
  7926. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7927. executionFrequency, _ := json["execution_frequency"].(string)
  7928. advice.ExecutionFrequency = executionFrequency
  7929. }
  7930. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7931. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7932. advice.Price = price
  7933. }
  7934. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7935. med_list_codg, _ := json["medical_insurance_number"].(string)
  7936. advice.MedListCodg = med_list_codg
  7937. }
  7938. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7939. day := int64(json["day"].(float64))
  7940. advice.Day = day
  7941. }
  7942. return 0
  7943. }
  7944. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7945. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7946. id := int64(json["id"].(float64))
  7947. project.ID = id
  7948. historyProject, _ := service.GetHisProjectByID(id)
  7949. project.FeedetlSn = historyProject.FeedetlSn
  7950. }
  7951. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7952. project_id := int64(json["project_id"].(float64))
  7953. project.ProjectId = project_id
  7954. }
  7955. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7956. // price := int64(json["price"].(float64))
  7957. // formatInt_price := strconv.FormatInt(price, 10)
  7958. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7959. // project.Price = float_price
  7960. // }
  7961. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7962. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7963. project.Price = price
  7964. }
  7965. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7966. total, _ := json["total"].(string)
  7967. project.Count = total
  7968. }
  7969. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7970. medical_code, _ := json["medical_code"].(string)
  7971. project.MedListCodg = medical_code
  7972. }
  7973. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7974. single_dose, _ := json["single_dose"].(string)
  7975. project.SingleDose = single_dose
  7976. }
  7977. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7978. delivery_way, _ := json["delivery_way"].(string)
  7979. project.DeliveryWay = delivery_way
  7980. }
  7981. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7982. execution_frequency, _ := json["execution_frequency"].(string)
  7983. project.ExecutionFrequency = execution_frequency
  7984. }
  7985. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7986. remark, _ := json["remark"].(string)
  7987. project.Remark = remark
  7988. }
  7989. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7990. day, _ := json["number_days"].(string)
  7991. project.Day = day
  7992. }
  7993. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7994. unit, _ := json["unit"].(string)
  7995. project.Unit = unit
  7996. }
  7997. return 0
  7998. }
  7999. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8000. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8001. id := int64(json["id"].(float64))
  8002. historyAddtions, _ := service.GetHisAdditionByID(id)
  8003. additionalCharge.ID = id
  8004. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  8005. }
  8006. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8007. item_id := int64(json["item_id"].(float64))
  8008. additionalCharge.ItemId = item_id
  8009. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8010. if config.ID > 0 {
  8011. if len(config.Code) > 0 {
  8012. additionalCharge.MedListCodg = config.Code
  8013. }
  8014. }
  8015. }
  8016. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8017. // price := int64(json["price"].(float64))
  8018. // formatInt_price := strconv.FormatInt(price, 10)
  8019. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8020. // additionalCharge.Price = float_price
  8021. // }
  8022. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8023. // price := int64(json["price"].(float64))
  8024. // formatInt_price := strconv.FormatInt(price, 10)
  8025. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8026. // additionalCharge.Price = float_price
  8027. //}
  8028. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8029. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8030. additionalCharge.Price = price
  8031. }
  8032. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8033. count, _ := json["count"].(string)
  8034. counts, _ := strconv.ParseInt(count, 10, 64)
  8035. additionalCharge.Count = counts
  8036. }
  8037. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8038. item_name, _ := json["item_name"].(string)
  8039. additionalCharge.ItemName = item_name
  8040. }
  8041. return 0
  8042. }
  8043. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8044. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8045. utils.ErrorLog("drug_name")
  8046. return enums.ErrorCodeParamWrong
  8047. }
  8048. adviceName, _ := json["drug_name"].(string)
  8049. if len(adviceName) == 0 {
  8050. utils.ErrorLog("len(advice_name) == 0")
  8051. return enums.ErrorCodeParamWrong
  8052. }
  8053. advice.AdviceName = adviceName
  8054. adviceDesc, _ := json["advice_desc"].(string)
  8055. advice.AdviceDesc = adviceDesc
  8056. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8057. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8058. advice.DrugSpec = drugSpec
  8059. }
  8060. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8061. remark, _ := json["remark"].(string)
  8062. advice.Remark = remark
  8063. }
  8064. if json["id"] == nil {
  8065. advice.DrugId = 0
  8066. } else {
  8067. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8068. drug_id := int64(json["id"].(float64))
  8069. advice.DrugId = drug_id
  8070. }
  8071. }
  8072. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8073. groupno := int64(json["groupno"].(float64))
  8074. advice.Groupno = groupno
  8075. }
  8076. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8077. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8078. advice.IsSelfDrug = is_self_drug
  8079. }
  8080. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8081. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8082. drug_way_count, _ := json["drug_way_count"].(string)
  8083. advice.DrugWayCount = drug_way_count
  8084. }
  8085. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8086. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8087. advice.HospApprFlag = hosp_appr_flag
  8088. }
  8089. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8090. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8091. advice.PrescribingNumber = prescribingNumber
  8092. }
  8093. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8094. // frequency_type := int64(json["frequency_type"].(float64))
  8095. // advice.FrequencyType = frequency_type
  8096. //}
  8097. //
  8098. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8099. // day_count := int64(json["day_count"].(float64))
  8100. // advice.DayCount = day_count
  8101. //}
  8102. //
  8103. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8104. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8105. // week_day, _ := json["week_day"].(string)
  8106. // advice.WeekDay = week_day
  8107. //}
  8108. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8109. drugSpecUnit, _ := json["min_unit"].(string)
  8110. advice.DrugSpecUnit = drugSpecUnit
  8111. }
  8112. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8113. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8114. advice.SingleDose = singleDose
  8115. }
  8116. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8117. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8118. advice.SingleDoseUnit = singleDoseUnit
  8119. }
  8120. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8121. deliveryWay, _ := json["delivery_way"].(string)
  8122. advice.DeliveryWay = deliveryWay
  8123. }
  8124. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8125. executionFrequency, _ := json["execution_frequency"].(string)
  8126. advice.ExecutionFrequency = executionFrequency
  8127. }
  8128. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8129. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8130. advice.Price = price
  8131. }
  8132. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8133. med_list_codg, _ := json["medical_insurance_number"].(string)
  8134. advice.MedListCodg = med_list_codg
  8135. }
  8136. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8137. day := int64(json["day"].(float64))
  8138. advice.Day = day
  8139. }
  8140. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8141. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8142. advice.PrescribingNumberUnit = prescribingNumberUnit
  8143. }
  8144. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8145. advice_id := int64(json["advice_id"].(float64))
  8146. advice.ID = advice_id
  8147. if advice.ID > 0 {
  8148. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8149. if err == nil {
  8150. if hisAdvice.ID > 0 {
  8151. advice.ExecutionTime = hisAdvice.ExecutionTime
  8152. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8153. advice.ExecutionState = hisAdvice.ExecutionState
  8154. advice.CheckTime = hisAdvice.CheckTime
  8155. advice.Checker = hisAdvice.Checker
  8156. advice.CheckState = hisAdvice.CheckState
  8157. advice.StartTime = hisAdvice.StartTime
  8158. advice.HospApprFlag = hisAdvice.HospApprFlag
  8159. advice.IsMedicine = hisAdvice.IsMedicine
  8160. if hisAdvice.UserOrgId == 10028 {
  8161. 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 {
  8162. advice.ExecutionTime = 0
  8163. advice.ExecutionStaff = 0
  8164. advice.ExecutionState = 2
  8165. advice.CheckTime = 0
  8166. advice.Checker = 0
  8167. advice.CheckState = 2
  8168. }
  8169. } else {
  8170. 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 {
  8171. advice.ExecutionTime = 0
  8172. advice.ExecutionStaff = 0
  8173. advice.ExecutionState = 2
  8174. advice.CheckTime = 0
  8175. advice.Checker = 0
  8176. advice.CheckState = 2
  8177. advice.UpdatedTime = time.Now().Unix()
  8178. }
  8179. }
  8180. //advice.Groupno = hisAdvice.Groupno
  8181. }
  8182. }
  8183. }
  8184. }
  8185. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8186. //
  8187. //if drugStockConfig.IsOpen == 1 {
  8188. //
  8189. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8190. // if advice.ID == 0 { //医嘱不存在
  8191. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8192. // drug.Total = drug.Total - advice.PrescribingNumber
  8193. // service.UpdateBaseDrugLib(&drug)
  8194. //
  8195. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8196. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8197. // drug.Total = drug.Total - num
  8198. // service.UpdateBaseDrugLib(&drug)
  8199. // }
  8200. //
  8201. // } else if advice.ID > 0 { //医嘱存在
  8202. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8203. // var num float64
  8204. //
  8205. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8206. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8207. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8208. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8209. // drug.Total = drug.Total + num
  8210. // service.UpdateBaseDrugLib(&drug)
  8211. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8212. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8213. // drug.Total = drug.Total - num
  8214. // service.UpdateBaseDrugLib(&drug)
  8215. // }
  8216. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8217. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8218. // if num2 > advice.PrescribingNumber {
  8219. // num = num2 - advice.PrescribingNumber
  8220. // drug.Total = drug.Total + num
  8221. // service.UpdateBaseDrugLib(&drug)
  8222. // } else if num2 < advice.PrescribingNumber {
  8223. // num = advice.PrescribingNumber - num2
  8224. // drug.Total = drug.Total - num
  8225. // service.UpdateBaseDrugLib(&drug)
  8226. // }
  8227. //
  8228. // }
  8229. //
  8230. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8231. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8232. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8233. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8234. // if num1 > num2 {
  8235. // num = num1 - num2
  8236. // drug.Total = drug.Total + num
  8237. // service.UpdateBaseDrugLib(&drug)
  8238. // } else if num1 < num2 {
  8239. // num = num2 - num1
  8240. // drug.Total = drug.Total - num
  8241. // service.UpdateBaseDrugLib(&drug)
  8242. // }
  8243. //
  8244. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8245. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8246. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8247. // if hisAdvice.PrescribingNumber > num2 {
  8248. // num = hisAdvice.PrescribingNumber - num2
  8249. // drug.Total = drug.Total + num
  8250. // service.UpdateBaseDrugLib(&drug)
  8251. // } else if num2 < advice.PrescribingNumber {
  8252. // num = num2 - hisAdvice.PrescribingNumber
  8253. // drug.Total = drug.Total - num
  8254. // service.UpdateBaseDrugLib(&drug)
  8255. // }
  8256. //
  8257. // }
  8258. // }
  8259. // }
  8260. //}
  8261. //
  8262. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8263. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8264. // advice.ExecutionTime = execution_time
  8265. //}
  8266. //
  8267. //
  8268. //
  8269. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8270. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8271. // advice.ExecutionStaff = execution_staff
  8272. //}
  8273. //
  8274. //
  8275. //
  8276. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8277. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8278. // advice.ExecutionState = execution_state
  8279. //}
  8280. //
  8281. //
  8282. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8283. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8284. // advice.CheckTime = check_time
  8285. //}
  8286. //
  8287. //
  8288. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8289. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8290. // advice.CheckState = check_state
  8291. //}
  8292. //
  8293. //
  8294. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8295. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8296. // advice.Checker = checker
  8297. //}
  8298. //
  8299. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8300. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8301. // advice.StartTime = start_time
  8302. //}
  8303. return 0
  8304. }
  8305. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8306. project.ExecutionStaff = 0
  8307. project.ExecutionState = 2
  8308. project.ExecutionTime = 0
  8309. project.Checker = 0
  8310. project.CheckState = 2
  8311. project.CheckTime = 0
  8312. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8313. id := int64(json["id"].(float64))
  8314. project.ID = id
  8315. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8316. project.ExecutionStaff = temp_project.ExecutionStaff
  8317. project.ExecutionState = temp_project.ExecutionState
  8318. project.ExecutionTime = temp_project.ExecutionTime
  8319. project.Checker = temp_project.Checker
  8320. project.CheckState = temp_project.CheckState
  8321. project.CheckTime = temp_project.CheckTime
  8322. project.TeamId = temp_project.TeamId
  8323. }
  8324. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8325. types := int64(json["type"].(float64))
  8326. project.Type = types
  8327. }
  8328. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8329. project_id := int64(json["project_id"].(float64))
  8330. project.ProjectId = project_id
  8331. }
  8332. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8333. team_id := int64(json["team_id"].(float64))
  8334. project.TeamId = team_id
  8335. }
  8336. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8337. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8338. project.Price = price
  8339. }
  8340. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8341. total, _ := json["total"].(string)
  8342. //totals, _ := strconv.ParseInt(total, 10, 64)
  8343. project.Count = total
  8344. }
  8345. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8346. medical_code, _ := json["medical_code"].(string)
  8347. project.MedListCodg = medical_code
  8348. }
  8349. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8350. single_dose, _ := json["single_dose"].(string)
  8351. project.SingleDose = single_dose
  8352. }
  8353. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8354. delivery_way, _ := json["delivery_way"].(string)
  8355. project.DeliveryWay = delivery_way
  8356. }
  8357. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8358. execution_frequency, _ := json["execution_frequency"].(string)
  8359. project.ExecutionFrequency = execution_frequency
  8360. }
  8361. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8362. remark, _ := json["remark"].(string)
  8363. project.Remark = remark
  8364. }
  8365. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8366. day, _ := json["number_days"].(string)
  8367. project.Day = day
  8368. }
  8369. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8370. unit, _ := json["unit"].(string)
  8371. project.Unit = unit
  8372. }
  8373. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8374. // frequency_type := int64(json["frequency_type"].(float64))
  8375. // project.FrequencyType = frequency_type
  8376. //}
  8377. //
  8378. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8379. // day_count := int64(json["day_count"].(float64))
  8380. // project.DayCount = day_count
  8381. //}
  8382. //
  8383. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8384. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8385. // week_day, _ := json["week_day"].(string)
  8386. // project.WeekDay = week_day
  8387. //}
  8388. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8389. //
  8390. //if project.ID == 0 {
  8391. // if stockConfig.IsOpen == 1 {
  8392. // if project.Type == 3 {
  8393. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8394. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8395. // good.Total = good.Total - f_count
  8396. // service.UpdateGoodInfo(&good)
  8397. // }
  8398. // }
  8399. //
  8400. //} else {
  8401. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8402. //
  8403. // if stockConfig.IsOpen == 1 {
  8404. // if project.Type == 3 {
  8405. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8406. // if project.Count < temp_project.Count {
  8407. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8408. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8409. //
  8410. // other_count := f_count_two - f_count_one
  8411. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8412. // good.Total = good.Total + other_count_two
  8413. // service.UpdateGoodInfo(&good)
  8414. // } else if project.Count > temp_project.Count {
  8415. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8416. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8417. //
  8418. // other_count := f_count_one - f_count_two
  8419. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8420. // good.Total = good.Total - other_count_two
  8421. // service.UpdateGoodInfo(&good)
  8422. // }
  8423. //
  8424. // }
  8425. // }
  8426. //
  8427. //}
  8428. return 0
  8429. }
  8430. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8431. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8432. utils.ErrorLog("drug_name")
  8433. return enums.ErrorCodeParamWrong
  8434. }
  8435. adviceName, _ := json["drug_name"].(string)
  8436. if len(adviceName) == 0 {
  8437. utils.ErrorLog("len(advice_name) == 0")
  8438. return enums.ErrorCodeParamWrong
  8439. }
  8440. advice.AdviceName = adviceName
  8441. adviceDesc, _ := json["advice_desc"].(string)
  8442. advice.AdviceDesc = adviceDesc
  8443. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8444. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8445. advice.DrugSpec = drugSpec
  8446. }
  8447. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8448. remark, _ := json["remark"].(string)
  8449. advice.Remark = remark
  8450. }
  8451. if json["id"] == nil {
  8452. advice.DrugId = 0
  8453. } else {
  8454. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8455. drug_id := int64(json["id"].(float64))
  8456. advice.DrugId = drug_id
  8457. }
  8458. }
  8459. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8460. groupno := int64(json["groupno"].(float64))
  8461. advice.Groupno = groupno
  8462. }
  8463. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8464. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8465. advice.IsSelfDrug = is_self_drug
  8466. }
  8467. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8468. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8469. drug_way_count, _ := json["drug_way_count"].(string)
  8470. advice.DrugWayCount = drug_way_count
  8471. }
  8472. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8473. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8474. advice.HospApprFlag = hosp_appr_flag
  8475. }
  8476. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8477. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8478. advice.PrescribingNumber = prescribingNumber
  8479. }
  8480. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8481. // frequency_type := int64(json["frequency_type"].(float64))
  8482. // advice.FrequencyType = frequency_type
  8483. //}
  8484. //
  8485. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8486. // day_count := int64(json["day_count"].(float64))
  8487. // advice.DayCount = day_count
  8488. //}
  8489. //
  8490. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8491. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8492. // week_day, _ := json["week_day"].(string)
  8493. // advice.WeekDay = week_day
  8494. //}
  8495. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8496. drugSpecUnit, _ := json["min_unit"].(string)
  8497. advice.DrugSpecUnit = drugSpecUnit
  8498. }
  8499. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8500. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8501. advice.SingleDose = singleDose
  8502. }
  8503. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8504. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8505. advice.SingleDoseUnit = singleDoseUnit
  8506. }
  8507. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8508. deliveryWay, _ := json["delivery_way"].(string)
  8509. advice.DeliveryWay = deliveryWay
  8510. }
  8511. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8512. executionFrequency, _ := json["execution_frequency"].(string)
  8513. advice.ExecutionFrequency = executionFrequency
  8514. }
  8515. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8516. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8517. advice.Price = price
  8518. }
  8519. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8520. med_list_codg, _ := json["medical_insurance_number"].(string)
  8521. advice.MedListCodg = med_list_codg
  8522. }
  8523. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8524. day := int64(json["day"].(float64))
  8525. advice.Day = day
  8526. }
  8527. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8528. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8529. advice.PrescribingNumberUnit = prescribingNumberUnit
  8530. }
  8531. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8532. advice_id := int64(json["advice_id"].(float64))
  8533. advice.ID = advice_id
  8534. if advice.ID > 0 {
  8535. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8536. if err == nil {
  8537. if hisAdvice.ID > 0 {
  8538. advice.ExecutionTime = hisAdvice.ExecutionTime
  8539. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8540. advice.ExecutionState = hisAdvice.ExecutionState
  8541. advice.CheckTime = hisAdvice.CheckTime
  8542. advice.Checker = hisAdvice.Checker
  8543. advice.DrugCode = hisAdvice.DrugCode
  8544. advice.CheckState = hisAdvice.CheckState
  8545. advice.StartTime = hisAdvice.StartTime
  8546. advice.HospApprFlag = hisAdvice.HospApprFlag
  8547. advice.IsMedicine = hisAdvice.IsMedicine
  8548. if hisAdvice.UserOrgId == 10028 {
  8549. 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 {
  8550. advice.ExecutionTime = 0
  8551. advice.ExecutionStaff = 0
  8552. advice.ExecutionState = 2
  8553. advice.CheckTime = 0
  8554. advice.Checker = 0
  8555. advice.CheckState = 2
  8556. }
  8557. } else {
  8558. if hisAdvice.SingleDoseUnit != advice.SingleDoseUnit || 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 {
  8559. advice.ExecutionTime = 0
  8560. advice.ExecutionStaff = 0
  8561. advice.ExecutionState = 2
  8562. advice.CheckTime = 0
  8563. advice.Checker = 0
  8564. advice.CheckState = 2
  8565. //advice.UpdatedTime = time.Now().Unix()
  8566. advice.CreatedTime = hisAdvice.CreatedTime
  8567. advice.UpdatedTime = time.Now().Unix()
  8568. } else {
  8569. advice.CreatedTime = hisAdvice.CreatedTime
  8570. advice.UpdatedTime = hisAdvice.UpdatedTime
  8571. }
  8572. }
  8573. //advice.Groupno = hisAdvice.Groupno
  8574. } else {
  8575. advice.IsMedicine = 0
  8576. ctime := time.Now().Unix()
  8577. advice.CreatedTime = ctime
  8578. advice.UpdatedTime = ctime
  8579. }
  8580. }
  8581. } else {
  8582. advice.IsMedicine = 0
  8583. ctime := time.Now().Unix()
  8584. advice.CreatedTime = ctime
  8585. advice.UpdatedTime = ctime
  8586. }
  8587. }
  8588. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8589. //
  8590. //if drugStockConfig.IsOpen == 1 {
  8591. //
  8592. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8593. // if advice.ID == 0 { //医嘱不存在
  8594. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8595. // drug.Total = drug.Total - advice.PrescribingNumber
  8596. // service.UpdateBaseDrugLib(&drug)
  8597. //
  8598. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8599. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8600. // drug.Total = drug.Total - num
  8601. // service.UpdateBaseDrugLib(&drug)
  8602. // }
  8603. //
  8604. // } else if advice.ID > 0 { //医嘱存在
  8605. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8606. // var num float64
  8607. //
  8608. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8609. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8610. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8611. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8612. // drug.Total = drug.Total + num
  8613. // service.UpdateBaseDrugLib(&drug)
  8614. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8615. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8616. // drug.Total = drug.Total - num
  8617. // service.UpdateBaseDrugLib(&drug)
  8618. // }
  8619. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8620. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8621. // if num2 > advice.PrescribingNumber {
  8622. // num = num2 - advice.PrescribingNumber
  8623. // drug.Total = drug.Total + num
  8624. // service.UpdateBaseDrugLib(&drug)
  8625. // } else if num2 < advice.PrescribingNumber {
  8626. // num = advice.PrescribingNumber - num2
  8627. // drug.Total = drug.Total - num
  8628. // service.UpdateBaseDrugLib(&drug)
  8629. // }
  8630. //
  8631. // }
  8632. //
  8633. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8634. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8635. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8636. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8637. // if num1 > num2 {
  8638. // num = num1 - num2
  8639. // drug.Total = drug.Total + num
  8640. // service.UpdateBaseDrugLib(&drug)
  8641. // } else if num1 < num2 {
  8642. // num = num2 - num1
  8643. // drug.Total = drug.Total - num
  8644. // service.UpdateBaseDrugLib(&drug)
  8645. // }
  8646. //
  8647. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8648. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8649. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8650. // if hisAdvice.PrescribingNumber > num2 {
  8651. // num = hisAdvice.PrescribingNumber - num2
  8652. // drug.Total = drug.Total + num
  8653. // service.UpdateBaseDrugLib(&drug)
  8654. // } else if num2 < advice.PrescribingNumber {
  8655. // num = num2 - hisAdvice.PrescribingNumber
  8656. // drug.Total = drug.Total - num
  8657. // service.UpdateBaseDrugLib(&drug)
  8658. // }
  8659. //
  8660. // }
  8661. // }
  8662. // }
  8663. //}
  8664. //
  8665. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8666. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8667. // advice.ExecutionTime = execution_time
  8668. //}
  8669. //
  8670. //
  8671. //
  8672. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8673. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8674. // advice.ExecutionStaff = execution_staff
  8675. //}
  8676. //
  8677. //
  8678. //
  8679. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8680. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8681. // advice.ExecutionState = execution_state
  8682. //}
  8683. //
  8684. //
  8685. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8686. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8687. // advice.CheckTime = check_time
  8688. //}
  8689. //
  8690. //
  8691. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8692. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8693. // advice.CheckState = check_state
  8694. //}
  8695. //
  8696. //
  8697. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8698. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8699. // advice.Checker = checker
  8700. //}
  8701. //
  8702. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8703. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8704. // advice.StartTime = start_time
  8705. //}
  8706. return 0
  8707. }
  8708. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8709. project.ExecutionStaff = 0
  8710. project.ExecutionState = 2
  8711. project.ExecutionTime = 0
  8712. project.Checker = 0
  8713. project.CheckState = 2
  8714. project.CheckTime = 0
  8715. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8716. id := int64(json["id"].(float64))
  8717. project.ID = id
  8718. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8719. project.ExecutionStaff = temp_project.ExecutionStaff
  8720. project.ExecutionState = temp_project.ExecutionState
  8721. project.ExecutionTime = temp_project.ExecutionTime
  8722. project.Checker = temp_project.Checker
  8723. project.CheckState = temp_project.CheckState
  8724. project.CheckTime = temp_project.CheckTime
  8725. project.TeamId = temp_project.TeamId
  8726. }
  8727. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8728. types := int64(json["type"].(float64))
  8729. project.Type = types
  8730. }
  8731. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8732. project_id := int64(json["project_id"].(float64))
  8733. project.ProjectId = project_id
  8734. }
  8735. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8736. team_id := int64(json["team_id"].(float64))
  8737. project.TeamId = team_id
  8738. }
  8739. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8740. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8741. project.Price = price
  8742. }
  8743. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8744. total, _ := json["total"].(string)
  8745. //totals, _ := strconv.ParseInt(total, 10, 64)
  8746. project.Count = total
  8747. }
  8748. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8749. medical_code, _ := json["medical_code"].(string)
  8750. project.MedListCodg = medical_code
  8751. }
  8752. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8753. single_dose, _ := json["single_dose"].(string)
  8754. project.SingleDose = single_dose
  8755. }
  8756. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8757. delivery_way, _ := json["delivery_way"].(string)
  8758. project.DeliveryWay = delivery_way
  8759. }
  8760. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8761. execution_frequency, _ := json["execution_frequency"].(string)
  8762. project.ExecutionFrequency = execution_frequency
  8763. }
  8764. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8765. remark, _ := json["remark"].(string)
  8766. project.Remark = remark
  8767. }
  8768. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8769. day, _ := json["number_days"].(string)
  8770. project.Day = day
  8771. }
  8772. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8773. unit, _ := json["unit"].(string)
  8774. project.Unit = unit
  8775. }
  8776. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8777. // frequency_type := int64(json["frequency_type"].(float64))
  8778. // project.FrequencyType = frequency_type
  8779. //}
  8780. //
  8781. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8782. // day_count := int64(json["day_count"].(float64))
  8783. // project.DayCount = day_count
  8784. //}
  8785. //
  8786. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8787. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8788. // week_day, _ := json["week_day"].(string)
  8789. // project.WeekDay = week_day
  8790. //}
  8791. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8792. //
  8793. //if project.ID == 0 {
  8794. // if stockConfig.IsOpen == 1 {
  8795. // if project.Type == 3 {
  8796. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8797. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8798. // good.Total = good.Total - f_count
  8799. // service.UpdateGoodInfo(&good)
  8800. // }
  8801. // }
  8802. //
  8803. //} else {
  8804. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8805. //
  8806. // if stockConfig.IsOpen == 1 {
  8807. // if project.Type == 3 {
  8808. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8809. // if project.Count < temp_project.Count {
  8810. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8811. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8812. //
  8813. // other_count := f_count_two - f_count_one
  8814. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8815. // good.Total = good.Total + other_count_two
  8816. // service.UpdateGoodInfo(&good)
  8817. // } else if project.Count > temp_project.Count {
  8818. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8819. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8820. //
  8821. // other_count := f_count_one - f_count_two
  8822. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8823. // good.Total = good.Total - other_count_two
  8824. // service.UpdateGoodInfo(&good)
  8825. // }
  8826. //
  8827. // }
  8828. // }
  8829. //
  8830. //}
  8831. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8832. id := int64(json["id"].(float64))
  8833. if id > 0 {
  8834. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8835. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8836. fmt.Println("666666")
  8837. project.Mtime = time.Now().Unix()
  8838. project.Ctime = temp_project.Ctime
  8839. } else {
  8840. project.Mtime = temp_project.Mtime
  8841. project.Ctime = temp_project.Ctime
  8842. }
  8843. } else {
  8844. ctime := time.Now().Unix()
  8845. project.Mtime = ctime
  8846. project.Ctime = ctime
  8847. }
  8848. }
  8849. return 0
  8850. }
  8851. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8852. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8853. id := int64(json["id"].(float64))
  8854. additionalCharge.ID = id
  8855. }
  8856. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8857. item_id := int64(json["item_id"].(float64))
  8858. additionalCharge.ItemId = item_id
  8859. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8860. if config.ID > 0 {
  8861. if len(config.Code) > 0 {
  8862. additionalCharge.MedListCodg = config.Code
  8863. }
  8864. }
  8865. }
  8866. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8867. // price := int64(json["price"].(float64))
  8868. // formatInt_price := strconv.FormatInt(price, 10)
  8869. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8870. // additionalCharge.Price = float_price
  8871. // }
  8872. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8873. // price := int64(json["price"].(float64))
  8874. // formatInt_price := strconv.FormatInt(price, 10)
  8875. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8876. // additionalCharge.Price = float_price
  8877. //}
  8878. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8879. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8880. additionalCharge.Price = price
  8881. }
  8882. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8883. count, _ := json["count"].(string)
  8884. counts, _ := strconv.ParseInt(count, 10, 64)
  8885. additionalCharge.Count = counts
  8886. }
  8887. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8888. item_name, _ := json["item_name"].(string)
  8889. additionalCharge.ItemName = item_name
  8890. }
  8891. return 0
  8892. }
  8893. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8894. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8895. utils.ErrorLog("drug_name")
  8896. return enums.ErrorCodeParamWrong
  8897. }
  8898. adviceName, _ := json["drug_name"].(string)
  8899. if len(adviceName) == 0 {
  8900. utils.ErrorLog("len(advice_name) == 0")
  8901. return enums.ErrorCodeParamWrong
  8902. }
  8903. advice.AdviceName = adviceName
  8904. adviceDesc, _ := json["advice_desc"].(string)
  8905. advice.AdviceDesc = adviceDesc
  8906. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8907. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8908. advice.DrugSpec = drugSpec
  8909. }
  8910. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8911. remark, _ := json["remark"].(string)
  8912. advice.Remark = remark
  8913. }
  8914. if json["id"] == nil {
  8915. advice.DrugId = 0
  8916. } else {
  8917. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8918. drug_id := int64(json["id"].(float64))
  8919. advice.DrugId = drug_id
  8920. }
  8921. }
  8922. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8923. groupno := int64(json["groupno"].(float64))
  8924. advice.Groupno = groupno
  8925. }
  8926. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8927. drugSpecUnit, _ := json["min_unit"].(string)
  8928. advice.DrugSpecUnit = drugSpecUnit
  8929. }
  8930. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8931. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8932. advice.SingleDose = singleDose
  8933. }
  8934. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8935. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8936. advice.SingleDoseUnit = singleDoseUnit
  8937. }
  8938. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8939. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8940. advice.PrescribingNumber = prescribingNumber
  8941. }
  8942. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8943. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8944. advice.PrescribingNumberUnit = prescribingNumberUnit
  8945. }
  8946. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8947. deliveryWay, _ := json["delivery_way"].(string)
  8948. advice.DeliveryWay = deliveryWay
  8949. }
  8950. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8951. executionFrequency, _ := json["execution_frequency"].(string)
  8952. advice.ExecutionFrequency = executionFrequency
  8953. }
  8954. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8955. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8956. advice.Price = price
  8957. }
  8958. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8959. med_list_codg, _ := json["medical_insurance_number"].(string)
  8960. advice.MedListCodg = med_list_codg
  8961. }
  8962. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8963. day := int64(json["day"].(float64))
  8964. advice.Day = day
  8965. }
  8966. advice.FrequencyType = 1
  8967. return 0
  8968. }
  8969. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8970. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8971. types := int64(json["type"].(float64))
  8972. project.Type = types
  8973. }
  8974. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8975. project_id := int64(json["project_id"].(float64))
  8976. project.ProjectId = project_id
  8977. }
  8978. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8979. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8980. project.Price = price
  8981. }
  8982. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8983. total, _ := json["total"].(string)
  8984. //totals, _ := strconv.ParseInt(total, 10, 64)
  8985. project.Count = total
  8986. }
  8987. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8988. medical_code, _ := json["medical_code"].(string)
  8989. project.MedListCodg = medical_code
  8990. }
  8991. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8992. single_dose, _ := json["single_dose"].(string)
  8993. project.SingleDose = single_dose
  8994. }
  8995. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8996. delivery_way, _ := json["delivery_way"].(string)
  8997. project.DeliveryWay = delivery_way
  8998. }
  8999. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  9000. execution_frequency, _ := json["execution_frequency"].(string)
  9001. project.ExecutionFrequency = execution_frequency
  9002. }
  9003. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  9004. remark, _ := json["remark"].(string)
  9005. project.Remark = remark
  9006. }
  9007. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  9008. day, _ := json["number_days"].(string)
  9009. project.Day = day
  9010. }
  9011. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  9012. unit, _ := json["unit"].(string)
  9013. project.Unit = unit
  9014. }
  9015. project.FrequencyType = 1
  9016. return 0
  9017. }
  9018. func (c *HisApiController) GetHisOrderListTwo() {
  9019. start_time := c.GetString("start_time")
  9020. end_time := c.GetString("end_time")
  9021. timeLayout := "2006-01-02"
  9022. loc, _ := time.LoadLocation("Local")
  9023. var startTime int64
  9024. if len(start_time) > 0 {
  9025. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9026. if err != nil {
  9027. //fmt.Println(err)
  9028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9029. return
  9030. }
  9031. startTime = theTime.Unix()
  9032. }
  9033. var endTime int64
  9034. if len(end_time) > 0 {
  9035. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9036. if err != nil {
  9037. utils.ErrorLog(err.Error())
  9038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9039. return
  9040. }
  9041. endTime = theTime.Unix()
  9042. }
  9043. adminUser := c.GetAdminUserInfo()
  9044. org_id := adminUser.CurrentOrgId
  9045. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  9046. if err == nil {
  9047. c.ServeSuccessJSON(map[string]interface{}{
  9048. "order2": order,
  9049. })
  9050. } else {
  9051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9052. return
  9053. }
  9054. }
  9055. func (c *HisApiController) GetHisOrderList() {
  9056. page, _ := c.GetInt64("page", -1)
  9057. limit, _ := c.GetInt64("limit", -1)
  9058. start_time := c.GetString("start_time")
  9059. end_time := c.GetString("end_time")
  9060. types, _ := c.GetInt64("type", 0)
  9061. keywords := c.GetString("keywords")
  9062. p_type, _ := c.GetInt64("p_type", 0)
  9063. sort_type, _ := c.GetInt64("sort_type", 0)
  9064. charge_type, _ := c.GetInt64("charge_type", 0)
  9065. sch_type, _ := c.GetInt64("sch_type", 0)
  9066. zone_type, _ := c.GetInt64("zone_type", 0)
  9067. med_type, _ := c.GetInt64("med_type", 0)
  9068. timeLayout := "2006-01-02"
  9069. loc, _ := time.LoadLocation("Local")
  9070. var startTime int64
  9071. if len(start_time) > 0 {
  9072. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9073. if err != nil {
  9074. //fmt.Println(err)
  9075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9076. return
  9077. }
  9078. startTime = theTime.Unix()
  9079. }
  9080. var endTime int64
  9081. if len(end_time) > 0 {
  9082. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9083. if err != nil {
  9084. utils.ErrorLog(err.Error())
  9085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9086. return
  9087. }
  9088. endTime = theTime.Unix()
  9089. }
  9090. adminUser := c.GetAdminUserInfo()
  9091. org_id := adminUser.CurrentOrgId
  9092. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type)
  9093. for _, item := range order {
  9094. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  9095. item.DoctorName = info.Doctor
  9096. item.DepartmentName = info.XtHisDepartment.Name
  9097. }
  9098. if err == nil {
  9099. c.ServeSuccessJSON(map[string]interface{}{
  9100. "order": order,
  9101. "total": total,
  9102. })
  9103. } else {
  9104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9105. return
  9106. }
  9107. }
  9108. func (c *HisApiController) GetHisOrder() {
  9109. patient_id, _ := c.GetInt64("patient_id", 0)
  9110. number := c.GetString("number")
  9111. adminInfo := c.GetAdminUserInfo()
  9112. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  9113. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  9114. if err == nil {
  9115. c.ServeSuccessJSON(map[string]interface{}{
  9116. "order": order,
  9117. "prescription": prescriptions,
  9118. })
  9119. } else {
  9120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9121. return
  9122. }
  9123. }
  9124. func (c *HisApiController) GetHisPrescriptionList() {
  9125. record_date := c.GetString("record_date")
  9126. keywords := c.GetString("keywords")
  9127. page, _ := c.GetInt64("page")
  9128. limit, _ := c.GetInt64("limit")
  9129. sch_type, _ := c.GetInt64("sch_type")
  9130. timeLayout := "2006-01-02"
  9131. loc, _ := time.LoadLocation("Local")
  9132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9133. if err != nil {
  9134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9135. return
  9136. }
  9137. recordDateTime := theTime.Unix()
  9138. adminInfo := c.GetAdminUserInfo()
  9139. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  9140. //adminInfo := c.GetAdminUserInfo()
  9141. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  9142. //fmt.Println(prescriptionOrder)
  9143. if err == nil {
  9144. c.ServeSuccessJSON(map[string]interface{}{
  9145. "order": prescriptionOrder,
  9146. "total": total,
  9147. })
  9148. } else {
  9149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9150. return
  9151. }
  9152. }
  9153. func (c *HisApiController) GetHisPrescriptionInfo() {
  9154. id, _ := c.GetInt64("id")
  9155. adminInfo := c.GetAdminUserInfo()
  9156. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  9157. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  9158. if err == nil {
  9159. c.ServeSuccessJSON(map[string]interface{}{
  9160. "order": prescriptionOrder,
  9161. "prescription": prescription,
  9162. })
  9163. } else {
  9164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9165. return
  9166. }
  9167. }
  9168. func (c *HisApiController) GetMedicalInsuranceConfig() {
  9169. adminUser := c.GetAdminUserInfo()
  9170. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  9171. c.ServeSuccessJSON(map[string]interface{}{
  9172. "config": config,
  9173. })
  9174. }
  9175. type ResultTwo struct {
  9176. ErrMsg interface{} `json:"err_msg"`
  9177. InfRefmsgid string `json:"inf_refmsgid"`
  9178. Infcode int64 `json:"infcode"`
  9179. Output struct {
  9180. Baseinfo struct {
  9181. Age float64 `json:"age"`
  9182. Brdy string `json:"brdy"`
  9183. Certno string `json:"certno"`
  9184. Gend string `json:"gend"`
  9185. Naty string `json:"naty"`
  9186. PsnCertType string `json:"psn_cert_type"`
  9187. PsnName string `json:"psn_name"`
  9188. PsnNo string `json:"psn_no"`
  9189. } `json:"baseinfo"`
  9190. Idetinfo []interface{} `json:"idetinfo"`
  9191. Iinfo []struct {
  9192. Balc float64 `json:"balc"`
  9193. CvlservFlag string `json:"cvlserv_flag"`
  9194. EmpName string `json:"emp_name"`
  9195. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  9196. Insutype string `json:"insutype"`
  9197. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  9198. PausInsuDate interface{} `json:"paus_insu_date"`
  9199. PsnInsuDate string `json:"psn_insu_date"`
  9200. PsnInsuStas string `json:"psn_insu_stas"`
  9201. PsnType string `json:"psn_type"`
  9202. } `json:"insuinfo"`
  9203. } `json:"output"`
  9204. RefmsgTime string `json:"refmsg_time"`
  9205. RespondTime string `json:"respond_time"`
  9206. Signtype interface{} `json:"signtype"`
  9207. WarnInfo interface{} `json:"warn_info"`
  9208. }
  9209. type ResultThree struct {
  9210. Cainfo interface{} `json:"cainfo"`
  9211. ErrMsg interface{} `json:"err_msg"`
  9212. InfRefmsgid string `json:"inf_refmsgid"`
  9213. Infcode int64 `json:"infcode"`
  9214. Output struct {
  9215. Data struct {
  9216. IptOtpNo string `json:"ipt_otp_no"`
  9217. MdtrtID string `json:"mdtrt_id"`
  9218. PsnNo string `json:"psn_no"`
  9219. } `json:"data"`
  9220. } `json:"output"`
  9221. RefmsgTime string `json:"refmsg_time"`
  9222. RespondTime string `json:"respond_time"`
  9223. Signtype interface{} `json:"signtype"`
  9224. WarnMsg interface{} `json:"warn_msg"`
  9225. }
  9226. type ResultFour struct {
  9227. Cainfo string `json:"cainfo"`
  9228. ErrMsg string `json:"err_msg"`
  9229. InfRefmsgid string `json:"inf_refmsgid"`
  9230. Infcode int64 `json:"infcode"`
  9231. Output struct {
  9232. Result []struct {
  9233. BasMednFlag string `json:"bas_medn_flag"`
  9234. ChldMedcFlag string `json:"chld_medc_flag"`
  9235. ChrgitmLv string `json:"chrgitm_lv"`
  9236. Cnt float64 `json:"cnt"`
  9237. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  9238. DrtReimFlag string `json:"drt_reim_flag"`
  9239. FeedetlSn string `json:"feedetl_sn"`
  9240. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9241. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  9242. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9243. ListSpItemFlag string `json:"list_sp_item_flag"`
  9244. LmtUsedFlag string `json:"lmt_used_flag"`
  9245. MedChrgitmType string `json:"med_chrgitm_type"`
  9246. Memo string `json:"memo"`
  9247. OverlmtAmt float64 `json:"overlmt_amt"`
  9248. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9249. Pric float64 `json:"pric"`
  9250. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  9251. SelfpayProp float64 `json:"selfpay_prop"`
  9252. } `json:"result"`
  9253. } `json:"output"`
  9254. RefmsgTime string `json:"refmsg_time"`
  9255. RespondTime string `json:"respond_time"`
  9256. Signtype string `json:"signtype"`
  9257. WarnMsg string `json:"warn_msg"`
  9258. }
  9259. type ResultFive struct {
  9260. Insutype string `json:"insutype"`
  9261. }
  9262. type ResultSix struct {
  9263. Cainfo interface{} `json:"cainfo"`
  9264. ErrMsg interface{} `json:"err_msg"`
  9265. InfRefmsgid string `json:"inf_refmsgid"`
  9266. Infcode int64 `json:"infcode"`
  9267. Output struct {
  9268. } `json:"output"`
  9269. RefmsgTime string `json:"refmsg_time"`
  9270. RespondTime string `json:"respond_time"`
  9271. Signtype interface{} `json:"signtype"`
  9272. WarnMsg interface{} `json:"warn_msg"`
  9273. }
  9274. type ResultSeven struct {
  9275. Cainfo string `json:"cainfo"`
  9276. ErrMsg string `json:"err_msg"`
  9277. InfRefmsgid string `json:"inf_refmsgid"`
  9278. Infcode int64 `json:"infcode"`
  9279. Output struct {
  9280. Setldetail []interface{} `json:"setldetail"`
  9281. Setlinfo struct {
  9282. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9283. AcctPay float64 `json:"acct_pay"`
  9284. ActPayDedc float64 `json:"act_pay_dedc"`
  9285. Age float64 `json:"age"`
  9286. Balc float64 `json:"balc"`
  9287. Brdy string `json:"brdy"`
  9288. Certno string `json:"certno"`
  9289. ClrOptins string `json:"clr_optins"`
  9290. ClrType string `json:"clr_type"`
  9291. ClrWay string `json:"clr_way"`
  9292. CvlservFlag string `json:"cvlserv_flag"`
  9293. CvlservPay float64 `json:"cvlserv_pay"`
  9294. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9295. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9296. Gend string `json:"gend"`
  9297. HifesPay float64 `json:"hifes_pay"`
  9298. HifmiPay float64 `json:"hifmi_pay"`
  9299. HifobPay float64 `json:"hifob_pay"`
  9300. HifpPay float64 `json:"hifp_pay"`
  9301. HospPartAmt float64 `json:"hosp_part_amt"`
  9302. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9303. Insutype string `json:"insutype"`
  9304. MafPay float64 `json:"maf_pay"`
  9305. MdtrtCertType string `json:"mdtrt_cert_type"`
  9306. MdtrtID string `json:"mdtrt_id"`
  9307. MedType string `json:"med_type"`
  9308. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9309. MedinsSetlID string `json:"medins_setl_id"`
  9310. Naty string `json:"naty"`
  9311. OthPay float64 `json:"oth_pay"`
  9312. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9313. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9314. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9315. PsnCashPay float64 `json:"psn_cash_pay"`
  9316. PsnCertType string `json:"psn_cert_type"`
  9317. PsnName string `json:"psn_name"`
  9318. PsnNo string `json:"psn_no"`
  9319. PsnPartAmt float64 `json:"psn_part_amt"`
  9320. PsnType string `json:"psn_type"`
  9321. SetlID string `json:"setl_id"`
  9322. SetlTime string `json:"setl_time"`
  9323. } `json:"setlinfo"`
  9324. } `json:"output"`
  9325. RefmsgTime string `json:"refmsg_time"`
  9326. RespondTime string `json:"respond_time"`
  9327. Signtype interface{} `json:"signtype"`
  9328. WarnMsg interface{} `json:"warn_msg"`
  9329. }
  9330. type ResultEight struct {
  9331. Cainfo string `json:"cainfo"`
  9332. ErrMsg string `json:"err_msg"`
  9333. InfRefmsgid string `json:"inf_refmsgid"`
  9334. Infcode int64 `json:"infcode"`
  9335. Output struct {
  9336. Stmtinfo struct {
  9337. SetlOptins string `json:"setl_optins"`
  9338. StmtRslt string `json:"stmt_rslt"`
  9339. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  9340. } `json:"stmtinfo"`
  9341. } `json:"output"`
  9342. RefmsgTime string `json:"refmsg_time"`
  9343. RespondTime string `json:"respond_time"`
  9344. Signtype interface{} `json:"signtype"`
  9345. WarnMsg interface{} `json:"warn_msg"`
  9346. }
  9347. type ResultNine struct {
  9348. Cainfo string `json:"cainfo"`
  9349. ErrMsg string `json:"err_msg"`
  9350. InfRefmsgid string `json:"inf_refmsgid"`
  9351. Infcode int64 `json:"infcode"`
  9352. Output struct {
  9353. FileQuryNo string `json:"file_qury_no"`
  9354. } `json:"output"`
  9355. RefmsgTime string `json:"refmsg_time"`
  9356. RespondTime string `json:"respond_time"`
  9357. Signtype interface{} `json:"signtype"`
  9358. WarnMsg interface{} `json:"warn_msg"`
  9359. }
  9360. type ResultTen struct {
  9361. Cainfo string `json:"cainfo"`
  9362. ErrMsg string `json:"err_msg"`
  9363. InfRefmsgid string `json:"inf_refmsgid"`
  9364. Infcode int64 `json:"infcode"`
  9365. Output struct {
  9366. DldEndtime string `json:"dld_endtime"`
  9367. FileQuryNo string `json:"file_qury_no"`
  9368. Filename string `json:"filename"`
  9369. } `json:"output"`
  9370. RefmsgTime string `json:"refmsg_time"`
  9371. RespondTime string `json:"respond_time"`
  9372. Signtype interface{} `json:"signtype"`
  9373. WarnMsg interface{} `json:"warn_msg"`
  9374. }
  9375. type ResultEleven struct {
  9376. Cainfo string `json:"cainfo"`
  9377. ErrMsg string `json:"err_msg"`
  9378. InfRefmsgid string `json:"inf_refmsgid"`
  9379. Infcode int64 `json:"infcode"`
  9380. Output struct {
  9381. Setlinfo struct {
  9382. FixmedinsName string `json:"fixmedins_name"`
  9383. FixmedinsCode string `json:"fixmedins_code"`
  9384. PsnNo string `json:"psn_no"`
  9385. PsnName string `json:"psn_name"`
  9386. HifobPay float64 `json:"hifob_pay"`
  9387. Gend string `json:"gend"`
  9388. Brdy string `json:"brdy"`
  9389. PsnCertType string `json:"psn_cert_type"`
  9390. PsnType string `json:"psn_type"`
  9391. EmpName string `json:"emp_name"`
  9392. Certno string `json:"certno"`
  9393. Insutype string `json:"insutype"`
  9394. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9395. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9396. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9397. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9398. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9399. ActPayDedc float64 `json:"act_pay_dedc"`
  9400. HifpPay float64 `json:"hifp_pay"`
  9401. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9402. CvlservPay float64 `json:"cvlserv_pay"`
  9403. HifesPay float64 `json:"hifes_pay"`
  9404. HifmiPay float64 `json:"hifmi_pay"`
  9405. MafPay float64 `json:"maf_pay"`
  9406. OthPay float64 `json:"oth_pay"`
  9407. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9408. PsnPay float64 `json:"psn_pay"`
  9409. AcctPay float64 `json:"acct_pay"`
  9410. CashPayamt float64 `json:"cash_payamt"`
  9411. Balc float64 `json:"balc"`
  9412. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9413. MedinsSetlId string `json:"medins_setl_id"`
  9414. RefdSetlFlag string `json:"refd_setl_flag"`
  9415. SetlTime string `json:"setl_time"`
  9416. MedType string `json:"med_type"`
  9417. } `json:"setlinfo"`
  9418. } `json:"output"`
  9419. RefmsgTime string `json:"refmsg_time"`
  9420. RespondTime string `json:"respond_time"`
  9421. Signtype interface{} `json:"signtype"`
  9422. WarnMsg interface{} `json:"warn_msg"`
  9423. }
  9424. type Custom struct {
  9425. DetItemFeeSumamt string
  9426. Cut string
  9427. FeedetlSn string
  9428. Price string
  9429. MedListCodg string
  9430. Type int64
  9431. AdviceId int64
  9432. ProjectId int64
  9433. ItemId int64
  9434. CostType int64
  9435. }
  9436. // 获取个人信息----挂号-----上传就诊信息
  9437. func (c *HisApiController) GetRegisterInfo() {
  9438. id, _ := c.GetInt64("id")
  9439. record_time := c.GetString("record_time")
  9440. settlementValue, _ := c.GetInt64("settlement_value")
  9441. medical_insurance_card := c.GetString("medical_insurance_card")
  9442. name := c.GetString("name")
  9443. id_card_type, _ := c.GetInt64("id_card_type")
  9444. certificates, _ := c.GetInt64("certificates")
  9445. medical_care, _ := c.GetInt64("medical_care")
  9446. birthday := c.GetString("birthday")
  9447. age, _ := c.GetInt64("age")
  9448. id_card := c.GetString("id_card")
  9449. register_type, _ := c.GetInt64("register")
  9450. doctor, _ := c.GetInt64("doctor")
  9451. department, _ := c.GetInt64("department")
  9452. gender, _ := c.GetInt64("sex")
  9453. phone := c.GetString("phone")
  9454. registration_fee, _ := c.GetFloat("registration_fee")
  9455. medical_expenses, _ := c.GetFloat("medical_expenses")
  9456. social_type, _ := c.GetInt64("social_type")
  9457. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9458. diagnosis_ids := c.GetString("diagnosis")
  9459. sick_type, _ := c.GetInt64("sick_type")
  9460. reg_type := c.GetString("p_type")
  9461. timeLayout := "2006-01-02"
  9462. loc, _ := time.LoadLocation("Local")
  9463. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9464. birthUnix := birthdays.Unix()
  9465. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9466. if err != nil {
  9467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9468. return
  9469. }
  9470. recordDateTime := theTime.Unix()
  9471. adminInfo := c.GetAdminUserInfo()
  9472. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9473. if tempPatient.ID == 0 {
  9474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9475. return
  9476. }
  9477. var patient service.Patients
  9478. if id == 0 {
  9479. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9480. } else {
  9481. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9482. }
  9483. if patient.ID == 0 {
  9484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9485. return
  9486. }
  9487. if len(patient.IdCardNo) == 0 {
  9488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9489. return
  9490. }
  9491. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9492. if len(his) >= 1 {
  9493. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9494. if len(his) >= 1 && order.ID == 0 {
  9495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9496. return
  9497. }
  9498. }
  9499. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9500. fmt.Println(timeStr)
  9501. timeArr := strings.Split(timeStr, " ")
  9502. fmt.Println(timeArr)
  9503. timeArrTwo := strings.Split(timeArr[0], "-")
  9504. timeArrThree := strings.Split(timeArr[1], ":")
  9505. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9506. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9507. if len(lists) == 0 {
  9508. var hisPatient models.XtHisPatient
  9509. hisPatient = models.XtHisPatient{
  9510. Name: name,
  9511. Age: age,
  9512. Gender: gender,
  9513. Birthday: birthUnix,
  9514. Phone: phone,
  9515. MedicalTreatmentType: medical_care,
  9516. IdType: certificates,
  9517. IdCardNo: id_card,
  9518. BalanceAccountsType: settlementValue,
  9519. SocialType: social_type,
  9520. MedicalInsuranceNumber: medical_insurance_card,
  9521. RegisterType: register_type,
  9522. RegisterCost: registration_fee,
  9523. TreatmentCost: medical_expenses,
  9524. AdminUserId: adminInfo.AdminUser.Id,
  9525. UserOrgId: adminInfo.CurrentOrgId,
  9526. Status: 1,
  9527. RecordDate: recordDateTime,
  9528. IsReturn: 1,
  9529. PatientId: patient.ID,
  9530. Ctime: time.Now().Unix(),
  9531. Mtime: time.Now().Unix(),
  9532. Number: str,
  9533. IdCardType: id_card_type,
  9534. Departments: department,
  9535. Doctor: doctor,
  9536. PType: reg_type,
  9537. Diagnosis: diagnosis_ids,
  9538. SickType: sick_type,
  9539. }
  9540. service.CreateHisPatient(&hisPatient)
  9541. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9542. c.ServeSuccessJSON(map[string]interface{}{
  9543. "his_info": hisPatient,
  9544. })
  9545. } else {
  9546. //chrgBchno := rand.Intn(1000000) + 10000
  9547. var hisPatient models.XtHisPatient
  9548. hisPatient = models.XtHisPatient{
  9549. Name: name,
  9550. Age: age,
  9551. Gender: gender,
  9552. Birthday: birthUnix,
  9553. Phone: phone,
  9554. MedicalTreatmentType: medical_care,
  9555. IdType: certificates,
  9556. IdCardNo: id_card,
  9557. BalanceAccountsType: settlementValue,
  9558. SocialType: social_type,
  9559. MedicalInsuranceNumber: medical_insurance_card,
  9560. RegisterType: register_type,
  9561. RegisterCost: registration_fee,
  9562. TreatmentCost: medical_expenses,
  9563. AdminUserId: adminInfo.AdminUser.Id,
  9564. UserOrgId: adminInfo.CurrentOrgId,
  9565. Status: 1,
  9566. RecordDate: recordDateTime,
  9567. IsReturn: 1,
  9568. PatientId: patient.ID,
  9569. Ctime: time.Now().Unix(),
  9570. Mtime: time.Now().Unix(),
  9571. Number: str,
  9572. IdCardType: id_card_type,
  9573. Departments: department,
  9574. Doctor: doctor,
  9575. PType: reg_type,
  9576. Diagnosis: diagnosis_ids,
  9577. SickType: sick_type,
  9578. }
  9579. service.CreateHisPatient(&hisPatient)
  9580. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9581. c.ServeSuccessJSON(map[string]interface{}{
  9582. "his_info": hisPatient,
  9583. })
  9584. }
  9585. }
  9586. // 上传明细----结算
  9587. func (c *HisApiController) GetUploadInfo() {
  9588. id, _ := c.GetInt64("id")
  9589. record_time := c.GetString("record_time")
  9590. his_patient_id, _ := c.GetInt64("his_patient_id")
  9591. oth_desc := c.GetString("oth_desc")
  9592. pay_way, _ := c.GetInt64("pay_way")
  9593. pay_ways := c.GetString("pay_ways")
  9594. pay_price, _ := c.GetFloat("pay_price")
  9595. pay_card_no := c.GetString("pay_card_no")
  9596. discount_price, _ := c.GetFloat("discount_price")
  9597. preferential_price, _ := c.GetFloat("preferential_price")
  9598. reality_price, _ := c.GetFloat("reality_price")
  9599. found_price, _ := c.GetFloat("found_price")
  9600. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9601. private_price, _ := c.GetFloat("private_price")
  9602. timeLayout := "2006-01-02"
  9603. loc, _ := time.LoadLocation("Local")
  9604. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9605. fapiao_code := c.GetString("fapiao_code")
  9606. fapiao_number := c.GetString("fapiao_number")
  9607. diagnosis_id := c.GetString("diagnosis")
  9608. sick_type, _ := c.GetInt64("sick_type")
  9609. reg_type, _ := c.GetInt64("p_type")
  9610. order_id, _ := c.GetInt64("order_id")
  9611. cash_pay := c.GetString("cash_pay")
  9612. wechat_pay := c.GetString("wechat_pay")
  9613. ali_pay := c.GetString("ali_pay")
  9614. jifen_pay := c.GetString("jifen_pay")
  9615. card_desc := c.GetString("card_desc")
  9616. band_card_pay := c.GetString("band_card_pay")
  9617. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9618. tmp_decimal := c.GetString("tmp_decimal")
  9619. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9620. var decimal float64 //本次使用的押金
  9621. var errmsg error
  9622. tx := service.XTWriteDB().Begin() //开了事务
  9623. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9624. defer func() {
  9625. if errmsg != nil {
  9626. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9627. tx.Rollback()
  9628. } else {
  9629. tx.Commit()
  9630. }
  9631. }()
  9632. fmt.Println("dec_way", dec_way)
  9633. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9634. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9635. return
  9636. }
  9637. if len(tmp_decimal) > 0 {
  9638. if tmp_decimal[0] == 45 {
  9639. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9640. return
  9641. }
  9642. }
  9643. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9644. fmt.Println(errs)
  9645. decimal = tt
  9646. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9647. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9648. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9649. if err != nil {
  9650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9651. return
  9652. }
  9653. recordDateTime := theTime.Unix()
  9654. adminUser := c.GetAdminUserInfo()
  9655. var prescriptions []*models.HisPrescription
  9656. var prescriptionsOne []*models.HisPrescription
  9657. var start_time int64
  9658. var end_time int64
  9659. ids_str := c.GetString("ids")
  9660. ids_arr := strings.Split(ids_str, ",")
  9661. if tempOrder.ID == 0 {
  9662. if settle_accounts_type == 1 { //日结
  9663. fmt.Println(reg_type)
  9664. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9665. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9666. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9667. } else {
  9668. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9669. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9670. }
  9671. } else { //月结
  9672. start_time_str := c.GetString("start_time")
  9673. end_time_str := c.GetString("end_time")
  9674. timeLayout := "2006-01-02"
  9675. loc, _ := time.LoadLocation("Local")
  9676. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9677. if err != nil {
  9678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9679. return
  9680. }
  9681. recordStartTime := theStartTime.Unix()
  9682. start_time = recordStartTime
  9683. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9684. if err != nil {
  9685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9686. return
  9687. }
  9688. recordEndTime := theEndTime.Unix()
  9689. end_time = recordEndTime
  9690. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9691. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9692. }
  9693. var goods []*models.DialysisBeforePrepareGoods
  9694. var newGoods []*models.NewDialysisBeforePrepareGoods
  9695. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9696. var infos []*models.HisDoctorAdviceInfo
  9697. var infoList []*models.HisDoctorAdviceInfo
  9698. var hisAdvice []*models.HisDoctorAdviceInfo
  9699. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9700. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9701. //判断库存不足
  9702. //结算出库开关
  9703. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9704. if settConfig.IsOpen == 1 {
  9705. //判断库存的地方
  9706. for _, info := range prescriptions {
  9707. if info.Type == 1 {
  9708. infos = append(infos, info.HisDoctorAdviceInfo...)
  9709. }
  9710. if info.Type == 2 {
  9711. for _, sumItem := range info.HisPrescriptionProject {
  9712. if sumItem.Type == 3 {
  9713. var good models.DialysisBeforePrepareGoods
  9714. var newGood models.NewDialysisBeforePrepareGoods
  9715. good.GoodId = sumItem.GoodInfo.ID
  9716. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9717. count, _ := strconv.Atoi(sumItem.Count)
  9718. good.Count = int64(count)
  9719. good.StorehouseId = houseConfig.StorehouseOutInfo
  9720. good.ProjectId = sumItem.ID
  9721. goods = append(goods, &good)
  9722. newGood.GoodId = sumItem.GoodInfo.ID
  9723. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9724. count2, _ := strconv.Atoi(sumItem.Count)
  9725. newGood.Count = int64(count2)
  9726. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9727. newGood.ProjectId = sumItem.ID
  9728. newGoods = append(newGoods, &newGood)
  9729. }
  9730. }
  9731. }
  9732. }
  9733. for _, info := range prescriptionsOne {
  9734. if info.Type == 1 {
  9735. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9736. }
  9737. if info.Type == 2 {
  9738. for _, sumItem := range info.HisPrescriptionProject {
  9739. if sumItem.Type == 3 {
  9740. var newGood models.NewDialysisBeforePrepareGoods
  9741. newGood.GoodId = sumItem.GoodInfo.ID
  9742. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9743. count2, _ := strconv.Atoi(sumItem.Count)
  9744. newGood.Count = int64(count2)
  9745. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9746. newGood.ProjectId = sumItem.ID
  9747. newGoodOne = append(newGoodOne, &newGood)
  9748. }
  9749. }
  9750. }
  9751. }
  9752. //判断
  9753. for _, itemOne := range infos {
  9754. for _, itemTwo := range hisAdvice {
  9755. if itemOne.DrugId == itemTwo.DrugId {
  9756. itemTwo.Child = append(itemTwo.Child, itemOne)
  9757. }
  9758. }
  9759. }
  9760. for _, itemTwo := range hisAdvice {
  9761. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9762. var sum_out_count int64
  9763. for _, itemThree := range itemTwo.Child {
  9764. var prescribing_number int64
  9765. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9766. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9767. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9768. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9769. }
  9770. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9771. prescribing_number = parseIntPrescribingNumber
  9772. }
  9773. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9774. prescribing_number = parseIntPrescribingNumber
  9775. }
  9776. sum_out_count += prescribing_number
  9777. }
  9778. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9779. if sum_out_count > drugStockOut.FlushCount {
  9780. c.ServeSuccessJSON(map[string]interface{}{
  9781. "msg": "2",
  9782. "drug": medical,
  9783. })
  9784. return
  9785. }
  9786. }
  9787. for _, itemOne := range newGoods {
  9788. for _, item := range newGoodOne {
  9789. if itemOne.GoodId == item.GoodId {
  9790. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9791. }
  9792. }
  9793. }
  9794. for _, item := range newGoodOne {
  9795. var sum_out_count_one int64
  9796. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9797. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9798. sum_out_count_one += itemOne.Count
  9799. }
  9800. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9801. fmt.Println("sum_out_count_one", sum_out_count_one)
  9802. fmt.Println("list.FlushCount", list.FlushCount)
  9803. if sum_out_count_one > list.FlushCount {
  9804. c.ServeSuccessJSON(map[string]interface{}{
  9805. "msg": "3",
  9806. "good": good,
  9807. })
  9808. return
  9809. }
  9810. }
  9811. }
  9812. timestamp := time.Now().Unix()
  9813. tempTime := time.Unix(timestamp, 0)
  9814. timeFormat := tempTime.Format("20060102150405")
  9815. chrgBchno := rand.Intn(100000) + 10000
  9816. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9817. strconv.FormatInt(his.PatientId, 10)
  9818. var ids []int64
  9819. for _, item := range prescriptions {
  9820. ids = append(ids, item.ID)
  9821. }
  9822. var total float64
  9823. for _, item := range prescriptions {
  9824. fmt.Println(item)
  9825. if item.Type == 1 { //药品
  9826. for _, subItem := range item.HisDoctorAdviceInfo {
  9827. if subItem.Drug.IsUser != 1 {
  9828. total = total + (subItem.Price * subItem.PrescribingNumber)
  9829. }
  9830. }
  9831. }
  9832. if item.Type == 2 { //项目
  9833. for _, subItem := range item.HisPrescriptionProject {
  9834. if subItem.Type == 2 {
  9835. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9836. total = total + (subItem.Price * cnt)
  9837. } else {
  9838. if subItem.GoodInfo.IsUser != 1 {
  9839. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9840. total = total + (subItem.Price * cnt)
  9841. }
  9842. }
  9843. }
  9844. }
  9845. for _, subItem := range item.HisAdditionalCharge {
  9846. total = total + (subItem.Price * float64(subItem.Count))
  9847. }
  9848. }
  9849. if reg_type == 1111 || reg_type == 1112 {
  9850. reg_type = 11
  9851. }
  9852. tm := time.Unix(time.Now().Unix(), 0)
  9853. allTotal := fmt.Sprintf("%.4f", total)
  9854. totals, _ := strconv.ParseFloat(allTotal, 64)
  9855. order := &models.HisOrder{
  9856. UserOrgId: adminUser.CurrentOrgId,
  9857. HisPatientId: his.ID,
  9858. PatientId: id,
  9859. SettleAccountsDate: recordDateTime,
  9860. Ctime: time.Now().Unix(),
  9861. Mtime: time.Now().Unix(),
  9862. Status: 1,
  9863. OrderStatus: 2,
  9864. MdtrtId: his.Number,
  9865. Number: chrg_bchno,
  9866. MedfeeSumamt: totals,
  9867. PayWay: pay_way,
  9868. PayWays: pay_ways,
  9869. PayPrice: pay_price,
  9870. MedType: strconv.Itoa(int(reg_type)),
  9871. PayCardNo: pay_card_no,
  9872. DiscountPrice: discount_price,
  9873. PreferentialPrice: preferential_price,
  9874. RealityPrice: reality_price,
  9875. FoundPrice: found_price,
  9876. MedicalInsurancePrice: medical_insurance_price,
  9877. PrivatePrice: private_price,
  9878. SettleEndTime: end_time,
  9879. SettleStartTime: start_time,
  9880. PsnPartAmt: totals,
  9881. PsnCashPay: totals,
  9882. SettleType: settle_accounts_type,
  9883. FaPiaoCode: fapiao_code,
  9884. FaPiaoNumber: fapiao_number,
  9885. Diagnosis: diagnosis_id,
  9886. PType: 2,
  9887. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9888. Decimal: decimal,
  9889. OthDesc: oth_desc,
  9890. CashPay: cash_pay,
  9891. WechatPay: wechat_pay,
  9892. AliPay: ali_pay,
  9893. JifenPay: jifen_pay,
  9894. BandCardPay: band_card_pay,
  9895. Creator: adminUser.AdminUser.Id,
  9896. CardDesc: card_desc,
  9897. }
  9898. err = service.CreateOrderTX(order, tx)
  9899. if err != nil {
  9900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9901. return
  9902. }
  9903. var customs []*Custom
  9904. for _, item := range prescriptions {
  9905. if item.Type == 1 { //药品a
  9906. for _, subItem := range item.HisDoctorAdviceInfo {
  9907. if subItem.Drug.IsUser != 1 {
  9908. cus := &Custom{
  9909. AdviceId: subItem.ID,
  9910. ProjectId: 0,
  9911. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9912. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9913. FeedetlSn: subItem.FeedetlSn,
  9914. Price: fmt.Sprintf("%.4f", subItem.Price),
  9915. MedListCodg: subItem.MedListCodg,
  9916. Type: 1,
  9917. CostType: 9,
  9918. }
  9919. customs = append(customs, cus)
  9920. }
  9921. }
  9922. }
  9923. if item.Type == 2 { //项目
  9924. for _, subItem := range item.HisPrescriptionProject {
  9925. if subItem.Type == 2 {
  9926. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9927. cus := &Custom{
  9928. AdviceId: 0,
  9929. ProjectId: subItem.ID,
  9930. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9931. Cut: fmt.Sprintf("%.4f", cnt),
  9932. FeedetlSn: subItem.FeedetlSn,
  9933. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9934. MedListCodg: subItem.MedListCodg,
  9935. Type: 2,
  9936. CostType: subItem.HisProject.CostClassify,
  9937. }
  9938. customs = append(customs, cus)
  9939. } else {
  9940. if subItem.GoodInfo.IsUser != 1 {
  9941. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9942. cus := &Custom{
  9943. AdviceId: 0,
  9944. ProjectId: subItem.ID,
  9945. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9946. Cut: fmt.Sprintf("%.4f", cnt),
  9947. FeedetlSn: subItem.FeedetlSn,
  9948. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9949. MedListCodg: subItem.MedListCodg,
  9950. Type: 2,
  9951. CostType: subItem.HisProject.CostClassify,
  9952. }
  9953. customs = append(customs, cus)
  9954. }
  9955. }
  9956. }
  9957. }
  9958. for _, item := range item.HisAdditionalCharge {
  9959. cus := &Custom{
  9960. ItemId: item.ID,
  9961. AdviceId: 0,
  9962. ProjectId: 0,
  9963. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9964. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9965. FeedetlSn: item.FeedetlSn,
  9966. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9967. MedListCodg: item.XtHisAddtionConfig.Code,
  9968. Type: 3,
  9969. CostType: 5,
  9970. }
  9971. customs = append(customs, cus)
  9972. }
  9973. }
  9974. for _, item := range customs {
  9975. var advice_id int64 = 0
  9976. var project_id int64 = 0
  9977. var item_id int64 = 0
  9978. var types int64 = 0
  9979. var med_chrgitm_type string
  9980. if item.Type == 1 {
  9981. advice_id = item.AdviceId
  9982. project_id = 0
  9983. item_id = 0
  9984. med_chrgitm_type = "09"
  9985. } else if item.Type == 2 {
  9986. med_chrgitm_type = "05"
  9987. if item.CostType == 3 {
  9988. med_chrgitm_type = "04"
  9989. }
  9990. if item.CostType == 8 {
  9991. med_chrgitm_type = "03"
  9992. }
  9993. advice_id = 0
  9994. item_id = 0
  9995. project_id = item.ProjectId
  9996. } else if item.Type == 3 {
  9997. advice_id = 0
  9998. item_id = item.ItemId
  9999. project_id = 0
  10000. med_chrgitm_type = "08"
  10001. }
  10002. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10003. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10004. pric, _ := strconv.ParseFloat(item.Price, 32)
  10005. info := &models.HisOrderInfo{
  10006. OrderNumber: order.Number,
  10007. UploadDate: time.Now().Unix(),
  10008. AdviceId: advice_id,
  10009. DetItemFeeSumamt: detItemFeeSumamt,
  10010. MedChrgitmType: med_chrgitm_type,
  10011. Cnt: cut,
  10012. Pric: pric,
  10013. PatientId: id,
  10014. Status: 1,
  10015. Mtime: time.Now().Unix(),
  10016. Ctime: time.Now().Unix(),
  10017. UserOrgId: adminUser.CurrentOrgId,
  10018. HisPatientId: his.ID,
  10019. OrderId: order.ID,
  10020. ProjectId: project_id,
  10021. Type: types,
  10022. ItemId: item_id,
  10023. }
  10024. service.CreateOrderInfoTX(info, tx)
  10025. }
  10026. his.Diagnosis = diagnosis_id
  10027. his.SickType = sick_type
  10028. his.RegisterType = reg_type
  10029. his.MedicalTreatmentType = reg_type
  10030. service.UpdataHisPateintTX(&his, tx)
  10031. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  10032. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  10033. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  10034. //判断是否使用了押金
  10035. if dec_way == "true" {
  10036. tmpstring := strconv.FormatInt(order.ID, 10)
  10037. //扣押金
  10038. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  10039. order.Decimal = decimal
  10040. service.UpDateOrderTwo(order, tx)
  10041. if errmsg != nil {
  10042. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  10043. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10044. return
  10045. }
  10046. }
  10047. if err == nil {
  10048. for _, info := range prescriptions {
  10049. if info.Type == 1 {
  10050. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  10051. }
  10052. if info.Type == 2 {
  10053. for _, sumItem := range info.HisPrescriptionProject {
  10054. if sumItem.Type == 3 {
  10055. var good models.DialysisBeforePrepareGoods
  10056. var newGood models.NewDialysisBeforePrepareGoods
  10057. var oldGood models.OldDialysisBeforePrepareGoods
  10058. good.GoodId = sumItem.GoodInfo.ID
  10059. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10060. count, _ := strconv.Atoi(sumItem.Count)
  10061. good.Count = int64(count)
  10062. good.StorehouseId = houseConfig.StorehouseOutInfo
  10063. good.ProjectId = sumItem.ID
  10064. good.PatientId = sumItem.PatientId
  10065. goods = append(goods, &good)
  10066. newGood.GoodId = sumItem.GoodInfo.ID
  10067. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10068. count2, _ := strconv.Atoi(sumItem.Count)
  10069. newGood.Count = int64(count2)
  10070. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10071. newGood.ProjectId = sumItem.ID
  10072. newGood.PatientId = sumItem.HisPatientId
  10073. newGoods = append(newGoods, &newGood)
  10074. oldGood.GoodId = sumItem.GoodInfo.ID
  10075. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10076. count3, _ := strconv.Atoi(sumItem.Count)
  10077. oldGood.Count = int64(count3)
  10078. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  10079. oldGood.ProjectId = sumItem.ID
  10080. oldGood.RecordDate = sumItem.RecordDate
  10081. oldGood.PatientId = sumItem.HisPatientId
  10082. oldGoods = append(oldGoods, &oldGood)
  10083. }
  10084. }
  10085. }
  10086. }
  10087. if settConfig.IsOpen == 1 {
  10088. for _, item := range infoList {
  10089. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  10090. if medical.IsUse == 2 {
  10091. //药品出库
  10092. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  10093. //查询默认仓库
  10094. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  10095. //查询默认仓库剩余多少库存
  10096. var sum_count int64
  10097. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  10098. for _, its := range stockInfo {
  10099. if its.MaxUnit == medical.MaxUnit {
  10100. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  10101. }
  10102. sum_count += its.StockMaxNumber + its.StockMinNumber
  10103. }
  10104. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  10105. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  10106. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  10107. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  10108. }
  10109. }
  10110. orgId := c.GetAdminUserInfo().CurrentOrgId
  10111. if len(oldGoods) > 0 {
  10112. timeStr := time.Now().Format("2006-01-02")
  10113. timeArr := strings.Split(timeStr, "-")
  10114. total, _ := service.FindAllWarehouseOut(orgId)
  10115. total = total + 1
  10116. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  10117. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  10118. number = number + total
  10119. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  10120. operation_time := time.Now().Unix()
  10121. creater := c.GetAdminUserInfo().AdminUser.Id
  10122. //查询默认出库仓库库存
  10123. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  10124. recordDateStr := time.Now().Format("2006-01-02")
  10125. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  10126. nowtime := recordDate.Unix()
  10127. warehouseOut := models.WarehouseOut{
  10128. WarehouseOutOrderNumber: warehousing_out_order,
  10129. OperationTime: operation_time,
  10130. OrgId: orgId,
  10131. Creater: creater,
  10132. Ctime: time.Now().Unix(),
  10133. Status: 1,
  10134. WarehouseOutTime: nowtime,
  10135. Type: 1,
  10136. StorehouseId: storeConfig.StorehouseOutInfo,
  10137. IsCheck: 1,
  10138. OrderId: order.ID,
  10139. IsSys: 5,
  10140. }
  10141. //查询是否生成出库单
  10142. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10143. if out.ID == 0 {
  10144. service.AddSigleWarehouseOutOne(&warehouseOut)
  10145. }
  10146. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10147. for _, item := range oldGoods {
  10148. dialyPrepareOne := models.DialysisBeforePrepare{
  10149. GoodTypeId: item.GoodTypeId,
  10150. GoodId: item.GoodId,
  10151. PatientId: his.PatientId,
  10152. RecordDate: item.RecordDate,
  10153. UserOrgId: adminUser.CurrentOrgId,
  10154. Count: item.Count,
  10155. Ctime: time.Now().Unix(),
  10156. Creater: adminUser.AdminUser.Id,
  10157. CommdityCode: item.CommdityCode,
  10158. Status: 1,
  10159. StorehouseId: houseConfig.StorehouseOutInfo,
  10160. }
  10161. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  10162. //非零用
  10163. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  10164. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10165. //查询剩余库存
  10166. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10167. var sum_count int64
  10168. for _, item := range goodList {
  10169. sum_count += item.StockCount
  10170. }
  10171. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10172. //耗材
  10173. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10174. }
  10175. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  10176. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10177. //查询剩余库存
  10178. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10179. var sum_count int64
  10180. for _, item := range goodList {
  10181. sum_count += item.StockCount
  10182. }
  10183. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10184. //耗材
  10185. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10186. }
  10187. }
  10188. }
  10189. }
  10190. c.ServeSuccessJSON(map[string]interface{}{
  10191. "msg": "结算成功",
  10192. })
  10193. }
  10194. }
  10195. }
  10196. // 退款
  10197. func (c *HisApiController) Refund() {
  10198. order_id, _ := c.GetInt64("order_id")
  10199. order, _ := service.GetHisOrderByID(order_id)
  10200. adminUser := c.GetAdminUserInfo()
  10201. orgid := c.GetAdminUserInfo().CurrentOrgId
  10202. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  10203. if err != nil {
  10204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10205. return
  10206. }
  10207. tmp := strconv.FormatInt(order.ID, 10)
  10208. //当押金不为零时产生退费记录
  10209. if order.Decimal != 0 {
  10210. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  10211. if err != nil {
  10212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10213. return
  10214. }
  10215. }
  10216. fapiao, _ := service.GetFaPiaoHisOrderByID(order_id)
  10217. if fapiao.ID > 0 {
  10218. c.ServeSuccessJSON(map[string]interface{}{
  10219. "failed_code": -10,
  10220. "msg": "该结算已经开具发票无法退费,请先红冲发票",
  10221. })
  10222. return
  10223. }
  10224. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  10225. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  10226. var goods []*models.DialysisBeforePrepareGoods
  10227. var newGoods []*models.NewDialysisBeforePrepareGoods
  10228. var infos []*models.HisDoctorAdviceInfo
  10229. for _, info := range orders {
  10230. if info.AdviceId > 0 && info.ProjectId == 0 {
  10231. infos = append(infos, &info.HisDoctorAdviceInfo)
  10232. }
  10233. if info.ProjectId > 0 && info.AdviceId == 0 {
  10234. if info.HisPrescriptionProject.Type == 3 {
  10235. var good models.DialysisBeforePrepareGoods
  10236. var newGood models.NewDialysisBeforePrepareGoods
  10237. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10238. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10239. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10240. good.Count = int64(count)
  10241. good.StorehouseId = houseConfig.StorehouseOutInfo
  10242. good.ProjectId = info.HisPrescriptionProject.ID
  10243. good.PatientId = info.PatientId
  10244. good.OrderId = order_id
  10245. goods = append(goods, &good)
  10246. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10247. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10248. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10249. newGood.Count = int64(count2)
  10250. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10251. newGood.ProjectId = info.HisPrescriptionProject.ID
  10252. newGood.RecordDate = order.SettleAccountsDate
  10253. newGood.UserOrgId = order.UserOrgId
  10254. newGood.PatientId = info.PatientId
  10255. newGood.OrderId = order_id
  10256. newGoods = append(newGoods, &newGood)
  10257. }
  10258. }
  10259. }
  10260. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  10261. if settConfig.IsOpen == 1 {
  10262. for _, item := range infos {
  10263. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10264. }
  10265. for _, item := range newGoods {
  10266. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10267. }
  10268. }
  10269. c.ServeSuccessJSON(map[string]interface{}{
  10270. "msg": "退费成功",
  10271. })
  10272. }
  10273. func (c *HisApiController) RefundNumber() {
  10274. his_patient_id, _ := c.GetInt64("id")
  10275. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10276. info.Status = 0
  10277. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  10278. if count > 0 {
  10279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  10280. return
  10281. }
  10282. err := service.SaveHisPatient(info)
  10283. if err == nil {
  10284. c.ServeSuccessJSON(map[string]interface{}{
  10285. "msg": "退号成功",
  10286. })
  10287. } else {
  10288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10289. return
  10290. }
  10291. }
  10292. func (this *HisApiController) AdditionalCharge() {
  10293. dataBody := make(map[string]interface{}, 0)
  10294. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10295. fmt.Println(err)
  10296. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  10297. patient_id := int64(dataBody["patient_id"].(float64))
  10298. medicineData, _ := dataBody["medicineData"].([]interface{})
  10299. adminUserInfo := this.GetAdminUserInfo()
  10300. orgId := adminUserInfo.CurrentOrgId
  10301. admin_user_id := adminUserInfo.AdminUser.Id
  10302. timeStr := time.Now().Format("2006-01-02")
  10303. timeLayout := "2006-01-02 15:04:05"
  10304. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10305. timenow := timeStringToTime.Unix()
  10306. var additionalCharges []*models.HisAdditionalCharge
  10307. for _, item := range medicineData {
  10308. var randNum int
  10309. randNum = rand.Intn(10000) + 1000
  10310. timestamp := time.Now().Unix()
  10311. tempTime := time.Unix(timestamp, 0)
  10312. timeFormat := tempTime.Format("20060102150405")
  10313. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  10314. items := item.(map[string]interface{})
  10315. money := items["price"].(string)
  10316. item_id_str := items["item_id"].(string)
  10317. name := items["name"].(string)
  10318. id_str := items["id"].(string)
  10319. moneys, _ := strconv.ParseInt(money, 10, 64)
  10320. monStr := strconv.FormatInt(moneys, 10)
  10321. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  10322. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  10323. id, _ := strconv.ParseInt(id_str, 10, 64)
  10324. additionalCharge := &models.HisAdditionalCharge{
  10325. ID: id,
  10326. HisPatientId: his_patient_id,
  10327. UserOrgId: orgId,
  10328. PatientId: patient_id,
  10329. RecordDate: timenow,
  10330. Price: monneyStr,
  10331. Status: 1,
  10332. ItemName: name,
  10333. ItemId: item_id,
  10334. AdminUserId: admin_user_id,
  10335. CreatedTime: time.Now().Unix(),
  10336. OrderStatus: 0,
  10337. PrescriptionNumber: "",
  10338. BatchNumber: "",
  10339. FeedetlSn: p_number,
  10340. }
  10341. service.CreateAdditionalCharge(additionalCharge)
  10342. additionalCharges = append(additionalCharges, additionalCharge)
  10343. }
  10344. this.ServeSuccessJSON(map[string]interface{}{
  10345. "msg": "添加成功",
  10346. "additional_charges": additionalCharges,
  10347. })
  10348. }
  10349. func (this *HisApiController) DeleteAddition() {
  10350. id, _ := this.GetInt64("id")
  10351. //TODO 需要判断是否已经结算
  10352. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  10353. if err == nil {
  10354. this.ServeSuccessJSON(map[string]interface{}{
  10355. "msg": "删除成功",
  10356. })
  10357. return
  10358. } else {
  10359. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10360. return
  10361. }
  10362. }
  10363. func (this *HisApiController) GetAdminUsers() {
  10364. adminUser := this.GetAdminUserInfo()
  10365. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  10366. this.ServeSuccessJSON(map[string]interface{}{
  10367. "doctors": doctors,
  10368. })
  10369. }
  10370. func (this *HisApiController) GetLastOrNextHisPrescription() {
  10371. change_type, _ := this.GetInt64("type", 0)
  10372. record_date := this.GetString("record_time")
  10373. patient_id, _ := this.GetInt64("patient_id", 0)
  10374. p_type, _ := this.GetInt64("p_type", 0)
  10375. timeLayout := "2006-01-02"
  10376. loc, _ := time.LoadLocation("Local")
  10377. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  10378. record_time := theAdviceRecordTime.Unix()
  10379. adminUserInfo := this.GetAdminUserInfo()
  10380. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  10381. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10382. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10383. if config.ID > 0 && config.IsOpen == 1 {
  10384. for _, subitems := range prescriptions {
  10385. for _, item := range subitems.VMHisPrescription {
  10386. for _, subItem := range item.HisDoctorAdviceInfo {
  10387. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10388. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10389. if info.RetailPrice > 0 {
  10390. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10391. subItem.Drug.RetailPrice = drug.RetailPrice
  10392. }
  10393. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10394. subItem.Drug.MinPrice = info.RetailPrice
  10395. subItem.Drug.RetailPrice = info.RetailPrice
  10396. }
  10397. }
  10398. }
  10399. }
  10400. }
  10401. }
  10402. if config.ID > 0 && config.IsOpen == 1 {
  10403. for _, subitems := range prescriptions {
  10404. for _, item := range subitems.VMHisPrescription {
  10405. for _, subItem := range item.HisPrescriptionProject {
  10406. if subItem.Type == 3 {
  10407. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10408. if info.Price > 0 {
  10409. subItem.GoodInfo.PackingPrice = info.Price
  10410. }
  10411. }
  10412. }
  10413. }
  10414. }
  10415. }
  10416. }
  10417. if err == nil {
  10418. if len(prescriptions) == 0 {
  10419. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  10420. return
  10421. } else {
  10422. this.ServeSuccessJSON(map[string]interface{}{
  10423. "prescriptions": prescriptions,
  10424. })
  10425. return
  10426. }
  10427. } else {
  10428. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10429. return
  10430. }
  10431. }
  10432. func RemoveRepeatedPurviewElementByHP(arr []service.VMOtherHisPrescriptionInfo) (newArr []service.VMOtherHisPrescriptionInfo) {
  10433. newArr = make([]service.VMOtherHisPrescriptionInfo, 0)
  10434. for i := 0; i < len(arr); i++ {
  10435. repeat := false
  10436. for j := i + 1; j < len(arr); j++ {
  10437. if arr[i].PatientId == arr[j].PatientId && arr[i].RecordDate == arr[j].RecordDate {
  10438. repeat = true
  10439. break
  10440. }
  10441. }
  10442. if !repeat {
  10443. newArr = append(newArr, arr[i])
  10444. }
  10445. }
  10446. return
  10447. }
  10448. func (this *HisApiController) GetCallHisPrescription() {
  10449. patient_id, _ := this.GetInt64("patient_id", 0)
  10450. timeLayout := "2006-01-02"
  10451. loc, _ := time.LoadLocation("Local")
  10452. start_time := this.GetString("start_time")
  10453. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10454. end_time := this.GetString("end_time")
  10455. p_type, _ := this.GetInt64("p_type")
  10456. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10457. adminUserInfo := this.GetAdminUserInfo()
  10458. new_prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  10459. prescriptions := RemoveRepeatedPurviewElementByHP(new_prescriptions)
  10460. //if
  10461. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  10462. //
  10463. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  10464. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10465. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10466. if config.ID > 0 && config.IsOpen == 1 {
  10467. for _, subitems := range prescriptions {
  10468. for _, item := range subitems.VMHisPrescription {
  10469. for _, subItem := range item.HisDoctorAdviceInfo {
  10470. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10471. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10472. if info.RetailPrice > 0 {
  10473. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10474. subItem.Drug.RetailPrice = drug.RetailPrice
  10475. }
  10476. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10477. subItem.Drug.MinPrice = info.RetailPrice
  10478. subItem.Drug.RetailPrice = info.RetailPrice
  10479. }
  10480. }
  10481. }
  10482. }
  10483. }
  10484. }
  10485. if config.ID > 0 && config.IsOpen == 1 {
  10486. for _, subitems := range prescriptions {
  10487. for _, item := range subitems.VMHisPrescription {
  10488. for _, subItem := range item.HisPrescriptionProject {
  10489. if subItem.Type == 3 {
  10490. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10491. if info.Price > 0 {
  10492. subItem.GoodInfo.PackingPrice = info.Price
  10493. }
  10494. }
  10495. }
  10496. }
  10497. }
  10498. }
  10499. }
  10500. if err == nil {
  10501. this.ServeSuccessJSON(map[string]interface{}{
  10502. "prescriptions": prescriptions,
  10503. })
  10504. return
  10505. } else {
  10506. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10507. return
  10508. }
  10509. }
  10510. func (this *HisApiController) GetHisDayPrescription() {
  10511. timeLayout := "2006-01-02"
  10512. loc, _ := time.LoadLocation("Local")
  10513. start_time := this.GetString("start_time")
  10514. patient_id, _ := this.GetInt64("patient_id", 0)
  10515. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10516. end_time := this.GetString("end_time")
  10517. p_type, _ := this.GetInt64("p_type")
  10518. order_status, _ := this.GetInt64("type")
  10519. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10520. adminUserInfo := this.GetAdminUserInfo()
  10521. var dayHisPrescription []*models.HisPrescription
  10522. var err error
  10523. if order_status == 1 || order_status == 0 {
  10524. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10525. } else if order_status == 2 {
  10526. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10527. }
  10528. var settle_total float64
  10529. for _, item := range dayHisPrescription {
  10530. if len(item.HisPrescriptionProject) > 0 {
  10531. for _, subItem := range item.HisPrescriptionProject {
  10532. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10533. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10534. settle_total = settle_total + total
  10535. }
  10536. }
  10537. if len(item.HisDoctorAdviceInfo) > 0 {
  10538. for _, subItem := range item.HisDoctorAdviceInfo {
  10539. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10540. settle_total = settle_total + total
  10541. }
  10542. }
  10543. }
  10544. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10545. if err == nil {
  10546. this.ServeSuccessJSON(map[string]interface{}{
  10547. "day_prescription": dayHisPrescription,
  10548. "settle_total": settle_total,
  10549. })
  10550. return
  10551. } else {
  10552. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10553. return
  10554. }
  10555. }
  10556. func (c *HisApiController) GetHisChargePatientList() {
  10557. record_date := c.GetString("record_date")
  10558. order_status, _ := c.GetInt64("type")
  10559. sch_type, _ := c.GetInt64("sch_type")
  10560. timeLayout := "2006-01-02"
  10561. loc, _ := time.LoadLocation("Local")
  10562. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10563. if err != nil {
  10564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10565. return
  10566. }
  10567. recordDateTime := theTime.Unix()
  10568. adminInfo := c.GetAdminUserInfo()
  10569. var tempPatients []*service.NewTempPatients
  10570. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10571. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10572. if order_status != 2 {
  10573. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10574. } else {
  10575. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10576. }
  10577. } else {
  10578. if order_status != 2 {
  10579. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10580. } else {
  10581. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10582. }
  10583. }
  10584. var patients []*service.NewTempPatients
  10585. var patients_two []*service.NewTempPatients
  10586. for _, item := range tempPatients {
  10587. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10588. //过滤掉没挂号的和没开处方的
  10589. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10590. patients = append(patients, item)
  10591. }
  10592. //过滤掉没挂号的
  10593. if len(item.HisPatient) > 0 {
  10594. patients_two = append(patients_two, item)
  10595. }
  10596. } else {
  10597. if len(item.HisPrescription) > 0 {
  10598. patients = append(patients, item)
  10599. }
  10600. }
  10601. }
  10602. c.ServeSuccessJSON(map[string]interface{}{
  10603. "list": patients,
  10604. "list_two": patients_two,
  10605. })
  10606. }
  10607. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10608. record_date := c.GetString("record_date")
  10609. timeLayout := "2006-01-02"
  10610. loc, _ := time.LoadLocation("Local")
  10611. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10612. if err != nil {
  10613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10614. return
  10615. }
  10616. recordDateTime := theTime.Unix()
  10617. adminUser := c.GetAdminUserInfo()
  10618. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10619. var patients []*service.Patients
  10620. for _, item := range tempPatients {
  10621. if item.HisPatient.ID == 0 {
  10622. patients = append(patients, item)
  10623. }
  10624. }
  10625. c.ServeSuccessJSON(map[string]interface{}{
  10626. "list": patients,
  10627. //"list_two": patients_two,
  10628. })
  10629. }
  10630. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10631. newArr = make([]*service.Patients, 0)
  10632. for i := 0; i < len(patient); i++ {
  10633. repeat := false
  10634. for j := i + 1; j < len(patient); j++ {
  10635. if patient[i].ID == patient[j].ID {
  10636. repeat = true
  10637. break
  10638. }
  10639. }
  10640. if !repeat {
  10641. newArr = append(newArr, patient[i])
  10642. }
  10643. }
  10644. return
  10645. }
  10646. func (c *HisApiController) GetHisChargePatientInfo() {
  10647. patient_id, _ := c.GetInt64("patient_id")
  10648. his_patient_id, _ := c.GetInt64("his_patient_id")
  10649. record_date := c.GetString("record_date")
  10650. //start_time := c.GetString("start_time")
  10651. //end_time := c.GetString("end_time")
  10652. order_status, _ := c.GetInt64("type", 0)
  10653. p_type, _ := c.GetInt64("p_type", 0)
  10654. order_id, _ := c.GetInt64("order_id", 0)
  10655. timeLayout := "2006-01-02"
  10656. loc, _ := time.LoadLocation("Local")
  10657. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10658. if err != nil {
  10659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10660. return
  10661. }
  10662. recordDateTime := theTime.Unix()
  10663. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10664. //if err != nil {
  10665. //
  10666. //}
  10667. //startRecordDateTime := startTime.Unix()
  10668. //
  10669. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10670. //if err != nil {
  10671. //
  10672. //}
  10673. //endRecordDateTime := endTime.Unix()
  10674. admin := c.GetAdminUserInfo()
  10675. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10676. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10677. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10678. var prescriptions []*models.HisPrescription
  10679. //var unChargeMonthPrescriptions []*models.HisPrescription
  10680. order, _ := service.GetHisOrderByID(order_id)
  10681. if order_status == 1 || order_status == 0 {
  10682. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10683. } else if order_status == 2 {
  10684. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10685. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10686. }
  10687. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10688. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10689. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10690. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10691. //获取所有科室信息
  10692. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10693. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10694. c.ServeSuccessJSON(map[string]interface{}{
  10695. "his_info": his_patient_info,
  10696. "last_his_patient_info": last_his_patient_info,
  10697. "xt_info": xt_patient_info,
  10698. "prescription": prescriptions,
  10699. "case_history": case_history,
  10700. "info": patientPrescriptionInfo,
  10701. "last_info": lastPatientPrescriptionInfo,
  10702. "order": order,
  10703. "doctors": doctors,
  10704. "department": department,
  10705. "sch": sch,
  10706. })
  10707. return
  10708. }
  10709. func (c *HisApiController) GetAllOrderDetail() {
  10710. order_id, _ := c.GetInt64("id", 0)
  10711. order, _ := service.GetHisOrderByID(order_id)
  10712. if order.ID == 0 {
  10713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10714. return
  10715. }
  10716. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10717. org_id := c.GetAdminUserInfo().CurrentOrgId
  10718. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10719. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10720. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10721. c.ServeSuccessJSON(map[string]interface{}{
  10722. "order": order,
  10723. "order_info": order_info,
  10724. "patient": patient,
  10725. "admin_info": adminInfo,
  10726. "hospital_record": record,
  10727. })
  10728. return
  10729. }
  10730. func (c *HisApiController) GetAllOrderDetailCollect() {
  10731. order_id, _ := c.GetInt64("id", 0)
  10732. order, _ := service.GetHisOrderByID(order_id)
  10733. if order.ID == 0 {
  10734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10735. return
  10736. }
  10737. org_id := c.GetAdminUserInfo().CurrentOrgId
  10738. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10739. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10740. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10741. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10742. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10743. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10744. var bedCostTotal float64 = 0 //床位总费
  10745. //var bedCostSelfTotal float64 = 0 //床位自费
  10746. var operationCostTotal float64 = 0 //手术费
  10747. //var operationCostSelfTotal float64 = 0 //手术费
  10748. var otherCostTotal float64 = 0 //其他费用
  10749. //var otherCostSelfTotal float64 = 0 //其他费用
  10750. var materialCostTotal float64 = 0 //材料费
  10751. //var materialCostSelfTotal float64 = 0 //材料费
  10752. var westernMedicineCostTotal float64 = 0 //西药费
  10753. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10754. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10755. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10756. var checkCostTotal float64 = 0 //检查费
  10757. //var checkCostSelfTotal float64 = 0 //检查费
  10758. var laboratoryCostTotal float64 = 0 //化验费
  10759. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10760. var treatCostTotal float64 = 0 //治疗费用
  10761. //var treatCostSelfTotal float64 = 0 //治疗费用
  10762. var zhenChaCostTotal float64 = 0 //其他费用
  10763. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10764. decimal.DivisionPrecision = 2
  10765. var BalanceAccountsType int64
  10766. if his.ID > 0 {
  10767. BalanceAccountsType = his.BalanceAccountsType
  10768. } else {
  10769. BalanceAccountsType = record.BalanceAccountsType
  10770. }
  10771. if BalanceAccountsType != 2 {
  10772. for _, item := range order_info {
  10773. if org_id == 10215 {
  10774. if item.MedChrgitmType == "01" { //床位费
  10775. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10776. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10777. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10778. }
  10779. if item.MedChrgitmType == "02" { //诊察费
  10780. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10781. //zhenChaCostSelfTotal = zhenChaCostTotal
  10782. }
  10783. if item.MedChrgitmType == "03" { //检查费
  10784. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10785. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10786. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10787. }
  10788. //if item.MedChrgitmType == "02" { //检查费
  10789. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10790. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10791. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10792. //}
  10793. if item.MedChrgitmType == "04" { //化验费
  10794. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10795. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10796. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10797. }
  10798. if item.MedChrgitmType == "05" { //治疗费
  10799. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10800. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10801. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10802. }
  10803. if item.MedChrgitmType == "06" { //手术费
  10804. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10805. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10806. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10807. }
  10808. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10809. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10810. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10811. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10812. }
  10813. if item.MedChrgitmType == "09" { //西药费
  10814. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10815. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10816. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10817. }
  10818. if item.MedChrgitmType == "11" { //中成费
  10819. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10820. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10821. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10822. }
  10823. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10824. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10825. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10826. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10827. }
  10828. } else if org_id == 10188 || org_id == 10217 {
  10829. if item.MedChrgitmType == "01" { //床位费
  10830. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10831. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10832. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10833. }
  10834. if item.MedChrgitmType == "02" { //诊察费
  10835. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10836. //zhenChaCostSelfTotal = zhenChaCostTotal
  10837. }
  10838. if item.MedChrgitmType == "03" { //检查费
  10839. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10840. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10841. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10842. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10843. }
  10844. //if item.MedChrgitmType == "02" { //检查费
  10845. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10846. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10847. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10848. //}
  10849. if item.MedChrgitmType == "04" { //化验费
  10850. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10851. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10852. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10853. }
  10854. if item.MedChrgitmType == "05" { //治疗费
  10855. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10856. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10857. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10858. }
  10859. if item.MedChrgitmType == "06" { //手术费
  10860. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10861. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10862. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10863. }
  10864. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10865. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10866. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10867. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10868. }
  10869. if item.MedChrgitmType == "09" { //西药费
  10870. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10871. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10872. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10873. }
  10874. if item.MedChrgitmType == "11" { //中成费
  10875. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10876. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10877. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10878. }
  10879. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10880. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10881. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10882. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10883. }
  10884. } else {
  10885. if item.MedChrgitmType == "01" { //床位费
  10886. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10887. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10888. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10889. }
  10890. //if item.MedChrgitmType == "02" { //诊察费
  10891. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10892. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10893. //}
  10894. if item.MedChrgitmType == "03" { //检查费
  10895. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10896. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10897. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10898. }
  10899. //if item.MedChrgitmType == "02" { //检查费
  10900. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10901. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10902. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10903. //}
  10904. if item.MedChrgitmType == "04" { //化验费
  10905. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10906. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10907. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10908. }
  10909. if item.MedChrgitmType == "05" { //治疗费
  10910. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10911. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10912. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10913. }
  10914. if item.MedChrgitmType == "06" { //手术费
  10915. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10916. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10917. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10918. }
  10919. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10920. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10921. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10922. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10923. }
  10924. if item.MedChrgitmType == "09" { //西药费
  10925. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10926. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10927. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10928. }
  10929. if item.MedChrgitmType == "11" { //中成费
  10930. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10931. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10932. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10933. }
  10934. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10935. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10936. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10937. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10938. }
  10939. }
  10940. }
  10941. c.ServeSuccessJSON(map[string]interface{}{
  10942. "order": order,
  10943. "order_info": order_info,
  10944. "patient": patient,
  10945. "admin_info": adminInfo,
  10946. "his_hospital": record,
  10947. "bedCostTotal": bedCostTotal,
  10948. "operationCostTotal": operationCostTotal,
  10949. "otherCostTotal": otherCostTotal,
  10950. "materialCostTotal": materialCostTotal,
  10951. "westernMedicineCostTotal": westernMedicineCostTotal,
  10952. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10953. "checkCostTotal": checkCostTotal,
  10954. "zhenChaCostTotal": zhenChaCostTotal,
  10955. "laboratoryCostTotal": laboratoryCostTotal,
  10956. "treatCostTotal": treatCostTotal,
  10957. })
  10958. } else {
  10959. for _, item := range order_info {
  10960. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10961. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10962. item.MedChrgitmType = "09"
  10963. }
  10964. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10965. if item.HisPrescriptionProject.Type == 2 {
  10966. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10967. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10968. case 0:
  10969. item.MedChrgitmType = "0"
  10970. break
  10971. case 1:
  10972. item.MedChrgitmType = "14"
  10973. break
  10974. case 2:
  10975. item.MedChrgitmType = "05"
  10976. break
  10977. case 3:
  10978. item.MedChrgitmType = "03"
  10979. break
  10980. case 4:
  10981. item.MedChrgitmType = "03"
  10982. break
  10983. case 5:
  10984. item.MedChrgitmType = "08"
  10985. break
  10986. case 6:
  10987. item.MedChrgitmType = "14"
  10988. break
  10989. case 7:
  10990. item.MedChrgitmType = "14"
  10991. break
  10992. case 8:
  10993. item.MedChrgitmType = "03"
  10994. break
  10995. case 9:
  10996. item.MedChrgitmType = "14"
  10997. break
  10998. case 10:
  10999. item.MedChrgitmType = "14"
  11000. break
  11001. case 11:
  11002. item.MedChrgitmType = "06"
  11003. break
  11004. case 12:
  11005. item.MedChrgitmType = "12"
  11006. break
  11007. case 13:
  11008. item.MedChrgitmType = "01"
  11009. break
  11010. case 14:
  11011. item.MedChrgitmType = "04"
  11012. break
  11013. case 15:
  11014. item.MedChrgitmType = "14"
  11015. break
  11016. }
  11017. } else {
  11018. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11019. case 1:
  11020. item.MedChrgitmType = "14"
  11021. break
  11022. case 2:
  11023. item.MedChrgitmType = "05"
  11024. break
  11025. case 3:
  11026. item.MedChrgitmType = "04"
  11027. break
  11028. case 4:
  11029. item.MedChrgitmType = "14"
  11030. break
  11031. case 5:
  11032. item.MedChrgitmType = "08"
  11033. break
  11034. case 6:
  11035. item.MedChrgitmType = "14"
  11036. break
  11037. case 7:
  11038. item.MedChrgitmType = "14"
  11039. break
  11040. case 8:
  11041. item.MedChrgitmType = "03"
  11042. break
  11043. case 9:
  11044. item.MedChrgitmType = "14"
  11045. break
  11046. }
  11047. }
  11048. } else if item.HisPrescriptionProject.Type == 3 {
  11049. item.MedChrgitmType = "08"
  11050. }
  11051. }
  11052. }
  11053. for _, item := range order_info {
  11054. if org_id == 10215 {
  11055. if item.MedChrgitmType == "01" { //床位费
  11056. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11057. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11058. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11059. }
  11060. if item.MedChrgitmType == "02" { //诊察费
  11061. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11062. //zhenChaCostSelfTotal = zhenChaCostTotal
  11063. }
  11064. if item.MedChrgitmType == "03" { //检查费
  11065. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11066. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11067. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11068. }
  11069. //if item.MedChrgitmType == "02" { //检查费
  11070. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11071. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11072. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11073. //}
  11074. if item.MedChrgitmType == "04" { //化验费
  11075. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11076. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11077. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11078. }
  11079. if item.MedChrgitmType == "05" { //治疗费
  11080. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11081. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11082. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11083. }
  11084. if item.MedChrgitmType == "06" { //手术费
  11085. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11086. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11087. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11088. }
  11089. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11090. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11091. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11092. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11093. }
  11094. if item.MedChrgitmType == "09" { //西药费
  11095. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11096. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11097. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11098. }
  11099. if item.MedChrgitmType == "11" { //中成费
  11100. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11101. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11102. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11103. }
  11104. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11105. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11106. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11107. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11108. }
  11109. } else {
  11110. if item.MedChrgitmType == "01" { //床位费
  11111. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11112. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11113. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11114. }
  11115. //if item.MedChrgitmType == "02" { //诊察费
  11116. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11117. // //zhenChaCostSelfTotal = zhenChaCostTotal
  11118. //}
  11119. if item.MedChrgitmType == "03" { //检查费
  11120. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11121. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11122. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11123. }
  11124. //if item.MedChrgitmType == "02" { //检查费
  11125. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11126. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11127. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11128. //}
  11129. if item.MedChrgitmType == "04" { //化验费
  11130. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11131. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11132. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11133. }
  11134. if item.MedChrgitmType == "05" { //治疗费
  11135. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11136. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11137. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11138. }
  11139. if item.MedChrgitmType == "06" { //手术费
  11140. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11141. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11142. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11143. }
  11144. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11145. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11146. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11147. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11148. }
  11149. if item.MedChrgitmType == "09" { //西药费
  11150. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11151. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11152. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11153. }
  11154. if item.MedChrgitmType == "11" { //中成费
  11155. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11156. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11157. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11158. }
  11159. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11160. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11161. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11162. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11163. }
  11164. }
  11165. }
  11166. c.ServeSuccessJSON(map[string]interface{}{
  11167. "order": order,
  11168. "order_info": order_info,
  11169. "patient": patient,
  11170. "admin_info": adminInfo,
  11171. "his_hospital": record,
  11172. "bedCostTotal": bedCostTotal,
  11173. "operationCostTotal": operationCostTotal,
  11174. "otherCostTotal": otherCostTotal,
  11175. "materialCostTotal": materialCostTotal,
  11176. "westernMedicineCostTotal": westernMedicineCostTotal,
  11177. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11178. "checkCostTotal": checkCostTotal,
  11179. "zhenChaCostTotal": zhenChaCostTotal,
  11180. "laboratoryCostTotal": laboratoryCostTotal,
  11181. "treatCostTotal": treatCostTotal,
  11182. })
  11183. }
  11184. }
  11185. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  11186. page, _ := c.GetInt64("page")
  11187. limit, _ := c.GetInt64("limit")
  11188. keywords := c.GetString("keywords")
  11189. start_time := c.GetString("start_time")
  11190. end_time := c.GetString("end_time")
  11191. //clr_type := c.GetString("clr_type")
  11192. insutype := c.GetString("insutype")
  11193. timeLayout := "2006-01-02"
  11194. loc, _ := time.LoadLocation("Local")
  11195. var theStartTIme int64
  11196. if len(start_time) > 0 {
  11197. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11198. theStartTIme = theTime.Unix()
  11199. }
  11200. var theEndtTIme int64
  11201. if len(end_time) > 0 {
  11202. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11203. theEndtTIme = theTime.Unix()
  11204. }
  11205. if page <= 0 {
  11206. page = 1
  11207. }
  11208. if limit <= 0 {
  11209. limit = 10
  11210. }
  11211. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  11212. c.ServeSuccessJSON(map[string]interface{}{
  11213. "total": total,
  11214. "list": list,
  11215. })
  11216. return
  11217. }
  11218. func (c *HisApiController) GetPutOnRecordList() {
  11219. page, _ := c.GetInt64("page")
  11220. limit, _ := c.GetInt64("limit")
  11221. keywords := c.GetString("keywords")
  11222. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  11223. if page <= 0 {
  11224. page = 1
  11225. }
  11226. if limit <= 0 {
  11227. limit = 10
  11228. }
  11229. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  11230. c.ServeSuccessJSON(map[string]interface{}{
  11231. "total": total,
  11232. "list": list,
  11233. })
  11234. return
  11235. }
  11236. func (c *HisApiController) GetCompareData() {
  11237. start_time := c.GetString("start_time")
  11238. end_time := c.GetString("end_time")
  11239. insutype := c.GetString("insutype")
  11240. clr_type := c.GetString("clr_type")
  11241. timeLayout := "2006-01-02"
  11242. loc, _ := time.LoadLocation("Local")
  11243. var theStartTIme int64
  11244. if len(start_time) > 0 {
  11245. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11246. if err != nil {
  11247. theStartTIme = 0
  11248. }
  11249. theStartTIme = theTime.Unix()
  11250. }
  11251. var theEndtTIme int64
  11252. if len(end_time) > 0 {
  11253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11254. if err != nil {
  11255. theEndtTIme = 0
  11256. }
  11257. theEndtTIme = theTime.Unix()
  11258. }
  11259. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  11260. fmt.Println(err)
  11261. if err == nil {
  11262. c.ServeSuccessJSON(map[string]interface{}{
  11263. "list": formData,
  11264. })
  11265. } else {
  11266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  11267. return
  11268. }
  11269. }
  11270. func (c *HisApiController) GetFaPiaoData() {
  11271. order_id, _ := c.GetInt64("order_id")
  11272. patient_id, _ := c.GetInt64("patient_id")
  11273. //number := c.GetString("number")
  11274. adminUser := c.GetAdminUserInfo()
  11275. order, _ := service.GetHisOrderByID(order_id)
  11276. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11277. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11278. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11279. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11280. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  11281. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  11282. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11283. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11284. var bedCostTotal float64 = 0 //床位总费
  11285. var bedCostSelfTotal float64 = 0 //床位自费
  11286. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11287. var operationCostTotal float64 = 0 //手术费
  11288. var operationCostSelfTotal float64 = 0 //手术费
  11289. var operationCostPartSelfTotal float64 = 0 //手术费
  11290. var otherCostTotal float64 = 0 //其他费用
  11291. var otherCostSelfTotal float64 = 0 //其他费用
  11292. var otherCostPartSelfTotal float64 = 0 //其他费用
  11293. var materialCostTotal float64 = 0 //材料费
  11294. var materialCostSelfTotal float64 = 0 //材料费
  11295. var materialCostPartSelfTotal float64 = 0 //材料费
  11296. var westernMedicineCostTotal float64 = 0 //西药费
  11297. var westernMedicineCostSelfTotal float64 = 0 //西药费
  11298. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11299. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11300. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11301. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11302. var checkCostTotal float64 = 0 //检查费
  11303. var checkCostSelfTotal float64 = 0 //检查费
  11304. var checkCostPartSelfTotal float64 = 0 //检查费
  11305. var hiliCostTotal float64 = 0 //护理费
  11306. var hiliCostSelfTotal float64 = 0 //护理费
  11307. var hiliCostPartSelfTotal float64 = 0 //护理费
  11308. var laboratoryCostTotal float64 = 0 //化验费
  11309. var laboratoryCostSelfTotal float64 = 0 //化验费
  11310. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11311. var treatCostTotal float64 = 0 //治疗费用
  11312. var treatCostSelfTotal float64 = 0 //治疗费用
  11313. var treatCostPartSelfTotal float64 = 0 //治疗费用
  11314. var zhenChaCostTotal float64 = 0 //其他费用
  11315. var zhenChaCostSelfTotal float64 = 0 //其他费用
  11316. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11317. decimal.DivisionPrecision = 2
  11318. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11319. var balanceAccountsType int64
  11320. if his.ID > 0 {
  11321. balanceAccountsType = his.BalanceAccountsType
  11322. } else {
  11323. balanceAccountsType = his_hospital_record.BalanceAccountsType
  11324. }
  11325. if balanceAccountsType == 2 {
  11326. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11327. for _, item := range orderInfos_two {
  11328. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11329. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11330. item.MedChrgitmType = "09"
  11331. }
  11332. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11333. if item.HisPrescriptionProject.Type == 2 {
  11334. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11335. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11336. case 0:
  11337. item.MedChrgitmType = "0"
  11338. break
  11339. case 1:
  11340. item.MedChrgitmType = "14"
  11341. break
  11342. case 2:
  11343. item.MedChrgitmType = "05"
  11344. break
  11345. case 3:
  11346. item.MedChrgitmType = "03"
  11347. break
  11348. case 4:
  11349. item.MedChrgitmType = "03"
  11350. break
  11351. case 5:
  11352. item.MedChrgitmType = "08"
  11353. break
  11354. case 6:
  11355. item.MedChrgitmType = "14"
  11356. break
  11357. case 7:
  11358. item.MedChrgitmType = "14"
  11359. break
  11360. case 8:
  11361. item.MedChrgitmType = "03"
  11362. break
  11363. case 9:
  11364. item.MedChrgitmType = "14"
  11365. break
  11366. case 10:
  11367. item.MedChrgitmType = "14"
  11368. break
  11369. case 11:
  11370. item.MedChrgitmType = "06"
  11371. break
  11372. case 12:
  11373. item.MedChrgitmType = "12"
  11374. break
  11375. case 13:
  11376. item.MedChrgitmType = "01"
  11377. break
  11378. case 14:
  11379. item.MedChrgitmType = "04"
  11380. break
  11381. case 15:
  11382. item.MedChrgitmType = "02"
  11383. break
  11384. }
  11385. } else {
  11386. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11387. case 1:
  11388. item.MedChrgitmType = "14"
  11389. break
  11390. case 2:
  11391. item.MedChrgitmType = "05"
  11392. break
  11393. case 3:
  11394. item.MedChrgitmType = "04"
  11395. break
  11396. case 4:
  11397. item.MedChrgitmType = "03"
  11398. break
  11399. case 5:
  11400. item.MedChrgitmType = "08"
  11401. break
  11402. case 6:
  11403. item.MedChrgitmType = "14"
  11404. break
  11405. case 7:
  11406. item.MedChrgitmType = "14"
  11407. break
  11408. case 8:
  11409. item.MedChrgitmType = "03"
  11410. break
  11411. case 9:
  11412. item.MedChrgitmType = "14"
  11413. break
  11414. }
  11415. }
  11416. } else if item.HisPrescriptionProject.Type == 3 {
  11417. item.MedChrgitmType = "08"
  11418. }
  11419. }
  11420. }
  11421. for _, item := range orderInfos_two {
  11422. fmt.Println(item.MedChrgitmType)
  11423. if item.MedChrgitmType == "07" { //床位费
  11424. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11425. hiliCostSelfTotal = hiliCostTotal
  11426. }
  11427. if item.MedChrgitmType == "01" { //床位费
  11428. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11429. bedCostSelfTotal = bedCostTotal
  11430. }
  11431. if item.MedChrgitmType == "02" { //诊察费
  11432. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11433. zhenChaCostSelfTotal = zhenChaCostTotal
  11434. }
  11435. if item.MedChrgitmType == "03" { //检查费
  11436. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11437. checkCostSelfTotal = checkCostTotal
  11438. }
  11439. if item.MedChrgitmType == "04" { //化验费
  11440. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11441. laboratoryCostSelfTotal = laboratoryCostTotal
  11442. }
  11443. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11444. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11445. treatCostSelfTotal = treatCostTotal
  11446. }
  11447. if item.MedChrgitmType == "06" { //手术费
  11448. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11449. operationCostSelfTotal = treatCostTotal
  11450. }
  11451. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  11452. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11453. materialCostSelfTotal = materialCostTotal
  11454. }
  11455. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11456. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11457. westernMedicineCostSelfTotal = westernMedicineCostTotal
  11458. }
  11459. if item.MedChrgitmType == "11" { //中成费
  11460. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11461. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11462. }
  11463. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11464. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11465. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11466. otherCostSelfTotal = otherCostTotal
  11467. }
  11468. } else {
  11469. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11470. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11471. otherCostSelfTotal = otherCostTotal
  11472. }
  11473. }
  11474. }
  11475. } else {
  11476. for _, item := range orderInfos {
  11477. if item.MedChrgitmType == "01" { //床位费
  11478. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11479. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11480. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11481. }
  11482. if item.MedChrgitmType == "02" { //诊察费
  11483. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11484. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11485. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11486. }
  11487. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11488. if item.MedChrgitmType == "03" { //检查费
  11489. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11490. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11491. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11492. }
  11493. } else {
  11494. if item.MedChrgitmType == "03" { //检查费
  11495. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11496. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11497. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11498. }
  11499. }
  11500. if item.MedChrgitmType == "04" { //化验费
  11501. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11502. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11503. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11504. }
  11505. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11506. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11507. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11508. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11509. }
  11510. if item.MedChrgitmType == "06" { //手术费
  11511. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11512. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11513. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11514. }
  11515. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11516. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11517. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11518. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11519. }
  11520. if item.MedChrgitmType == "07" { //护理
  11521. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11522. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11523. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11524. }
  11525. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11526. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11527. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11528. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11529. }
  11530. if item.MedChrgitmType == "11" { //中成费
  11531. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11532. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11533. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11534. }
  11535. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11536. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11537. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11538. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11539. }
  11540. }
  11541. }
  11542. timeLayout := "2006-01-02"
  11543. loc, _ := time.LoadLocation("Local")
  11544. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11545. if err != nil {
  11546. }
  11547. startRecordDateTime := startTime.Unix()
  11548. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11549. if err != nil {
  11550. }
  11551. endRecordDateTime := endTime.Unix()
  11552. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11553. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11554. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11555. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11556. c.ServeSuccessJSON(map[string]interface{}{
  11557. "charge_admin_name": charge_admin.UserName,
  11558. "order_number": order.Number, //业务流水号
  11559. "id_card_no": his.IdCardNo, //社会保障号
  11560. "patient": patient,
  11561. "department_name": department.Name, //科室
  11562. "number": his.Number, //门诊号
  11563. "date": order.SettleAccountsDate, //结算日期
  11564. "name": order.PsnName, //姓名
  11565. "gender": patient.Gender, //性别
  11566. "psn_cash_money": order.PsnCashPay, //个人支付
  11567. "pay_way": "门诊", //结算方式
  11568. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11569. "admin_user_name": admin.UserName, //收款员
  11570. "order": order,
  11571. "order_info": orderInfos_two,
  11572. "his": his,
  11573. "bedCostTotal": bedCostTotal,
  11574. "bedCostSelfTotal": bedCostSelfTotal,
  11575. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11576. "operationCostTotal": operationCostTotal,
  11577. "operationCostSelfTotal": operationCostSelfTotal,
  11578. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11579. "otherCostTotal": otherCostTotal,
  11580. "otherCostSelfTotal": otherCostSelfTotal,
  11581. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11582. "materialCostTotal": materialCostTotal,
  11583. "materialCostSelfTotal": materialCostSelfTotal,
  11584. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11585. "westernMedicineCostTotal": westernMedicineCostTotal,
  11586. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11587. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11588. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11589. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11590. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11591. "checkCostTotal": checkCostTotal,
  11592. "checkCostSelfTotal": checkCostSelfTotal,
  11593. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11594. "laboratoryCostTotal": laboratoryCostTotal,
  11595. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11596. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11597. "treatCostTotal": treatCostTotal,
  11598. "treatCostSelfTotal": treatCostSelfTotal,
  11599. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11600. "zhenChaCostTotal": zhenChaCostTotal,
  11601. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11602. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11603. "his_hospital_record": his_hospital_record,
  11604. "pre_pay_money": pre_pay_money,
  11605. "refund_sum": sum,
  11606. "doctor_info": doctor_info,
  11607. "hiliCostTotal": hiliCostTotal,
  11608. "hiliCostSelfTotal": hiliCostSelfTotal,
  11609. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11610. })
  11611. }
  11612. //func (c *HisApiController) GetFaPiaoDatas() {
  11613. // order_ids := c.GetString("order_ids")
  11614. // patient_id, _ := c.GetInt64("patient_id")
  11615. // adminUser := c.GetAdminUserInfo()
  11616. //
  11617. // orders := strings.Split(order_ids, ",")
  11618. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11619. //
  11620. // for _, item := range orders {
  11621. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11622. // order, _ := service.GetHisOrderByID(order_id)
  11623. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11624. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11625. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11626. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11627. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11628. //
  11629. // }
  11630. //
  11631. // var bedCostTotal float64 = 0 //床位总费
  11632. // var bedCostSelfTotal float64 = 0 //床位自费
  11633. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11634. //
  11635. // var operationCostTotal float64 = 0 //手术费
  11636. // var operationCostSelfTotal float64 = 0 //手术费
  11637. // var operationCostPartSelfTotal float64 = 0 //手术费
  11638. //
  11639. // var otherCostTotal float64 = 0 //其他费用
  11640. // var otherCostSelfTotal float64 = 0 //其他费用
  11641. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11642. //
  11643. // var materialCostTotal float64 = 0 //材料费
  11644. // var materialCostSelfTotal float64 = 0 //材料费
  11645. // var materialCostPartSelfTotal float64 = 0 //材料费
  11646. //
  11647. // var westernMedicineCostTotal float64 = 0 //西药费
  11648. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11649. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11650. //
  11651. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11652. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11653. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11654. //
  11655. // var checkCostTotal float64 = 0 //检查费
  11656. // var checkCostSelfTotal float64 = 0 //检查费
  11657. // var checkCostPartSelfTotal float64 = 0 //检查费
  11658. //
  11659. // var laboratoryCostTotal float64 = 0 //化验费
  11660. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11661. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11662. //
  11663. // var treatCostTotal float64 = 0 //治疗费用
  11664. // var treatCostSelfTotal float64 = 0 //治疗费用
  11665. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11666. //
  11667. // var zhenChaCostTotal float64 = 0 //其他费用
  11668. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11669. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11670. //
  11671. // decimal.DivisionPrecision = 2
  11672. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11673. //
  11674. // var balanceAccountsType int64
  11675. // if his.ID > 0 {
  11676. // balanceAccountsType = his.BalanceAccountsType
  11677. // } else {
  11678. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11679. // }
  11680. // if balanceAccountsType == 2 {
  11681. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11682. // for _, item := range orderInfos_two {
  11683. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11684. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11685. // item.MedChrgitmType = "09"
  11686. // }
  11687. //
  11688. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11689. // if item.HisPrescriptionProject.Type == 2 {
  11690. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11691. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11692. // case 0:
  11693. // item.MedChrgitmType = "0"
  11694. // break
  11695. // case 1:
  11696. // item.MedChrgitmType = "14"
  11697. // break
  11698. // case 2:
  11699. // item.MedChrgitmType = "05"
  11700. //
  11701. // break
  11702. // case 3:
  11703. // item.MedChrgitmType = "03"
  11704. //
  11705. // break
  11706. // case 4:
  11707. // item.MedChrgitmType = "03"
  11708. //
  11709. // break
  11710. // case 5:
  11711. // item.MedChrgitmType = "08"
  11712. //
  11713. // break
  11714. // case 6:
  11715. // item.MedChrgitmType = "14"
  11716. //
  11717. // break
  11718. // case 7:
  11719. // item.MedChrgitmType = "14"
  11720. //
  11721. // break
  11722. // case 8:
  11723. // item.MedChrgitmType = "03"
  11724. // break
  11725. // case 9:
  11726. // item.MedChrgitmType = "14"
  11727. // break
  11728. // case 10:
  11729. // item.MedChrgitmType = "14"
  11730. // break
  11731. // case 11:
  11732. // item.MedChrgitmType = "06"
  11733. // break
  11734. // case 12:
  11735. // item.MedChrgitmType = "12"
  11736. // break
  11737. // case 13:
  11738. // item.MedChrgitmType = "01"
  11739. // break
  11740. // case 14:
  11741. // item.MedChrgitmType = "04"
  11742. // break
  11743. // case 15:
  11744. // item.MedChrgitmType = "02"
  11745. // break
  11746. //
  11747. // }
  11748. //
  11749. // } else {
  11750. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11751. //
  11752. // case 1:
  11753. // item.MedChrgitmType = "14"
  11754. // break
  11755. // case 2:
  11756. // item.MedChrgitmType = "05"
  11757. //
  11758. // break
  11759. // case 3:
  11760. // item.MedChrgitmType = "03"
  11761. //
  11762. // break
  11763. // case 4:
  11764. // item.MedChrgitmType = "03"
  11765. //
  11766. // break
  11767. // case 5:
  11768. // item.MedChrgitmType = "08"
  11769. //
  11770. // break
  11771. // case 6:
  11772. // item.MedChrgitmType = "14"
  11773. //
  11774. // break
  11775. // case 7:
  11776. // item.MedChrgitmType = "14"
  11777. //
  11778. // break
  11779. // case 8:
  11780. // item.MedChrgitmType = "03"
  11781. // break
  11782. // case 9:
  11783. // item.MedChrgitmType = "14"
  11784. // break
  11785. //
  11786. // }
  11787. //
  11788. // }
  11789. //
  11790. // } else if item.HisPrescriptionProject.Type == 3 {
  11791. // item.MedChrgitmType = "08"
  11792. // }
  11793. // }
  11794. // }
  11795. //
  11796. // for _, item := range orderInfos_two {
  11797. // fmt.Println(item.MedChrgitmType)
  11798. // if item.MedChrgitmType == "01" { //床位费
  11799. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11800. // bedCostSelfTotal = bedCostTotal
  11801. // }
  11802. //
  11803. // if item.MedChrgitmType == "02" { //诊察费
  11804. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11805. // zhenChaCostSelfTotal = zhenChaCostTotal
  11806. // }
  11807. //
  11808. // if item.MedChrgitmType == "03" { //检查费
  11809. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11810. // checkCostSelfTotal = checkCostTotal
  11811. // }
  11812. //
  11813. // if item.MedChrgitmType == "04" { //化验费
  11814. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11815. // laboratoryCostSelfTotal = laboratoryCostTotal
  11816. // }
  11817. //
  11818. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11819. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11820. // treatCostSelfTotal = treatCostTotal
  11821. // }
  11822. //
  11823. // if item.MedChrgitmType == "06" { //手术费
  11824. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11825. // operationCostSelfTotal = treatCostTotal
  11826. // }
  11827. //
  11828. // if item.MedChrgitmType == "08" { //材料费
  11829. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11830. // materialCostSelfTotal = materialCostTotal
  11831. // }
  11832. //
  11833. // if item.MedChrgitmType == "09" { //西药费
  11834. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11835. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11836. // }
  11837. //
  11838. // if item.MedChrgitmType == "11" { //中成费
  11839. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11840. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11841. // }
  11842. //
  11843. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11844. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11845. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11846. // otherCostSelfTotal = otherCostTotal
  11847. // }
  11848. // } else {
  11849. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11850. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11851. // otherCostSelfTotal = otherCostTotal
  11852. // }
  11853. //
  11854. // }
  11855. //
  11856. // }
  11857. //
  11858. // } else {
  11859. // for _, item := range orderInfos {
  11860. // if item.MedChrgitmType == "01" { //床位费
  11861. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11862. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11863. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11864. // }
  11865. //
  11866. // if item.MedChrgitmType == "02" { //诊察费
  11867. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11868. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11869. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11870. // }
  11871. //
  11872. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11873. // if item.MedChrgitmType == "03" { //检查费
  11874. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11875. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11876. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11877. //
  11878. // }
  11879. // } else {
  11880. // if item.MedChrgitmType == "03" { //检查费
  11881. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11882. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11883. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11884. // }
  11885. //
  11886. // }
  11887. //
  11888. // if item.MedChrgitmType == "04" { //化验费
  11889. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11890. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11891. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11892. //
  11893. // }
  11894. //
  11895. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11896. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11897. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11898. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11899. //
  11900. // }
  11901. //
  11902. // if item.MedChrgitmType == "06" { //手术费
  11903. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11904. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11905. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11906. // }
  11907. //
  11908. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11909. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11910. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11911. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11912. // }
  11913. //
  11914. // if item.MedChrgitmType == "09" { //西药费
  11915. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11916. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11917. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11918. // }
  11919. //
  11920. // if item.MedChrgitmType == "11" { //中成费
  11921. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11922. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11923. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11924. // }
  11925. //
  11926. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11927. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11928. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11929. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11930. // }
  11931. //
  11932. // }
  11933. // }
  11934. // timeLayout := "2006-01-02"
  11935. // loc, _ := time.LoadLocation("Local")
  11936. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11937. // if err != nil {
  11938. // }
  11939. // startRecordDateTime := startTime.Unix()
  11940. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11941. // if err != nil {
  11942. // }
  11943. // endRecordDateTime := endTime.Unix()
  11944. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11945. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11946. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11947. //
  11948. // c.ServeSuccessJSON(map[string]interface{}{
  11949. // "order_number": order.Number, //业务流水号
  11950. // "id_card_no": his.IdCardNo, //社会保障号
  11951. // "department_name": department.Name, //科室
  11952. // "number": his.Number, //门诊号
  11953. // "date": order.SettleAccountsDate, //结算日期
  11954. // "name": order.PsnName, //姓名
  11955. // "gender": patient.Gender, //性别
  11956. // "psn_cash_money": order.PsnCashPay, //个人支付
  11957. // "pay_way": "门诊", //结算方式
  11958. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11959. // "admin_user_name": admin.UserName, //收款员
  11960. // "order": order,
  11961. // "order_info": orderInfos_two,
  11962. // "his": his,
  11963. // "bedCostTotal": bedCostTotal,
  11964. // "bedCostSelfTotal": bedCostSelfTotal,
  11965. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11966. // "operationCostTotal": operationCostTotal,
  11967. // "operationCostSelfTotal": operationCostSelfTotal,
  11968. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11969. // "otherCostTotal": otherCostTotal,
  11970. // "otherCostSelfTotal": otherCostSelfTotal,
  11971. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11972. // "materialCostTotal": materialCostTotal,
  11973. // "materialCostSelfTotal": materialCostSelfTotal,
  11974. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11975. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11976. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11977. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11978. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11979. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11980. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11981. // "checkCostTotal": checkCostTotal,
  11982. // "checkCostSelfTotal": checkCostSelfTotal,
  11983. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11984. // "laboratoryCostTotal": laboratoryCostTotal,
  11985. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11986. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11987. // "treatCostTotal": treatCostTotal,
  11988. // "treatCostSelfTotal": treatCostSelfTotal,
  11989. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11990. // "zhenChaCostTotal": zhenChaCostTotal,
  11991. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11992. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11993. // "his_hospital_record": his_hospital_record,
  11994. // "pre_pay_money": pre_pay_money,
  11995. // "refund_sum": sum,
  11996. // })
  11997. //
  11998. //}
  11999. func (this *HisApiController) GetIncomeStatisticsData() {
  12000. start_time := this.GetString("start_time")
  12001. end_time := this.GetString("end_time")
  12002. key_words := this.GetString("key_words")
  12003. limit, _ := this.GetInt64("limit")
  12004. page, _ := this.GetInt64("page")
  12005. if page <= 0 {
  12006. page = 1
  12007. }
  12008. if limit <= 0 {
  12009. limit = 10
  12010. }
  12011. statistics_type, _ := this.GetInt64("statistics_type")
  12012. admin := this.GetAdminUserInfo()
  12013. timeLayout := "2006-01-02"
  12014. loc, _ := time.LoadLocation("Local")
  12015. var theStartTIme int64
  12016. if len(start_time) > 0 {
  12017. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12018. if err != nil {
  12019. theStartTIme = 0
  12020. }
  12021. theStartTIme = theTime.Unix()
  12022. }
  12023. var theEndtTIme int64
  12024. if len(end_time) > 0 {
  12025. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12026. if err != nil {
  12027. theEndtTIme = 0
  12028. }
  12029. theEndtTIme = theTime.Unix()
  12030. }
  12031. if statistics_type == 1 {
  12032. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  12033. this.ServeSuccessJSON(map[string]interface{}{
  12034. "list": list,
  12035. "total": total,
  12036. })
  12037. } else {
  12038. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  12039. this.ServeSuccessJSON(map[string]interface{}{
  12040. "list": list,
  12041. "total": total,
  12042. })
  12043. }
  12044. }
  12045. func (c *HisApiController) PostProjectInformation() {
  12046. adminUser := c.GetAdminUserInfo()
  12047. orgId := adminUser.CurrentOrgId
  12048. dataBody := make(map[string]interface{}, 0)
  12049. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12050. if err != nil {
  12051. utils.ErrorLog(err.Error())
  12052. return
  12053. }
  12054. utils.ErrorLog("%v", dataBody)
  12055. var projectList []*models.HisProject
  12056. var total_goods []interface{}
  12057. tempProjects := dataBody["projects"].([]interface{})
  12058. total_goods = tempProjects
  12059. for index, projectMap := range tempProjects {
  12060. projectM := projectMap.(map[string]interface{})
  12061. var project models.HisProject
  12062. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  12063. utils.ErrorLog("project_name")
  12064. return
  12065. }
  12066. project_name, _ := projectM["project_name"].(string)
  12067. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  12068. err_log := models.ExportErrLog{
  12069. LogType: 6,
  12070. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12071. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  12072. Status: 1,
  12073. CreateTime: time.Now().Unix(),
  12074. UpdateTime: time.Now().Unix(),
  12075. ExportTime: time.Now().Unix(),
  12076. }
  12077. service.CreateExportErrLog(&err_log)
  12078. continue
  12079. }
  12080. project.ProjectName = project_name
  12081. prices := projectM["price"].(string)
  12082. price, _ := strconv.ParseFloat(prices, 64)
  12083. if price <= 0 { //名字为空则生成一条导入错误日志
  12084. err_log := models.ExportErrLog{
  12085. LogType: 6,
  12086. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12087. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  12088. Status: 1,
  12089. CreateTime: time.Now().Unix(),
  12090. UpdateTime: time.Now().Unix(),
  12091. ExportTime: time.Now().Unix(),
  12092. }
  12093. service.CreateExportErrLog(&err_log)
  12094. continue
  12095. }
  12096. project.Price = price
  12097. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  12098. utils.ErrorLog("unit_id")
  12099. return
  12100. }
  12101. unit := projectM["unit"].(string)
  12102. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  12103. err_log := models.ExportErrLog{
  12104. LogType: 6,
  12105. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12106. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  12107. Status: 1,
  12108. CreateTime: time.Now().Unix(),
  12109. UpdateTime: time.Now().Unix(),
  12110. ExportTime: time.Now().Unix(),
  12111. }
  12112. service.CreateExportErrLog(&err_log)
  12113. continue
  12114. }
  12115. project.Unit = unit
  12116. cost_classify := projectM["cost_classify"].(string)
  12117. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  12118. err_log := models.ExportErrLog{
  12119. LogType: 6,
  12120. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12121. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12122. Status: 1,
  12123. CreateTime: time.Now().Unix(),
  12124. UpdateTime: time.Now().Unix(),
  12125. ExportTime: time.Now().Unix(),
  12126. }
  12127. service.CreateExportErrLog(&err_log)
  12128. continue
  12129. }
  12130. var costClassify = "费用类别"
  12131. var cost_classify_id int64
  12132. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  12133. if len(cost_classify) != 0 {
  12134. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  12135. if errcode == gorm.ErrRecordNotFound {
  12136. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  12137. dataconfig := models.DictDataconfig{
  12138. ParentId: costClassifyConfig.ID,
  12139. Module: "system",
  12140. OrgId: orgId,
  12141. Name: cost_classify,
  12142. FieldName: "",
  12143. Value: costConfig.Value + 1,
  12144. CreatedTime: "",
  12145. UpdatedTime: "",
  12146. CreateUserId: adminUser.AdminUser.Id,
  12147. Status: 1,
  12148. Remark: "",
  12149. DeleteIdSystem: 0,
  12150. Title: "",
  12151. Content: "",
  12152. Order: 0,
  12153. Code: "",
  12154. }
  12155. service.CreatedDicConfig(&dataconfig)
  12156. }
  12157. }
  12158. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  12159. for _, it := range costClassList {
  12160. if cost_classify == it.Name {
  12161. cost_classify_id = int64(it.Value)
  12162. }
  12163. }
  12164. project.CostClassify = cost_classify_id
  12165. executive_section := projectM["executive_section"].(string)
  12166. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  12167. err_log := models.ExportErrLog{
  12168. LogType: 6,
  12169. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12170. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  12171. Status: 1,
  12172. CreateTime: time.Now().Unix(),
  12173. UpdateTime: time.Now().Unix(),
  12174. ExportTime: time.Now().Unix(),
  12175. }
  12176. service.CreateExportErrLog(&err_log)
  12177. continue
  12178. }
  12179. if len(executive_section) != 0 {
  12180. //查找科室是否有内容
  12181. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  12182. if errcodedepart == gorm.ErrRecordNotFound {
  12183. department := models.XtHisDepartment{
  12184. Name: executive_section,
  12185. Status: 1,
  12186. UserOrgId: adminUser.CurrentOrgId,
  12187. CreatedTime: time.Now().Unix(),
  12188. }
  12189. service.CreateDePartment(&department)
  12190. }
  12191. }
  12192. var executive_section_id int64
  12193. departMentList, _ := service.GetAllDepartMent(orgId)
  12194. for _, it := range departMentList {
  12195. if executive_section == it.Name {
  12196. executive_section_id = it.ID
  12197. }
  12198. }
  12199. project.ExecutiveSection = executive_section_id
  12200. medical_coverage := projectM["medical_coverage"].(string)
  12201. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  12202. err_log := models.ExportErrLog{
  12203. LogType: 6,
  12204. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12205. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12206. Status: 1,
  12207. CreateTime: time.Now().Unix(),
  12208. UpdateTime: time.Now().Unix(),
  12209. ExportTime: time.Now().Unix(),
  12210. }
  12211. service.CreateExportErrLog(&err_log)
  12212. continue
  12213. }
  12214. var medicalCoverage = "医保等级"
  12215. var medical_coverage_id int64
  12216. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  12217. if len(medical_coverage) != 0 {
  12218. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  12219. if errormedicalcoverage == gorm.ErrRecordNotFound {
  12220. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  12221. dataconfig := models.DictDataconfig{
  12222. ParentId: medicalCoverageConfig.ID,
  12223. Module: "system",
  12224. OrgId: orgId,
  12225. Name: medical_coverage,
  12226. FieldName: "",
  12227. Value: medicalCoverageConfig.Value + 1,
  12228. CreatedTime: "",
  12229. UpdatedTime: "",
  12230. CreateUserId: adminUser.AdminUser.Id,
  12231. Status: 1,
  12232. Remark: "",
  12233. DeleteIdSystem: 0,
  12234. Title: "",
  12235. Content: "",
  12236. Order: 0,
  12237. Code: "",
  12238. }
  12239. service.CreatedDicConfig(&dataconfig)
  12240. }
  12241. }
  12242. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  12243. for _, it := range medicalCoverageList {
  12244. if medical_coverage == it.Name {
  12245. medical_coverage_id = int64(it.Value)
  12246. }
  12247. }
  12248. project.MedicalCoverage = medical_coverage_id
  12249. pinyin := projectM["pinyin"].(string)
  12250. project.Pinyin = pinyin
  12251. wubi := projectM["wubi"].(string)
  12252. project.Wubi = wubi
  12253. statistical_classification := projectM["statistical_classification"].(string)
  12254. var statisticalClassification = "统计分类"
  12255. var statistical_classification_id int64
  12256. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  12257. if len(statistical_classification) != 0 {
  12258. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  12259. if classificationerrcodes == gorm.ErrRecordNotFound {
  12260. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  12261. dataconfig := models.DictDataconfig{
  12262. ParentId: classiFication.ID,
  12263. Module: "system",
  12264. OrgId: orgId,
  12265. Name: statistical_classification,
  12266. FieldName: "",
  12267. Value: classiFicationConfig.Value + 1,
  12268. CreatedTime: "",
  12269. UpdatedTime: "",
  12270. CreateUserId: adminUser.AdminUser.Id,
  12271. Status: 1,
  12272. Remark: "",
  12273. DeleteIdSystem: 0,
  12274. Title: "",
  12275. Content: "",
  12276. Order: 0,
  12277. Code: "",
  12278. }
  12279. service.CreatedDicConfig(&dataconfig)
  12280. }
  12281. }
  12282. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  12283. for _, it := range classiFicationList {
  12284. if statistical_classification == it.Name {
  12285. statistical_classification_id = int64(it.Value)
  12286. }
  12287. }
  12288. project.StatisticalClassification = statistical_classification_id
  12289. disease_directory := int64(projectM["disease_directory"].(float64))
  12290. project.DiseaseDirectory = disease_directory
  12291. is_record := int64(projectM["is_record"].(float64))
  12292. project.IsRecord = is_record
  12293. medical_code := projectM["medical_code"].(string)
  12294. project.MedicalCode = medical_code
  12295. tube_color := projectM["tube_color"].(string)
  12296. var tubeColor = "试管颜色"
  12297. var tube_color_id int64
  12298. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  12299. if len(tube_color) != 0 {
  12300. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  12301. if errcodetube == gorm.ErrRecordNotFound {
  12302. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  12303. dataconfig := models.DictDataconfig{
  12304. ParentId: tubeColorConfig.ID,
  12305. Module: "system",
  12306. OrgId: orgId,
  12307. Name: tube_color,
  12308. FieldName: "",
  12309. Value: tubeConfig.Value + 1,
  12310. CreatedTime: "",
  12311. UpdatedTime: "",
  12312. CreateUserId: adminUser.AdminUser.Id,
  12313. Status: 1,
  12314. Remark: "",
  12315. DeleteIdSystem: 0,
  12316. Title: "",
  12317. Content: "",
  12318. Order: 0,
  12319. Code: "",
  12320. }
  12321. service.CreatedDicConfig(&dataconfig)
  12322. }
  12323. }
  12324. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  12325. for _, it := range tubeColorList {
  12326. if tube_color == it.Name {
  12327. tube_color_id = int64(it.Value)
  12328. }
  12329. }
  12330. project.TubeColor = tube_color_id
  12331. single_dose := projectM["single_dose"].(string)
  12332. project.SingleDose = single_dose
  12333. execution_frequency := projectM["execution_frequency"].(string)
  12334. project.ExecutionFrequency = execution_frequency
  12335. delivery_way := projectM["delivery_way"].(string)
  12336. project.DeliveryWay = delivery_way
  12337. number_days := projectM["number_days"].(string)
  12338. project.NumberDays = number_days
  12339. total := projectM["total"].(string)
  12340. project.Total = total
  12341. medical_status := int64(projectM["medical_status"].(float64))
  12342. project.MedicalStatus = medical_status
  12343. category := int64(projectM["category"].(float64))
  12344. project.Category = category
  12345. specail_project := int64(projectM["specail_project"].(float64))
  12346. project.SpecailProject = specail_project
  12347. social_security_directory_code := projectM["social_security_directory_code"].(string)
  12348. project.SocialSecurityDirectoryCode = social_security_directory_code
  12349. remark := projectM["remark"].(string)
  12350. project.Remark = remark
  12351. record_date := projectM["record_date"].(string)
  12352. timeLayout := "2006-01-02"
  12353. loc, _ := time.LoadLocation("Local")
  12354. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12355. project.RecordDate = theTime.Unix()
  12356. projectList = append(projectList, &project)
  12357. }
  12358. export_time := time.Now().Unix()
  12359. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  12360. if len(projectList) > 0 {
  12361. for _, item := range projectList {
  12362. hans := item.ProjectName // 要转换的汉字字符串
  12363. // 创建一个拼音转换器
  12364. p := pinyin.NewArgs()
  12365. // 将汉字转为拼音
  12366. pinyinSlice := pinyin.Pinyin(hans, p)
  12367. // 输出拼音
  12368. fmt.Println("Pinyin:", pinyinSlice)
  12369. // 获取首字母
  12370. firstLetter := ""
  12371. for _, py := range pinyinSlice {
  12372. if len(py) > 0 {
  12373. firstLetter += string(py[0][0])
  12374. }
  12375. }
  12376. item.FirstLetter = firstLetter
  12377. project := models.HisProject{
  12378. ProjectName: item.ProjectName,
  12379. Price: item.Price,
  12380. Unit: item.Unit,
  12381. CostClassify: item.CostClassify,
  12382. ExecutiveSection: item.ExecutiveSection,
  12383. MedicalCoverage: item.MedicalCoverage,
  12384. UserOrgId: orgId,
  12385. Status: 1,
  12386. CreatedTime: time.Now().Unix(),
  12387. Pinyin: item.Pinyin,
  12388. Wubi: item.Wubi,
  12389. StatisticalClassification: item.StatisticalClassification,
  12390. DiseaseDirectory: item.DiseaseDirectory,
  12391. IsRecord: item.IsRecord,
  12392. MedicalCode: item.MedicalCode,
  12393. TubeColor: item.TubeColor,
  12394. SingleDose: item.SingleDose,
  12395. DeliveryWay: item.DeliveryWay,
  12396. NumberDays: item.NumberDays,
  12397. Total: item.Total,
  12398. Category: item.Category,
  12399. MedicalStatus: item.MedicalStatus,
  12400. SpecailProject: item.SpecailProject,
  12401. RecordDate: item.RecordDate,
  12402. Remark: item.Remark,
  12403. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  12404. ExecutionFrequency: item.ExecutionFrequency,
  12405. FirstLetter: item.FirstLetter,
  12406. }
  12407. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  12408. if errcodeproject == gorm.ErrRecordNotFound {
  12409. service.CreateProjectInfomation(&project)
  12410. } else if errcodeproject == nil {
  12411. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  12412. }
  12413. log := models.ExportLog{
  12414. LogType: 6,
  12415. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12416. TotalNum: int64(len(total_goods)),
  12417. FailNum: int64(len(errLogs)),
  12418. SuccessNum: int64(len(projectList)),
  12419. CreateTime: time.Now().Unix(),
  12420. UpdateTime: time.Now().Unix(),
  12421. ExportTime: export_time,
  12422. Status: 1,
  12423. }
  12424. service.CreateExportLog(&log)
  12425. c.ServeSuccessJSON(map[string]interface{}{
  12426. "msg": "导入成功",
  12427. "total_num": len(total_goods),
  12428. "success_num": len(projectList),
  12429. "fail_num": int64(len(errLogs)),
  12430. })
  12431. }
  12432. } else {
  12433. log := models.ExportLog{
  12434. LogType: 6,
  12435. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12436. TotalNum: int64(len(total_goods)),
  12437. FailNum: int64(len(errLogs)),
  12438. SuccessNum: int64(len(projectList)),
  12439. CreateTime: time.Now().Unix(),
  12440. UpdateTime: time.Now().Unix(),
  12441. ExportTime: export_time,
  12442. Status: 1,
  12443. }
  12444. service.CreateExportLog(&log)
  12445. c.ServeSuccessJSON(map[string]interface{}{
  12446. "msg": "导入成功",
  12447. "total_num": len(total_goods),
  12448. "success_num": len(projectList),
  12449. "fail_num": int64(len(errLogs)),
  12450. })
  12451. }
  12452. }
  12453. //func (this *HisApiController) EditProjectInformation(){
  12454. //
  12455. // id, _ := this.GetInt64("id")
  12456. // project_team := this.GetString("project_team")
  12457. // price := this.GetString("price")
  12458. // price_float, _ := strconv.ParseFloat(price, 64)
  12459. // pinyin := this.GetString("pinyin")
  12460. // wubi := this.GetString("wubi")
  12461. // tube_color, _ := this.GetInt64("tube_color")
  12462. // team_type, _ := this.GetInt64("team_type")
  12463. // remark := this.GetString("remark")
  12464. // ids := this.GetString("ids")
  12465. // item_id := this.GetString("item_id")
  12466. // projectTeam := models.XtHisProjectTeam{
  12467. // ProjectTeam: project_team,
  12468. // Price: price_float,
  12469. // Pinyin: pinyin,
  12470. // Wubi: wubi,
  12471. // TubeColor: tube_color,
  12472. // TeamType: team_type,
  12473. // Remark: remark,
  12474. // ProjectId: ids,
  12475. // ItemId: item_id,
  12476. // }
  12477. //
  12478. //
  12479. // dataBody := make(map[string]interface{}, 0)
  12480. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12481. // if err != nil {
  12482. // utils.ErrorLog(err.Error())
  12483. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12484. // return
  12485. // }
  12486. //
  12487. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12488. //
  12489. //
  12490. // if err != nil {
  12491. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12492. // return
  12493. // }
  12494. //
  12495. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12496. // infos, _ := dataBody["info"].([]interface{})
  12497. // if len(infos) > 0 {
  12498. // var ids []string
  12499. //
  12500. // for _, item := range infos {
  12501. // items := item.(map[string]interface{})
  12502. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12503. // utils.ErrorLog("id")
  12504. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12505. // return
  12506. // }
  12507. // id := int64(items["id"].(float64))
  12508. //
  12509. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12510. // utils.ErrorLog("type")
  12511. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12512. // return
  12513. // }
  12514. // types := int64(items["type"].(float64))
  12515. //
  12516. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12517. // utils.ErrorLog("number")
  12518. // }
  12519. //
  12520. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12521. //
  12522. // projectList := models.XtHisProjectList{
  12523. // Number: number,
  12524. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12525. // ProjectId: id,
  12526. // Status: 1,
  12527. // CreatedTime: time.Now().Unix(),
  12528. // UpdatedTime: time.Now().Unix(),
  12529. // TeamId: projectTeam.ID,
  12530. // Type: types,
  12531. // }
  12532. // list := projectList
  12533. //
  12534. // service.CreateProjectList(&list)
  12535. //
  12536. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12537. //
  12538. // }
  12539. // ids_str := strings.Join(ids, ",")
  12540. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12541. // service.SaveProjectTeam(&projectTeam)
  12542. // this.ServeSuccessJSON(map[string]interface{}{
  12543. // "projectTeam": projectTeam,
  12544. // })
  12545. // }
  12546. // }
  12547. //}
  12548. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12549. name := c.GetString("name")
  12550. mode_id, _ := c.GetInt64("mode", 0)
  12551. types, _ := c.GetInt64("type", 0)
  12552. patient_id, _ := c.GetInt64("patient_id", 0)
  12553. types = 1
  12554. adminInfo := c.GetAdminUserInfo()
  12555. template := &models.HisPrescriptionTemplate{
  12556. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12557. PatientId: patient_id,
  12558. Type: types,
  12559. Status: 1,
  12560. Ctime: time.Now().Unix(),
  12561. Mtime: time.Now().Unix(),
  12562. Name: name,
  12563. Mode: mode_id,
  12564. }
  12565. dataBody := make(map[string]interface{}, 0)
  12566. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12567. if err != nil {
  12568. utils.ErrorLog(err.Error())
  12569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12570. return
  12571. }
  12572. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12573. //如果已经存在记录则删除处方
  12574. if template_one.ID > 0 {
  12575. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12576. var ids []int64
  12577. var org_id int64
  12578. for _, item := range ps {
  12579. org_id = c.GetAdminUserInfo().CurrentOrgId
  12580. ids = append(ids, item.ID)
  12581. }
  12582. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12583. if err2 == nil {
  12584. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12585. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12586. if len(prescriptions) > 0 {
  12587. for _, item := range prescriptions {
  12588. items := item.(map[string]interface{})
  12589. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12590. utils.ErrorLog("type")
  12591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12592. return
  12593. }
  12594. types := int64(items["type"].(float64))
  12595. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12596. utils.ErrorLog("med_type")
  12597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12598. return
  12599. }
  12600. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12601. ctime := time.Now().Unix()
  12602. prescription := &models.HisPrescriptionInfoTemplate{
  12603. PatientId: patient_id,
  12604. UserOrgId: adminInfo.CurrentOrgId,
  12605. Ctime: ctime,
  12606. Mtime: ctime,
  12607. Type: types,
  12608. Modifier: adminInfo.AdminUser.Id,
  12609. Creator: adminInfo.AdminUser.Id,
  12610. Status: 1,
  12611. PTemplateId: template_one.ID,
  12612. MedType: med_type,
  12613. }
  12614. service.CreateHisPrescriptionInfoTemplate(prescription)
  12615. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12616. advices := items["advices"].([]interface{})
  12617. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12618. ctime := time.Now().Unix()
  12619. mtime := ctime
  12620. if len(advices) > 0 {
  12621. for _, advice := range advices {
  12622. var s models.HisPrescriptionAdviceTemplate
  12623. s.PrescriptionId = prescription.ID
  12624. s.AdviceType = 2
  12625. s.StopState = 2
  12626. s.ExecutionState = 2
  12627. s.Status = 1
  12628. s.UserOrgId = adminInfo.CurrentOrgId
  12629. s.CreatedTime = ctime
  12630. s.UpdatedTime = mtime
  12631. s.PatientId = patient_id
  12632. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12633. if errcode > 0 {
  12634. c.ServeFailJSONWithSGJErrorCode(errcode)
  12635. return
  12636. }
  12637. service.CreateHisPrescriptionAdviceTemplate(&s)
  12638. }
  12639. }
  12640. }
  12641. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12642. projects := items["project"].([]interface{})
  12643. if len(projects) > 0 {
  12644. for _, project := range projects {
  12645. var p models.HisPrescriptionProjectTemplate
  12646. p.PrescriptionId = prescription.ID
  12647. p.Ctime = time.Now().Unix()
  12648. p.Mtime = time.Now().Unix()
  12649. p.PatientId = patient_id
  12650. p.UserOrgId = adminInfo.CurrentOrgId
  12651. p.Status = 1
  12652. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12653. if errcode > 0 {
  12654. c.ServeFailJSONWithSGJErrorCode(errcode)
  12655. return
  12656. }
  12657. service.CreateHisPrescriptionProjectTemplate(&p)
  12658. }
  12659. }
  12660. }
  12661. }
  12662. c.ServeSuccessJSON(map[string]interface{}{
  12663. "msg": "创建成功",
  12664. })
  12665. }
  12666. }
  12667. } else {
  12668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12669. return
  12670. }
  12671. } else {
  12672. err3 := service.CreateHisPrescriptionTemplate(template)
  12673. if err3 == nil {
  12674. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12675. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12676. if len(prescriptions) > 0 {
  12677. for _, item := range prescriptions {
  12678. items := item.(map[string]interface{})
  12679. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12680. utils.ErrorLog("type")
  12681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12682. return
  12683. }
  12684. types := int64(items["type"].(float64))
  12685. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12686. utils.ErrorLog("med_type")
  12687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12688. return
  12689. }
  12690. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12691. ctime := time.Now().Unix()
  12692. prescription := &models.HisPrescriptionInfoTemplate{
  12693. PatientId: patient_id,
  12694. UserOrgId: adminInfo.CurrentOrgId,
  12695. Ctime: ctime,
  12696. Mtime: ctime,
  12697. Type: types,
  12698. Modifier: adminInfo.AdminUser.Id,
  12699. Creator: adminInfo.AdminUser.Id,
  12700. Status: 1,
  12701. PTemplateId: template.ID,
  12702. MedType: med_type,
  12703. }
  12704. service.CreateHisPrescriptionInfoTemplate(prescription)
  12705. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12706. advices := items["advices"].([]interface{})
  12707. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12708. ctime := time.Now().Unix()
  12709. mtime := ctime
  12710. if len(advices) > 0 {
  12711. for _, advice := range advices {
  12712. var s models.HisPrescriptionAdviceTemplate
  12713. s.PrescriptionId = prescription.ID
  12714. s.AdviceType = 2
  12715. s.StopState = 2
  12716. s.ExecutionState = 2
  12717. s.Status = 1
  12718. s.UserOrgId = adminInfo.CurrentOrgId
  12719. s.CreatedTime = ctime
  12720. s.UpdatedTime = mtime
  12721. s.PatientId = patient_id
  12722. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12723. if errcode > 0 {
  12724. c.ServeFailJSONWithSGJErrorCode(errcode)
  12725. return
  12726. }
  12727. service.CreateHisPrescriptionAdviceTemplate(&s)
  12728. }
  12729. }
  12730. }
  12731. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12732. projects := items["project"].([]interface{})
  12733. if len(projects) > 0 {
  12734. for _, project := range projects {
  12735. var p models.HisPrescriptionProjectTemplate
  12736. p.PrescriptionId = prescription.ID
  12737. p.Ctime = time.Now().Unix()
  12738. p.Mtime = time.Now().Unix()
  12739. p.PatientId = patient_id
  12740. p.UserOrgId = adminInfo.CurrentOrgId
  12741. p.Status = 1
  12742. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12743. if errcode > 0 {
  12744. c.ServeFailJSONWithSGJErrorCode(errcode)
  12745. return
  12746. }
  12747. service.CreateHisPrescriptionProjectTemplate(&p)
  12748. }
  12749. }
  12750. }
  12751. }
  12752. c.ServeSuccessJSON(map[string]interface{}{
  12753. "msg": "创建成功",
  12754. })
  12755. }
  12756. }
  12757. } else {
  12758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12759. return
  12760. }
  12761. }
  12762. }
  12763. func (c *HisApiController) PreSettle() {
  12764. id, _ := c.GetInt64("id")
  12765. record_time := c.GetString("record_time")
  12766. his_patient_id, _ := c.GetInt64("his_patient_id")
  12767. timeLayout := "2006-01-02"
  12768. loc, _ := time.LoadLocation("Local")
  12769. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12770. diagnosis_id := c.GetString("diagnosis")
  12771. sick_type, _ := c.GetInt64("sick_type")
  12772. reg_type, _ := c.GetInt64("p_type")
  12773. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12774. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12775. if err != nil {
  12776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12777. return
  12778. }
  12779. recordDateTime := theTime.Unix()
  12780. adminUser := c.GetAdminUserInfo()
  12781. var prescriptions []*models.HisPrescription
  12782. var start_time int64
  12783. var end_time int64
  12784. ids_str := c.GetString("ids")
  12785. ids_arr := strings.Split(ids_str, ",")
  12786. fmt.Println(reg_type)
  12787. if settle_accounts_type == 1 { //日结
  12788. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12789. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12790. } else {
  12791. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12792. }
  12793. fmt.Println(prescriptions)
  12794. } else { //月结
  12795. start_time_str := c.GetString("start_time")
  12796. end_time_str := c.GetString("end_time")
  12797. timeLayout := "2006-01-02"
  12798. loc, _ := time.LoadLocation("Local")
  12799. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12800. if err != nil {
  12801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12802. return
  12803. }
  12804. recordStartTime := theStartTime.Unix()
  12805. start_time = recordStartTime
  12806. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12807. if err != nil {
  12808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12809. return
  12810. }
  12811. recordEndTime := theEndTime.Unix()
  12812. end_time = recordEndTime
  12813. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12814. }
  12815. if reg_type == 1111 || reg_type == 1112 {
  12816. reg_type = 11
  12817. }
  12818. timestamp := time.Now().Unix()
  12819. tempTime := time.Unix(timestamp, 0)
  12820. timeFormat := tempTime.Format("20060102150405")
  12821. chrgBchno := rand.Intn(100000) + 10000
  12822. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12823. strconv.FormatInt(his.PatientId, 10)
  12824. var ids []int64
  12825. for _, item := range prescriptions {
  12826. ids = append(ids, item.ID)
  12827. }
  12828. fmt.Println(ids)
  12829. var total float64
  12830. for _, item := range prescriptions {
  12831. fmt.Println(item)
  12832. if item.Type == 1 { //药品
  12833. for _, subItem := range item.HisDoctorAdviceInfo {
  12834. total = total + (subItem.Price * subItem.PrescribingNumber)
  12835. }
  12836. }
  12837. if item.Type == 2 { //项目
  12838. for _, subItem := range item.HisPrescriptionProject {
  12839. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12840. total = total + (subItem.Price * cnt)
  12841. }
  12842. }
  12843. for _, subItem := range item.HisAdditionalCharge {
  12844. total = total + (subItem.Price * float64(subItem.Count))
  12845. }
  12846. }
  12847. allTotal := fmt.Sprintf("%.2f", total)
  12848. totals, _ := strconv.ParseFloat(allTotal, 64)
  12849. order := &models.HisOrder{
  12850. UserOrgId: adminUser.CurrentOrgId,
  12851. HisPatientId: his.ID,
  12852. PatientId: id,
  12853. SettleAccountsDate: recordDateTime,
  12854. Ctime: time.Now().Unix(),
  12855. Mtime: time.Now().Unix(),
  12856. Status: 1,
  12857. OrderStatus: 1,
  12858. MdtrtId: his.Number,
  12859. Number: chrg_bchno,
  12860. MedfeeSumamt: totals,
  12861. SettleEndTime: end_time,
  12862. SettleStartTime: start_time,
  12863. SettleType: settle_accounts_type,
  12864. PsnPartAmt: totals,
  12865. PsnCashPay: totals,
  12866. PType: 2,
  12867. IsPre: 1,
  12868. MedType: strconv.Itoa(int(reg_type)),
  12869. Diagnosis: diagnosis_id,
  12870. }
  12871. err = service.CreateOrder(order)
  12872. if err != nil {
  12873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12874. return
  12875. }
  12876. var customs []*Custom
  12877. for _, item := range prescriptions {
  12878. fmt.Println(item.Type)
  12879. if item.Type == 1 { //药品
  12880. for _, subItem := range item.HisDoctorAdviceInfo {
  12881. cus := &Custom{
  12882. AdviceId: subItem.ID,
  12883. ProjectId: 0,
  12884. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12885. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12886. FeedetlSn: subItem.FeedetlSn,
  12887. Price: fmt.Sprintf("%.2f", subItem.Price),
  12888. MedListCodg: subItem.MedListCodg,
  12889. Type: 1,
  12890. }
  12891. customs = append(customs, cus)
  12892. }
  12893. }
  12894. if item.Type == 2 { //项目
  12895. for _, subItem := range item.HisPrescriptionProject {
  12896. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12897. cus := &Custom{
  12898. AdviceId: 0,
  12899. ProjectId: subItem.ID,
  12900. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12901. Cut: fmt.Sprintf("%.2f", cnt),
  12902. FeedetlSn: subItem.FeedetlSn,
  12903. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12904. MedListCodg: subItem.MedListCodg,
  12905. Type: 2,
  12906. }
  12907. customs = append(customs, cus)
  12908. }
  12909. }
  12910. for _, item := range item.HisAdditionalCharge {
  12911. cus := &Custom{
  12912. ItemId: item.ID,
  12913. AdviceId: 0,
  12914. ProjectId: 0,
  12915. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12916. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12917. FeedetlSn: item.FeedetlSn,
  12918. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12919. MedListCodg: item.XtHisAddtionConfig.Code,
  12920. Type: 3,
  12921. }
  12922. customs = append(customs, cus)
  12923. }
  12924. }
  12925. fmt.Println(customs)
  12926. for _, item := range customs {
  12927. var advice_id int64 = 0
  12928. var project_id int64 = 0
  12929. var item_id int64 = 0
  12930. var types int64 = 0
  12931. if item.Type == 1 {
  12932. advice_id = item.AdviceId
  12933. project_id = 0
  12934. item_id = 0
  12935. } else if item.Type == 2 {
  12936. advice_id = 0
  12937. item_id = 0
  12938. project_id = item.ProjectId
  12939. } else if item.Type == 3 {
  12940. advice_id = 0
  12941. item_id = item.ItemId
  12942. project_id = 0
  12943. }
  12944. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12945. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12946. pric, _ := strconv.ParseFloat(item.Price, 32)
  12947. info := &models.HisOrderInfo{
  12948. OrderNumber: order.Number,
  12949. UploadDate: time.Now().Unix(),
  12950. AdviceId: advice_id,
  12951. DetItemFeeSumamt: detItemFeeSumamt,
  12952. Cnt: cut,
  12953. Pric: pric,
  12954. PatientId: id,
  12955. Status: 1,
  12956. Mtime: time.Now().Unix(),
  12957. Ctime: time.Now().Unix(),
  12958. UserOrgId: adminUser.CurrentOrgId,
  12959. HisPatientId: his.ID,
  12960. OrderId: order.ID,
  12961. ProjectId: project_id,
  12962. Type: types,
  12963. ItemId: item_id,
  12964. }
  12965. service.CreateOrderInfo(info)
  12966. }
  12967. his.SickType = sick_type
  12968. service.UpdataHisPateint(&his)
  12969. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12970. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12971. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12972. if err == nil {
  12973. c.ServeSuccessJSON(map[string]interface{}{
  12974. "msg": "结算成功",
  12975. })
  12976. }
  12977. }
  12978. type CustomOrderInfo struct {
  12979. Name string
  12980. Spec string
  12981. Unit string
  12982. Count float64
  12983. Price float64
  12984. Total float64
  12985. }
  12986. func (c *HisApiController) GetPrivateExpensesInfo() {
  12987. order_id, _ := c.GetInt64("id", 0)
  12988. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12989. order, _ := service.GetHisOrderByID(order_id)
  12990. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12991. if order.ID == 0 {
  12992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12993. return
  12994. }
  12995. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12996. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12997. org_id := c.GetAdminUserInfo().CurrentOrgId
  12998. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12999. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  13000. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  13001. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  13002. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  13003. //var orderInfos_four []*models.HisOrderInfoTwo
  13004. //for _, item := range orderInfos_three {
  13005. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  13006. // item.HisPrescriptionProject.IsCheckTeam = 1
  13007. // orderInfos_four = append(orderInfos_four, item)
  13008. //
  13009. // }
  13010. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  13011. // item.HisPrescriptionProject.IsCheckTeam = 2
  13012. // orderInfos_two = append(orderInfos_two, item)
  13013. // }
  13014. //}
  13015. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  13016. //var cus_slice []CustomOrderInfo
  13017. //for _, item := range new_order_info {
  13018. // var cus CustomOrderInfo
  13019. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  13020. // cus.Unit = ""
  13021. // cus.Spec = ""
  13022. // var total float64
  13023. // for _, subItem := range orderInfos_four {
  13024. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  13025. // total = total + subItem.DetItemFeeSumamt
  13026. // fmt.Println(subItem.DetItemFeeSumamt)
  13027. // }
  13028. // }
  13029. // cus.Count = 1
  13030. // cus.Total = total
  13031. // cus_slice = append(cus_slice, cus)
  13032. //}
  13033. orderInfos = append(orderInfos, orderInfos_two...)
  13034. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  13035. //orderInfos = append(orderInfos, orderInfos_three...)
  13036. //}/**/
  13037. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  13038. c.ServeSuccessJSON(map[string]interface{}{
  13039. "order": order,
  13040. "order_info": orderInfos,
  13041. "patient": patient,
  13042. "admin_info": adminInfo,
  13043. "his": his,
  13044. "current_admin": role,
  13045. "org_config": miConfig,
  13046. //"new_order_info": cus_slice,
  13047. })
  13048. }
  13049. func (this *HisApiController) ChangeMedType() {
  13050. med_type := this.GetString("med_type")
  13051. old_med_type := this.GetString("old_med_type")
  13052. ids := this.GetString("ids")
  13053. settle_type, _ := this.GetInt64("settle_type")
  13054. start_time := this.GetString("start_time")
  13055. end_time := this.GetString("end_time")
  13056. ids_arr := strings.Split(ids, ",")
  13057. if settle_type == 1 { //日结
  13058. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  13059. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  13060. prescription.MedType = med_type
  13061. err := service.SaveHisPrescriptionTwo(&prescription)
  13062. if err == nil {
  13063. this.ServeSuccessJSON(map[string]interface{}{
  13064. "msg": "修改成功",
  13065. })
  13066. } else {
  13067. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  13068. return
  13069. }
  13070. } else if settle_type == 2 {
  13071. timeLayout := "2006-01-02"
  13072. loc, _ := time.LoadLocation("Local")
  13073. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13074. if err != nil {
  13075. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13076. return
  13077. }
  13078. recordStartTime := theStartTime.Unix()
  13079. start_time_timestamp := recordStartTime
  13080. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  13081. if err != nil {
  13082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13083. return
  13084. }
  13085. recordEndTime := theEndTime.Unix()
  13086. end_time_timestamp := recordEndTime
  13087. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  13088. if updateErr == nil {
  13089. this.ServeSuccessJSON(map[string]interface{}{
  13090. "msg": "修改成功",
  13091. })
  13092. } else {
  13093. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  13094. return
  13095. }
  13096. }
  13097. }
  13098. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  13099. patient_id, _ := c.GetInt64("patient_id")
  13100. his_patient_id, _ := c.GetInt64("his_patient_id")
  13101. record_date := c.GetString("record_date")
  13102. start_time := c.GetString("start_time")
  13103. end_time := c.GetString("end_time")
  13104. order_status, _ := c.GetInt64("type", 0)
  13105. p_type, _ := c.GetInt64("p_type", 0)
  13106. order_id, _ := c.GetInt64("order_id", 0)
  13107. timeLayout := "2006-01-02"
  13108. loc, _ := time.LoadLocation("Local")
  13109. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13110. if err != nil {
  13111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13112. return
  13113. }
  13114. recordDateTime := theTime.Unix()
  13115. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13116. if err != nil {
  13117. }
  13118. startRecordDateTime := startTime.Unix()
  13119. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13120. if err != nil {
  13121. }
  13122. endRecordDateTime := endTime.Unix()
  13123. admin := c.GetAdminUserInfo()
  13124. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  13125. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13126. order, _ := service.GetHisOrderByID(order_id)
  13127. var monthPrescriptions []*models.HisPrescription
  13128. if order_status == 1 || order_status == 0 {
  13129. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13130. } else if order_status == 2 {
  13131. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  13132. }
  13133. var settle_total float64
  13134. for _, item := range monthPrescriptions {
  13135. if len(item.HisPrescriptionProject) > 0 {
  13136. for _, subItem := range item.HisPrescriptionProject {
  13137. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13138. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13139. settle_total = settle_total + total
  13140. }
  13141. }
  13142. if len(item.HisDoctorAdviceInfo) > 0 {
  13143. for _, subItem := range item.HisDoctorAdviceInfo {
  13144. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13145. settle_total = settle_total + total
  13146. }
  13147. }
  13148. }
  13149. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13150. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13151. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13152. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13153. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13154. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13155. //获取所有科室信息
  13156. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13157. var dia string
  13158. for _, item := range month_p_info {
  13159. if len(dia) == 0 {
  13160. dia = item.Diagnosis
  13161. } else {
  13162. dia = dia + "," + item.Diagnosis
  13163. }
  13164. }
  13165. dia_arr := removeDuplicates(strings.Split(dia, ","))
  13166. dia_arr = removeEmptyStrings(dia_arr)
  13167. c.ServeSuccessJSON(map[string]interface{}{
  13168. "his_info": his_patient_info,
  13169. "xt_info": xt_patient_info,
  13170. "case_history": case_history,
  13171. "info": patientPrescriptionInfo,
  13172. "last_info": lastPatientPrescriptionInfo,
  13173. "month_prescriptions": monthPrescriptions,
  13174. "order": order,
  13175. "doctors": doctors,
  13176. "department": department,
  13177. "settle_total": settle_total,
  13178. "dia_arr": dia_arr,
  13179. })
  13180. return
  13181. }
  13182. func removeEmptyStrings(input []string) []string {
  13183. var output []string
  13184. for _, s := range input {
  13185. if s != "" {
  13186. output = append(output, s)
  13187. }
  13188. }
  13189. return output
  13190. }
  13191. func removeDuplicates(input []string) []string {
  13192. seen := make(map[string]bool)
  13193. output := []string{}
  13194. for _, s := range input {
  13195. if _, exists := seen[s]; !exists {
  13196. seen[s] = true
  13197. output = append(output, s)
  13198. }
  13199. }
  13200. return output
  13201. }
  13202. func (c *HisApiController) GetHisMonthPatientInfo() {
  13203. patient_id, _ := c.GetInt64("patient_id")
  13204. his_patient_id, _ := c.GetInt64("his_patient_id")
  13205. record_date := c.GetString("record_date")
  13206. number := c.GetString("number")
  13207. start_time := c.GetString("start_time")
  13208. end_time := c.GetString("end_time")
  13209. p_type, _ := c.GetInt64("p_type")
  13210. timeLayout := "2006-01-02"
  13211. loc, _ := time.LoadLocation("Local")
  13212. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13213. if err != nil {
  13214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13215. return
  13216. }
  13217. recordDateTime := theTime.Unix()
  13218. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13219. if err != nil {
  13220. }
  13221. startRecordDateTime := startTime.Unix()
  13222. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13223. if err != nil {
  13224. }
  13225. endRecordDateTime := endTime.Unix()
  13226. admin := c.GetAdminUserInfo()
  13227. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  13228. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13229. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  13230. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13231. var settle_total float64
  13232. for _, item := range monthPrescriptions {
  13233. if len(item.HisPrescriptionProject) > 0 {
  13234. for _, subItem := range item.HisPrescriptionProject {
  13235. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13236. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13237. settle_total = settle_total + total
  13238. }
  13239. }
  13240. if len(item.HisDoctorAdviceInfo) > 0 {
  13241. for _, subItem := range item.HisDoctorAdviceInfo {
  13242. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13243. settle_total = settle_total + total
  13244. }
  13245. }
  13246. }
  13247. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13248. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13249. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13250. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13251. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  13252. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13253. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  13254. //获取所有科室信息
  13255. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13256. c.ServeSuccessJSON(map[string]interface{}{
  13257. "his_info": his_patient_info,
  13258. "xt_info": xt_patient_info,
  13259. "case_history": case_history,
  13260. "info": patientPrescriptionInfo,
  13261. "month_prescriptions": monthPrescriptions,
  13262. "order": order,
  13263. "doctors": doctors,
  13264. "department": department,
  13265. "count": count,
  13266. "drugStockConfig": drugStockConfig,
  13267. "last_info": lastPatientPrescriptionInfo,
  13268. "settle_total": settle_total,
  13269. })
  13270. return
  13271. }
  13272. func (c *HisApiController) GetAllOrder() {
  13273. org_id := c.GetAdminUserInfo().CurrentOrgId
  13274. orders, _ := service.GetNewHisOrderList(org_id)
  13275. c.ServeSuccessJSON(map[string]interface{}{
  13276. "order": orders,
  13277. })
  13278. return
  13279. }
  13280. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  13281. newArr = make([]*models.HisOrderInfoTwo, 0)
  13282. for i := 0; i < len(arr); i++ {
  13283. repeat := false
  13284. for j := i + 1; j < len(arr); j++ {
  13285. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  13286. repeat = true
  13287. break
  13288. }
  13289. }
  13290. if !repeat {
  13291. newArr = append(newArr, arr[i])
  13292. }
  13293. }
  13294. return
  13295. }
  13296. // 修改处方退库操作 参数传修改之前的处方数据
  13297. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  13298. if advice.ExecutionState == 1 {
  13299. //查询该病人该药品是否有库存记录
  13300. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  13301. if errcode == gorm.ErrRecordNotFound {
  13302. } else {
  13303. //退库
  13304. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  13305. if advice.PrescribingNumberUnit == drug.MinUnit {
  13306. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13307. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13308. //退库
  13309. warehouseInfo := models.DrugWarehouseInfo{
  13310. StockMinNumber: prescribingNumber,
  13311. }
  13312. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  13313. operation_time := time.Now().Unix()
  13314. creater := advice.AdviceDoctor
  13315. ctime := time.Now().Unix()
  13316. timeStr := time.Now().Format("2006-01-02")
  13317. timeArr := strings.Split(timeStr, "-")
  13318. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13319. total = total + 1
  13320. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13321. cancelStock := models.DrugCancelStock{
  13322. OrderNumber: orderNumber,
  13323. OperaTime: operation_time,
  13324. OrgId: advice.UserOrgId,
  13325. Creater: creater,
  13326. Ctime: ctime,
  13327. Status: 1,
  13328. ReturnTime: advice.AdviceDate,
  13329. Dealer: info.Dealer,
  13330. Manufacturer: info.Manufacturer,
  13331. Type: 1,
  13332. }
  13333. service.AddSigleDrugCancelStock(&cancelStock)
  13334. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13335. dealer, _ := service.GetDealerById(info.Dealer)
  13336. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13337. cancelStockInfo := models.DrugCancelStockInfo{
  13338. OrderNumber: cancelInfo.OrderNumber,
  13339. CancelStockId: cancelInfo.ID,
  13340. DrugId: info.DrugId,
  13341. Count: info.Count,
  13342. Status: 1,
  13343. Ctime: ctime,
  13344. OrgId: advice.UserOrgId,
  13345. Type: 1,
  13346. Manufacturer: manufactureName.ManufacturerName,
  13347. Dealer: dealer.DealerName,
  13348. Total: 0,
  13349. RetailPrice: info.RetailPrice,
  13350. RetailTotalPrice: info.RetailTotalPrice,
  13351. Price: info.Price,
  13352. RegisterAccount: "",
  13353. Remark: info.Remark,
  13354. BatchNumber: info.BatchNumber,
  13355. MaxUnit: info.CountUnit,
  13356. ProductDate: info.ProductDate,
  13357. ExpiryDate: info.ExpiryDate,
  13358. BatchNumberId: info.WarehouseInfoId,
  13359. }
  13360. flow := models.DrugFlow{
  13361. WarehousingId: 0,
  13362. DrugId: info.DrugId,
  13363. Number: "",
  13364. BatchNumber: info.BatchNumber,
  13365. Count: info.Count,
  13366. UserOrgId: advice.UserOrgId,
  13367. PatientId: 0,
  13368. SystemTime: ctime,
  13369. ConsumableType: 4,
  13370. IsSys: 0,
  13371. WarehousingOrder: "",
  13372. WarehouseOutId: 0,
  13373. WarehouseOutOrderNumber: "",
  13374. IsEdit: 0,
  13375. CancelStockId: cancelStock.ID,
  13376. CancelOrderNumber: cancelStock.OrderNumber,
  13377. Manufacturer: info.Manufacturer,
  13378. Dealer: info.Dealer,
  13379. Creator: advice.UserOrgId,
  13380. UpdateCreator: 0,
  13381. Status: 1,
  13382. Ctime: time.Now().Unix(),
  13383. Mtime: 0,
  13384. Price: info.Price,
  13385. WarehousingDetailId: 0,
  13386. WarehouseOutDetailId: 0,
  13387. CancelOutDetailId: 0,
  13388. ExpireDate: info.ExpiryDate,
  13389. ProductDate: info.ProductDate,
  13390. MaxUnit: info.CountUnit,
  13391. MinUnit: "",
  13392. }
  13393. service.CreatedCancelStock(cancelStockInfo)
  13394. service.CreateDrugFlowOne(flow)
  13395. } else {
  13396. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13397. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13398. if advice.PrescribingNumberUnit == drug.MaxUnit {
  13399. warehouseInfo := models.DrugWarehouseInfo{
  13400. StockMinNumber: prescribingNumber,
  13401. }
  13402. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  13403. }
  13404. operation_time := time.Now().Unix()
  13405. creater := advice.AdviceDoctor
  13406. ctime := time.Now().Unix()
  13407. timeStr := time.Now().Format("2006-01-02")
  13408. timeArr := strings.Split(timeStr, "-")
  13409. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13410. total = total + 1
  13411. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13412. cancelStock := models.DrugCancelStock{
  13413. OrderNumber: orderNumber,
  13414. OperaTime: operation_time,
  13415. OrgId: advice.UserOrgId,
  13416. Creater: creater,
  13417. Ctime: ctime,
  13418. Status: 1,
  13419. ReturnTime: advice.AdviceDate,
  13420. Dealer: info.Dealer,
  13421. Manufacturer: info.Manufacturer,
  13422. Type: 1,
  13423. }
  13424. service.AddSigleDrugCancelStock(&cancelStock)
  13425. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13426. dealer, _ := service.GetDealerById(info.Dealer)
  13427. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13428. cancelStockInfo := models.DrugCancelStockInfo{
  13429. OrderNumber: cancelInfo.OrderNumber,
  13430. CancelStockId: cancelInfo.ID,
  13431. DrugId: info.DrugId,
  13432. Count: info.Count,
  13433. Status: 1,
  13434. Ctime: ctime,
  13435. OrgId: advice.UserOrgId,
  13436. Type: 1,
  13437. Manufacturer: manufactureName.ManufacturerName,
  13438. Dealer: dealer.DealerName,
  13439. Total: 0,
  13440. RetailPrice: info.RetailPrice,
  13441. RetailTotalPrice: info.RetailTotalPrice,
  13442. Price: info.Price,
  13443. RegisterAccount: "",
  13444. Remark: info.Remark,
  13445. BatchNumber: info.BatchNumber,
  13446. MaxUnit: info.CountUnit,
  13447. ProductDate: info.ProductDate,
  13448. ExpiryDate: info.ExpiryDate,
  13449. BatchNumberId: info.WarehouseInfoId,
  13450. }
  13451. flow := models.DrugFlow{
  13452. WarehousingId: 0,
  13453. DrugId: info.DrugId,
  13454. Number: "",
  13455. BatchNumber: info.BatchNumber,
  13456. Count: info.Count,
  13457. UserOrgId: advice.UserOrgId,
  13458. PatientId: 0,
  13459. SystemTime: ctime,
  13460. ConsumableType: 4,
  13461. IsSys: 0,
  13462. WarehousingOrder: "",
  13463. WarehouseOutId: 0,
  13464. WarehouseOutOrderNumber: "",
  13465. IsEdit: 0,
  13466. CancelStockId: cancelStock.ID,
  13467. CancelOrderNumber: cancelStock.OrderNumber,
  13468. Manufacturer: info.Manufacturer,
  13469. Dealer: info.Dealer,
  13470. Creator: advice.AdviceDoctor,
  13471. UpdateCreator: 0,
  13472. Status: 1,
  13473. Ctime: time.Now().Unix(),
  13474. Mtime: 0,
  13475. Price: info.Price,
  13476. WarehousingDetailId: 0,
  13477. WarehouseOutDetailId: 0,
  13478. CancelOutDetailId: 0,
  13479. ExpireDate: info.ExpiryDate,
  13480. ProductDate: info.ProductDate,
  13481. MaxUnit: info.CountUnit,
  13482. MinUnit: "",
  13483. }
  13484. service.CreatedCancelStock(cancelStockInfo)
  13485. service.CreateDrugFlowOne(flow)
  13486. }
  13487. }
  13488. }
  13489. return err
  13490. }
  13491. func (this *HisApiController) DeleteNCDS() {
  13492. id, _ := this.GetInt64("id", 0)
  13493. if id > 0 {
  13494. service.DeletePsnNCDSRecordById(id)
  13495. this.ServeSuccessJSON(map[string]interface{}{
  13496. "msg": "删除成功",
  13497. })
  13498. } else {
  13499. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13500. return
  13501. }
  13502. }
  13503. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13504. id, _ := c.GetInt64("id")
  13505. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13506. c.ServeSuccessJSON(map[string]interface{}{
  13507. "advice": advice,
  13508. })
  13509. return
  13510. }
  13511. func (c *HisApiController) GetHisMonthChargePatientList() {
  13512. record_date := c.GetString("record_date")
  13513. start_time := c.GetString("start_time")
  13514. end_time := c.GetString("end_time")
  13515. timeLayout := "2006-01-02"
  13516. loc, _ := time.LoadLocation("Local")
  13517. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13518. if err != nil {
  13519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13520. return
  13521. }
  13522. if err != nil {
  13523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13524. return
  13525. }
  13526. recordDateTime := theTime.Unix()
  13527. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13528. if err != nil {
  13529. }
  13530. startRecordDateTime := startTime.Unix()
  13531. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13532. if err != nil {
  13533. }
  13534. endRecordDateTime := endTime.Unix()
  13535. adminInfo := c.GetAdminUserInfo()
  13536. var tempMonthChargePatients []*service.MonthChargePatients
  13537. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13538. for _, item := range tempPatients {
  13539. //过滤没有处方的
  13540. if len(item.HisPrescription) == 0 {
  13541. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13542. }
  13543. }
  13544. c.ServeSuccessJSON(map[string]interface{}{
  13545. "list": tempMonthChargePatients,
  13546. })
  13547. }
  13548. // PrescriptionDifference 医嘱数量差值结构体
  13549. type PrescriptionDrugDifference struct {
  13550. DrugID int64 //基础库药品id
  13551. ID int64 //医嘱id
  13552. Difference float64 //差值
  13553. Unit string //单位
  13554. }
  13555. type PrescriptionGoodDifference struct {
  13556. GoodID int64 //基础库项目耗材id
  13557. ID int64 //医嘱id
  13558. Difference int64 //差值
  13559. Unit string //单位
  13560. Type int64 //类型
  13561. }
  13562. type EditCustomData struct {
  13563. adviceList []*models.HisDoctorAdviceInfo
  13564. projectList []*models.HisPrescriptionProject
  13565. }
  13566. type SrcCustomData struct {
  13567. adviceList []*models.HisDoctorAdviceInfo
  13568. projectList []*models.HisPrescriptionProject
  13569. }
  13570. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13571. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13572. differences := make([]*PrescriptionDrugDifference, 0)
  13573. // 创建一个 map 来存储第一个切片中的药品信息
  13574. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13575. for _, advice := range firstPrescription {
  13576. firstMap[advice.DrugId] = advice
  13577. }
  13578. // 遍历第二个切片中的药品信息,并比较数量差值
  13579. for _, advice := range secondPrescription {
  13580. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13581. diff := &PrescriptionDrugDifference{
  13582. DrugID: advice.DrugId,
  13583. ID: firstAdvice.ID,
  13584. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13585. Unit: firstAdvice.PrescribingNumberUnit,
  13586. }
  13587. differences = append(differences, diff)
  13588. }
  13589. }
  13590. return differences
  13591. }
  13592. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13593. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13594. differences := make([]*PrescriptionGoodDifference, 0)
  13595. // 创建一个 map 来存储第一个切片中的耗材信息
  13596. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13597. for _, good := range firstPrescription {
  13598. firstMap[good.ProjectId] = good
  13599. }
  13600. // 遍历第二个切片中的耗材信息,并比较数量差值
  13601. for _, good := range secondPrescription {
  13602. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13603. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13604. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13605. diff := &PrescriptionGoodDifference{
  13606. GoodID: good.ProjectId,
  13607. ID: firstGood.ID,
  13608. Difference: count - firstCount,
  13609. Unit: firstGood.Unit,
  13610. Type: firstGood.Type,
  13611. }
  13612. differences = append(differences, diff)
  13613. }
  13614. }
  13615. return differences
  13616. }
  13617. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13618. var adviceList []*models.HisDoctorAdviceInfo
  13619. var projectList []*models.HisPrescriptionProject
  13620. var advice_ids []int64
  13621. var project_ids []int64
  13622. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13623. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13624. //var tempPrescription *models.HisPrescriptionProjectscription
  13625. if len(prescriptions) > 0 {
  13626. for _, item := range prescriptions {
  13627. items := item.(map[string]interface{})
  13628. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13629. advices := items["advices"].([]interface{})
  13630. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13631. groupNo := int64(0)
  13632. ctime := time.Now().Unix()
  13633. mtime := ctime
  13634. if len(advices) > 0 {
  13635. for _, advice := range advices {
  13636. var s models.HisDoctorAdviceInfo
  13637. s.AdviceType = 2
  13638. s.StopState = 2
  13639. s.ExecutionState = 2
  13640. s.Status = 1
  13641. s.Groupno = groupNo
  13642. s.CreatedTime = ctime
  13643. s.UpdatedTime = mtime
  13644. s.IsSettle = 2
  13645. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13646. //存储切片中
  13647. if s.ID > 0 {
  13648. advice_ids = append(advice_ids, s.ID)
  13649. adviceList = append(adviceList, &s)
  13650. }
  13651. }
  13652. }
  13653. }
  13654. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13655. projects := items["project"].([]interface{})
  13656. if len(projects) > 0 {
  13657. for _, project := range projects {
  13658. var p models.HisPrescriptionProject
  13659. p.Ctime = time.Now().Unix()
  13660. p.Mtime = time.Now().Unix()
  13661. p.Status = 1
  13662. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13663. if p.ID > 0 {
  13664. project_ids = append(project_ids, p.ID)
  13665. projectList = append(projectList, &p)
  13666. }
  13667. }
  13668. }
  13669. }
  13670. }
  13671. }
  13672. }
  13673. editCustomData.projectList = projectList
  13674. editCustomData.adviceList = adviceList
  13675. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13676. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13677. srcCustomData.adviceList = list
  13678. srcCustomData.projectList = list2
  13679. return
  13680. }
  13681. func (c *HisApiController) GetAllGoodInforList() {
  13682. orgId := c.GetAdminUserInfo().CurrentOrgId
  13683. goodList, _ := service.GetAllGoodList(orgId)
  13684. c.ServeSuccessJSON(map[string]interface{}{
  13685. "goodList": goodList,
  13686. })
  13687. return
  13688. }
  13689. func (this *HisApiController) SaveGoodList() {
  13690. project_name := this.GetString("project_name")
  13691. sort, _ := this.GetInt64("sort")
  13692. orgId := this.GetAdminUserInfo().CurrentOrgId
  13693. dataBody := make(map[string]interface{}, 0)
  13694. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13695. if err != nil {
  13696. utils.ErrorLog(err.Error())
  13697. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13698. return
  13699. }
  13700. goodTeam := models.XtGoodTeam{
  13701. ProjectName: project_name,
  13702. Sort: sort,
  13703. UserOrgId: orgId,
  13704. Status: 1,
  13705. Ctime: time.Now().Unix(),
  13706. Mtime: time.Now().Unix(),
  13707. }
  13708. service.CreateGoodTeam(goodTeam)
  13709. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13710. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13711. infos, _ := dataBody["info"].([]interface{})
  13712. if len(infos) > 0 {
  13713. for _, item := range infos {
  13714. items := item.(map[string]interface{})
  13715. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13716. utils.ErrorLog("good_id")
  13717. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13718. return
  13719. }
  13720. good_id := int64(items["good_id"].(float64))
  13721. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13722. utils.ErrorLog("number")
  13723. }
  13724. number := int64(items["number"].(float64))
  13725. xtGoodTeamList := models.XtGoodTeamList{
  13726. GoodId: good_id,
  13727. Count: number,
  13728. TeamId: lastGoodTeam.ID,
  13729. UserOrgId: orgId,
  13730. Status: 1,
  13731. Ctime: time.Now().Unix(),
  13732. Mtime: time.Now().Unix(),
  13733. }
  13734. service.CreateGoodList(xtGoodTeamList)
  13735. }
  13736. this.ServeSuccessJSON(map[string]interface{}{
  13737. "lastGoodTeam": lastGoodTeam,
  13738. })
  13739. }
  13740. }
  13741. return
  13742. }
  13743. func (this *HisApiController) GetGoodList() {
  13744. orgId := this.GetAdminUserInfo().CurrentOrgId
  13745. limit, _ := this.GetInt64("limit")
  13746. page, _ := this.GetInt64("page")
  13747. keyword := this.GetString("keyword")
  13748. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13749. this.ServeSuccessJSON(map[string]interface{}{
  13750. "list": list,
  13751. "total": total,
  13752. })
  13753. }
  13754. func (this *HisApiController) GetGoodNameDetail() {
  13755. id, _ := this.GetInt64("id")
  13756. orgId := this.GetAdminUserInfo().CurrentOrgId
  13757. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13758. goodList, _ := service.GetAllGoodList(orgId)
  13759. this.ServeSuccessJSON(map[string]interface{}{
  13760. "goodNameDetail": goodNameDetail,
  13761. "goodList": goodList,
  13762. })
  13763. }
  13764. func (this *HisApiController) UpdateGoodList() {
  13765. project_name := this.GetString("project_name")
  13766. sort, _ := this.GetInt64("sort")
  13767. id, _ := this.GetInt64("id")
  13768. orgId := this.GetAdminUserInfo().CurrentOrgId
  13769. dataBody := make(map[string]interface{}, 0)
  13770. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13771. if err != nil {
  13772. utils.ErrorLog(err.Error())
  13773. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13774. return
  13775. }
  13776. goodTeam := models.XtGoodTeam{
  13777. ProjectName: project_name,
  13778. Sort: sort,
  13779. UserOrgId: orgId,
  13780. Status: 1,
  13781. Ctime: time.Now().Unix(),
  13782. Mtime: time.Now().Unix(),
  13783. ID: id,
  13784. }
  13785. service.SaveGoodTeam(goodTeam)
  13786. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13787. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13788. infos, _ := dataBody["info"].([]interface{})
  13789. if len(infos) > 0 {
  13790. for _, item := range infos {
  13791. items := item.(map[string]interface{})
  13792. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13793. utils.ErrorLog("good_id")
  13794. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13795. return
  13796. }
  13797. good_id := int64(items["good_id"].(float64))
  13798. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13799. utils.ErrorLog("id")
  13800. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13801. return
  13802. }
  13803. id := int64(items["id"].(float64))
  13804. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13805. utils.ErrorLog("number")
  13806. }
  13807. number := int64(items["number"].(float64))
  13808. xtGoodTeamList := models.XtGoodTeamList{
  13809. ID: id,
  13810. GoodId: good_id,
  13811. Count: number,
  13812. TeamId: lastGoodTeam.ID,
  13813. UserOrgId: orgId,
  13814. Status: 1,
  13815. Ctime: time.Now().Unix(),
  13816. Mtime: time.Now().Unix(),
  13817. }
  13818. service.SaveGoodList(xtGoodTeamList)
  13819. }
  13820. this.ServeSuccessJSON(map[string]interface{}{
  13821. "lastGoodTeam": lastGoodTeam,
  13822. })
  13823. }
  13824. }
  13825. return
  13826. }
  13827. func (this *HisApiController) DeleteGoodTeam() {
  13828. id, _ := this.GetInt64("id")
  13829. team, _ := service.DeleteGoodTeam(id)
  13830. this.ServeSuccessJSON(map[string]interface{}{
  13831. "team": team,
  13832. })
  13833. }
  13834. func (this *HisApiController) DeleteGood() {
  13835. id, _ := this.GetInt64("id")
  13836. good, _ := service.DeleteGood(id)
  13837. this.ServeSuccessJSON(map[string]interface{}{
  13838. "good": good,
  13839. })
  13840. }