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("/test/net", &HisApiController{}, "get:TestNet")
  26. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  27. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  28. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  29. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  30. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  31. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  32. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  33. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  34. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  35. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  36. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  37. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  38. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  41. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  42. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  43. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  44. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  45. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  46. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  47. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  48. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  49. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  51. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  52. //新增附加费用
  53. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  54. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  55. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  56. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  57. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  58. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  59. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  60. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  61. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  62. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  63. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  64. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  65. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  66. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  67. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  68. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  83. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  84. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  85. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  86. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  87. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  88. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  89. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  90. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  91. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  92. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  93. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  94. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  95. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  96. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  97. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  98. }
  99. func (c *HisApiController) TestNet() {
  100. c.ServeSuccessJSON(map[string]interface{}{
  101. "msg": "成功",
  102. })
  103. }
  104. func (c *HisApiController) CheckHisPatient() {
  105. record_date := c.GetString("record_date")
  106. patient_id, _ := c.GetInt64("patient_id")
  107. timeLayout := "2006-01-02"
  108. loc, _ := time.LoadLocation("Local")
  109. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  110. if err != nil {
  111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  112. return
  113. }
  114. recordDateTime := theTime.Unix()
  115. adminInfo := c.GetAdminUserInfo()
  116. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  117. if len(patients) > 1 {
  118. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  119. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  120. c.ServeSuccessJSON(map[string]interface{}{
  121. "status": 1,
  122. "msg": "关联",
  123. "ps": ps,
  124. "his_patient_id": patients[len(patients)-1].ID,
  125. "patient_id": patients[len(patients)-1].PatientId,
  126. })
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. }
  133. } else {
  134. c.ServeSuccessJSON(map[string]interface{}{
  135. "status": 0,
  136. "msg": "无需关联",
  137. })
  138. return
  139. }
  140. }
  141. func (c *HisApiController) AssociationHisPrescription() {
  142. record_date := c.GetString("record_date")
  143. his_patient_id, _ := c.GetInt64("his_patient_id")
  144. patient_id, _ := c.GetInt64("patient_id")
  145. p_ids := c.GetString("p_ids")
  146. p_ids_arr := strings.Split(p_ids, ",")
  147. timeLayout := "2006-01-02"
  148. loc, _ := time.LoadLocation("Local")
  149. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  150. if err != nil {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. recordDateTime := theTime.Unix()
  155. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  156. if his_patient_id == 0 || his_patient.ID == 0 {
  157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  158. return
  159. }
  160. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  161. if err == nil {
  162. c.ServeSuccessJSON(map[string]interface{}{
  163. "msg": "关联处方成功",
  164. })
  165. return
  166. } else {
  167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  168. return
  169. }
  170. }
  171. //func (c *HisApiController) AssociationHisPrescription() {
  172. // record_date, _ := c.GetInt64("record_date")
  173. // his_patient_id, _ := c.GetInt64("his_patient_id")
  174. // patient_id, _ := c.GetInt64("patient_id")
  175. // p_ids := c.GetString("p_ids")
  176. // p_ids_arr := strings.Split(p_ids, ",")
  177. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  178. // if his_patient_id == 0 || his_patient.ID == 0 {
  179. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  180. // return
  181. // }
  182. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  183. // if err == nil {
  184. // c.ServeSuccessJSON(map[string]interface{}{
  185. // "msg": "关联处方成功",
  186. // })
  187. // return
  188. // } else {
  189. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  190. // return
  191. // }
  192. //}
  193. func (c *HisApiController) GetFaPiaoNumber() {
  194. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  195. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  196. fmt.Println(count)
  197. var zero string
  198. number := count + 1
  199. //if number >= 1000 {
  200. // zero = "0000" + strconv.FormatInt(number, 10)
  201. //} else if number >= 10000 {
  202. // zero = "000" + strconv.FormatInt(number, 10)
  203. //} else if number >= 100000 {
  204. // zero = "00" + strconv.FormatInt(number, 10)
  205. //} else if number >= 1000000 {
  206. // zero = "0" + strconv.FormatInt(number, 10)
  207. //} else {
  208. zero = "0" + strconv.FormatInt(number, 10)
  209. //}
  210. c.ServeSuccessJSON(map[string]interface{}{
  211. "fapiao_number": zero,
  212. })
  213. return
  214. }
  215. func (c *HisApiController) ChangeOrderDesc() {
  216. id, _ := c.GetInt64("id")
  217. desc := c.GetString("desc")
  218. change_type := c.GetString("change_type")
  219. order, _ := service.GetHisOrderByID(id)
  220. if order.ID == 0 {
  221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  222. return
  223. }
  224. switch change_type {
  225. case "oth_desc":
  226. order.OthDesc = desc
  227. break
  228. case "cash_pay":
  229. order.CashPay = desc
  230. break
  231. case "jifen_pay":
  232. order.JifenPay = desc
  233. break
  234. case "card_desc":
  235. order.CardDesc = desc
  236. break
  237. case "band_card_pay":
  238. order.BandCardPay = desc
  239. break
  240. case "ali_pay":
  241. order.AliPay = desc
  242. break
  243. case "wechat_pay":
  244. order.WechatPay = desc
  245. break
  246. case "fa_piao_number":
  247. order.FaPiaoNumber = desc
  248. break
  249. case "fa_piao_code":
  250. order.FaPiaoCode = desc
  251. break
  252. }
  253. err := service.SaveHisOrder(&order)
  254. if err == nil {
  255. c.ServeSuccessJSON(map[string]interface{}{
  256. "msg": "修改成功",
  257. })
  258. return
  259. } else {
  260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  261. return
  262. }
  263. }
  264. func (c *HisApiController) GetMonthHisPatient() {
  265. record_date := c.GetString("record_date")
  266. //order_status, _ := c.GetInt64("type")
  267. timeLayout := "2006-01-02"
  268. loc, _ := time.LoadLocation("Local")
  269. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  270. if err != nil {
  271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  272. return
  273. }
  274. recordDateTime := theTime.Unix()
  275. adminInfo := c.GetAdminUserInfo()
  276. var tempPatients []service.NewTempPatients
  277. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  278. // 获取当前时间
  279. now := time.Now()
  280. // 获取本月的第一天
  281. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  282. // 获取下个月的第一天
  283. nextMonth := firstDay.AddDate(0, 1, 0)
  284. // 获取本月的最后一天
  285. lastDay := nextMonth.Add(-time.Nanosecond)
  286. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  287. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  288. var patients []service.NewTempPatients
  289. var patients_two []service.NewTempPatients
  290. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  291. for _, item := range tempPatients {
  292. //过滤掉没挂号的和没开处方的
  293. if len(item.HisPrescription) > 0 {
  294. patients = append(patients, item)
  295. patients_two = append(patients_two, item)
  296. }
  297. ////过滤掉没挂号的
  298. //if len(item.HisPatient) > 0 {
  299. //}
  300. }
  301. } else {
  302. for _, item := range tempPatients {
  303. //过滤掉没挂号的和没开处方的
  304. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  305. patients = append(patients, item)
  306. }
  307. ////过滤掉没挂号的
  308. //if len(item.HisPatient) > 0 {
  309. // patients_two = append(patients_two, item)
  310. //}
  311. }
  312. }
  313. c.ServeSuccessJSON(map[string]interface{}{
  314. "list": patients,
  315. "list_two": patients_two,
  316. "chargePatients": chargePatients,
  317. })
  318. }
  319. func (c *HisApiController) GetBatchSettleAccounts() {
  320. order_ids := c.GetString("order_ids")
  321. admin_user_id, _ := c.GetInt64("admin_user_id")
  322. adminUser := c.GetAdminUserInfo()
  323. orders := strings.Split(order_ids, ",")
  324. var newOrders []models.Orders
  325. for _, item := range orders {
  326. order, _ := service.GetHisOrderByIDTenOne(item)
  327. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  328. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  329. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  330. orderInfos = append(orderInfos, orderInfos_two...)
  331. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  332. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  333. var diagnosis_ids []string
  334. if his.ID > 0 {
  335. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  336. } else {
  337. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  338. }
  339. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  340. var dia_config []*models.HisXtDiagnoseConfig
  341. var name string
  342. for _, item := range diagnosis_ids {
  343. id, _ := strconv.ParseInt(item, 10, 64)
  344. diagnosisConfig, _ := service.FindDiagnoseById(id)
  345. dia_config = append(dia_config, diagnosisConfig)
  346. if len(name) == 0 {
  347. name = diagnosisConfig.ClassName
  348. } else {
  349. name = name + "," + diagnosisConfig.ClassName
  350. }
  351. }
  352. var bedCostTotal float64 = 0 //床位总费
  353. var bedCostSelfTotal float64 = 0 //床位自费
  354. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  355. var bedSelfTotal float64 = 0 //床位部分项目自费
  356. var bedInscpTotal float64 = 0 //床位部分项目自费
  357. var operationCostTotal float64 = 0 //手术费
  358. var operationCostSelfTotal float64 = 0 //手术费
  359. var operationCostPartSelfTotal float64 = 0 //手术费
  360. var operationSelfTotal float64 = 0 //床位部分项目自费
  361. var operationInscpTotal float64 = 0 //床位部分项目自费
  362. var otherCostTotal float64 = 0 //其他费用
  363. var otherCostSelfTotal float64 = 0 //其他费用
  364. var otherCostPartSelfTotal float64 = 0 //其他费用
  365. var otherSelfTotal float64 = 0 //床位部分项目自费
  366. var otherInscpTotal float64 = 0 //床位部分项目自费
  367. var materialCostTotal float64 = 0 //材料费
  368. var materialCostSelfTotal float64 = 0 //材料费
  369. var materialCostPartSelfTotal float64 = 0 //材料费
  370. var materialSelfTotal float64 = 0 //床位部分项目自费
  371. var materialInscpTotal float64 = 0 //床位部分项目自费
  372. var westernMedicineCostTotal float64 = 0 //西药费
  373. var westernMedicineCostSelfTotal float64 = 0 //西药费
  374. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  375. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  376. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  377. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  378. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  379. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  380. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  381. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  382. var checkCostTotal float64 = 0 //检查费
  383. var checkCostSelfTotal float64 = 0 //检查费
  384. var checkCostPartSelfTotal float64 = 0 //检查费
  385. var checkSelfTotal float64 = 0 //床位部分项目自费
  386. var checkInscpTotal float64 = 0 //床位部分项目自费
  387. var laboratoryCostTotal float64 = 0 //化验费
  388. var laboratoryCostSelfTotal float64 = 0 //化验费
  389. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  390. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  391. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  392. var treatCostTotal float64 = 0 //治疗费用
  393. var treatCostSelfTotal float64 = 0 //治疗费用
  394. var treatCostPartSelfTotal float64 = 0 //治疗费用
  395. var treatSelfTotal float64 = 0 //床位部分项目自费
  396. var treatInscpTotal float64 = 0 //床位部分项目自费
  397. decimal.DivisionPrecision = 2
  398. for _, item := range orderInfos {
  399. if item.MedChrgitmType == "01" { //床位费
  400. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  407. if item.MedChrgitmType == "03" { //检查费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. } else {
  415. if item.MedChrgitmType == "03" { //检查费
  416. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. }
  423. if item.MedChrgitmType == "04" { //化验费
  424. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  425. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  426. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  427. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  428. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  429. }
  430. if item.MedChrgitmType == "05" { //治疗费
  431. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  432. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  433. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  434. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  435. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  436. }
  437. if item.MedChrgitmType == "06" { //手术费
  438. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  439. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  440. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  441. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  442. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  443. }
  444. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  445. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  446. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  447. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  448. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  449. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  450. }
  451. if item.MedChrgitmType == "09" { //西药费
  452. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  453. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  454. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  455. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  456. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  457. }
  458. if item.MedChrgitmType == "11" { //中成费
  459. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  460. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  461. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  462. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  463. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  464. }
  465. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  466. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  467. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  468. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  469. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  470. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  471. }
  472. }
  473. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  474. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  475. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  476. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  477. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  478. var doctor_name string
  479. if roles.ID == 0 {
  480. doctor_name = "管理员"
  481. } else {
  482. doctor_name = roles.UserName
  483. }
  484. yiliao_leibie := ""
  485. switch order.MedType {
  486. case "11":
  487. yiliao_leibie = "普通门诊"
  488. break
  489. case "12":
  490. yiliao_leibie = "门诊挂号"
  491. break
  492. case "13":
  493. yiliao_leibie = "急诊"
  494. break
  495. case "14":
  496. yiliao_leibie = "门诊特殊病"
  497. break
  498. case "15":
  499. yiliao_leibie = "门诊统筹"
  500. break
  501. case "16":
  502. yiliao_leibie = "门诊慢性病"
  503. break
  504. case "21":
  505. yiliao_leibie = "普通住院"
  506. break
  507. }
  508. var newOrder models.Orders
  509. newOrder.Diagnosis = name
  510. newOrder.OrderInfos = orderInfos
  511. newOrder.Number = order.MdtrtId
  512. newOrder.Date = order.SettleAccountsDate
  513. newOrder.ChargeAdmin = charge_admin
  514. newOrder.PrintorAdmin = printor_admin
  515. newOrder.Order = order
  516. newOrder.BedCostTotal = bedCostTotal
  517. newOrder.BedCostSelfTotal = bedCostSelfTotal
  518. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  519. newOrder.BedSelfTotal = bedSelfTotal
  520. newOrder.BedInscpTotal = bedInscpTotal
  521. newOrder.OperationCostTotal = operationCostTotal
  522. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  523. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  524. newOrder.OperationSelfTotal = operationSelfTotal
  525. newOrder.OperationInscpTotal = operationInscpTotal
  526. newOrder.OtherCostTotal = otherCostTotal
  527. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  528. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  529. newOrder.OtherSelfTotal = otherSelfTotal
  530. newOrder.OtherInscpTotal = otherInscpTotal
  531. newOrder.MaterialCostTotal = materialCostTotal
  532. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  533. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  534. newOrder.MaterialSelfTotal = materialSelfTotal
  535. newOrder.MaterialInscpTotal = materialInscpTotal
  536. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  537. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  538. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  539. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  540. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  541. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  542. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  543. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  544. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  545. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  546. newOrder.CheckCostTotal = checkCostTotal
  547. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  548. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  549. newOrder.CheckSelfTotal = checkSelfTotal
  550. newOrder.CheckInscpTotal = checkInscpTotal
  551. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  552. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  553. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  554. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  555. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  556. newOrder.TreatCostTotal = treatCostTotal
  557. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  558. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  559. newOrder.TreatSelfTotal = treatSelfTotal
  560. newOrder.TreatInscpTotal = treatInscpTotal
  561. newOrder.DoctorInfo = doctor_info
  562. newOrder.DoctorName = doctor_name
  563. newOrder.HealthCardNo = order.PsnNo
  564. newOrder.YiliaoLeibie = yiliao_leibie
  565. newOrder.Patient = patient
  566. newOrder.OrgName = miConfig.OrgName
  567. newOrder.OrgCode = miConfig.Code
  568. newOrder.OrderNumber = order.Number
  569. newOrder.HisPatient = his
  570. newOrder.DiaConfig = dia_config
  571. newOrders = append(newOrders, newOrder)
  572. }
  573. c.ServeSuccessJSON(map[string]interface{}{
  574. "orders": newOrders,
  575. })
  576. }
  577. func (c *HisApiController) GetTestOrder() {
  578. order_id, _ := c.GetInt64("order_id")
  579. admin_user_id, _ := c.GetInt64("admin_user_id")
  580. adminUser := c.GetAdminUserInfo()
  581. order, _ := service.GetHisOrderByID(order_id)
  582. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  583. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  584. orderInfos = append(orderInfos, orderInfos_two...)
  585. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  586. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  587. var dia_config []*models.HisXtDiagnoseConfig
  588. var name string
  589. var bedCostTotal float64 = 0 //床位总费
  590. var bedCostSelfTotal float64 = 0 //床位自费
  591. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  592. var bedSelfTotal float64 = 0 //床位部分项目自费
  593. var bedInscpTotal float64 = 0 //床位部分项目自费
  594. var operationCostTotal float64 = 0 //手术费
  595. var operationCostSelfTotal float64 = 0 //手术费
  596. var operationCostPartSelfTotal float64 = 0 //手术费
  597. var operationSelfTotal float64 = 0 //床位部分项目自费
  598. var operationInscpTotal float64 = 0 //床位部分项目自费
  599. var otherCostTotal float64 = 0 //其他费用
  600. var otherCostSelfTotal float64 = 0 //其他费用
  601. var otherCostPartSelfTotal float64 = 0 //其他费用
  602. var otherSelfTotal float64 = 0 //床位部分项目自费
  603. var otherInscpTotal float64 = 0 //床位部分项目自费
  604. var materialCostTotal float64 = 0 //材料费
  605. var materialCostSelfTotal float64 = 0 //材料费
  606. var materialCostPartSelfTotal float64 = 0 //材料费
  607. var materialSelfTotal float64 = 0 //床位部分项目自费
  608. var materialInscpTotal float64 = 0 //床位部分项目自费
  609. var westernMedicineCostTotal float64 = 0 //西药费
  610. var westernMedicineCostSelfTotal float64 = 0 //西药费
  611. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  612. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  613. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  614. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  615. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  616. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  617. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  618. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  619. var checkCostTotal float64 = 0 //检查费
  620. var checkCostSelfTotal float64 = 0 //检查费
  621. var checkCostPartSelfTotal float64 = 0 //检查费
  622. var checkSelfTotal float64 = 0 //床位部分项目自费
  623. var checkInscpTotal float64 = 0 //床位部分项目自费
  624. var laboratoryCostTotal float64 = 0 //化验费
  625. var laboratoryCostSelfTotal float64 = 0 //化验费
  626. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  627. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  628. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  629. var treatCostTotal float64 = 0 //治疗费用
  630. var treatCostSelfTotal float64 = 0 //治疗费用
  631. var treatCostPartSelfTotal float64 = 0 //治疗费用
  632. var treatSelfTotal float64 = 0 //床位部分项目自费
  633. var treatInscpTotal float64 = 0 //床位部分项目自费
  634. decimal.DivisionPrecision = 2
  635. for _, item := range orderInfos {
  636. if item.MedChrgitmType == "01" { //床位费
  637. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  644. if item.MedChrgitmType == "03" { //检查费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. } else {
  652. if item.MedChrgitmType == "03" { //检查费
  653. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. }
  660. if item.MedChrgitmType == "04" { //化验费
  661. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  662. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  663. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  664. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  665. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  666. }
  667. if item.MedChrgitmType == "05" { //治疗费
  668. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  669. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  670. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  671. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  672. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  673. }
  674. if item.MedChrgitmType == "06" { //手术费
  675. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  676. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  677. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  678. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  679. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  680. }
  681. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  682. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  683. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  684. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  685. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  686. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  687. }
  688. if item.MedChrgitmType == "09" { //西药费
  689. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  690. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  691. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  692. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  693. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  694. }
  695. if item.MedChrgitmType == "11" { //中成费
  696. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  697. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  698. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  699. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  700. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  701. }
  702. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  703. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  704. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  705. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  706. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  707. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  708. }
  709. }
  710. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  711. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  712. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  713. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  714. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  715. var doctor_name string
  716. if roles.ID == 0 {
  717. doctor_name = "管理员"
  718. } else {
  719. doctor_name = roles.UserName
  720. }
  721. yiliao_leibie := ""
  722. switch order.MedType {
  723. case "11":
  724. yiliao_leibie = "普通门诊"
  725. break
  726. case "12":
  727. yiliao_leibie = "门诊挂号"
  728. break
  729. case "13":
  730. yiliao_leibie = "急诊"
  731. break
  732. case "14":
  733. yiliao_leibie = "门诊特殊病"
  734. break
  735. case "15":
  736. yiliao_leibie = "门诊统筹"
  737. break
  738. case "16":
  739. yiliao_leibie = "门诊慢性病"
  740. break
  741. case "21":
  742. yiliao_leibie = "普通住院"
  743. break
  744. }
  745. c.ServeSuccessJSON(map[string]interface{}{
  746. "diagnosis": name,
  747. "order_infos": orderInfos,
  748. "number": order.MdtrtId,
  749. "date": order.SettleAccountsDate,
  750. "charge_admin": charge_admin,
  751. "printor_admin": printor_admin,
  752. "info": order,
  753. "order": order,
  754. "bedCostTotal": bedCostTotal,
  755. "bedCostSelfTotal": bedCostSelfTotal,
  756. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  757. "bedSelfTotal": bedSelfTotal,
  758. "bedInscpTotal": bedInscpTotal,
  759. "operationCostTotal": operationCostTotal,
  760. "operationCostSelfTotal": operationCostSelfTotal,
  761. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  762. "operationSelfTotal": operationSelfTotal,
  763. "operationInscpTotal": operationInscpTotal,
  764. "otherCostTotal": otherCostTotal,
  765. "otherCostSelfTotal": otherCostSelfTotal,
  766. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  767. "otherSelfTotal": otherSelfTotal,
  768. "otherInscpTotal": otherInscpTotal,
  769. "materialCostTotal": materialCostTotal,
  770. "materialCostSelfTotal": materialCostSelfTotal,
  771. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  772. "materialSelfTotal": materialSelfTotal,
  773. "materialInscpTotal": materialInscpTotal,
  774. "westernMedicineCostTotal": westernMedicineCostTotal,
  775. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  776. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  777. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  778. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  779. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  780. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  781. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  782. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  783. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  784. "checkCostTotal": checkCostTotal,
  785. "checkCostSelfTotal": checkCostSelfTotal,
  786. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  787. "checkSelfTotal": checkSelfTotal,
  788. "checkInscpTotal": checkInscpTotal,
  789. "laboratoryCostTotal": laboratoryCostTotal,
  790. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  791. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  792. "laboratorySelfTotal": laboratorySelfTotal,
  793. "laboratoryInscpTotal": laboratoryInscpTotal,
  794. "treatCostTotal": treatCostTotal,
  795. "treatCostSelfTotal": treatCostSelfTotal,
  796. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  797. "treatSelfTotal": treatSelfTotal,
  798. "treatInscpTotal": treatInscpTotal,
  799. "doctor_info": doctor_info,
  800. "doctor_name": doctor_name,
  801. "health_card_no": order.PsnNo,
  802. "yiliao_leibie": yiliao_leibie,
  803. "patient": patient,
  804. "org_name": miConfig.OrgName,
  805. "org_code": miConfig.Code,
  806. "order_number": order.Number,
  807. "his_hospital": his_hospital,
  808. "dia_config": dia_config,
  809. })
  810. }
  811. type CustomFundPay struct {
  812. FundPayType string `json:"fund_pay_type"`
  813. FundPayamt float64 `json:"fund_payamt"`
  814. InscpScpAmt float64 `json:"inscp_scp_amt"`
  815. }
  816. func (c *PublicApiController) GetBaiLinExportData() {
  817. data := service.GetBaiLinOrderData()
  818. fmt.Println(len(data))
  819. var new_data []*models.NewCustomHisOrder
  820. for _, item := range data {
  821. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  822. new_data = append(new_data, item)
  823. }
  824. }
  825. fmt.Println(len(new_data))
  826. c.ServeSuccessJSON(map[string]interface{}{
  827. "list": new_data,
  828. })
  829. }
  830. func (c *HisApiController) GetHisUnChargePatientList() {
  831. record_date := c.GetString("record_date")
  832. sch_type, _ := c.GetInt64("sch_type")
  833. timeLayout := "2006-01-02"
  834. loc, _ := time.LoadLocation("Local")
  835. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  836. if err != nil {
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  838. return
  839. }
  840. recordDateTime := theTime.Unix()
  841. adminInfo := c.GetAdminUserInfo()
  842. var tempPatients []*service.NewTempPatients
  843. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  844. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  845. var patients []*service.NewTempPatients
  846. var patients_two []*service.NewTempPatients
  847. for _, item := range tempPatients {
  848. //过滤掉没挂号的和没开处方的
  849. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  850. patients = append(patients, item)
  851. }
  852. //过滤掉没挂号的
  853. if len(item.HisPatient) > 0 {
  854. patients_two = append(patients_two, item)
  855. }
  856. }
  857. c.ServeSuccessJSON(map[string]interface{}{
  858. "list": patients,
  859. "list_two": patients_two,
  860. })
  861. }
  862. func (c *HisApiController) GetPrivateExpensesOrder() {
  863. //id, _ := c.GetInt64("id")
  864. //record_time := c.GetString("record_time")
  865. order_id, _ := c.GetInt64("order_id")
  866. admin_user_id, _ := c.GetInt64("admin_user_id")
  867. //timeLayout := "2006-01-02"
  868. //loc, _ := time.LoadLocation("Local")
  869. //
  870. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  871. //if err != nil {
  872. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  873. // return
  874. //}
  875. //recordDateTime := theTime.Unix()
  876. adminUser := c.GetAdminUserInfo()
  877. order, _ := service.GetHisOrderByID(order_id)
  878. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  879. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  880. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  881. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  882. //var config []*models.HisXtDiagnoseConfig
  883. var name string
  884. if order.PType == 1 {
  885. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  886. for _, item := range diagnosis_ids {
  887. id, _ := strconv.ParseInt(item, 10, 64)
  888. diagnosisConfig, _ := service.FindDiagnoseById(id)
  889. if len(name) == 0 {
  890. name = diagnosisConfig.ClassName
  891. } else {
  892. name = name + "," + diagnosisConfig.ClassName
  893. }
  894. }
  895. } else {
  896. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  897. for _, item := range diagnosis_ids {
  898. id, _ := strconv.ParseInt(item, 10, 64)
  899. diagnosisConfig, _ := service.FindDiagnoseById(id)
  900. if len(name) == 0 {
  901. name = diagnosisConfig.ClassName
  902. } else {
  903. name = name + "," + diagnosisConfig.ClassName
  904. }
  905. }
  906. }
  907. var bedCostTotal float64 = 0 //床位总费
  908. var bedCostSelfTotal float64 = 0 //床位自费
  909. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  910. var bedSelfTotal float64 = 0 //床位部分项目自费
  911. var bedInscpTotal float64 = 0 //床位部分项目自费
  912. var operationCostTotal float64 = 0 //手术费
  913. var operationCostSelfTotal float64 = 0 //手术费
  914. var operationCostPartSelfTotal float64 = 0 //手术费
  915. var operationSelfTotal float64 = 0 //床位部分项目自费
  916. var operationInscpTotal float64 = 0 //床位部分项目自费
  917. var otherCostTotal float64 = 0 //其他费用
  918. //var otherCostSelfTotal float64 = 0 //其他费用
  919. var otherCostPartSelfTotal float64 = 0 //其他费用
  920. //var otherSelfTotal float64 = 0 //床位部分项目自费
  921. //var otherInscpTotal float64 = 0 //床位部分项目自费
  922. var materialCostTotal float64 = 0 //材料费
  923. var materialCostSelfTotal float64 = 0 //材料费
  924. var materialCostPartSelfTotal float64 = 0 //材料费
  925. var materialSelfTotal float64 = 0 //床位部分项目自费
  926. var materialInscpTotal float64 = 0 //床位部分项目自费
  927. var westernMedicineCostTotal float64 = 0 //西药费
  928. var westernMedicineCostSelfTotal float64 = 0 //西药费
  929. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  930. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  931. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  932. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  933. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  934. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  935. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  936. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  937. var checkCostTotal float64 = 0 //检查费
  938. var checkCostSelfTotal float64 = 0 //检查费
  939. var checkCostPartSelfTotal float64 = 0 //检查费
  940. var checkSelfTotal float64 = 0 //床位部分项目自费
  941. var checkInscpTotal float64 = 0 //床位部分项目自费
  942. var laboratoryCostTotal float64 = 0 //化验费
  943. var laboratoryCostSelfTotal float64 = 0 //化验费
  944. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  945. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  946. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  947. var treatCostTotal float64 = 0 //治疗费用
  948. var treatCostSelfTotal float64 = 0 //治疗费用
  949. var treatCostPartSelfTotal float64 = 0 //治疗费用
  950. var treatSelfTotal float64 = 0 //床位部分项目自费
  951. var treatInscpTotal float64 = 0 //床位部分项目自费
  952. var zhenChaCostTotal float64 = 0 //其他费用
  953. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  954. decimal.DivisionPrecision = 2
  955. for _, item := range orderInfos {
  956. //item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  957. if c.GetAdminUserInfo().CurrentOrgId != 10726 {
  958. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  959. item.MedChrgitmType = "09"
  960. }
  961. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  962. if item.HisPrescriptionProject.Type == 2 {
  963. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  964. fmt.Println("CostClassify")
  965. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  966. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  967. case 0:
  968. item.MedChrgitmType = "0"
  969. break
  970. case 1:
  971. item.MedChrgitmType = "14"
  972. break
  973. case 2:
  974. item.MedChrgitmType = "05"
  975. break
  976. case 3:
  977. item.MedChrgitmType = "03"
  978. break
  979. case 4:
  980. item.MedChrgitmType = "03"
  981. break
  982. case 5:
  983. item.MedChrgitmType = "08"
  984. break
  985. case 6:
  986. item.MedChrgitmType = "14"
  987. break
  988. case 7:
  989. item.MedChrgitmType = "14"
  990. break
  991. case 8:
  992. item.MedChrgitmType = "03"
  993. break
  994. case 9:
  995. item.MedChrgitmType = "14"
  996. break
  997. case 10:
  998. item.MedChrgitmType = "14"
  999. break
  1000. case 11:
  1001. item.MedChrgitmType = "06"
  1002. break
  1003. case 12:
  1004. item.MedChrgitmType = "12"
  1005. break
  1006. case 13:
  1007. item.MedChrgitmType = "01"
  1008. break
  1009. case 14:
  1010. item.MedChrgitmType = "04"
  1011. break
  1012. case 15:
  1013. item.MedChrgitmType = "14"
  1014. break
  1015. case 101:
  1016. item.MedChrgitmType = "04"
  1017. break
  1018. }
  1019. } else {
  1020. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  1021. case 1:
  1022. item.MedChrgitmType = "14"
  1023. break
  1024. case 2:
  1025. item.MedChrgitmType = "05"
  1026. break
  1027. case 3:
  1028. item.MedChrgitmType = "04"
  1029. break
  1030. case 4:
  1031. item.MedChrgitmType = "14"
  1032. break
  1033. case 5:
  1034. item.MedChrgitmType = "08"
  1035. break
  1036. case 6:
  1037. item.MedChrgitmType = "14"
  1038. break
  1039. case 7:
  1040. item.MedChrgitmType = "14"
  1041. break
  1042. case 8:
  1043. item.MedChrgitmType = "03"
  1044. break
  1045. case 9:
  1046. item.MedChrgitmType = "14"
  1047. break
  1048. case 101:
  1049. item.MedChrgitmType = "04"
  1050. break
  1051. default:
  1052. item.MedChrgitmType = "14"
  1053. break
  1054. }
  1055. }
  1056. } else if item.HisPrescriptionProject.Type == 3 {
  1057. item.MedChrgitmType = "08"
  1058. }
  1059. }
  1060. }
  1061. }
  1062. if order.IsMedicineInsurance != 1 {
  1063. order.PsnCashPay = order.MedfeeSumamt
  1064. }
  1065. for _, item := range orderInfos {
  1066. if item.MedChrgitmType == "01" { //床位费
  1067. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1068. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1069. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1070. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1071. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1072. }
  1073. if item.MedChrgitmType == "02" { //诊察费
  1074. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1075. //zhenChaCostSelfTotal = zhenChaCostTotal
  1076. }
  1077. if item.MedChrgitmType == "03" { //检查费
  1078. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1079. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1080. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1081. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1082. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1083. }
  1084. if item.MedChrgitmType == "02" { //检查费
  1085. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1086. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1087. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1088. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1089. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1090. }
  1091. if item.MedChrgitmType == "04" { //化验费
  1092. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1093. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1094. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1095. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1096. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1097. }
  1098. if item.MedChrgitmType == "05" { //治疗费
  1099. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1100. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1101. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1102. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1103. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1104. }
  1105. if item.MedChrgitmType == "06" { //手术费
  1106. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1107. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1108. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1109. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1110. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1111. }
  1112. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1113. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1114. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1115. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1116. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1117. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1118. }
  1119. if item.MedChrgitmType == "09" { //西药费
  1120. fmt.Println("FulamtOwnpayAmt")
  1121. fmt.Println(item.FulamtOwnpayAmt)
  1122. fmt.Println("FulamtOwnpayAmt")
  1123. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1124. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1125. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1126. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1127. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1128. }
  1129. if item.MedChrgitmType == "11" { //中成费
  1130. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1131. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1132. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1133. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1134. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1135. }
  1136. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1137. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1138. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1139. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1140. }
  1141. }
  1142. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1143. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1144. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1145. var dia_config []*models.HisXtDiagnoseConfig
  1146. var diagnosis_ids []string
  1147. if his.ID > 0 {
  1148. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1149. } else {
  1150. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1151. }
  1152. for _, item := range diagnosis_ids {
  1153. id, _ := strconv.ParseInt(item, 10, 64)
  1154. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1155. dia_config = append(dia_config, diagnosisConfig)
  1156. }
  1157. var rf []CustomFundPay
  1158. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1159. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1160. c.ServeSuccessJSON(map[string]interface{}{
  1161. "patient": patient,
  1162. "order_infos": orderInfos,
  1163. "diagnosis": name,
  1164. "bedCostTotal": bedCostTotal,
  1165. "bedCostSelfTotal": bedCostSelfTotal,
  1166. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1167. "bedSelfTotal": bedSelfTotal,
  1168. "bedInscpTotal": bedInscpTotal,
  1169. "operationCostTotal": operationCostTotal,
  1170. "operationCostSelfTotal": operationCostSelfTotal,
  1171. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1172. "operationInscpTotal": operationInscpTotal,
  1173. "operationSelfTotal": operationSelfTotal,
  1174. "otherCostTotal": otherCostTotal,
  1175. //"otherCostSelfTotal": otherCostSelfTotal,
  1176. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1177. "materialCostTotal": materialCostTotal,
  1178. "materialCostSelfTotal": materialCostSelfTotal,
  1179. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1180. "materialSelfTotal": materialSelfTotal,
  1181. "materialInscpTotal": materialInscpTotal,
  1182. "westernMedicineCostTotal": westernMedicineCostTotal,
  1183. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  1184. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1185. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  1186. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  1187. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1188. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  1189. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1190. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  1191. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  1192. "checkCostTotal": checkCostTotal,
  1193. "checkCostSelfTotal": checkCostSelfTotal,
  1194. "checkSelfTotal": checkSelfTotal,
  1195. "checkInscpTotal": checkInscpTotal,
  1196. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1197. "zhenChaCostTotal": zhenChaCostTotal,
  1198. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1199. "laboratoryCostTotal": laboratoryCostTotal,
  1200. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  1201. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1202. "laboratorySelfTotal": laboratorySelfTotal,
  1203. "laboratoryInscpTotal": laboratoryInscpTotal,
  1204. "treatCostTotal": treatCostTotal,
  1205. "treatCostSelfTotal": treatCostSelfTotal,
  1206. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1207. "treatSelfTotal": treatSelfTotal,
  1208. "treatInscpTotal": treatInscpTotal,
  1209. "charge_admin": charge_admin,
  1210. "printor_admin": printor_admin,
  1211. "org_name": org.OrgName,
  1212. "org_code": miConfig.Code,
  1213. "name": patient.Name,
  1214. "number": order.MdtrtId,
  1215. "date": order.SettleAccountsDate,
  1216. "info": order,
  1217. "new_order": order,
  1218. "his_hospital": his_hospital,
  1219. "his": his,
  1220. "funds": rf,
  1221. "dia_config": dia_config,
  1222. })
  1223. }
  1224. func (c *HisApiController) RefudDetail() {
  1225. order_id, _ := c.GetInt64("order_id")
  1226. order, _ := service.GetHisOrderByID(order_id)
  1227. adminUser := c.GetAdminUserInfo()
  1228. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1229. c.ServeSuccessJSON(map[string]interface{}{
  1230. "msg": "撤销成功",
  1231. })
  1232. }
  1233. func (c *HisApiController) Sscard() {
  1234. //r := CardInit()
  1235. //if r == 0 {
  1236. // GetBaseInfo()
  1237. //}
  1238. //c.ServeSuccessJSON(map[string]interface{}{
  1239. // "list": "11",
  1240. //})
  1241. }
  1242. func GetBaseInfo() error {
  1243. //handle := syscall.MustLoadDLL("SSCard.dll")
  1244. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1245. //
  1246. //str := make([]byte, 256)
  1247. //str1 := make([]byte, 256)
  1248. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1249. //if ferr != nil {
  1250. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1251. // return ferr
  1252. //}
  1253. //
  1254. //fmt.Println(string(str))
  1255. //
  1256. //fmt.Println(r)
  1257. return nil
  1258. }
  1259. func CardInit() int {
  1260. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1261. //add := DllTestDef.MustFindProc("Init")
  1262. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1263. //if err != nil {
  1264. // fmt.Println("SSCard的运算结果为:", ret)
  1265. //}
  1266. //result := int(ret)
  1267. return 0
  1268. }
  1269. func IntPtr(n int) uintptr {
  1270. return uintptr(n)
  1271. }
  1272. func StrPtr(s string) uintptr {
  1273. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1274. }
  1275. func (c *HisApiController) GetHisPatientList() {
  1276. record_date := c.GetString("record_date")
  1277. sch_type, _ := c.GetInt64("sch_type")
  1278. patient_type, _ := c.GetInt64("patient_type")
  1279. fmt.Println("patient_type")
  1280. fmt.Println(patient_type)
  1281. timeLayout := "2006-01-02"
  1282. loc, _ := time.LoadLocation("Local")
  1283. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1284. if err != nil {
  1285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1286. return
  1287. }
  1288. recordDateTime := theTime.Unix()
  1289. adminInfo := c.GetAdminUserInfo()
  1290. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1291. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1292. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1293. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1294. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1295. fmt.Println(patients_three)
  1296. //获取当前用户的信息
  1297. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1298. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1299. //获取所有科室信息
  1300. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1301. //var aa []service.PatientThree
  1302. noElementsSlice := make([]service.PatientThree, 0)
  1303. c.ServeSuccessJSON(map[string]interface{}{
  1304. "list": patients_three,
  1305. "list_two": patients_four,
  1306. "list_three": noElementsSlice,
  1307. "info": adminUserInfo,
  1308. "doctors": doctors,
  1309. "department": department,
  1310. })
  1311. } else {
  1312. //获取当前用户的信息
  1313. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1314. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1315. //获取所有科室信息
  1316. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1317. //var aa []service.PatientThree
  1318. noElementsSlice := make([]service.PatientThree, 0)
  1319. c.ServeSuccessJSON(map[string]interface{}{
  1320. "list": patients,
  1321. "list_two": patients_two,
  1322. "list_three": noElementsSlice,
  1323. "info": adminUserInfo,
  1324. "doctors": doctors,
  1325. "department": department,
  1326. })
  1327. }
  1328. }
  1329. type CustomTemplate struct {
  1330. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1331. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1332. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1333. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1334. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1335. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1336. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1337. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1338. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1339. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1340. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1341. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1342. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1343. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1344. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1345. }
  1346. func (c *HisApiController) GetHisPatientInfo() {
  1347. patient_id, _ := c.GetInt64("patient_id")
  1348. his_patient_id, _ := c.GetInt64("his_patient_id")
  1349. record_date := c.GetString("record_date")
  1350. number := c.GetString("number")
  1351. //start_time := c.GetString("start_time")
  1352. //end_time := c.GetString("end_time")
  1353. p_type, _ := c.GetInt64("p_type")
  1354. timeLayout := "2006-01-02"
  1355. loc, _ := time.LoadLocation("Local")
  1356. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1357. if err != nil {
  1358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1359. return
  1360. }
  1361. recordDateTime := theTime.Unix()
  1362. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1363. //if err != nil {
  1364. //
  1365. //}
  1366. //startRecordDateTime := startTime.Unix()
  1367. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1368. //if err != nil {
  1369. //
  1370. //}
  1371. //endRecordDateTime := endTime.Unix()
  1372. admin := c.GetAdminUserInfo()
  1373. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1374. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1375. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1376. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1377. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1378. var prescriptions []*models.HisPrescription
  1379. var last_prescriptions []*models.HisPrescription
  1380. var sch_prescriptions []CustomTemplate
  1381. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1382. if p_type == 1 { //住院
  1383. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1384. for _, item := range prescriptions {
  1385. for _, subItem := range item.HisDoctorAdviceInfo {
  1386. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1387. if info.RetailPrice > 0 {
  1388. subItem.Drug.MinPrice = info.RetailPrice
  1389. }
  1390. }
  1391. }
  1392. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1393. } else { //门诊
  1394. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1395. for _, item := range prescriptions {
  1396. for _, subItem := range item.HisDoctorAdviceInfo {
  1397. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1398. if info.RetailPrice > 0 {
  1399. subItem.Drug.MinPrice = info.RetailPrice
  1400. }
  1401. }
  1402. }
  1403. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1404. }
  1405. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1406. if sch.ID > 0 {
  1407. var week string
  1408. t := time.Now()
  1409. switch t.Weekday().String() {
  1410. case "Monday":
  1411. week = "周一"
  1412. break
  1413. case "Tuesday":
  1414. week = "周二"
  1415. break
  1416. case "Wednesday":
  1417. week = "周三"
  1418. break
  1419. case "Thursday":
  1420. week = "周四"
  1421. break
  1422. case "Friday":
  1423. week = "周五"
  1424. break
  1425. case "Saturday":
  1426. week = "周六"
  1427. break
  1428. case "Sunday":
  1429. week = "周日"
  1430. break
  1431. }
  1432. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1433. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1434. //根据推送频率组装新的数组
  1435. for _, item := range temp_sch_prescriptions {
  1436. var cus CustomTemplate
  1437. cus.ID = item.ID
  1438. cus.UserOrgId = item.UserOrgId
  1439. cus.PatientId = item.PatientId
  1440. cus.MedType = item.MedType
  1441. cus.RecordDate = item.RecordDate
  1442. cus.Type = item.Type
  1443. cus.PType = item.PType
  1444. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1445. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1446. if subItem.FrequencyType == 1 { //每次必推
  1447. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1448. }
  1449. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1450. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1451. }
  1452. if subItem.FrequencyType == 2 { //按照天数频率
  1453. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1454. now := p.Unix()
  1455. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1456. dayStr2 := "-" + dayStr
  1457. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1458. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1459. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1460. if len(advices) == 0 {
  1461. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1462. }
  1463. }
  1464. }
  1465. }
  1466. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1467. if subItem.Type == 2 {
  1468. if subItem.XtHisProject.MedicalStatus != 1 {
  1469. if subItem.FrequencyType == 1 {
  1470. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1471. }
  1472. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1473. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1474. }
  1475. if subItem.FrequencyType == 2 {
  1476. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1477. now := p.Unix()
  1478. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1479. dayStr2 := "-" + dayStr
  1480. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1481. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1482. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1483. if len(projects) == 0 {
  1484. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1485. }
  1486. }
  1487. }
  1488. } else if subItem.Type == 3 {
  1489. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1490. if subItem.FrequencyType == 1 {
  1491. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1492. }
  1493. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1494. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1495. }
  1496. if subItem.FrequencyType == 2 {
  1497. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1498. now := p.Unix()
  1499. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1500. dayStr2 := "-" + dayStr
  1501. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1502. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1503. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1504. if len(projects) == 0 {
  1505. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1506. }
  1507. }
  1508. }
  1509. }
  1510. }
  1511. sch_prescriptions = append(sch_prescriptions, cus)
  1512. }
  1513. for _, item := range sch_prescriptions {
  1514. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1515. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1516. }
  1517. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1518. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1519. }
  1520. }
  1521. }
  1522. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1523. if config.ID > 0 && config.IsOpen == 1 {
  1524. for _, item := range sch_prescriptions {
  1525. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1526. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1527. if info.RetailPrice > 0 {
  1528. subItem.Drug.MinPrice = info.RetailPrice
  1529. if admin.CurrentOrgId != 10598 {
  1530. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1531. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1532. }
  1533. }
  1534. }
  1535. }
  1536. }
  1537. if config.ID > 0 && config.IsOpen == 1 {
  1538. for _, item := range sch_prescriptions {
  1539. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1540. if subItem.Type == 3 {
  1541. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1542. if info.Price > 0 {
  1543. subItem.GoodInfo.PackingPrice = info.Price
  1544. if admin.CurrentOrgId != 10598 {
  1545. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1546. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1547. }
  1548. }
  1549. }
  1550. }
  1551. }
  1552. }
  1553. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1554. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1555. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1556. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1557. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1558. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1559. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1560. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1561. //获取所有科室信息
  1562. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1563. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1564. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1565. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1566. fmt.Println(prescriptions)
  1567. fmt.Println(sch_prescriptions)
  1568. fmt.Println(last_prescriptions)
  1569. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1570. if len(sch_prescriptions) > 0 {
  1571. var index = 0
  1572. for subindex, item := range sch_prescriptions {
  1573. if item.Type == 2 {
  1574. index = subindex
  1575. }
  1576. }
  1577. fmt.Println(index)
  1578. fmt.Println(len(sch_prescriptions))
  1579. if index >= 0 && index < len(sch_prescriptions) {
  1580. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1581. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1582. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1583. if one.ID > 0 {
  1584. var hpt models.HisPrescriptionProjectTemplate
  1585. hpt.Type = 3
  1586. hpt.ID = 0
  1587. hpt.PatientId = sch_prescriptions[index].PatientId
  1588. hpt.Status = 1
  1589. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1590. hpt.Mtime = time.Now().Unix()
  1591. hpt.Ctime = time.Now().Unix()
  1592. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1593. hpt.Count = "1"
  1594. hpt.Price = one.RetailPrice
  1595. hpt.ProjectId = one.ID
  1596. hpt.FeedetlSn = ""
  1597. hpt.PrescriptionId = sch_prescriptions[index].ID
  1598. hpt.Unit = one.PackingUnit
  1599. hpt.Day = "1"
  1600. hpt.SingleDose = "1"
  1601. hpt.GoodInfo = one
  1602. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1603. }
  1604. if two.ID > 0 {
  1605. var hpt models.HisPrescriptionProjectTemplate
  1606. hpt.Type = 3
  1607. hpt.ID = 0
  1608. hpt.PatientId = sch_prescriptions[index].PatientId
  1609. hpt.Status = 1
  1610. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1611. hpt.Mtime = time.Now().Unix()
  1612. hpt.Ctime = time.Now().Unix()
  1613. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1614. hpt.Count = "1"
  1615. hpt.Price = two.RetailPrice
  1616. hpt.ProjectId = two.ID
  1617. hpt.FeedetlSn = ""
  1618. hpt.PrescriptionId = sch_prescriptions[index].ID
  1619. hpt.Unit = two.PackingUnit
  1620. hpt.Day = "1"
  1621. hpt.SingleDose = "1"
  1622. hpt.GoodInfo = two
  1623. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1624. }
  1625. //if three.ID > 0 {
  1626. // var hpt models.HisPrescriptionProjectTemplate
  1627. // hpt.Type = 3
  1628. // hpt.ID = 0
  1629. // hpt.PatientId = sch_prescriptions[index].PatientId
  1630. // hpt.Status = 1
  1631. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1632. // hpt.Mtime = time.Now().Unix()
  1633. // hpt.Ctime = time.Now().Unix()
  1634. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1635. // hpt.Count = "1"
  1636. // hpt.Price = three.RetailPrice
  1637. // hpt.ProjectId = three.ID
  1638. // hpt.FeedetlSn = ""
  1639. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1640. // hpt.Unit = three.PackingUnit
  1641. // hpt.Day = "1"
  1642. // hpt.SingleDose = "1"
  1643. // hpt.GoodInfo = three
  1644. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1645. //}
  1646. fmt.Println(sch_prescriptions)
  1647. }
  1648. } else {
  1649. if len(last_prescriptions) > 0 {
  1650. var index = 0
  1651. for subindex, item := range last_prescriptions {
  1652. if item.Type == 2 {
  1653. index = subindex
  1654. }
  1655. }
  1656. if index >= 0 && index < len(last_prescriptions) {
  1657. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1658. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1659. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1660. if one.ID > 0 {
  1661. var hpt models.HisPrescriptionProject
  1662. hpt.Type = 3
  1663. hpt.ID = 0
  1664. hpt.PatientId = last_prescriptions[index].PatientId
  1665. hpt.Status = 1
  1666. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1667. hpt.Mtime = time.Now().Unix()
  1668. hpt.Ctime = time.Now().Unix()
  1669. hpt.RecordDate = last_prescriptions[index].RecordDate
  1670. hpt.Count = "1"
  1671. hpt.Price = one.RetailPrice
  1672. hpt.ProjectId = one.ID
  1673. hpt.FeedetlSn = ""
  1674. hpt.PrescriptionId = last_prescriptions[index].ID
  1675. hpt.Unit = one.PackingUnit
  1676. hpt.Day = "1"
  1677. hpt.SingleDose = "1"
  1678. hpt.GoodInfo = one
  1679. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1680. }
  1681. if two.ID > 0 {
  1682. var hpt models.HisPrescriptionProject
  1683. hpt.Type = 3
  1684. hpt.ID = 0
  1685. hpt.PatientId = last_prescriptions[index].PatientId
  1686. hpt.Status = 1
  1687. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1688. hpt.Mtime = time.Now().Unix()
  1689. hpt.Ctime = time.Now().Unix()
  1690. hpt.RecordDate = last_prescriptions[index].RecordDate
  1691. hpt.Count = "1"
  1692. hpt.Price = two.RetailPrice
  1693. hpt.ProjectId = two.ID
  1694. hpt.FeedetlSn = ""
  1695. hpt.PrescriptionId = last_prescriptions[index].ID
  1696. hpt.Unit = two.PackingUnit
  1697. hpt.Day = "1"
  1698. hpt.SingleDose = "1"
  1699. hpt.GoodInfo = two
  1700. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1701. }
  1702. //if three.ID > 0 {
  1703. // var hpt models.HisPrescriptionProject
  1704. // hpt.Type = 3
  1705. // hpt.ID = 0
  1706. // hpt.PatientId = last_prescriptions[index].PatientId
  1707. // hpt.Status = 1
  1708. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1709. // hpt.Mtime = time.Now().Unix()
  1710. // hpt.Ctime = time.Now().Unix()
  1711. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1712. // hpt.Count = "1"
  1713. // hpt.Price = three.RetailPrice
  1714. // hpt.ProjectId = three.ID
  1715. // hpt.FeedetlSn = ""
  1716. // hpt.PrescriptionId = last_prescriptions[index].ID
  1717. // hpt.Unit = three.PackingUnit
  1718. // hpt.Day = "1"
  1719. // hpt.SingleDose = "1"
  1720. // hpt.GoodInfo = three
  1721. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1722. //}
  1723. }
  1724. }
  1725. }
  1726. }
  1727. c.ServeSuccessJSON(map[string]interface{}{
  1728. "his_info": his_patient_info,
  1729. "xt_info": xt_patient_info,
  1730. "prescription": prescriptions,
  1731. "case_history": case_history,
  1732. "info": patientPrescriptionInfo,
  1733. //"month_prescriptions": monthPrescriptions,
  1734. "order": order,
  1735. "doctors": doctors,
  1736. "department": department,
  1737. "sch_prescriptions": sch_prescriptions,
  1738. "last_prescriptions": last_prescriptions,
  1739. "schedule": sch,
  1740. "count": count,
  1741. "drugStockConfig": drugStockConfig,
  1742. "last_info": lastPatientPrescriptionInfo,
  1743. "befor": beforThrity,
  1744. "LastCaseHistory": LastCaseHistory,
  1745. "prescriptionInfo": prescriptionInfo,
  1746. })
  1747. return
  1748. }
  1749. func (c *HisApiController) GetHisPrescriptionConfig() {
  1750. adminInfo := c.GetAdminUserInfo()
  1751. //获取医嘱模版
  1752. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1753. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1754. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1755. //获取所有基础药
  1756. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1757. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1758. if config.ID > 0 && config.IsOpen == 1 {
  1759. for _, item := range drugs {
  1760. var index = 0
  1761. for _, subItem := range item.OtherDrugWarehouseInfo {
  1762. if index == 0 {
  1763. index = index + 1
  1764. if subItem.RetailPrice > 0 {
  1765. item.MinPrice = subItem.RetailPrice
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1772. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1773. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1774. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1775. //获取所有科室信息
  1776. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1777. //获取诊断信息
  1778. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1779. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1780. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1781. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1782. //获取是否开启保存耗材出库的开关
  1783. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1784. c.ServeSuccessJSON(map[string]interface{}{
  1785. "drugs": drugs,
  1786. "advices_template": advices,
  1787. "drugways": drugways,
  1788. "efs": efs,
  1789. "doctors": doctors,
  1790. "department": department,
  1791. "sick": sick,
  1792. "additions": additions,
  1793. "diagnose": diagnose,
  1794. "manufacturers": manufacturers,
  1795. "goodOutOpen": goodOutOpen,
  1796. "patientDiagnose": patientDiagnose,
  1797. })
  1798. }
  1799. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1800. //获取所有基础药
  1801. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1802. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1803. if config.ID > 0 && config.IsOpen == 1 {
  1804. for _, item := range drugs {
  1805. var index = 0
  1806. for _, subItem := range item.OtherDrugWarehouseInfo {
  1807. if index == 0 {
  1808. index = index + 1
  1809. if subItem.RetailPrice > 0 {
  1810. item.MinPrice = subItem.RetailPrice
  1811. }
  1812. }
  1813. }
  1814. }
  1815. }
  1816. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1817. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1818. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1819. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1820. //获取所有科室信息
  1821. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1822. //获取诊断信息
  1823. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1824. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1825. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1826. //获取是否开启保存耗材出库的开关
  1827. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1828. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1829. c.ServeSuccessJSON(map[string]interface{}{
  1830. "drugs": drugs,
  1831. "advices_template": advices,
  1832. "drugways": drugways,
  1833. "efs": efs,
  1834. "doctors": doctors,
  1835. "department": department,
  1836. "sick": sick,
  1837. "additions": additions,
  1838. "diagnose": diagnose,
  1839. "manufacturers": manufacturers,
  1840. "goodOutOpen": goodOutOpen,
  1841. "patientDiagnose": patientDiagnose,
  1842. })
  1843. }
  1844. }
  1845. func (c *HisApiController) CreateHisPrescription() {
  1846. record_date := c.GetString("record_date")
  1847. patient_id, _ := c.GetInt64("patient_id")
  1848. reg_type, _ := c.GetInt64("reg_type")
  1849. diagnose := c.GetString("diagnose")
  1850. sick_type, _ := c.GetInt64("sick_type")
  1851. sick_history := c.GetString("sick_history")
  1852. doctor_id, _ := c.GetInt64("doctor", 0)
  1853. department, _ := c.GetInt64("department", 0)
  1854. his_patient_id, _ := c.GetInt64("his_patient_id")
  1855. p_type, _ := c.GetInt64("p_type")
  1856. patient_diagnose := c.GetString("patient_diagnose")
  1857. dataBody := make(map[string]interface{}, 0)
  1858. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1859. if err != nil {
  1860. utils.ErrorLog(err.Error())
  1861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1862. return
  1863. }
  1864. //edit, src := GetCompareData(dataBody)
  1865. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1866. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1867. //fmt.Println(drugResult)
  1868. //fmt.Println(goodResult)
  1869. timeLayout := "2006-01-02"
  1870. loc, _ := time.LoadLocation("Local")
  1871. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1872. if err != nil {
  1873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1874. return
  1875. }
  1876. adminInfo := c.GetAdminUserInfo()
  1877. recordDateTime := theTime.Unix()
  1878. //查询默认出库仓库库存
  1879. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1880. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1881. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1882. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1883. if len(lists) == 1 {
  1884. his_patient_id = lists[0].ID
  1885. }
  1886. }
  1887. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1888. //自动出库的开关开启
  1889. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1890. //自动出库
  1891. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1892. //耗材保存处方出库
  1893. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1894. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1895. //已发药和已收费限制逻辑
  1896. isMidicine := false
  1897. isCharge := false
  1898. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1899. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1900. if len(prescriptions) > 0 {
  1901. for _, item := range prescriptions {
  1902. items := item.(map[string]interface{})
  1903. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1904. utils.ErrorLog("id")
  1905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1906. return
  1907. }
  1908. id := int64(items["id"].(float64))
  1909. if id > 0 {
  1910. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1911. if err != nil {
  1912. if new_prescription.OrderStatus == 4 {
  1913. isCharge = true
  1914. }
  1915. }
  1916. }
  1917. }
  1918. }
  1919. }
  1920. if isMidicine == true {
  1921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1922. return
  1923. }
  1924. if isCharge == true {
  1925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1926. return
  1927. }
  1928. // 开始主事务
  1929. db := service.XTWriteDB()
  1930. tx := db.Begin()
  1931. // 在函数结束时处理事务回滚
  1932. defer func() {
  1933. if r := recover(); r != nil {
  1934. tx.Rollback()
  1935. }
  1936. }()
  1937. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1938. //药品发药出库
  1939. if pharmacyConfig.IsOpen == 1 {
  1940. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1941. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1942. if len(prescriptions) > 0 {
  1943. for _, item := range prescriptions {
  1944. items := item.(map[string]interface{})
  1945. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1946. advices := items["advices"].([]interface{})
  1947. if len(advices) > 0 {
  1948. for _, advice := range advices {
  1949. var drug_id int64
  1950. var prescribing_number float64
  1951. var prescribingNumberUnit string
  1952. var adviceId int64
  1953. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1954. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1955. }
  1956. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1957. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1958. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1959. }
  1960. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1961. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1962. }
  1963. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1964. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1965. }
  1966. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1967. if drug.ID == 0 {
  1968. tx.Rollback()
  1969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1970. return
  1971. }
  1972. //查询药品的所有库存
  1973. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1974. var total_count int64
  1975. for _, it := range list {
  1976. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1977. }
  1978. totals := strconv.FormatInt(total_count, 10)
  1979. //查询该药品是否存在开药记录
  1980. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1981. //新增处方盘点库存是否充足
  1982. if advicelist.ID == 0 {
  1983. all_count, _ := strconv.ParseFloat(totals, 64)
  1984. if prescribingNumberUnit == drug.MinUnit {
  1985. if drug.IsUse != 1 {
  1986. if drug.IsProject == 0 || drug.IsProject == 2 {
  1987. if all_count == 0 {
  1988. tx.Rollback()
  1989. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1990. return
  1991. }
  1992. if prescribing_number > all_count {
  1993. tx.Rollback()
  1994. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1995. return
  1996. }
  1997. }
  1998. }
  1999. }
  2000. if prescribingNumberUnit == drug.MaxUnit {
  2001. num := prescribing_number * float64(drug.MinNumber)
  2002. if drug.IsUse != 1 {
  2003. if drug.IsProject == 0 || drug.IsProject == 2 {
  2004. if all_count == 0 {
  2005. tx.Rollback()
  2006. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2007. return
  2008. }
  2009. if num > all_count {
  2010. tx.Rollback()
  2011. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2012. return
  2013. }
  2014. }
  2015. }
  2016. }
  2017. }
  2018. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2019. //不使用保存处方出库
  2020. if drugOutConfig.IsOpen != 1 {
  2021. //修改处方
  2022. for _, advice := range advices {
  2023. var drug_id int64
  2024. var prescribing_number float64
  2025. var prescribingNumberUnit string
  2026. var prescribingNumber string
  2027. var adviceId int64
  2028. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2029. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2030. }
  2031. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2032. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2033. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2034. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2035. }
  2036. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2037. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2038. }
  2039. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2040. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2041. }
  2042. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2043. if drug.ID == 0 {
  2044. tx.Rollback()
  2045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2046. return
  2047. }
  2048. //查询药品的所有库存
  2049. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2050. var total_count int64
  2051. for _, it := range list {
  2052. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2053. }
  2054. totals := strconv.FormatInt(total_count, 10)
  2055. //查询该药品是否存在开药记录
  2056. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2057. //新增处方
  2058. if advicelist.ID == 0 {
  2059. all_count, _ := strconv.ParseFloat(totals, 64)
  2060. if prescribingNumberUnit == drug.MinUnit {
  2061. if drug.IsUse != 1 {
  2062. if drug.IsProject == 0 || drug.IsProject == 2 {
  2063. if all_count == 0 {
  2064. tx.Rollback()
  2065. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2066. return
  2067. }
  2068. if prescribing_number > all_count {
  2069. tx.Rollback()
  2070. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2071. return
  2072. }
  2073. }
  2074. }
  2075. } else {
  2076. if prescribingNumberUnit == drug.MaxUnit {
  2077. num := prescribing_number * float64(drug.MinNumber)
  2078. if drug.IsUse != 1 {
  2079. if drug.IsProject == 0 || drug.IsProject == 2 {
  2080. if all_count == 0 {
  2081. tx.Rollback()
  2082. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2083. return
  2084. }
  2085. if num > all_count {
  2086. tx.Rollback()
  2087. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2088. return
  2089. }
  2090. }
  2091. }
  2092. }
  2093. }
  2094. }
  2095. //修改处方
  2096. if advicelist.ID > 0 {
  2097. var device_number int64
  2098. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2099. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2100. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2101. device_number = prescribingNumberInt * drug.MinNumber
  2102. }
  2103. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2104. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2105. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2106. device_number = prescribingNumberInt
  2107. }
  2108. var number_count int64
  2109. if prescribingNumberUnit == drug.MaxUnit {
  2110. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2111. number_count = prescribingNumberInt * drug.MinNumber
  2112. }
  2113. if prescribingNumberUnit == drug.MinUnit {
  2114. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2115. number_count = prescribingNumberInt
  2116. }
  2117. //如果修改的数量大于之前修改的数量
  2118. if (number_count - device_number) > 0 {
  2119. //如果修改的差数量 大于库存数量
  2120. if drug.IsUse != 1 {
  2121. if (number_count - device_number) > total_count {
  2122. tx.Rollback()
  2123. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2124. return
  2125. }
  2126. }
  2127. }
  2128. }
  2129. }
  2130. }
  2131. }
  2132. }
  2133. }
  2134. }
  2135. }
  2136. }
  2137. }
  2138. //已发药和已收费限制逻辑
  2139. //执行出库的逻辑
  2140. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2141. //校验库存总量
  2142. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2143. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2144. if len(prescriptions) > 0 {
  2145. for _, item := range prescriptions {
  2146. items := item.(map[string]interface{})
  2147. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2148. advices := items["advices"].([]interface{})
  2149. if len(advices) > 0 {
  2150. for _, advice := range advices {
  2151. var drug_id int64
  2152. var prescribing_number float64
  2153. var prescribingNumberUnit string
  2154. var adviceId int64
  2155. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2156. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2157. }
  2158. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2159. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2160. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2161. }
  2162. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2163. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2164. }
  2165. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2166. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2167. }
  2168. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2169. if drug.ID == 0 {
  2170. tx.Rollback()
  2171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2172. return
  2173. }
  2174. //查询药品的所有库存
  2175. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2176. var total_count int64
  2177. for _, it := range list {
  2178. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2179. }
  2180. totals := strconv.FormatInt(total_count, 10)
  2181. //查询该药品是否存在开药记录
  2182. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2183. //查询最新批次库存
  2184. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2185. var batch_number_count int64
  2186. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2187. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2188. //新增处方
  2189. if advicelist.ID == 0 {
  2190. all_count, _ := strconv.ParseFloat(totals, 64)
  2191. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2192. if prescribingNumberUnit == drug.MinUnit {
  2193. if drug.IsUse != 1 {
  2194. if drug.IsProject == 0 || drug.IsProject == 2 {
  2195. if all_count == 0 {
  2196. tx.Rollback()
  2197. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2198. return
  2199. }
  2200. if prescribing_number > all_count {
  2201. tx.Rollback()
  2202. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2203. return
  2204. }
  2205. }
  2206. if adminInfo.CurrentOrgId == 10215 {
  2207. if prescribing_number > batch_number_all_count {
  2208. tx.Rollback()
  2209. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2210. return
  2211. }
  2212. }
  2213. }
  2214. }
  2215. if prescribingNumberUnit == drug.MaxUnit {
  2216. num := prescribing_number * float64(drug.MinNumber)
  2217. if drug.IsUse != 1 {
  2218. if drug.IsProject == 0 || drug.IsProject == 2 {
  2219. if all_count == 0 {
  2220. tx.Rollback()
  2221. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2222. return
  2223. }
  2224. if num > all_count {
  2225. tx.Rollback()
  2226. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2227. return
  2228. }
  2229. }
  2230. if adminInfo.CurrentOrgId == 10215 {
  2231. if num > batch_number_all_count {
  2232. tx.Rollback()
  2233. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2234. return
  2235. }
  2236. }
  2237. }
  2238. }
  2239. }
  2240. //不是保存处方出库
  2241. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2242. if drugOutConfig.IsOpen != 1 {
  2243. //修改处方
  2244. for _, advice := range advices {
  2245. var drug_id int64
  2246. var prescribing_number float64
  2247. var prescribingNumberUnit string
  2248. var prescribingNumber string
  2249. var adviceId int64
  2250. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2251. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2252. }
  2253. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2254. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2255. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2256. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2257. }
  2258. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2259. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2260. }
  2261. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2262. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2263. }
  2264. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2265. if drug.ID == 0 {
  2266. tx.Rollback()
  2267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2268. return
  2269. }
  2270. //查询药品的所有库存
  2271. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2272. var total_count int64
  2273. for _, it := range list {
  2274. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2275. }
  2276. totals := strconv.FormatInt(total_count, 10)
  2277. //查询该药品是否存在开药记录
  2278. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2279. //新增处方
  2280. if advicelist.ID == 0 {
  2281. //查询最新批次库存
  2282. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2283. var batch_number_count int64
  2284. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2285. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2286. all_count, _ := strconv.ParseFloat(totals, 64)
  2287. if all_count == 0 {
  2288. tx.Rollback()
  2289. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2290. return
  2291. }
  2292. if prescribingNumberUnit == drug.MinUnit {
  2293. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2294. if drug.IsUse != 1 {
  2295. if drug.IsProject == 0 || drug.IsProject == 2 {
  2296. if all_count == 0 {
  2297. tx.Rollback()
  2298. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2299. return
  2300. }
  2301. if prescribing_number > all_count {
  2302. tx.Rollback()
  2303. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2304. return
  2305. }
  2306. }
  2307. if adminInfo.CurrentOrgId == 10215 {
  2308. if prescribing_number > batch_number_all_count {
  2309. tx.Rollback()
  2310. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2311. return
  2312. }
  2313. }
  2314. }
  2315. } else {
  2316. if prescribingNumberUnit == drug.MaxUnit {
  2317. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2318. num := prescribing_number * float64(drug.MinNumber)
  2319. if drug.IsUse != 1 {
  2320. if drug.IsProject == 0 || drug.IsProject == 2 {
  2321. if all_count == 0 {
  2322. tx.Rollback()
  2323. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2324. return
  2325. }
  2326. if num > all_count {
  2327. tx.Rollback()
  2328. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2329. return
  2330. }
  2331. }
  2332. if adminInfo.CurrentOrgId == 10215 {
  2333. if prescribing_number > batch_number_all_count {
  2334. tx.Rollback()
  2335. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2336. return
  2337. }
  2338. }
  2339. }
  2340. }
  2341. }
  2342. }
  2343. //修改处方
  2344. if advicelist.ID > 0 {
  2345. //查询最新批次库存
  2346. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2347. var batch_number_count int64
  2348. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2349. var device_number int64
  2350. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2351. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2352. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2353. device_number = prescribingNumberInt * drug.MinNumber
  2354. }
  2355. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2356. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2357. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2358. device_number = prescribingNumberInt
  2359. //回退库存
  2360. }
  2361. var number_count int64
  2362. if prescribingNumberUnit == drug.MaxUnit {
  2363. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2364. number_count = prescribingNumberInt * drug.MinNumber
  2365. //回退库存
  2366. }
  2367. if prescribingNumberUnit == drug.MinUnit {
  2368. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2369. number_count = prescribingNumberInt
  2370. //回退库存
  2371. }
  2372. //如果修改的数量大于之前修改的数量
  2373. if (number_count - device_number) > 0 {
  2374. //如果修改的差数量 大于库存数量
  2375. if drug.IsUse != 1 {
  2376. if drug.IsProject == 0 || drug.IsProject == 2 {
  2377. if total_count == 0 {
  2378. tx.Rollback()
  2379. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2380. return
  2381. }
  2382. if (number_count - device_number) > total_count {
  2383. tx.Rollback()
  2384. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2385. return
  2386. }
  2387. if (number_count - device_number) > batch_number_count {
  2388. tx.Rollback()
  2389. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2390. return
  2391. }
  2392. }
  2393. if adminInfo.CurrentOrgId == 10215 {
  2394. // 查询该药品最后一次出库记录
  2395. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2396. var out_count int64
  2397. var in_count int64
  2398. var stock_max_number int64
  2399. var stock_min_number int64
  2400. for _, it := range outInfo {
  2401. if it.CountUnit == drug.MaxUnit {
  2402. it.Count = it.Count * drug.MinNumber
  2403. }
  2404. out_count += it.Count
  2405. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2406. stock_max_number = warehouseInfoList.StockMaxNumber
  2407. stock_min_number = warehouseInfoList.StockMinNumber
  2408. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2409. }
  2410. if out_count > 0 {
  2411. if (number_count - device_number) > in_count {
  2412. tx.Rollback()
  2413. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2414. return
  2415. }
  2416. }
  2417. // 未出库
  2418. if out_count == 0 {
  2419. var sum_in_count int64
  2420. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2421. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2422. //如果修改的数量大于有库存的第一个批次
  2423. if number_count > sum_in_count {
  2424. tx.Rollback()
  2425. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2426. return
  2427. }
  2428. }
  2429. }
  2430. }
  2431. }
  2432. //药品发药
  2433. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2434. //不使用药品发药的功能
  2435. //if pharmacyConfig.IsOpen != 1 {
  2436. // if device_number != number_count {
  2437. //
  2438. // //查询该药品的出库记录
  2439. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2440. // if len(outListExport) > 0 {
  2441. // //
  2442. // for _, item := range outListExport {
  2443. // //回退库存
  2444. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2445. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2446. // }
  2447. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2448. // var stock_max_number int64
  2449. // var stock_min_number int64
  2450. //
  2451. // if number_count >= drug.MinNumber {
  2452. //
  2453. // stock_max_number = device_number / drug.MinNumber
  2454. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2455. //
  2456. // stock_min_number = device_number % drug.MinNumber
  2457. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2458. //
  2459. // } else {
  2460. //
  2461. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2462. //
  2463. // }
  2464. // }
  2465. //
  2466. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2467. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2468. // }
  2469. // }
  2470. // }
  2471. //
  2472. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2473. // var sum_count int64
  2474. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2475. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2476. // for _, its := range stockInfo {
  2477. // if its.MaxUnit == drug.MaxUnit {
  2478. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2479. // }
  2480. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2481. // }
  2482. // //更新字典里面的库存
  2483. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2484. //
  2485. // //剩余库存
  2486. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2487. //
  2488. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2489. // //减少出库数量
  2490. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2491. //
  2492. // }
  2493. //}
  2494. }
  2495. }
  2496. }
  2497. //保存处方开药
  2498. if drugOutConfig.IsOpen == 1 {
  2499. //修改处方
  2500. for _, advice := range advices {
  2501. var drug_id int64
  2502. var prescribing_number float64
  2503. var prescribingNumberUnit string
  2504. var prescribingNumber string
  2505. var adviceId int64
  2506. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2507. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2508. }
  2509. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2510. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2511. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2512. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2513. }
  2514. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2515. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2516. }
  2517. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2518. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2519. }
  2520. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2521. if drug.ID == 0 {
  2522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2523. return
  2524. }
  2525. //查询药品的所有库存
  2526. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2527. var total_count int64
  2528. for _, it := range list {
  2529. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2530. }
  2531. totals := strconv.FormatInt(total_count, 10)
  2532. //查询该药品是否存在开药记录
  2533. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2534. //新增处方
  2535. if advicelist.ID == 0 {
  2536. //查询最新批次库存
  2537. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2538. var batch_number_count int64
  2539. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2540. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2541. all_count, _ := strconv.ParseFloat(totals, 64)
  2542. if prescribingNumberUnit == drug.MinUnit {
  2543. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2544. if drug.IsUse != 1 {
  2545. if drug.IsProject == 0 || drug.IsProject == 2 {
  2546. if all_count == 0 {
  2547. tx.Rollback()
  2548. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2549. return
  2550. }
  2551. if prescribing_number > all_count {
  2552. tx.Rollback()
  2553. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2554. return
  2555. }
  2556. }
  2557. if adminInfo.CurrentOrgId == 10215 {
  2558. if prescribing_number > batch_number_all_count {
  2559. tx.Rollback()
  2560. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2561. return
  2562. }
  2563. }
  2564. }
  2565. } else {
  2566. if prescribingNumberUnit == drug.MaxUnit {
  2567. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2568. num := prescribing_number * float64(drug.MinNumber)
  2569. if drug.IsUse != 1 {
  2570. if drug.IsProject == 0 || drug.IsProject == 2 {
  2571. if all_count == 0 {
  2572. tx.Rollback()
  2573. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2574. return
  2575. }
  2576. if num > all_count {
  2577. tx.Rollback()
  2578. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2579. return
  2580. }
  2581. }
  2582. if adminInfo.CurrentOrgId == 10215 {
  2583. if prescribing_number > batch_number_all_count {
  2584. tx.Rollback()
  2585. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2586. return
  2587. }
  2588. }
  2589. }
  2590. }
  2591. }
  2592. }
  2593. //修改处方
  2594. if advicelist.ID > 0 {
  2595. //查询最新批次库存
  2596. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2597. var batch_number_count int64
  2598. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2599. var device_number int64
  2600. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2601. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2602. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2603. device_number = prescribingNumberInt * drug.MinNumber
  2604. }
  2605. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2606. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2607. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2608. device_number = prescribingNumberInt
  2609. }
  2610. var number_count int64
  2611. if prescribingNumberUnit == drug.MaxUnit {
  2612. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2613. number_count = prescribingNumberInt * drug.MinNumber
  2614. }
  2615. if prescribingNumberUnit == drug.MinUnit {
  2616. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2617. number_count = prescribingNumberInt
  2618. }
  2619. //如果修改的数量大于之前修改的数量
  2620. if (number_count - device_number) > 0 {
  2621. //如果修改的差数量 大于库存数量
  2622. if drug.IsUse != 1 {
  2623. if drug.IsProject == 0 || drug.IsProject == 2 {
  2624. if total_count == 0 {
  2625. tx.Rollback()
  2626. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2627. return
  2628. }
  2629. if (number_count - device_number) > total_count {
  2630. tx.Rollback()
  2631. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2632. return
  2633. }
  2634. }
  2635. if adminInfo.CurrentOrgId == 10215 {
  2636. if (number_count - device_number) > batch_number_count {
  2637. tx.Rollback()
  2638. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2639. return
  2640. }
  2641. }
  2642. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2643. //查询历史出库数据总批次
  2644. // 查询该药品最后一次出库记录
  2645. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2646. var out_count int64
  2647. var in_count int64
  2648. var stock_max_number int64
  2649. var stock_min_number int64
  2650. for _, it := range outInfo {
  2651. if it.CountUnit == drug.MaxUnit {
  2652. it.Count = it.Count * drug.MinNumber
  2653. }
  2654. out_count += it.Count
  2655. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2656. stock_max_number = warehouseInfoList.StockMaxNumber
  2657. stock_min_number = warehouseInfoList.StockMinNumber
  2658. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2659. }
  2660. if out_count > 0 {
  2661. if (number_count - device_number) > in_count {
  2662. tx.Rollback()
  2663. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2664. return
  2665. }
  2666. }
  2667. // 未出库
  2668. if out_count == 0 {
  2669. var sum_in_count int64
  2670. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2671. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2672. if sum_in_count == 0 {
  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. if number_count > sum_in_count {
  2679. tx.Rollback()
  2680. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2681. return
  2682. }
  2683. }
  2684. }
  2685. }
  2686. }
  2687. }
  2688. }
  2689. }
  2690. }
  2691. }
  2692. }
  2693. }
  2694. }
  2695. }
  2696. }
  2697. //校验耗材库存
  2698. if goodOutConfig.IsOpen == 1 {
  2699. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2700. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2701. if len(prescriptions) > 0 {
  2702. for _, item := range prescriptions {
  2703. items := item.(map[string]interface{})
  2704. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2705. projects := items["project"].([]interface{})
  2706. if len(projects) > 0 {
  2707. for _, project := range projects {
  2708. var project_id int64
  2709. var project_type int64
  2710. var totals float64
  2711. var project_name string
  2712. var parsetotal int64
  2713. var id int64
  2714. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2715. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2716. }
  2717. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2718. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2719. }
  2720. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2721. total, _ := project.(map[string]interface{})["total"].(string)
  2722. totals, _ = strconv.ParseFloat(total, 64)
  2723. }
  2724. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2725. project_name = project.(map[string]interface{})["project_name"].(string)
  2726. }
  2727. if project_type == 3 {
  2728. //查找该耗材的出库记录
  2729. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2730. if len(goodWarehouseInfo) == 0 {
  2731. //查询耗材库存
  2732. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2733. var stock_count int64
  2734. for _, it := range list {
  2735. stock_count += it.StockCount
  2736. }
  2737. stock_counts := strconv.FormatInt(stock_count, 10)
  2738. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2739. if stock_total_count == 0 {
  2740. tx.Rollback()
  2741. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2742. return
  2743. }
  2744. if totals > stock_total_count {
  2745. tx.Rollback()
  2746. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2747. return
  2748. }
  2749. }
  2750. if len(goodWarehouseInfo) > 0 {
  2751. //查询该患者耗材的历史数据
  2752. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2753. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2754. //数量发生改变
  2755. if parsetotal != count {
  2756. //如果现在的数量大于历史数量,就要看库存是否足够
  2757. if parsetotal > count {
  2758. //查询耗材所有库存
  2759. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2760. var stock_count int64
  2761. for _, it := range list {
  2762. stock_count += it.StockCount
  2763. }
  2764. //库存不足
  2765. if stock_count == 0 {
  2766. tx.Rollback()
  2767. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2768. return
  2769. }
  2770. if (parsetotal - count) > stock_count {
  2771. tx.Rollback()
  2772. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2773. return
  2774. }
  2775. }
  2776. }
  2777. }
  2778. }
  2779. }
  2780. }
  2781. }
  2782. }
  2783. }
  2784. }
  2785. }
  2786. //不使用耗材保存处方出库
  2787. if goodOutConfig.IsOpen != 1 {
  2788. if stockConfig.IsOpen == 1 {
  2789. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2790. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2791. if len(prescriptions) > 0 {
  2792. for _, item := range prescriptions {
  2793. items := item.(map[string]interface{})
  2794. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2795. projects := items["project"].([]interface{})
  2796. if len(projects) > 0 {
  2797. for _, project := range projects {
  2798. var project_id int64
  2799. var project_type int64
  2800. var totals float64
  2801. var project_name string
  2802. var parsetotal int64
  2803. var id int64
  2804. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2805. id = int64(project.(map[string]interface{})["id"].(float64))
  2806. }
  2807. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2808. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2809. }
  2810. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2811. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2812. }
  2813. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2814. total, _ := project.(map[string]interface{})["total"].(string)
  2815. totals, _ = strconv.ParseFloat(total, 64)
  2816. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2817. }
  2818. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2819. project_name = project.(map[string]interface{})["project_name"].(string)
  2820. }
  2821. if project_type == 3 {
  2822. //查找该耗材的出库记录
  2823. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2824. //没有出库记录
  2825. if len(goodWarehouseInfo) == 0 {
  2826. //查询耗材库存
  2827. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2828. var stock_count int64
  2829. for _, it := range list {
  2830. stock_count += it.StockCount
  2831. }
  2832. stock_counts := strconv.FormatInt(stock_count, 10)
  2833. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2834. if stock_total_count == 0 {
  2835. tx.Rollback()
  2836. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2837. return
  2838. }
  2839. if totals > stock_total_count {
  2840. tx.Rollback()
  2841. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2842. return
  2843. }
  2844. //查找今日该患者已经出库的所有耗材
  2845. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2846. for _, item := range goodList {
  2847. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2848. var flush_count int64
  2849. for _, it := range goodListSix {
  2850. flush_count += it.StockCount
  2851. }
  2852. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2853. creater := adminInfo.AdminUser.Id
  2854. if errs != nil {
  2855. goodErrcode := models.XtGoodErrcode{
  2856. UserOrgId: item.OrgId,
  2857. Errcode: "手动出库更新剩余出库失败",
  2858. GoodId: item.GoodId,
  2859. Status: 1,
  2860. Ctime: time.Now().Unix(),
  2861. Mtime: 0,
  2862. Count: 0,
  2863. StockCount: 0,
  2864. Creater: creater,
  2865. BatchNumberId: 0,
  2866. WarehouseOutId: 0,
  2867. }
  2868. service.CreateGoodErrcode(goodErrcode)
  2869. }
  2870. }
  2871. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2872. }
  2873. //有出库记录
  2874. if len(goodWarehouseInfo) > 0 {
  2875. //查询该患者耗材的历史数据
  2876. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2877. fmt.Println("ordProject-----------------------", ordProject.ProjectId)
  2878. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2879. //数量发生改变
  2880. if parsetotal != count {
  2881. //查找今日该患者已经出库的所有耗材
  2882. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2883. for _, item := range goodList {
  2884. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2885. var flush_count int64
  2886. for _, it := range goodListSix {
  2887. flush_count += it.StockCount
  2888. }
  2889. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2890. //减少出库数量
  2891. creater := adminInfo.AdminUser.Id
  2892. if errs != nil {
  2893. goodErrcode := models.XtGoodErrcode{
  2894. UserOrgId: item.OrgId,
  2895. Errcode: "手动出库更新剩余出库失败",
  2896. GoodId: item.GoodId,
  2897. Status: 1,
  2898. Ctime: time.Now().Unix(),
  2899. Mtime: 0,
  2900. Count: 0,
  2901. StockCount: 0,
  2902. Creater: creater,
  2903. BatchNumberId: 0,
  2904. WarehouseOutId: 0,
  2905. }
  2906. service.CreateGoodErrcode(goodErrcode)
  2907. }
  2908. //查询默认仓库
  2909. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2910. var total_count int64
  2911. for _, it := range stockList {
  2912. total_count += it.StockCount
  2913. }
  2914. //基础库插入数据
  2915. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2916. }
  2917. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2918. }
  2919. }
  2920. }
  2921. }
  2922. }
  2923. }
  2924. }
  2925. }
  2926. }
  2927. }
  2928. }
  2929. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2930. var hpInfo models.HisPrescriptionInfo
  2931. if info.ID == 0 {
  2932. var randNum int
  2933. randNum = rand.Intn(10000) + 1000
  2934. timestamp := time.Now().Unix()
  2935. tempTime := time.Unix(timestamp, 0)
  2936. timeFormat := tempTime.Format("20060102150405")
  2937. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2938. hpInfo = models.HisPrescriptionInfo{
  2939. HisPatientId: his_patient_id,
  2940. UserOrgId: adminInfo.CurrentOrgId,
  2941. RecordDate: theTime.Unix(),
  2942. PatientId: patient_id,
  2943. Status: 1,
  2944. Ctime: time.Now().Unix(),
  2945. Mtime: time.Now().Unix(),
  2946. Creator: adminInfo.AdminUser.Id,
  2947. Modifier: adminInfo.AdminUser.Id,
  2948. Diagnosis: diagnose,
  2949. SickHistory: sick_history,
  2950. Departments: department,
  2951. RegisterType: reg_type,
  2952. PrescriptionNumber: p_number,
  2953. PrescriptionStatus: 1,
  2954. Doctor: role.UserName,
  2955. DoctorId: doctor_id,
  2956. SickType: sick_type,
  2957. PType: p_type,
  2958. PatientDiagnosis: patient_diagnose,
  2959. }
  2960. service.SavePatientPrescriptionInfo(hpInfo)
  2961. //创建步骤表
  2962. finish := models.XtDialysisFinish{
  2963. IsFinish: 1,
  2964. UserOrgId: adminInfo.CurrentOrgId,
  2965. Status: 1,
  2966. Ctime: time.Now().Unix(),
  2967. Mtime: 0,
  2968. Module: 4,
  2969. RecordDate: theTime.Unix(),
  2970. Sourse: 1,
  2971. PatientId: patient_id,
  2972. }
  2973. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2974. if dialysisFinish.ID == 0 {
  2975. service.CreateDialysisFinish(finish)
  2976. }
  2977. redis := service.RedisClient()
  2978. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2979. redis.Set(key, "", time.Second)
  2980. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2981. redis.Set(keyOne, "", time.Second)
  2982. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2983. redis.Set(keySeven, "", time.Second)
  2984. defer redis.Close()
  2985. } else {
  2986. hpInfo = models.HisPrescriptionInfo{
  2987. ID: info.ID,
  2988. UserOrgId: adminInfo.CurrentOrgId,
  2989. RecordDate: info.RecordDate,
  2990. PatientId: info.PatientId,
  2991. Status: 1,
  2992. Ctime: info.Ctime,
  2993. Mtime: time.Now().Unix(),
  2994. Creator: info.Creator,
  2995. Modifier: adminInfo.AdminUser.Id,
  2996. Diagnosis: diagnose,
  2997. SickHistory: sick_history,
  2998. Departments: department,
  2999. RegisterType: reg_type,
  3000. PrescriptionNumber: info.PrescriptionNumber,
  3001. Doctor: role.UserName,
  3002. PrescriptionStatus: info.PrescriptionStatus,
  3003. DoctorId: doctor_id,
  3004. SickType: sick_type,
  3005. PType: info.PType,
  3006. HisPatientId: info.HisPatientId,
  3007. PatientDiagnosis: patient_diagnose,
  3008. }
  3009. service.SavePatientPrescriptionInfo(hpInfo)
  3010. //创建步骤表
  3011. finish := models.XtDialysisFinish{
  3012. IsFinish: 1,
  3013. UserOrgId: adminInfo.CurrentOrgId,
  3014. Status: 1,
  3015. Ctime: time.Now().Unix(),
  3016. Mtime: 0,
  3017. Module: 4,
  3018. RecordDate: info.RecordDate,
  3019. Sourse: 1,
  3020. PatientId: info.PatientId,
  3021. }
  3022. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  3023. if dialysisFinish.ID == 0 {
  3024. service.CreateDialysisFinish(finish)
  3025. }
  3026. redis := service.RedisClient()
  3027. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3028. redis.Set(key, "", time.Second)
  3029. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3030. redis.Set(keyOne, "", time.Second)
  3031. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3032. redis.Set(keySeven, "", time.Second)
  3033. defer redis.Close()
  3034. }
  3035. //定义切片
  3036. var adviceList []models.HisDoctorAdviceInfo
  3037. var projectList []models.HisPrescriptionProject
  3038. 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 || adminInfo.CurrentOrgId == 9478 || adminInfo.CurrentOrgId == 10567 {
  3039. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3040. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3041. var tempPrescription *models.HisPrescription
  3042. if len(prescriptions) > 0 {
  3043. for _, item := range prescriptions {
  3044. // 开始外部循环的事务
  3045. tx := db.Begin()
  3046. // 在函数结束时处理事务回滚
  3047. defer func() {
  3048. if r := recover(); r != nil {
  3049. tx.Rollback()
  3050. }
  3051. }()
  3052. items := item.(map[string]interface{})
  3053. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3054. utils.ErrorLog("id")
  3055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3056. return
  3057. }
  3058. id := int64(items["id"].(float64))
  3059. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3060. tempPrescription = &new_prescription
  3061. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3062. utils.ErrorLog("type")
  3063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3064. return
  3065. }
  3066. types := int64(items["type"].(float64))
  3067. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3068. utils.ErrorLog("med_type")
  3069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3070. return
  3071. }
  3072. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3073. if med_type == "0" {
  3074. med_type = "14"
  3075. }
  3076. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3077. // utils.ErrorLog("diagnoses")
  3078. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3079. // return
  3080. //}
  3081. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3082. diagnoses, _ := items["diagnoses"].(string)
  3083. //if order_status == 0 {
  3084. // order_status = 1
  3085. //}
  3086. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3087. utils.ErrorLog("pre_time")
  3088. }
  3089. preTime, _ := items["pre_time"].(string)
  3090. fmt.Println("preTime", preTime)
  3091. timeLayout := "2006-01-02"
  3092. loc, _ := time.LoadLocation("Local")
  3093. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3094. //result := strings.Split(preTime, " ")
  3095. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3096. if err != nil {
  3097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3098. return
  3099. }
  3100. pTime := theTime2.Unix()
  3101. ctime := time.Now().Unix()
  3102. if tempPrescription.ID == 0 {
  3103. prescription := &models.HisPrescription{
  3104. ID: 0,
  3105. PatientId: patient_id,
  3106. UserOrgId: adminInfo.CurrentOrgId,
  3107. RecordDate: recordDateTime,
  3108. Ctime: ctime,
  3109. Mtime: ctime,
  3110. Type: types,
  3111. Modifier: adminInfo.AdminUser.Id,
  3112. Creator: adminInfo.AdminUser.Id,
  3113. Status: 1,
  3114. Doctor: role.UserName,
  3115. HisPatientId: his_patient_id,
  3116. OrderStatus: 1,
  3117. BatchNumber: "",
  3118. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3119. PreTime: pTime,
  3120. PType: p_type,
  3121. MedType: med_type,
  3122. Diagnose: diagnoses,
  3123. }
  3124. tempPrescription = prescription
  3125. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3126. redis := service.RedisClient()
  3127. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3128. redis.Set(key, "", time.Second)
  3129. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3130. redis.Set(keyOne, "", time.Second)
  3131. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3132. redis.Set(keySeven, "", time.Second)
  3133. defer redis.Close()
  3134. } else {
  3135. tempPrescription.ID = id
  3136. tempPrescription.Type = types
  3137. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3138. tempPrescription.Mtime = time.Now().Unix()
  3139. tempPrescription.Doctor = role.UserName
  3140. //tempPrescription.OrderStatus = order_status
  3141. tempPrescription.PreTime = pTime
  3142. tempPrescription.MedType = med_type
  3143. tempPrescription.Diagnose = diagnoses
  3144. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3145. redis := service.RedisClient()
  3146. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3147. redis.Set(key, "", time.Second)
  3148. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3149. redis.Set(keyOne, "", time.Second)
  3150. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3151. redis.Set(keySeven, "", time.Second)
  3152. defer redis.Close()
  3153. }
  3154. //service.SaveHisPrescription(prescription)
  3155. //更改患者挂号状态
  3156. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3157. fmt.Println("更改失败", err2)
  3158. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3159. advices := items["advices"].([]interface{})
  3160. groupNo := int64(0)
  3161. if len(advices) > 0 {
  3162. for _, advice := range advices {
  3163. tx := db.Begin()
  3164. // 在函数结束时处理事务回滚
  3165. defer func() {
  3166. if r := recover(); r != nil {
  3167. tx.Rollback()
  3168. }
  3169. }()
  3170. var s models.HisDoctorAdviceInfo
  3171. s.PrescriptionId = tempPrescription.ID
  3172. s.AdviceType = 2
  3173. s.AdviceDoctor = doctor_id
  3174. s.StopState = 2
  3175. s.ExecutionState = 2
  3176. s.AdviceDate = theTime3.Unix()
  3177. s.Status = 1
  3178. s.UserOrgId = adminInfo.CurrentOrgId
  3179. s.RecordDate = theTime3.Unix()
  3180. s.StartTime = tempPrescription.PreTime
  3181. s.Groupno = groupNo
  3182. s.PatientId = patient_id
  3183. s.HisPatientId = his_patient_id
  3184. s.StartTime = pTime
  3185. s.IsSettle = 2
  3186. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3187. if errcode > 0 {
  3188. c.ServeFailJSONWithSGJErrorCode(errcode)
  3189. return
  3190. }
  3191. s.StartTime = pTime
  3192. var total_count int64 //处方总库存
  3193. //查询改药品信息
  3194. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3195. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3196. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3197. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3198. total_count += prescribingNumberSeven * medical.MinNumber
  3199. }
  3200. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3201. total_count += prescribingNumberSeven
  3202. }
  3203. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3204. total_count += prescribingNumberSeven
  3205. }
  3206. //if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3207. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3208. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3209. // if s.Price != lastWarehouse.RetailPrice {
  3210. // s.Price = lastWarehouse.RetailPrice
  3211. // }
  3212. // if s.Price == 0 {
  3213. // if lastWarehouse.ID == 0 {
  3214. // lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3215. // s.Price = lastWarehouseTwo.RetailPrice
  3216. // }
  3217. //
  3218. // }
  3219. //}
  3220. //查询保存处方出库开关是否打开
  3221. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3222. if s.PatientId != 30038 {
  3223. if drugOutConfig.IsOpen == 1 {
  3224. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3225. // 查询该药品最后一次出库记录
  3226. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3227. var is_user_total int64
  3228. var no_user_total int64
  3229. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3230. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3231. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3232. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3233. }
  3234. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3235. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3236. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3237. no_user_total += prescribingNumberSevenTy
  3238. }
  3239. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3240. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3241. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3242. no_user_total += prescribingNumberSevenTy
  3243. }
  3244. if len(druginfo) > 0 {
  3245. for _, it := range druginfo {
  3246. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3247. it.Count = it.Count * drug.MinNumber
  3248. is_user_total += it.Count
  3249. }
  3250. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3251. is_user_total += it.Count
  3252. }
  3253. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3254. is_user_total += it.Count
  3255. }
  3256. }
  3257. }
  3258. //库存不足
  3259. if s.UserOrgId != 10206 {
  3260. //判断库存不足的地方
  3261. if s.ID == 0 {
  3262. //查询改药品是否已经停用
  3263. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3264. if base.ID > 0 {
  3265. tx.Rollback()
  3266. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3267. return
  3268. }
  3269. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3270. if drugMedical.SumCount == 0 {
  3271. tx.Rollback()
  3272. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3273. return
  3274. }
  3275. list, _ := service.GetLastDrugWarehouseInfoList(s.DrugId)
  3276. if len(list) == 0 {
  3277. tx.Rollback()
  3278. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3279. return
  3280. }
  3281. //针对康德
  3282. //if s.UserOrgId == 10402 || s.UserOrgId == 10164 {
  3283. // //获取该药品的总入库数量
  3284. // drugWarehouseinfo, _ := service.GetAllDrugInfoList(s.DrugId, s.UserOrgId)
  3285. //
  3286. // //获取该药品总共开了多少支医嘱
  3287. // hisDocInfoList, _ := service.GetHisDocInfoList(s.DrugId, s.UserOrgId)
  3288. // var in_count int64
  3289. // var in_prescription_number_total int64
  3290. // if len(drugWarehouseinfo) > 0 {
  3291. // for _, item := range drugWarehouseinfo {
  3292. // if item.MaxUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3293. //
  3294. // in_count += item.WarehousingCount * drugMedical.MinNumber
  3295. // }
  3296. //
  3297. // if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3298. //
  3299. // in_count += item.WarehousingCount
  3300. // }
  3301. //
  3302. // if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3303. //
  3304. // in_count += item.WarehousingCount
  3305. // }
  3306. //
  3307. // }
  3308. // }
  3309. //
  3310. // if len(hisDocInfoList) > 0 {
  3311. //
  3312. // for _, item := range hisDocInfoList {
  3313. // if item.PrescribingNumberUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3314. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3315. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3316. //
  3317. // in_prescription_number_total += prescribingNumberSevenTy * drug.MinNumber
  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. // if item.PrescribingNumberUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3327. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3328. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3329. // in_prescription_number_total += prescribingNumberSevenTy
  3330. // }
  3331. // }
  3332. // }
  3333. // //
  3334. // //fmt.Println("no_user_total------------------------------", no_user_total)
  3335. // //fmt.Println("in_prescription_number_total---------------------------", in_prescription_number_total)
  3336. // //fmt.Println("in_count----------------------------------", in_count)
  3337. //
  3338. // //如果已经开过的医嘱 加上未开的医嘱数量 大于 入库总数量则提示库存不足
  3339. // if no_user_total+in_prescription_number_total > in_count {
  3340. // tx.Rollback()
  3341. // c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3342. // return
  3343. // }
  3344. //
  3345. //}
  3346. //查询该药品所有入库数量
  3347. }
  3348. if s.ID > 0 {
  3349. //查询改药品是否已经停用
  3350. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3351. if base.ID > 0 {
  3352. tx.Rollback()
  3353. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3354. return
  3355. }
  3356. }
  3357. }
  3358. //fmt.Println("药品名称----------------------", drug.DrugName)
  3359. //fmt.Println("药品名称----------------------", drug.IsUse)
  3360. //fmt.Println("drug_iiiiiiiiiiiiiiiiiiii", drug.ID)
  3361. //fmt.Println("is_user_total-------------------------", is_user_total)
  3362. //fmt.Println("no_user_total-------------------------", no_user_total)
  3363. //fmt.Println("drug.IsUse---------------", drug.IsUse)
  3364. //fmt.Println("00000000000000000000", s.UserOrgId)
  3365. if is_user_total != no_user_total {
  3366. //出库
  3367. //针对御享天源
  3368. if drug.IsUse == 1 && s.UserOrgId == 10635 {
  3369. //查询改药品是否已经停用
  3370. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3371. if base.ID > 0 {
  3372. tx.Rollback()
  3373. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3374. return
  3375. }
  3376. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3377. if drugMedical.SumCount == 0 {
  3378. tx.Rollback()
  3379. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3380. return
  3381. }
  3382. creater := adminInfo.AdminUser.Id
  3383. newadviceInfo := &models.HisDoctorAdviceInfo{
  3384. ID: s.ID,
  3385. UserOrgId: s.UserOrgId,
  3386. PatientId: s.PatientId,
  3387. HisPatientId: s.HisPatientId,
  3388. AdviceType: s.AdviceType,
  3389. AdviceDate: s.AdviceDate,
  3390. StartTime: s.StartTime,
  3391. AdviceName: s.AdviceName,
  3392. AdviceDesc: s.AdviceDesc,
  3393. ReminderDate: s.ReminderDate,
  3394. SingleDose: s.SingleDose,
  3395. SingleDoseUnit: s.SingleDoseUnit,
  3396. PrescribingNumber: s.PrescribingNumber,
  3397. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3398. DeliveryWay: s.DeliveryWay,
  3399. ExecutionFrequency: s.ExecutionFrequency,
  3400. AdviceDoctor: s.AdviceDoctor,
  3401. Status: s.Status,
  3402. CreatedTime: s.CreatedTime,
  3403. UpdatedTime: s.UpdatedTime,
  3404. AdviceAffirm: s.AdviceAffirm,
  3405. Remark: s.Remark,
  3406. StopTime: s.StopTime,
  3407. StopReason: s.StopReason,
  3408. StopDoctor: s.StopDoctor,
  3409. StopState: s.StopState,
  3410. ParentId: s.ParentId,
  3411. ExecutionTime: s.ExecutionTime,
  3412. ExecutionStaff: s.ExecutionStaff,
  3413. ExecutionState: s.ExecutionState,
  3414. Checker: s.Checker,
  3415. RecordDate: s.RecordDate,
  3416. DialysisOrderId: s.DialysisOrderId,
  3417. CheckTime: s.CheckTime,
  3418. CheckState: s.CheckState,
  3419. DrugSpec: s.DrugSpec,
  3420. DrugSpecUnit: s.DrugSpecUnit,
  3421. Groupno: s.Groupno,
  3422. RemindType: s.RemindType,
  3423. FrequencyType: s.FrequencyType,
  3424. DayCount: s.DayCount,
  3425. WeekDay: s.WeekDay,
  3426. TemplateId: s.TemplateId,
  3427. Modifier: s.Modifier,
  3428. DrugId: s.DrugId,
  3429. Price: s.Price,
  3430. PrescriptionId: s.PrescriptionId,
  3431. MedListCodg: s.MedListCodg,
  3432. FeedetlSn: s.FeedetlSn,
  3433. Day: s.DayCount,
  3434. ChildDoctorAdvice: nil,
  3435. Drug: models.Drug{},
  3436. Diagnosis: s.Diagnosis,
  3437. Way: s.Way,
  3438. HospApprFlag: s.HospApprFlag,
  3439. LmtUsedFlag: s.LmtUsedFlag,
  3440. HisOrderInfo: models.HisOrderInfo{},
  3441. IsMedicine: s.IsMedicine,
  3442. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3443. Child: nil,
  3444. IsSettle: s.IsSettle,
  3445. IsMobile: s.IsMobile,
  3446. IsSelfDrug: s.IsSelfDrug,
  3447. DrugWayCount: s.DrugWayCount,
  3448. }
  3449. var history_count int64
  3450. var local_count int64
  3451. //查找已经开过的医嘱信息
  3452. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3453. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3454. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3455. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3456. local_count += prescribingNumberSevenTy * drug.MinNumber
  3457. }
  3458. if s.PrescribingNumberUnit == drug.MinUnit && 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 s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3464. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3465. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3466. local_count += prescribingNumberSevenTy
  3467. }
  3468. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3469. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3470. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3471. history_count += prescribingNumberSevenTy * drug.MinNumber
  3472. }
  3473. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && 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. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3479. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3480. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3481. history_count += prescribingNumberSevenTy
  3482. }
  3483. //fmt.Println("local_count---------------", local_count)
  3484. //fmt.Println("history_count---------------", history_count)
  3485. //如果当前出库数量大于历史出库数量则需要出库
  3486. if local_count > history_count {
  3487. //按最小单位出库
  3488. var cha_count = local_count - history_count
  3489. newadviceInfo.PrescribingNumber = float64(cha_count)
  3490. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3491. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3492. }
  3493. //如果当前出库数量小于历史出库数量则需要退库
  3494. if local_count < history_count {
  3495. var cha_count = history_count - local_count
  3496. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3497. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3498. }
  3499. if local_count == history_count {
  3500. if is_user_total == 0 {
  3501. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3502. }
  3503. }
  3504. }
  3505. if drug.IsUse == 2 {
  3506. creater := adminInfo.AdminUser.Id
  3507. newadviceInfo := &models.HisDoctorAdviceInfo{
  3508. ID: s.ID,
  3509. UserOrgId: s.UserOrgId,
  3510. PatientId: s.PatientId,
  3511. HisPatientId: s.HisPatientId,
  3512. AdviceType: s.AdviceType,
  3513. AdviceDate: s.AdviceDate,
  3514. StartTime: s.StartTime,
  3515. AdviceName: s.AdviceName,
  3516. AdviceDesc: s.AdviceDesc,
  3517. ReminderDate: s.ReminderDate,
  3518. SingleDose: s.SingleDose,
  3519. SingleDoseUnit: s.SingleDoseUnit,
  3520. PrescribingNumber: s.PrescribingNumber,
  3521. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3522. DeliveryWay: s.DeliveryWay,
  3523. ExecutionFrequency: s.ExecutionFrequency,
  3524. AdviceDoctor: s.AdviceDoctor,
  3525. Status: s.Status,
  3526. CreatedTime: s.CreatedTime,
  3527. UpdatedTime: s.UpdatedTime,
  3528. AdviceAffirm: s.AdviceAffirm,
  3529. Remark: s.Remark,
  3530. StopTime: s.StopTime,
  3531. StopReason: s.StopReason,
  3532. StopDoctor: s.StopDoctor,
  3533. StopState: s.StopState,
  3534. ParentId: s.ParentId,
  3535. ExecutionTime: s.ExecutionTime,
  3536. ExecutionStaff: s.ExecutionStaff,
  3537. ExecutionState: s.ExecutionState,
  3538. Checker: s.Checker,
  3539. RecordDate: s.RecordDate,
  3540. DialysisOrderId: s.DialysisOrderId,
  3541. CheckTime: s.CheckTime,
  3542. CheckState: s.CheckState,
  3543. DrugSpec: s.DrugSpec,
  3544. DrugSpecUnit: s.DrugSpecUnit,
  3545. Groupno: s.Groupno,
  3546. RemindType: s.RemindType,
  3547. FrequencyType: s.FrequencyType,
  3548. DayCount: s.DayCount,
  3549. WeekDay: s.WeekDay,
  3550. TemplateId: s.TemplateId,
  3551. Modifier: s.Modifier,
  3552. DrugId: s.DrugId,
  3553. Price: s.Price,
  3554. PrescriptionId: s.PrescriptionId,
  3555. MedListCodg: s.MedListCodg,
  3556. FeedetlSn: s.FeedetlSn,
  3557. Day: s.DayCount,
  3558. ChildDoctorAdvice: nil,
  3559. Drug: models.Drug{},
  3560. Diagnosis: s.Diagnosis,
  3561. Way: s.Way,
  3562. HospApprFlag: s.HospApprFlag,
  3563. LmtUsedFlag: s.LmtUsedFlag,
  3564. HisOrderInfo: models.HisOrderInfo{},
  3565. IsMedicine: s.IsMedicine,
  3566. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3567. Child: nil,
  3568. IsSettle: s.IsSettle,
  3569. IsMobile: s.IsMobile,
  3570. IsSelfDrug: s.IsSelfDrug,
  3571. DrugWayCount: s.DrugWayCount,
  3572. }
  3573. var history_count int64
  3574. var local_count int64
  3575. //查找已经开过的医嘱信息
  3576. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3577. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3578. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3579. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3580. local_count += prescribingNumberSevenTy * drug.MinNumber
  3581. }
  3582. if s.PrescribingNumberUnit == drug.MinUnit && 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 s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3588. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3589. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3590. local_count += prescribingNumberSevenTy
  3591. }
  3592. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3593. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3594. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3595. history_count += prescribingNumberSevenTy * drug.MinNumber
  3596. }
  3597. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && 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. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3603. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3604. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3605. history_count += prescribingNumberSevenTy
  3606. }
  3607. fmt.Println("local_count---------------", local_count)
  3608. fmt.Println("history_count---------------", history_count)
  3609. //如果当前出库数量大于历史出库数量则需要出库
  3610. if local_count > history_count {
  3611. //按最小单位出库
  3612. var cha_count = local_count - history_count
  3613. newadviceInfo.PrescribingNumber = float64(cha_count)
  3614. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3615. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3616. }
  3617. //如果当前出库数量小于历史出库数量则需要退库
  3618. if local_count < history_count {
  3619. var cha_count = history_count - local_count
  3620. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3621. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3622. }
  3623. if local_count == history_count {
  3624. if is_user_total == 0 {
  3625. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3626. }
  3627. }
  3628. }
  3629. //更新字典里面的库存
  3630. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3631. var sum_count int64
  3632. for _, its := range stockInfo {
  3633. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3634. if its.MaxUnit == baseDrug.MaxUnit {
  3635. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3636. }
  3637. sum_count += its.StockMaxNumber + its.StockMinNumber
  3638. }
  3639. //更新基础库存
  3640. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3641. //剩余库存
  3642. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3643. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3644. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3645. //创建医嘱
  3646. service.CreateHisDoctorAdviceOne(&s, tx)
  3647. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3648. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3649. if len(outInfoTwo) > 0 {
  3650. for _, item := range outInfoTwo {
  3651. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3652. }
  3653. }
  3654. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3655. if len(drugAutoDetail) > 0 {
  3656. for _, item := range drugAutoDetail {
  3657. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3658. }
  3659. }
  3660. }
  3661. }
  3662. }
  3663. //记录日志
  3664. byterequest, _ := json.Marshal(s)
  3665. adviceLog := models.XtDoctorAdviceLog{
  3666. UserOrgId: s.UserOrgId,
  3667. PatientId: s.PatientId,
  3668. AdminUserId: adminInfo.AdminUser.Id,
  3669. Module: 1,
  3670. ErrLog: string(byterequest),
  3671. Status: 1,
  3672. Ctime: time.Now().Unix(),
  3673. Mtime: 0,
  3674. Source: "电脑端新建his医嘱",
  3675. RecordDate: s.AdviceDate,
  3676. }
  3677. service.CreateDoctorAdviceLog(adviceLog)
  3678. //存储切片中
  3679. adviceList = append(adviceList, s)
  3680. redis := service.RedisClient()
  3681. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3682. redis.Set(key, "", time.Second)
  3683. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3684. redis.Set(keyOne, "", time.Second)
  3685. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3686. redis.Set(keySeven, "", time.Second)
  3687. var randNum int
  3688. randNum = rand.Intn(1000) + 1000
  3689. //timestamp := time.Now().Unix()
  3690. //tempTime := time.Unix(timestamp, 0)
  3691. //timeFormat := tempTime.Format("20060102150405")
  3692. s.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3693. //赤峰
  3694. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3695. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3696. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3697. if info.RetailPrice > 0 {
  3698. if s.DeliveryWay == "口服" {
  3699. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3700. s.Price = drug.RetailPrice
  3701. }
  3702. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3703. s.Price = info.RetailPrice
  3704. }
  3705. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3706. s.Price = info.RetailPrice
  3707. }
  3708. }
  3709. }
  3710. }
  3711. service.CreateHisDoctorAdviceOne(&s, tx)
  3712. tx.Commit()
  3713. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3714. redis.Set(keySix, "", time.Second)
  3715. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3716. redis.Set(keyFive, "", time.Second)
  3717. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3718. redis.Set(keyEight, "", time.Second)
  3719. defer redis.Close()
  3720. }
  3721. }
  3722. }
  3723. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3724. projects := items["project"].([]interface{})
  3725. if len(projects) > 0 {
  3726. for _, project := range projects {
  3727. tx := db.Begin()
  3728. // 在函数结束时处理事务回滚
  3729. defer func() {
  3730. if r := recover(); r != nil {
  3731. tx.Rollback()
  3732. }
  3733. }()
  3734. var p models.HisPrescriptionProject
  3735. p.PrescriptionId = tempPrescription.ID
  3736. p.PatientId = patient_id
  3737. p.RecordDate = theTime3.Unix()
  3738. p.Doctor = doctor_id
  3739. p.UserOrgId = adminInfo.CurrentOrgId
  3740. p.HisPatientId = his_patient_id
  3741. p.Status = 1
  3742. p.StartTime = pTime
  3743. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3744. if errcode > 0 {
  3745. tx.Rollback()
  3746. c.ServeFailJSONWithSGJErrorCode(errcode)
  3747. return
  3748. }
  3749. if p.ID == 0 {
  3750. p.IsOut = 2
  3751. }
  3752. if p.ID > 0 {
  3753. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3754. p.IsOut = projectDetail.IsOut
  3755. }
  3756. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3757. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3758. if p.Type == 3 {
  3759. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3760. if p.Price != lastWarehouse.PackingPrice {
  3761. p.Price = lastWarehouse.PackingPrice
  3762. }
  3763. if p.Price == 0 {
  3764. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3765. p.Price = lastWarehouseTwo.PackingPrice
  3766. }
  3767. if p.Unit == "" {
  3768. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3769. p.Unit = goodInfoOne.PackingUnit
  3770. }
  3771. }
  3772. }
  3773. if adminInfo.CurrentOrgId != 10206 {
  3774. if p.Type == 3 {
  3775. //判断耗材库存充不充足
  3776. if p.ID == 0 {
  3777. //查询该耗材是否停用
  3778. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3779. //表示该耗材已经停用,不能保存
  3780. if goodInfoSeven.ID == 0 {
  3781. tx.Rollback()
  3782. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3783. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3784. return
  3785. }
  3786. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3787. if goodInfoOne.SumCount == 0 {
  3788. tx.Rollback()
  3789. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3790. return
  3791. }
  3792. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3793. if len(goodListOne) == 0 {
  3794. tx.Rollback()
  3795. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3796. return
  3797. }
  3798. }
  3799. if p.ID > 0 {
  3800. //查询该耗材是否停用
  3801. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3802. //表示该耗材已经停用,不能保存
  3803. if goodInfoSeven.ID == 0 {
  3804. tx.Rollback()
  3805. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3806. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3807. return
  3808. }
  3809. //查询该耗材今日是否已经出过库
  3810. goodOutList, _ := service.GetGoodWareHouseOutInfoByGood(p.ProjectId, p.RecordDate, p.UserOrgId)
  3811. var his_count int64
  3812. if len(goodOutList) > 0 {
  3813. for _, item := range goodOutList {
  3814. his_count += item.Count
  3815. }
  3816. }
  3817. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3818. //如果当前的处方数量大于 历史出库数量 要判断库存够不够
  3819. if nowCount > his_count {
  3820. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3821. if goodInfoOne.SumCount == 0 {
  3822. tx.Rollback()
  3823. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3824. return
  3825. }
  3826. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3827. if len(goodListOne) == 0 {
  3828. tx.Rollback()
  3829. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3830. return
  3831. }
  3832. }
  3833. if len(goodOutList) == 0 {
  3834. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3835. if goodInfoOne.SumCount == 0 {
  3836. tx.Rollback()
  3837. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3838. return
  3839. }
  3840. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3841. if len(goodListOne) == 0 {
  3842. tx.Rollback()
  3843. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3844. return
  3845. }
  3846. }
  3847. }
  3848. }
  3849. }
  3850. //查询保存耗材出库开关是否打开
  3851. if p.PatientId != 30038 {
  3852. //用机构ID区分
  3853. if adminInfo.CurrentOrgId != 9671 {
  3854. if goodOutConfig.IsOpen == 1 {
  3855. //耗材出库
  3856. if p.Type == 3 {
  3857. //对比当前数据和历史出库数据
  3858. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3859. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3860. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3861. ////针对康德
  3862. //if p.UserOrgId == 10164 || p.UserOrgId == 10402 {
  3863. //
  3864. // //查询耗材的总入库数量
  3865. // warehouseInfo, _ := service.GetAllWarehouseInfo(p.ProjectId, adminInfo.CurrentOrgId)
  3866. //
  3867. // //查询该耗材的总出库数量
  3868. // prescriptionGood, _ := service.GetHisPrescriptionByGoodId(p.ProjectId, adminInfo.CurrentOrgId)
  3869. //
  3870. // var all_good_count int64
  3871. //
  3872. // var prescription_count int64
  3873. // if len(warehouseInfo) > 0 {
  3874. //
  3875. // for _, item := range warehouseInfo {
  3876. // all_good_count += item.WarehousingCount
  3877. // }
  3878. // }
  3879. // if len(prescriptionGood) > 0 {
  3880. // for _, item := range prescriptionGood {
  3881. //
  3882. // hisCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3883. // prescription_count += hisCount
  3884. // }
  3885. // }
  3886. //
  3887. // //fmt.Println("prescription_count-------------------------", prescription_count)
  3888. // //fmt.Println("nowCount-------------------------", nowCount)
  3889. // //fmt.Println("all_good_count-------------------------", all_good_count)
  3890. //
  3891. // if prescription_count+nowCount > all_good_count {
  3892. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3893. // tx.Rollback()
  3894. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3895. // return
  3896. // }
  3897. //}
  3898. fmt.Println("nowCount222=================", nowCount)
  3899. fmt.Println("historyCount-333----------------", historyCount)
  3900. //如果当前处方数量大于历史数据,则需要出库
  3901. if nowCount > historyCount {
  3902. var cha_count int64
  3903. cha_count = nowCount - historyCount
  3904. timeStr := time.Now().Format("2006-01-02")
  3905. timeArr := strings.Split(timeStr, "-")
  3906. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3907. total = total + 1
  3908. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3909. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3910. number = number + total
  3911. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3912. operation_time := time.Now().Unix()
  3913. creater := c.GetAdminUserInfo().AdminUser.Id
  3914. recordDateStr := time.Now().Format("2006-01-02")
  3915. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3916. nowtime := recordDate.Unix()
  3917. warehouseOut := models.WarehouseOut{
  3918. WarehouseOutOrderNumber: warehousing_out_order,
  3919. OperationTime: operation_time,
  3920. OrgId: adminInfo.CurrentOrgId,
  3921. Creater: creater,
  3922. Ctime: time.Now().Unix(),
  3923. Status: 1,
  3924. WarehouseOutTime: nowtime,
  3925. Type: 1,
  3926. StorehouseId: storeConfig.StorehouseOutInfo,
  3927. IsCheck: 1,
  3928. IsSys: 1,
  3929. }
  3930. //查询是否生成出库单
  3931. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3932. if out.ID == 0 {
  3933. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3934. }
  3935. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3936. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3937. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3938. dialyPrepareOne := models.DialysisBeforePrepare{
  3939. GoodTypeId: goodObj.GoodTypeId,
  3940. GoodId: p.ProjectId,
  3941. PatientId: p.PatientId,
  3942. RecordDate: p.RecordDate,
  3943. UserOrgId: adminInfo.CurrentOrgId,
  3944. Count: cha_count,
  3945. Ctime: time.Now().Unix(),
  3946. Creater: creater,
  3947. Status: 1,
  3948. StorehouseId: houseConfig.StorehouseOutInfo,
  3949. ProjectId: p.ID,
  3950. }
  3951. //出库
  3952. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3953. }
  3954. //如果当前处方数量小于历史数据,怎需要退库
  3955. if nowCount < historyCount {
  3956. var cha_count int64
  3957. cha_count = historyCount - nowCount
  3958. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3959. creater := c.GetAdminUserInfo().AdminUser.Id
  3960. newPrescriptionProject := &models.HisPrescriptionProject{
  3961. ID: p.ID,
  3962. ProjectId: p.ProjectId,
  3963. Price: p.Price,
  3964. UserOrgId: p.UserOrgId,
  3965. Status: 1,
  3966. Ctime: time.Now().Unix(),
  3967. Mtime: time.Now().Unix(),
  3968. PatientId: p.PatientId,
  3969. HisPatientId: p.HisPatientId,
  3970. RecordDate: p.RecordDate,
  3971. PrescriptionId: p.PrescriptionId,
  3972. Count: p.Count,
  3973. FeedetlSn: p.FeedetlSn,
  3974. MedListCodg: p.MedListCodg,
  3975. SingleDose: p.SingleDose,
  3976. DeliveryWay: p.DeliveryWay,
  3977. ExecutionFrequency: p.ExecutionFrequency,
  3978. Day: p.Day,
  3979. HisProject: models.HisProject{},
  3980. GoodInfo: models.GoodInfo{},
  3981. Remark: p.Remark,
  3982. Unit: p.Unit,
  3983. Type: p.Type,
  3984. Doctor: p.Doctor,
  3985. ExecutionTime: p.ExecutionTime,
  3986. ExecutionStaff: p.ExecutionStaff,
  3987. ExecutionState: p.ExecutionState,
  3988. CheckTime: p.CheckTime,
  3989. CheckState: p.CheckState,
  3990. Checker: p.Checker,
  3991. StartTime: p.StartTime,
  3992. TeamId: p.TeamId,
  3993. XtHisProjectTeam: models.XtHisProjectTeam{},
  3994. FrequencyType: p.FrequencyType,
  3995. DayCount: p.DayCount,
  3996. WeekDay: p.WeekDay,
  3997. IsCheckTeam: p.IsCheckTeam,
  3998. HisOrderInfo: models.HisOrderInfo{},
  3999. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4000. IsOut: p.IsOut,
  4001. YbSyncStatus: p.YbSyncStatus,
  4002. }
  4003. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4004. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4005. }
  4006. if nowCount == historyCount {
  4007. if historyCount == 0 {
  4008. recordDateStr := time.Now().Format("2006-01-02")
  4009. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4010. nowtime := recordDate.Unix()
  4011. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4012. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4013. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4014. creater := c.GetAdminUserInfo().AdminUser.Id
  4015. dialyPrepareOne := models.DialysisBeforePrepare{
  4016. GoodTypeId: goodObj.GoodTypeId,
  4017. GoodId: p.ProjectId,
  4018. PatientId: p.PatientId,
  4019. RecordDate: p.RecordDate,
  4020. UserOrgId: adminInfo.CurrentOrgId,
  4021. Count: nowCount,
  4022. Ctime: time.Now().Unix(),
  4023. Creater: creater,
  4024. Status: 1,
  4025. StorehouseId: houseConfig.StorehouseOutInfo,
  4026. ProjectId: p.ID,
  4027. }
  4028. //出库
  4029. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4030. }
  4031. }
  4032. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4033. //查询历史出库数据
  4034. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4035. var out_count_five int64
  4036. for _, item := range flowGood {
  4037. out_count_five += item.Count
  4038. }
  4039. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4040. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4041. if out_count_five != parseIntCount {
  4042. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4043. detail := models.AutomaticReduceDetail{
  4044. WarehouseOutId: 0,
  4045. WarehouseOutOrderNumber: "",
  4046. PatientId: p.PatientId,
  4047. Ctime: time.Now().Unix(),
  4048. Mtime: 0,
  4049. Status: 1,
  4050. RecordTime: p.RecordDate,
  4051. OrgId: p.UserOrgId,
  4052. GoodId: p.ProjectId,
  4053. GoodTypeId: 0,
  4054. Count: parseIntCount,
  4055. Type: 0,
  4056. ProjectId: lastHisProject.ID,
  4057. StorehouseId: 0,
  4058. }
  4059. service.CreateNewAutoDetail(detail, tx)
  4060. }
  4061. // //查询耗材最后一次出库记录
  4062. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4063. // //查询默认出库仓库库存
  4064. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4065. // if len(wareOut) > 0 {
  4066. //
  4067. // for _, it := range wareOut {
  4068. // //回退库存
  4069. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4070. //
  4071. // //删除出库记录
  4072. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4073. //
  4074. // }
  4075. // }
  4076. //
  4077. // timeStr := time.Now().Format("2006-01-02")
  4078. // timeArr := strings.Split(timeStr, "-")
  4079. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4080. //
  4081. // total = total + 1
  4082. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4083. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4084. // number = number + total
  4085. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4086. //
  4087. // operation_time := time.Now().Unix()
  4088. // creater := c.GetAdminUserInfo().AdminUser.Id
  4089. //
  4090. // recordDateStr := time.Now().Format("2006-01-02")
  4091. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4092. // nowtime := recordDate.Unix()
  4093. // warehouseOut := models.WarehouseOut{
  4094. // WarehouseOutOrderNumber: warehousing_out_order,
  4095. // OperationTime: operation_time,
  4096. // OrgId: adminInfo.CurrentOrgId,
  4097. // Creater: creater,
  4098. // Ctime: time.Now().Unix(),
  4099. // Status: 1,
  4100. // WarehouseOutTime: nowtime,
  4101. // Type: 1,
  4102. // StorehouseId: storeConfig.StorehouseOutInfo,
  4103. // IsCheck: 1,
  4104. // IsSys: 1,
  4105. // }
  4106. // //查询是否生成出库单
  4107. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4108. // if out.ID == 0 {
  4109. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4110. // }
  4111. //
  4112. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4113. //
  4114. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4115. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4116. //
  4117. // dialyPrepareOne := models.DialysisBeforePrepare{
  4118. // GoodTypeId: goodObj.GoodTypeId,
  4119. // GoodId: p.ProjectId,
  4120. // PatientId: p.PatientId,
  4121. // RecordDate: p.RecordDate,
  4122. // UserOrgId: adminInfo.CurrentOrgId,
  4123. // Count: parseIntCount,
  4124. // Ctime: time.Now().Unix(),
  4125. // Creater: creater,
  4126. // Status: 1,
  4127. // StorehouseId: houseConfig.StorehouseOutInfo,
  4128. // ProjectId: lastHisProject.ID,
  4129. // }
  4130. // //判断是否是零用耗材(非零用)
  4131. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4132. //
  4133. // //查询历史出库数据
  4134. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4135. // var out_count int64
  4136. // for _, item := range flowGood {
  4137. // out_count += item.Count
  4138. // }
  4139. // //如果历史数和当前数据不想等才进行退库出库
  4140. // if out_count != parseIntCount {
  4141. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4142. //
  4143. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4144. // detail := models.AutomaticReduceDetail{
  4145. // WarehouseOutId: 0,
  4146. // WarehouseOutOrderNumber: "",
  4147. // PatientId: p.PatientId,
  4148. // Ctime: time.Now().Unix(),
  4149. // Mtime: 0,
  4150. // Status: 1,
  4151. // RecordTime: p.RecordDate,
  4152. // OrgId: p.UserOrgId,
  4153. // GoodId: p.ProjectId,
  4154. // GoodTypeId: 0,
  4155. // Count: parseIntCount,
  4156. // Type: 0,
  4157. // ProjectId: lastHisProject.ID,
  4158. // StorehouseId: 0,
  4159. // }
  4160. //
  4161. // service.CreateNewAutoDetail(detail, tx)
  4162. //
  4163. // //查询剩余库存
  4164. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4165. // var sum_count int64
  4166. // for _, item := range goodList {
  4167. // sum_count += item.StockCount
  4168. // }
  4169. //
  4170. // //更新剩余库存
  4171. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4172. //
  4173. // //耗材
  4174. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4175. //
  4176. // }
  4177. // //判断是否是零用耗材(零用但是是出库耗材)
  4178. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4179. //
  4180. // //查询历史出库数据
  4181. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4182. // var out_count int64
  4183. // for _, item := range flowGood {
  4184. // out_count += item.Count
  4185. // }
  4186. // //如果历史数和当前数据不想等才进行退库出库
  4187. // if out_count != parseIntCount {
  4188. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4189. //
  4190. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4191. // detail := models.AutomaticReduceDetail{
  4192. // WarehouseOutId: 0,
  4193. // WarehouseOutOrderNumber: "",
  4194. // PatientId: p.PatientId,
  4195. // Ctime: time.Now().Unix(),
  4196. // Mtime: 0,
  4197. // Status: 1,
  4198. // RecordTime: p.RecordDate,
  4199. // OrgId: p.UserOrgId,
  4200. // GoodId: p.ProjectId,
  4201. // GoodTypeId: 0,
  4202. // Count: parseIntCount,
  4203. // Type: 0,
  4204. // ProjectId: p.ID,
  4205. // StorehouseId: 0,
  4206. // }
  4207. //
  4208. // service.CreateNewAutoDetail(detail, tx)
  4209. //
  4210. // //查询剩余库存
  4211. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4212. // var sum_count int64
  4213. // for _, item := range goodList {
  4214. // sum_count += item.StockCount
  4215. // }
  4216. //
  4217. // //更新剩余库存
  4218. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4219. //
  4220. // //耗材
  4221. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4222. // }
  4223. //
  4224. // }
  4225. //
  4226. // }
  4227. //
  4228. //}
  4229. //记录日志
  4230. byterequest, _ := json.Marshal(p)
  4231. adviceLog := models.XtDoctorAdviceLog{
  4232. UserOrgId: p.UserOrgId,
  4233. PatientId: p.PatientId,
  4234. AdminUserId: adminInfo.AdminUser.Id,
  4235. Module: 1,
  4236. ErrLog: string(byterequest),
  4237. Status: 1,
  4238. Ctime: time.Now().Unix(),
  4239. Mtime: 0,
  4240. Source: "电脑端新建his项目",
  4241. RecordDate: p.RecordDate,
  4242. }
  4243. service.CreateDoctorAdviceLog(adviceLog)
  4244. projectList = append(projectList, p)
  4245. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4246. //新增或者编辑项目,修改对应的标签数据
  4247. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4248. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4249. var label models.HisLabelPrintInfo
  4250. project, _ := service.GetProjectDetail(p.ProjectId)
  4251. if project.CostClassify == 3 { //类别为检验检查
  4252. if p.TeamId > 0 { //检验检查组套
  4253. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4254. if tempLabel.ID == 0 {
  4255. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4256. label.Number = tempPrescription.PrescriptionNumber
  4257. label.ProjectId = project.ID
  4258. label.Status = 1
  4259. label.IsPrint = 2
  4260. label.DoctorId = info.DoctorId
  4261. label.UserOrgId = p.UserOrgId
  4262. label.PatientId = patient_id
  4263. label.RecordDate = recordDateTime
  4264. label.Ctime = time.Now().Unix()
  4265. label.Mtime = time.Now().Unix()
  4266. label.ItemId = p.TeamId
  4267. label.FeedetlSn = p.FeedetlSn
  4268. label.PProjectId = p.ID
  4269. label.ProjectName = team.ProjectTeam
  4270. label.PatientName = patient.Name
  4271. service.CreateNewHisLabelRecord(&label, tx)
  4272. }
  4273. } else { //单条检验检查项目
  4274. label.Number = tempPrescription.PrescriptionNumber
  4275. label.ProjectId = project.ID
  4276. label.Status = 1
  4277. label.DoctorId = info.DoctorId
  4278. label.UserOrgId = p.UserOrgId
  4279. label.PatientId = patient_id
  4280. label.RecordDate = recordDateTime
  4281. label.IsPrint = 2
  4282. label.Ctime = time.Now().Unix()
  4283. label.Mtime = time.Now().Unix()
  4284. label.FeedetlSn = p.FeedetlSn
  4285. label.PProjectId = p.ID
  4286. label.ItemId = p.TeamId
  4287. label.ProjectName = project.ProjectName
  4288. label.PatientName = patient.Name
  4289. service.CreateNewHisLabelRecord(&label, tx)
  4290. }
  4291. }
  4292. }
  4293. }
  4294. }
  4295. }
  4296. }
  4297. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  4298. //
  4299. // //耗材出库
  4300. // if p.Type == 3 {
  4301. //
  4302. // //对比当前数据和历史出库数据
  4303. //
  4304. // historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  4305. //
  4306. // historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  4307. //
  4308. // nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4309. //
  4310. // //如果当前处方数量大于历史数据,则需要出库
  4311. // if nowCount > historyCount {
  4312. //
  4313. // var cha_count int64
  4314. // cha_count = nowCount - historyCount
  4315. //
  4316. // timeStr := time.Now().Format("2006-01-02")
  4317. // timeArr := strings.Split(timeStr, "-")
  4318. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4319. //
  4320. // total = total + 1
  4321. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4322. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4323. // number = number + total
  4324. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4325. //
  4326. // operation_time := time.Now().Unix()
  4327. // creater := c.GetAdminUserInfo().AdminUser.Id
  4328. //
  4329. // recordDateStr := time.Now().Format("2006-01-02")
  4330. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4331. // nowtime := recordDate.Unix()
  4332. // warehouseOut := models.WarehouseOut{
  4333. // WarehouseOutOrderNumber: warehousing_out_order,
  4334. // OperationTime: operation_time,
  4335. // OrgId: adminInfo.CurrentOrgId,
  4336. // Creater: creater,
  4337. // Ctime: time.Now().Unix(),
  4338. // Status: 1,
  4339. // WarehouseOutTime: nowtime,
  4340. // Type: 1,
  4341. // StorehouseId: storeConfig.StorehouseOutInfo,
  4342. // IsCheck: 1,
  4343. // IsSys: 1,
  4344. // }
  4345. // //查询是否生成出库单
  4346. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4347. // if out.ID == 0 {
  4348. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4349. // }
  4350. //
  4351. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4352. //
  4353. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4354. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4355. //
  4356. // dialyPrepareOne := models.DialysisBeforePrepare{
  4357. // GoodTypeId: goodObj.GoodTypeId,
  4358. // GoodId: p.ProjectId,
  4359. // PatientId: p.PatientId,
  4360. // RecordDate: p.RecordDate,
  4361. // UserOrgId: adminInfo.CurrentOrgId,
  4362. // Count: cha_count,
  4363. // Ctime: time.Now().Unix(),
  4364. // Creater: creater,
  4365. // Status: 1,
  4366. // StorehouseId: houseConfig.StorehouseOutInfo,
  4367. // ProjectId: p.ID,
  4368. // }
  4369. // //出库
  4370. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4371. //
  4372. // }
  4373. //
  4374. // //如果当前处方数量小于历史数据,怎需要退库
  4375. // if nowCount < historyCount {
  4376. //
  4377. // var cha_count int64
  4378. // cha_count = historyCount - nowCount
  4379. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4380. // creater := c.GetAdminUserInfo().AdminUser.Id
  4381. //
  4382. // newPrescriptionProject := &models.HisPrescriptionProject{
  4383. // ID: p.ID,
  4384. // ProjectId: p.ProjectId,
  4385. // Price: p.Price,
  4386. // UserOrgId: p.UserOrgId,
  4387. // Status: 1,
  4388. // Ctime: time.Now().Unix(),
  4389. // Mtime: time.Now().Unix(),
  4390. // PatientId: p.PatientId,
  4391. // HisPatientId: p.HisPatientId,
  4392. // RecordDate: p.RecordDate,
  4393. // PrescriptionId: p.PrescriptionId,
  4394. // Count: p.Count,
  4395. // FeedetlSn: p.FeedetlSn,
  4396. // MedListCodg: p.MedListCodg,
  4397. // SingleDose: p.SingleDose,
  4398. // DeliveryWay: p.DeliveryWay,
  4399. // ExecutionFrequency: p.ExecutionFrequency,
  4400. // Day: p.Day,
  4401. // HisProject: models.HisProject{},
  4402. // GoodInfo: models.GoodInfo{},
  4403. // Remark: p.Remark,
  4404. // Unit: p.Unit,
  4405. // Type: p.Type,
  4406. // Doctor: p.Doctor,
  4407. // ExecutionTime: p.ExecutionTime,
  4408. // ExecutionStaff: p.ExecutionStaff,
  4409. // ExecutionState: p.ExecutionState,
  4410. // CheckTime: p.CheckTime,
  4411. // CheckState: p.CheckState,
  4412. // Checker: p.Checker,
  4413. // StartTime: p.StartTime,
  4414. // TeamId: p.TeamId,
  4415. // XtHisProjectTeam: models.XtHisProjectTeam{},
  4416. // FrequencyType: p.FrequencyType,
  4417. // DayCount: p.DayCount,
  4418. // WeekDay: p.WeekDay,
  4419. // IsCheckTeam: p.IsCheckTeam,
  4420. // HisOrderInfo: models.HisOrderInfo{},
  4421. // ExecutionFrequencyId: p.ExecutionFrequencyId,
  4422. // IsOut: p.IsOut,
  4423. // YbSyncStatus: p.YbSyncStatus,
  4424. // }
  4425. //
  4426. // service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4427. //
  4428. // service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4429. //
  4430. // }
  4431. //
  4432. // if nowCount == historyCount {
  4433. // if historyCount == 0 {
  4434. // recordDateStr := time.Now().Format("2006-01-02")
  4435. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4436. // nowtime := recordDate.Unix()
  4437. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4438. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4439. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4440. // creater := c.GetAdminUserInfo().AdminUser.Id
  4441. // dialyPrepareOne := models.DialysisBeforePrepare{
  4442. // GoodTypeId: goodObj.GoodTypeId,
  4443. // GoodId: p.ProjectId,
  4444. // PatientId: p.PatientId,
  4445. // RecordDate: p.RecordDate,
  4446. // UserOrgId: adminInfo.CurrentOrgId,
  4447. // Count: nowCount,
  4448. // Ctime: time.Now().Unix(),
  4449. // Creater: creater,
  4450. // Status: 1,
  4451. // StorehouseId: houseConfig.StorehouseOutInfo,
  4452. // ProjectId: p.ID,
  4453. // }
  4454. // //出库
  4455. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4456. // }
  4457. // }
  4458. //
  4459. // lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4460. // //查询历史出库数据
  4461. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4462. //
  4463. // var out_count_five int64
  4464. // for _, item := range flowGood {
  4465. // out_count_five += item.Count
  4466. // }
  4467. // parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4468. //
  4469. // //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4470. // if out_count_five != parseIntCount {
  4471. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4472. // detail := models.AutomaticReduceDetail{
  4473. // WarehouseOutId: 0,
  4474. // WarehouseOutOrderNumber: "",
  4475. // PatientId: p.PatientId,
  4476. // Ctime: time.Now().Unix(),
  4477. // Mtime: 0,
  4478. // Status: 1,
  4479. // RecordTime: p.RecordDate,
  4480. // OrgId: p.UserOrgId,
  4481. // GoodId: p.ProjectId,
  4482. // GoodTypeId: 0,
  4483. // Count: parseIntCount,
  4484. // Type: 0,
  4485. // ProjectId: lastHisProject.ID,
  4486. // StorehouseId: 0,
  4487. // }
  4488. //
  4489. // service.CreateNewAutoDetail(detail, tx)
  4490. // }
  4491. // // //查询耗材最后一次出库记录
  4492. // // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4493. // // //查询默认出库仓库库存
  4494. // // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4495. // // if len(wareOut) > 0 {
  4496. // //
  4497. // // for _, it := range wareOut {
  4498. // // //回退库存
  4499. // // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4500. // //
  4501. // // //删除出库记录
  4502. // // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4503. // //
  4504. // // }
  4505. // // }
  4506. // //
  4507. // // timeStr := time.Now().Format("2006-01-02")
  4508. // // timeArr := strings.Split(timeStr, "-")
  4509. // // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4510. // //
  4511. // // total = total + 1
  4512. // // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4513. // // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4514. // // number = number + total
  4515. // // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4516. // //
  4517. // // operation_time := time.Now().Unix()
  4518. // // creater := c.GetAdminUserInfo().AdminUser.Id
  4519. // //
  4520. // // recordDateStr := time.Now().Format("2006-01-02")
  4521. // // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4522. // // nowtime := recordDate.Unix()
  4523. // // warehouseOut := models.WarehouseOut{
  4524. // // WarehouseOutOrderNumber: warehousing_out_order,
  4525. // // OperationTime: operation_time,
  4526. // // OrgId: adminInfo.CurrentOrgId,
  4527. // // Creater: creater,
  4528. // // Ctime: time.Now().Unix(),
  4529. // // Status: 1,
  4530. // // WarehouseOutTime: nowtime,
  4531. // // Type: 1,
  4532. // // StorehouseId: storeConfig.StorehouseOutInfo,
  4533. // // IsCheck: 1,
  4534. // // IsSys: 1,
  4535. // // }
  4536. // // //查询是否生成出库单
  4537. // // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4538. // // if out.ID == 0 {
  4539. // // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4540. // // }
  4541. // //
  4542. // // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4543. // //
  4544. // // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4545. // // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4546. // //
  4547. // // dialyPrepareOne := models.DialysisBeforePrepare{
  4548. // // GoodTypeId: goodObj.GoodTypeId,
  4549. // // GoodId: p.ProjectId,
  4550. // // PatientId: p.PatientId,
  4551. // // RecordDate: p.RecordDate,
  4552. // // UserOrgId: adminInfo.CurrentOrgId,
  4553. // // Count: parseIntCount,
  4554. // // Ctime: time.Now().Unix(),
  4555. // // Creater: creater,
  4556. // // Status: 1,
  4557. // // StorehouseId: houseConfig.StorehouseOutInfo,
  4558. // // ProjectId: lastHisProject.ID,
  4559. // // }
  4560. // // //判断是否是零用耗材(非零用)
  4561. // // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4562. // //
  4563. // // //查询历史出库数据
  4564. // // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4565. // // var out_count int64
  4566. // // for _, item := range flowGood {
  4567. // // out_count += item.Count
  4568. // // }
  4569. // // //如果历史数和当前数据不想等才进行退库出库
  4570. // // if out_count != parseIntCount {
  4571. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4572. // //
  4573. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4574. // // detail := models.AutomaticReduceDetail{
  4575. // // WarehouseOutId: 0,
  4576. // // WarehouseOutOrderNumber: "",
  4577. // // PatientId: p.PatientId,
  4578. // // Ctime: time.Now().Unix(),
  4579. // // Mtime: 0,
  4580. // // Status: 1,
  4581. // // RecordTime: p.RecordDate,
  4582. // // OrgId: p.UserOrgId,
  4583. // // GoodId: p.ProjectId,
  4584. // // GoodTypeId: 0,
  4585. // // Count: parseIntCount,
  4586. // // Type: 0,
  4587. // // ProjectId: lastHisProject.ID,
  4588. // // StorehouseId: 0,
  4589. // // }
  4590. // //
  4591. // // service.CreateNewAutoDetail(detail, tx)
  4592. // //
  4593. // // //查询剩余库存
  4594. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4595. // // var sum_count int64
  4596. // // for _, item := range goodList {
  4597. // // sum_count += item.StockCount
  4598. // // }
  4599. // //
  4600. // // //更新剩余库存
  4601. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4602. // //
  4603. // // //耗材
  4604. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4605. // //
  4606. // // }
  4607. // // //判断是否是零用耗材(零用但是是出库耗材)
  4608. // // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4609. // //
  4610. // // //查询历史出库数据
  4611. // // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4612. // // var out_count int64
  4613. // // for _, item := range flowGood {
  4614. // // out_count += item.Count
  4615. // // }
  4616. // // //如果历史数和当前数据不想等才进行退库出库
  4617. // // if out_count != parseIntCount {
  4618. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4619. // //
  4620. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4621. // // detail := models.AutomaticReduceDetail{
  4622. // // WarehouseOutId: 0,
  4623. // // WarehouseOutOrderNumber: "",
  4624. // // PatientId: p.PatientId,
  4625. // // Ctime: time.Now().Unix(),
  4626. // // Mtime: 0,
  4627. // // Status: 1,
  4628. // // RecordTime: p.RecordDate,
  4629. // // OrgId: p.UserOrgId,
  4630. // // GoodId: p.ProjectId,
  4631. // // GoodTypeId: 0,
  4632. // // Count: parseIntCount,
  4633. // // Type: 0,
  4634. // // ProjectId: p.ID,
  4635. // // StorehouseId: 0,
  4636. // // }
  4637. // //
  4638. // // service.CreateNewAutoDetail(detail, tx)
  4639. // //
  4640. // // //查询剩余库存
  4641. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4642. // // var sum_count int64
  4643. // // for _, item := range goodList {
  4644. // // sum_count += item.StockCount
  4645. // // }
  4646. // //
  4647. // // //更新剩余库存
  4648. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4649. // //
  4650. // // //耗材
  4651. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4652. // // }
  4653. // //
  4654. // // }
  4655. // //
  4656. // // }
  4657. // //
  4658. // //}
  4659. //
  4660. // //记录日志
  4661. // byterequest, _ := json.Marshal(p)
  4662. // adviceLog := models.XtDoctorAdviceLog{
  4663. // UserOrgId: p.UserOrgId,
  4664. // PatientId: p.PatientId,
  4665. // AdminUserId: adminInfo.AdminUser.Id,
  4666. // Module: 1,
  4667. // ErrLog: string(byterequest),
  4668. // Status: 1,
  4669. // Ctime: time.Now().Unix(),
  4670. // Mtime: 0,
  4671. // Source: "电脑端新建his项目",
  4672. // RecordDate: p.RecordDate,
  4673. // }
  4674. // service.CreateDoctorAdviceLog(adviceLog)
  4675. //
  4676. // projectList = append(projectList, p)
  4677. //
  4678. // if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4679. // //新增或者编辑项目,修改对应的标签数据
  4680. // labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4681. // if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4682. // var label models.HisLabelPrintInfo
  4683. // project, _ := service.GetProjectDetail(p.ProjectId)
  4684. // if project.CostClassify == 3 { //类别为检验检查
  4685. // if p.TeamId > 0 { //检验检查组套
  4686. // tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4687. // if tempLabel.ID == 0 {
  4688. // team, _ := service.GetProjectTeamDetail(p.TeamId)
  4689. // label.Number = tempPrescription.PrescriptionNumber
  4690. // label.ProjectId = project.ID
  4691. // label.Status = 1
  4692. // label.IsPrint = 2
  4693. // label.DoctorId = info.DoctorId
  4694. // label.UserOrgId = p.UserOrgId
  4695. // label.PatientId = patient_id
  4696. // label.RecordDate = recordDateTime
  4697. // label.Ctime = time.Now().Unix()
  4698. // label.Mtime = time.Now().Unix()
  4699. // label.ItemId = p.TeamId
  4700. // label.FeedetlSn = p.FeedetlSn
  4701. // label.PProjectId = p.ID
  4702. // label.ProjectName = team.ProjectTeam
  4703. // label.PatientName = patient.Name
  4704. // service.CreateNewHisLabelRecord(&label, tx)
  4705. // }
  4706. // } else { //单条检验检查项目
  4707. // label.Number = tempPrescription.PrescriptionNumber
  4708. // label.ProjectId = project.ID
  4709. // label.Status = 1
  4710. // label.DoctorId = info.DoctorId
  4711. // label.UserOrgId = p.UserOrgId
  4712. // label.PatientId = patient_id
  4713. // label.RecordDate = recordDateTime
  4714. // label.IsPrint = 2
  4715. // label.Ctime = time.Now().Unix()
  4716. // label.Mtime = time.Now().Unix()
  4717. // label.FeedetlSn = p.FeedetlSn
  4718. // label.PProjectId = p.ID
  4719. // label.ItemId = p.TeamId
  4720. // label.ProjectName = project.ProjectName
  4721. // label.PatientName = patient.Name
  4722. // service.CreateNewHisLabelRecord(&label, tx)
  4723. // }
  4724. // }
  4725. // }
  4726. // }
  4727. //
  4728. // }
  4729. //}
  4730. }
  4731. //插入检验数据
  4732. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4733. //新增或者编辑项目,修改对应的标签数据
  4734. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4735. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4736. var label models.HisLabelPrintInfo
  4737. project, _ := service.GetProjectDetail(p.ProjectId)
  4738. if project.CostClassify == 3 { //类别为检验检查
  4739. if p.TeamId > 0 { //检验检查组套
  4740. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4741. if tempLabel.ID == 0 {
  4742. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4743. label.Number = tempPrescription.PrescriptionNumber
  4744. label.ProjectId = project.ID
  4745. label.Status = 1
  4746. label.IsPrint = 2
  4747. label.DoctorId = info.DoctorId
  4748. label.UserOrgId = p.UserOrgId
  4749. label.PatientId = patient_id
  4750. label.RecordDate = recordDateTime
  4751. label.Ctime = time.Now().Unix()
  4752. label.Mtime = time.Now().Unix()
  4753. label.ItemId = p.TeamId
  4754. label.FeedetlSn = p.FeedetlSn
  4755. label.PProjectId = p.ID
  4756. label.ProjectName = team.ProjectTeam
  4757. label.PatientName = patient.Name
  4758. service.CreateHisLabelRecord(&label)
  4759. }
  4760. } else { //单条检验检查项目
  4761. label.Number = tempPrescription.PrescriptionNumber
  4762. label.ProjectId = project.ID
  4763. label.Status = 1
  4764. label.DoctorId = info.DoctorId
  4765. label.UserOrgId = p.UserOrgId
  4766. label.PatientId = patient_id
  4767. label.RecordDate = recordDateTime
  4768. label.IsPrint = 2
  4769. label.Ctime = time.Now().Unix()
  4770. label.Mtime = time.Now().Unix()
  4771. label.FeedetlSn = p.FeedetlSn
  4772. label.PProjectId = p.ID
  4773. label.ItemId = p.TeamId
  4774. label.ProjectName = project.ProjectName
  4775. label.PatientName = patient.Name
  4776. service.CreateHisLabelRecord(&label)
  4777. }
  4778. }
  4779. }
  4780. }
  4781. service.CreateNewHisProjectTwo(&p, tx)
  4782. var randNum int
  4783. randNum = rand.Intn(1000) + 1000
  4784. p.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4785. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4786. if goodBase.ID > 0 {
  4787. tx.Rollback()
  4788. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4789. return
  4790. }
  4791. service.CreateNewHisProjectTwo(&p, tx)
  4792. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4793. //查询剩余库存
  4794. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4795. var sum_count int64
  4796. for _, item := range goodList {
  4797. sum_count += item.StockCount
  4798. }
  4799. //更新剩余库存
  4800. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4801. //耗材
  4802. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4803. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4804. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4805. if len(outInfoTwo) > 0 {
  4806. for _, item := range outInfoTwo {
  4807. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4808. }
  4809. }
  4810. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4811. if len(drugAutoDetail) > 0 {
  4812. for _, item := range drugAutoDetail {
  4813. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4814. }
  4815. }
  4816. tx.Commit()
  4817. }
  4818. }
  4819. }
  4820. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4821. // addition := items["addition"].([]interface{})
  4822. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4823. // ctime := time.Now().Unix()
  4824. // mtime := ctime
  4825. // if len(addition) > 0 {
  4826. // for _, item := range addition {
  4827. // var s models.HisAdditionalCharge
  4828. // s.PrescriptionId = tempPrescription.ID
  4829. // s.Status = 1
  4830. // s.UserOrgId = adminInfo.CurrentOrgId
  4831. // s.RecordDate = recordDateTime
  4832. // s.CreatedTime = ctime
  4833. // s.UpdatedTime = mtime
  4834. // s.PatientId = patient_id
  4835. // s.HisPatientId = his_patient_id
  4836. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4837. // if errcode > 0 {
  4838. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4839. // return
  4840. // }
  4841. // service.CreateAdditionalCharge(&s)
  4842. // var randNum int
  4843. // randNum = rand.Intn(10000) + 1000
  4844. // timestamp := time.Now().Unix()
  4845. // tempTime := time.Unix(timestamp, 0)
  4846. // timeFormat := tempTime.Format("20060102150405")
  4847. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4848. // service.CreateAdditionalCharge(&s)
  4849. //
  4850. // }
  4851. // }
  4852. //}
  4853. }
  4854. }
  4855. }
  4856. tx.Commit()
  4857. if err == nil {
  4858. c.ServeSuccessJSON(map[string]interface{}{
  4859. "msg": "保存成功",
  4860. })
  4861. return
  4862. } else {
  4863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4864. return
  4865. }
  4866. } else {
  4867. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4868. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4869. var tempPrescription *models.HisPrescription
  4870. if len(prescriptions) > 0 {
  4871. for _, item := range prescriptions {
  4872. items := item.(map[string]interface{})
  4873. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4874. utils.ErrorLog("id")
  4875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4876. return
  4877. }
  4878. id := int64(items["id"].(float64))
  4879. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4880. tempPrescription = &new_prescription
  4881. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4882. utils.ErrorLog("type")
  4883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4884. return
  4885. }
  4886. types := int64(items["type"].(float64))
  4887. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4888. utils.ErrorLog("med_type")
  4889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4890. return
  4891. }
  4892. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4893. if med_type == "0" {
  4894. med_type = "14"
  4895. }
  4896. //if order_status == 0 {
  4897. // order_status = 1
  4898. //}
  4899. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4900. // utils.ErrorLog("diagnoses")
  4901. //}
  4902. diagnoses, _ := items["diagnoses"].(string)
  4903. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4904. utils.ErrorLog("pre_time")
  4905. }
  4906. preTime, _ := items["pre_time"].(string)
  4907. timeLayout := "2006-01-02"
  4908. loc, _ := time.LoadLocation("Local")
  4909. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4910. //result := strings.Split(preTime, " ")
  4911. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4912. if err != nil {
  4913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4914. return
  4915. }
  4916. pTime := theTime2.Unix()
  4917. ctime := time.Now().Unix()
  4918. if tempPrescription.ID == 0 {
  4919. prescription := &models.HisPrescription{
  4920. ID: 0,
  4921. PatientId: patient_id,
  4922. UserOrgId: adminInfo.CurrentOrgId,
  4923. RecordDate: recordDateTime,
  4924. Ctime: ctime,
  4925. Mtime: ctime,
  4926. Type: types,
  4927. Modifier: adminInfo.AdminUser.Id,
  4928. Creator: adminInfo.AdminUser.Id,
  4929. Status: 1,
  4930. Doctor: role.UserName,
  4931. HisPatientId: his_patient_id,
  4932. OrderStatus: 1,
  4933. BatchNumber: "",
  4934. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4935. PreTime: pTime,
  4936. PType: p_type,
  4937. MedType: med_type,
  4938. Diagnose: diagnoses,
  4939. }
  4940. tempPrescription = prescription
  4941. service.SaveHisPrescription(tempPrescription)
  4942. redis := service.RedisClient()
  4943. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4944. redis.Set(key, "", time.Second)
  4945. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4946. redis.Set(keyOne, "", time.Second)
  4947. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4948. redis.Set(keySeven, "", time.Second)
  4949. defer redis.Close()
  4950. } else {
  4951. tempPrescription.ID = id
  4952. tempPrescription.Type = types
  4953. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4954. tempPrescription.Mtime = time.Now().Unix()
  4955. tempPrescription.Doctor = role.UserName
  4956. //tempPrescription.OrderStatus = order_status
  4957. tempPrescription.PreTime = pTime
  4958. tempPrescription.MedType = med_type
  4959. tempPrescription.Diagnose = diagnoses
  4960. service.SaveHisPrescription(tempPrescription)
  4961. redis := service.RedisClient()
  4962. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4963. redis.Set(key, "", time.Second)
  4964. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4965. redis.Set(keyOne, "", time.Second)
  4966. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4967. redis.Set(keySeven, "", time.Second)
  4968. defer redis.Close()
  4969. }
  4970. //service.SaveHisPrescription(prescription)
  4971. //更改患者挂号状态
  4972. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4973. fmt.Println("更改失败", err2)
  4974. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4975. advices := items["advices"].([]interface{})
  4976. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4977. groupNo := int64(0)
  4978. if len(advices) > 0 {
  4979. for _, advice := range advices {
  4980. var s models.HisDoctorAdviceInfo
  4981. s.PrescriptionId = tempPrescription.ID
  4982. s.AdviceType = 2
  4983. s.AdviceDoctor = doctor_id
  4984. s.StopState = 2
  4985. s.ExecutionState = 2
  4986. s.AdviceDate = theTime3.Unix()
  4987. s.Status = 1
  4988. s.UserOrgId = adminInfo.CurrentOrgId
  4989. s.RecordDate = theTime3.Unix()
  4990. s.StartTime = tempPrescription.PreTime
  4991. s.Groupno = groupNo
  4992. s.PatientId = patient_id
  4993. s.HisPatientId = his_patient_id
  4994. s.StartTime = pTime
  4995. s.IsSettle = 2
  4996. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4997. if errcode > 0 {
  4998. c.ServeFailJSONWithSGJErrorCode(errcode)
  4999. return
  5000. }
  5001. s.StartTime = pTime
  5002. var total_count int64 //处方总库存
  5003. //查询改药品信息
  5004. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  5005. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  5006. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5007. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5008. total_count += prescribingNumberSeven * medical.MinNumber
  5009. }
  5010. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5011. total_count += prescribingNumberSeven
  5012. }
  5013. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  5014. total_count += prescribingNumberSeven
  5015. }
  5016. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5017. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5018. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5019. if s.Price != lastWarehouse.RetailPrice {
  5020. s.Price = lastWarehouse.RetailPrice
  5021. }
  5022. if s.Price == 0 {
  5023. if lastWarehouse.ID == 0 {
  5024. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  5025. s.Price = lastWarehouseTwo.RetailPrice
  5026. }
  5027. }
  5028. }
  5029. if adminInfo.CurrentOrgId != 10206 {
  5030. if s.ID == 0 {
  5031. //查询改药品是否已经停用
  5032. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  5033. if base.ID > 0 {
  5034. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  5035. return
  5036. }
  5037. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  5038. if drugMedical.SumCount == 0 {
  5039. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  5040. return
  5041. }
  5042. }
  5043. }
  5044. //赤峰
  5045. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  5046. drug, _ := service.GetDrugByGoodId(s.DrugId)
  5047. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  5048. if info.RetailPrice > 0 {
  5049. if s.DeliveryWay == "口服" {
  5050. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5051. s.Price = drug.RetailPrice
  5052. }
  5053. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5054. s.Price = info.RetailPrice
  5055. }
  5056. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5057. s.Price = info.RetailPrice
  5058. }
  5059. }
  5060. }
  5061. }
  5062. service.CreateHisDoctorAdvice(&s)
  5063. //记录日志
  5064. byterequest, _ := json.Marshal(s)
  5065. adviceLog := models.XtDoctorAdviceLog{
  5066. UserOrgId: s.UserOrgId,
  5067. PatientId: s.PatientId,
  5068. AdminUserId: adminInfo.AdminUser.Id,
  5069. Module: 1,
  5070. ErrLog: string(byterequest),
  5071. Status: 1,
  5072. Ctime: time.Now().Unix(),
  5073. Mtime: 0,
  5074. Source: "电脑端新建his医嘱",
  5075. RecordDate: s.AdviceDate,
  5076. }
  5077. service.CreateDoctorAdviceLog(adviceLog)
  5078. //存储切片中
  5079. adviceList = append(adviceList, s)
  5080. redis := service.RedisClient()
  5081. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5082. redis.Set(key, "", time.Second)
  5083. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5084. redis.Set(keyOne, "", time.Second)
  5085. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5086. redis.Set(keySeven, "", time.Second)
  5087. var randNum int
  5088. randNum = rand.Intn(1000) + 1000
  5089. //timestamp := time.Now().Unix()
  5090. //tempTime := time.Unix(timestamp, 0)
  5091. //timeFormat := tempTime.Format("20060102150405")
  5092. s.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  5093. service.CreateHisDoctorAdvice(&s)
  5094. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5095. redis.Set(keySix, "", time.Second)
  5096. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5097. redis.Set(keyFive, "", time.Second)
  5098. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5099. redis.Set(keyEight, "", time.Second)
  5100. defer redis.Close()
  5101. }
  5102. }
  5103. }
  5104. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5105. projects := items["project"].([]interface{})
  5106. if len(projects) > 0 {
  5107. for _, project := range projects {
  5108. var p models.HisPrescriptionProject
  5109. p.PrescriptionId = tempPrescription.ID
  5110. p.PatientId = patient_id
  5111. p.RecordDate = theTime3.Unix()
  5112. p.Doctor = doctor_id
  5113. p.UserOrgId = adminInfo.CurrentOrgId
  5114. p.HisPatientId = his_patient_id
  5115. p.Status = 1
  5116. p.StartTime = pTime
  5117. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  5118. if errcode > 0 {
  5119. c.ServeFailJSONWithSGJErrorCode(errcode)
  5120. return
  5121. }
  5122. if p.ID == 0 {
  5123. p.IsOut = 2
  5124. }
  5125. if p.ID > 0 {
  5126. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  5127. p.IsOut = projectDetail.IsOut
  5128. }
  5129. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5130. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5131. if p.Type == 3 {
  5132. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  5133. if p.Price != lastWarehouse.PackingPrice {
  5134. p.Price = lastWarehouse.PackingPrice
  5135. }
  5136. if p.Price == 0 {
  5137. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  5138. p.Price = lastWarehouseTwo.PackingPrice
  5139. }
  5140. if p.Unit == "" {
  5141. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5142. p.Unit = goodInfoOne.PackingUnit
  5143. }
  5144. }
  5145. }
  5146. if adminInfo.CurrentOrgId != 10206 {
  5147. if p.Type == 3 {
  5148. if p.ID == 0 {
  5149. //查询该耗材是否停用
  5150. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  5151. //表示该耗材已经停用,不能保存
  5152. if goodInfoSeven.ID == 0 {
  5153. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5154. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  5155. return
  5156. }
  5157. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5158. if goodInfoOne.SumCount == 0 {
  5159. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  5160. return
  5161. }
  5162. }
  5163. }
  5164. }
  5165. service.CreateHisProjectTwo(&p)
  5166. //记录日志
  5167. byterequest, _ := json.Marshal(p)
  5168. adviceLog := models.XtDoctorAdviceLog{
  5169. UserOrgId: p.UserOrgId,
  5170. PatientId: p.PatientId,
  5171. AdminUserId: adminInfo.AdminUser.Id,
  5172. Module: 1,
  5173. ErrLog: string(byterequest),
  5174. Status: 1,
  5175. Ctime: time.Now().Unix(),
  5176. Mtime: 0,
  5177. Source: "电脑端新建his项目",
  5178. RecordDate: p.RecordDate,
  5179. }
  5180. service.CreateDoctorAdviceLog(adviceLog)
  5181. projectList = append(projectList, p)
  5182. var randNum int
  5183. randNum = rand.Intn(1000) + 1000
  5184. p.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  5185. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  5186. //新增或者编辑项目,修改对应的标签数据
  5187. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  5188. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  5189. var label models.HisLabelPrintInfo
  5190. project, _ := service.GetProjectDetail(p.ProjectId)
  5191. if project.CostClassify == 3 { //类别为检验检查
  5192. if p.TeamId > 0 { //检验检查组套
  5193. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  5194. if tempLabel.ID == 0 {
  5195. team, _ := service.GetProjectTeamDetail(p.TeamId)
  5196. label.Number = tempPrescription.PrescriptionNumber
  5197. label.ProjectId = project.ID
  5198. label.Status = 1
  5199. label.IsPrint = 2
  5200. label.DoctorId = info.DoctorId
  5201. label.UserOrgId = p.UserOrgId
  5202. label.PatientId = patient_id
  5203. label.RecordDate = recordDateTime
  5204. label.Ctime = time.Now().Unix()
  5205. label.Mtime = time.Now().Unix()
  5206. label.ItemId = p.TeamId
  5207. label.FeedetlSn = p.FeedetlSn
  5208. label.PProjectId = p.ID
  5209. label.ProjectName = team.ProjectTeam
  5210. label.PatientName = patient.Name
  5211. service.CreateHisLabelRecord(&label)
  5212. }
  5213. } else { //单条检验检查项目
  5214. label.Number = tempPrescription.PrescriptionNumber
  5215. label.ProjectId = project.ID
  5216. label.Status = 1
  5217. label.DoctorId = info.DoctorId
  5218. label.UserOrgId = p.UserOrgId
  5219. label.PatientId = patient_id
  5220. label.RecordDate = recordDateTime
  5221. label.IsPrint = 2
  5222. label.Ctime = time.Now().Unix()
  5223. label.Mtime = time.Now().Unix()
  5224. label.FeedetlSn = p.FeedetlSn
  5225. label.PProjectId = p.ID
  5226. label.ItemId = p.TeamId
  5227. label.ProjectName = project.ProjectName
  5228. label.PatientName = patient.Name
  5229. service.CreateHisLabelRecord(&label)
  5230. }
  5231. }
  5232. }
  5233. }
  5234. service.SaveHisProjectTwo(&p)
  5235. }
  5236. }
  5237. }
  5238. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5239. // addition := items["addition"].([]interface{})
  5240. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5241. // ctime := time.Now().Unix()
  5242. // mtime := ctime
  5243. // if len(addition) > 0 {
  5244. // for _, item := range addition {
  5245. // var s models.HisAdditionalCharge
  5246. // s.PrescriptionId = tempPrescription.ID
  5247. // s.Status = 1
  5248. // s.UserOrgId = adminInfo.CurrentOrgId
  5249. // s.RecordDate = recordDateTime
  5250. // s.CreatedTime = ctime
  5251. // s.UpdatedTime = mtime
  5252. // s.PatientId = patient_id
  5253. // s.HisPatientId = his_patient_id
  5254. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5255. // if errcode > 0 {
  5256. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5257. // return
  5258. // }
  5259. // service.CreateAdditionalCharge(&s)
  5260. // var randNum int
  5261. // randNum = rand.Intn(10000) + 1000
  5262. // timestamp := time.Now().Unix()
  5263. // tempTime := time.Unix(timestamp, 0)
  5264. // timeFormat := tempTime.Format("20060102150405")
  5265. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  5266. // service.CreateAdditionalCharge(&s)
  5267. //
  5268. // }
  5269. // }
  5270. //}
  5271. }
  5272. }
  5273. //查询今日该患者开的药品处方
  5274. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5275. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  5276. //药品出库
  5277. if drugOutConfig.IsOpen == 1 {
  5278. for _, item := range hisdoctorlist {
  5279. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  5280. // 查询该药品最后一次出库记录
  5281. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  5282. if len(druginfo) > 0 {
  5283. //回退库存
  5284. for _, it := range druginfo {
  5285. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5286. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5287. }
  5288. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5289. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5290. }
  5291. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5292. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5293. }
  5294. }
  5295. }
  5296. //删除记录
  5297. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  5298. //查询最后一次数据
  5299. if drugOutConfig.IsOpen == 1 {
  5300. //出库
  5301. if drug.IsUse == 2 {
  5302. creater := adminInfo.AdminUser.Id
  5303. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  5304. }
  5305. //更新字典里面的库存
  5306. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5307. var sum_count int64
  5308. for _, its := range stockInfo {
  5309. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5310. if its.MaxUnit == baseDrug.MaxUnit {
  5311. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5312. }
  5313. sum_count += its.StockMaxNumber + its.StockMinNumber
  5314. }
  5315. //更新基础库存
  5316. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5317. //剩余库存
  5318. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  5319. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  5320. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  5321. }
  5322. }
  5323. }
  5324. fmt.Println("耗材----------------------------------", goodOutConfig.IsOpen)
  5325. //耗材保存处方出库
  5326. if goodOutConfig.IsOpen == 1 {
  5327. //查询今日耗材出库数量
  5328. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5329. for _, item := range hisgoodlist {
  5330. //查询历史出库数据
  5331. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5332. var out_count_five int64
  5333. for _, item := range flowGood {
  5334. out_count_five += item.Count
  5335. }
  5336. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  5337. fmt.Println("out_count_five-------------------", out_count_five)
  5338. fmt.Println("parseIntCount---------------", parseIntCount)
  5339. if out_count_five != parseIntCount {
  5340. //查询耗材最后一次出库记录
  5341. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  5342. //查询默认出库仓库库存
  5343. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5344. if len(wareOut) > 0 {
  5345. for _, it := range wareOut {
  5346. //回退库存
  5347. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  5348. //删除出库记录
  5349. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  5350. }
  5351. }
  5352. timeStr := time.Now().Format("2006-01-02")
  5353. timeArr := strings.Split(timeStr, "-")
  5354. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  5355. total = total + 1
  5356. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5357. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5358. number = number + total
  5359. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5360. operation_time := time.Now().Unix()
  5361. creater := c.GetAdminUserInfo().AdminUser.Id
  5362. recordDateStr := time.Now().Format("2006-01-02")
  5363. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5364. nowtime := recordDate.Unix()
  5365. warehouseOut := models.WarehouseOut{
  5366. WarehouseOutOrderNumber: warehousing_out_order,
  5367. OperationTime: operation_time,
  5368. OrgId: adminInfo.CurrentOrgId,
  5369. Creater: creater,
  5370. Ctime: time.Now().Unix(),
  5371. Status: 1,
  5372. WarehouseOutTime: nowtime,
  5373. Type: 1,
  5374. StorehouseId: storeConfig.StorehouseOutInfo,
  5375. IsCheck: 1,
  5376. IsSys: 1,
  5377. }
  5378. //查询是否生成出库单
  5379. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5380. if out.ID == 0 {
  5381. service.AddSigleWarehouseOutOne(&warehouseOut)
  5382. }
  5383. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5384. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5385. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5386. dialyPrepareOne := models.DialysisBeforePrepare{
  5387. GoodTypeId: goodObj.GoodTypeId,
  5388. GoodId: item.ProjectId,
  5389. PatientId: item.PatientId,
  5390. RecordDate: item.RecordDate,
  5391. UserOrgId: adminInfo.CurrentOrgId,
  5392. Count: parseIntCount,
  5393. Ctime: time.Now().Unix(),
  5394. Creater: creater,
  5395. Status: 1,
  5396. StorehouseId: houseConfig.StorehouseOutInfo,
  5397. ProjectId: item.ID,
  5398. }
  5399. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5400. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5401. //查询历史出库数据
  5402. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5403. var out_count int64
  5404. for _, item := range flowGood {
  5405. out_count += item.Count
  5406. }
  5407. //如果历史数和当前数据不想等才进行退库出库
  5408. if out_count != parseIntCount {
  5409. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5410. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5411. detail := models.AutomaticReduceDetail{
  5412. WarehouseOutId: 0,
  5413. WarehouseOutOrderNumber: "",
  5414. PatientId: item.PatientId,
  5415. Ctime: time.Now().Unix(),
  5416. Mtime: 0,
  5417. Status: 1,
  5418. RecordTime: item.RecordDate,
  5419. OrgId: item.UserOrgId,
  5420. GoodId: item.ProjectId,
  5421. GoodTypeId: 0,
  5422. Count: parseIntCount,
  5423. Type: 0,
  5424. ProjectId: item.ID,
  5425. StorehouseId: 0,
  5426. }
  5427. service.CreateAutoDetail(detail)
  5428. //查询剩余库存
  5429. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5430. var sum_count int64
  5431. for _, item := range goodList {
  5432. sum_count += item.StockCount
  5433. }
  5434. //更新剩余库存
  5435. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5436. //耗材
  5437. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5438. }
  5439. }
  5440. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5441. //查询历史出库数据
  5442. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5443. var out_count int64
  5444. for _, item := range flowGood {
  5445. out_count += item.Count
  5446. }
  5447. //如果历史数和当前数据不想等才进行退库出库
  5448. if out_count != parseIntCount {
  5449. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5450. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5451. detail := models.AutomaticReduceDetail{
  5452. WarehouseOutId: 0,
  5453. WarehouseOutOrderNumber: "",
  5454. PatientId: item.PatientId,
  5455. Ctime: time.Now().Unix(),
  5456. Mtime: 0,
  5457. Status: 1,
  5458. RecordTime: item.RecordDate,
  5459. OrgId: item.UserOrgId,
  5460. GoodId: item.ProjectId,
  5461. GoodTypeId: 0,
  5462. Count: parseIntCount,
  5463. Type: 0,
  5464. ProjectId: item.ID,
  5465. StorehouseId: 0,
  5466. }
  5467. service.CreateAutoDetail(detail)
  5468. //查询剩余库存
  5469. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5470. var sum_count int64
  5471. for _, item := range goodList {
  5472. sum_count += item.StockCount
  5473. }
  5474. //更新剩余库存
  5475. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5476. //耗材
  5477. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5478. }
  5479. }
  5480. }
  5481. }
  5482. }
  5483. ////同步到自备药
  5484. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5485. if selfPrescriptionOpen.IsOpen == 1 {
  5486. timeStr := time.Now().Format("2006-01-02")
  5487. timeArr := strings.Split(timeStr, "-")
  5488. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5489. total = total + 1
  5490. operation_time := time.Now().Unix()
  5491. creater := adminInfo.AdminUser.Id
  5492. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5493. warehousing := models.XtSelfDrugWarehouse{
  5494. WarehousingOrder: warehousing_order,
  5495. OperationTime: operation_time,
  5496. OrgId: adminInfo.CurrentOrgId,
  5497. Creater: creater,
  5498. Ctime: time.Now().Unix(),
  5499. Status: 1,
  5500. WarehousingTime: recordDateTime,
  5501. Type: 0,
  5502. StorehouseId: 0,
  5503. IsCheck: 1,
  5504. PatientId: patient_id,
  5505. IsSys: 1,
  5506. }
  5507. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5508. if selfDrugWarehouse.ID == 0 {
  5509. service.AddSelfDrugWarehouse(&warehousing, tx)
  5510. }
  5511. if selfDrugWarehouse.ID > 0 {
  5512. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5513. }
  5514. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5515. fmt.Println(info)
  5516. for _, item := range hisdoctorlist {
  5517. //查询该病人的该药品是否已经入库
  5518. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5519. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5520. var in_count int64
  5521. if len(selfdruginfo) > 0 {
  5522. for _, item := range selfdruginfo {
  5523. var in_count_one int64
  5524. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5525. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5526. }
  5527. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5528. in_count_one = item.WarehousingCount
  5529. }
  5530. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5531. in_count_one = item.WarehousingCount
  5532. }
  5533. in_count += in_count_one
  5534. }
  5535. }
  5536. if selfBasedrug.IsSelfDrug == 1 {
  5537. var total_count int64
  5538. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5539. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5540. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5541. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5542. }
  5543. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5544. total_count += prescribingNumberSeven
  5545. }
  5546. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5547. total_count += prescribingNumberSeven
  5548. }
  5549. //入库
  5550. if total_count > in_count {
  5551. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5552. WarehousingOrder: warehousing_order,
  5553. WarehousingId: info.ID,
  5554. DrugId: item.DrugId,
  5555. Number: "",
  5556. ProductDate: 0,
  5557. ExpiryDate: 0,
  5558. WarehousingCount: total_count - in_count,
  5559. WarehouseingUnit: selfBasedrug.MinUnit,
  5560. Price: 0,
  5561. TotalPrice: 0,
  5562. Status: 1,
  5563. Ctime: time.Now().Unix(),
  5564. Remark: "",
  5565. OrgId: adminInfo.CurrentOrgId,
  5566. Type: 0,
  5567. Manufacturer: selfBasedrug.Manufacturer,
  5568. Dealer: selfBasedrug.Dealer,
  5569. StockMaxNumber: total_count - in_count,
  5570. RetailTotalPrice: 0,
  5571. BatchNumber: "",
  5572. MaxUnit: selfBasedrug.MinUnit,
  5573. MinUnit: selfBasedrug.MinUnit,
  5574. RetailPrice: 0,
  5575. StorehouseId: 0,
  5576. IsCheck: 1,
  5577. StockMinNumber: 0,
  5578. PatientId: patient_id,
  5579. IsSys: 1,
  5580. RecordDate: item.RecordDate,
  5581. AdviceId: item.ID,
  5582. }
  5583. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5584. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5585. Creator := adminInfo.AdminUser.Id
  5586. //查询默认仓库剩余多少库存
  5587. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5588. var sum_count int64
  5589. for _, it := range list {
  5590. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5591. if it.MaxUnit == baseDrug.MaxUnit {
  5592. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5593. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5594. }
  5595. sum_count += it.StockMaxNumber + it.StockMinNumber
  5596. }
  5597. flow := &models.XtSelfDrugFlow{
  5598. WarehousingId: info.ID,
  5599. DrugId: item.DrugId,
  5600. Number: "",
  5601. BatchNumber: "",
  5602. Count: total_count - in_count,
  5603. UserOrgId: adminInfo.CurrentOrgId,
  5604. PatientId: item.PatientId,
  5605. SystemTime: time.Now().Unix(),
  5606. ConsumableType: 1,
  5607. IsSys: 1,
  5608. WarehousingOrder: warehousing_order,
  5609. WarehouseOutId: 0,
  5610. WarehouseOutOrderNumber: "",
  5611. IsEdit: 0,
  5612. CancelStockId: 0,
  5613. CancelOrderNumber: "",
  5614. Manufacturer: selfBasedrug.Manufacturer,
  5615. Dealer: selfBasedrug.Dealer,
  5616. Creator: Creator,
  5617. UpdateCreator: Creator,
  5618. Status: 1,
  5619. Ctime: item.AdviceDate,
  5620. Mtime: 0,
  5621. Price: item.Price,
  5622. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5623. WarehouseOutDetailId: 0,
  5624. CancelOutDetailId: 0,
  5625. ExpireDate: 0,
  5626. ProductDate: 0,
  5627. MaxUnit: selfBasedrug.MinUnit,
  5628. MinUnit: selfBasedrug.MinUnit,
  5629. StorehouseId: 0,
  5630. OverCount: sum_count,
  5631. OperateTime: time.Now().Unix(),
  5632. AdviceId: item.ID,
  5633. }
  5634. service.CreateSelfDrugFlow(flow, tx)
  5635. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5636. var total_count int64 // 入库总数量
  5637. var over_count int64 //剩余库存
  5638. for _, it := range drugInfolist {
  5639. if it.MaxUnit == selfBasedrug.MaxUnit {
  5640. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5641. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5642. }
  5643. }
  5644. for _, it := range drugInfolist {
  5645. total_count += it.WarehousingCount
  5646. over_count += it.StockMaxNumber + it.StockMinNumber
  5647. }
  5648. //查询该仓库是否有默认数据
  5649. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5650. if selfDrugStock.ID == 0 {
  5651. drugStock := models.XtSelfDrugStockCount{
  5652. UserOrgId: item.UserOrgId,
  5653. PatientId: item.PatientId,
  5654. SumInCount: total_count,
  5655. SumOutCount: 0,
  5656. SumCancelCount: 0,
  5657. DrugId: item.DrugId,
  5658. Ctime: time.Now().Unix(),
  5659. Mtime: 0,
  5660. Status: 1,
  5661. FlushCount: over_count,
  5662. SumActOutCount: 0,
  5663. }
  5664. service.CreateSelfDrugStockSum(drugStock, tx)
  5665. }
  5666. if selfDrugStock.ID > 0 {
  5667. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5668. }
  5669. }
  5670. //查询这个单据的出库数量
  5671. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5672. var his_out_count int64
  5673. for _, item := range drugFlowList {
  5674. his_out_count += item.Count
  5675. }
  5676. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5677. if (total_count + his_out_count) <= in_count {
  5678. // 出库
  5679. if total_count < in_count {
  5680. var cha_count int64
  5681. cha_count = in_count - total_count
  5682. var stock_number int64 = 0
  5683. //查询库存是否充足
  5684. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5685. // 将该批次的剩余库存数量转换为拆零数量
  5686. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5687. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5688. }
  5689. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5690. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5691. }
  5692. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5693. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5694. }
  5695. if stock_number >= cha_count {
  5696. var maxNumber int64 = 0
  5697. var minNumber int64 = 0
  5698. maxNumber = cha_count / selfBasedrug.MinNumber
  5699. minNumber = cha_count % selfBasedrug.MinNumber
  5700. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5701. minNumber = maxNumber
  5702. }
  5703. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5704. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5706. return
  5707. }
  5708. }
  5709. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5710. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5711. }
  5712. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5713. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5714. }
  5715. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5716. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5717. }
  5718. if warehouse.StockMaxNumber < 0 {
  5719. warehouse.StockMaxNumber = 0
  5720. }
  5721. if warehouse.StockMinNumber < 0 {
  5722. warehouse.StockMinNumber = 0
  5723. }
  5724. warehouse.Mtime = time.Now().Unix()
  5725. if warehouse.StockMinNumber < minNumber {
  5726. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5727. if warehouse.MaxUnit != warehouse.MinUnit {
  5728. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5729. }
  5730. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5731. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5732. }
  5733. } else {
  5734. if minNumber > 0 {
  5735. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5736. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5737. }
  5738. }
  5739. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5740. if warehouse.StockMinNumber > 0 {
  5741. if warehouse.StockMinNumber-cha_count >= 0 {
  5742. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5743. }
  5744. }
  5745. }
  5746. }
  5747. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5748. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5749. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5750. }
  5751. }
  5752. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5753. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5755. return
  5756. }
  5757. }
  5758. if warehouse.StockMinNumber <= 0 {
  5759. warehouse.StockMinNumber = 0
  5760. }
  5761. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5762. //查询该药品剩余库存
  5763. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5764. var over_count int64
  5765. for _, its := range infolist {
  5766. if its.MaxUnit == selfBasedrug.MaxUnit {
  5767. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5768. }
  5769. over_count += its.StockMaxNumber + its.StockMinNumber
  5770. }
  5771. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5772. drugflow := models.XtSelfDrugFlow{
  5773. WarehouseOutId: 0,
  5774. WarehouseOutOrderNumber: warehousing_order,
  5775. WarehousingOrder: warehousing_order,
  5776. DrugId: item.DrugId,
  5777. Number: warehouse.Number,
  5778. ProductDate: warehouse.ProductDate,
  5779. ExpireDate: warehouse.ExpiryDate,
  5780. Count: cha_count,
  5781. Price: warehouse.RetailPrice,
  5782. Status: 1,
  5783. Ctime: item.AdviceDate,
  5784. Mtime: time.Now().Unix(),
  5785. UserOrgId: item.UserOrgId,
  5786. Manufacturer: warehouse.Manufacturer,
  5787. Dealer: warehouse.Dealer,
  5788. BatchNumber: warehouse.BatchNumber,
  5789. MaxUnit: selfBasedrug.MinUnit,
  5790. ConsumableType: 20,
  5791. IsEdit: 1,
  5792. Creator: 0,
  5793. IsSys: 3,
  5794. WarehouseOutDetailId: drugWareInfo.ID,
  5795. AdviceId: item.ID,
  5796. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5797. StorehouseId: 0,
  5798. AdminUserId: creater,
  5799. LastPrice: warehouse.Price,
  5800. StockCount: "",
  5801. WarehousingDetailId: 0,
  5802. OverCount: over_count,
  5803. RetailPrice: item.Price, //手动出库出库价格
  5804. WarehousingId: warehouse.ID,
  5805. SystemTime: item.AdviceDate,
  5806. PatientId: item.PatientId,
  5807. Remark: "保存处方入库数据差",
  5808. OperateTime: time.Now().Unix(),
  5809. }
  5810. if warehouse.RetailPrice == 0 {
  5811. drugflow.Price = item.Price
  5812. }
  5813. service.CreateSelfDrugFlowOne(drugflow, tx)
  5814. var out_count int64
  5815. out_count = in_count - total_count
  5816. //
  5817. //fmt.Println("in_count------------------", in_count)
  5818. //fmt.Println("total_count------------------", total_count)
  5819. //添加出库数量
  5820. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5821. //查询剩余库存
  5822. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5823. var sum_count int64
  5824. for _, its := range stockInfo {
  5825. if its.MaxUnit == selfBasedrug.MaxUnit {
  5826. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5827. }
  5828. sum_count += its.StockMaxNumber + its.StockMinNumber
  5829. }
  5830. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5831. } else {
  5832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5833. return
  5834. }
  5835. }
  5836. }
  5837. }
  5838. }
  5839. }
  5840. }
  5841. tx.Commit()
  5842. if err == nil {
  5843. c.ServeSuccessJSON(map[string]interface{}{
  5844. "msg": "保存成功",
  5845. })
  5846. return
  5847. } else {
  5848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5849. return
  5850. }
  5851. }
  5852. }
  5853. //func (c *HisApiController) EditHisPrescription() {
  5854. // record_date := c.GetString("record_date")
  5855. // patient_id, _ := c.GetInt64("patient_id")
  5856. // reg_type, _ := c.GetInt64("reg_type")
  5857. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5858. // diagnose := c.GetString("diagnose")
  5859. // sick_type, _ := c.GetInt64("sick_type")
  5860. // sick_history := c.GetString("sick_history")
  5861. // doctor_id, _ := c.GetInt64("doctor", 0)
  5862. // department, _ := c.GetInt64("department", 0)
  5863. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5864. // p_type, _ := c.GetInt64("p_type")
  5865. //
  5866. // dataBody := make(map[string]interface{}, 0)
  5867. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5868. // if err != nil {
  5869. // utils.ErrorLog(err.Error())
  5870. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5871. // return
  5872. // }
  5873. //
  5874. // timeLayout := "2006-01-02"
  5875. // loc, _ := time.LoadLocation("Local")
  5876. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5877. // if err != nil {
  5878. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5879. // return
  5880. // }
  5881. // adminInfo := c.GetAdminUserInfo()
  5882. // recordDateTime := theTime.Unix()
  5883. //
  5884. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5885. //
  5886. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5887. // var hpInfo models.HisPrescriptionInfo
  5888. // if info.ID == 0 {
  5889. // var randNum int
  5890. // randNum = rand.Intn(10000) + 1000
  5891. // timestamp := time.Now().Unix()
  5892. // tempTime := time.Unix(timestamp, 0)
  5893. // timeFormat := tempTime.Format("20060102150405")
  5894. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5895. //
  5896. // hpInfo = models.HisPrescriptionInfo{
  5897. // UserOrgId: adminInfo.CurrentOrgId,
  5898. // RecordDate: theTime.Unix(),
  5899. // PatientId: patient_id,
  5900. // Status: 1,
  5901. // Ctime: time.Now().Unix(),
  5902. // Mtime: time.Now().Unix(),
  5903. // Creator: adminInfo.AdminUser.Id,
  5904. // Modifier: adminInfo.AdminUser.Id,
  5905. // Diagnosis: diagnose,
  5906. // SickHistory: sick_history,
  5907. // Departments: department,
  5908. // RegisterType: reg_type,
  5909. // PrescriptionNumber: p_number,
  5910. // PrescriptionStatus: 1,
  5911. // Doctor: role.UserName,
  5912. // DoctorId: doctor_id,
  5913. // SickType: sick_type,
  5914. // PType: p_type,
  5915. // }
  5916. // service.SavePatientPrescriptionInfo(hpInfo)
  5917. //
  5918. // } else {
  5919. // hpInfo = models.HisPrescriptionInfo{
  5920. // ID: info.ID,
  5921. // UserOrgId: adminInfo.CurrentOrgId,
  5922. // RecordDate: info.RecordDate,
  5923. // PatientId: info.PatientId,
  5924. // Status: 1,
  5925. // Ctime: info.Ctime,
  5926. // Mtime: time.Now().Unix(),
  5927. // Creator: info.Creator,
  5928. // Modifier: adminInfo.AdminUser.Id,
  5929. // Diagnosis: diagnose,
  5930. // SickHistory: sick_history,
  5931. // Departments: department,
  5932. // RegisterType: reg_type,
  5933. // PrescriptionNumber: info.PrescriptionNumber,
  5934. // Doctor: role.UserName,
  5935. // PrescriptionStatus: info.PrescriptionStatus,
  5936. // DoctorId: doctor_id,
  5937. // SickType: sick_type,
  5938. // PType: info.PType,
  5939. // }
  5940. // service.SavePatientPrescriptionInfo(hpInfo)
  5941. // }
  5942. //
  5943. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5944. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5945. //
  5946. // if len(prescriptions) > 0 {
  5947. // for _, item := range prescriptions {
  5948. // items := item.(map[string]interface{})
  5949. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5950. // utils.ErrorLog("id")
  5951. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5952. // return
  5953. // }
  5954. // id := int64(items["id"].(float64))
  5955. //
  5956. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5957. // utils.ErrorLog("type")
  5958. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5959. // return
  5960. // }
  5961. // types := int64(items["type"].(float64))
  5962. //
  5963. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5964. // utils.ErrorLog("med_type")
  5965. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5966. // return
  5967. // }
  5968. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5969. //
  5970. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5971. //
  5972. // ctime := time.Now().Unix()
  5973. //
  5974. // prescription := &models.HisPrescription{
  5975. // ID: id,
  5976. // PatientId: patient_id,
  5977. // UserOrgId: adminInfo.CurrentOrgId,
  5978. // RecordDate: recordDateTime,
  5979. // Ctime: ctime,
  5980. // Mtime: ctime,
  5981. // Type: types,
  5982. // Modifier: adminInfo.AdminUser.Id,
  5983. // Creator: adminInfo.AdminUser.Id,
  5984. // Status: 1,
  5985. // Doctor: role.UserName,
  5986. // HisPatientId: his_patient_id,
  5987. // OrderStatus: 1,
  5988. // BatchNumber: "",
  5989. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5990. // PType: hpInfo.PType,
  5991. // MedType: med_type,
  5992. // }
  5993. //
  5994. // if historyPrescription.ID > 0 {
  5995. // prescription.PreTime = historyPrescription.PreTime
  5996. //
  5997. // }
  5998. //
  5999. // service.SaveHisPrescription(prescription)
  6000. //
  6001. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  6002. // advices := items["advices"].([]interface{})
  6003. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6004. // groupNo := int64(0)
  6005. // ctime := time.Now().Unix()
  6006. // mtime := ctime
  6007. // if len(advices) > 0 {
  6008. // for _, advice := range advices {
  6009. // var s models.HisDoctorAdviceInfo
  6010. // s.PrescriptionId = prescription.ID
  6011. // s.AdviceType = 2
  6012. // s.AdviceDoctor = adminInfo.AdminUser.Id
  6013. // s.StopState = 2
  6014. // s.ExecutionState = 2
  6015. // s.AdviceDate = recordDateTime
  6016. // s.Status = 1
  6017. // s.UserOrgId = adminInfo.CurrentOrgId
  6018. // s.RecordDate = recordDateTime
  6019. // s.StartTime = prescription.PreTime
  6020. // s.Groupno = groupNo
  6021. // s.CreatedTime = ctime
  6022. // s.UpdatedTime = mtime
  6023. // s.PatientId = patient_id
  6024. // s.HisPatientId = his_patient_id
  6025. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  6026. // if errcode > 0 {
  6027. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6028. // return
  6029. // }
  6030. //
  6031. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  6032. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  6033. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  6034. // if s.Price == 0 {
  6035. // s.Price = lastWarehouse.RetailPrice
  6036. // }
  6037. // }
  6038. //
  6039. // service.CreateHisDoctorAdvice(&s)
  6040. // //记录日志
  6041. // byterequest, _ := json.Marshal(s)
  6042. // adviceLog := models.XtDoctorAdviceLog{
  6043. // UserOrgId: s.UserOrgId,
  6044. // PatientId: s.PatientId,
  6045. // AdminUserId: adminInfo.AdminUser.Id,
  6046. // Module: 1,
  6047. // ErrLog: string(byterequest),
  6048. // Status: 1,
  6049. // Ctime: time.Now().Unix(),
  6050. // Mtime: 0,
  6051. // Source: "电脑端his医嘱修改",
  6052. // RecordDate: s.AdviceDate,
  6053. // }
  6054. // service.CreateDoctorAdviceLog(adviceLog)
  6055. // redis := service.RedisClient()
  6056. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  6057. // redis.Set(key, "", time.Second)
  6058. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  6059. // fmt.Println("keyOne", keyOne)
  6060. // redis.Set(keyOne, "", time.Second)
  6061. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  6062. // redis.Set(keySeven, "", time.Second)
  6063. // redis.Close()
  6064. //
  6065. // }
  6066. // }
  6067. // }
  6068. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  6069. // projects := items["project"].([]interface{})
  6070. // if len(projects) > 0 {
  6071. // for _, project := range projects {
  6072. // var p models.HisPrescriptionProject
  6073. // p.PrescriptionId = prescription.ID
  6074. // p.Ctime = time.Now().Unix()
  6075. // p.Mtime = time.Now().Unix()
  6076. // p.PatientId = patient_id
  6077. // p.RecordDate = recordDateTime
  6078. // p.UserOrgId = adminInfo.CurrentOrgId
  6079. // p.HisPatientId = his_patient_id
  6080. // p.Status = 1
  6081. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  6082. // if errcode > 0 {
  6083. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6084. // return
  6085. // }
  6086. // service.CreateHisProjectTwo(&p)
  6087. //
  6088. // //记录日志
  6089. // byterequest, _ := json.Marshal(p)
  6090. // adviceLog := models.XtDoctorAdviceLog{
  6091. // UserOrgId: p.UserOrgId,
  6092. // PatientId: p.PatientId,
  6093. // AdminUserId: adminInfo.AdminUser.Id,
  6094. // Module: 1,
  6095. // ErrLog: string(byterequest),
  6096. // Status: 1,
  6097. // Ctime: time.Now().Unix(),
  6098. // Mtime: 0,
  6099. // Source: "电脑端his项目修改",
  6100. // RecordDate: p.RecordDate,
  6101. // }
  6102. // service.CreateDoctorAdviceLog(adviceLog)
  6103. // }
  6104. // }
  6105. // }
  6106. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  6107. // addition := items["addition"].([]interface{})
  6108. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6109. // ctime := time.Now().Unix()
  6110. // mtime := ctime
  6111. // if len(addition) > 0 {
  6112. // for _, item := range addition {
  6113. // var s models.HisAdditionalCharge
  6114. // s.PrescriptionId = prescription.ID
  6115. // s.Status = 1
  6116. // s.UserOrgId = adminInfo.CurrentOrgId
  6117. // s.RecordDate = recordDateTime
  6118. // s.CreatedTime = ctime
  6119. // s.UpdatedTime = mtime
  6120. // s.PatientId = patient_id
  6121. // s.HisPatientId = his_patient_id
  6122. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  6123. // if errcode > 0 {
  6124. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6125. // return
  6126. // }
  6127. // service.CreateAdditionalCharge(&s)
  6128. // }
  6129. // }
  6130. // }
  6131. //
  6132. // }
  6133. // }
  6134. // }
  6135. // if err == nil {
  6136. // c.ServeSuccessJSON(map[string]interface{}{
  6137. // "msg": "保存成功",
  6138. // })
  6139. // return
  6140. //
  6141. // } else {
  6142. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6143. // return
  6144. // }
  6145. //}
  6146. func (c *HisApiController) DeletePrescription() {
  6147. prescription_id, _ := c.GetInt64("id")
  6148. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  6149. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  6150. ////同步到自备药
  6151. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6152. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6153. if selfPrescriptionOpen.IsOpen == 1 {
  6154. // 在函数结束时处理事务回滚
  6155. db := service.XTWriteDB()
  6156. tx := db.Begin()
  6157. defer func() {
  6158. if r := recover(); r != nil {
  6159. tx.Rollback()
  6160. } else {
  6161. tx.Commit()
  6162. }
  6163. }()
  6164. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  6165. for _, item := range advicesList {
  6166. timeStr := time.Now().Format("2006-01-02")
  6167. timeArr := strings.Split(timeStr, "-")
  6168. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6169. total = total + 1
  6170. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6171. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6172. number = number + total
  6173. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6174. operation_time := time.Now().Unix()
  6175. creater := c.GetAdminUserInfo().AdminUser.Id
  6176. //创建一个出库单
  6177. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6178. WarehouseOutOrderNumber: warehousing_out_order,
  6179. OperationTime: operation_time,
  6180. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6181. Creater: creater,
  6182. Ctime: time.Now().Unix(),
  6183. Status: 1,
  6184. WarehouseOutTime: item.AdviceDate,
  6185. Type: 0,
  6186. PatientId: item.PatientId,
  6187. IsCheck: 1,
  6188. }
  6189. //查询今日是否有出库数据
  6190. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  6191. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  6192. if lastWarehouseOut.ID == 0 {
  6193. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6194. }
  6195. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  6196. var total_count int64
  6197. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  6198. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6199. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6200. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6201. }
  6202. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6203. total_count += prescribingNumberSeven
  6204. }
  6205. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6206. total_count += prescribingNumberSeven
  6207. }
  6208. //出库
  6209. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6210. WarehouseOutOrderNumber: warehousing_out_order,
  6211. WarehouseOutId: lastWarehouseOut.ID,
  6212. DrugId: item.DrugId,
  6213. Count: total_count,
  6214. Price: 0,
  6215. TotalPrice: 0,
  6216. Status: 1,
  6217. Ctime: item.AdviceDate,
  6218. Mtime: item.AdviceDate,
  6219. Remark: "",
  6220. OrgId: item.UserOrgId,
  6221. Type: 0,
  6222. Manufacturer: selfBasedrug.Manufacturer,
  6223. Dealer: selfBasedrug.Dealer,
  6224. RetailPrice: 0,
  6225. RetailTotalPrice: 0,
  6226. CountUnit: selfBasedrug.MinUnit,
  6227. ExpiryDate: 0,
  6228. ProductDate: 0,
  6229. Number: "",
  6230. BatchNumber: "",
  6231. IsSys: 1,
  6232. WarehouseInfoId: 0,
  6233. AdminUserId: 0,
  6234. StockCount: "",
  6235. IsCheck: 1,
  6236. SysRecordTime: item.AdviceDate,
  6237. PatientId: item.PatientId,
  6238. ClassType: "",
  6239. AdviceId: item.ID,
  6240. }
  6241. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6242. }
  6243. fmt.Println("长度-------------------------------", warehousingOutInfo)
  6244. for _, it := range warehousingOutInfo {
  6245. //查询今日是否有出库数据
  6246. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  6247. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6248. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6249. //出库逻辑
  6250. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  6251. //查询剩余库存
  6252. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6253. var sum_count int64
  6254. for _, its := range stockInfo {
  6255. if its.MaxUnit == medical.MaxUnit {
  6256. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6257. }
  6258. sum_count += its.StockMaxNumber + its.StockMinNumber
  6259. }
  6260. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6261. }
  6262. }
  6263. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6264. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6265. //耗材保存处方出库
  6266. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6267. //已收费和已发药限制逻辑
  6268. isCharge := false
  6269. isMedicine := false
  6270. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6271. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6272. if new_prescription.IsMedicine == 1 {
  6273. isMedicine = true
  6274. }
  6275. for _, item := range new_prescriptions {
  6276. if item.OrderStatus == 4 {
  6277. isCharge = true
  6278. }
  6279. }
  6280. if p_err != nil {
  6281. if new_prescription.ID > 0 {
  6282. if new_prescription.OrderStatus == 2 {
  6283. isCharge = true
  6284. }
  6285. }
  6286. }
  6287. for _, item := range advices {
  6288. if item.IsMedicine == 1 {
  6289. isMedicine = true
  6290. }
  6291. }
  6292. if isCharge {
  6293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6294. return
  6295. }
  6296. if isMedicine {
  6297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6298. return
  6299. }
  6300. //已收费和已发药限制逻辑
  6301. if len(projects) > 0 {
  6302. for _, item := range projects {
  6303. service.DeletePrintInfo(item.ID) //删除打印信息
  6304. if goodOutConfig.IsOpen != 1 {
  6305. if stockConfig.IsOpen == 1 {
  6306. if item.Type == 3 && item.IsOut == 1 {
  6307. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6308. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6309. good.Total = good.Total + f_count
  6310. service.UpdateGoodInfo(&good)
  6311. operation_time := time.Now().Unix()
  6312. creater := c.GetAdminUserInfo().AdminUser.Id
  6313. //创建退库单
  6314. timeStr := time.Now().Format("2006-01-02")
  6315. timeArr := strings.Split(timeStr, "-")
  6316. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6317. total = total + 1
  6318. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6319. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6320. cancelStock := models.CancelStock{
  6321. OrderNumber: orderNumber,
  6322. OperaTime: operation_time,
  6323. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6324. Creater: creater,
  6325. Ctime: time.Now().Unix(),
  6326. Status: 1,
  6327. ReturnTime: item.RecordDate,
  6328. Type: 1,
  6329. StorehouseId: houseConfig.StorehouseOutInfo,
  6330. IsCheck: 1,
  6331. }
  6332. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6333. if msgerrkonde == gorm.ErrRecordNotFound {
  6334. service.AddSigleCancelStock(&cancelStock)
  6335. }
  6336. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6337. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6338. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6339. //查询该耗材是否出库
  6340. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6341. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6342. deaerler, _ := service.GetDealerById(info.Dealer)
  6343. var total_count int64
  6344. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6345. total_count += count
  6346. if info.ID > 0 {
  6347. if info.Count >= total_count {
  6348. //回退库存
  6349. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6350. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6351. var flush_count int64
  6352. for _, it := range goodList {
  6353. flush_count += it.StockCount
  6354. }
  6355. cancelStockInfo := models.CancelStockInfo{
  6356. GoodId: item.ProjectId,
  6357. CancelStockId: cancel.ID,
  6358. GoodTypeId: good.GoodTypeId,
  6359. Count: prescribingNumber,
  6360. Price: info.Price,
  6361. Total: 0,
  6362. ProductDate: info.ProductDate,
  6363. ExpiryDate: info.ExpiryDate,
  6364. Ctime: time.Now().Unix(),
  6365. Status: 1,
  6366. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6367. OrderNumber: cancel.OrderNumber,
  6368. Type: 0,
  6369. Dealer: deaerler.DealerName,
  6370. Manufacturer: manufacturer.ManufacturerName,
  6371. Number: info.Number,
  6372. RegisterAccount: "",
  6373. Remark: "",
  6374. WarehouseInfoId: info.WarehouseInfotId,
  6375. PatientId: info.PatientId,
  6376. RecordDate: info.SysRecordTime,
  6377. StorehouseId: houseConfig.StorehouseOutInfo,
  6378. IsCheck: 1,
  6379. }
  6380. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6381. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6382. flow := models.VmStockFlow{
  6383. WarehousingId: info.WarehouseInfotId,
  6384. GoodId: item.ProjectId,
  6385. Number: info.Number,
  6386. LicenseNumber: info.LicenseNumber,
  6387. Count: prescribingNumber,
  6388. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6389. PatientId: item.PatientId,
  6390. SystemTime: info.SysRecordTime,
  6391. ConsumableType: 7,
  6392. IsSys: 0,
  6393. WarehousingOrder: "",
  6394. WarehouseOutId: info.WarehouseOutId,
  6395. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6396. IsEdit: 0,
  6397. CancelStockId: cancel.ID,
  6398. CancelOrderNumber: cancel.OrderNumber,
  6399. Manufacturer: manufacturer.ID,
  6400. Dealer: 0,
  6401. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6402. UpdateCreator: 0,
  6403. Status: 1,
  6404. Ctime: time.Now().Unix(),
  6405. Mtime: 0,
  6406. Price: info.Price,
  6407. WarehousingDetailId: info.WarehouseInfotId,
  6408. WarehouseOutDetailId: info.ID,
  6409. CancelOutDetailId: cancelInfo.ID,
  6410. ProductDate: info.ProductDate,
  6411. ExpireDate: info.ExpiryDate,
  6412. StorehouseId: houseConfig.StorehouseOutInfo,
  6413. OverCount: flush_count,
  6414. OperateTime: time.Now().Unix(),
  6415. }
  6416. service.CreateStockFlowOne(flow)
  6417. //退库数量增加
  6418. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6419. //出库数量减少
  6420. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6421. }
  6422. if info.Count < total_count {
  6423. //回退库存
  6424. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6425. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6426. var flush_count int64
  6427. for _, it := range goodList {
  6428. flush_count += it.StockCount
  6429. }
  6430. cancelStockInfo := models.CancelStockInfo{
  6431. GoodId: item.ProjectId,
  6432. CancelStockId: cancel.ID,
  6433. GoodTypeId: good.GoodTypeId,
  6434. Count: info.Count,
  6435. Price: info.Price,
  6436. Total: 0,
  6437. ProductDate: info.ProductDate,
  6438. ExpiryDate: info.ExpiryDate,
  6439. Ctime: time.Now().Unix(),
  6440. Status: 1,
  6441. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6442. OrderNumber: cancel.OrderNumber,
  6443. Type: 0,
  6444. Dealer: deaerler.DealerName,
  6445. Manufacturer: manufacturer.ManufacturerName,
  6446. Number: info.Number,
  6447. RegisterAccount: "",
  6448. Remark: "",
  6449. WarehouseInfoId: info.WarehouseInfotId,
  6450. PatientId: info.PatientId,
  6451. RecordDate: info.SysRecordTime,
  6452. StorehouseId: houseConfig.StorehouseOutInfo,
  6453. IsCheck: 1,
  6454. }
  6455. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6456. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6457. flow := models.VmStockFlow{
  6458. WarehousingId: info.WarehouseInfotId,
  6459. GoodId: item.ProjectId,
  6460. Number: info.Number,
  6461. LicenseNumber: info.LicenseNumber,
  6462. Count: info.Count,
  6463. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6464. PatientId: item.PatientId,
  6465. SystemTime: info.SysRecordTime,
  6466. ConsumableType: 7,
  6467. IsSys: 0,
  6468. WarehousingOrder: "",
  6469. WarehouseOutId: info.WarehouseOutId,
  6470. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6471. IsEdit: 0,
  6472. CancelStockId: cancel.ID,
  6473. CancelOrderNumber: cancel.OrderNumber,
  6474. Manufacturer: manufacturer.ID,
  6475. Dealer: 0,
  6476. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6477. UpdateCreator: 0,
  6478. Status: 1,
  6479. Ctime: time.Now().Unix(),
  6480. Mtime: 0,
  6481. Price: info.Price,
  6482. WarehousingDetailId: info.WarehouseInfotId,
  6483. WarehouseOutDetailId: info.ID,
  6484. CancelOutDetailId: cancelInfo.ID,
  6485. ProductDate: info.ProductDate,
  6486. ExpireDate: info.ExpiryDate,
  6487. StorehouseId: houseConfig.StorehouseOutInfo,
  6488. OverCount: flush_count,
  6489. OperateTime: time.Now().Unix(),
  6490. }
  6491. service.CreateStockFlowOne(flow)
  6492. //退库数量增加
  6493. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6494. //出库数量减少
  6495. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6496. }
  6497. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6498. var flush_count int64
  6499. for _, it := range goodList {
  6500. flush_count += it.StockCount
  6501. }
  6502. //查询已出库数量
  6503. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6504. if prescribingNumber < dialysisInfo.Count {
  6505. //改变数量
  6506. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6507. }
  6508. if prescribingNumber >= dialysisInfo.Count {
  6509. //删除出库表
  6510. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6511. }
  6512. //更新库存
  6513. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6514. //更新基础库库存
  6515. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6516. }
  6517. }
  6518. }
  6519. }
  6520. //保存耗材出库
  6521. if goodOutConfig.IsOpen == 1 {
  6522. if item.Type == 3 {
  6523. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6524. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6525. good.Total = good.Total + f_count
  6526. service.UpdateGoodInfo(&good)
  6527. operation_time := time.Now().Unix()
  6528. creater := c.GetAdminUserInfo().AdminUser.Id
  6529. //创建退库单
  6530. timeStr := time.Now().Format("2006-01-02")
  6531. timeArr := strings.Split(timeStr, "-")
  6532. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6533. total = total + 1
  6534. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6535. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6536. cancelStock := models.CancelStock{
  6537. OrderNumber: orderNumber,
  6538. OperaTime: operation_time,
  6539. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6540. Creater: creater,
  6541. Ctime: time.Now().Unix(),
  6542. Status: 1,
  6543. ReturnTime: item.RecordDate,
  6544. Type: 1,
  6545. StorehouseId: houseConfig.StorehouseOutInfo,
  6546. IsCheck: 1,
  6547. }
  6548. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6549. if msgerrkonde == gorm.ErrRecordNotFound {
  6550. service.AddSigleCancelStock(&cancelStock)
  6551. }
  6552. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6553. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6554. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6555. //查询该耗材是否出库
  6556. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6557. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6558. deaerler, _ := service.GetDealerById(info.Dealer)
  6559. var total_count int64
  6560. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6561. total_count += count
  6562. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6563. var flush_count int64
  6564. for _, it := range goodList {
  6565. flush_count += it.StockCount
  6566. }
  6567. fmt.Println("历史出库数据", info.Count)
  6568. fmt.Println("出库数量", total_count)
  6569. if info.ID > 0 {
  6570. cancelStockInfo := models.CancelStockInfo{
  6571. GoodId: item.ProjectId,
  6572. CancelStockId: cancel.ID,
  6573. GoodTypeId: good.GoodTypeId,
  6574. Count: prescribingNumber,
  6575. Price: info.Price,
  6576. Total: 0,
  6577. ProductDate: info.ProductDate,
  6578. ExpiryDate: info.ExpiryDate,
  6579. Ctime: time.Now().Unix(),
  6580. Status: 1,
  6581. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6582. OrderNumber: cancel.OrderNumber,
  6583. Type: 0,
  6584. Dealer: deaerler.DealerName,
  6585. Manufacturer: manufacturer.ManufacturerName,
  6586. Number: info.Number,
  6587. RegisterAccount: "",
  6588. Remark: "",
  6589. WarehouseInfoId: info.WarehouseInfotId,
  6590. PatientId: info.PatientId,
  6591. RecordDate: info.SysRecordTime,
  6592. StorehouseId: houseConfig.StorehouseOutInfo,
  6593. IsCheck: 1,
  6594. }
  6595. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6596. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6597. //查询出库数量
  6598. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6599. //出库数据 大于 退库数量
  6600. if len(list) > 0 {
  6601. for _, it := range list {
  6602. //回退库存
  6603. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6604. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6605. var flush_count_one int64
  6606. for _, it := range goodList {
  6607. flush_count_one += it.StockCount
  6608. }
  6609. //查询该批次是否有退库数据
  6610. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6611. creater := c.GetAdminUserInfo().AdminUser.Id
  6612. flow := models.VmStockFlow{
  6613. WarehousingId: it.WarehouseInfotId,
  6614. GoodId: it.GoodId,
  6615. Number: it.Number,
  6616. LicenseNumber: it.LicenseNumber,
  6617. Count: it.Count,
  6618. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6619. PatientId: it.PatientId,
  6620. SystemTime: it.SysRecordTime,
  6621. ConsumableType: 7,
  6622. IsSys: 0,
  6623. WarehousingOrder: "",
  6624. WarehouseOutId: it.WarehouseOutId,
  6625. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6626. IsEdit: 0,
  6627. CancelStockId: cancel.ID,
  6628. CancelOrderNumber: cancel.OrderNumber,
  6629. Manufacturer: manufacturer.ID,
  6630. Dealer: 0,
  6631. Creator: creater,
  6632. UpdateCreator: 0,
  6633. Status: 1,
  6634. Ctime: time.Now().Unix(),
  6635. Mtime: 0,
  6636. Price: it.Price,
  6637. WarehousingDetailId: it.WarehouseInfotId,
  6638. WarehouseOutDetailId: it.ID,
  6639. CancelOutDetailId: cancelInfo.ID,
  6640. ProductDate: it.ProductDate,
  6641. ExpireDate: it.ExpiryDate,
  6642. StorehouseId: houseConfig.StorehouseOutInfo,
  6643. OverCount: flush_count_one,
  6644. OperateTime: time.Now().Unix(),
  6645. }
  6646. service.CreateStockFlowOne(flow)
  6647. //if flow.ID > 0 {
  6648. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6649. //}
  6650. }
  6651. }
  6652. //flow := models.VmStockFlow{
  6653. // WarehousingId: info.WarehouseInfotId,
  6654. // GoodId: item.ProjectId,
  6655. // Number: info.Number,
  6656. // LicenseNumber: info.LicenseNumber,
  6657. // Count: prescribingNumber,
  6658. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6659. // PatientId: item.PatientId,
  6660. // SystemTime: info.SysRecordTime,
  6661. // ConsumableType: 7,
  6662. // IsSys: 0,
  6663. // WarehousingOrder: "",
  6664. // WarehouseOutId: info.WarehouseOutId,
  6665. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6666. // IsEdit: 0,
  6667. // CancelStockId: cancel.ID,
  6668. // CancelOrderNumber: cancel.OrderNumber,
  6669. // Manufacturer: manufacturer.ID,
  6670. // Dealer: 0,
  6671. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6672. // UpdateCreator: 0,
  6673. // Status: 1,
  6674. // Ctime: time.Now().Unix(),
  6675. // Mtime: 0,
  6676. // Price: info.Price,
  6677. // WarehousingDetailId: info.WarehouseInfotId,
  6678. // WarehouseOutDetailId: info.ID,
  6679. // CancelOutDetailId: cancelInfo.ID,
  6680. // ProductDate: info.ProductDate,
  6681. // ExpireDate: info.ExpiryDate,
  6682. // StorehouseId: houseConfig.StorehouseOutInfo,
  6683. // OverCount: flush_count,
  6684. //}
  6685. //service.CreateStockFlowOne(flow)
  6686. //退库数量增加
  6687. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6688. //出库数量减少
  6689. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6690. //查询已出库数量
  6691. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6692. if prescribingNumber < dialysisInfo.Count {
  6693. //改变数量
  6694. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6695. }
  6696. if prescribingNumber >= dialysisInfo.Count {
  6697. //删除出库表
  6698. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6699. }
  6700. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6701. var flush_count_one int64
  6702. for _, it := range goodList {
  6703. flush_count_one += it.StockCount
  6704. }
  6705. //更新库存
  6706. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6707. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6708. //更新基础库库存
  6709. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6710. }
  6711. }
  6712. }
  6713. }
  6714. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6715. fmt.Println(err)
  6716. }
  6717. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6718. fmt.Println(err)
  6719. if len(advices) > 0 {
  6720. for _, item := range advices {
  6721. redis := service.RedisClient()
  6722. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6723. redis.Set(keyFive, "", time.Second)
  6724. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6725. redis.Set(keyOne, "", time.Second)
  6726. redis.Close()
  6727. }
  6728. }
  6729. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6730. if len(advices) > 0 {
  6731. for _, item := range advices {
  6732. creater := c.GetAdminUserInfo().AdminUser.Id
  6733. service.DrugAutoAddCancelInfo(item, creater)
  6734. }
  6735. }
  6736. } else {
  6737. if drugOutConfig.IsOpen == 1 {
  6738. if len(advices) > 0 {
  6739. for _, item := range advices {
  6740. creater := c.GetAdminUserInfo().AdminUser.Id
  6741. service.DrugAutoAddCancelInfo(item, creater)
  6742. }
  6743. }
  6744. } else {
  6745. if len(advices) > 0 {
  6746. for _, item := range advices {
  6747. creater := c.GetAdminUserInfo().AdminUser.Id
  6748. service.DrugAutoAddCancelInfo(item, creater)
  6749. }
  6750. }
  6751. }
  6752. }
  6753. c.ServeSuccessJSON(map[string]interface{}{
  6754. "msg": "删除成功",
  6755. })
  6756. return
  6757. }
  6758. func (c *HisApiController) DeleteDoctorAdvice() {
  6759. id, _ := c.GetInt64("id")
  6760. advice, _ := service.GetHisDoctorAdvicesById(id)
  6761. ////同步到自备药
  6762. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6763. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6764. if selfPrescriptionOpen.IsOpen == 1 {
  6765. db := service.XTWriteDB()
  6766. tx := db.Begin()
  6767. defer func() {
  6768. if r := recover(); r != nil {
  6769. tx.Rollback()
  6770. } else {
  6771. tx.Commit()
  6772. }
  6773. }()
  6774. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6775. var total_count int64
  6776. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6777. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6778. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6779. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6780. }
  6781. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6782. total_count += prescribingNumberSeven
  6783. }
  6784. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6785. total_count += prescribingNumberSeven
  6786. }
  6787. timeStr := time.Now().Format("2006-01-02")
  6788. timeArr := strings.Split(timeStr, "-")
  6789. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6790. total = total + 1
  6791. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6792. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6793. number = number + total
  6794. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6795. operation_time := time.Now().Unix()
  6796. creater := c.GetAdminUserInfo().AdminUser.Id
  6797. //创建一个出库单
  6798. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6799. WarehouseOutOrderNumber: warehousing_out_order,
  6800. OperationTime: operation_time,
  6801. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6802. Creater: creater,
  6803. Ctime: time.Now().Unix(),
  6804. Status: 1,
  6805. WarehouseOutTime: advice.AdviceDate,
  6806. Type: 0,
  6807. PatientId: advice.PatientId,
  6808. IsCheck: 1,
  6809. }
  6810. //查询今日是否有出库数据
  6811. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6812. if lastWarehouseOut.ID == 0 {
  6813. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6814. }
  6815. //出库
  6816. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6817. WarehouseOutId: lastWarehouseOut.ID,
  6818. WarehouseOutOrderNumber: warehousing_out_order,
  6819. DrugId: advice.DrugId,
  6820. Count: total_count,
  6821. Price: 0,
  6822. TotalPrice: 0,
  6823. Status: 1,
  6824. Ctime: advice.AdviceDate,
  6825. Mtime: advice.AdviceDate,
  6826. Remark: "",
  6827. OrgId: advice.UserOrgId,
  6828. Type: 0,
  6829. Manufacturer: selfBasedrug.Manufacturer,
  6830. Dealer: selfBasedrug.Dealer,
  6831. RetailPrice: 0,
  6832. RetailTotalPrice: 0,
  6833. CountUnit: advice.PrescribingNumberUnit,
  6834. ExpiryDate: 0,
  6835. ProductDate: 0,
  6836. Number: "",
  6837. BatchNumber: "",
  6838. IsSys: 0,
  6839. WarehouseInfoId: 0,
  6840. AdminUserId: 0,
  6841. StockCount: "",
  6842. IsCheck: 1,
  6843. SysRecordTime: advice.AdviceDate,
  6844. PatientId: advice.PatientId,
  6845. AdviceId: advice.ID,
  6846. ClassType: "",
  6847. }
  6848. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6849. for _, it := range warehousingOutInfo {
  6850. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6851. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6852. //出库逻辑
  6853. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6854. //查询剩余库存
  6855. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6856. var sum_count int64
  6857. for _, its := range stockInfo {
  6858. if its.MaxUnit == medical.MaxUnit {
  6859. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6860. }
  6861. sum_count += its.StockMaxNumber + its.StockMinNumber
  6862. }
  6863. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6864. }
  6865. }
  6866. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6867. //已收费和已发药的限制逻辑
  6868. isCharge := false
  6869. isMedicine := false
  6870. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6871. //获取今天该患者所有处方,判断是否发药或者收费
  6872. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6873. //for _, item := range new_prescriptions {
  6874. if new_prescription.IsMedicine == 1 {
  6875. isMedicine = true
  6876. }
  6877. //}
  6878. for _, item := range new_prescriptions {
  6879. if item.OrderStatus == 4 {
  6880. isCharge = true
  6881. }
  6882. }
  6883. if isMedicine {
  6884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6885. return
  6886. }
  6887. if isCharge {
  6888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6889. return
  6890. }
  6891. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6892. creater := c.GetAdminUserInfo().AdminUser.Id
  6893. for _, item := range advices {
  6894. if item.IsMedicine == 1 {
  6895. isMedicine = true
  6896. }
  6897. byterequest, _ := json.Marshal(item)
  6898. adviceLog := models.XtDoctorAdviceLog{
  6899. UserOrgId: item.UserOrgId,
  6900. PatientId: item.PatientId,
  6901. AdminUserId: creater,
  6902. Module: 1,
  6903. ErrLog: string(byterequest),
  6904. Status: 1,
  6905. Ctime: time.Now().Unix(),
  6906. Mtime: 0,
  6907. Source: "电脑端删除医嘱",
  6908. RecordDate: item.AdviceDate,
  6909. }
  6910. service.CreateDoctorAdviceLog(adviceLog)
  6911. }
  6912. if isMedicine {
  6913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6914. return
  6915. }
  6916. if new_prescription.ID > 0 {
  6917. if new_prescription.OrderStatus == 2 {
  6918. isCharge = true
  6919. }
  6920. }
  6921. if isCharge {
  6922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6923. return
  6924. }
  6925. //已收费和已发药的限制逻辑
  6926. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6927. redis := service.RedisClient()
  6928. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6929. redis.Set(keyFive, "", time.Second)
  6930. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6931. redis.Set(keyOne, "", time.Second)
  6932. defer redis.Close()
  6933. if err == nil {
  6934. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6935. //查询是否在处方中出库
  6936. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6937. if openConfig.IsOpen != 1 {
  6938. //判断该医嘱是否执行了
  6939. if advice.ExecutionState == 1 {
  6940. creater := c.GetAdminUserInfo().AdminUser.Id
  6941. service.DrugAutoAddCancelInfo(&advice, creater)
  6942. }
  6943. }
  6944. //开启保存处方扣减功能
  6945. if openConfig.IsOpen == 1 {
  6946. creater := c.GetAdminUserInfo().AdminUser.Id
  6947. service.DrugAutoAddCancelInfo(&advice, creater)
  6948. }
  6949. } else {
  6950. if drugOutConfig.IsOpen == 1 {
  6951. //查询是否在处方中出库
  6952. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6953. if openConfig.IsOpen != 1 {
  6954. //判断该医嘱是否执行了
  6955. if advice.ExecutionState == 1 {
  6956. creater := c.GetAdminUserInfo().AdminUser.Id
  6957. service.DrugAutoAddCancelInfo(&advice, creater)
  6958. }
  6959. }
  6960. //开启保存处方扣减功能
  6961. if openConfig.IsOpen == 1 {
  6962. creater := c.GetAdminUserInfo().AdminUser.Id
  6963. service.DrugAutoAddCancelInfo(&advice, creater)
  6964. }
  6965. } else {
  6966. //判断该医嘱是否执行了
  6967. if advice.ExecutionState == 1 {
  6968. creater := c.GetAdminUserInfo().AdminUser.Id
  6969. service.DrugAutoAddCancelInfo(&advice, creater)
  6970. }
  6971. }
  6972. }
  6973. c.ServeSuccessJSON(map[string]interface{}{
  6974. "msg": "删除成功",
  6975. })
  6976. return
  6977. } else {
  6978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6979. return
  6980. }
  6981. }
  6982. func (c *HisApiController) DeleteProject() {
  6983. id, _ := c.GetInt64("id")
  6984. adminInfo := c.GetAdminUserInfo()
  6985. project, _ := service.GetHisProjectByID(id)
  6986. // var consumable models.DialysisBeforePrepare
  6987. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6988. //耗材保存处方出库
  6989. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6990. isCharge := false
  6991. isMedicine := false
  6992. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6993. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6994. creater := c.GetAdminUserInfo().AdminUser.Id
  6995. for _, item := range new_prescriptions {
  6996. if item.IsMedicine == 1 {
  6997. isMedicine = true
  6998. }
  6999. byterequest, _ := json.Marshal(item)
  7000. adviceLog := models.XtDoctorAdviceLog{
  7001. UserOrgId: item.UserOrgId,
  7002. PatientId: item.PatientId,
  7003. AdminUserId: creater,
  7004. Module: 1,
  7005. ErrLog: string(byterequest),
  7006. Status: 1,
  7007. Ctime: time.Now().Unix(),
  7008. Mtime: 0,
  7009. Source: "电脑端删除医嘱",
  7010. RecordDate: item.RecordDate,
  7011. }
  7012. service.CreateDoctorAdviceLog(adviceLog)
  7013. }
  7014. for _, item := range new_prescriptions {
  7015. if item.OrderStatus == 4 {
  7016. isCharge = true
  7017. }
  7018. }
  7019. if isMedicine {
  7020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  7021. return
  7022. }
  7023. if isCharge {
  7024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  7025. return
  7026. }
  7027. if new_prescription.ID > 0 {
  7028. if new_prescription.OrderStatus == 2 {
  7029. isCharge = true
  7030. }
  7031. }
  7032. if isCharge {
  7033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  7034. return
  7035. }
  7036. service.DeletePrintInfo(id)
  7037. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  7038. label.Status = 0
  7039. service.CreateHisLabelRecordTwo(&label)
  7040. fmt.Println(goodOutConfig.IsOpen)
  7041. if goodOutConfig.IsOpen != 1 {
  7042. if stockConfig.IsOpen == 1 {
  7043. if project.Type == 2 {
  7044. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7045. fmt.Println(err)
  7046. }
  7047. if project.Type == 3 && project.IsOut == 1 {
  7048. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7049. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7050. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7051. operation_time := time.Now().Unix()
  7052. creater := adminInfo.AdminUser.Id
  7053. //创建退库单
  7054. timeStr := time.Now().Format("2006-01-02")
  7055. timeArr := strings.Split(timeStr, "-")
  7056. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7057. total = total + 1
  7058. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7059. cancelStock := models.CancelStock{
  7060. OrderNumber: orderNumber,
  7061. OperaTime: operation_time,
  7062. OrgId: adminInfo.CurrentOrgId,
  7063. Creater: creater,
  7064. Ctime: time.Now().Unix(),
  7065. Status: 1,
  7066. ReturnTime: project.RecordDate,
  7067. Type: 1,
  7068. StorehouseId: houseConfig.StorehouseOutInfo,
  7069. IsCheck: 1,
  7070. }
  7071. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7072. if msgerrkonde == gorm.ErrRecordNotFound {
  7073. service.AddSigleCancelStock(&cancelStock)
  7074. }
  7075. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7076. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7077. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7078. //查询是否有出库
  7079. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7080. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7081. deaerler, _ := service.GetDealerById(info.Dealer)
  7082. if info.ID > 0 {
  7083. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7084. if info.Count >= prescribingNumber {
  7085. cancelStockInfo := models.CancelStockInfo{
  7086. GoodId: project.ProjectId,
  7087. CancelStockId: cancel.ID,
  7088. GoodTypeId: good.GoodTypeId,
  7089. Count: prescribingNumber,
  7090. Price: info.Price,
  7091. Total: 0,
  7092. ProductDate: info.ProductDate,
  7093. ExpiryDate: info.ExpiryDate,
  7094. Ctime: time.Now().Unix(),
  7095. Status: 1,
  7096. OrgId: adminInfo.CurrentOrgId,
  7097. OrderNumber: cancel.OrderNumber,
  7098. Type: 0,
  7099. Dealer: deaerler.DealerName,
  7100. Manufacturer: manufacturer.ManufacturerName,
  7101. Number: info.Number,
  7102. RegisterAccount: "",
  7103. Remark: "",
  7104. WarehouseInfoId: info.WarehouseInfotId,
  7105. PatientId: info.PatientId,
  7106. RecordDate: info.SysRecordTime,
  7107. StorehouseId: houseConfig.StorehouseOutInfo,
  7108. IsCheck: 1,
  7109. }
  7110. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7111. //回退库存
  7112. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  7113. //退库数量增加
  7114. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7115. //出库数量减少
  7116. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7117. }
  7118. if info.Count < prescribingNumber {
  7119. cancelStockInfo := models.CancelStockInfo{
  7120. GoodId: project.ProjectId,
  7121. CancelStockId: cancel.ID,
  7122. GoodTypeId: good.GoodTypeId,
  7123. Count: info.Count,
  7124. Price: info.Price,
  7125. Total: 0,
  7126. ProductDate: info.ProductDate,
  7127. ExpiryDate: info.ExpiryDate,
  7128. Ctime: time.Now().Unix(),
  7129. Status: 1,
  7130. OrgId: adminInfo.CurrentOrgId,
  7131. OrderNumber: cancel.OrderNumber,
  7132. Type: 0,
  7133. Dealer: deaerler.DealerName,
  7134. Manufacturer: manufacturer.ManufacturerName,
  7135. Number: info.Number,
  7136. RegisterAccount: "",
  7137. Remark: "",
  7138. WarehouseInfoId: info.WarehouseInfotId,
  7139. PatientId: info.PatientId,
  7140. RecordDate: info.SysRecordTime,
  7141. StorehouseId: houseConfig.StorehouseOutInfo,
  7142. IsCheck: 1,
  7143. }
  7144. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7145. //回退库存
  7146. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7147. //退库数量增加
  7148. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  7149. //出库数量减少
  7150. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  7151. }
  7152. //查询剩余库存
  7153. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7154. var over_count int64
  7155. for _, it := range goodList {
  7156. over_count += it.StockCount
  7157. }
  7158. //出库数据 大于 退库数量
  7159. if info.Count >= prescribingNumber {
  7160. flow := models.VmStockFlow{
  7161. WarehousingId: info.WarehouseInfotId,
  7162. GoodId: project.ProjectId,
  7163. Number: info.Number,
  7164. LicenseNumber: info.LicenseNumber,
  7165. Count: prescribingNumber,
  7166. UserOrgId: adminInfo.CurrentOrgId,
  7167. PatientId: project.PatientId,
  7168. SystemTime: info.SysRecordTime,
  7169. ConsumableType: 7,
  7170. IsSys: 0,
  7171. WarehousingOrder: "",
  7172. WarehouseOutId: info.WarehouseOutId,
  7173. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7174. IsEdit: 0,
  7175. CancelStockId: cancel.ID,
  7176. CancelOrderNumber: cancel.OrderNumber,
  7177. Manufacturer: manufacturer.ID,
  7178. Dealer: 0,
  7179. Creator: adminInfo.AdminUser.Id,
  7180. UpdateCreator: 0,
  7181. Status: 1,
  7182. Ctime: time.Now().Unix(),
  7183. Mtime: 0,
  7184. Price: info.Price,
  7185. WarehousingDetailId: info.WarehouseInfotId,
  7186. WarehouseOutDetailId: info.ID,
  7187. CancelOutDetailId: cancelInfo.ID,
  7188. ProductDate: info.ProductDate,
  7189. ExpireDate: info.ExpiryDate,
  7190. StorehouseId: houseConfig.StorehouseOutInfo,
  7191. OverCount: over_count,
  7192. OperateTime: time.Now().Unix(),
  7193. }
  7194. service.CreateStockFlowOne(flow)
  7195. }
  7196. //出库数据小于退库数据
  7197. if info.Count < prescribingNumber {
  7198. flow := models.VmStockFlow{
  7199. WarehousingId: info.WarehouseInfotId,
  7200. GoodId: project.ProjectId,
  7201. Number: info.Number,
  7202. LicenseNumber: info.LicenseNumber,
  7203. Count: info.Count,
  7204. UserOrgId: adminInfo.CurrentOrgId,
  7205. PatientId: project.PatientId,
  7206. SystemTime: info.SysRecordTime,
  7207. ConsumableType: 7,
  7208. IsSys: 0,
  7209. WarehousingOrder: "",
  7210. WarehouseOutId: info.WarehouseOutId,
  7211. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7212. IsEdit: 0,
  7213. CancelStockId: cancel.ID,
  7214. CancelOrderNumber: cancel.OrderNumber,
  7215. Manufacturer: manufacturer.ID,
  7216. Dealer: 0,
  7217. Creator: adminInfo.AdminUser.Id,
  7218. UpdateCreator: 0,
  7219. Status: 1,
  7220. Ctime: time.Now().Unix(),
  7221. Mtime: 0,
  7222. Price: info.Price,
  7223. WarehousingDetailId: info.WarehouseInfotId,
  7224. WarehouseOutDetailId: info.ID,
  7225. CancelOutDetailId: cancelInfo.ID,
  7226. ProductDate: info.ProductDate,
  7227. ExpireDate: info.ExpiryDate,
  7228. StorehouseId: houseConfig.StorehouseOutInfo,
  7229. OverCount: over_count,
  7230. OperateTime: time.Now().Unix(),
  7231. }
  7232. service.CreateStockFlowOne(flow)
  7233. }
  7234. //查询已出库数量
  7235. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7236. if prescribingNumber < dialysisInfo.Count {
  7237. //改变数量
  7238. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7239. }
  7240. if prescribingNumber >= dialysisInfo.Count {
  7241. //删除出库表
  7242. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7243. }
  7244. //更新剩余库存
  7245. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7246. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7247. var total_count_one int64
  7248. for _, it := range stockList {
  7249. total_count_one += it.StockCount
  7250. }
  7251. //基础库插入数据
  7252. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7253. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7254. var flush_count int64
  7255. for _, it := range goodListOne {
  7256. flush_count += it.StockCount
  7257. }
  7258. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7259. if errs != nil {
  7260. goodErrcode := models.XtGoodErrcode{
  7261. UserOrgId: project.UserOrgId,
  7262. Errcode: "手动出库更新剩余出库失败",
  7263. GoodId: project.ProjectId,
  7264. Status: 1,
  7265. Ctime: time.Now().Unix(),
  7266. Mtime: 0,
  7267. Count: 0,
  7268. StockCount: 0,
  7269. Creater: creater,
  7270. BatchNumberId: 0,
  7271. WarehouseOutId: 0,
  7272. }
  7273. service.CreateGoodErrcode(goodErrcode)
  7274. }
  7275. }
  7276. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7277. fmt.Println(err)
  7278. } else {
  7279. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7280. fmt.Println(err)
  7281. }
  7282. } else {
  7283. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7284. fmt.Println(err)
  7285. }
  7286. }
  7287. //保存处方出库
  7288. if goodOutConfig.IsOpen == 1 {
  7289. if project.Type == 3 {
  7290. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7291. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7292. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7293. operation_time := time.Now().Unix()
  7294. creater := adminInfo.AdminUser.Id
  7295. //创建退库单
  7296. timeStr := time.Now().Format("2006-01-02")
  7297. timeArr := strings.Split(timeStr, "-")
  7298. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7299. total = total + 1
  7300. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7301. cancelStock := models.CancelStock{
  7302. OrderNumber: orderNumber,
  7303. OperaTime: operation_time,
  7304. OrgId: adminInfo.CurrentOrgId,
  7305. Creater: creater,
  7306. Ctime: time.Now().Unix(),
  7307. Status: 1,
  7308. ReturnTime: project.RecordDate,
  7309. Type: 1,
  7310. StorehouseId: houseConfig.StorehouseOutInfo,
  7311. IsCheck: 1,
  7312. }
  7313. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7314. if msgerrkonde == gorm.ErrRecordNotFound {
  7315. service.AddSigleCancelStock(&cancelStock)
  7316. }
  7317. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7318. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7319. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7320. //获取出库数据
  7321. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7322. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7323. deaerler, _ := service.GetDealerById(info.Dealer)
  7324. if info.ID > 0 {
  7325. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7326. if info.Count >= prescribingNumber {
  7327. cancelStockInfo := models.CancelStockInfo{
  7328. GoodId: project.ProjectId,
  7329. CancelStockId: cancel.ID,
  7330. GoodTypeId: good.GoodTypeId,
  7331. Count: prescribingNumber,
  7332. Price: info.Price,
  7333. Total: 0,
  7334. ProductDate: info.ProductDate,
  7335. ExpiryDate: info.ExpiryDate,
  7336. Ctime: time.Now().Unix(),
  7337. Status: 1,
  7338. OrgId: adminInfo.CurrentOrgId,
  7339. OrderNumber: cancel.OrderNumber,
  7340. Type: 0,
  7341. Dealer: deaerler.DealerName,
  7342. Manufacturer: manufacturer.ManufacturerName,
  7343. Number: info.Number,
  7344. RegisterAccount: "",
  7345. Remark: "",
  7346. WarehouseInfoId: info.WarehouseInfotId,
  7347. PatientId: info.PatientId,
  7348. RecordDate: info.SysRecordTime,
  7349. StorehouseId: houseConfig.StorehouseOutInfo,
  7350. IsCheck: 1,
  7351. }
  7352. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7353. //退库数量增加
  7354. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7355. //出库数量减少
  7356. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7357. }
  7358. if info.Count < prescribingNumber {
  7359. cancelStockInfo := models.CancelStockInfo{
  7360. GoodId: project.ProjectId,
  7361. CancelStockId: cancel.ID,
  7362. GoodTypeId: good.GoodTypeId,
  7363. Count: prescribingNumber,
  7364. Price: info.Price,
  7365. Total: 0,
  7366. ProductDate: info.ProductDate,
  7367. ExpiryDate: info.ExpiryDate,
  7368. Ctime: time.Now().Unix(),
  7369. Status: 1,
  7370. OrgId: adminInfo.CurrentOrgId,
  7371. OrderNumber: cancel.OrderNumber,
  7372. Type: 0,
  7373. Dealer: deaerler.DealerName,
  7374. Manufacturer: manufacturer.ManufacturerName,
  7375. Number: info.Number,
  7376. RegisterAccount: "",
  7377. Remark: "",
  7378. WarehouseInfoId: info.WarehouseInfotId,
  7379. PatientId: info.PatientId,
  7380. RecordDate: info.SysRecordTime,
  7381. StorehouseId: houseConfig.StorehouseOutInfo,
  7382. IsCheck: 1,
  7383. }
  7384. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7385. //回退库存
  7386. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7387. }
  7388. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7389. var over_count int64
  7390. for _, it := range goodList {
  7391. over_count += it.StockCount
  7392. }
  7393. //查询出库数量
  7394. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  7395. //出库数据 大于 退库数量
  7396. if len(list) > 0 {
  7397. for _, it := range list {
  7398. //回退库存
  7399. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  7400. //退库数量增加
  7401. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  7402. //出库数量减少
  7403. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  7404. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7405. var over_count_one int64
  7406. for _, it := range goodList {
  7407. over_count_one += it.StockCount
  7408. }
  7409. //查询该批次是否有退库数据
  7410. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  7411. flow := models.VmStockFlow{
  7412. WarehousingId: it.WarehouseInfotId,
  7413. GoodId: it.GoodId,
  7414. Number: it.Number,
  7415. LicenseNumber: it.LicenseNumber,
  7416. Count: it.Count,
  7417. UserOrgId: adminInfo.CurrentOrgId,
  7418. PatientId: it.PatientId,
  7419. SystemTime: it.SysRecordTime,
  7420. ConsumableType: 7,
  7421. IsSys: 0,
  7422. WarehousingOrder: "",
  7423. WarehouseOutId: it.WarehouseOutId,
  7424. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7425. IsEdit: 0,
  7426. CancelStockId: cancel.ID,
  7427. CancelOrderNumber: cancel.OrderNumber,
  7428. Manufacturer: manufacturer.ID,
  7429. Dealer: 0,
  7430. Creator: adminInfo.AdminUser.Id,
  7431. UpdateCreator: 0,
  7432. Status: 1,
  7433. Ctime: time.Now().Unix(),
  7434. Mtime: 0,
  7435. Price: it.Price,
  7436. WarehousingDetailId: it.WarehouseInfotId,
  7437. WarehouseOutDetailId: it.ID,
  7438. CancelOutDetailId: cancelInfo.ID,
  7439. ProductDate: it.ProductDate,
  7440. ExpireDate: it.ExpiryDate,
  7441. StorehouseId: houseConfig.StorehouseOutInfo,
  7442. OverCount: over_count_one,
  7443. OperateTime: time.Now().Unix(),
  7444. }
  7445. service.CreateStockFlowOne(flow)
  7446. }
  7447. }
  7448. //查询已出库数量
  7449. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7450. if prescribingNumber < dialysisInfo.Count {
  7451. //改变数量
  7452. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7453. }
  7454. if prescribingNumber >= dialysisInfo.Count {
  7455. //删除出库表
  7456. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7457. }
  7458. //更新剩余库存
  7459. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7460. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7461. var total_count_one int64
  7462. for _, it := range stockList {
  7463. total_count_one += it.StockCount
  7464. }
  7465. //基础库插入数据
  7466. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7467. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7468. var flush_count int64
  7469. for _, it := range goodListOne {
  7470. flush_count += it.StockCount
  7471. }
  7472. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7473. if errs != nil {
  7474. goodErrcode := models.XtGoodErrcode{
  7475. UserOrgId: project.UserOrgId,
  7476. Errcode: "手动出库更新剩余出库失败",
  7477. GoodId: project.ProjectId,
  7478. Status: 1,
  7479. Ctime: time.Now().Unix(),
  7480. Mtime: 0,
  7481. Count: 0,
  7482. StockCount: 0,
  7483. Creater: creater,
  7484. BatchNumberId: 0,
  7485. WarehouseOutId: 0,
  7486. }
  7487. service.CreateGoodErrcode(goodErrcode)
  7488. }
  7489. }
  7490. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7491. fmt.Println(err)
  7492. } else {
  7493. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7494. fmt.Println(err)
  7495. }
  7496. }
  7497. c.ServeSuccessJSON(map[string]interface{}{
  7498. "msg": "删除成功",
  7499. })
  7500. return
  7501. }
  7502. func (c *HisApiController) CreateHisAdditionalCharge() {
  7503. his_patient_id, _ := c.GetInt64("his_patient_id")
  7504. patient_id, _ := c.GetInt64("patient_id")
  7505. record_date := c.GetString("record_date")
  7506. timeLayout := "2006-01-02"
  7507. loc, _ := time.LoadLocation("Local")
  7508. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7509. if err != nil {
  7510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7511. return
  7512. }
  7513. adminInfo := c.GetAdminUserInfo()
  7514. recordDateTime := theTime.Unix()
  7515. dataBody := make(map[string]interface{}, 0)
  7516. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7517. if err != nil {
  7518. utils.ErrorLog(err.Error())
  7519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7520. return
  7521. }
  7522. var additions []*models.HisAdditionalCharge
  7523. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7524. additions, _ := dataBody["addition"].([]interface{})
  7525. if len(additions) > 0 {
  7526. for _, item := range additions {
  7527. items := item.(map[string]interface{})
  7528. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7529. utils.ErrorLog("item_id")
  7530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7531. return
  7532. }
  7533. item_id := int64(items["item_id"].(float64))
  7534. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7535. utils.ErrorLog("item_name")
  7536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7537. return
  7538. }
  7539. item_name := items["item_name"].(string)
  7540. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7541. utils.ErrorLog("price")
  7542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7543. return
  7544. }
  7545. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7546. ctime := time.Now().Unix()
  7547. additional := &models.HisAdditionalCharge{
  7548. PatientId: patient_id,
  7549. HisPatientId: his_patient_id,
  7550. UserOrgId: adminInfo.CurrentOrgId,
  7551. RecordDate: recordDateTime,
  7552. CreatedTime: ctime,
  7553. UpdatedTime: ctime,
  7554. Modifier: adminInfo.AdminUser.Id,
  7555. Creator: adminInfo.AdminUser.Id,
  7556. Price: price,
  7557. ItemName: item_name,
  7558. ItemId: item_id,
  7559. Status: 1,
  7560. }
  7561. additions = append(additions, additional)
  7562. }
  7563. }
  7564. }
  7565. for _, item := range additions {
  7566. service.CreateAddtionalCharge(item)
  7567. }
  7568. c.ServeSuccessJSON(map[string]interface{}{
  7569. "msg": "创建成功",
  7570. })
  7571. }
  7572. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7573. blood_fat := c.GetString("blood_fat")
  7574. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7575. blood_sugar := c.GetString("blood_sugar")
  7576. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7577. chief_conplaint := c.GetString("chief_conplaint")
  7578. dbp := c.GetString("dbp")
  7579. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7580. delivery_way, _ := c.GetInt64("delivery_way")
  7581. diagnostic := c.GetString("diagnostic")
  7582. family_history := c.GetString("family_history")
  7583. height := c.GetString("height")
  7584. history_of_present_illness := c.GetString("history_of_present_illness")
  7585. is_infect, _ := c.GetInt64("is_infect")
  7586. past_history := c.GetString("past_history")
  7587. patient_id, _ := c.GetInt64("patient_id")
  7588. his_patient_id, _ := c.GetInt64("his_patient_id")
  7589. personal_history := c.GetString("personal_history")
  7590. pulse := c.GetString("pulse")
  7591. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7592. sbp := c.GetString("sbp")
  7593. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7594. heightfloat, _ := strconv.ParseFloat(height, 64)
  7595. sicktype := c.GetString("sick_type")
  7596. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7597. symptom := c.GetString("symptom")
  7598. sick_date := c.GetString("sick_date")
  7599. temperatures := c.GetString("temperature")
  7600. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7601. record_date := c.GetString("record_date")
  7602. breathing := c.GetString("breathing")
  7603. doctor_advice := c.GetString("doctor_advice")
  7604. remark := c.GetString("remark")
  7605. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7606. sick, _ := c.GetInt64("sick")
  7607. diagnose, _ := c.GetInt64("diagnose")
  7608. //id, _ := c.GetInt64("id")
  7609. timeLayout := "2006-01-02"
  7610. loc, _ := time.LoadLocation("Local")
  7611. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7612. allergic_history := c.GetString("allergic_history")
  7613. if err != nil {
  7614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7615. return
  7616. }
  7617. recordDateTime := theTime.Unix()
  7618. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7619. if err != nil {
  7620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7621. return
  7622. }
  7623. sickTimes := sickTime.Unix()
  7624. ctime := time.Now().Unix()
  7625. primary_disease := c.GetString("primary_disease")
  7626. confirm_failure_date := c.GetString("confirm_failure_date")
  7627. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7628. drug_allergy_history := c.GetString("drug_allergy_history")
  7629. physical_examination := c.GetString("physical_examination")
  7630. special_inspection := c.GetString("special_inspection")
  7631. lab_apparatus := c.GetString("lab_apparatus")
  7632. caseHistory := models.HisPatientCaseHistory{
  7633. HisPatientId: his_patient_id,
  7634. PatientId: patient_id,
  7635. Temperature: temperature,
  7636. BloodSugar: bloodsugarfloat,
  7637. Pulse: pulsefloat,
  7638. Sbp: sbpfloat,
  7639. Dbp: dbpfloat,
  7640. Height: heightfloat,
  7641. BloodFat: bloodfatfloat,
  7642. SickType: sick_type,
  7643. Symptom: symptom,
  7644. SickDate: sickTimes,
  7645. IsInfect: is_infect,
  7646. HistoryOfPresentIllness: history_of_present_illness,
  7647. PastHistory: past_history,
  7648. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7649. ChiefConplaint: chief_conplaint,
  7650. PersonalHistory: personal_history,
  7651. FamilyHistory: family_history,
  7652. Diagnostic: diagnostic,
  7653. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7654. Status: 1,
  7655. Ctime: ctime,
  7656. Mtime: ctime,
  7657. RecordDate: recordDateTime,
  7658. DeliveryWay: delivery_way,
  7659. Breathing: breathingfloat,
  7660. DoctorAdvice: doctor_advice,
  7661. Remark: remark,
  7662. Sick: sick,
  7663. Diagnose: diagnose,
  7664. AllergicHistory: allergic_history,
  7665. PrimaryDisease: primary_disease,
  7666. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7667. DrugAllergyHistory: drug_allergy_history,
  7668. PhysicalExamination: physical_examination,
  7669. SpecialInspection: special_inspection,
  7670. LabApparatus: lab_apparatus,
  7671. }
  7672. //查询该患者是否有病历
  7673. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7674. if errcodes == gorm.ErrRecordNotFound {
  7675. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7676. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7677. if err != nil {
  7678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7679. return
  7680. }
  7681. c.ServeSuccessJSON(map[string]interface{}{
  7682. "caseHistory": caseHistory,
  7683. "historyInfo": historyInfo,
  7684. })
  7685. return
  7686. } else if errcodes == nil {
  7687. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7688. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7689. if err != nil {
  7690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7691. return
  7692. }
  7693. c.ServeSuccessJSON(map[string]interface{}{
  7694. "caseHistory": caseHistory,
  7695. "historyInfo": historyInfo,
  7696. })
  7697. }
  7698. //查询该患者是否有病历
  7699. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7700. //if errcode == gorm.ErrRecordNotFound {
  7701. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7702. // if err != nil {
  7703. // c.ServeSuccessJSON(map[string]interface{}{
  7704. // "msg": "保存成功",
  7705. // })
  7706. // }
  7707. //} else if errcode == nil {
  7708. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7709. // return
  7710. //}
  7711. }
  7712. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7713. patient_id, _ := c.GetInt64("patient_id", 0)
  7714. adminUser := c.GetAdminUserInfo()
  7715. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7716. c.ServeSuccessJSON(map[string]interface{}{
  7717. "list": caseHistorys,
  7718. })
  7719. }
  7720. func (c *HisApiController) GetHisPatientCaseHistory() {
  7721. record_date, _ := c.GetInt64("record_date", 0)
  7722. patient_id, _ := c.GetInt64("patient_id", 0)
  7723. admin := c.GetAdminUserInfo()
  7724. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7725. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7726. c.ServeSuccessJSON(map[string]interface{}{
  7727. "info": info,
  7728. "case_history": case_history,
  7729. })
  7730. }
  7731. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7732. template_name := c.GetString("template_name")
  7733. template_remark := c.GetString("template_remark")
  7734. doctor := c.GetAdminUserInfo().AdminUser.Id
  7735. diagnostic := c.GetString("diagnostic")
  7736. chief_conplaint := c.GetString("chief_conplain")
  7737. history_of_present_illness := c.GetString("history_of_present_illness")
  7738. past_history := c.GetString("past_history")
  7739. personal_history := c.GetString("personal_history")
  7740. family_history := c.GetString("family_history")
  7741. user_name := c.GetString("user_name")
  7742. doctor_advice := c.GetString("doctor_advice")
  7743. remark := c.GetString("remark")
  7744. //record_date := c.GetString("record_date")
  7745. //fmt.Println("record_date--------",record_date)
  7746. //timeLayout := "2006-01-02"
  7747. //loc, _ := time.LoadLocation("Local")
  7748. //
  7749. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7750. //if err != nil {
  7751. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7752. // return
  7753. //}
  7754. //recordDateTime := theTime.Unix()
  7755. ctime := time.Now().Unix()
  7756. template := models.HisCaseHistoryTemplate{
  7757. HistoryOfPresentIllness: history_of_present_illness,
  7758. PastHistory: past_history,
  7759. ChiefConplaint: chief_conplaint,
  7760. PersonalHistory: personal_history,
  7761. FamilyHistory: family_history,
  7762. Diagnostic: diagnostic,
  7763. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7764. Status: 1,
  7765. Ctime: ctime,
  7766. Mtime: ctime,
  7767. RecordDate: time.Now().Unix(),
  7768. TemplateName: template_name,
  7769. TemplateRemark: template_remark,
  7770. Creator: doctor,
  7771. Modifier: doctor,
  7772. UserName: user_name,
  7773. DoctorAdvice: doctor_advice,
  7774. Remark: remark,
  7775. }
  7776. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7777. if err == nil {
  7778. c.ServeSuccessJSON(map[string]interface{}{
  7779. "msg": "保存成功",
  7780. })
  7781. } else {
  7782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7783. return
  7784. }
  7785. }
  7786. func (c *HisApiController) GetCaseHistoryTemplate() {
  7787. timeLayout := "2006-01-02"
  7788. loc, _ := time.LoadLocation("Local")
  7789. keyword := c.GetString("keyword")
  7790. start_time := c.GetString("start_time")
  7791. end_time := c.GetString("end_time")
  7792. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7793. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7794. admin := c.GetAdminUserInfo()
  7795. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7796. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7797. c.ServeSuccessJSON(map[string]interface{}{
  7798. "template": template,
  7799. //"history": history,
  7800. })
  7801. }
  7802. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7803. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7804. utils.ErrorLog("drug_name")
  7805. return enums.ErrorCodeParamWrong
  7806. }
  7807. adviceName, _ := json["drug_name"].(string)
  7808. if len(adviceName) == 0 {
  7809. utils.ErrorLog("len(advice_name) == 0")
  7810. return enums.ErrorCodeParamWrong
  7811. }
  7812. advice.AdviceName = adviceName
  7813. adviceDesc, _ := json["advice_desc"].(string)
  7814. advice.AdviceDesc = adviceDesc
  7815. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7816. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7817. advice.DrugSpec = drugSpec
  7818. }
  7819. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7820. remark, _ := json["remark"].(string)
  7821. advice.Remark = remark
  7822. }
  7823. if json["id"] == nil {
  7824. advice.DrugId = 0
  7825. } else {
  7826. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7827. drug_id := int64(json["id"].(float64))
  7828. advice.DrugId = drug_id
  7829. }
  7830. }
  7831. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7832. advice_id := int64(json["advice_id"].(float64))
  7833. advice.ID = advice_id
  7834. if advice.ID > 0 {
  7835. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7836. if err == nil {
  7837. if hisAdvice.ID > 0 {
  7838. advice.ExecutionTime = hisAdvice.ExecutionTime
  7839. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7840. advice.ExecutionState = hisAdvice.ExecutionState
  7841. advice.CheckTime = hisAdvice.CheckTime
  7842. advice.Checker = hisAdvice.Checker
  7843. advice.CheckState = hisAdvice.CheckState
  7844. advice.StartTime = hisAdvice.StartTime
  7845. advice.FeedetlSn = hisAdvice.FeedetlSn
  7846. }
  7847. }
  7848. }
  7849. }
  7850. //
  7851. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7852. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7853. // advice.ExecutionTime = execution_time
  7854. //}
  7855. //
  7856. //
  7857. //
  7858. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7859. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7860. // advice.ExecutionStaff = execution_staff
  7861. //}
  7862. //
  7863. //
  7864. //
  7865. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7866. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7867. // advice.ExecutionState = execution_state
  7868. //}
  7869. //
  7870. //
  7871. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7872. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7873. // advice.CheckTime = check_time
  7874. //}
  7875. //
  7876. //
  7877. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7878. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7879. // advice.CheckState = check_state
  7880. //}
  7881. //
  7882. //
  7883. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7884. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7885. // advice.Checker = checker
  7886. //}
  7887. //
  7888. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7889. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7890. // advice.StartTime = start_time
  7891. //}
  7892. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7893. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7894. advice.IsSelfDrug = is_self_drug
  7895. }
  7896. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7897. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7898. drug_way_count, _ := json["drug_way_count"].(string)
  7899. advice.DrugWayCount = drug_way_count
  7900. }
  7901. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7902. drugSpecUnit, _ := json["min_unit"].(string)
  7903. advice.DrugSpecUnit = drugSpecUnit
  7904. }
  7905. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7906. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7907. advice.SingleDose = singleDose
  7908. }
  7909. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7910. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7911. advice.SingleDoseUnit = singleDoseUnit
  7912. }
  7913. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7914. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7915. advice.PrescribingNumber = prescribingNumber
  7916. }
  7917. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7918. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7919. advice.PrescribingNumberUnit = prescribingNumberUnit
  7920. }
  7921. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7922. deliveryWay, _ := json["delivery_way"].(string)
  7923. advice.DeliveryWay = deliveryWay
  7924. }
  7925. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7926. executionFrequency, _ := json["execution_frequency"].(string)
  7927. advice.ExecutionFrequency = executionFrequency
  7928. }
  7929. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7930. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7931. advice.Price = price
  7932. }
  7933. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7934. med_list_codg, _ := json["medical_insurance_number"].(string)
  7935. advice.MedListCodg = med_list_codg
  7936. }
  7937. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7938. day := int64(json["day"].(float64))
  7939. advice.Day = day
  7940. }
  7941. return 0
  7942. }
  7943. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7944. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7945. id := int64(json["id"].(float64))
  7946. project.ID = id
  7947. historyProject, _ := service.GetHisProjectByID(id)
  7948. project.FeedetlSn = historyProject.FeedetlSn
  7949. }
  7950. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7951. project_id := int64(json["project_id"].(float64))
  7952. project.ProjectId = project_id
  7953. }
  7954. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7955. // price := int64(json["price"].(float64))
  7956. // formatInt_price := strconv.FormatInt(price, 10)
  7957. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7958. // project.Price = float_price
  7959. // }
  7960. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7961. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7962. project.Price = price
  7963. }
  7964. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7965. total, _ := json["total"].(string)
  7966. project.Count = total
  7967. }
  7968. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7969. medical_code, _ := json["medical_code"].(string)
  7970. project.MedListCodg = medical_code
  7971. }
  7972. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7973. single_dose, _ := json["single_dose"].(string)
  7974. project.SingleDose = single_dose
  7975. }
  7976. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7977. delivery_way, _ := json["delivery_way"].(string)
  7978. project.DeliveryWay = delivery_way
  7979. }
  7980. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7981. execution_frequency, _ := json["execution_frequency"].(string)
  7982. project.ExecutionFrequency = execution_frequency
  7983. }
  7984. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7985. remark, _ := json["remark"].(string)
  7986. project.Remark = remark
  7987. }
  7988. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7989. day, _ := json["number_days"].(string)
  7990. project.Day = day
  7991. }
  7992. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7993. unit, _ := json["unit"].(string)
  7994. project.Unit = unit
  7995. }
  7996. return 0
  7997. }
  7998. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7999. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8000. id := int64(json["id"].(float64))
  8001. historyAddtions, _ := service.GetHisAdditionByID(id)
  8002. additionalCharge.ID = id
  8003. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  8004. }
  8005. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8006. item_id := int64(json["item_id"].(float64))
  8007. additionalCharge.ItemId = item_id
  8008. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8009. if config.ID > 0 {
  8010. if len(config.Code) > 0 {
  8011. additionalCharge.MedListCodg = config.Code
  8012. }
  8013. }
  8014. }
  8015. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8016. // price := int64(json["price"].(float64))
  8017. // formatInt_price := strconv.FormatInt(price, 10)
  8018. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8019. // additionalCharge.Price = float_price
  8020. // }
  8021. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8022. // price := int64(json["price"].(float64))
  8023. // formatInt_price := strconv.FormatInt(price, 10)
  8024. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8025. // additionalCharge.Price = float_price
  8026. //}
  8027. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8028. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8029. additionalCharge.Price = price
  8030. }
  8031. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8032. count, _ := json["count"].(string)
  8033. counts, _ := strconv.ParseInt(count, 10, 64)
  8034. additionalCharge.Count = counts
  8035. }
  8036. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8037. item_name, _ := json["item_name"].(string)
  8038. additionalCharge.ItemName = item_name
  8039. }
  8040. return 0
  8041. }
  8042. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8043. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8044. utils.ErrorLog("drug_name")
  8045. return enums.ErrorCodeParamWrong
  8046. }
  8047. adviceName, _ := json["drug_name"].(string)
  8048. if len(adviceName) == 0 {
  8049. utils.ErrorLog("len(advice_name) == 0")
  8050. return enums.ErrorCodeParamWrong
  8051. }
  8052. advice.AdviceName = adviceName
  8053. adviceDesc, _ := json["advice_desc"].(string)
  8054. advice.AdviceDesc = adviceDesc
  8055. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8056. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8057. advice.DrugSpec = drugSpec
  8058. }
  8059. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8060. remark, _ := json["remark"].(string)
  8061. advice.Remark = remark
  8062. }
  8063. if json["id"] == nil {
  8064. advice.DrugId = 0
  8065. } else {
  8066. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8067. drug_id := int64(json["id"].(float64))
  8068. advice.DrugId = drug_id
  8069. }
  8070. }
  8071. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8072. groupno := int64(json["groupno"].(float64))
  8073. advice.Groupno = groupno
  8074. }
  8075. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8076. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8077. advice.IsSelfDrug = is_self_drug
  8078. }
  8079. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8080. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8081. drug_way_count, _ := json["drug_way_count"].(string)
  8082. advice.DrugWayCount = drug_way_count
  8083. }
  8084. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8085. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8086. advice.HospApprFlag = hosp_appr_flag
  8087. }
  8088. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8089. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8090. advice.PrescribingNumber = prescribingNumber
  8091. }
  8092. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8093. // frequency_type := int64(json["frequency_type"].(float64))
  8094. // advice.FrequencyType = frequency_type
  8095. //}
  8096. //
  8097. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8098. // day_count := int64(json["day_count"].(float64))
  8099. // advice.DayCount = day_count
  8100. //}
  8101. //
  8102. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8103. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8104. // week_day, _ := json["week_day"].(string)
  8105. // advice.WeekDay = week_day
  8106. //}
  8107. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8108. drugSpecUnit, _ := json["min_unit"].(string)
  8109. advice.DrugSpecUnit = drugSpecUnit
  8110. }
  8111. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8112. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8113. advice.SingleDose = singleDose
  8114. }
  8115. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8116. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8117. advice.SingleDoseUnit = singleDoseUnit
  8118. }
  8119. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8120. deliveryWay, _ := json["delivery_way"].(string)
  8121. advice.DeliveryWay = deliveryWay
  8122. }
  8123. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8124. executionFrequency, _ := json["execution_frequency"].(string)
  8125. advice.ExecutionFrequency = executionFrequency
  8126. }
  8127. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8128. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8129. advice.Price = price
  8130. }
  8131. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8132. med_list_codg, _ := json["medical_insurance_number"].(string)
  8133. advice.MedListCodg = med_list_codg
  8134. }
  8135. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8136. day := int64(json["day"].(float64))
  8137. advice.Day = day
  8138. }
  8139. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8140. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8141. advice.PrescribingNumberUnit = prescribingNumberUnit
  8142. }
  8143. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8144. advice_id := int64(json["advice_id"].(float64))
  8145. advice.ID = advice_id
  8146. if advice.ID > 0 {
  8147. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8148. if err == nil {
  8149. if hisAdvice.ID > 0 {
  8150. advice.ExecutionTime = hisAdvice.ExecutionTime
  8151. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8152. advice.ExecutionState = hisAdvice.ExecutionState
  8153. advice.CheckTime = hisAdvice.CheckTime
  8154. advice.Checker = hisAdvice.Checker
  8155. advice.CheckState = hisAdvice.CheckState
  8156. advice.StartTime = hisAdvice.StartTime
  8157. advice.HospApprFlag = hisAdvice.HospApprFlag
  8158. advice.IsMedicine = hisAdvice.IsMedicine
  8159. if hisAdvice.UserOrgId == 10028 {
  8160. 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 {
  8161. advice.ExecutionTime = 0
  8162. advice.ExecutionStaff = 0
  8163. advice.ExecutionState = 2
  8164. advice.CheckTime = 0
  8165. advice.Checker = 0
  8166. advice.CheckState = 2
  8167. }
  8168. } else {
  8169. 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 {
  8170. advice.ExecutionTime = 0
  8171. advice.ExecutionStaff = 0
  8172. advice.ExecutionState = 2
  8173. advice.CheckTime = 0
  8174. advice.Checker = 0
  8175. advice.CheckState = 2
  8176. advice.UpdatedTime = time.Now().Unix()
  8177. }
  8178. }
  8179. //advice.Groupno = hisAdvice.Groupno
  8180. }
  8181. }
  8182. }
  8183. }
  8184. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8185. //
  8186. //if drugStockConfig.IsOpen == 1 {
  8187. //
  8188. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8189. // if advice.ID == 0 { //医嘱不存在
  8190. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8191. // drug.Total = drug.Total - advice.PrescribingNumber
  8192. // service.UpdateBaseDrugLib(&drug)
  8193. //
  8194. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8195. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8196. // drug.Total = drug.Total - num
  8197. // service.UpdateBaseDrugLib(&drug)
  8198. // }
  8199. //
  8200. // } else if advice.ID > 0 { //医嘱存在
  8201. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8202. // var num float64
  8203. //
  8204. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8205. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8206. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8207. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8208. // drug.Total = drug.Total + num
  8209. // service.UpdateBaseDrugLib(&drug)
  8210. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8211. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8212. // drug.Total = drug.Total - num
  8213. // service.UpdateBaseDrugLib(&drug)
  8214. // }
  8215. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8216. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8217. // if num2 > advice.PrescribingNumber {
  8218. // num = num2 - advice.PrescribingNumber
  8219. // drug.Total = drug.Total + num
  8220. // service.UpdateBaseDrugLib(&drug)
  8221. // } else if num2 < advice.PrescribingNumber {
  8222. // num = advice.PrescribingNumber - num2
  8223. // drug.Total = drug.Total - num
  8224. // service.UpdateBaseDrugLib(&drug)
  8225. // }
  8226. //
  8227. // }
  8228. //
  8229. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8230. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8231. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8232. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8233. // if num1 > num2 {
  8234. // num = num1 - num2
  8235. // drug.Total = drug.Total + num
  8236. // service.UpdateBaseDrugLib(&drug)
  8237. // } else if num1 < num2 {
  8238. // num = num2 - num1
  8239. // drug.Total = drug.Total - num
  8240. // service.UpdateBaseDrugLib(&drug)
  8241. // }
  8242. //
  8243. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8244. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8245. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8246. // if hisAdvice.PrescribingNumber > num2 {
  8247. // num = hisAdvice.PrescribingNumber - num2
  8248. // drug.Total = drug.Total + num
  8249. // service.UpdateBaseDrugLib(&drug)
  8250. // } else if num2 < advice.PrescribingNumber {
  8251. // num = num2 - hisAdvice.PrescribingNumber
  8252. // drug.Total = drug.Total - num
  8253. // service.UpdateBaseDrugLib(&drug)
  8254. // }
  8255. //
  8256. // }
  8257. // }
  8258. // }
  8259. //}
  8260. //
  8261. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8262. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8263. // advice.ExecutionTime = execution_time
  8264. //}
  8265. //
  8266. //
  8267. //
  8268. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8269. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8270. // advice.ExecutionStaff = execution_staff
  8271. //}
  8272. //
  8273. //
  8274. //
  8275. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8276. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8277. // advice.ExecutionState = execution_state
  8278. //}
  8279. //
  8280. //
  8281. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8282. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8283. // advice.CheckTime = check_time
  8284. //}
  8285. //
  8286. //
  8287. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8288. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8289. // advice.CheckState = check_state
  8290. //}
  8291. //
  8292. //
  8293. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8294. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8295. // advice.Checker = checker
  8296. //}
  8297. //
  8298. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8299. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8300. // advice.StartTime = start_time
  8301. //}
  8302. return 0
  8303. }
  8304. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8305. project.ExecutionStaff = 0
  8306. project.ExecutionState = 2
  8307. project.ExecutionTime = 0
  8308. project.Checker = 0
  8309. project.CheckState = 2
  8310. project.CheckTime = 0
  8311. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8312. id := int64(json["id"].(float64))
  8313. project.ID = id
  8314. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8315. project.ExecutionStaff = temp_project.ExecutionStaff
  8316. project.ExecutionState = temp_project.ExecutionState
  8317. project.ExecutionTime = temp_project.ExecutionTime
  8318. project.Checker = temp_project.Checker
  8319. project.CheckState = temp_project.CheckState
  8320. project.CheckTime = temp_project.CheckTime
  8321. project.TeamId = temp_project.TeamId
  8322. }
  8323. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8324. types := int64(json["type"].(float64))
  8325. project.Type = types
  8326. }
  8327. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8328. project_id := int64(json["project_id"].(float64))
  8329. project.ProjectId = project_id
  8330. }
  8331. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8332. team_id := int64(json["team_id"].(float64))
  8333. project.TeamId = team_id
  8334. }
  8335. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8336. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8337. project.Price = price
  8338. }
  8339. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8340. total, _ := json["total"].(string)
  8341. //totals, _ := strconv.ParseInt(total, 10, 64)
  8342. project.Count = total
  8343. }
  8344. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8345. medical_code, _ := json["medical_code"].(string)
  8346. project.MedListCodg = medical_code
  8347. }
  8348. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8349. single_dose, _ := json["single_dose"].(string)
  8350. project.SingleDose = single_dose
  8351. }
  8352. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8353. delivery_way, _ := json["delivery_way"].(string)
  8354. project.DeliveryWay = delivery_way
  8355. }
  8356. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8357. execution_frequency, _ := json["execution_frequency"].(string)
  8358. project.ExecutionFrequency = execution_frequency
  8359. }
  8360. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8361. remark, _ := json["remark"].(string)
  8362. project.Remark = remark
  8363. }
  8364. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8365. day, _ := json["number_days"].(string)
  8366. project.Day = day
  8367. }
  8368. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8369. unit, _ := json["unit"].(string)
  8370. project.Unit = unit
  8371. }
  8372. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8373. // frequency_type := int64(json["frequency_type"].(float64))
  8374. // project.FrequencyType = frequency_type
  8375. //}
  8376. //
  8377. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8378. // day_count := int64(json["day_count"].(float64))
  8379. // project.DayCount = day_count
  8380. //}
  8381. //
  8382. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8383. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8384. // week_day, _ := json["week_day"].(string)
  8385. // project.WeekDay = week_day
  8386. //}
  8387. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8388. //
  8389. //if project.ID == 0 {
  8390. // if stockConfig.IsOpen == 1 {
  8391. // if project.Type == 3 {
  8392. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8393. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8394. // good.Total = good.Total - f_count
  8395. // service.UpdateGoodInfo(&good)
  8396. // }
  8397. // }
  8398. //
  8399. //} else {
  8400. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8401. //
  8402. // if stockConfig.IsOpen == 1 {
  8403. // if project.Type == 3 {
  8404. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8405. // if project.Count < temp_project.Count {
  8406. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8407. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8408. //
  8409. // other_count := f_count_two - f_count_one
  8410. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8411. // good.Total = good.Total + other_count_two
  8412. // service.UpdateGoodInfo(&good)
  8413. // } else if project.Count > temp_project.Count {
  8414. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8415. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8416. //
  8417. // other_count := f_count_one - f_count_two
  8418. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8419. // good.Total = good.Total - other_count_two
  8420. // service.UpdateGoodInfo(&good)
  8421. // }
  8422. //
  8423. // }
  8424. // }
  8425. //
  8426. //}
  8427. return 0
  8428. }
  8429. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8430. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8431. utils.ErrorLog("drug_name")
  8432. return enums.ErrorCodeParamWrong
  8433. }
  8434. adviceName, _ := json["drug_name"].(string)
  8435. if len(adviceName) == 0 {
  8436. utils.ErrorLog("len(advice_name) == 0")
  8437. return enums.ErrorCodeParamWrong
  8438. }
  8439. advice.AdviceName = adviceName
  8440. adviceDesc, _ := json["advice_desc"].(string)
  8441. advice.AdviceDesc = adviceDesc
  8442. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8443. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8444. advice.DrugSpec = drugSpec
  8445. }
  8446. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8447. remark, _ := json["remark"].(string)
  8448. advice.Remark = remark
  8449. }
  8450. if json["id"] == nil {
  8451. advice.DrugId = 0
  8452. } else {
  8453. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8454. drug_id := int64(json["id"].(float64))
  8455. advice.DrugId = drug_id
  8456. }
  8457. }
  8458. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8459. groupno := int64(json["groupno"].(float64))
  8460. advice.Groupno = groupno
  8461. }
  8462. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8463. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8464. advice.IsSelfDrug = is_self_drug
  8465. }
  8466. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8467. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8468. drug_way_count, _ := json["drug_way_count"].(string)
  8469. advice.DrugWayCount = drug_way_count
  8470. }
  8471. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8472. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8473. advice.HospApprFlag = hosp_appr_flag
  8474. }
  8475. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8476. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8477. advice.PrescribingNumber = prescribingNumber
  8478. }
  8479. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8480. // frequency_type := int64(json["frequency_type"].(float64))
  8481. // advice.FrequencyType = frequency_type
  8482. //}
  8483. //
  8484. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8485. // day_count := int64(json["day_count"].(float64))
  8486. // advice.DayCount = day_count
  8487. //}
  8488. //
  8489. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8490. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8491. // week_day, _ := json["week_day"].(string)
  8492. // advice.WeekDay = week_day
  8493. //}
  8494. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8495. drugSpecUnit, _ := json["min_unit"].(string)
  8496. advice.DrugSpecUnit = drugSpecUnit
  8497. }
  8498. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8499. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8500. advice.SingleDose = singleDose
  8501. }
  8502. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8503. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8504. advice.SingleDoseUnit = singleDoseUnit
  8505. }
  8506. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8507. deliveryWay, _ := json["delivery_way"].(string)
  8508. advice.DeliveryWay = deliveryWay
  8509. }
  8510. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8511. executionFrequency, _ := json["execution_frequency"].(string)
  8512. advice.ExecutionFrequency = executionFrequency
  8513. }
  8514. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8515. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8516. advice.Price = price
  8517. }
  8518. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8519. med_list_codg, _ := json["medical_insurance_number"].(string)
  8520. advice.MedListCodg = med_list_codg
  8521. }
  8522. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8523. day := int64(json["day"].(float64))
  8524. advice.Day = day
  8525. }
  8526. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8527. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8528. advice.PrescribingNumberUnit = prescribingNumberUnit
  8529. }
  8530. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8531. advice_id := int64(json["advice_id"].(float64))
  8532. advice.ID = advice_id
  8533. if advice.ID > 0 {
  8534. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8535. if err == nil {
  8536. if hisAdvice.ID > 0 {
  8537. advice.ExecutionTime = hisAdvice.ExecutionTime
  8538. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8539. advice.ExecutionState = hisAdvice.ExecutionState
  8540. advice.CheckTime = hisAdvice.CheckTime
  8541. advice.Checker = hisAdvice.Checker
  8542. advice.DrugCode = hisAdvice.DrugCode
  8543. advice.CheckState = hisAdvice.CheckState
  8544. advice.StartTime = hisAdvice.StartTime
  8545. advice.HospApprFlag = hisAdvice.HospApprFlag
  8546. advice.IsMedicine = hisAdvice.IsMedicine
  8547. if hisAdvice.UserOrgId == 10028 {
  8548. 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 {
  8549. advice.ExecutionTime = 0
  8550. advice.ExecutionStaff = 0
  8551. advice.ExecutionState = 2
  8552. advice.CheckTime = 0
  8553. advice.Checker = 0
  8554. advice.CheckState = 2
  8555. }
  8556. } else {
  8557. 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 {
  8558. advice.ExecutionTime = 0
  8559. advice.ExecutionStaff = 0
  8560. advice.ExecutionState = 2
  8561. advice.CheckTime = 0
  8562. advice.Checker = 0
  8563. advice.CheckState = 2
  8564. //advice.UpdatedTime = time.Now().Unix()
  8565. advice.CreatedTime = hisAdvice.CreatedTime
  8566. advice.UpdatedTime = time.Now().Unix()
  8567. } else {
  8568. advice.CreatedTime = hisAdvice.CreatedTime
  8569. advice.UpdatedTime = hisAdvice.UpdatedTime
  8570. }
  8571. }
  8572. //advice.Groupno = hisAdvice.Groupno
  8573. } else {
  8574. advice.IsMedicine = 0
  8575. ctime := time.Now().Unix()
  8576. advice.CreatedTime = ctime
  8577. advice.UpdatedTime = ctime
  8578. }
  8579. }
  8580. } else {
  8581. advice.IsMedicine = 0
  8582. ctime := time.Now().Unix()
  8583. advice.CreatedTime = ctime
  8584. advice.UpdatedTime = ctime
  8585. }
  8586. }
  8587. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8588. //
  8589. //if drugStockConfig.IsOpen == 1 {
  8590. //
  8591. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8592. // if advice.ID == 0 { //医嘱不存在
  8593. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8594. // drug.Total = drug.Total - advice.PrescribingNumber
  8595. // service.UpdateBaseDrugLib(&drug)
  8596. //
  8597. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8598. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8599. // drug.Total = drug.Total - num
  8600. // service.UpdateBaseDrugLib(&drug)
  8601. // }
  8602. //
  8603. // } else if advice.ID > 0 { //医嘱存在
  8604. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8605. // var num float64
  8606. //
  8607. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8608. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8609. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8610. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8611. // drug.Total = drug.Total + num
  8612. // service.UpdateBaseDrugLib(&drug)
  8613. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8614. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8615. // drug.Total = drug.Total - num
  8616. // service.UpdateBaseDrugLib(&drug)
  8617. // }
  8618. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8619. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8620. // if num2 > advice.PrescribingNumber {
  8621. // num = num2 - advice.PrescribingNumber
  8622. // drug.Total = drug.Total + num
  8623. // service.UpdateBaseDrugLib(&drug)
  8624. // } else if num2 < advice.PrescribingNumber {
  8625. // num = advice.PrescribingNumber - num2
  8626. // drug.Total = drug.Total - num
  8627. // service.UpdateBaseDrugLib(&drug)
  8628. // }
  8629. //
  8630. // }
  8631. //
  8632. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8633. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8634. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8635. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8636. // if num1 > num2 {
  8637. // num = num1 - num2
  8638. // drug.Total = drug.Total + num
  8639. // service.UpdateBaseDrugLib(&drug)
  8640. // } else if num1 < num2 {
  8641. // num = num2 - num1
  8642. // drug.Total = drug.Total - num
  8643. // service.UpdateBaseDrugLib(&drug)
  8644. // }
  8645. //
  8646. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8647. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8648. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8649. // if hisAdvice.PrescribingNumber > num2 {
  8650. // num = hisAdvice.PrescribingNumber - num2
  8651. // drug.Total = drug.Total + num
  8652. // service.UpdateBaseDrugLib(&drug)
  8653. // } else if num2 < advice.PrescribingNumber {
  8654. // num = num2 - hisAdvice.PrescribingNumber
  8655. // drug.Total = drug.Total - num
  8656. // service.UpdateBaseDrugLib(&drug)
  8657. // }
  8658. //
  8659. // }
  8660. // }
  8661. // }
  8662. //}
  8663. //
  8664. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8665. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8666. // advice.ExecutionTime = execution_time
  8667. //}
  8668. //
  8669. //
  8670. //
  8671. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8672. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8673. // advice.ExecutionStaff = execution_staff
  8674. //}
  8675. //
  8676. //
  8677. //
  8678. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8679. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8680. // advice.ExecutionState = execution_state
  8681. //}
  8682. //
  8683. //
  8684. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8685. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8686. // advice.CheckTime = check_time
  8687. //}
  8688. //
  8689. //
  8690. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8691. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8692. // advice.CheckState = check_state
  8693. //}
  8694. //
  8695. //
  8696. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8697. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8698. // advice.Checker = checker
  8699. //}
  8700. //
  8701. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8702. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8703. // advice.StartTime = start_time
  8704. //}
  8705. return 0
  8706. }
  8707. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8708. project.ExecutionStaff = 0
  8709. project.ExecutionState = 2
  8710. project.ExecutionTime = 0
  8711. project.Checker = 0
  8712. project.CheckState = 2
  8713. project.CheckTime = 0
  8714. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8715. id := int64(json["id"].(float64))
  8716. project.ID = id
  8717. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8718. project.ExecutionStaff = temp_project.ExecutionStaff
  8719. project.ExecutionState = temp_project.ExecutionState
  8720. project.ExecutionTime = temp_project.ExecutionTime
  8721. project.Checker = temp_project.Checker
  8722. project.CheckState = temp_project.CheckState
  8723. project.CheckTime = temp_project.CheckTime
  8724. project.TeamId = temp_project.TeamId
  8725. }
  8726. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8727. types := int64(json["type"].(float64))
  8728. project.Type = types
  8729. }
  8730. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8731. project_id := int64(json["project_id"].(float64))
  8732. project.ProjectId = project_id
  8733. }
  8734. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8735. team_id := int64(json["team_id"].(float64))
  8736. project.TeamId = team_id
  8737. }
  8738. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8739. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8740. project.Price = price
  8741. }
  8742. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8743. total, _ := json["total"].(string)
  8744. //totals, _ := strconv.ParseInt(total, 10, 64)
  8745. project.Count = total
  8746. }
  8747. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8748. medical_code, _ := json["medical_code"].(string)
  8749. project.MedListCodg = medical_code
  8750. }
  8751. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8752. single_dose, _ := json["single_dose"].(string)
  8753. project.SingleDose = single_dose
  8754. }
  8755. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8756. delivery_way, _ := json["delivery_way"].(string)
  8757. project.DeliveryWay = delivery_way
  8758. }
  8759. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8760. execution_frequency, _ := json["execution_frequency"].(string)
  8761. project.ExecutionFrequency = execution_frequency
  8762. }
  8763. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8764. remark, _ := json["remark"].(string)
  8765. project.Remark = remark
  8766. }
  8767. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8768. day, _ := json["number_days"].(string)
  8769. project.Day = day
  8770. }
  8771. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8772. unit, _ := json["unit"].(string)
  8773. project.Unit = unit
  8774. }
  8775. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8776. // frequency_type := int64(json["frequency_type"].(float64))
  8777. // project.FrequencyType = frequency_type
  8778. //}
  8779. //
  8780. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8781. // day_count := int64(json["day_count"].(float64))
  8782. // project.DayCount = day_count
  8783. //}
  8784. //
  8785. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8786. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8787. // week_day, _ := json["week_day"].(string)
  8788. // project.WeekDay = week_day
  8789. //}
  8790. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8791. //
  8792. //if project.ID == 0 {
  8793. // if stockConfig.IsOpen == 1 {
  8794. // if project.Type == 3 {
  8795. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8796. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8797. // good.Total = good.Total - f_count
  8798. // service.UpdateGoodInfo(&good)
  8799. // }
  8800. // }
  8801. //
  8802. //} else {
  8803. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8804. //
  8805. // if stockConfig.IsOpen == 1 {
  8806. // if project.Type == 3 {
  8807. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8808. // if project.Count < temp_project.Count {
  8809. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8810. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8811. //
  8812. // other_count := f_count_two - f_count_one
  8813. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8814. // good.Total = good.Total + other_count_two
  8815. // service.UpdateGoodInfo(&good)
  8816. // } else if project.Count > temp_project.Count {
  8817. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8818. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8819. //
  8820. // other_count := f_count_one - f_count_two
  8821. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8822. // good.Total = good.Total - other_count_two
  8823. // service.UpdateGoodInfo(&good)
  8824. // }
  8825. //
  8826. // }
  8827. // }
  8828. //
  8829. //}
  8830. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8831. id := int64(json["id"].(float64))
  8832. if id > 0 {
  8833. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8834. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8835. fmt.Println("666666")
  8836. project.Mtime = time.Now().Unix()
  8837. project.Ctime = temp_project.Ctime
  8838. } else {
  8839. project.Mtime = temp_project.Mtime
  8840. project.Ctime = temp_project.Ctime
  8841. }
  8842. } else {
  8843. ctime := time.Now().Unix()
  8844. project.Mtime = ctime
  8845. project.Ctime = ctime
  8846. }
  8847. }
  8848. return 0
  8849. }
  8850. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8851. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8852. id := int64(json["id"].(float64))
  8853. additionalCharge.ID = id
  8854. }
  8855. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8856. item_id := int64(json["item_id"].(float64))
  8857. additionalCharge.ItemId = item_id
  8858. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8859. if config.ID > 0 {
  8860. if len(config.Code) > 0 {
  8861. additionalCharge.MedListCodg = config.Code
  8862. }
  8863. }
  8864. }
  8865. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8866. // price := int64(json["price"].(float64))
  8867. // formatInt_price := strconv.FormatInt(price, 10)
  8868. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8869. // additionalCharge.Price = float_price
  8870. // }
  8871. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8872. // price := int64(json["price"].(float64))
  8873. // formatInt_price := strconv.FormatInt(price, 10)
  8874. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8875. // additionalCharge.Price = float_price
  8876. //}
  8877. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8878. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8879. additionalCharge.Price = price
  8880. }
  8881. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8882. count, _ := json["count"].(string)
  8883. counts, _ := strconv.ParseInt(count, 10, 64)
  8884. additionalCharge.Count = counts
  8885. }
  8886. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8887. item_name, _ := json["item_name"].(string)
  8888. additionalCharge.ItemName = item_name
  8889. }
  8890. return 0
  8891. }
  8892. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8893. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8894. utils.ErrorLog("drug_name")
  8895. return enums.ErrorCodeParamWrong
  8896. }
  8897. adviceName, _ := json["drug_name"].(string)
  8898. if len(adviceName) == 0 {
  8899. utils.ErrorLog("len(advice_name) == 0")
  8900. return enums.ErrorCodeParamWrong
  8901. }
  8902. advice.AdviceName = adviceName
  8903. adviceDesc, _ := json["advice_desc"].(string)
  8904. advice.AdviceDesc = adviceDesc
  8905. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8906. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8907. advice.DrugSpec = drugSpec
  8908. }
  8909. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8910. remark, _ := json["remark"].(string)
  8911. advice.Remark = remark
  8912. }
  8913. if json["id"] == nil {
  8914. advice.DrugId = 0
  8915. } else {
  8916. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8917. drug_id := int64(json["id"].(float64))
  8918. advice.DrugId = drug_id
  8919. }
  8920. }
  8921. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8922. groupno := int64(json["groupno"].(float64))
  8923. advice.Groupno = groupno
  8924. }
  8925. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8926. drugSpecUnit, _ := json["min_unit"].(string)
  8927. advice.DrugSpecUnit = drugSpecUnit
  8928. }
  8929. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8930. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8931. advice.SingleDose = singleDose
  8932. }
  8933. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8934. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8935. advice.SingleDoseUnit = singleDoseUnit
  8936. }
  8937. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8938. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8939. advice.PrescribingNumber = prescribingNumber
  8940. }
  8941. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8942. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8943. advice.PrescribingNumberUnit = prescribingNumberUnit
  8944. }
  8945. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8946. deliveryWay, _ := json["delivery_way"].(string)
  8947. advice.DeliveryWay = deliveryWay
  8948. }
  8949. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8950. executionFrequency, _ := json["execution_frequency"].(string)
  8951. advice.ExecutionFrequency = executionFrequency
  8952. }
  8953. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8954. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8955. advice.Price = price
  8956. }
  8957. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8958. med_list_codg, _ := json["medical_insurance_number"].(string)
  8959. advice.MedListCodg = med_list_codg
  8960. }
  8961. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8962. day := int64(json["day"].(float64))
  8963. advice.Day = day
  8964. }
  8965. advice.FrequencyType = 1
  8966. return 0
  8967. }
  8968. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8969. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8970. types := int64(json["type"].(float64))
  8971. project.Type = types
  8972. }
  8973. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8974. project_id := int64(json["project_id"].(float64))
  8975. project.ProjectId = project_id
  8976. }
  8977. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8978. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8979. project.Price = price
  8980. }
  8981. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8982. total, _ := json["total"].(string)
  8983. //totals, _ := strconv.ParseInt(total, 10, 64)
  8984. project.Count = total
  8985. }
  8986. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8987. medical_code, _ := json["medical_code"].(string)
  8988. project.MedListCodg = medical_code
  8989. }
  8990. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8991. single_dose, _ := json["single_dose"].(string)
  8992. project.SingleDose = single_dose
  8993. }
  8994. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8995. delivery_way, _ := json["delivery_way"].(string)
  8996. project.DeliveryWay = delivery_way
  8997. }
  8998. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8999. execution_frequency, _ := json["execution_frequency"].(string)
  9000. project.ExecutionFrequency = execution_frequency
  9001. }
  9002. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  9003. remark, _ := json["remark"].(string)
  9004. project.Remark = remark
  9005. }
  9006. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  9007. day, _ := json["number_days"].(string)
  9008. project.Day = day
  9009. }
  9010. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  9011. unit, _ := json["unit"].(string)
  9012. project.Unit = unit
  9013. }
  9014. project.FrequencyType = 1
  9015. return 0
  9016. }
  9017. func (c *HisApiController) GetHisOrderListTwo() {
  9018. start_time := c.GetString("start_time")
  9019. end_time := c.GetString("end_time")
  9020. timeLayout := "2006-01-02"
  9021. loc, _ := time.LoadLocation("Local")
  9022. var startTime int64
  9023. if len(start_time) > 0 {
  9024. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9025. if err != nil {
  9026. //fmt.Println(err)
  9027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9028. return
  9029. }
  9030. startTime = theTime.Unix()
  9031. }
  9032. var endTime int64
  9033. if len(end_time) > 0 {
  9034. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9035. if err != nil {
  9036. utils.ErrorLog(err.Error())
  9037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9038. return
  9039. }
  9040. endTime = theTime.Unix()
  9041. }
  9042. adminUser := c.GetAdminUserInfo()
  9043. org_id := adminUser.CurrentOrgId
  9044. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  9045. if err == nil {
  9046. c.ServeSuccessJSON(map[string]interface{}{
  9047. "order2": order,
  9048. })
  9049. } else {
  9050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9051. return
  9052. }
  9053. }
  9054. func (c *HisApiController) GetHisOrderList() {
  9055. page, _ := c.GetInt64("page", -1)
  9056. limit, _ := c.GetInt64("limit", -1)
  9057. start_time := c.GetString("start_time")
  9058. end_time := c.GetString("end_time")
  9059. types, _ := c.GetInt64("type", 0)
  9060. keywords := c.GetString("keywords")
  9061. p_type, _ := c.GetInt64("p_type", 0)
  9062. sort_type, _ := c.GetInt64("sort_type", 0)
  9063. charge_type, _ := c.GetInt64("charge_type", 0)
  9064. sch_type, _ := c.GetInt64("sch_type", 0)
  9065. zone_type, _ := c.GetInt64("zone_type", 0)
  9066. med_type, _ := c.GetInt64("med_type", 0)
  9067. timeLayout := "2006-01-02"
  9068. loc, _ := time.LoadLocation("Local")
  9069. var startTime int64
  9070. if len(start_time) > 0 {
  9071. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9072. if err != nil {
  9073. //fmt.Println(err)
  9074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9075. return
  9076. }
  9077. startTime = theTime.Unix()
  9078. }
  9079. var endTime int64
  9080. if len(end_time) > 0 {
  9081. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9082. if err != nil {
  9083. utils.ErrorLog(err.Error())
  9084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9085. return
  9086. }
  9087. endTime = theTime.Unix()
  9088. }
  9089. adminUser := c.GetAdminUserInfo()
  9090. org_id := adminUser.CurrentOrgId
  9091. 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)
  9092. for _, item := range order {
  9093. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  9094. item.DoctorName = info.Doctor
  9095. item.DepartmentName = info.XtHisDepartment.Name
  9096. }
  9097. if err == nil {
  9098. c.ServeSuccessJSON(map[string]interface{}{
  9099. "order": order,
  9100. "total": total,
  9101. })
  9102. } else {
  9103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9104. return
  9105. }
  9106. }
  9107. func (c *HisApiController) GetHisOrder() {
  9108. patient_id, _ := c.GetInt64("patient_id", 0)
  9109. number := c.GetString("number")
  9110. adminInfo := c.GetAdminUserInfo()
  9111. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  9112. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  9113. if err == nil {
  9114. c.ServeSuccessJSON(map[string]interface{}{
  9115. "order": order,
  9116. "prescription": prescriptions,
  9117. })
  9118. } else {
  9119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9120. return
  9121. }
  9122. }
  9123. func (c *HisApiController) GetHisPrescriptionList() {
  9124. record_date := c.GetString("record_date")
  9125. keywords := c.GetString("keywords")
  9126. page, _ := c.GetInt64("page")
  9127. limit, _ := c.GetInt64("limit")
  9128. sch_type, _ := c.GetInt64("sch_type")
  9129. timeLayout := "2006-01-02"
  9130. loc, _ := time.LoadLocation("Local")
  9131. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9132. if err != nil {
  9133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9134. return
  9135. }
  9136. recordDateTime := theTime.Unix()
  9137. adminInfo := c.GetAdminUserInfo()
  9138. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  9139. //adminInfo := c.GetAdminUserInfo()
  9140. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  9141. //fmt.Println(prescriptionOrder)
  9142. if err == nil {
  9143. c.ServeSuccessJSON(map[string]interface{}{
  9144. "order": prescriptionOrder,
  9145. "total": total,
  9146. })
  9147. } else {
  9148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9149. return
  9150. }
  9151. }
  9152. func (c *HisApiController) GetHisPrescriptionInfo() {
  9153. id, _ := c.GetInt64("id")
  9154. adminInfo := c.GetAdminUserInfo()
  9155. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  9156. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  9157. if err == nil {
  9158. c.ServeSuccessJSON(map[string]interface{}{
  9159. "order": prescriptionOrder,
  9160. "prescription": prescription,
  9161. })
  9162. } else {
  9163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9164. return
  9165. }
  9166. }
  9167. func (c *HisApiController) GetMedicalInsuranceConfig() {
  9168. adminUser := c.GetAdminUserInfo()
  9169. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  9170. c.ServeSuccessJSON(map[string]interface{}{
  9171. "config": config,
  9172. })
  9173. }
  9174. type ResultTwo struct {
  9175. ErrMsg interface{} `json:"err_msg"`
  9176. InfRefmsgid string `json:"inf_refmsgid"`
  9177. Infcode int64 `json:"infcode"`
  9178. Output struct {
  9179. Baseinfo struct {
  9180. Age float64 `json:"age"`
  9181. Brdy string `json:"brdy"`
  9182. Certno string `json:"certno"`
  9183. Gend string `json:"gend"`
  9184. Naty string `json:"naty"`
  9185. PsnCertType string `json:"psn_cert_type"`
  9186. PsnName string `json:"psn_name"`
  9187. PsnNo string `json:"psn_no"`
  9188. } `json:"baseinfo"`
  9189. Idetinfo []interface{} `json:"idetinfo"`
  9190. Iinfo []struct {
  9191. Balc float64 `json:"balc"`
  9192. CvlservFlag string `json:"cvlserv_flag"`
  9193. EmpName string `json:"emp_name"`
  9194. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  9195. Insutype string `json:"insutype"`
  9196. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  9197. PausInsuDate interface{} `json:"paus_insu_date"`
  9198. PsnInsuDate string `json:"psn_insu_date"`
  9199. PsnInsuStas string `json:"psn_insu_stas"`
  9200. PsnType string `json:"psn_type"`
  9201. } `json:"insuinfo"`
  9202. } `json:"output"`
  9203. RefmsgTime string `json:"refmsg_time"`
  9204. RespondTime string `json:"respond_time"`
  9205. Signtype interface{} `json:"signtype"`
  9206. WarnInfo interface{} `json:"warn_info"`
  9207. }
  9208. type ResultThree struct {
  9209. Cainfo interface{} `json:"cainfo"`
  9210. ErrMsg interface{} `json:"err_msg"`
  9211. InfRefmsgid string `json:"inf_refmsgid"`
  9212. Infcode int64 `json:"infcode"`
  9213. Output struct {
  9214. Data struct {
  9215. IptOtpNo string `json:"ipt_otp_no"`
  9216. MdtrtID string `json:"mdtrt_id"`
  9217. PsnNo string `json:"psn_no"`
  9218. } `json:"data"`
  9219. } `json:"output"`
  9220. RefmsgTime string `json:"refmsg_time"`
  9221. RespondTime string `json:"respond_time"`
  9222. Signtype interface{} `json:"signtype"`
  9223. WarnMsg interface{} `json:"warn_msg"`
  9224. }
  9225. type ResultFour struct {
  9226. Cainfo string `json:"cainfo"`
  9227. ErrMsg string `json:"err_msg"`
  9228. InfRefmsgid string `json:"inf_refmsgid"`
  9229. Infcode int64 `json:"infcode"`
  9230. Output struct {
  9231. Result []struct {
  9232. BasMednFlag string `json:"bas_medn_flag"`
  9233. ChldMedcFlag string `json:"chld_medc_flag"`
  9234. ChrgitmLv string `json:"chrgitm_lv"`
  9235. Cnt float64 `json:"cnt"`
  9236. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  9237. DrtReimFlag string `json:"drt_reim_flag"`
  9238. FeedetlSn string `json:"feedetl_sn"`
  9239. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9240. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  9241. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9242. ListSpItemFlag string `json:"list_sp_item_flag"`
  9243. LmtUsedFlag string `json:"lmt_used_flag"`
  9244. MedChrgitmType string `json:"med_chrgitm_type"`
  9245. Memo string `json:"memo"`
  9246. OverlmtAmt float64 `json:"overlmt_amt"`
  9247. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9248. Pric float64 `json:"pric"`
  9249. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  9250. SelfpayProp float64 `json:"selfpay_prop"`
  9251. } `json:"result"`
  9252. } `json:"output"`
  9253. RefmsgTime string `json:"refmsg_time"`
  9254. RespondTime string `json:"respond_time"`
  9255. Signtype string `json:"signtype"`
  9256. WarnMsg string `json:"warn_msg"`
  9257. }
  9258. type ResultFive struct {
  9259. Insutype string `json:"insutype"`
  9260. }
  9261. type ResultSix struct {
  9262. Cainfo interface{} `json:"cainfo"`
  9263. ErrMsg interface{} `json:"err_msg"`
  9264. InfRefmsgid string `json:"inf_refmsgid"`
  9265. Infcode int64 `json:"infcode"`
  9266. Output struct {
  9267. } `json:"output"`
  9268. RefmsgTime string `json:"refmsg_time"`
  9269. RespondTime string `json:"respond_time"`
  9270. Signtype interface{} `json:"signtype"`
  9271. WarnMsg interface{} `json:"warn_msg"`
  9272. }
  9273. type ResultSeven struct {
  9274. Cainfo string `json:"cainfo"`
  9275. ErrMsg string `json:"err_msg"`
  9276. InfRefmsgid string `json:"inf_refmsgid"`
  9277. Infcode int64 `json:"infcode"`
  9278. Output struct {
  9279. Setldetail []interface{} `json:"setldetail"`
  9280. Setlinfo struct {
  9281. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9282. AcctPay float64 `json:"acct_pay"`
  9283. ActPayDedc float64 `json:"act_pay_dedc"`
  9284. Age float64 `json:"age"`
  9285. Balc float64 `json:"balc"`
  9286. Brdy string `json:"brdy"`
  9287. Certno string `json:"certno"`
  9288. ClrOptins string `json:"clr_optins"`
  9289. ClrType string `json:"clr_type"`
  9290. ClrWay string `json:"clr_way"`
  9291. CvlservFlag string `json:"cvlserv_flag"`
  9292. CvlservPay float64 `json:"cvlserv_pay"`
  9293. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9294. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9295. Gend string `json:"gend"`
  9296. HifesPay float64 `json:"hifes_pay"`
  9297. HifmiPay float64 `json:"hifmi_pay"`
  9298. HifobPay float64 `json:"hifob_pay"`
  9299. HifpPay float64 `json:"hifp_pay"`
  9300. HospPartAmt float64 `json:"hosp_part_amt"`
  9301. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9302. Insutype string `json:"insutype"`
  9303. MafPay float64 `json:"maf_pay"`
  9304. MdtrtCertType string `json:"mdtrt_cert_type"`
  9305. MdtrtID string `json:"mdtrt_id"`
  9306. MedType string `json:"med_type"`
  9307. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9308. MedinsSetlID string `json:"medins_setl_id"`
  9309. Naty string `json:"naty"`
  9310. OthPay float64 `json:"oth_pay"`
  9311. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9312. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9313. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9314. PsnCashPay float64 `json:"psn_cash_pay"`
  9315. PsnCertType string `json:"psn_cert_type"`
  9316. PsnName string `json:"psn_name"`
  9317. PsnNo string `json:"psn_no"`
  9318. PsnPartAmt float64 `json:"psn_part_amt"`
  9319. PsnType string `json:"psn_type"`
  9320. SetlID string `json:"setl_id"`
  9321. SetlTime string `json:"setl_time"`
  9322. } `json:"setlinfo"`
  9323. } `json:"output"`
  9324. RefmsgTime string `json:"refmsg_time"`
  9325. RespondTime string `json:"respond_time"`
  9326. Signtype interface{} `json:"signtype"`
  9327. WarnMsg interface{} `json:"warn_msg"`
  9328. }
  9329. type ResultEight struct {
  9330. Cainfo string `json:"cainfo"`
  9331. ErrMsg string `json:"err_msg"`
  9332. InfRefmsgid string `json:"inf_refmsgid"`
  9333. Infcode int64 `json:"infcode"`
  9334. Output struct {
  9335. Stmtinfo struct {
  9336. SetlOptins string `json:"setl_optins"`
  9337. StmtRslt string `json:"stmt_rslt"`
  9338. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  9339. } `json:"stmtinfo"`
  9340. } `json:"output"`
  9341. RefmsgTime string `json:"refmsg_time"`
  9342. RespondTime string `json:"respond_time"`
  9343. Signtype interface{} `json:"signtype"`
  9344. WarnMsg interface{} `json:"warn_msg"`
  9345. }
  9346. type ResultNine struct {
  9347. Cainfo string `json:"cainfo"`
  9348. ErrMsg string `json:"err_msg"`
  9349. InfRefmsgid string `json:"inf_refmsgid"`
  9350. Infcode int64 `json:"infcode"`
  9351. Output struct {
  9352. FileQuryNo string `json:"file_qury_no"`
  9353. } `json:"output"`
  9354. RefmsgTime string `json:"refmsg_time"`
  9355. RespondTime string `json:"respond_time"`
  9356. Signtype interface{} `json:"signtype"`
  9357. WarnMsg interface{} `json:"warn_msg"`
  9358. }
  9359. type ResultTen struct {
  9360. Cainfo string `json:"cainfo"`
  9361. ErrMsg string `json:"err_msg"`
  9362. InfRefmsgid string `json:"inf_refmsgid"`
  9363. Infcode int64 `json:"infcode"`
  9364. Output struct {
  9365. DldEndtime string `json:"dld_endtime"`
  9366. FileQuryNo string `json:"file_qury_no"`
  9367. Filename string `json:"filename"`
  9368. } `json:"output"`
  9369. RefmsgTime string `json:"refmsg_time"`
  9370. RespondTime string `json:"respond_time"`
  9371. Signtype interface{} `json:"signtype"`
  9372. WarnMsg interface{} `json:"warn_msg"`
  9373. }
  9374. type ResultEleven struct {
  9375. Cainfo string `json:"cainfo"`
  9376. ErrMsg string `json:"err_msg"`
  9377. InfRefmsgid string `json:"inf_refmsgid"`
  9378. Infcode int64 `json:"infcode"`
  9379. Output struct {
  9380. Setlinfo struct {
  9381. FixmedinsName string `json:"fixmedins_name"`
  9382. FixmedinsCode string `json:"fixmedins_code"`
  9383. PsnNo string `json:"psn_no"`
  9384. PsnName string `json:"psn_name"`
  9385. HifobPay float64 `json:"hifob_pay"`
  9386. Gend string `json:"gend"`
  9387. Brdy string `json:"brdy"`
  9388. PsnCertType string `json:"psn_cert_type"`
  9389. PsnType string `json:"psn_type"`
  9390. EmpName string `json:"emp_name"`
  9391. Certno string `json:"certno"`
  9392. Insutype string `json:"insutype"`
  9393. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9394. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9395. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9396. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9397. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9398. ActPayDedc float64 `json:"act_pay_dedc"`
  9399. HifpPay float64 `json:"hifp_pay"`
  9400. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9401. CvlservPay float64 `json:"cvlserv_pay"`
  9402. HifesPay float64 `json:"hifes_pay"`
  9403. HifmiPay float64 `json:"hifmi_pay"`
  9404. MafPay float64 `json:"maf_pay"`
  9405. OthPay float64 `json:"oth_pay"`
  9406. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9407. PsnPay float64 `json:"psn_pay"`
  9408. AcctPay float64 `json:"acct_pay"`
  9409. CashPayamt float64 `json:"cash_payamt"`
  9410. Balc float64 `json:"balc"`
  9411. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9412. MedinsSetlId string `json:"medins_setl_id"`
  9413. RefdSetlFlag string `json:"refd_setl_flag"`
  9414. SetlTime string `json:"setl_time"`
  9415. MedType string `json:"med_type"`
  9416. } `json:"setlinfo"`
  9417. } `json:"output"`
  9418. RefmsgTime string `json:"refmsg_time"`
  9419. RespondTime string `json:"respond_time"`
  9420. Signtype interface{} `json:"signtype"`
  9421. WarnMsg interface{} `json:"warn_msg"`
  9422. }
  9423. type Custom struct {
  9424. DetItemFeeSumamt string
  9425. Cut string
  9426. FeedetlSn string
  9427. Price string
  9428. MedListCodg string
  9429. Type int64
  9430. AdviceId int64
  9431. ProjectId int64
  9432. ItemId int64
  9433. CostType int64
  9434. }
  9435. // 获取个人信息----挂号-----上传就诊信息
  9436. func (c *HisApiController) GetRegisterInfo() {
  9437. id, _ := c.GetInt64("id")
  9438. record_time := c.GetString("record_time")
  9439. settlementValue, _ := c.GetInt64("settlement_value")
  9440. medical_insurance_card := c.GetString("medical_insurance_card")
  9441. name := c.GetString("name")
  9442. id_card_type, _ := c.GetInt64("id_card_type")
  9443. certificates, _ := c.GetInt64("certificates")
  9444. medical_care, _ := c.GetInt64("medical_care")
  9445. birthday := c.GetString("birthday")
  9446. age, _ := c.GetInt64("age")
  9447. id_card := c.GetString("id_card")
  9448. register_type, _ := c.GetInt64("register")
  9449. doctor, _ := c.GetInt64("doctor")
  9450. department, _ := c.GetInt64("department")
  9451. gender, _ := c.GetInt64("sex")
  9452. phone := c.GetString("phone")
  9453. registration_fee, _ := c.GetFloat("registration_fee")
  9454. medical_expenses, _ := c.GetFloat("medical_expenses")
  9455. social_type, _ := c.GetInt64("social_type")
  9456. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9457. diagnosis_ids := c.GetString("diagnosis")
  9458. sick_type, _ := c.GetInt64("sick_type")
  9459. reg_type := c.GetString("p_type")
  9460. timeLayout := "2006-01-02"
  9461. loc, _ := time.LoadLocation("Local")
  9462. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9463. birthUnix := birthdays.Unix()
  9464. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9465. if err != nil {
  9466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9467. return
  9468. }
  9469. recordDateTime := theTime.Unix()
  9470. adminInfo := c.GetAdminUserInfo()
  9471. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9472. if tempPatient.ID == 0 {
  9473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9474. return
  9475. }
  9476. var patient service.Patients
  9477. if id == 0 {
  9478. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9479. } else {
  9480. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9481. }
  9482. if patient.ID == 0 {
  9483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9484. return
  9485. }
  9486. if len(patient.IdCardNo) == 0 {
  9487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9488. return
  9489. }
  9490. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9491. if len(his) >= 1 {
  9492. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9493. if len(his) >= 1 && order.ID == 0 {
  9494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9495. return
  9496. }
  9497. }
  9498. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9499. fmt.Println(timeStr)
  9500. timeArr := strings.Split(timeStr, " ")
  9501. fmt.Println(timeArr)
  9502. timeArrTwo := strings.Split(timeArr[0], "-")
  9503. timeArrThree := strings.Split(timeArr[1], ":")
  9504. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9505. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9506. if len(lists) == 0 {
  9507. var hisPatient models.XtHisPatient
  9508. hisPatient = models.XtHisPatient{
  9509. Name: name,
  9510. Age: age,
  9511. Gender: gender,
  9512. Birthday: birthUnix,
  9513. Phone: phone,
  9514. MedicalTreatmentType: medical_care,
  9515. IdType: certificates,
  9516. IdCardNo: id_card,
  9517. BalanceAccountsType: settlementValue,
  9518. SocialType: social_type,
  9519. MedicalInsuranceNumber: medical_insurance_card,
  9520. RegisterType: register_type,
  9521. RegisterCost: registration_fee,
  9522. TreatmentCost: medical_expenses,
  9523. AdminUserId: adminInfo.AdminUser.Id,
  9524. UserOrgId: adminInfo.CurrentOrgId,
  9525. Status: 1,
  9526. RecordDate: recordDateTime,
  9527. IsReturn: 1,
  9528. PatientId: patient.ID,
  9529. Ctime: time.Now().Unix(),
  9530. Mtime: time.Now().Unix(),
  9531. Number: str,
  9532. IdCardType: id_card_type,
  9533. Departments: department,
  9534. Doctor: doctor,
  9535. PType: reg_type,
  9536. Diagnosis: diagnosis_ids,
  9537. SickType: sick_type,
  9538. }
  9539. service.CreateHisPatient(&hisPatient)
  9540. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9541. c.ServeSuccessJSON(map[string]interface{}{
  9542. "his_info": hisPatient,
  9543. })
  9544. } else {
  9545. //chrgBchno := rand.Intn(1000000) + 10000
  9546. var hisPatient models.XtHisPatient
  9547. hisPatient = models.XtHisPatient{
  9548. Name: name,
  9549. Age: age,
  9550. Gender: gender,
  9551. Birthday: birthUnix,
  9552. Phone: phone,
  9553. MedicalTreatmentType: medical_care,
  9554. IdType: certificates,
  9555. IdCardNo: id_card,
  9556. BalanceAccountsType: settlementValue,
  9557. SocialType: social_type,
  9558. MedicalInsuranceNumber: medical_insurance_card,
  9559. RegisterType: register_type,
  9560. RegisterCost: registration_fee,
  9561. TreatmentCost: medical_expenses,
  9562. AdminUserId: adminInfo.AdminUser.Id,
  9563. UserOrgId: adminInfo.CurrentOrgId,
  9564. Status: 1,
  9565. RecordDate: recordDateTime,
  9566. IsReturn: 1,
  9567. PatientId: patient.ID,
  9568. Ctime: time.Now().Unix(),
  9569. Mtime: time.Now().Unix(),
  9570. Number: str,
  9571. IdCardType: id_card_type,
  9572. Departments: department,
  9573. Doctor: doctor,
  9574. PType: reg_type,
  9575. Diagnosis: diagnosis_ids,
  9576. SickType: sick_type,
  9577. }
  9578. service.CreateHisPatient(&hisPatient)
  9579. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9580. c.ServeSuccessJSON(map[string]interface{}{
  9581. "his_info": hisPatient,
  9582. })
  9583. }
  9584. }
  9585. // 上传明细----结算
  9586. func (c *HisApiController) GetUploadInfo() {
  9587. id, _ := c.GetInt64("id")
  9588. record_time := c.GetString("record_time")
  9589. his_patient_id, _ := c.GetInt64("his_patient_id")
  9590. oth_desc := c.GetString("oth_desc")
  9591. pay_way, _ := c.GetInt64("pay_way")
  9592. pay_ways := c.GetString("pay_ways")
  9593. pay_price, _ := c.GetFloat("pay_price")
  9594. pay_card_no := c.GetString("pay_card_no")
  9595. discount_price, _ := c.GetFloat("discount_price")
  9596. preferential_price, _ := c.GetFloat("preferential_price")
  9597. reality_price, _ := c.GetFloat("reality_price")
  9598. found_price, _ := c.GetFloat("found_price")
  9599. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9600. private_price, _ := c.GetFloat("private_price")
  9601. timeLayout := "2006-01-02"
  9602. loc, _ := time.LoadLocation("Local")
  9603. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9604. fapiao_code := c.GetString("fapiao_code")
  9605. fapiao_number := c.GetString("fapiao_number")
  9606. diagnosis_id := c.GetString("diagnosis")
  9607. sick_type, _ := c.GetInt64("sick_type")
  9608. reg_type, _ := c.GetInt64("p_type")
  9609. order_id, _ := c.GetInt64("order_id")
  9610. cash_pay := c.GetString("cash_pay")
  9611. wechat_pay := c.GetString("wechat_pay")
  9612. ali_pay := c.GetString("ali_pay")
  9613. jifen_pay := c.GetString("jifen_pay")
  9614. card_desc := c.GetString("card_desc")
  9615. band_card_pay := c.GetString("band_card_pay")
  9616. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9617. tmp_decimal := c.GetString("tmp_decimal")
  9618. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9619. var decimal float64 //本次使用的押金
  9620. var errmsg error
  9621. tx := service.XTWriteDB().Begin() //开了事务
  9622. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9623. defer func() {
  9624. if errmsg != nil {
  9625. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9626. tx.Rollback()
  9627. } else {
  9628. tx.Commit()
  9629. }
  9630. }()
  9631. fmt.Println("dec_way", dec_way)
  9632. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9633. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9634. return
  9635. }
  9636. if len(tmp_decimal) > 0 {
  9637. if tmp_decimal[0] == 45 {
  9638. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9639. return
  9640. }
  9641. }
  9642. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9643. fmt.Println(errs)
  9644. decimal = tt
  9645. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9646. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9647. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9648. if err != nil {
  9649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9650. return
  9651. }
  9652. recordDateTime := theTime.Unix()
  9653. adminUser := c.GetAdminUserInfo()
  9654. var prescriptions []*models.HisPrescription
  9655. var prescriptionsOne []*models.HisPrescription
  9656. var start_time int64
  9657. var end_time int64
  9658. ids_str := c.GetString("ids")
  9659. ids_arr := strings.Split(ids_str, ",")
  9660. if tempOrder.ID == 0 {
  9661. if settle_accounts_type == 1 { //日结
  9662. fmt.Println(reg_type)
  9663. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9664. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9665. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9666. } else {
  9667. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9668. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9669. }
  9670. } else { //月结
  9671. start_time_str := c.GetString("start_time")
  9672. end_time_str := c.GetString("end_time")
  9673. timeLayout := "2006-01-02"
  9674. loc, _ := time.LoadLocation("Local")
  9675. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9676. if err != nil {
  9677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9678. return
  9679. }
  9680. recordStartTime := theStartTime.Unix()
  9681. start_time = recordStartTime
  9682. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9683. if err != nil {
  9684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9685. return
  9686. }
  9687. recordEndTime := theEndTime.Unix()
  9688. end_time = recordEndTime
  9689. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9690. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9691. }
  9692. var goods []*models.DialysisBeforePrepareGoods
  9693. var newGoods []*models.NewDialysisBeforePrepareGoods
  9694. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9695. var infos []*models.HisDoctorAdviceInfo
  9696. var infoList []*models.HisDoctorAdviceInfo
  9697. var hisAdvice []*models.HisDoctorAdviceInfo
  9698. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9699. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9700. //判断库存不足
  9701. //结算出库开关
  9702. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9703. if settConfig.IsOpen == 1 {
  9704. //判断库存的地方
  9705. for _, info := range prescriptions {
  9706. if info.Type == 1 {
  9707. infos = append(infos, info.HisDoctorAdviceInfo...)
  9708. }
  9709. if info.Type == 2 {
  9710. for _, sumItem := range info.HisPrescriptionProject {
  9711. if sumItem.Type == 3 {
  9712. var good models.DialysisBeforePrepareGoods
  9713. var newGood models.NewDialysisBeforePrepareGoods
  9714. good.GoodId = sumItem.GoodInfo.ID
  9715. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9716. count, _ := strconv.Atoi(sumItem.Count)
  9717. good.Count = int64(count)
  9718. good.StorehouseId = houseConfig.StorehouseOutInfo
  9719. good.ProjectId = sumItem.ID
  9720. goods = append(goods, &good)
  9721. newGood.GoodId = sumItem.GoodInfo.ID
  9722. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9723. count2, _ := strconv.Atoi(sumItem.Count)
  9724. newGood.Count = int64(count2)
  9725. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9726. newGood.ProjectId = sumItem.ID
  9727. newGoods = append(newGoods, &newGood)
  9728. }
  9729. }
  9730. }
  9731. }
  9732. for _, info := range prescriptionsOne {
  9733. if info.Type == 1 {
  9734. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9735. }
  9736. if info.Type == 2 {
  9737. for _, sumItem := range info.HisPrescriptionProject {
  9738. if sumItem.Type == 3 {
  9739. var newGood models.NewDialysisBeforePrepareGoods
  9740. newGood.GoodId = sumItem.GoodInfo.ID
  9741. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9742. count2, _ := strconv.Atoi(sumItem.Count)
  9743. newGood.Count = int64(count2)
  9744. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9745. newGood.ProjectId = sumItem.ID
  9746. newGoodOne = append(newGoodOne, &newGood)
  9747. }
  9748. }
  9749. }
  9750. }
  9751. //判断
  9752. for _, itemOne := range infos {
  9753. for _, itemTwo := range hisAdvice {
  9754. if itemOne.DrugId == itemTwo.DrugId {
  9755. itemTwo.Child = append(itemTwo.Child, itemOne)
  9756. }
  9757. }
  9758. }
  9759. for _, itemTwo := range hisAdvice {
  9760. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9761. var sum_out_count int64
  9762. for _, itemThree := range itemTwo.Child {
  9763. var prescribing_number int64
  9764. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9765. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9766. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9767. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9768. }
  9769. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9770. prescribing_number = parseIntPrescribingNumber
  9771. }
  9772. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9773. prescribing_number = parseIntPrescribingNumber
  9774. }
  9775. sum_out_count += prescribing_number
  9776. }
  9777. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9778. if sum_out_count > drugStockOut.FlushCount {
  9779. c.ServeSuccessJSON(map[string]interface{}{
  9780. "msg": "2",
  9781. "drug": medical,
  9782. })
  9783. return
  9784. }
  9785. }
  9786. for _, itemOne := range newGoods {
  9787. for _, item := range newGoodOne {
  9788. if itemOne.GoodId == item.GoodId {
  9789. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9790. }
  9791. }
  9792. }
  9793. for _, item := range newGoodOne {
  9794. var sum_out_count_one int64
  9795. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9796. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9797. sum_out_count_one += itemOne.Count
  9798. }
  9799. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9800. fmt.Println("sum_out_count_one", sum_out_count_one)
  9801. fmt.Println("list.FlushCount", list.FlushCount)
  9802. if sum_out_count_one > list.FlushCount {
  9803. c.ServeSuccessJSON(map[string]interface{}{
  9804. "msg": "3",
  9805. "good": good,
  9806. })
  9807. return
  9808. }
  9809. }
  9810. }
  9811. timestamp := time.Now().Unix()
  9812. tempTime := time.Unix(timestamp, 0)
  9813. timeFormat := tempTime.Format("20060102150405")
  9814. chrgBchno := rand.Intn(100000) + 10000
  9815. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9816. strconv.FormatInt(his.PatientId, 10)
  9817. var ids []int64
  9818. for _, item := range prescriptions {
  9819. ids = append(ids, item.ID)
  9820. }
  9821. var total float64
  9822. for _, item := range prescriptions {
  9823. fmt.Println(item)
  9824. if item.Type == 1 { //药品
  9825. for _, subItem := range item.HisDoctorAdviceInfo {
  9826. if subItem.Drug.IsUser != 1 {
  9827. total = total + (subItem.Price * subItem.PrescribingNumber)
  9828. }
  9829. }
  9830. }
  9831. if item.Type == 2 { //项目
  9832. for _, subItem := range item.HisPrescriptionProject {
  9833. if subItem.Type == 2 {
  9834. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9835. total = total + (subItem.Price * cnt)
  9836. } else {
  9837. if subItem.GoodInfo.IsUser != 1 {
  9838. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9839. total = total + (subItem.Price * cnt)
  9840. }
  9841. }
  9842. }
  9843. }
  9844. for _, subItem := range item.HisAdditionalCharge {
  9845. total = total + (subItem.Price * float64(subItem.Count))
  9846. }
  9847. }
  9848. if reg_type == 1111 || reg_type == 1112 {
  9849. reg_type = 11
  9850. }
  9851. tm := time.Unix(time.Now().Unix(), 0)
  9852. allTotal := fmt.Sprintf("%.4f", total)
  9853. totals, _ := strconv.ParseFloat(allTotal, 64)
  9854. order := &models.HisOrder{
  9855. UserOrgId: adminUser.CurrentOrgId,
  9856. HisPatientId: his.ID,
  9857. PatientId: id,
  9858. SettleAccountsDate: recordDateTime,
  9859. Ctime: time.Now().Unix(),
  9860. Mtime: time.Now().Unix(),
  9861. Status: 1,
  9862. OrderStatus: 2,
  9863. MdtrtId: his.Number,
  9864. Number: chrg_bchno,
  9865. MedfeeSumamt: totals,
  9866. PayWay: pay_way,
  9867. PayWays: pay_ways,
  9868. PayPrice: pay_price,
  9869. MedType: strconv.Itoa(int(reg_type)),
  9870. PayCardNo: pay_card_no,
  9871. DiscountPrice: discount_price,
  9872. PreferentialPrice: preferential_price,
  9873. RealityPrice: reality_price,
  9874. FoundPrice: found_price,
  9875. MedicalInsurancePrice: medical_insurance_price,
  9876. PrivatePrice: private_price,
  9877. SettleEndTime: end_time,
  9878. SettleStartTime: start_time,
  9879. PsnPartAmt: totals,
  9880. PsnCashPay: totals,
  9881. SettleType: settle_accounts_type,
  9882. FaPiaoCode: fapiao_code,
  9883. FaPiaoNumber: fapiao_number,
  9884. Diagnosis: diagnosis_id,
  9885. PType: 2,
  9886. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9887. Decimal: decimal,
  9888. OthDesc: oth_desc,
  9889. CashPay: cash_pay,
  9890. WechatPay: wechat_pay,
  9891. AliPay: ali_pay,
  9892. JifenPay: jifen_pay,
  9893. BandCardPay: band_card_pay,
  9894. Creator: adminUser.AdminUser.Id,
  9895. CardDesc: card_desc,
  9896. }
  9897. err = service.CreateOrderTX(order, tx)
  9898. if err != nil {
  9899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9900. return
  9901. }
  9902. var customs []*Custom
  9903. for _, item := range prescriptions {
  9904. if item.Type == 1 { //药品a
  9905. for _, subItem := range item.HisDoctorAdviceInfo {
  9906. if subItem.Drug.IsUser != 1 {
  9907. cus := &Custom{
  9908. AdviceId: subItem.ID,
  9909. ProjectId: 0,
  9910. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9911. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9912. FeedetlSn: subItem.FeedetlSn,
  9913. Price: fmt.Sprintf("%.4f", subItem.Price),
  9914. MedListCodg: subItem.MedListCodg,
  9915. Type: 1,
  9916. CostType: 9,
  9917. }
  9918. customs = append(customs, cus)
  9919. }
  9920. }
  9921. }
  9922. if item.Type == 2 { //项目
  9923. for _, subItem := range item.HisPrescriptionProject {
  9924. if subItem.Type == 2 {
  9925. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9926. cus := &Custom{
  9927. AdviceId: 0,
  9928. ProjectId: subItem.ID,
  9929. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9930. Cut: fmt.Sprintf("%.4f", cnt),
  9931. FeedetlSn: subItem.FeedetlSn,
  9932. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9933. MedListCodg: subItem.MedListCodg,
  9934. Type: 2,
  9935. CostType: subItem.HisProject.CostClassify,
  9936. }
  9937. customs = append(customs, cus)
  9938. } else {
  9939. if subItem.GoodInfo.IsUser != 1 {
  9940. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9941. cus := &Custom{
  9942. AdviceId: 0,
  9943. ProjectId: subItem.ID,
  9944. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9945. Cut: fmt.Sprintf("%.4f", cnt),
  9946. FeedetlSn: subItem.FeedetlSn,
  9947. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9948. MedListCodg: subItem.MedListCodg,
  9949. Type: 2,
  9950. CostType: subItem.HisProject.CostClassify,
  9951. }
  9952. customs = append(customs, cus)
  9953. }
  9954. }
  9955. }
  9956. }
  9957. for _, item := range item.HisAdditionalCharge {
  9958. cus := &Custom{
  9959. ItemId: item.ID,
  9960. AdviceId: 0,
  9961. ProjectId: 0,
  9962. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9963. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9964. FeedetlSn: item.FeedetlSn,
  9965. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9966. MedListCodg: item.XtHisAddtionConfig.Code,
  9967. Type: 3,
  9968. CostType: 5,
  9969. }
  9970. customs = append(customs, cus)
  9971. }
  9972. }
  9973. for _, item := range customs {
  9974. var advice_id int64 = 0
  9975. var project_id int64 = 0
  9976. var item_id int64 = 0
  9977. var types int64 = 0
  9978. var med_chrgitm_type string
  9979. if item.Type == 1 {
  9980. advice_id = item.AdviceId
  9981. project_id = 0
  9982. item_id = 0
  9983. med_chrgitm_type = "09"
  9984. } else if item.Type == 2 {
  9985. med_chrgitm_type = "05"
  9986. if item.CostType == 3 {
  9987. med_chrgitm_type = "04"
  9988. }
  9989. if item.CostType == 8 {
  9990. med_chrgitm_type = "03"
  9991. }
  9992. advice_id = 0
  9993. item_id = 0
  9994. project_id = item.ProjectId
  9995. } else if item.Type == 3 {
  9996. advice_id = 0
  9997. item_id = item.ItemId
  9998. project_id = 0
  9999. med_chrgitm_type = "08"
  10000. }
  10001. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10002. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10003. pric, _ := strconv.ParseFloat(item.Price, 32)
  10004. info := &models.HisOrderInfo{
  10005. OrderNumber: order.Number,
  10006. UploadDate: time.Now().Unix(),
  10007. AdviceId: advice_id,
  10008. DetItemFeeSumamt: detItemFeeSumamt,
  10009. MedChrgitmType: med_chrgitm_type,
  10010. Cnt: cut,
  10011. Pric: pric,
  10012. PatientId: id,
  10013. Status: 1,
  10014. Mtime: time.Now().Unix(),
  10015. Ctime: time.Now().Unix(),
  10016. UserOrgId: adminUser.CurrentOrgId,
  10017. HisPatientId: his.ID,
  10018. OrderId: order.ID,
  10019. ProjectId: project_id,
  10020. Type: types,
  10021. ItemId: item_id,
  10022. }
  10023. service.CreateOrderInfoTX(info, tx)
  10024. }
  10025. his.Diagnosis = diagnosis_id
  10026. his.SickType = sick_type
  10027. his.RegisterType = reg_type
  10028. his.MedicalTreatmentType = reg_type
  10029. service.UpdataHisPateintTX(&his, tx)
  10030. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  10031. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  10032. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  10033. //判断是否使用了押金
  10034. if dec_way == "true" {
  10035. tmpstring := strconv.FormatInt(order.ID, 10)
  10036. //扣押金
  10037. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  10038. order.Decimal = decimal
  10039. service.UpDateOrderTwo(order, tx)
  10040. if errmsg != nil {
  10041. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  10042. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10043. return
  10044. }
  10045. }
  10046. if err == nil {
  10047. for _, info := range prescriptions {
  10048. if info.Type == 1 {
  10049. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  10050. }
  10051. if info.Type == 2 {
  10052. for _, sumItem := range info.HisPrescriptionProject {
  10053. if sumItem.Type == 3 {
  10054. var good models.DialysisBeforePrepareGoods
  10055. var newGood models.NewDialysisBeforePrepareGoods
  10056. var oldGood models.OldDialysisBeforePrepareGoods
  10057. good.GoodId = sumItem.GoodInfo.ID
  10058. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10059. count, _ := strconv.Atoi(sumItem.Count)
  10060. good.Count = int64(count)
  10061. good.StorehouseId = houseConfig.StorehouseOutInfo
  10062. good.ProjectId = sumItem.ID
  10063. good.PatientId = sumItem.PatientId
  10064. goods = append(goods, &good)
  10065. newGood.GoodId = sumItem.GoodInfo.ID
  10066. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10067. count2, _ := strconv.Atoi(sumItem.Count)
  10068. newGood.Count = int64(count2)
  10069. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10070. newGood.ProjectId = sumItem.ID
  10071. newGood.PatientId = sumItem.HisPatientId
  10072. newGoods = append(newGoods, &newGood)
  10073. oldGood.GoodId = sumItem.GoodInfo.ID
  10074. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10075. count3, _ := strconv.Atoi(sumItem.Count)
  10076. oldGood.Count = int64(count3)
  10077. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  10078. oldGood.ProjectId = sumItem.ID
  10079. oldGood.RecordDate = sumItem.RecordDate
  10080. oldGood.PatientId = sumItem.HisPatientId
  10081. oldGoods = append(oldGoods, &oldGood)
  10082. }
  10083. }
  10084. }
  10085. }
  10086. if settConfig.IsOpen == 1 {
  10087. for _, item := range infoList {
  10088. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  10089. if medical.IsUse == 2 {
  10090. //药品出库
  10091. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  10092. //查询默认仓库
  10093. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  10094. //查询默认仓库剩余多少库存
  10095. var sum_count int64
  10096. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  10097. for _, its := range stockInfo {
  10098. if its.MaxUnit == medical.MaxUnit {
  10099. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  10100. }
  10101. sum_count += its.StockMaxNumber + its.StockMinNumber
  10102. }
  10103. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  10104. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  10105. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  10106. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  10107. }
  10108. }
  10109. orgId := c.GetAdminUserInfo().CurrentOrgId
  10110. if len(oldGoods) > 0 {
  10111. timeStr := time.Now().Format("2006-01-02")
  10112. timeArr := strings.Split(timeStr, "-")
  10113. total, _ := service.FindAllWarehouseOut(orgId)
  10114. total = total + 1
  10115. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  10116. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  10117. number = number + total
  10118. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  10119. operation_time := time.Now().Unix()
  10120. creater := c.GetAdminUserInfo().AdminUser.Id
  10121. //查询默认出库仓库库存
  10122. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  10123. recordDateStr := time.Now().Format("2006-01-02")
  10124. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  10125. nowtime := recordDate.Unix()
  10126. warehouseOut := models.WarehouseOut{
  10127. WarehouseOutOrderNumber: warehousing_out_order,
  10128. OperationTime: operation_time,
  10129. OrgId: orgId,
  10130. Creater: creater,
  10131. Ctime: time.Now().Unix(),
  10132. Status: 1,
  10133. WarehouseOutTime: nowtime,
  10134. Type: 1,
  10135. StorehouseId: storeConfig.StorehouseOutInfo,
  10136. IsCheck: 1,
  10137. OrderId: order.ID,
  10138. IsSys: 5,
  10139. }
  10140. //查询是否生成出库单
  10141. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10142. if out.ID == 0 {
  10143. service.AddSigleWarehouseOutOne(&warehouseOut)
  10144. }
  10145. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10146. for _, item := range oldGoods {
  10147. dialyPrepareOne := models.DialysisBeforePrepare{
  10148. GoodTypeId: item.GoodTypeId,
  10149. GoodId: item.GoodId,
  10150. PatientId: his.PatientId,
  10151. RecordDate: item.RecordDate,
  10152. UserOrgId: adminUser.CurrentOrgId,
  10153. Count: item.Count,
  10154. Ctime: time.Now().Unix(),
  10155. Creater: adminUser.AdminUser.Id,
  10156. CommdityCode: item.CommdityCode,
  10157. Status: 1,
  10158. StorehouseId: houseConfig.StorehouseOutInfo,
  10159. }
  10160. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  10161. //非零用
  10162. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  10163. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10164. //查询剩余库存
  10165. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10166. var sum_count int64
  10167. for _, item := range goodList {
  10168. sum_count += item.StockCount
  10169. }
  10170. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10171. //耗材
  10172. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10173. }
  10174. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  10175. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10176. //查询剩余库存
  10177. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10178. var sum_count int64
  10179. for _, item := range goodList {
  10180. sum_count += item.StockCount
  10181. }
  10182. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10183. //耗材
  10184. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10185. }
  10186. }
  10187. }
  10188. }
  10189. c.ServeSuccessJSON(map[string]interface{}{
  10190. "msg": "结算成功",
  10191. })
  10192. }
  10193. }
  10194. }
  10195. // 退款
  10196. func (c *HisApiController) Refund() {
  10197. order_id, _ := c.GetInt64("order_id")
  10198. order, _ := service.GetHisOrderByID(order_id)
  10199. adminUser := c.GetAdminUserInfo()
  10200. orgid := c.GetAdminUserInfo().CurrentOrgId
  10201. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  10202. if err != nil {
  10203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10204. return
  10205. }
  10206. tmp := strconv.FormatInt(order.ID, 10)
  10207. //当押金不为零时产生退费记录
  10208. if order.Decimal != 0 {
  10209. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  10210. if err != nil {
  10211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10212. return
  10213. }
  10214. }
  10215. fapiao, _ := service.GetFaPiaoHisOrderByID(order_id)
  10216. if fapiao.ID > 0 {
  10217. c.ServeSuccessJSON(map[string]interface{}{
  10218. "failed_code": -10,
  10219. "msg": "该结算已经开具发票无法退费,请先红冲发票",
  10220. })
  10221. return
  10222. }
  10223. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  10224. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  10225. var goods []*models.DialysisBeforePrepareGoods
  10226. var newGoods []*models.NewDialysisBeforePrepareGoods
  10227. var infos []*models.HisDoctorAdviceInfo
  10228. for _, info := range orders {
  10229. if info.AdviceId > 0 && info.ProjectId == 0 {
  10230. infos = append(infos, &info.HisDoctorAdviceInfo)
  10231. }
  10232. if info.ProjectId > 0 && info.AdviceId == 0 {
  10233. if info.HisPrescriptionProject.Type == 3 {
  10234. var good models.DialysisBeforePrepareGoods
  10235. var newGood models.NewDialysisBeforePrepareGoods
  10236. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10237. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10238. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10239. good.Count = int64(count)
  10240. good.StorehouseId = houseConfig.StorehouseOutInfo
  10241. good.ProjectId = info.HisPrescriptionProject.ID
  10242. good.PatientId = info.PatientId
  10243. good.OrderId = order_id
  10244. goods = append(goods, &good)
  10245. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10246. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10247. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10248. newGood.Count = int64(count2)
  10249. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10250. newGood.ProjectId = info.HisPrescriptionProject.ID
  10251. newGood.RecordDate = order.SettleAccountsDate
  10252. newGood.UserOrgId = order.UserOrgId
  10253. newGood.PatientId = info.PatientId
  10254. newGood.OrderId = order_id
  10255. newGoods = append(newGoods, &newGood)
  10256. }
  10257. }
  10258. }
  10259. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  10260. if settConfig.IsOpen == 1 {
  10261. for _, item := range infos {
  10262. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10263. }
  10264. for _, item := range newGoods {
  10265. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10266. }
  10267. }
  10268. c.ServeSuccessJSON(map[string]interface{}{
  10269. "msg": "退费成功",
  10270. })
  10271. }
  10272. func (c *HisApiController) RefundNumber() {
  10273. his_patient_id, _ := c.GetInt64("id")
  10274. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10275. info.Status = 0
  10276. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  10277. if count > 0 {
  10278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  10279. return
  10280. }
  10281. err := service.SaveHisPatient(info)
  10282. if err == nil {
  10283. c.ServeSuccessJSON(map[string]interface{}{
  10284. "msg": "退号成功",
  10285. })
  10286. } else {
  10287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10288. return
  10289. }
  10290. }
  10291. func (this *HisApiController) AdditionalCharge() {
  10292. dataBody := make(map[string]interface{}, 0)
  10293. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10294. fmt.Println(err)
  10295. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  10296. patient_id := int64(dataBody["patient_id"].(float64))
  10297. medicineData, _ := dataBody["medicineData"].([]interface{})
  10298. adminUserInfo := this.GetAdminUserInfo()
  10299. orgId := adminUserInfo.CurrentOrgId
  10300. admin_user_id := adminUserInfo.AdminUser.Id
  10301. timeStr := time.Now().Format("2006-01-02")
  10302. timeLayout := "2006-01-02 15:04:05"
  10303. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10304. timenow := timeStringToTime.Unix()
  10305. var additionalCharges []*models.HisAdditionalCharge
  10306. for _, item := range medicineData {
  10307. var randNum int
  10308. randNum = rand.Intn(10000) + 1000
  10309. timestamp := time.Now().Unix()
  10310. tempTime := time.Unix(timestamp, 0)
  10311. timeFormat := tempTime.Format("20060102150405")
  10312. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  10313. items := item.(map[string]interface{})
  10314. money := items["price"].(string)
  10315. item_id_str := items["item_id"].(string)
  10316. name := items["name"].(string)
  10317. id_str := items["id"].(string)
  10318. moneys, _ := strconv.ParseInt(money, 10, 64)
  10319. monStr := strconv.FormatInt(moneys, 10)
  10320. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  10321. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  10322. id, _ := strconv.ParseInt(id_str, 10, 64)
  10323. additionalCharge := &models.HisAdditionalCharge{
  10324. ID: id,
  10325. HisPatientId: his_patient_id,
  10326. UserOrgId: orgId,
  10327. PatientId: patient_id,
  10328. RecordDate: timenow,
  10329. Price: monneyStr,
  10330. Status: 1,
  10331. ItemName: name,
  10332. ItemId: item_id,
  10333. AdminUserId: admin_user_id,
  10334. CreatedTime: time.Now().Unix(),
  10335. OrderStatus: 0,
  10336. PrescriptionNumber: "",
  10337. BatchNumber: "",
  10338. FeedetlSn: p_number,
  10339. }
  10340. service.CreateAdditionalCharge(additionalCharge)
  10341. additionalCharges = append(additionalCharges, additionalCharge)
  10342. }
  10343. this.ServeSuccessJSON(map[string]interface{}{
  10344. "msg": "添加成功",
  10345. "additional_charges": additionalCharges,
  10346. })
  10347. }
  10348. func (this *HisApiController) DeleteAddition() {
  10349. id, _ := this.GetInt64("id")
  10350. //TODO 需要判断是否已经结算
  10351. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  10352. if err == nil {
  10353. this.ServeSuccessJSON(map[string]interface{}{
  10354. "msg": "删除成功",
  10355. })
  10356. return
  10357. } else {
  10358. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10359. return
  10360. }
  10361. }
  10362. func (this *HisApiController) GetAdminUsers() {
  10363. adminUser := this.GetAdminUserInfo()
  10364. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  10365. this.ServeSuccessJSON(map[string]interface{}{
  10366. "doctors": doctors,
  10367. })
  10368. }
  10369. func (this *HisApiController) GetLastOrNextHisPrescription() {
  10370. change_type, _ := this.GetInt64("type", 0)
  10371. record_date := this.GetString("record_time")
  10372. patient_id, _ := this.GetInt64("patient_id", 0)
  10373. p_type, _ := this.GetInt64("p_type", 0)
  10374. timeLayout := "2006-01-02"
  10375. loc, _ := time.LoadLocation("Local")
  10376. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  10377. record_time := theAdviceRecordTime.Unix()
  10378. adminUserInfo := this.GetAdminUserInfo()
  10379. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  10380. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10381. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10382. if config.ID > 0 && config.IsOpen == 1 {
  10383. for _, subitems := range prescriptions {
  10384. for _, item := range subitems.VMHisPrescription {
  10385. for _, subItem := range item.HisDoctorAdviceInfo {
  10386. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10387. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10388. if info.RetailPrice > 0 {
  10389. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10390. subItem.Drug.RetailPrice = drug.RetailPrice
  10391. }
  10392. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10393. subItem.Drug.MinPrice = info.RetailPrice
  10394. subItem.Drug.RetailPrice = info.RetailPrice
  10395. }
  10396. }
  10397. }
  10398. }
  10399. }
  10400. }
  10401. if config.ID > 0 && config.IsOpen == 1 {
  10402. for _, subitems := range prescriptions {
  10403. for _, item := range subitems.VMHisPrescription {
  10404. for _, subItem := range item.HisPrescriptionProject {
  10405. if subItem.Type == 3 {
  10406. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10407. if info.Price > 0 {
  10408. subItem.GoodInfo.PackingPrice = info.Price
  10409. }
  10410. }
  10411. }
  10412. }
  10413. }
  10414. }
  10415. }
  10416. if err == nil {
  10417. if len(prescriptions) == 0 {
  10418. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  10419. return
  10420. } else {
  10421. this.ServeSuccessJSON(map[string]interface{}{
  10422. "prescriptions": prescriptions,
  10423. })
  10424. return
  10425. }
  10426. } else {
  10427. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10428. return
  10429. }
  10430. }
  10431. func RemoveRepeatedPurviewElementByHP(arr []service.VMOtherHisPrescriptionInfo) (newArr []service.VMOtherHisPrescriptionInfo) {
  10432. newArr = make([]service.VMOtherHisPrescriptionInfo, 0)
  10433. for i := 0; i < len(arr); i++ {
  10434. repeat := false
  10435. for j := i + 1; j < len(arr); j++ {
  10436. if arr[i].PatientId == arr[j].PatientId && arr[i].RecordDate == arr[j].RecordDate {
  10437. repeat = true
  10438. break
  10439. }
  10440. }
  10441. if !repeat {
  10442. newArr = append(newArr, arr[i])
  10443. }
  10444. }
  10445. return
  10446. }
  10447. func (this *HisApiController) GetCallHisPrescription() {
  10448. patient_id, _ := this.GetInt64("patient_id", 0)
  10449. timeLayout := "2006-01-02"
  10450. loc, _ := time.LoadLocation("Local")
  10451. start_time := this.GetString("start_time")
  10452. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10453. end_time := this.GetString("end_time")
  10454. p_type, _ := this.GetInt64("p_type")
  10455. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10456. adminUserInfo := this.GetAdminUserInfo()
  10457. new_prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  10458. prescriptions := RemoveRepeatedPurviewElementByHP(new_prescriptions)
  10459. //if
  10460. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  10461. //
  10462. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  10463. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10464. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10465. if config.ID > 0 && config.IsOpen == 1 {
  10466. for _, subitems := range prescriptions {
  10467. for _, item := range subitems.VMHisPrescription {
  10468. for _, subItem := range item.HisDoctorAdviceInfo {
  10469. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10470. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10471. if info.RetailPrice > 0 {
  10472. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10473. subItem.Drug.RetailPrice = drug.RetailPrice
  10474. }
  10475. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10476. subItem.Drug.MinPrice = info.RetailPrice
  10477. subItem.Drug.RetailPrice = info.RetailPrice
  10478. }
  10479. }
  10480. }
  10481. }
  10482. }
  10483. }
  10484. if config.ID > 0 && config.IsOpen == 1 {
  10485. for _, subitems := range prescriptions {
  10486. for _, item := range subitems.VMHisPrescription {
  10487. for _, subItem := range item.HisPrescriptionProject {
  10488. if subItem.Type == 3 {
  10489. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10490. if info.Price > 0 {
  10491. subItem.GoodInfo.PackingPrice = info.Price
  10492. }
  10493. }
  10494. }
  10495. }
  10496. }
  10497. }
  10498. }
  10499. if err == nil {
  10500. this.ServeSuccessJSON(map[string]interface{}{
  10501. "prescriptions": prescriptions,
  10502. })
  10503. return
  10504. } else {
  10505. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10506. return
  10507. }
  10508. }
  10509. func (this *HisApiController) GetHisDayPrescription() {
  10510. timeLayout := "2006-01-02"
  10511. loc, _ := time.LoadLocation("Local")
  10512. start_time := this.GetString("start_time")
  10513. patient_id, _ := this.GetInt64("patient_id", 0)
  10514. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10515. end_time := this.GetString("end_time")
  10516. p_type, _ := this.GetInt64("p_type")
  10517. order_status, _ := this.GetInt64("type")
  10518. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10519. adminUserInfo := this.GetAdminUserInfo()
  10520. var dayHisPrescription []*models.HisPrescription
  10521. var err error
  10522. if order_status == 1 || order_status == 0 {
  10523. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10524. } else if order_status == 2 {
  10525. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10526. }
  10527. var settle_total float64
  10528. for _, item := range dayHisPrescription {
  10529. if len(item.HisPrescriptionProject) > 0 {
  10530. for _, subItem := range item.HisPrescriptionProject {
  10531. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10532. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10533. settle_total = settle_total + total
  10534. }
  10535. }
  10536. if len(item.HisDoctorAdviceInfo) > 0 {
  10537. for _, subItem := range item.HisDoctorAdviceInfo {
  10538. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10539. settle_total = settle_total + total
  10540. }
  10541. }
  10542. }
  10543. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10544. if err == nil {
  10545. this.ServeSuccessJSON(map[string]interface{}{
  10546. "day_prescription": dayHisPrescription,
  10547. "settle_total": settle_total,
  10548. })
  10549. return
  10550. } else {
  10551. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10552. return
  10553. }
  10554. }
  10555. func (c *HisApiController) GetHisChargePatientList() {
  10556. record_date := c.GetString("record_date")
  10557. order_status, _ := c.GetInt64("type")
  10558. sch_type, _ := c.GetInt64("sch_type")
  10559. timeLayout := "2006-01-02"
  10560. loc, _ := time.LoadLocation("Local")
  10561. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10562. if err != nil {
  10563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10564. return
  10565. }
  10566. recordDateTime := theTime.Unix()
  10567. adminInfo := c.GetAdminUserInfo()
  10568. var tempPatients []*service.NewTempPatients
  10569. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10570. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10571. if order_status != 2 {
  10572. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10573. } else {
  10574. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10575. }
  10576. } else {
  10577. if order_status != 2 {
  10578. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10579. } else {
  10580. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10581. }
  10582. }
  10583. var patients []*service.NewTempPatients
  10584. var patients_two []*service.NewTempPatients
  10585. for _, item := range tempPatients {
  10586. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10587. //过滤掉没挂号的和没开处方的
  10588. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10589. patients = append(patients, item)
  10590. }
  10591. //过滤掉没挂号的
  10592. if len(item.HisPatient) > 0 {
  10593. patients_two = append(patients_two, item)
  10594. }
  10595. } else {
  10596. if len(item.HisPrescription) > 0 {
  10597. patients = append(patients, item)
  10598. }
  10599. }
  10600. }
  10601. c.ServeSuccessJSON(map[string]interface{}{
  10602. "list": patients,
  10603. "list_two": patients_two,
  10604. })
  10605. }
  10606. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10607. record_date := c.GetString("record_date")
  10608. timeLayout := "2006-01-02"
  10609. loc, _ := time.LoadLocation("Local")
  10610. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10611. if err != nil {
  10612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10613. return
  10614. }
  10615. recordDateTime := theTime.Unix()
  10616. adminUser := c.GetAdminUserInfo()
  10617. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10618. var patients []*service.Patients
  10619. for _, item := range tempPatients {
  10620. if item.HisPatient.ID == 0 {
  10621. patients = append(patients, item)
  10622. }
  10623. }
  10624. c.ServeSuccessJSON(map[string]interface{}{
  10625. "list": patients,
  10626. //"list_two": patients_two,
  10627. })
  10628. }
  10629. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10630. newArr = make([]*service.Patients, 0)
  10631. for i := 0; i < len(patient); i++ {
  10632. repeat := false
  10633. for j := i + 1; j < len(patient); j++ {
  10634. if patient[i].ID == patient[j].ID {
  10635. repeat = true
  10636. break
  10637. }
  10638. }
  10639. if !repeat {
  10640. newArr = append(newArr, patient[i])
  10641. }
  10642. }
  10643. return
  10644. }
  10645. func (c *HisApiController) GetHisChargePatientInfo() {
  10646. patient_id, _ := c.GetInt64("patient_id")
  10647. his_patient_id, _ := c.GetInt64("his_patient_id")
  10648. record_date := c.GetString("record_date")
  10649. //start_time := c.GetString("start_time")
  10650. //end_time := c.GetString("end_time")
  10651. order_status, _ := c.GetInt64("type", 0)
  10652. p_type, _ := c.GetInt64("p_type", 0)
  10653. order_id, _ := c.GetInt64("order_id", 0)
  10654. timeLayout := "2006-01-02"
  10655. loc, _ := time.LoadLocation("Local")
  10656. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10657. if err != nil {
  10658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10659. return
  10660. }
  10661. recordDateTime := theTime.Unix()
  10662. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10663. //if err != nil {
  10664. //
  10665. //}
  10666. //startRecordDateTime := startTime.Unix()
  10667. //
  10668. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10669. //if err != nil {
  10670. //
  10671. //}
  10672. //endRecordDateTime := endTime.Unix()
  10673. admin := c.GetAdminUserInfo()
  10674. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10675. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10676. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10677. var prescriptions []*models.HisPrescription
  10678. //var unChargeMonthPrescriptions []*models.HisPrescription
  10679. order, _ := service.GetHisOrderByID(order_id)
  10680. if order_status == 1 || order_status == 0 {
  10681. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10682. } else if order_status == 2 {
  10683. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10684. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10685. }
  10686. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10687. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10688. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10689. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10690. //获取所有科室信息
  10691. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10692. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10693. c.ServeSuccessJSON(map[string]interface{}{
  10694. "his_info": his_patient_info,
  10695. "last_his_patient_info": last_his_patient_info,
  10696. "xt_info": xt_patient_info,
  10697. "prescription": prescriptions,
  10698. "case_history": case_history,
  10699. "info": patientPrescriptionInfo,
  10700. "last_info": lastPatientPrescriptionInfo,
  10701. "order": order,
  10702. "doctors": doctors,
  10703. "department": department,
  10704. "sch": sch,
  10705. })
  10706. return
  10707. }
  10708. func (c *HisApiController) GetAllOrderDetail() {
  10709. order_id, _ := c.GetInt64("id", 0)
  10710. order, _ := service.GetHisOrderByID(order_id)
  10711. if order.ID == 0 {
  10712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10713. return
  10714. }
  10715. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10716. org_id := c.GetAdminUserInfo().CurrentOrgId
  10717. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10718. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10719. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10720. c.ServeSuccessJSON(map[string]interface{}{
  10721. "order": order,
  10722. "order_info": order_info,
  10723. "patient": patient,
  10724. "admin_info": adminInfo,
  10725. "hospital_record": record,
  10726. })
  10727. return
  10728. }
  10729. func (c *HisApiController) GetAllOrderDetailCollect() {
  10730. order_id, _ := c.GetInt64("id", 0)
  10731. order, _ := service.GetHisOrderByID(order_id)
  10732. if order.ID == 0 {
  10733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10734. return
  10735. }
  10736. org_id := c.GetAdminUserInfo().CurrentOrgId
  10737. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10738. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10739. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10740. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10741. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10742. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10743. var bedCostTotal float64 = 0 //床位总费
  10744. //var bedCostSelfTotal float64 = 0 //床位自费
  10745. var operationCostTotal float64 = 0 //手术费
  10746. //var operationCostSelfTotal float64 = 0 //手术费
  10747. var otherCostTotal float64 = 0 //其他费用
  10748. //var otherCostSelfTotal float64 = 0 //其他费用
  10749. var materialCostTotal float64 = 0 //材料费
  10750. //var materialCostSelfTotal float64 = 0 //材料费
  10751. var westernMedicineCostTotal float64 = 0 //西药费
  10752. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10753. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10754. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10755. var checkCostTotal float64 = 0 //检查费
  10756. //var checkCostSelfTotal float64 = 0 //检查费
  10757. var laboratoryCostTotal float64 = 0 //化验费
  10758. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10759. var treatCostTotal float64 = 0 //治疗费用
  10760. //var treatCostSelfTotal float64 = 0 //治疗费用
  10761. var zhenChaCostTotal float64 = 0 //其他费用
  10762. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10763. decimal.DivisionPrecision = 2
  10764. var BalanceAccountsType int64
  10765. if his.ID > 0 {
  10766. BalanceAccountsType = his.BalanceAccountsType
  10767. } else {
  10768. BalanceAccountsType = record.BalanceAccountsType
  10769. }
  10770. if BalanceAccountsType != 2 {
  10771. for _, item := range order_info {
  10772. if org_id == 10215 {
  10773. if item.MedChrgitmType == "01" { //床位费
  10774. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10775. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10776. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10777. }
  10778. if item.MedChrgitmType == "02" { //诊察费
  10779. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10780. //zhenChaCostSelfTotal = zhenChaCostTotal
  10781. }
  10782. if item.MedChrgitmType == "03" { //检查费
  10783. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10784. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10785. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10786. }
  10787. //if item.MedChrgitmType == "02" { //检查费
  10788. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10789. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10790. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10791. //}
  10792. if item.MedChrgitmType == "04" { //化验费
  10793. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10794. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10795. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10796. }
  10797. if item.MedChrgitmType == "05" { //治疗费
  10798. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10799. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10800. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10801. }
  10802. if item.MedChrgitmType == "06" { //手术费
  10803. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10804. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10805. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10806. }
  10807. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10808. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10809. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10810. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10811. }
  10812. if item.MedChrgitmType == "09" { //西药费
  10813. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10814. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10815. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10816. }
  10817. if item.MedChrgitmType == "11" { //中成费
  10818. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10819. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10820. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10821. }
  10822. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10823. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10824. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10825. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10826. }
  10827. } else if org_id == 10188 || org_id == 10217 {
  10828. if item.MedChrgitmType == "01" { //床位费
  10829. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10830. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10831. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10832. }
  10833. if item.MedChrgitmType == "02" { //诊察费
  10834. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10835. //zhenChaCostSelfTotal = zhenChaCostTotal
  10836. }
  10837. if item.MedChrgitmType == "03" { //检查费
  10838. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10839. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10840. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10841. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10842. }
  10843. //if item.MedChrgitmType == "02" { //检查费
  10844. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10845. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10846. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10847. //}
  10848. if item.MedChrgitmType == "04" { //化验费
  10849. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10850. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10851. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10852. }
  10853. if item.MedChrgitmType == "05" { //治疗费
  10854. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10855. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10856. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10857. }
  10858. if item.MedChrgitmType == "06" { //手术费
  10859. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10860. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10861. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10862. }
  10863. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10864. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10865. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10866. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10867. }
  10868. if item.MedChrgitmType == "09" { //西药费
  10869. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10870. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10871. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10872. }
  10873. if item.MedChrgitmType == "11" { //中成费
  10874. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10875. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10876. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10877. }
  10878. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10879. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10880. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10881. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10882. }
  10883. } else {
  10884. if item.MedChrgitmType == "01" { //床位费
  10885. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10886. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10887. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10888. }
  10889. //if item.MedChrgitmType == "02" { //诊察费
  10890. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10891. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10892. //}
  10893. if item.MedChrgitmType == "03" { //检查费
  10894. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10895. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10896. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10897. }
  10898. //if item.MedChrgitmType == "02" { //检查费
  10899. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10900. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10901. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10902. //}
  10903. if item.MedChrgitmType == "04" { //化验费
  10904. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10905. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10906. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10907. }
  10908. if item.MedChrgitmType == "05" { //治疗费
  10909. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10910. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10911. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10912. }
  10913. if item.MedChrgitmType == "06" { //手术费
  10914. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10915. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10916. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10917. }
  10918. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10919. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10920. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10921. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10922. }
  10923. if item.MedChrgitmType == "09" { //西药费
  10924. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10925. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10926. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10927. }
  10928. if item.MedChrgitmType == "11" { //中成费
  10929. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10930. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10931. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10932. }
  10933. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10934. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10935. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10936. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10937. }
  10938. }
  10939. }
  10940. c.ServeSuccessJSON(map[string]interface{}{
  10941. "order": order,
  10942. "order_info": order_info,
  10943. "patient": patient,
  10944. "admin_info": adminInfo,
  10945. "his_hospital": record,
  10946. "bedCostTotal": bedCostTotal,
  10947. "operationCostTotal": operationCostTotal,
  10948. "otherCostTotal": otherCostTotal,
  10949. "materialCostTotal": materialCostTotal,
  10950. "westernMedicineCostTotal": westernMedicineCostTotal,
  10951. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10952. "checkCostTotal": checkCostTotal,
  10953. "zhenChaCostTotal": zhenChaCostTotal,
  10954. "laboratoryCostTotal": laboratoryCostTotal,
  10955. "treatCostTotal": treatCostTotal,
  10956. })
  10957. } else {
  10958. for _, item := range order_info {
  10959. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10960. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10961. item.MedChrgitmType = "09"
  10962. }
  10963. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10964. if item.HisPrescriptionProject.Type == 2 {
  10965. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10966. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10967. case 0:
  10968. item.MedChrgitmType = "0"
  10969. break
  10970. case 1:
  10971. item.MedChrgitmType = "14"
  10972. break
  10973. case 2:
  10974. item.MedChrgitmType = "05"
  10975. break
  10976. case 3:
  10977. item.MedChrgitmType = "03"
  10978. break
  10979. case 4:
  10980. item.MedChrgitmType = "03"
  10981. break
  10982. case 5:
  10983. item.MedChrgitmType = "08"
  10984. break
  10985. case 6:
  10986. item.MedChrgitmType = "14"
  10987. break
  10988. case 7:
  10989. item.MedChrgitmType = "14"
  10990. break
  10991. case 8:
  10992. item.MedChrgitmType = "03"
  10993. break
  10994. case 9:
  10995. item.MedChrgitmType = "14"
  10996. break
  10997. case 10:
  10998. item.MedChrgitmType = "14"
  10999. break
  11000. case 11:
  11001. item.MedChrgitmType = "06"
  11002. break
  11003. case 12:
  11004. item.MedChrgitmType = "12"
  11005. break
  11006. case 13:
  11007. item.MedChrgitmType = "01"
  11008. break
  11009. case 14:
  11010. item.MedChrgitmType = "04"
  11011. break
  11012. case 15:
  11013. item.MedChrgitmType = "14"
  11014. break
  11015. }
  11016. } else {
  11017. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11018. case 1:
  11019. item.MedChrgitmType = "14"
  11020. break
  11021. case 2:
  11022. item.MedChrgitmType = "05"
  11023. break
  11024. case 3:
  11025. item.MedChrgitmType = "04"
  11026. break
  11027. case 4:
  11028. item.MedChrgitmType = "14"
  11029. break
  11030. case 5:
  11031. item.MedChrgitmType = "08"
  11032. break
  11033. case 6:
  11034. item.MedChrgitmType = "14"
  11035. break
  11036. case 7:
  11037. item.MedChrgitmType = "14"
  11038. break
  11039. case 8:
  11040. item.MedChrgitmType = "03"
  11041. break
  11042. case 9:
  11043. item.MedChrgitmType = "14"
  11044. break
  11045. }
  11046. }
  11047. } else if item.HisPrescriptionProject.Type == 3 {
  11048. item.MedChrgitmType = "08"
  11049. }
  11050. }
  11051. }
  11052. for _, item := range order_info {
  11053. if org_id == 10215 {
  11054. if item.MedChrgitmType == "01" { //床位费
  11055. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11056. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11057. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11058. }
  11059. if item.MedChrgitmType == "02" { //诊察费
  11060. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11061. //zhenChaCostSelfTotal = zhenChaCostTotal
  11062. }
  11063. if item.MedChrgitmType == "03" { //检查费
  11064. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11065. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11066. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11067. }
  11068. //if item.MedChrgitmType == "02" { //检查费
  11069. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11070. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11071. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11072. //}
  11073. if item.MedChrgitmType == "04" { //化验费
  11074. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11075. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11076. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11077. }
  11078. if item.MedChrgitmType == "05" { //治疗费
  11079. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11080. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11081. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11082. }
  11083. if item.MedChrgitmType == "06" { //手术费
  11084. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11085. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11086. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11087. }
  11088. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11089. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11090. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11091. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11092. }
  11093. if item.MedChrgitmType == "09" { //西药费
  11094. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11095. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11096. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11097. }
  11098. if item.MedChrgitmType == "11" { //中成费
  11099. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11100. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11101. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11102. }
  11103. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11104. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11105. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11106. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11107. }
  11108. } else {
  11109. if item.MedChrgitmType == "01" { //床位费
  11110. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11111. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11112. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11113. }
  11114. //if item.MedChrgitmType == "02" { //诊察费
  11115. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11116. // //zhenChaCostSelfTotal = zhenChaCostTotal
  11117. //}
  11118. if item.MedChrgitmType == "03" { //检查费
  11119. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11120. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11121. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11122. }
  11123. //if item.MedChrgitmType == "02" { //检查费
  11124. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11125. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11126. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11127. //}
  11128. if item.MedChrgitmType == "04" { //化验费
  11129. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11130. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11131. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11132. }
  11133. if item.MedChrgitmType == "05" { //治疗费
  11134. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11135. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11136. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11137. }
  11138. if item.MedChrgitmType == "06" { //手术费
  11139. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11140. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11141. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11142. }
  11143. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11144. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11145. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11146. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11147. }
  11148. if item.MedChrgitmType == "09" { //西药费
  11149. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11150. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11151. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11152. }
  11153. if item.MedChrgitmType == "11" { //中成费
  11154. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11155. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11156. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11157. }
  11158. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11159. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11160. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11161. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11162. }
  11163. }
  11164. }
  11165. c.ServeSuccessJSON(map[string]interface{}{
  11166. "order": order,
  11167. "order_info": order_info,
  11168. "patient": patient,
  11169. "admin_info": adminInfo,
  11170. "his_hospital": record,
  11171. "bedCostTotal": bedCostTotal,
  11172. "operationCostTotal": operationCostTotal,
  11173. "otherCostTotal": otherCostTotal,
  11174. "materialCostTotal": materialCostTotal,
  11175. "westernMedicineCostTotal": westernMedicineCostTotal,
  11176. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11177. "checkCostTotal": checkCostTotal,
  11178. "zhenChaCostTotal": zhenChaCostTotal,
  11179. "laboratoryCostTotal": laboratoryCostTotal,
  11180. "treatCostTotal": treatCostTotal,
  11181. })
  11182. }
  11183. }
  11184. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  11185. page, _ := c.GetInt64("page")
  11186. limit, _ := c.GetInt64("limit")
  11187. keywords := c.GetString("keywords")
  11188. start_time := c.GetString("start_time")
  11189. end_time := c.GetString("end_time")
  11190. //clr_type := c.GetString("clr_type")
  11191. insutype := c.GetString("insutype")
  11192. timeLayout := "2006-01-02"
  11193. loc, _ := time.LoadLocation("Local")
  11194. var theStartTIme int64
  11195. if len(start_time) > 0 {
  11196. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11197. theStartTIme = theTime.Unix()
  11198. }
  11199. var theEndtTIme int64
  11200. if len(end_time) > 0 {
  11201. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11202. theEndtTIme = theTime.Unix()
  11203. }
  11204. if page <= 0 {
  11205. page = 1
  11206. }
  11207. if limit <= 0 {
  11208. limit = 10
  11209. }
  11210. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  11211. c.ServeSuccessJSON(map[string]interface{}{
  11212. "total": total,
  11213. "list": list,
  11214. })
  11215. return
  11216. }
  11217. func (c *HisApiController) GetPutOnRecordList() {
  11218. page, _ := c.GetInt64("page")
  11219. limit, _ := c.GetInt64("limit")
  11220. keywords := c.GetString("keywords")
  11221. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  11222. if page <= 0 {
  11223. page = 1
  11224. }
  11225. if limit <= 0 {
  11226. limit = 10
  11227. }
  11228. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  11229. c.ServeSuccessJSON(map[string]interface{}{
  11230. "total": total,
  11231. "list": list,
  11232. })
  11233. return
  11234. }
  11235. func (c *HisApiController) GetCompareData() {
  11236. start_time := c.GetString("start_time")
  11237. end_time := c.GetString("end_time")
  11238. insutype := c.GetString("insutype")
  11239. clr_type := c.GetString("clr_type")
  11240. timeLayout := "2006-01-02"
  11241. loc, _ := time.LoadLocation("Local")
  11242. var theStartTIme int64
  11243. if len(start_time) > 0 {
  11244. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11245. if err != nil {
  11246. theStartTIme = 0
  11247. }
  11248. theStartTIme = theTime.Unix()
  11249. }
  11250. var theEndtTIme int64
  11251. if len(end_time) > 0 {
  11252. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11253. if err != nil {
  11254. theEndtTIme = 0
  11255. }
  11256. theEndtTIme = theTime.Unix()
  11257. }
  11258. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  11259. fmt.Println(err)
  11260. if err == nil {
  11261. c.ServeSuccessJSON(map[string]interface{}{
  11262. "list": formData,
  11263. })
  11264. } else {
  11265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  11266. return
  11267. }
  11268. }
  11269. func (c *HisApiController) GetFaPiaoData() {
  11270. order_id, _ := c.GetInt64("order_id")
  11271. patient_id, _ := c.GetInt64("patient_id")
  11272. //number := c.GetString("number")
  11273. adminUser := c.GetAdminUserInfo()
  11274. order, _ := service.GetHisOrderByID(order_id)
  11275. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11276. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11277. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11278. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11279. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  11280. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  11281. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11282. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11283. var bedCostTotal float64 = 0 //床位总费
  11284. var bedCostSelfTotal float64 = 0 //床位自费
  11285. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11286. var operationCostTotal float64 = 0 //手术费
  11287. var operationCostSelfTotal float64 = 0 //手术费
  11288. var operationCostPartSelfTotal float64 = 0 //手术费
  11289. var otherCostTotal float64 = 0 //其他费用
  11290. var otherCostSelfTotal float64 = 0 //其他费用
  11291. var otherCostPartSelfTotal float64 = 0 //其他费用
  11292. var materialCostTotal float64 = 0 //材料费
  11293. var materialCostSelfTotal float64 = 0 //材料费
  11294. var materialCostPartSelfTotal float64 = 0 //材料费
  11295. var westernMedicineCostTotal float64 = 0 //西药费
  11296. var westernMedicineCostSelfTotal float64 = 0 //西药费
  11297. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11298. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11299. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11300. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11301. var checkCostTotal float64 = 0 //检查费
  11302. var checkCostSelfTotal float64 = 0 //检查费
  11303. var checkCostPartSelfTotal float64 = 0 //检查费
  11304. var hiliCostTotal float64 = 0 //护理费
  11305. var hiliCostSelfTotal float64 = 0 //护理费
  11306. var hiliCostPartSelfTotal float64 = 0 //护理费
  11307. var laboratoryCostTotal float64 = 0 //化验费
  11308. var laboratoryCostSelfTotal float64 = 0 //化验费
  11309. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11310. var treatCostTotal float64 = 0 //治疗费用
  11311. var treatCostSelfTotal float64 = 0 //治疗费用
  11312. var treatCostPartSelfTotal float64 = 0 //治疗费用
  11313. var zhenChaCostTotal float64 = 0 //其他费用
  11314. var zhenChaCostSelfTotal float64 = 0 //其他费用
  11315. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11316. decimal.DivisionPrecision = 2
  11317. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11318. var balanceAccountsType int64
  11319. if his.ID > 0 {
  11320. balanceAccountsType = his.BalanceAccountsType
  11321. } else {
  11322. balanceAccountsType = his_hospital_record.BalanceAccountsType
  11323. }
  11324. if balanceAccountsType == 2 {
  11325. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11326. for _, item := range orderInfos_two {
  11327. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11328. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11329. item.MedChrgitmType = "09"
  11330. }
  11331. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11332. if item.HisPrescriptionProject.Type == 2 {
  11333. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11334. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11335. case 0:
  11336. item.MedChrgitmType = "0"
  11337. break
  11338. case 1:
  11339. item.MedChrgitmType = "14"
  11340. break
  11341. case 2:
  11342. item.MedChrgitmType = "05"
  11343. break
  11344. case 3:
  11345. item.MedChrgitmType = "03"
  11346. break
  11347. case 4:
  11348. item.MedChrgitmType = "03"
  11349. break
  11350. case 5:
  11351. item.MedChrgitmType = "08"
  11352. break
  11353. case 6:
  11354. item.MedChrgitmType = "14"
  11355. break
  11356. case 7:
  11357. item.MedChrgitmType = "14"
  11358. break
  11359. case 8:
  11360. item.MedChrgitmType = "03"
  11361. break
  11362. case 9:
  11363. item.MedChrgitmType = "14"
  11364. break
  11365. case 10:
  11366. item.MedChrgitmType = "14"
  11367. break
  11368. case 11:
  11369. item.MedChrgitmType = "06"
  11370. break
  11371. case 12:
  11372. item.MedChrgitmType = "12"
  11373. break
  11374. case 13:
  11375. item.MedChrgitmType = "01"
  11376. break
  11377. case 14:
  11378. item.MedChrgitmType = "04"
  11379. break
  11380. case 15:
  11381. item.MedChrgitmType = "02"
  11382. break
  11383. }
  11384. } else {
  11385. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11386. case 1:
  11387. item.MedChrgitmType = "14"
  11388. break
  11389. case 2:
  11390. item.MedChrgitmType = "05"
  11391. break
  11392. case 3:
  11393. item.MedChrgitmType = "04"
  11394. break
  11395. case 4:
  11396. item.MedChrgitmType = "03"
  11397. break
  11398. case 5:
  11399. item.MedChrgitmType = "08"
  11400. break
  11401. case 6:
  11402. item.MedChrgitmType = "14"
  11403. break
  11404. case 7:
  11405. item.MedChrgitmType = "14"
  11406. break
  11407. case 8:
  11408. item.MedChrgitmType = "03"
  11409. break
  11410. case 9:
  11411. item.MedChrgitmType = "14"
  11412. break
  11413. }
  11414. }
  11415. } else if item.HisPrescriptionProject.Type == 3 {
  11416. item.MedChrgitmType = "08"
  11417. }
  11418. }
  11419. }
  11420. for _, item := range orderInfos_two {
  11421. fmt.Println(item.MedChrgitmType)
  11422. if item.MedChrgitmType == "07" { //床位费
  11423. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11424. hiliCostSelfTotal = hiliCostTotal
  11425. }
  11426. if item.MedChrgitmType == "01" { //床位费
  11427. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11428. bedCostSelfTotal = bedCostTotal
  11429. }
  11430. if item.MedChrgitmType == "02" { //诊察费
  11431. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11432. zhenChaCostSelfTotal = zhenChaCostTotal
  11433. }
  11434. if item.MedChrgitmType == "03" { //检查费
  11435. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11436. checkCostSelfTotal = checkCostTotal
  11437. }
  11438. if item.MedChrgitmType == "04" { //化验费
  11439. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11440. laboratoryCostSelfTotal = laboratoryCostTotal
  11441. }
  11442. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11443. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11444. treatCostSelfTotal = treatCostTotal
  11445. }
  11446. if item.MedChrgitmType == "06" { //手术费
  11447. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11448. operationCostSelfTotal = treatCostTotal
  11449. }
  11450. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  11451. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11452. materialCostSelfTotal = materialCostTotal
  11453. }
  11454. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11455. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11456. westernMedicineCostSelfTotal = westernMedicineCostTotal
  11457. }
  11458. if item.MedChrgitmType == "11" { //中成费
  11459. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11460. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11461. }
  11462. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11463. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11464. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11465. otherCostSelfTotal = otherCostTotal
  11466. }
  11467. } else {
  11468. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11469. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11470. otherCostSelfTotal = otherCostTotal
  11471. }
  11472. }
  11473. }
  11474. } else {
  11475. for _, item := range orderInfos {
  11476. if item.MedChrgitmType == "01" { //床位费
  11477. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11478. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11479. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11480. }
  11481. if item.MedChrgitmType == "02" { //诊察费
  11482. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11483. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11484. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11485. }
  11486. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11487. if item.MedChrgitmType == "03" { //检查费
  11488. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11489. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11490. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11491. }
  11492. } else {
  11493. if item.MedChrgitmType == "03" { //检查费
  11494. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11495. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11496. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11497. }
  11498. }
  11499. if item.MedChrgitmType == "04" { //化验费
  11500. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11501. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11502. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11503. }
  11504. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11505. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11506. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11507. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11508. }
  11509. if item.MedChrgitmType == "06" { //手术费
  11510. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11511. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11512. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11513. }
  11514. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11515. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11516. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11517. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11518. }
  11519. if item.MedChrgitmType == "07" { //护理
  11520. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11521. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11522. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11523. }
  11524. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11525. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11526. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11527. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11528. }
  11529. if item.MedChrgitmType == "11" { //中成费
  11530. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11531. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11532. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11533. }
  11534. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11535. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11536. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11537. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11538. }
  11539. }
  11540. }
  11541. timeLayout := "2006-01-02"
  11542. loc, _ := time.LoadLocation("Local")
  11543. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11544. if err != nil {
  11545. }
  11546. startRecordDateTime := startTime.Unix()
  11547. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11548. if err != nil {
  11549. }
  11550. endRecordDateTime := endTime.Unix()
  11551. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11552. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11553. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11554. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11555. c.ServeSuccessJSON(map[string]interface{}{
  11556. "charge_admin_name": charge_admin.UserName,
  11557. "order_number": order.Number, //业务流水号
  11558. "id_card_no": his.IdCardNo, //社会保障号
  11559. "patient": patient,
  11560. "department_name": department.Name, //科室
  11561. "number": his.Number, //门诊号
  11562. "date": order.SettleAccountsDate, //结算日期
  11563. "name": order.PsnName, //姓名
  11564. "gender": patient.Gender, //性别
  11565. "psn_cash_money": order.PsnCashPay, //个人支付
  11566. "pay_way": "门诊", //结算方式
  11567. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11568. "admin_user_name": admin.UserName, //收款员
  11569. "order": order,
  11570. "order_info": orderInfos_two,
  11571. "his": his,
  11572. "bedCostTotal": bedCostTotal,
  11573. "bedCostSelfTotal": bedCostSelfTotal,
  11574. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11575. "operationCostTotal": operationCostTotal,
  11576. "operationCostSelfTotal": operationCostSelfTotal,
  11577. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11578. "otherCostTotal": otherCostTotal,
  11579. "otherCostSelfTotal": otherCostSelfTotal,
  11580. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11581. "materialCostTotal": materialCostTotal,
  11582. "materialCostSelfTotal": materialCostSelfTotal,
  11583. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11584. "westernMedicineCostTotal": westernMedicineCostTotal,
  11585. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11586. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11587. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11588. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11589. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11590. "checkCostTotal": checkCostTotal,
  11591. "checkCostSelfTotal": checkCostSelfTotal,
  11592. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11593. "laboratoryCostTotal": laboratoryCostTotal,
  11594. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11595. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11596. "treatCostTotal": treatCostTotal,
  11597. "treatCostSelfTotal": treatCostSelfTotal,
  11598. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11599. "zhenChaCostTotal": zhenChaCostTotal,
  11600. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11601. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11602. "his_hospital_record": his_hospital_record,
  11603. "pre_pay_money": pre_pay_money,
  11604. "refund_sum": sum,
  11605. "doctor_info": doctor_info,
  11606. "hiliCostTotal": hiliCostTotal,
  11607. "hiliCostSelfTotal": hiliCostSelfTotal,
  11608. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11609. })
  11610. }
  11611. //func (c *HisApiController) GetFaPiaoDatas() {
  11612. // order_ids := c.GetString("order_ids")
  11613. // patient_id, _ := c.GetInt64("patient_id")
  11614. // adminUser := c.GetAdminUserInfo()
  11615. //
  11616. // orders := strings.Split(order_ids, ",")
  11617. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11618. //
  11619. // for _, item := range orders {
  11620. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11621. // order, _ := service.GetHisOrderByID(order_id)
  11622. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11623. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11624. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11625. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11626. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11627. //
  11628. // }
  11629. //
  11630. // var bedCostTotal float64 = 0 //床位总费
  11631. // var bedCostSelfTotal float64 = 0 //床位自费
  11632. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11633. //
  11634. // var operationCostTotal float64 = 0 //手术费
  11635. // var operationCostSelfTotal float64 = 0 //手术费
  11636. // var operationCostPartSelfTotal float64 = 0 //手术费
  11637. //
  11638. // var otherCostTotal float64 = 0 //其他费用
  11639. // var otherCostSelfTotal float64 = 0 //其他费用
  11640. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11641. //
  11642. // var materialCostTotal float64 = 0 //材料费
  11643. // var materialCostSelfTotal float64 = 0 //材料费
  11644. // var materialCostPartSelfTotal float64 = 0 //材料费
  11645. //
  11646. // var westernMedicineCostTotal float64 = 0 //西药费
  11647. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11648. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11649. //
  11650. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11651. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11652. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11653. //
  11654. // var checkCostTotal float64 = 0 //检查费
  11655. // var checkCostSelfTotal float64 = 0 //检查费
  11656. // var checkCostPartSelfTotal float64 = 0 //检查费
  11657. //
  11658. // var laboratoryCostTotal float64 = 0 //化验费
  11659. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11660. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11661. //
  11662. // var treatCostTotal float64 = 0 //治疗费用
  11663. // var treatCostSelfTotal float64 = 0 //治疗费用
  11664. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11665. //
  11666. // var zhenChaCostTotal float64 = 0 //其他费用
  11667. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11668. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11669. //
  11670. // decimal.DivisionPrecision = 2
  11671. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11672. //
  11673. // var balanceAccountsType int64
  11674. // if his.ID > 0 {
  11675. // balanceAccountsType = his.BalanceAccountsType
  11676. // } else {
  11677. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11678. // }
  11679. // if balanceAccountsType == 2 {
  11680. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11681. // for _, item := range orderInfos_two {
  11682. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11683. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11684. // item.MedChrgitmType = "09"
  11685. // }
  11686. //
  11687. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11688. // if item.HisPrescriptionProject.Type == 2 {
  11689. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11690. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11691. // case 0:
  11692. // item.MedChrgitmType = "0"
  11693. // break
  11694. // case 1:
  11695. // item.MedChrgitmType = "14"
  11696. // break
  11697. // case 2:
  11698. // item.MedChrgitmType = "05"
  11699. //
  11700. // break
  11701. // case 3:
  11702. // item.MedChrgitmType = "03"
  11703. //
  11704. // break
  11705. // case 4:
  11706. // item.MedChrgitmType = "03"
  11707. //
  11708. // break
  11709. // case 5:
  11710. // item.MedChrgitmType = "08"
  11711. //
  11712. // break
  11713. // case 6:
  11714. // item.MedChrgitmType = "14"
  11715. //
  11716. // break
  11717. // case 7:
  11718. // item.MedChrgitmType = "14"
  11719. //
  11720. // break
  11721. // case 8:
  11722. // item.MedChrgitmType = "03"
  11723. // break
  11724. // case 9:
  11725. // item.MedChrgitmType = "14"
  11726. // break
  11727. // case 10:
  11728. // item.MedChrgitmType = "14"
  11729. // break
  11730. // case 11:
  11731. // item.MedChrgitmType = "06"
  11732. // break
  11733. // case 12:
  11734. // item.MedChrgitmType = "12"
  11735. // break
  11736. // case 13:
  11737. // item.MedChrgitmType = "01"
  11738. // break
  11739. // case 14:
  11740. // item.MedChrgitmType = "04"
  11741. // break
  11742. // case 15:
  11743. // item.MedChrgitmType = "02"
  11744. // break
  11745. //
  11746. // }
  11747. //
  11748. // } else {
  11749. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11750. //
  11751. // case 1:
  11752. // item.MedChrgitmType = "14"
  11753. // break
  11754. // case 2:
  11755. // item.MedChrgitmType = "05"
  11756. //
  11757. // break
  11758. // case 3:
  11759. // item.MedChrgitmType = "03"
  11760. //
  11761. // break
  11762. // case 4:
  11763. // item.MedChrgitmType = "03"
  11764. //
  11765. // break
  11766. // case 5:
  11767. // item.MedChrgitmType = "08"
  11768. //
  11769. // break
  11770. // case 6:
  11771. // item.MedChrgitmType = "14"
  11772. //
  11773. // break
  11774. // case 7:
  11775. // item.MedChrgitmType = "14"
  11776. //
  11777. // break
  11778. // case 8:
  11779. // item.MedChrgitmType = "03"
  11780. // break
  11781. // case 9:
  11782. // item.MedChrgitmType = "14"
  11783. // break
  11784. //
  11785. // }
  11786. //
  11787. // }
  11788. //
  11789. // } else if item.HisPrescriptionProject.Type == 3 {
  11790. // item.MedChrgitmType = "08"
  11791. // }
  11792. // }
  11793. // }
  11794. //
  11795. // for _, item := range orderInfos_two {
  11796. // fmt.Println(item.MedChrgitmType)
  11797. // if item.MedChrgitmType == "01" { //床位费
  11798. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11799. // bedCostSelfTotal = bedCostTotal
  11800. // }
  11801. //
  11802. // if item.MedChrgitmType == "02" { //诊察费
  11803. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11804. // zhenChaCostSelfTotal = zhenChaCostTotal
  11805. // }
  11806. //
  11807. // if item.MedChrgitmType == "03" { //检查费
  11808. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11809. // checkCostSelfTotal = checkCostTotal
  11810. // }
  11811. //
  11812. // if item.MedChrgitmType == "04" { //化验费
  11813. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11814. // laboratoryCostSelfTotal = laboratoryCostTotal
  11815. // }
  11816. //
  11817. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11818. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11819. // treatCostSelfTotal = treatCostTotal
  11820. // }
  11821. //
  11822. // if item.MedChrgitmType == "06" { //手术费
  11823. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11824. // operationCostSelfTotal = treatCostTotal
  11825. // }
  11826. //
  11827. // if item.MedChrgitmType == "08" { //材料费
  11828. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11829. // materialCostSelfTotal = materialCostTotal
  11830. // }
  11831. //
  11832. // if item.MedChrgitmType == "09" { //西药费
  11833. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11834. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11835. // }
  11836. //
  11837. // if item.MedChrgitmType == "11" { //中成费
  11838. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11839. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11840. // }
  11841. //
  11842. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11843. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11844. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11845. // otherCostSelfTotal = otherCostTotal
  11846. // }
  11847. // } else {
  11848. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11849. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11850. // otherCostSelfTotal = otherCostTotal
  11851. // }
  11852. //
  11853. // }
  11854. //
  11855. // }
  11856. //
  11857. // } else {
  11858. // for _, item := range orderInfos {
  11859. // if item.MedChrgitmType == "01" { //床位费
  11860. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11861. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11862. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11863. // }
  11864. //
  11865. // if item.MedChrgitmType == "02" { //诊察费
  11866. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11867. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11868. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11869. // }
  11870. //
  11871. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11872. // if item.MedChrgitmType == "03" { //检查费
  11873. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11874. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11875. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11876. //
  11877. // }
  11878. // } else {
  11879. // if item.MedChrgitmType == "03" { //检查费
  11880. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11881. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11882. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11883. // }
  11884. //
  11885. // }
  11886. //
  11887. // if item.MedChrgitmType == "04" { //化验费
  11888. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11889. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11890. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11891. //
  11892. // }
  11893. //
  11894. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11895. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11896. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11897. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11898. //
  11899. // }
  11900. //
  11901. // if item.MedChrgitmType == "06" { //手术费
  11902. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11903. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11904. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11905. // }
  11906. //
  11907. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11908. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11909. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11910. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11911. // }
  11912. //
  11913. // if item.MedChrgitmType == "09" { //西药费
  11914. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11915. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11916. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11917. // }
  11918. //
  11919. // if item.MedChrgitmType == "11" { //中成费
  11920. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11921. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11922. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11923. // }
  11924. //
  11925. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11926. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11927. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11928. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11929. // }
  11930. //
  11931. // }
  11932. // }
  11933. // timeLayout := "2006-01-02"
  11934. // loc, _ := time.LoadLocation("Local")
  11935. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11936. // if err != nil {
  11937. // }
  11938. // startRecordDateTime := startTime.Unix()
  11939. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11940. // if err != nil {
  11941. // }
  11942. // endRecordDateTime := endTime.Unix()
  11943. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11944. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11945. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11946. //
  11947. // c.ServeSuccessJSON(map[string]interface{}{
  11948. // "order_number": order.Number, //业务流水号
  11949. // "id_card_no": his.IdCardNo, //社会保障号
  11950. // "department_name": department.Name, //科室
  11951. // "number": his.Number, //门诊号
  11952. // "date": order.SettleAccountsDate, //结算日期
  11953. // "name": order.PsnName, //姓名
  11954. // "gender": patient.Gender, //性别
  11955. // "psn_cash_money": order.PsnCashPay, //个人支付
  11956. // "pay_way": "门诊", //结算方式
  11957. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11958. // "admin_user_name": admin.UserName, //收款员
  11959. // "order": order,
  11960. // "order_info": orderInfos_two,
  11961. // "his": his,
  11962. // "bedCostTotal": bedCostTotal,
  11963. // "bedCostSelfTotal": bedCostSelfTotal,
  11964. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11965. // "operationCostTotal": operationCostTotal,
  11966. // "operationCostSelfTotal": operationCostSelfTotal,
  11967. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11968. // "otherCostTotal": otherCostTotal,
  11969. // "otherCostSelfTotal": otherCostSelfTotal,
  11970. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11971. // "materialCostTotal": materialCostTotal,
  11972. // "materialCostSelfTotal": materialCostSelfTotal,
  11973. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11974. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11975. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11976. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11977. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11978. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11979. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11980. // "checkCostTotal": checkCostTotal,
  11981. // "checkCostSelfTotal": checkCostSelfTotal,
  11982. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11983. // "laboratoryCostTotal": laboratoryCostTotal,
  11984. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11985. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11986. // "treatCostTotal": treatCostTotal,
  11987. // "treatCostSelfTotal": treatCostSelfTotal,
  11988. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11989. // "zhenChaCostTotal": zhenChaCostTotal,
  11990. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11991. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11992. // "his_hospital_record": his_hospital_record,
  11993. // "pre_pay_money": pre_pay_money,
  11994. // "refund_sum": sum,
  11995. // })
  11996. //
  11997. //}
  11998. func (this *HisApiController) GetIncomeStatisticsData() {
  11999. start_time := this.GetString("start_time")
  12000. end_time := this.GetString("end_time")
  12001. key_words := this.GetString("key_words")
  12002. limit, _ := this.GetInt64("limit")
  12003. page, _ := this.GetInt64("page")
  12004. if page <= 0 {
  12005. page = 1
  12006. }
  12007. if limit <= 0 {
  12008. limit = 10
  12009. }
  12010. statistics_type, _ := this.GetInt64("statistics_type")
  12011. admin := this.GetAdminUserInfo()
  12012. timeLayout := "2006-01-02"
  12013. loc, _ := time.LoadLocation("Local")
  12014. var theStartTIme int64
  12015. if len(start_time) > 0 {
  12016. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12017. if err != nil {
  12018. theStartTIme = 0
  12019. }
  12020. theStartTIme = theTime.Unix()
  12021. }
  12022. var theEndtTIme int64
  12023. if len(end_time) > 0 {
  12024. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12025. if err != nil {
  12026. theEndtTIme = 0
  12027. }
  12028. theEndtTIme = theTime.Unix()
  12029. }
  12030. if statistics_type == 1 {
  12031. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  12032. this.ServeSuccessJSON(map[string]interface{}{
  12033. "list": list,
  12034. "total": total,
  12035. })
  12036. } else {
  12037. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  12038. this.ServeSuccessJSON(map[string]interface{}{
  12039. "list": list,
  12040. "total": total,
  12041. })
  12042. }
  12043. }
  12044. func (c *HisApiController) PostProjectInformation() {
  12045. adminUser := c.GetAdminUserInfo()
  12046. orgId := adminUser.CurrentOrgId
  12047. dataBody := make(map[string]interface{}, 0)
  12048. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12049. if err != nil {
  12050. utils.ErrorLog(err.Error())
  12051. return
  12052. }
  12053. utils.ErrorLog("%v", dataBody)
  12054. var projectList []*models.HisProject
  12055. var total_goods []interface{}
  12056. tempProjects := dataBody["projects"].([]interface{})
  12057. total_goods = tempProjects
  12058. for index, projectMap := range tempProjects {
  12059. projectM := projectMap.(map[string]interface{})
  12060. var project models.HisProject
  12061. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  12062. utils.ErrorLog("project_name")
  12063. return
  12064. }
  12065. project_name, _ := projectM["project_name"].(string)
  12066. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  12067. err_log := models.ExportErrLog{
  12068. LogType: 6,
  12069. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12070. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  12071. Status: 1,
  12072. CreateTime: time.Now().Unix(),
  12073. UpdateTime: time.Now().Unix(),
  12074. ExportTime: time.Now().Unix(),
  12075. }
  12076. service.CreateExportErrLog(&err_log)
  12077. continue
  12078. }
  12079. project.ProjectName = project_name
  12080. prices := projectM["price"].(string)
  12081. price, _ := strconv.ParseFloat(prices, 64)
  12082. if price <= 0 { //名字为空则生成一条导入错误日志
  12083. err_log := models.ExportErrLog{
  12084. LogType: 6,
  12085. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12086. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  12087. Status: 1,
  12088. CreateTime: time.Now().Unix(),
  12089. UpdateTime: time.Now().Unix(),
  12090. ExportTime: time.Now().Unix(),
  12091. }
  12092. service.CreateExportErrLog(&err_log)
  12093. continue
  12094. }
  12095. project.Price = price
  12096. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  12097. utils.ErrorLog("unit_id")
  12098. return
  12099. }
  12100. unit := projectM["unit"].(string)
  12101. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  12102. err_log := models.ExportErrLog{
  12103. LogType: 6,
  12104. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12105. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  12106. Status: 1,
  12107. CreateTime: time.Now().Unix(),
  12108. UpdateTime: time.Now().Unix(),
  12109. ExportTime: time.Now().Unix(),
  12110. }
  12111. service.CreateExportErrLog(&err_log)
  12112. continue
  12113. }
  12114. project.Unit = unit
  12115. cost_classify := projectM["cost_classify"].(string)
  12116. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  12117. err_log := models.ExportErrLog{
  12118. LogType: 6,
  12119. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12120. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12121. Status: 1,
  12122. CreateTime: time.Now().Unix(),
  12123. UpdateTime: time.Now().Unix(),
  12124. ExportTime: time.Now().Unix(),
  12125. }
  12126. service.CreateExportErrLog(&err_log)
  12127. continue
  12128. }
  12129. var costClassify = "费用类别"
  12130. var cost_classify_id int64
  12131. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  12132. if len(cost_classify) != 0 {
  12133. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  12134. if errcode == gorm.ErrRecordNotFound {
  12135. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  12136. dataconfig := models.DictDataconfig{
  12137. ParentId: costClassifyConfig.ID,
  12138. Module: "system",
  12139. OrgId: orgId,
  12140. Name: cost_classify,
  12141. FieldName: "",
  12142. Value: costConfig.Value + 1,
  12143. CreatedTime: "",
  12144. UpdatedTime: "",
  12145. CreateUserId: adminUser.AdminUser.Id,
  12146. Status: 1,
  12147. Remark: "",
  12148. DeleteIdSystem: 0,
  12149. Title: "",
  12150. Content: "",
  12151. Order: 0,
  12152. Code: "",
  12153. }
  12154. service.CreatedDicConfig(&dataconfig)
  12155. }
  12156. }
  12157. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  12158. for _, it := range costClassList {
  12159. if cost_classify == it.Name {
  12160. cost_classify_id = int64(it.Value)
  12161. }
  12162. }
  12163. project.CostClassify = cost_classify_id
  12164. executive_section := projectM["executive_section"].(string)
  12165. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  12166. err_log := models.ExportErrLog{
  12167. LogType: 6,
  12168. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12169. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  12170. Status: 1,
  12171. CreateTime: time.Now().Unix(),
  12172. UpdateTime: time.Now().Unix(),
  12173. ExportTime: time.Now().Unix(),
  12174. }
  12175. service.CreateExportErrLog(&err_log)
  12176. continue
  12177. }
  12178. if len(executive_section) != 0 {
  12179. //查找科室是否有内容
  12180. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  12181. if errcodedepart == gorm.ErrRecordNotFound {
  12182. department := models.XtHisDepartment{
  12183. Name: executive_section,
  12184. Status: 1,
  12185. UserOrgId: adminUser.CurrentOrgId,
  12186. CreatedTime: time.Now().Unix(),
  12187. }
  12188. service.CreateDePartment(&department)
  12189. }
  12190. }
  12191. var executive_section_id int64
  12192. departMentList, _ := service.GetAllDepartMent(orgId)
  12193. for _, it := range departMentList {
  12194. if executive_section == it.Name {
  12195. executive_section_id = it.ID
  12196. }
  12197. }
  12198. project.ExecutiveSection = executive_section_id
  12199. medical_coverage := projectM["medical_coverage"].(string)
  12200. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  12201. err_log := models.ExportErrLog{
  12202. LogType: 6,
  12203. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12204. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12205. Status: 1,
  12206. CreateTime: time.Now().Unix(),
  12207. UpdateTime: time.Now().Unix(),
  12208. ExportTime: time.Now().Unix(),
  12209. }
  12210. service.CreateExportErrLog(&err_log)
  12211. continue
  12212. }
  12213. var medicalCoverage = "医保等级"
  12214. var medical_coverage_id int64
  12215. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  12216. if len(medical_coverage) != 0 {
  12217. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  12218. if errormedicalcoverage == gorm.ErrRecordNotFound {
  12219. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  12220. dataconfig := models.DictDataconfig{
  12221. ParentId: medicalCoverageConfig.ID,
  12222. Module: "system",
  12223. OrgId: orgId,
  12224. Name: medical_coverage,
  12225. FieldName: "",
  12226. Value: medicalCoverageConfig.Value + 1,
  12227. CreatedTime: "",
  12228. UpdatedTime: "",
  12229. CreateUserId: adminUser.AdminUser.Id,
  12230. Status: 1,
  12231. Remark: "",
  12232. DeleteIdSystem: 0,
  12233. Title: "",
  12234. Content: "",
  12235. Order: 0,
  12236. Code: "",
  12237. }
  12238. service.CreatedDicConfig(&dataconfig)
  12239. }
  12240. }
  12241. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  12242. for _, it := range medicalCoverageList {
  12243. if medical_coverage == it.Name {
  12244. medical_coverage_id = int64(it.Value)
  12245. }
  12246. }
  12247. project.MedicalCoverage = medical_coverage_id
  12248. pinyin := projectM["pinyin"].(string)
  12249. project.Pinyin = pinyin
  12250. wubi := projectM["wubi"].(string)
  12251. project.Wubi = wubi
  12252. statistical_classification := projectM["statistical_classification"].(string)
  12253. var statisticalClassification = "统计分类"
  12254. var statistical_classification_id int64
  12255. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  12256. if len(statistical_classification) != 0 {
  12257. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  12258. if classificationerrcodes == gorm.ErrRecordNotFound {
  12259. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  12260. dataconfig := models.DictDataconfig{
  12261. ParentId: classiFication.ID,
  12262. Module: "system",
  12263. OrgId: orgId,
  12264. Name: statistical_classification,
  12265. FieldName: "",
  12266. Value: classiFicationConfig.Value + 1,
  12267. CreatedTime: "",
  12268. UpdatedTime: "",
  12269. CreateUserId: adminUser.AdminUser.Id,
  12270. Status: 1,
  12271. Remark: "",
  12272. DeleteIdSystem: 0,
  12273. Title: "",
  12274. Content: "",
  12275. Order: 0,
  12276. Code: "",
  12277. }
  12278. service.CreatedDicConfig(&dataconfig)
  12279. }
  12280. }
  12281. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  12282. for _, it := range classiFicationList {
  12283. if statistical_classification == it.Name {
  12284. statistical_classification_id = int64(it.Value)
  12285. }
  12286. }
  12287. project.StatisticalClassification = statistical_classification_id
  12288. disease_directory := int64(projectM["disease_directory"].(float64))
  12289. project.DiseaseDirectory = disease_directory
  12290. is_record := int64(projectM["is_record"].(float64))
  12291. project.IsRecord = is_record
  12292. medical_code := projectM["medical_code"].(string)
  12293. project.MedicalCode = medical_code
  12294. tube_color := projectM["tube_color"].(string)
  12295. var tubeColor = "试管颜色"
  12296. var tube_color_id int64
  12297. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  12298. if len(tube_color) != 0 {
  12299. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  12300. if errcodetube == gorm.ErrRecordNotFound {
  12301. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  12302. dataconfig := models.DictDataconfig{
  12303. ParentId: tubeColorConfig.ID,
  12304. Module: "system",
  12305. OrgId: orgId,
  12306. Name: tube_color,
  12307. FieldName: "",
  12308. Value: tubeConfig.Value + 1,
  12309. CreatedTime: "",
  12310. UpdatedTime: "",
  12311. CreateUserId: adminUser.AdminUser.Id,
  12312. Status: 1,
  12313. Remark: "",
  12314. DeleteIdSystem: 0,
  12315. Title: "",
  12316. Content: "",
  12317. Order: 0,
  12318. Code: "",
  12319. }
  12320. service.CreatedDicConfig(&dataconfig)
  12321. }
  12322. }
  12323. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  12324. for _, it := range tubeColorList {
  12325. if tube_color == it.Name {
  12326. tube_color_id = int64(it.Value)
  12327. }
  12328. }
  12329. project.TubeColor = tube_color_id
  12330. single_dose := projectM["single_dose"].(string)
  12331. project.SingleDose = single_dose
  12332. execution_frequency := projectM["execution_frequency"].(string)
  12333. project.ExecutionFrequency = execution_frequency
  12334. delivery_way := projectM["delivery_way"].(string)
  12335. project.DeliveryWay = delivery_way
  12336. number_days := projectM["number_days"].(string)
  12337. project.NumberDays = number_days
  12338. total := projectM["total"].(string)
  12339. project.Total = total
  12340. medical_status := int64(projectM["medical_status"].(float64))
  12341. project.MedicalStatus = medical_status
  12342. category := int64(projectM["category"].(float64))
  12343. project.Category = category
  12344. specail_project := int64(projectM["specail_project"].(float64))
  12345. project.SpecailProject = specail_project
  12346. social_security_directory_code := projectM["social_security_directory_code"].(string)
  12347. project.SocialSecurityDirectoryCode = social_security_directory_code
  12348. remark := projectM["remark"].(string)
  12349. project.Remark = remark
  12350. record_date := projectM["record_date"].(string)
  12351. timeLayout := "2006-01-02"
  12352. loc, _ := time.LoadLocation("Local")
  12353. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12354. project.RecordDate = theTime.Unix()
  12355. projectList = append(projectList, &project)
  12356. }
  12357. export_time := time.Now().Unix()
  12358. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  12359. if len(projectList) > 0 {
  12360. for _, item := range projectList {
  12361. hans := item.ProjectName // 要转换的汉字字符串
  12362. // 创建一个拼音转换器
  12363. p := pinyin.NewArgs()
  12364. // 将汉字转为拼音
  12365. pinyinSlice := pinyin.Pinyin(hans, p)
  12366. // 输出拼音
  12367. fmt.Println("Pinyin:", pinyinSlice)
  12368. // 获取首字母
  12369. firstLetter := ""
  12370. for _, py := range pinyinSlice {
  12371. if len(py) > 0 {
  12372. firstLetter += string(py[0][0])
  12373. }
  12374. }
  12375. item.FirstLetter = firstLetter
  12376. project := models.HisProject{
  12377. ProjectName: item.ProjectName,
  12378. Price: item.Price,
  12379. Unit: item.Unit,
  12380. CostClassify: item.CostClassify,
  12381. ExecutiveSection: item.ExecutiveSection,
  12382. MedicalCoverage: item.MedicalCoverage,
  12383. UserOrgId: orgId,
  12384. Status: 1,
  12385. CreatedTime: time.Now().Unix(),
  12386. Pinyin: item.Pinyin,
  12387. Wubi: item.Wubi,
  12388. StatisticalClassification: item.StatisticalClassification,
  12389. DiseaseDirectory: item.DiseaseDirectory,
  12390. IsRecord: item.IsRecord,
  12391. MedicalCode: item.MedicalCode,
  12392. TubeColor: item.TubeColor,
  12393. SingleDose: item.SingleDose,
  12394. DeliveryWay: item.DeliveryWay,
  12395. NumberDays: item.NumberDays,
  12396. Total: item.Total,
  12397. Category: item.Category,
  12398. MedicalStatus: item.MedicalStatus,
  12399. SpecailProject: item.SpecailProject,
  12400. RecordDate: item.RecordDate,
  12401. Remark: item.Remark,
  12402. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  12403. ExecutionFrequency: item.ExecutionFrequency,
  12404. FirstLetter: item.FirstLetter,
  12405. }
  12406. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  12407. if errcodeproject == gorm.ErrRecordNotFound {
  12408. service.CreateProjectInfomation(&project)
  12409. } else if errcodeproject == nil {
  12410. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  12411. }
  12412. log := models.ExportLog{
  12413. LogType: 6,
  12414. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12415. TotalNum: int64(len(total_goods)),
  12416. FailNum: int64(len(errLogs)),
  12417. SuccessNum: int64(len(projectList)),
  12418. CreateTime: time.Now().Unix(),
  12419. UpdateTime: time.Now().Unix(),
  12420. ExportTime: export_time,
  12421. Status: 1,
  12422. }
  12423. service.CreateExportLog(&log)
  12424. c.ServeSuccessJSON(map[string]interface{}{
  12425. "msg": "导入成功",
  12426. "total_num": len(total_goods),
  12427. "success_num": len(projectList),
  12428. "fail_num": int64(len(errLogs)),
  12429. })
  12430. }
  12431. } else {
  12432. log := models.ExportLog{
  12433. LogType: 6,
  12434. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12435. TotalNum: int64(len(total_goods)),
  12436. FailNum: int64(len(errLogs)),
  12437. SuccessNum: int64(len(projectList)),
  12438. CreateTime: time.Now().Unix(),
  12439. UpdateTime: time.Now().Unix(),
  12440. ExportTime: export_time,
  12441. Status: 1,
  12442. }
  12443. service.CreateExportLog(&log)
  12444. c.ServeSuccessJSON(map[string]interface{}{
  12445. "msg": "导入成功",
  12446. "total_num": len(total_goods),
  12447. "success_num": len(projectList),
  12448. "fail_num": int64(len(errLogs)),
  12449. })
  12450. }
  12451. }
  12452. //func (this *HisApiController) EditProjectInformation(){
  12453. //
  12454. // id, _ := this.GetInt64("id")
  12455. // project_team := this.GetString("project_team")
  12456. // price := this.GetString("price")
  12457. // price_float, _ := strconv.ParseFloat(price, 64)
  12458. // pinyin := this.GetString("pinyin")
  12459. // wubi := this.GetString("wubi")
  12460. // tube_color, _ := this.GetInt64("tube_color")
  12461. // team_type, _ := this.GetInt64("team_type")
  12462. // remark := this.GetString("remark")
  12463. // ids := this.GetString("ids")
  12464. // item_id := this.GetString("item_id")
  12465. // projectTeam := models.XtHisProjectTeam{
  12466. // ProjectTeam: project_team,
  12467. // Price: price_float,
  12468. // Pinyin: pinyin,
  12469. // Wubi: wubi,
  12470. // TubeColor: tube_color,
  12471. // TeamType: team_type,
  12472. // Remark: remark,
  12473. // ProjectId: ids,
  12474. // ItemId: item_id,
  12475. // }
  12476. //
  12477. //
  12478. // dataBody := make(map[string]interface{}, 0)
  12479. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12480. // if err != nil {
  12481. // utils.ErrorLog(err.Error())
  12482. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12483. // return
  12484. // }
  12485. //
  12486. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12487. //
  12488. //
  12489. // if err != nil {
  12490. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12491. // return
  12492. // }
  12493. //
  12494. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12495. // infos, _ := dataBody["info"].([]interface{})
  12496. // if len(infos) > 0 {
  12497. // var ids []string
  12498. //
  12499. // for _, item := range infos {
  12500. // items := item.(map[string]interface{})
  12501. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12502. // utils.ErrorLog("id")
  12503. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12504. // return
  12505. // }
  12506. // id := int64(items["id"].(float64))
  12507. //
  12508. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12509. // utils.ErrorLog("type")
  12510. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12511. // return
  12512. // }
  12513. // types := int64(items["type"].(float64))
  12514. //
  12515. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12516. // utils.ErrorLog("number")
  12517. // }
  12518. //
  12519. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12520. //
  12521. // projectList := models.XtHisProjectList{
  12522. // Number: number,
  12523. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12524. // ProjectId: id,
  12525. // Status: 1,
  12526. // CreatedTime: time.Now().Unix(),
  12527. // UpdatedTime: time.Now().Unix(),
  12528. // TeamId: projectTeam.ID,
  12529. // Type: types,
  12530. // }
  12531. // list := projectList
  12532. //
  12533. // service.CreateProjectList(&list)
  12534. //
  12535. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12536. //
  12537. // }
  12538. // ids_str := strings.Join(ids, ",")
  12539. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12540. // service.SaveProjectTeam(&projectTeam)
  12541. // this.ServeSuccessJSON(map[string]interface{}{
  12542. // "projectTeam": projectTeam,
  12543. // })
  12544. // }
  12545. // }
  12546. //}
  12547. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12548. name := c.GetString("name")
  12549. mode_id, _ := c.GetInt64("mode", 0)
  12550. types, _ := c.GetInt64("type", 0)
  12551. patient_id, _ := c.GetInt64("patient_id", 0)
  12552. types = 1
  12553. adminInfo := c.GetAdminUserInfo()
  12554. template := &models.HisPrescriptionTemplate{
  12555. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12556. PatientId: patient_id,
  12557. Type: types,
  12558. Status: 1,
  12559. Ctime: time.Now().Unix(),
  12560. Mtime: time.Now().Unix(),
  12561. Name: name,
  12562. Mode: mode_id,
  12563. }
  12564. dataBody := make(map[string]interface{}, 0)
  12565. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12566. if err != nil {
  12567. utils.ErrorLog(err.Error())
  12568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12569. return
  12570. }
  12571. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12572. //如果已经存在记录则删除处方
  12573. if template_one.ID > 0 {
  12574. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12575. var ids []int64
  12576. var org_id int64
  12577. for _, item := range ps {
  12578. org_id = c.GetAdminUserInfo().CurrentOrgId
  12579. ids = append(ids, item.ID)
  12580. }
  12581. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12582. if err2 == nil {
  12583. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12584. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12585. if len(prescriptions) > 0 {
  12586. for _, item := range prescriptions {
  12587. items := item.(map[string]interface{})
  12588. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12589. utils.ErrorLog("type")
  12590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12591. return
  12592. }
  12593. types := int64(items["type"].(float64))
  12594. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12595. utils.ErrorLog("med_type")
  12596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12597. return
  12598. }
  12599. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12600. ctime := time.Now().Unix()
  12601. prescription := &models.HisPrescriptionInfoTemplate{
  12602. PatientId: patient_id,
  12603. UserOrgId: adminInfo.CurrentOrgId,
  12604. Ctime: ctime,
  12605. Mtime: ctime,
  12606. Type: types,
  12607. Modifier: adminInfo.AdminUser.Id,
  12608. Creator: adminInfo.AdminUser.Id,
  12609. Status: 1,
  12610. PTemplateId: template_one.ID,
  12611. MedType: med_type,
  12612. }
  12613. service.CreateHisPrescriptionInfoTemplate(prescription)
  12614. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12615. advices := items["advices"].([]interface{})
  12616. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12617. ctime := time.Now().Unix()
  12618. mtime := ctime
  12619. if len(advices) > 0 {
  12620. for _, advice := range advices {
  12621. var s models.HisPrescriptionAdviceTemplate
  12622. s.PrescriptionId = prescription.ID
  12623. s.AdviceType = 2
  12624. s.StopState = 2
  12625. s.ExecutionState = 2
  12626. s.Status = 1
  12627. s.UserOrgId = adminInfo.CurrentOrgId
  12628. s.CreatedTime = ctime
  12629. s.UpdatedTime = mtime
  12630. s.PatientId = patient_id
  12631. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12632. if errcode > 0 {
  12633. c.ServeFailJSONWithSGJErrorCode(errcode)
  12634. return
  12635. }
  12636. service.CreateHisPrescriptionAdviceTemplate(&s)
  12637. }
  12638. }
  12639. }
  12640. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12641. projects := items["project"].([]interface{})
  12642. if len(projects) > 0 {
  12643. for _, project := range projects {
  12644. var p models.HisPrescriptionProjectTemplate
  12645. p.PrescriptionId = prescription.ID
  12646. p.Ctime = time.Now().Unix()
  12647. p.Mtime = time.Now().Unix()
  12648. p.PatientId = patient_id
  12649. p.UserOrgId = adminInfo.CurrentOrgId
  12650. p.Status = 1
  12651. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12652. if errcode > 0 {
  12653. c.ServeFailJSONWithSGJErrorCode(errcode)
  12654. return
  12655. }
  12656. service.CreateHisPrescriptionProjectTemplate(&p)
  12657. }
  12658. }
  12659. }
  12660. }
  12661. c.ServeSuccessJSON(map[string]interface{}{
  12662. "msg": "创建成功",
  12663. })
  12664. }
  12665. }
  12666. } else {
  12667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12668. return
  12669. }
  12670. } else {
  12671. err3 := service.CreateHisPrescriptionTemplate(template)
  12672. if err3 == nil {
  12673. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12674. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12675. if len(prescriptions) > 0 {
  12676. for _, item := range prescriptions {
  12677. items := item.(map[string]interface{})
  12678. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12679. utils.ErrorLog("type")
  12680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12681. return
  12682. }
  12683. types := int64(items["type"].(float64))
  12684. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12685. utils.ErrorLog("med_type")
  12686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12687. return
  12688. }
  12689. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12690. ctime := time.Now().Unix()
  12691. prescription := &models.HisPrescriptionInfoTemplate{
  12692. PatientId: patient_id,
  12693. UserOrgId: adminInfo.CurrentOrgId,
  12694. Ctime: ctime,
  12695. Mtime: ctime,
  12696. Type: types,
  12697. Modifier: adminInfo.AdminUser.Id,
  12698. Creator: adminInfo.AdminUser.Id,
  12699. Status: 1,
  12700. PTemplateId: template.ID,
  12701. MedType: med_type,
  12702. }
  12703. service.CreateHisPrescriptionInfoTemplate(prescription)
  12704. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12705. advices := items["advices"].([]interface{})
  12706. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12707. ctime := time.Now().Unix()
  12708. mtime := ctime
  12709. if len(advices) > 0 {
  12710. for _, advice := range advices {
  12711. var s models.HisPrescriptionAdviceTemplate
  12712. s.PrescriptionId = prescription.ID
  12713. s.AdviceType = 2
  12714. s.StopState = 2
  12715. s.ExecutionState = 2
  12716. s.Status = 1
  12717. s.UserOrgId = adminInfo.CurrentOrgId
  12718. s.CreatedTime = ctime
  12719. s.UpdatedTime = mtime
  12720. s.PatientId = patient_id
  12721. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12722. if errcode > 0 {
  12723. c.ServeFailJSONWithSGJErrorCode(errcode)
  12724. return
  12725. }
  12726. service.CreateHisPrescriptionAdviceTemplate(&s)
  12727. }
  12728. }
  12729. }
  12730. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12731. projects := items["project"].([]interface{})
  12732. if len(projects) > 0 {
  12733. for _, project := range projects {
  12734. var p models.HisPrescriptionProjectTemplate
  12735. p.PrescriptionId = prescription.ID
  12736. p.Ctime = time.Now().Unix()
  12737. p.Mtime = time.Now().Unix()
  12738. p.PatientId = patient_id
  12739. p.UserOrgId = adminInfo.CurrentOrgId
  12740. p.Status = 1
  12741. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12742. if errcode > 0 {
  12743. c.ServeFailJSONWithSGJErrorCode(errcode)
  12744. return
  12745. }
  12746. service.CreateHisPrescriptionProjectTemplate(&p)
  12747. }
  12748. }
  12749. }
  12750. }
  12751. c.ServeSuccessJSON(map[string]interface{}{
  12752. "msg": "创建成功",
  12753. })
  12754. }
  12755. }
  12756. } else {
  12757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12758. return
  12759. }
  12760. }
  12761. }
  12762. func (c *HisApiController) PreSettle() {
  12763. id, _ := c.GetInt64("id")
  12764. record_time := c.GetString("record_time")
  12765. his_patient_id, _ := c.GetInt64("his_patient_id")
  12766. timeLayout := "2006-01-02"
  12767. loc, _ := time.LoadLocation("Local")
  12768. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12769. diagnosis_id := c.GetString("diagnosis")
  12770. sick_type, _ := c.GetInt64("sick_type")
  12771. reg_type, _ := c.GetInt64("p_type")
  12772. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12773. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12774. if err != nil {
  12775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12776. return
  12777. }
  12778. recordDateTime := theTime.Unix()
  12779. adminUser := c.GetAdminUserInfo()
  12780. var prescriptions []*models.HisPrescription
  12781. var start_time int64
  12782. var end_time int64
  12783. ids_str := c.GetString("ids")
  12784. ids_arr := strings.Split(ids_str, ",")
  12785. fmt.Println(reg_type)
  12786. if settle_accounts_type == 1 { //日结
  12787. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12788. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12789. } else {
  12790. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12791. }
  12792. fmt.Println(prescriptions)
  12793. } else { //月结
  12794. start_time_str := c.GetString("start_time")
  12795. end_time_str := c.GetString("end_time")
  12796. timeLayout := "2006-01-02"
  12797. loc, _ := time.LoadLocation("Local")
  12798. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12799. if err != nil {
  12800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12801. return
  12802. }
  12803. recordStartTime := theStartTime.Unix()
  12804. start_time = recordStartTime
  12805. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12806. if err != nil {
  12807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12808. return
  12809. }
  12810. recordEndTime := theEndTime.Unix()
  12811. end_time = recordEndTime
  12812. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12813. }
  12814. if reg_type == 1111 || reg_type == 1112 {
  12815. reg_type = 11
  12816. }
  12817. timestamp := time.Now().Unix()
  12818. tempTime := time.Unix(timestamp, 0)
  12819. timeFormat := tempTime.Format("20060102150405")
  12820. chrgBchno := rand.Intn(100000) + 10000
  12821. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12822. strconv.FormatInt(his.PatientId, 10)
  12823. var ids []int64
  12824. for _, item := range prescriptions {
  12825. ids = append(ids, item.ID)
  12826. }
  12827. fmt.Println(ids)
  12828. var total float64
  12829. for _, item := range prescriptions {
  12830. fmt.Println(item)
  12831. if item.Type == 1 { //药品
  12832. for _, subItem := range item.HisDoctorAdviceInfo {
  12833. total = total + (subItem.Price * subItem.PrescribingNumber)
  12834. }
  12835. }
  12836. if item.Type == 2 { //项目
  12837. for _, subItem := range item.HisPrescriptionProject {
  12838. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12839. total = total + (subItem.Price * cnt)
  12840. }
  12841. }
  12842. for _, subItem := range item.HisAdditionalCharge {
  12843. total = total + (subItem.Price * float64(subItem.Count))
  12844. }
  12845. }
  12846. allTotal := fmt.Sprintf("%.2f", total)
  12847. totals, _ := strconv.ParseFloat(allTotal, 64)
  12848. order := &models.HisOrder{
  12849. UserOrgId: adminUser.CurrentOrgId,
  12850. HisPatientId: his.ID,
  12851. PatientId: id,
  12852. SettleAccountsDate: recordDateTime,
  12853. Ctime: time.Now().Unix(),
  12854. Mtime: time.Now().Unix(),
  12855. Status: 1,
  12856. OrderStatus: 1,
  12857. MdtrtId: his.Number,
  12858. Number: chrg_bchno,
  12859. MedfeeSumamt: totals,
  12860. SettleEndTime: end_time,
  12861. SettleStartTime: start_time,
  12862. SettleType: settle_accounts_type,
  12863. PsnPartAmt: totals,
  12864. PsnCashPay: totals,
  12865. PType: 2,
  12866. IsPre: 1,
  12867. MedType: strconv.Itoa(int(reg_type)),
  12868. Diagnosis: diagnosis_id,
  12869. }
  12870. err = service.CreateOrder(order)
  12871. if err != nil {
  12872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12873. return
  12874. }
  12875. var customs []*Custom
  12876. for _, item := range prescriptions {
  12877. fmt.Println(item.Type)
  12878. if item.Type == 1 { //药品
  12879. for _, subItem := range item.HisDoctorAdviceInfo {
  12880. cus := &Custom{
  12881. AdviceId: subItem.ID,
  12882. ProjectId: 0,
  12883. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12884. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12885. FeedetlSn: subItem.FeedetlSn,
  12886. Price: fmt.Sprintf("%.2f", subItem.Price),
  12887. MedListCodg: subItem.MedListCodg,
  12888. Type: 1,
  12889. }
  12890. customs = append(customs, cus)
  12891. }
  12892. }
  12893. if item.Type == 2 { //项目
  12894. for _, subItem := range item.HisPrescriptionProject {
  12895. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12896. cus := &Custom{
  12897. AdviceId: 0,
  12898. ProjectId: subItem.ID,
  12899. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12900. Cut: fmt.Sprintf("%.2f", cnt),
  12901. FeedetlSn: subItem.FeedetlSn,
  12902. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12903. MedListCodg: subItem.MedListCodg,
  12904. Type: 2,
  12905. }
  12906. customs = append(customs, cus)
  12907. }
  12908. }
  12909. for _, item := range item.HisAdditionalCharge {
  12910. cus := &Custom{
  12911. ItemId: item.ID,
  12912. AdviceId: 0,
  12913. ProjectId: 0,
  12914. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12915. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12916. FeedetlSn: item.FeedetlSn,
  12917. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12918. MedListCodg: item.XtHisAddtionConfig.Code,
  12919. Type: 3,
  12920. }
  12921. customs = append(customs, cus)
  12922. }
  12923. }
  12924. fmt.Println(customs)
  12925. for _, item := range customs {
  12926. var advice_id int64 = 0
  12927. var project_id int64 = 0
  12928. var item_id int64 = 0
  12929. var types int64 = 0
  12930. if item.Type == 1 {
  12931. advice_id = item.AdviceId
  12932. project_id = 0
  12933. item_id = 0
  12934. } else if item.Type == 2 {
  12935. advice_id = 0
  12936. item_id = 0
  12937. project_id = item.ProjectId
  12938. } else if item.Type == 3 {
  12939. advice_id = 0
  12940. item_id = item.ItemId
  12941. project_id = 0
  12942. }
  12943. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12944. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12945. pric, _ := strconv.ParseFloat(item.Price, 32)
  12946. info := &models.HisOrderInfo{
  12947. OrderNumber: order.Number,
  12948. UploadDate: time.Now().Unix(),
  12949. AdviceId: advice_id,
  12950. DetItemFeeSumamt: detItemFeeSumamt,
  12951. Cnt: cut,
  12952. Pric: pric,
  12953. PatientId: id,
  12954. Status: 1,
  12955. Mtime: time.Now().Unix(),
  12956. Ctime: time.Now().Unix(),
  12957. UserOrgId: adminUser.CurrentOrgId,
  12958. HisPatientId: his.ID,
  12959. OrderId: order.ID,
  12960. ProjectId: project_id,
  12961. Type: types,
  12962. ItemId: item_id,
  12963. }
  12964. service.CreateOrderInfo(info)
  12965. }
  12966. his.SickType = sick_type
  12967. service.UpdataHisPateint(&his)
  12968. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12969. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12970. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12971. if err == nil {
  12972. c.ServeSuccessJSON(map[string]interface{}{
  12973. "msg": "结算成功",
  12974. })
  12975. }
  12976. }
  12977. type CustomOrderInfo struct {
  12978. Name string
  12979. Spec string
  12980. Unit string
  12981. Count float64
  12982. Price float64
  12983. Total float64
  12984. }
  12985. func (c *HisApiController) GetPrivateExpensesInfo() {
  12986. order_id, _ := c.GetInt64("id", 0)
  12987. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12988. order, _ := service.GetHisOrderByID(order_id)
  12989. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12990. if order.ID == 0 {
  12991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12992. return
  12993. }
  12994. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12995. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12996. org_id := c.GetAdminUserInfo().CurrentOrgId
  12997. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12998. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12999. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  13000. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  13001. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  13002. //var orderInfos_four []*models.HisOrderInfoTwo
  13003. //for _, item := range orderInfos_three {
  13004. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  13005. // item.HisPrescriptionProject.IsCheckTeam = 1
  13006. // orderInfos_four = append(orderInfos_four, item)
  13007. //
  13008. // }
  13009. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  13010. // item.HisPrescriptionProject.IsCheckTeam = 2
  13011. // orderInfos_two = append(orderInfos_two, item)
  13012. // }
  13013. //}
  13014. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  13015. //var cus_slice []CustomOrderInfo
  13016. //for _, item := range new_order_info {
  13017. // var cus CustomOrderInfo
  13018. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  13019. // cus.Unit = ""
  13020. // cus.Spec = ""
  13021. // var total float64
  13022. // for _, subItem := range orderInfos_four {
  13023. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  13024. // total = total + subItem.DetItemFeeSumamt
  13025. // fmt.Println(subItem.DetItemFeeSumamt)
  13026. // }
  13027. // }
  13028. // cus.Count = 1
  13029. // cus.Total = total
  13030. // cus_slice = append(cus_slice, cus)
  13031. //}
  13032. orderInfos = append(orderInfos, orderInfos_two...)
  13033. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  13034. //orderInfos = append(orderInfos, orderInfos_three...)
  13035. //}/**/
  13036. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  13037. c.ServeSuccessJSON(map[string]interface{}{
  13038. "order": order,
  13039. "order_info": orderInfos,
  13040. "patient": patient,
  13041. "admin_info": adminInfo,
  13042. "his": his,
  13043. "current_admin": role,
  13044. "org_config": miConfig,
  13045. //"new_order_info": cus_slice,
  13046. })
  13047. }
  13048. func (this *HisApiController) ChangeMedType() {
  13049. med_type := this.GetString("med_type")
  13050. old_med_type := this.GetString("old_med_type")
  13051. ids := this.GetString("ids")
  13052. settle_type, _ := this.GetInt64("settle_type")
  13053. start_time := this.GetString("start_time")
  13054. end_time := this.GetString("end_time")
  13055. ids_arr := strings.Split(ids, ",")
  13056. if settle_type == 1 { //日结
  13057. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  13058. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  13059. prescription.MedType = med_type
  13060. err := service.SaveHisPrescriptionTwo(&prescription)
  13061. if err == nil {
  13062. this.ServeSuccessJSON(map[string]interface{}{
  13063. "msg": "修改成功",
  13064. })
  13065. } else {
  13066. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  13067. return
  13068. }
  13069. } else if settle_type == 2 {
  13070. timeLayout := "2006-01-02"
  13071. loc, _ := time.LoadLocation("Local")
  13072. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13073. if err != nil {
  13074. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13075. return
  13076. }
  13077. recordStartTime := theStartTime.Unix()
  13078. start_time_timestamp := recordStartTime
  13079. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  13080. if err != nil {
  13081. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13082. return
  13083. }
  13084. recordEndTime := theEndTime.Unix()
  13085. end_time_timestamp := recordEndTime
  13086. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  13087. if updateErr == nil {
  13088. this.ServeSuccessJSON(map[string]interface{}{
  13089. "msg": "修改成功",
  13090. })
  13091. } else {
  13092. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  13093. return
  13094. }
  13095. }
  13096. }
  13097. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  13098. patient_id, _ := c.GetInt64("patient_id")
  13099. his_patient_id, _ := c.GetInt64("his_patient_id")
  13100. record_date := c.GetString("record_date")
  13101. start_time := c.GetString("start_time")
  13102. end_time := c.GetString("end_time")
  13103. order_status, _ := c.GetInt64("type", 0)
  13104. p_type, _ := c.GetInt64("p_type", 0)
  13105. order_id, _ := c.GetInt64("order_id", 0)
  13106. timeLayout := "2006-01-02"
  13107. loc, _ := time.LoadLocation("Local")
  13108. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13109. if err != nil {
  13110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13111. return
  13112. }
  13113. recordDateTime := theTime.Unix()
  13114. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13115. if err != nil {
  13116. }
  13117. startRecordDateTime := startTime.Unix()
  13118. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13119. if err != nil {
  13120. }
  13121. endRecordDateTime := endTime.Unix()
  13122. admin := c.GetAdminUserInfo()
  13123. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  13124. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13125. order, _ := service.GetHisOrderByID(order_id)
  13126. var monthPrescriptions []*models.HisPrescription
  13127. if order_status == 1 || order_status == 0 {
  13128. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13129. } else if order_status == 2 {
  13130. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  13131. }
  13132. var settle_total float64
  13133. for _, item := range monthPrescriptions {
  13134. if len(item.HisPrescriptionProject) > 0 {
  13135. for _, subItem := range item.HisPrescriptionProject {
  13136. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13137. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13138. settle_total = settle_total + total
  13139. }
  13140. }
  13141. if len(item.HisDoctorAdviceInfo) > 0 {
  13142. for _, subItem := range item.HisDoctorAdviceInfo {
  13143. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13144. settle_total = settle_total + total
  13145. }
  13146. }
  13147. }
  13148. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13149. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13150. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13151. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13152. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13153. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13154. //获取所有科室信息
  13155. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13156. var dia string
  13157. for _, item := range month_p_info {
  13158. if len(dia) == 0 {
  13159. dia = item.Diagnosis
  13160. } else {
  13161. dia = dia + "," + item.Diagnosis
  13162. }
  13163. }
  13164. dia_arr := removeDuplicates(strings.Split(dia, ","))
  13165. dia_arr = removeEmptyStrings(dia_arr)
  13166. c.ServeSuccessJSON(map[string]interface{}{
  13167. "his_info": his_patient_info,
  13168. "xt_info": xt_patient_info,
  13169. "case_history": case_history,
  13170. "info": patientPrescriptionInfo,
  13171. "last_info": lastPatientPrescriptionInfo,
  13172. "month_prescriptions": monthPrescriptions,
  13173. "order": order,
  13174. "doctors": doctors,
  13175. "department": department,
  13176. "settle_total": settle_total,
  13177. "dia_arr": dia_arr,
  13178. })
  13179. return
  13180. }
  13181. func removeEmptyStrings(input []string) []string {
  13182. var output []string
  13183. for _, s := range input {
  13184. if s != "" {
  13185. output = append(output, s)
  13186. }
  13187. }
  13188. return output
  13189. }
  13190. func removeDuplicates(input []string) []string {
  13191. seen := make(map[string]bool)
  13192. output := []string{}
  13193. for _, s := range input {
  13194. if _, exists := seen[s]; !exists {
  13195. seen[s] = true
  13196. output = append(output, s)
  13197. }
  13198. }
  13199. return output
  13200. }
  13201. func (c *HisApiController) GetHisMonthPatientInfo() {
  13202. patient_id, _ := c.GetInt64("patient_id")
  13203. his_patient_id, _ := c.GetInt64("his_patient_id")
  13204. record_date := c.GetString("record_date")
  13205. number := c.GetString("number")
  13206. start_time := c.GetString("start_time")
  13207. end_time := c.GetString("end_time")
  13208. p_type, _ := c.GetInt64("p_type")
  13209. timeLayout := "2006-01-02"
  13210. loc, _ := time.LoadLocation("Local")
  13211. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13212. if err != nil {
  13213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13214. return
  13215. }
  13216. recordDateTime := theTime.Unix()
  13217. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13218. if err != nil {
  13219. }
  13220. startRecordDateTime := startTime.Unix()
  13221. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13222. if err != nil {
  13223. }
  13224. endRecordDateTime := endTime.Unix()
  13225. admin := c.GetAdminUserInfo()
  13226. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  13227. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13228. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  13229. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13230. var settle_total float64
  13231. for _, item := range monthPrescriptions {
  13232. if len(item.HisPrescriptionProject) > 0 {
  13233. for _, subItem := range item.HisPrescriptionProject {
  13234. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13235. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13236. settle_total = settle_total + total
  13237. }
  13238. }
  13239. if len(item.HisDoctorAdviceInfo) > 0 {
  13240. for _, subItem := range item.HisDoctorAdviceInfo {
  13241. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13242. settle_total = settle_total + total
  13243. }
  13244. }
  13245. }
  13246. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13247. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13248. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13249. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13250. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  13251. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13252. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  13253. //获取所有科室信息
  13254. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13255. c.ServeSuccessJSON(map[string]interface{}{
  13256. "his_info": his_patient_info,
  13257. "xt_info": xt_patient_info,
  13258. "case_history": case_history,
  13259. "info": patientPrescriptionInfo,
  13260. "month_prescriptions": monthPrescriptions,
  13261. "order": order,
  13262. "doctors": doctors,
  13263. "department": department,
  13264. "count": count,
  13265. "drugStockConfig": drugStockConfig,
  13266. "last_info": lastPatientPrescriptionInfo,
  13267. "settle_total": settle_total,
  13268. })
  13269. return
  13270. }
  13271. func (c *HisApiController) GetAllOrder() {
  13272. org_id := c.GetAdminUserInfo().CurrentOrgId
  13273. orders, _ := service.GetNewHisOrderList(org_id)
  13274. c.ServeSuccessJSON(map[string]interface{}{
  13275. "order": orders,
  13276. })
  13277. return
  13278. }
  13279. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  13280. newArr = make([]*models.HisOrderInfoTwo, 0)
  13281. for i := 0; i < len(arr); i++ {
  13282. repeat := false
  13283. for j := i + 1; j < len(arr); j++ {
  13284. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  13285. repeat = true
  13286. break
  13287. }
  13288. }
  13289. if !repeat {
  13290. newArr = append(newArr, arr[i])
  13291. }
  13292. }
  13293. return
  13294. }
  13295. // 修改处方退库操作 参数传修改之前的处方数据
  13296. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  13297. if advice.ExecutionState == 1 {
  13298. //查询该病人该药品是否有库存记录
  13299. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  13300. if errcode == gorm.ErrRecordNotFound {
  13301. } else {
  13302. //退库
  13303. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  13304. if advice.PrescribingNumberUnit == drug.MinUnit {
  13305. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13306. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13307. //退库
  13308. warehouseInfo := models.DrugWarehouseInfo{
  13309. StockMinNumber: prescribingNumber,
  13310. }
  13311. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  13312. operation_time := time.Now().Unix()
  13313. creater := advice.AdviceDoctor
  13314. ctime := time.Now().Unix()
  13315. timeStr := time.Now().Format("2006-01-02")
  13316. timeArr := strings.Split(timeStr, "-")
  13317. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13318. total = total + 1
  13319. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13320. cancelStock := models.DrugCancelStock{
  13321. OrderNumber: orderNumber,
  13322. OperaTime: operation_time,
  13323. OrgId: advice.UserOrgId,
  13324. Creater: creater,
  13325. Ctime: ctime,
  13326. Status: 1,
  13327. ReturnTime: advice.AdviceDate,
  13328. Dealer: info.Dealer,
  13329. Manufacturer: info.Manufacturer,
  13330. Type: 1,
  13331. }
  13332. service.AddSigleDrugCancelStock(&cancelStock)
  13333. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13334. dealer, _ := service.GetDealerById(info.Dealer)
  13335. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13336. cancelStockInfo := models.DrugCancelStockInfo{
  13337. OrderNumber: cancelInfo.OrderNumber,
  13338. CancelStockId: cancelInfo.ID,
  13339. DrugId: info.DrugId,
  13340. Count: info.Count,
  13341. Status: 1,
  13342. Ctime: ctime,
  13343. OrgId: advice.UserOrgId,
  13344. Type: 1,
  13345. Manufacturer: manufactureName.ManufacturerName,
  13346. Dealer: dealer.DealerName,
  13347. Total: 0,
  13348. RetailPrice: info.RetailPrice,
  13349. RetailTotalPrice: info.RetailTotalPrice,
  13350. Price: info.Price,
  13351. RegisterAccount: "",
  13352. Remark: info.Remark,
  13353. BatchNumber: info.BatchNumber,
  13354. MaxUnit: info.CountUnit,
  13355. ProductDate: info.ProductDate,
  13356. ExpiryDate: info.ExpiryDate,
  13357. BatchNumberId: info.WarehouseInfoId,
  13358. }
  13359. flow := models.DrugFlow{
  13360. WarehousingId: 0,
  13361. DrugId: info.DrugId,
  13362. Number: "",
  13363. BatchNumber: info.BatchNumber,
  13364. Count: info.Count,
  13365. UserOrgId: advice.UserOrgId,
  13366. PatientId: 0,
  13367. SystemTime: ctime,
  13368. ConsumableType: 4,
  13369. IsSys: 0,
  13370. WarehousingOrder: "",
  13371. WarehouseOutId: 0,
  13372. WarehouseOutOrderNumber: "",
  13373. IsEdit: 0,
  13374. CancelStockId: cancelStock.ID,
  13375. CancelOrderNumber: cancelStock.OrderNumber,
  13376. Manufacturer: info.Manufacturer,
  13377. Dealer: info.Dealer,
  13378. Creator: advice.UserOrgId,
  13379. UpdateCreator: 0,
  13380. Status: 1,
  13381. Ctime: time.Now().Unix(),
  13382. Mtime: 0,
  13383. Price: info.Price,
  13384. WarehousingDetailId: 0,
  13385. WarehouseOutDetailId: 0,
  13386. CancelOutDetailId: 0,
  13387. ExpireDate: info.ExpiryDate,
  13388. ProductDate: info.ProductDate,
  13389. MaxUnit: info.CountUnit,
  13390. MinUnit: "",
  13391. }
  13392. service.CreatedCancelStock(cancelStockInfo)
  13393. service.CreateDrugFlowOne(flow)
  13394. } else {
  13395. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13396. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13397. if advice.PrescribingNumberUnit == drug.MaxUnit {
  13398. warehouseInfo := models.DrugWarehouseInfo{
  13399. StockMinNumber: prescribingNumber,
  13400. }
  13401. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  13402. }
  13403. operation_time := time.Now().Unix()
  13404. creater := advice.AdviceDoctor
  13405. ctime := time.Now().Unix()
  13406. timeStr := time.Now().Format("2006-01-02")
  13407. timeArr := strings.Split(timeStr, "-")
  13408. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13409. total = total + 1
  13410. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13411. cancelStock := models.DrugCancelStock{
  13412. OrderNumber: orderNumber,
  13413. OperaTime: operation_time,
  13414. OrgId: advice.UserOrgId,
  13415. Creater: creater,
  13416. Ctime: ctime,
  13417. Status: 1,
  13418. ReturnTime: advice.AdviceDate,
  13419. Dealer: info.Dealer,
  13420. Manufacturer: info.Manufacturer,
  13421. Type: 1,
  13422. }
  13423. service.AddSigleDrugCancelStock(&cancelStock)
  13424. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13425. dealer, _ := service.GetDealerById(info.Dealer)
  13426. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13427. cancelStockInfo := models.DrugCancelStockInfo{
  13428. OrderNumber: cancelInfo.OrderNumber,
  13429. CancelStockId: cancelInfo.ID,
  13430. DrugId: info.DrugId,
  13431. Count: info.Count,
  13432. Status: 1,
  13433. Ctime: ctime,
  13434. OrgId: advice.UserOrgId,
  13435. Type: 1,
  13436. Manufacturer: manufactureName.ManufacturerName,
  13437. Dealer: dealer.DealerName,
  13438. Total: 0,
  13439. RetailPrice: info.RetailPrice,
  13440. RetailTotalPrice: info.RetailTotalPrice,
  13441. Price: info.Price,
  13442. RegisterAccount: "",
  13443. Remark: info.Remark,
  13444. BatchNumber: info.BatchNumber,
  13445. MaxUnit: info.CountUnit,
  13446. ProductDate: info.ProductDate,
  13447. ExpiryDate: info.ExpiryDate,
  13448. BatchNumberId: info.WarehouseInfoId,
  13449. }
  13450. flow := models.DrugFlow{
  13451. WarehousingId: 0,
  13452. DrugId: info.DrugId,
  13453. Number: "",
  13454. BatchNumber: info.BatchNumber,
  13455. Count: info.Count,
  13456. UserOrgId: advice.UserOrgId,
  13457. PatientId: 0,
  13458. SystemTime: ctime,
  13459. ConsumableType: 4,
  13460. IsSys: 0,
  13461. WarehousingOrder: "",
  13462. WarehouseOutId: 0,
  13463. WarehouseOutOrderNumber: "",
  13464. IsEdit: 0,
  13465. CancelStockId: cancelStock.ID,
  13466. CancelOrderNumber: cancelStock.OrderNumber,
  13467. Manufacturer: info.Manufacturer,
  13468. Dealer: info.Dealer,
  13469. Creator: advice.AdviceDoctor,
  13470. UpdateCreator: 0,
  13471. Status: 1,
  13472. Ctime: time.Now().Unix(),
  13473. Mtime: 0,
  13474. Price: info.Price,
  13475. WarehousingDetailId: 0,
  13476. WarehouseOutDetailId: 0,
  13477. CancelOutDetailId: 0,
  13478. ExpireDate: info.ExpiryDate,
  13479. ProductDate: info.ProductDate,
  13480. MaxUnit: info.CountUnit,
  13481. MinUnit: "",
  13482. }
  13483. service.CreatedCancelStock(cancelStockInfo)
  13484. service.CreateDrugFlowOne(flow)
  13485. }
  13486. }
  13487. }
  13488. return err
  13489. }
  13490. func (this *HisApiController) DeleteNCDS() {
  13491. id, _ := this.GetInt64("id", 0)
  13492. if id > 0 {
  13493. service.DeletePsnNCDSRecordById(id)
  13494. this.ServeSuccessJSON(map[string]interface{}{
  13495. "msg": "删除成功",
  13496. })
  13497. } else {
  13498. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13499. return
  13500. }
  13501. }
  13502. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13503. id, _ := c.GetInt64("id")
  13504. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13505. c.ServeSuccessJSON(map[string]interface{}{
  13506. "advice": advice,
  13507. })
  13508. return
  13509. }
  13510. func (c *HisApiController) GetHisMonthChargePatientList() {
  13511. record_date := c.GetString("record_date")
  13512. start_time := c.GetString("start_time")
  13513. end_time := c.GetString("end_time")
  13514. timeLayout := "2006-01-02"
  13515. loc, _ := time.LoadLocation("Local")
  13516. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13517. if err != nil {
  13518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13519. return
  13520. }
  13521. if err != nil {
  13522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13523. return
  13524. }
  13525. recordDateTime := theTime.Unix()
  13526. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13527. if err != nil {
  13528. }
  13529. startRecordDateTime := startTime.Unix()
  13530. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13531. if err != nil {
  13532. }
  13533. endRecordDateTime := endTime.Unix()
  13534. adminInfo := c.GetAdminUserInfo()
  13535. var tempMonthChargePatients []*service.MonthChargePatients
  13536. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13537. for _, item := range tempPatients {
  13538. //过滤没有处方的
  13539. if len(item.HisPrescription) == 0 {
  13540. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13541. }
  13542. }
  13543. c.ServeSuccessJSON(map[string]interface{}{
  13544. "list": tempMonthChargePatients,
  13545. })
  13546. }
  13547. // PrescriptionDifference 医嘱数量差值结构体
  13548. type PrescriptionDrugDifference struct {
  13549. DrugID int64 //基础库药品id
  13550. ID int64 //医嘱id
  13551. Difference float64 //差值
  13552. Unit string //单位
  13553. }
  13554. type PrescriptionGoodDifference struct {
  13555. GoodID int64 //基础库项目耗材id
  13556. ID int64 //医嘱id
  13557. Difference int64 //差值
  13558. Unit string //单位
  13559. Type int64 //类型
  13560. }
  13561. type EditCustomData struct {
  13562. adviceList []*models.HisDoctorAdviceInfo
  13563. projectList []*models.HisPrescriptionProject
  13564. }
  13565. type SrcCustomData struct {
  13566. adviceList []*models.HisDoctorAdviceInfo
  13567. projectList []*models.HisPrescriptionProject
  13568. }
  13569. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13570. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13571. differences := make([]*PrescriptionDrugDifference, 0)
  13572. // 创建一个 map 来存储第一个切片中的药品信息
  13573. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13574. for _, advice := range firstPrescription {
  13575. firstMap[advice.DrugId] = advice
  13576. }
  13577. // 遍历第二个切片中的药品信息,并比较数量差值
  13578. for _, advice := range secondPrescription {
  13579. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13580. diff := &PrescriptionDrugDifference{
  13581. DrugID: advice.DrugId,
  13582. ID: firstAdvice.ID,
  13583. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13584. Unit: firstAdvice.PrescribingNumberUnit,
  13585. }
  13586. differences = append(differences, diff)
  13587. }
  13588. }
  13589. return differences
  13590. }
  13591. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13592. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13593. differences := make([]*PrescriptionGoodDifference, 0)
  13594. // 创建一个 map 来存储第一个切片中的耗材信息
  13595. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13596. for _, good := range firstPrescription {
  13597. firstMap[good.ProjectId] = good
  13598. }
  13599. // 遍历第二个切片中的耗材信息,并比较数量差值
  13600. for _, good := range secondPrescription {
  13601. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13602. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13603. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13604. diff := &PrescriptionGoodDifference{
  13605. GoodID: good.ProjectId,
  13606. ID: firstGood.ID,
  13607. Difference: count - firstCount,
  13608. Unit: firstGood.Unit,
  13609. Type: firstGood.Type,
  13610. }
  13611. differences = append(differences, diff)
  13612. }
  13613. }
  13614. return differences
  13615. }
  13616. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13617. var adviceList []*models.HisDoctorAdviceInfo
  13618. var projectList []*models.HisPrescriptionProject
  13619. var advice_ids []int64
  13620. var project_ids []int64
  13621. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13622. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13623. //var tempPrescription *models.HisPrescriptionProjectscription
  13624. if len(prescriptions) > 0 {
  13625. for _, item := range prescriptions {
  13626. items := item.(map[string]interface{})
  13627. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13628. advices := items["advices"].([]interface{})
  13629. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13630. groupNo := int64(0)
  13631. ctime := time.Now().Unix()
  13632. mtime := ctime
  13633. if len(advices) > 0 {
  13634. for _, advice := range advices {
  13635. var s models.HisDoctorAdviceInfo
  13636. s.AdviceType = 2
  13637. s.StopState = 2
  13638. s.ExecutionState = 2
  13639. s.Status = 1
  13640. s.Groupno = groupNo
  13641. s.CreatedTime = ctime
  13642. s.UpdatedTime = mtime
  13643. s.IsSettle = 2
  13644. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13645. //存储切片中
  13646. if s.ID > 0 {
  13647. advice_ids = append(advice_ids, s.ID)
  13648. adviceList = append(adviceList, &s)
  13649. }
  13650. }
  13651. }
  13652. }
  13653. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13654. projects := items["project"].([]interface{})
  13655. if len(projects) > 0 {
  13656. for _, project := range projects {
  13657. var p models.HisPrescriptionProject
  13658. p.Ctime = time.Now().Unix()
  13659. p.Mtime = time.Now().Unix()
  13660. p.Status = 1
  13661. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13662. if p.ID > 0 {
  13663. project_ids = append(project_ids, p.ID)
  13664. projectList = append(projectList, &p)
  13665. }
  13666. }
  13667. }
  13668. }
  13669. }
  13670. }
  13671. }
  13672. editCustomData.projectList = projectList
  13673. editCustomData.adviceList = adviceList
  13674. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13675. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13676. srcCustomData.adviceList = list
  13677. srcCustomData.projectList = list2
  13678. return
  13679. }
  13680. func (c *HisApiController) GetAllGoodInforList() {
  13681. orgId := c.GetAdminUserInfo().CurrentOrgId
  13682. goodList, _ := service.GetAllGoodList(orgId)
  13683. c.ServeSuccessJSON(map[string]interface{}{
  13684. "goodList": goodList,
  13685. })
  13686. return
  13687. }
  13688. func (this *HisApiController) SaveGoodList() {
  13689. project_name := this.GetString("project_name")
  13690. sort, _ := this.GetInt64("sort")
  13691. orgId := this.GetAdminUserInfo().CurrentOrgId
  13692. dataBody := make(map[string]interface{}, 0)
  13693. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13694. if err != nil {
  13695. utils.ErrorLog(err.Error())
  13696. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13697. return
  13698. }
  13699. goodTeam := models.XtGoodTeam{
  13700. ProjectName: project_name,
  13701. Sort: sort,
  13702. UserOrgId: orgId,
  13703. Status: 1,
  13704. Ctime: time.Now().Unix(),
  13705. Mtime: time.Now().Unix(),
  13706. }
  13707. service.CreateGoodTeam(goodTeam)
  13708. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13709. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13710. infos, _ := dataBody["info"].([]interface{})
  13711. if len(infos) > 0 {
  13712. for _, item := range infos {
  13713. items := item.(map[string]interface{})
  13714. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13715. utils.ErrorLog("good_id")
  13716. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13717. return
  13718. }
  13719. good_id := int64(items["good_id"].(float64))
  13720. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13721. utils.ErrorLog("number")
  13722. }
  13723. number := int64(items["number"].(float64))
  13724. xtGoodTeamList := models.XtGoodTeamList{
  13725. GoodId: good_id,
  13726. Count: number,
  13727. TeamId: lastGoodTeam.ID,
  13728. UserOrgId: orgId,
  13729. Status: 1,
  13730. Ctime: time.Now().Unix(),
  13731. Mtime: time.Now().Unix(),
  13732. }
  13733. service.CreateGoodList(xtGoodTeamList)
  13734. }
  13735. this.ServeSuccessJSON(map[string]interface{}{
  13736. "lastGoodTeam": lastGoodTeam,
  13737. })
  13738. }
  13739. }
  13740. return
  13741. }
  13742. func (this *HisApiController) GetGoodList() {
  13743. orgId := this.GetAdminUserInfo().CurrentOrgId
  13744. limit, _ := this.GetInt64("limit")
  13745. page, _ := this.GetInt64("page")
  13746. keyword := this.GetString("keyword")
  13747. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13748. this.ServeSuccessJSON(map[string]interface{}{
  13749. "list": list,
  13750. "total": total,
  13751. })
  13752. }
  13753. func (this *HisApiController) GetGoodNameDetail() {
  13754. id, _ := this.GetInt64("id")
  13755. orgId := this.GetAdminUserInfo().CurrentOrgId
  13756. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13757. goodList, _ := service.GetAllGoodList(orgId)
  13758. this.ServeSuccessJSON(map[string]interface{}{
  13759. "goodNameDetail": goodNameDetail,
  13760. "goodList": goodList,
  13761. })
  13762. }
  13763. func (this *HisApiController) UpdateGoodList() {
  13764. project_name := this.GetString("project_name")
  13765. sort, _ := this.GetInt64("sort")
  13766. id, _ := this.GetInt64("id")
  13767. orgId := this.GetAdminUserInfo().CurrentOrgId
  13768. dataBody := make(map[string]interface{}, 0)
  13769. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13770. if err != nil {
  13771. utils.ErrorLog(err.Error())
  13772. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13773. return
  13774. }
  13775. goodTeam := models.XtGoodTeam{
  13776. ProjectName: project_name,
  13777. Sort: sort,
  13778. UserOrgId: orgId,
  13779. Status: 1,
  13780. Ctime: time.Now().Unix(),
  13781. Mtime: time.Now().Unix(),
  13782. ID: id,
  13783. }
  13784. service.SaveGoodTeam(goodTeam)
  13785. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13786. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13787. infos, _ := dataBody["info"].([]interface{})
  13788. if len(infos) > 0 {
  13789. for _, item := range infos {
  13790. items := item.(map[string]interface{})
  13791. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13792. utils.ErrorLog("good_id")
  13793. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13794. return
  13795. }
  13796. good_id := int64(items["good_id"].(float64))
  13797. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13798. utils.ErrorLog("id")
  13799. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13800. return
  13801. }
  13802. id := int64(items["id"].(float64))
  13803. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13804. utils.ErrorLog("number")
  13805. }
  13806. number := int64(items["number"].(float64))
  13807. xtGoodTeamList := models.XtGoodTeamList{
  13808. ID: id,
  13809. GoodId: good_id,
  13810. Count: number,
  13811. TeamId: lastGoodTeam.ID,
  13812. UserOrgId: orgId,
  13813. Status: 1,
  13814. Ctime: time.Now().Unix(),
  13815. Mtime: time.Now().Unix(),
  13816. }
  13817. service.SaveGoodList(xtGoodTeamList)
  13818. }
  13819. this.ServeSuccessJSON(map[string]interface{}{
  13820. "lastGoodTeam": lastGoodTeam,
  13821. })
  13822. }
  13823. }
  13824. return
  13825. }
  13826. func (this *HisApiController) DeleteGoodTeam() {
  13827. id, _ := this.GetInt64("id")
  13828. team, _ := service.DeleteGoodTeam(id)
  13829. this.ServeSuccessJSON(map[string]interface{}{
  13830. "team": team,
  13831. })
  13832. }
  13833. func (this *HisApiController) DeleteGood() {
  13834. id, _ := this.GetInt64("id")
  13835. good, _ := service.DeleteGood(id)
  13836. this.ServeSuccessJSON(map[string]interface{}{
  13837. "good": good,
  13838. })
  13839. }