his_api_controller.go 607KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655
  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 huliCostTotal float64 = 0 //治疗费用
  953. var huliCostSelfTotal float64 = 0 //治疗费用
  954. var huliCostPartSelfTotal float64 = 0 //治疗费用
  955. var huliSelfTotal float64 = 0 //床位部分项目自费
  956. var huliInscpTotal float64 = 0 //床位部分项目自费
  957. var zcCostTotal float64 = 0 //治疗费用
  958. var zcCostSelfTotal float64 = 0 //治疗费用
  959. var zcCostPartSelfTotal float64 = 0 //治疗费用
  960. var zcSelfTotal float64 = 0 //床位部分项目自费
  961. var zcInscpTotal float64 = 0 //床位部分项目自费
  962. var zhenChaCostTotal float64 = 0 //其他费用
  963. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  964. decimal.DivisionPrecision = 2
  965. for _, item := range orderInfos {
  966. //item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  967. if c.GetAdminUserInfo().CurrentOrgId != 10726 {
  968. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  969. item.MedChrgitmType = "09"
  970. }
  971. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  972. if item.HisPrescriptionProject.Type == 2 {
  973. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  974. fmt.Println("CostClassify")
  975. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  976. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  977. case 0:
  978. item.MedChrgitmType = "0"
  979. break
  980. case 1:
  981. item.MedChrgitmType = "14"
  982. break
  983. case 2:
  984. item.MedChrgitmType = "05"
  985. break
  986. case 3:
  987. item.MedChrgitmType = "03"
  988. break
  989. case 4:
  990. item.MedChrgitmType = "03"
  991. break
  992. case 5:
  993. item.MedChrgitmType = "08"
  994. break
  995. case 6:
  996. item.MedChrgitmType = "14"
  997. break
  998. case 7:
  999. item.MedChrgitmType = "14"
  1000. break
  1001. case 8:
  1002. item.MedChrgitmType = "03"
  1003. break
  1004. case 9:
  1005. item.MedChrgitmType = "14"
  1006. break
  1007. case 10:
  1008. item.MedChrgitmType = "14"
  1009. break
  1010. case 11:
  1011. item.MedChrgitmType = "06"
  1012. break
  1013. case 12:
  1014. item.MedChrgitmType = "12"
  1015. break
  1016. case 13:
  1017. item.MedChrgitmType = "01"
  1018. break
  1019. case 14:
  1020. item.MedChrgitmType = "04"
  1021. break
  1022. case 15:
  1023. item.MedChrgitmType = "14"
  1024. break
  1025. case 101:
  1026. item.MedChrgitmType = "04"
  1027. break
  1028. }
  1029. } else {
  1030. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  1031. case 1:
  1032. item.MedChrgitmType = "14"
  1033. break
  1034. case 2:
  1035. item.MedChrgitmType = "05"
  1036. break
  1037. case 3:
  1038. item.MedChrgitmType = "04"
  1039. break
  1040. case 4:
  1041. item.MedChrgitmType = "14"
  1042. break
  1043. case 5:
  1044. item.MedChrgitmType = "08"
  1045. break
  1046. case 6:
  1047. item.MedChrgitmType = "14"
  1048. break
  1049. case 7:
  1050. item.MedChrgitmType = "14"
  1051. break
  1052. case 8:
  1053. item.MedChrgitmType = "03"
  1054. break
  1055. case 9:
  1056. item.MedChrgitmType = "14"
  1057. break
  1058. case 101:
  1059. item.MedChrgitmType = "04"
  1060. break
  1061. default:
  1062. item.MedChrgitmType = "14"
  1063. break
  1064. }
  1065. }
  1066. } else if item.HisPrescriptionProject.Type == 3 {
  1067. item.MedChrgitmType = "08"
  1068. }
  1069. }
  1070. }
  1071. }
  1072. if order.IsMedicineInsurance != 1 {
  1073. order.PsnCashPay = order.MedfeeSumamt
  1074. }
  1075. for _, item := range orderInfos {
  1076. if item.MedChrgitmType == "01" { //床位费
  1077. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1078. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1079. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1080. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1081. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1082. }
  1083. if item.MedChrgitmType == "02" { //诊察费
  1084. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1085. //zhenChaCostSelfTotal = zhenChaCostTotal
  1086. }
  1087. if item.MedChrgitmType == "03" { //检查费
  1088. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1089. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1090. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1091. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1092. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1093. }
  1094. if item.MedChrgitmType == "02" { //检查费
  1095. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1096. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1097. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1098. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1099. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1100. }
  1101. if item.MedChrgitmType == "04" { //化验费
  1102. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1103. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1104. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1105. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1106. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1107. }
  1108. if item.MedChrgitmType == "05" { //治疗费
  1109. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1110. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1111. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1112. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1113. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1114. }
  1115. if item.MedChrgitmType == "06" { //手术费
  1116. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1117. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1118. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1119. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1120. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1121. }
  1122. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1123. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1124. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1125. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1126. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1127. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1128. }
  1129. if item.MedChrgitmType == "09" { //西药费
  1130. fmt.Println("FulamtOwnpayAmt")
  1131. fmt.Println(item.FulamtOwnpayAmt)
  1132. fmt.Println("FulamtOwnpayAmt")
  1133. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1134. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1135. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1136. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1137. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1138. }
  1139. if item.MedChrgitmType == "11" { //中成费
  1140. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1141. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1142. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1143. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1144. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1145. }
  1146. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1147. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1148. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1149. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1150. }
  1151. if item.MedChrgitmType == "02" { //其他费
  1152. zcCostTotal, _ = decimal.NewFromFloat(zcCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1153. zcCostSelfTotal, _ = decimal.NewFromFloat(zcCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1154. zcCostPartSelfTotal, _ = decimal.NewFromFloat(zcCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1155. zcSelfTotal, _ = decimal.NewFromFloat(zcSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1156. zcInscpTotal, _ = decimal.NewFromFloat(zcInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1157. }
  1158. if item.MedChrgitmType == "07" { //其他费
  1159. huliCostTotal, _ = decimal.NewFromFloat(huliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1160. huliCostSelfTotal, _ = decimal.NewFromFloat(huliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1161. huliCostPartSelfTotal, _ = decimal.NewFromFloat(huliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1162. huliSelfTotal, _ = decimal.NewFromFloat(huliSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1163. huliInscpTotal, _ = decimal.NewFromFloat(huliInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1164. }
  1165. }
  1166. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1167. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1168. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1169. var dia_config []*models.HisXtDiagnoseConfig
  1170. var diagnosis_ids []string
  1171. if his.ID > 0 {
  1172. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1173. } else {
  1174. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1175. }
  1176. for _, item := range diagnosis_ids {
  1177. id, _ := strconv.ParseInt(item, 10, 64)
  1178. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1179. dia_config = append(dia_config, diagnosisConfig)
  1180. }
  1181. var rf []CustomFundPay
  1182. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1183. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1184. c.ServeSuccessJSON(map[string]interface{}{
  1185. "patient": patient,
  1186. "order_infos": orderInfos,
  1187. "diagnosis": name,
  1188. "bedCostTotal": bedCostTotal,
  1189. "bedCostSelfTotal": bedCostSelfTotal,
  1190. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1191. "bedSelfTotal": bedSelfTotal,
  1192. "bedInscpTotal": bedInscpTotal,
  1193. "operationCostTotal": operationCostTotal,
  1194. "operationCostSelfTotal": operationCostSelfTotal,
  1195. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1196. "operationInscpTotal": operationInscpTotal,
  1197. "operationSelfTotal": operationSelfTotal,
  1198. "otherCostTotal": otherCostTotal,
  1199. "otherCostSelfTotal": otherCostSelfTotal,
  1200. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1201. "materialCostTotal": materialCostTotal,
  1202. "materialCostSelfTotal": materialCostSelfTotal,
  1203. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1204. "materialSelfTotal": materialSelfTotal,
  1205. "materialInscpTotal": materialInscpTotal,
  1206. "westernMedicineCostTotal": westernMedicineCostTotal,
  1207. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  1208. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1209. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  1210. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  1211. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1212. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  1213. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1214. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  1215. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  1216. "checkCostTotal": checkCostTotal,
  1217. "checkCostSelfTotal": checkCostSelfTotal,
  1218. "checkSelfTotal": checkSelfTotal,
  1219. "checkInscpTotal": checkInscpTotal,
  1220. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1221. "zhenChaCostTotal": zhenChaCostTotal,
  1222. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1223. "laboratoryCostTotal": laboratoryCostTotal,
  1224. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  1225. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1226. "laboratorySelfTotal": laboratorySelfTotal,
  1227. "laboratoryInscpTotal": laboratoryInscpTotal,
  1228. "treatCostTotal": treatCostTotal,
  1229. "treatCostSelfTotal": treatCostSelfTotal,
  1230. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1231. "treatSelfTotal": treatSelfTotal,
  1232. "treatInscpTotal": treatInscpTotal,
  1233. "charge_admin": charge_admin,
  1234. "printor_admin": printor_admin,
  1235. "org_name": org.OrgName,
  1236. "org_code": miConfig.Code,
  1237. "name": patient.Name,
  1238. "number": order.MdtrtId,
  1239. "date": order.SettleAccountsDate,
  1240. "info": order,
  1241. "new_order": order,
  1242. "his_hospital": his_hospital,
  1243. "his": his,
  1244. "funds": rf,
  1245. "dia_config": dia_config,
  1246. "huliCostTotal": huliCostTotal,
  1247. "huliCostSelfTotal": huliCostSelfTotal,
  1248. "huliCostPartSelfTotal": huliCostPartSelfTotal,
  1249. "huliSelfTotal": huliSelfTotal,
  1250. "huliInscpTotal": huliInscpTotal,
  1251. "zcCostTotal": zcCostTotal,
  1252. "zcCostSelfTotal": zcCostSelfTotal,
  1253. "zcCostPartSelfTotal": zcCostPartSelfTotal,
  1254. "zcSelfTotal": zcSelfTotal,
  1255. "zcInscpTotal": zcInscpTotal,
  1256. })
  1257. }
  1258. func (c *HisApiController) RefudDetail() {
  1259. order_id, _ := c.GetInt64("order_id")
  1260. order, _ := service.GetHisOrderByID(order_id)
  1261. adminUser := c.GetAdminUserInfo()
  1262. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1263. c.ServeSuccessJSON(map[string]interface{}{
  1264. "msg": "撤销成功",
  1265. })
  1266. }
  1267. func (c *HisApiController) Sscard() {
  1268. //r := CardInit()
  1269. //if r == 0 {
  1270. // GetBaseInfo()
  1271. //}
  1272. //c.ServeSuccessJSON(map[string]interface{}{
  1273. // "list": "11",
  1274. //})
  1275. }
  1276. func GetBaseInfo() error {
  1277. //handle := syscall.MustLoadDLL("SSCard.dll")
  1278. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1279. //
  1280. //str := make([]byte, 256)
  1281. //str1 := make([]byte, 256)
  1282. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1283. //if ferr != nil {
  1284. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1285. // return ferr
  1286. //}
  1287. //
  1288. //fmt.Println(string(str))
  1289. //
  1290. //fmt.Println(r)
  1291. return nil
  1292. }
  1293. func CardInit() int {
  1294. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1295. //add := DllTestDef.MustFindProc("Init")
  1296. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1297. //if err != nil {
  1298. // fmt.Println("SSCard的运算结果为:", ret)
  1299. //}
  1300. //result := int(ret)
  1301. return 0
  1302. }
  1303. func IntPtr(n int) uintptr {
  1304. return uintptr(n)
  1305. }
  1306. func StrPtr(s string) uintptr {
  1307. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1308. }
  1309. func (c *HisApiController) GetHisPatientList() {
  1310. record_date := c.GetString("record_date")
  1311. sch_type, _ := c.GetInt64("sch_type")
  1312. patient_type, _ := c.GetInt64("patient_type")
  1313. fmt.Println("patient_type")
  1314. fmt.Println(patient_type)
  1315. timeLayout := "2006-01-02"
  1316. loc, _ := time.LoadLocation("Local")
  1317. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1318. if err != nil {
  1319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1320. return
  1321. }
  1322. recordDateTime := theTime.Unix()
  1323. adminInfo := c.GetAdminUserInfo()
  1324. var patients []*service.PatientTwo
  1325. var patients_two []*service.Patients
  1326. if c.GetAdminUserInfo().CurrentOrgId == 10768 {
  1327. patients, _ = service.GetNewHisPatientListBySource(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1328. patients_two, _ = service.GetScheduleHisPatientListSource(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1329. } else {
  1330. patients, _ = service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1331. patients_two, _ = service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1332. }
  1333. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1334. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1335. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1336. fmt.Println(patients_three)
  1337. //获取当前用户的信息
  1338. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1339. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1340. //获取所有科室信息
  1341. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1342. //var aa []service.PatientThree
  1343. noElementsSlice := make([]service.PatientThree, 0)
  1344. c.ServeSuccessJSON(map[string]interface{}{
  1345. "list": patients_three,
  1346. "list_two": patients_four,
  1347. "list_three": noElementsSlice,
  1348. "info": adminUserInfo,
  1349. "doctors": doctors,
  1350. "department": department,
  1351. })
  1352. } else {
  1353. //获取当前用户的信息
  1354. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1355. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1356. //获取所有科室信息
  1357. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1358. //var aa []service.PatientThree
  1359. noElementsSlice := make([]service.PatientThree, 0)
  1360. c.ServeSuccessJSON(map[string]interface{}{
  1361. "list": patients,
  1362. "list_two": patients_two,
  1363. "list_three": noElementsSlice,
  1364. "info": adminUserInfo,
  1365. "doctors": doctors,
  1366. "department": department,
  1367. })
  1368. }
  1369. }
  1370. type CustomTemplate struct {
  1371. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1372. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1373. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1374. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1375. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1376. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1377. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1378. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1379. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1380. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1381. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1382. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1383. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1384. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1385. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1386. }
  1387. func (c *HisApiController) GetHisPatientInfo() {
  1388. patient_id, _ := c.GetInt64("patient_id")
  1389. his_patient_id, _ := c.GetInt64("his_patient_id")
  1390. record_date := c.GetString("record_date")
  1391. number := c.GetString("number")
  1392. //start_time := c.GetString("start_time")
  1393. //end_time := c.GetString("end_time")
  1394. p_type, _ := c.GetInt64("p_type")
  1395. timeLayout := "2006-01-02"
  1396. loc, _ := time.LoadLocation("Local")
  1397. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1398. if err != nil {
  1399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1400. return
  1401. }
  1402. recordDateTime := theTime.Unix()
  1403. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1404. //if err != nil {
  1405. //
  1406. //}
  1407. //startRecordDateTime := startTime.Unix()
  1408. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1409. //if err != nil {
  1410. //
  1411. //}
  1412. //endRecordDateTime := endTime.Unix()
  1413. admin := c.GetAdminUserInfo()
  1414. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1415. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1416. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1417. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1418. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1419. var prescriptions []*models.HisPrescription
  1420. var last_prescriptions []*models.HisPrescription
  1421. var sch_prescriptions []CustomTemplate
  1422. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1423. if p_type == 1 { //住院
  1424. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1425. for _, item := range prescriptions {
  1426. for _, subItem := range item.HisDoctorAdviceInfo {
  1427. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1428. if info.RetailPrice > 0 {
  1429. subItem.Drug.MinPrice = info.RetailPrice
  1430. }
  1431. }
  1432. }
  1433. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1434. } else { //门诊
  1435. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1436. for _, item := range prescriptions {
  1437. for _, subItem := range item.HisDoctorAdviceInfo {
  1438. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1439. if info.RetailPrice > 0 {
  1440. subItem.Drug.MinPrice = info.RetailPrice
  1441. }
  1442. }
  1443. }
  1444. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1445. }
  1446. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1447. if sch.ID > 0 {
  1448. var week string
  1449. t := theTime
  1450. switch t.Weekday().String() {
  1451. case "Monday":
  1452. week = "周一"
  1453. break
  1454. case "Tuesday":
  1455. week = "周二"
  1456. break
  1457. case "Wednesday":
  1458. week = "周三"
  1459. break
  1460. case "Thursday":
  1461. week = "周四"
  1462. break
  1463. case "Friday":
  1464. week = "周五"
  1465. break
  1466. case "Saturday":
  1467. week = "周六"
  1468. break
  1469. case "Sunday":
  1470. week = "周日"
  1471. break
  1472. }
  1473. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1474. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1475. //根据推送频率组装新的数组
  1476. for _, item := range temp_sch_prescriptions {
  1477. var cus CustomTemplate
  1478. cus.ID = item.ID
  1479. cus.UserOrgId = item.UserOrgId
  1480. cus.PatientId = item.PatientId
  1481. cus.MedType = item.MedType
  1482. cus.RecordDate = item.RecordDate
  1483. cus.Type = item.Type
  1484. cus.PType = item.PType
  1485. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1486. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1487. if subItem.FrequencyType == 1 { //每次必推
  1488. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1489. }
  1490. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1491. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1492. }
  1493. if subItem.FrequencyType == 2 { //按照天数频率
  1494. p, _ := time.Parse("2006-01-02", theTime.Format("2006-01-02"))
  1495. now := p.Unix()
  1496. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1497. dayStr2 := "-" + dayStr
  1498. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1499. oldTime := theTime.AddDate(0, 0, int(count)).Unix()
  1500. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1501. if len(advices) == 0 {
  1502. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1503. }
  1504. }
  1505. }
  1506. }
  1507. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1508. if subItem.Type == 2 {
  1509. if subItem.XtHisProject.MedicalStatus != 1 {
  1510. if subItem.FrequencyType == 1 {
  1511. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1512. }
  1513. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1514. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1515. }
  1516. if subItem.FrequencyType == 2 {
  1517. p, _ := time.Parse("2006-01-02", theTime.Format("2006-01-02"))
  1518. now := p.Unix()
  1519. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1520. dayStr2 := "-" + dayStr
  1521. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1522. oldTime := theTime.AddDate(0, 0, int(count)).Unix()
  1523. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1524. if len(projects) == 0 {
  1525. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1526. }
  1527. }
  1528. }
  1529. } else if subItem.Type == 3 {
  1530. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1531. if subItem.FrequencyType == 1 {
  1532. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1533. }
  1534. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1535. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1536. }
  1537. if subItem.FrequencyType == 2 {
  1538. p, _ := time.Parse("2006-01-02", theTime.Format("2006-01-02"))
  1539. now := p.Unix()
  1540. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1541. dayStr2 := "-" + dayStr
  1542. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1543. oldTime := theTime.AddDate(0, 0, int(count)).Unix()
  1544. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1545. if len(projects) == 0 {
  1546. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1547. }
  1548. }
  1549. }
  1550. }
  1551. }
  1552. sch_prescriptions = append(sch_prescriptions, cus)
  1553. }
  1554. for _, item := range sch_prescriptions {
  1555. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1556. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1557. }
  1558. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1559. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1560. }
  1561. }
  1562. }
  1563. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1564. if config.ID > 0 && config.IsOpen == 1 {
  1565. for _, item := range sch_prescriptions {
  1566. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1567. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1568. if info.RetailPrice > 0 {
  1569. subItem.Drug.MinPrice = info.RetailPrice
  1570. if admin.CurrentOrgId != 10598 {
  1571. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1572. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1573. }
  1574. }
  1575. }
  1576. }
  1577. }
  1578. if config.ID > 0 && config.IsOpen == 1 {
  1579. for _, item := range sch_prescriptions {
  1580. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1581. if subItem.Type == 3 {
  1582. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1583. if info.Price > 0 {
  1584. subItem.GoodInfo.PackingPrice = info.Price
  1585. if admin.CurrentOrgId != 10598 {
  1586. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1587. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1588. }
  1589. }
  1590. }
  1591. }
  1592. }
  1593. }
  1594. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1595. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1596. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1597. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1598. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1599. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1600. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1601. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1602. //获取所有科室信息
  1603. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1604. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1605. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1606. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1607. fmt.Println(prescriptions)
  1608. fmt.Println(sch_prescriptions)
  1609. fmt.Println(last_prescriptions)
  1610. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1611. if len(sch_prescriptions) > 0 {
  1612. var index = 0
  1613. for subindex, item := range sch_prescriptions {
  1614. if item.Type == 2 {
  1615. index = subindex
  1616. }
  1617. }
  1618. fmt.Println(index)
  1619. fmt.Println(len(sch_prescriptions))
  1620. if index >= 0 && index < len(sch_prescriptions) {
  1621. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1622. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1623. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1624. if one.ID > 0 {
  1625. var hpt models.HisPrescriptionProjectTemplate
  1626. hpt.Type = 3
  1627. hpt.ID = 0
  1628. hpt.PatientId = sch_prescriptions[index].PatientId
  1629. hpt.Status = 1
  1630. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1631. hpt.Mtime = time.Now().Unix()
  1632. hpt.Ctime = time.Now().Unix()
  1633. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1634. hpt.Count = "1"
  1635. hpt.Price = one.RetailPrice
  1636. hpt.ProjectId = one.ID
  1637. hpt.FeedetlSn = ""
  1638. hpt.PrescriptionId = sch_prescriptions[index].ID
  1639. hpt.Unit = one.PackingUnit
  1640. hpt.Day = "1"
  1641. hpt.SingleDose = "1"
  1642. hpt.GoodInfo = one
  1643. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1644. }
  1645. if two.ID > 0 {
  1646. var hpt models.HisPrescriptionProjectTemplate
  1647. hpt.Type = 3
  1648. hpt.ID = 0
  1649. hpt.PatientId = sch_prescriptions[index].PatientId
  1650. hpt.Status = 1
  1651. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1652. hpt.Mtime = time.Now().Unix()
  1653. hpt.Ctime = time.Now().Unix()
  1654. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1655. hpt.Count = "1"
  1656. hpt.Price = two.RetailPrice
  1657. hpt.ProjectId = two.ID
  1658. hpt.FeedetlSn = ""
  1659. hpt.PrescriptionId = sch_prescriptions[index].ID
  1660. hpt.Unit = two.PackingUnit
  1661. hpt.Day = "1"
  1662. hpt.SingleDose = "1"
  1663. hpt.GoodInfo = two
  1664. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1665. }
  1666. //if three.ID > 0 {
  1667. // var hpt models.HisPrescriptionProjectTemplate
  1668. // hpt.Type = 3
  1669. // hpt.ID = 0
  1670. // hpt.PatientId = sch_prescriptions[index].PatientId
  1671. // hpt.Status = 1
  1672. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1673. // hpt.Mtime = time.Now().Unix()
  1674. // hpt.Ctime = time.Now().Unix()
  1675. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1676. // hpt.Count = "1"
  1677. // hpt.Price = three.RetailPrice
  1678. // hpt.ProjectId = three.ID
  1679. // hpt.FeedetlSn = ""
  1680. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1681. // hpt.Unit = three.PackingUnit
  1682. // hpt.Day = "1"
  1683. // hpt.SingleDose = "1"
  1684. // hpt.GoodInfo = three
  1685. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1686. //}
  1687. fmt.Println(sch_prescriptions)
  1688. }
  1689. } else {
  1690. if len(last_prescriptions) > 0 {
  1691. var index = 0
  1692. for subindex, item := range last_prescriptions {
  1693. if item.Type == 2 {
  1694. index = subindex
  1695. }
  1696. }
  1697. if index >= 0 && index < len(last_prescriptions) {
  1698. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1699. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1700. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1701. if one.ID > 0 {
  1702. var hpt models.HisPrescriptionProject
  1703. hpt.Type = 3
  1704. hpt.ID = 0
  1705. hpt.PatientId = last_prescriptions[index].PatientId
  1706. hpt.Status = 1
  1707. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1708. hpt.Mtime = time.Now().Unix()
  1709. hpt.Ctime = time.Now().Unix()
  1710. hpt.RecordDate = last_prescriptions[index].RecordDate
  1711. hpt.Count = "1"
  1712. hpt.Price = one.RetailPrice
  1713. hpt.ProjectId = one.ID
  1714. hpt.FeedetlSn = ""
  1715. hpt.PrescriptionId = last_prescriptions[index].ID
  1716. hpt.Unit = one.PackingUnit
  1717. hpt.Day = "1"
  1718. hpt.SingleDose = "1"
  1719. hpt.GoodInfo = one
  1720. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1721. }
  1722. if two.ID > 0 {
  1723. var hpt models.HisPrescriptionProject
  1724. hpt.Type = 3
  1725. hpt.ID = 0
  1726. hpt.PatientId = last_prescriptions[index].PatientId
  1727. hpt.Status = 1
  1728. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1729. hpt.Mtime = time.Now().Unix()
  1730. hpt.Ctime = time.Now().Unix()
  1731. hpt.RecordDate = last_prescriptions[index].RecordDate
  1732. hpt.Count = "1"
  1733. hpt.Price = two.RetailPrice
  1734. hpt.ProjectId = two.ID
  1735. hpt.FeedetlSn = ""
  1736. hpt.PrescriptionId = last_prescriptions[index].ID
  1737. hpt.Unit = two.PackingUnit
  1738. hpt.Day = "1"
  1739. hpt.SingleDose = "1"
  1740. hpt.GoodInfo = two
  1741. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1742. }
  1743. //if three.ID > 0 {
  1744. // var hpt models.HisPrescriptionProject
  1745. // hpt.Type = 3
  1746. // hpt.ID = 0
  1747. // hpt.PatientId = last_prescriptions[index].PatientId
  1748. // hpt.Status = 1
  1749. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1750. // hpt.Mtime = time.Now().Unix()
  1751. // hpt.Ctime = time.Now().Unix()
  1752. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1753. // hpt.Count = "1"
  1754. // hpt.Price = three.RetailPrice
  1755. // hpt.ProjectId = three.ID
  1756. // hpt.FeedetlSn = ""
  1757. // hpt.PrescriptionId = last_prescriptions[index].ID
  1758. // hpt.Unit = three.PackingUnit
  1759. // hpt.Day = "1"
  1760. // hpt.SingleDose = "1"
  1761. // hpt.GoodInfo = three
  1762. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1763. //}
  1764. }
  1765. }
  1766. }
  1767. }
  1768. c.ServeSuccessJSON(map[string]interface{}{
  1769. "his_info": his_patient_info,
  1770. "xt_info": xt_patient_info,
  1771. "prescription": prescriptions,
  1772. "case_history": case_history,
  1773. "info": patientPrescriptionInfo,
  1774. //"month_prescriptions": monthPrescriptions,
  1775. "order": order,
  1776. "doctors": doctors,
  1777. "department": department,
  1778. "sch_prescriptions": sch_prescriptions,
  1779. "last_prescriptions": last_prescriptions,
  1780. "schedule": sch,
  1781. "count": count,
  1782. "drugStockConfig": drugStockConfig,
  1783. "last_info": lastPatientPrescriptionInfo,
  1784. "befor": beforThrity,
  1785. "LastCaseHistory": LastCaseHistory,
  1786. "prescriptionInfo": prescriptionInfo,
  1787. })
  1788. return
  1789. }
  1790. func (c *HisApiController) GetHisPrescriptionConfig() {
  1791. adminInfo := c.GetAdminUserInfo()
  1792. //获取医嘱模版
  1793. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1794. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1795. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1796. //获取所有基础药
  1797. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1798. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1799. if config.ID > 0 && config.IsOpen == 1 {
  1800. for _, item := range drugs {
  1801. var index = 0
  1802. for _, subItem := range item.OtherDrugWarehouseInfo {
  1803. if index == 0 {
  1804. index = index + 1
  1805. if subItem.RetailPrice > 0 {
  1806. item.MinPrice = subItem.RetailPrice
  1807. }
  1808. }
  1809. }
  1810. }
  1811. }
  1812. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1813. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1814. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1815. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1816. //获取所有科室信息
  1817. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1818. //获取诊断信息
  1819. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1820. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1821. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1822. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1823. //获取是否开启保存耗材出库的开关
  1824. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1825. c.ServeSuccessJSON(map[string]interface{}{
  1826. "drugs": drugs,
  1827. "advices_template": advices,
  1828. "drugways": drugways,
  1829. "efs": efs,
  1830. "doctors": doctors,
  1831. "department": department,
  1832. "sick": sick,
  1833. "additions": additions,
  1834. "diagnose": diagnose,
  1835. "manufacturers": manufacturers,
  1836. "goodOutOpen": goodOutOpen,
  1837. "patientDiagnose": patientDiagnose,
  1838. })
  1839. }
  1840. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1841. //获取所有基础药
  1842. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1843. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1844. if config.ID > 0 && config.IsOpen == 1 {
  1845. for _, item := range drugs {
  1846. var index = 0
  1847. for _, subItem := range item.OtherDrugWarehouseInfo {
  1848. if index == 0 {
  1849. index = index + 1
  1850. if subItem.RetailPrice > 0 {
  1851. item.MinPrice = subItem.RetailPrice
  1852. }
  1853. }
  1854. }
  1855. }
  1856. }
  1857. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1858. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1859. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1860. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1861. //获取所有科室信息
  1862. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1863. //获取诊断信息
  1864. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1865. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1866. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1867. //获取是否开启保存耗材出库的开关
  1868. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1869. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1870. c.ServeSuccessJSON(map[string]interface{}{
  1871. "drugs": drugs,
  1872. "advices_template": advices,
  1873. "drugways": drugways,
  1874. "efs": efs,
  1875. "doctors": doctors,
  1876. "department": department,
  1877. "sick": sick,
  1878. "additions": additions,
  1879. "diagnose": diagnose,
  1880. "manufacturers": manufacturers,
  1881. "goodOutOpen": goodOutOpen,
  1882. "patientDiagnose": patientDiagnose,
  1883. })
  1884. }
  1885. }
  1886. func (c *HisApiController) CreateHisPrescription() {
  1887. record_date := c.GetString("record_date")
  1888. patient_id, _ := c.GetInt64("patient_id")
  1889. reg_type, _ := c.GetInt64("reg_type")
  1890. diagnose := c.GetString("diagnose")
  1891. sick_type, _ := c.GetInt64("sick_type")
  1892. sick_history := c.GetString("sick_history")
  1893. doctor_id, _ := c.GetInt64("doctor", 0)
  1894. department, _ := c.GetInt64("department", 0)
  1895. his_patient_id, _ := c.GetInt64("his_patient_id")
  1896. p_type, _ := c.GetInt64("p_type")
  1897. patient_diagnose := c.GetString("patient_diagnose")
  1898. dataBody := make(map[string]interface{}, 0)
  1899. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1900. if err != nil {
  1901. utils.ErrorLog(err.Error())
  1902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1903. return
  1904. }
  1905. //edit, src := GetCompareData(dataBody)
  1906. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1907. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1908. //fmt.Println(drugResult)
  1909. //fmt.Println(goodResult)
  1910. timeLayout := "2006-01-02"
  1911. loc, _ := time.LoadLocation("Local")
  1912. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1913. if err != nil {
  1914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1915. return
  1916. }
  1917. adminInfo := c.GetAdminUserInfo()
  1918. recordDateTime := theTime.Unix()
  1919. //查询默认出库仓库库存
  1920. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1921. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1922. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1923. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1924. if len(lists) == 1 {
  1925. his_patient_id = lists[0].ID
  1926. }
  1927. }
  1928. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1929. //自动出库的开关开启
  1930. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1931. //自动出库
  1932. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1933. //耗材保存处方出库
  1934. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1935. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1936. //已发药和已收费限制逻辑
  1937. isMidicine := false
  1938. isCharge := false
  1939. //是否有库存
  1940. isSumCount := false
  1941. is_sum_total := false
  1942. var drug_name = ""
  1943. var good_name = ""
  1944. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1945. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1946. if len(prescriptions) > 0 {
  1947. for _, item := range prescriptions {
  1948. items := item.(map[string]interface{})
  1949. if adminInfo.CurrentOrgId == 9478 {
  1950. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1951. advices := items["advices"].([]interface{})
  1952. if len(advices) > 0 {
  1953. for _, advice := range advices {
  1954. var adviceId int64
  1955. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1956. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1957. }
  1958. var drug_id int64
  1959. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1960. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1961. }
  1962. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1963. //查询该药品是否存在开药记录
  1964. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1965. if advicelist.ID == 0 {
  1966. if drug.IsUse != 1 {
  1967. if drug.SumCount == 0 {
  1968. drug_name = drug.DrugName
  1969. isSumCount = true
  1970. }
  1971. }
  1972. }
  1973. }
  1974. }
  1975. }
  1976. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1977. projects := items["project"].([]interface{})
  1978. if len(projects) > 0 {
  1979. for _, project := range projects {
  1980. var project_id int64
  1981. var project_type int64
  1982. var project_name string
  1983. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1984. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1985. }
  1986. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1987. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1988. }
  1989. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1990. project_name = project.(map[string]interface{})["project_name"].(string)
  1991. }
  1992. if project_type == 3 {
  1993. //查找该耗材的出库记录
  1994. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1995. if len(goodWarehouseInfo) == 0 {
  1996. //查询耗材库存
  1997. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  1998. var stock_count int64
  1999. for _, it := range list {
  2000. stock_count += it.StockCount
  2001. }
  2002. if stock_count == 0 {
  2003. good_name = project_name
  2004. is_sum_total = true
  2005. }
  2006. }
  2007. }
  2008. }
  2009. }
  2010. }
  2011. }
  2012. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2013. utils.ErrorLog("id")
  2014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2015. return
  2016. }
  2017. id := int64(items["id"].(float64))
  2018. if id > 0 {
  2019. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2020. if err != nil {
  2021. if new_prescription.OrderStatus == 4 {
  2022. isCharge = true
  2023. }
  2024. }
  2025. }
  2026. }
  2027. }
  2028. }
  2029. if isMidicine == true {
  2030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  2031. return
  2032. }
  2033. if isCharge == true {
  2034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  2035. return
  2036. }
  2037. if adminInfo.CurrentOrgId == 9478 {
  2038. //不是保存处方出库
  2039. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2040. if drugOutConfig.IsOpen == 1 {
  2041. if isSumCount == true {
  2042. c.ServeDynamicFailJsonSend(drug_name + "库存不足,保存失败")
  2043. return
  2044. }
  2045. }
  2046. if goodOutConfig.IsOpen == 1 {
  2047. if is_sum_total == true {
  2048. c.ServeDynamicFailJsonSend(good_name + "库存不足,保存失败")
  2049. return
  2050. }
  2051. }
  2052. }
  2053. // 开始主事务
  2054. db := service.XTWriteDB()
  2055. tx := db.Begin()
  2056. // 在函数结束时处理事务回滚
  2057. defer func() {
  2058. if r := recover(); r != nil {
  2059. tx.Rollback()
  2060. }
  2061. }()
  2062. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2063. //药品发药出库
  2064. if pharmacyConfig.IsOpen == 1 {
  2065. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2066. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2067. if len(prescriptions) > 0 {
  2068. for _, item := range prescriptions {
  2069. items := item.(map[string]interface{})
  2070. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2071. advices := items["advices"].([]interface{})
  2072. if len(advices) > 0 {
  2073. for _, advice := range advices {
  2074. var drug_id int64
  2075. var prescribing_number float64
  2076. var prescribingNumberUnit string
  2077. var adviceId int64
  2078. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2079. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2080. }
  2081. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2082. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2083. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2084. }
  2085. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2086. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2087. }
  2088. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2089. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2090. }
  2091. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2092. if drug.ID == 0 {
  2093. tx.Rollback()
  2094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2095. return
  2096. }
  2097. //查询药品的所有库存
  2098. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2099. var total_count int64
  2100. for _, it := range list {
  2101. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2102. }
  2103. totals := strconv.FormatInt(total_count, 10)
  2104. //查询该药品是否存在开药记录
  2105. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2106. //新增处方盘点库存是否充足
  2107. if advicelist.ID == 0 {
  2108. all_count, _ := strconv.ParseFloat(totals, 64)
  2109. if prescribingNumberUnit == drug.MinUnit {
  2110. if drug.IsUse != 1 {
  2111. if drug.IsProject == 0 || drug.IsProject == 2 {
  2112. if all_count == 0 {
  2113. tx.Rollback()
  2114. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2115. return
  2116. }
  2117. if prescribing_number > all_count {
  2118. tx.Rollback()
  2119. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2120. return
  2121. }
  2122. }
  2123. }
  2124. }
  2125. if prescribingNumberUnit == drug.MaxUnit {
  2126. num := prescribing_number * float64(drug.MinNumber)
  2127. if drug.IsUse != 1 {
  2128. if drug.IsProject == 0 || drug.IsProject == 2 {
  2129. if all_count == 0 {
  2130. tx.Rollback()
  2131. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2132. return
  2133. }
  2134. if num > all_count {
  2135. tx.Rollback()
  2136. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2137. return
  2138. }
  2139. }
  2140. }
  2141. }
  2142. }
  2143. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2144. //不使用保存处方出库
  2145. if drugOutConfig.IsOpen != 1 {
  2146. //修改处方
  2147. for _, advice := range advices {
  2148. var drug_id int64
  2149. var prescribing_number float64
  2150. var prescribingNumberUnit string
  2151. var prescribingNumber string
  2152. var adviceId int64
  2153. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2154. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2155. }
  2156. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2157. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2158. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2159. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2160. }
  2161. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2162. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2163. }
  2164. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2165. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2166. }
  2167. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2168. if drug.ID == 0 {
  2169. tx.Rollback()
  2170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2171. return
  2172. }
  2173. //查询药品的所有库存
  2174. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2175. var total_count int64
  2176. for _, it := range list {
  2177. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2178. }
  2179. totals := strconv.FormatInt(total_count, 10)
  2180. //查询该药品是否存在开药记录
  2181. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2182. //新增处方
  2183. if advicelist.ID == 0 {
  2184. all_count, _ := strconv.ParseFloat(totals, 64)
  2185. if prescribingNumberUnit == drug.MinUnit {
  2186. if drug.IsUse != 1 {
  2187. if drug.IsProject == 0 || drug.IsProject == 2 {
  2188. if all_count == 0 {
  2189. tx.Rollback()
  2190. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2191. return
  2192. }
  2193. if prescribing_number > all_count {
  2194. tx.Rollback()
  2195. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2196. return
  2197. }
  2198. }
  2199. }
  2200. } else {
  2201. if prescribingNumberUnit == drug.MaxUnit {
  2202. num := prescribing_number * float64(drug.MinNumber)
  2203. if drug.IsUse != 1 {
  2204. if drug.IsProject == 0 || drug.IsProject == 2 {
  2205. if all_count == 0 {
  2206. tx.Rollback()
  2207. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2208. return
  2209. }
  2210. if num > all_count {
  2211. tx.Rollback()
  2212. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2213. return
  2214. }
  2215. }
  2216. }
  2217. }
  2218. }
  2219. }
  2220. //修改处方
  2221. if advicelist.ID > 0 {
  2222. var device_number int64
  2223. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2224. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2225. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2226. device_number = prescribingNumberInt * drug.MinNumber
  2227. }
  2228. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2229. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2230. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2231. device_number = prescribingNumberInt
  2232. }
  2233. var number_count int64
  2234. if prescribingNumberUnit == drug.MaxUnit {
  2235. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2236. number_count = prescribingNumberInt * drug.MinNumber
  2237. }
  2238. if prescribingNumberUnit == drug.MinUnit {
  2239. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2240. number_count = prescribingNumberInt
  2241. }
  2242. //如果修改的数量大于之前修改的数量
  2243. if (number_count - device_number) > 0 {
  2244. //如果修改的差数量 大于库存数量
  2245. if drug.IsUse != 1 {
  2246. if (number_count - device_number) > total_count {
  2247. tx.Rollback()
  2248. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2249. return
  2250. }
  2251. }
  2252. }
  2253. }
  2254. }
  2255. }
  2256. }
  2257. }
  2258. }
  2259. }
  2260. }
  2261. }
  2262. }
  2263. //已发药和已收费限制逻辑
  2264. //执行出库的逻辑
  2265. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2266. //校验库存总量
  2267. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2268. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2269. if len(prescriptions) > 0 {
  2270. for _, item := range prescriptions {
  2271. items := item.(map[string]interface{})
  2272. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2273. advices := items["advices"].([]interface{})
  2274. if len(advices) > 0 {
  2275. for _, advice := range advices {
  2276. var drug_id int64
  2277. var prescribing_number float64
  2278. var prescribingNumberUnit string
  2279. var adviceId int64
  2280. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2281. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2282. }
  2283. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2284. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2285. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2286. }
  2287. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2288. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2289. }
  2290. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2291. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2292. }
  2293. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2294. if drug.ID == 0 {
  2295. tx.Rollback()
  2296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2297. return
  2298. }
  2299. //查询药品的所有库存
  2300. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2301. var total_count int64
  2302. for _, it := range list {
  2303. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2304. }
  2305. totals := strconv.FormatInt(total_count, 10)
  2306. //查询该药品是否存在开药记录
  2307. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2308. //查询最新批次库存
  2309. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2310. var batch_number_count int64
  2311. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2312. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2313. //新增处方
  2314. if advicelist.ID == 0 {
  2315. all_count, _ := strconv.ParseFloat(totals, 64)
  2316. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2317. if prescribingNumberUnit == drug.MinUnit {
  2318. if drug.IsUse != 1 {
  2319. if drug.IsProject == 0 || drug.IsProject == 2 {
  2320. if all_count == 0 {
  2321. tx.Rollback()
  2322. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2323. return
  2324. }
  2325. if prescribing_number > all_count {
  2326. tx.Rollback()
  2327. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2328. return
  2329. }
  2330. }
  2331. if adminInfo.CurrentOrgId == 10215 {
  2332. if prescribing_number > batch_number_all_count {
  2333. tx.Rollback()
  2334. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2335. return
  2336. }
  2337. }
  2338. }
  2339. }
  2340. if prescribingNumberUnit == drug.MaxUnit {
  2341. num := prescribing_number * float64(drug.MinNumber)
  2342. if drug.IsUse != 1 {
  2343. if drug.IsProject == 0 || drug.IsProject == 2 {
  2344. if all_count == 0 {
  2345. tx.Rollback()
  2346. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2347. return
  2348. }
  2349. if num > all_count {
  2350. tx.Rollback()
  2351. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2352. return
  2353. }
  2354. }
  2355. if adminInfo.CurrentOrgId == 10215 {
  2356. if num > batch_number_all_count {
  2357. tx.Rollback()
  2358. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2359. return
  2360. }
  2361. }
  2362. }
  2363. }
  2364. }
  2365. //不是保存处方出库
  2366. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2367. if drugOutConfig.IsOpen != 1 {
  2368. //修改处方
  2369. for _, advice := range advices {
  2370. var drug_id int64
  2371. var prescribing_number float64
  2372. var prescribingNumberUnit string
  2373. var prescribingNumber string
  2374. var adviceId int64
  2375. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2376. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2377. }
  2378. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2379. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2380. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2381. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2382. }
  2383. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2384. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2385. }
  2386. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2387. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2388. }
  2389. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2390. if drug.ID == 0 {
  2391. tx.Rollback()
  2392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2393. return
  2394. }
  2395. //查询药品的所有库存
  2396. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2397. var total_count int64
  2398. for _, it := range list {
  2399. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2400. }
  2401. totals := strconv.FormatInt(total_count, 10)
  2402. //查询该药品是否存在开药记录
  2403. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2404. //新增处方
  2405. if advicelist.ID == 0 {
  2406. //查询最新批次库存
  2407. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2408. var batch_number_count int64
  2409. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2410. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2411. all_count, _ := strconv.ParseFloat(totals, 64)
  2412. if all_count == 0 {
  2413. tx.Rollback()
  2414. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2415. return
  2416. }
  2417. if prescribingNumberUnit == drug.MinUnit {
  2418. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2419. if drug.IsUse != 1 {
  2420. if drug.IsProject == 0 || drug.IsProject == 2 {
  2421. if all_count == 0 {
  2422. tx.Rollback()
  2423. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2424. return
  2425. }
  2426. if prescribing_number > all_count {
  2427. tx.Rollback()
  2428. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2429. return
  2430. }
  2431. }
  2432. if adminInfo.CurrentOrgId == 10215 {
  2433. if prescribing_number > batch_number_all_count {
  2434. tx.Rollback()
  2435. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2436. return
  2437. }
  2438. }
  2439. }
  2440. } else {
  2441. if prescribingNumberUnit == drug.MaxUnit {
  2442. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2443. num := prescribing_number * float64(drug.MinNumber)
  2444. if drug.IsUse != 1 {
  2445. if drug.IsProject == 0 || drug.IsProject == 2 {
  2446. if all_count == 0 {
  2447. tx.Rollback()
  2448. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2449. return
  2450. }
  2451. if num > all_count {
  2452. tx.Rollback()
  2453. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2454. return
  2455. }
  2456. }
  2457. if adminInfo.CurrentOrgId == 10215 {
  2458. if prescribing_number > batch_number_all_count {
  2459. tx.Rollback()
  2460. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2461. return
  2462. }
  2463. }
  2464. }
  2465. }
  2466. }
  2467. }
  2468. //修改处方
  2469. if advicelist.ID > 0 {
  2470. //查询最新批次库存
  2471. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2472. var batch_number_count int64
  2473. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2474. var device_number int64
  2475. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2476. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2477. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2478. device_number = prescribingNumberInt * drug.MinNumber
  2479. }
  2480. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2481. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2482. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2483. device_number = prescribingNumberInt
  2484. //回退库存
  2485. }
  2486. var number_count int64
  2487. if prescribingNumberUnit == drug.MaxUnit {
  2488. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2489. number_count = prescribingNumberInt * drug.MinNumber
  2490. //回退库存
  2491. }
  2492. if prescribingNumberUnit == drug.MinUnit {
  2493. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2494. number_count = prescribingNumberInt
  2495. //回退库存
  2496. }
  2497. //如果修改的数量大于之前修改的数量
  2498. if (number_count - device_number) > 0 {
  2499. //如果修改的差数量 大于库存数量
  2500. if drug.IsUse != 1 {
  2501. if drug.IsProject == 0 || drug.IsProject == 2 {
  2502. if total_count == 0 {
  2503. tx.Rollback()
  2504. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2505. return
  2506. }
  2507. if (number_count - device_number) > total_count {
  2508. tx.Rollback()
  2509. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2510. return
  2511. }
  2512. if (number_count - device_number) > batch_number_count {
  2513. tx.Rollback()
  2514. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2515. return
  2516. }
  2517. }
  2518. if adminInfo.CurrentOrgId == 10215 {
  2519. // 查询该药品最后一次出库记录
  2520. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2521. var out_count int64
  2522. var in_count int64
  2523. var stock_max_number int64
  2524. var stock_min_number int64
  2525. for _, it := range outInfo {
  2526. if it.CountUnit == drug.MaxUnit {
  2527. it.Count = it.Count * drug.MinNumber
  2528. }
  2529. out_count += it.Count
  2530. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2531. stock_max_number = warehouseInfoList.StockMaxNumber
  2532. stock_min_number = warehouseInfoList.StockMinNumber
  2533. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2534. }
  2535. if out_count > 0 {
  2536. if (number_count - device_number) > in_count {
  2537. tx.Rollback()
  2538. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2539. return
  2540. }
  2541. }
  2542. // 未出库
  2543. if out_count == 0 {
  2544. var sum_in_count int64
  2545. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2546. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2547. //如果修改的数量大于有库存的第一个批次
  2548. if number_count > sum_in_count {
  2549. tx.Rollback()
  2550. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2551. return
  2552. }
  2553. }
  2554. }
  2555. }
  2556. }
  2557. //药品发药
  2558. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2559. //不使用药品发药的功能
  2560. //if pharmacyConfig.IsOpen != 1 {
  2561. // if device_number != number_count {
  2562. //
  2563. // //查询该药品的出库记录
  2564. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2565. // if len(outListExport) > 0 {
  2566. // //
  2567. // for _, item := range outListExport {
  2568. // //回退库存
  2569. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2570. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2571. // }
  2572. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2573. // var stock_max_number int64
  2574. // var stock_min_number int64
  2575. //
  2576. // if number_count >= drug.MinNumber {
  2577. //
  2578. // stock_max_number = device_number / drug.MinNumber
  2579. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2580. //
  2581. // stock_min_number = device_number % drug.MinNumber
  2582. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2583. //
  2584. // } else {
  2585. //
  2586. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2587. //
  2588. // }
  2589. // }
  2590. //
  2591. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2592. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2593. // }
  2594. // }
  2595. // }
  2596. //
  2597. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2598. // var sum_count int64
  2599. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2600. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2601. // for _, its := range stockInfo {
  2602. // if its.MaxUnit == drug.MaxUnit {
  2603. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2604. // }
  2605. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2606. // }
  2607. // //更新字典里面的库存
  2608. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2609. //
  2610. // //剩余库存
  2611. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2612. //
  2613. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2614. // //减少出库数量
  2615. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2616. //
  2617. // }
  2618. //}
  2619. }
  2620. }
  2621. }
  2622. //保存处方开药
  2623. if drugOutConfig.IsOpen == 1 {
  2624. //修改处方
  2625. for _, advice := range advices {
  2626. var drug_id int64
  2627. var prescribing_number float64
  2628. var prescribingNumberUnit string
  2629. var prescribingNumber string
  2630. var adviceId int64
  2631. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2632. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2633. }
  2634. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2635. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2636. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2637. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2638. }
  2639. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2640. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2641. }
  2642. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2643. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2644. }
  2645. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2646. if drug.ID == 0 {
  2647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2648. return
  2649. }
  2650. //查询药品的所有库存
  2651. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2652. var total_count int64
  2653. for _, it := range list {
  2654. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2655. }
  2656. totals := strconv.FormatInt(total_count, 10)
  2657. //查询该药品是否存在开药记录
  2658. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2659. //新增处方
  2660. if advicelist.ID == 0 {
  2661. //查询最新批次库存
  2662. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2663. var batch_number_count int64
  2664. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2665. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2666. all_count, _ := strconv.ParseFloat(totals, 64)
  2667. if prescribingNumberUnit == drug.MinUnit {
  2668. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2669. if drug.IsUse != 1 {
  2670. if drug.IsProject == 0 || drug.IsProject == 2 {
  2671. if all_count == 0 {
  2672. tx.Rollback()
  2673. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2674. return
  2675. }
  2676. if prescribing_number > all_count {
  2677. tx.Rollback()
  2678. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2679. return
  2680. }
  2681. }
  2682. if adminInfo.CurrentOrgId == 10215 {
  2683. if prescribing_number > batch_number_all_count {
  2684. tx.Rollback()
  2685. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2686. return
  2687. }
  2688. }
  2689. }
  2690. } else {
  2691. if prescribingNumberUnit == drug.MaxUnit {
  2692. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2693. num := prescribing_number * float64(drug.MinNumber)
  2694. if drug.IsUse != 1 {
  2695. if drug.IsProject == 0 || drug.IsProject == 2 {
  2696. if all_count == 0 {
  2697. tx.Rollback()
  2698. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2699. return
  2700. }
  2701. if num > all_count {
  2702. tx.Rollback()
  2703. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2704. return
  2705. }
  2706. }
  2707. if adminInfo.CurrentOrgId == 10215 {
  2708. if prescribing_number > batch_number_all_count {
  2709. tx.Rollback()
  2710. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2711. return
  2712. }
  2713. }
  2714. }
  2715. }
  2716. }
  2717. }
  2718. //修改处方
  2719. if advicelist.ID > 0 {
  2720. //查询最新批次库存
  2721. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2722. var batch_number_count int64
  2723. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2724. var device_number int64
  2725. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2726. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2727. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2728. device_number = prescribingNumberInt * drug.MinNumber
  2729. }
  2730. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2731. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2732. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2733. device_number = prescribingNumberInt
  2734. }
  2735. var number_count int64
  2736. if prescribingNumberUnit == drug.MaxUnit {
  2737. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2738. number_count = prescribingNumberInt * drug.MinNumber
  2739. }
  2740. if prescribingNumberUnit == drug.MinUnit {
  2741. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2742. number_count = prescribingNumberInt
  2743. }
  2744. //如果修改的数量大于之前修改的数量
  2745. if (number_count - device_number) > 0 {
  2746. //如果修改的差数量 大于库存数量
  2747. if drug.IsUse != 1 {
  2748. if drug.IsProject == 0 || drug.IsProject == 2 {
  2749. if total_count == 0 {
  2750. tx.Rollback()
  2751. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2752. return
  2753. }
  2754. if (number_count - device_number) > total_count {
  2755. tx.Rollback()
  2756. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2757. return
  2758. }
  2759. }
  2760. if adminInfo.CurrentOrgId == 10215 {
  2761. if (number_count - device_number) > batch_number_count {
  2762. tx.Rollback()
  2763. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2764. return
  2765. }
  2766. }
  2767. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2768. //查询历史出库数据总批次
  2769. // 查询该药品最后一次出库记录
  2770. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2771. var out_count int64
  2772. var in_count int64
  2773. var stock_max_number int64
  2774. var stock_min_number int64
  2775. for _, it := range outInfo {
  2776. if it.CountUnit == drug.MaxUnit {
  2777. it.Count = it.Count * drug.MinNumber
  2778. }
  2779. out_count += it.Count
  2780. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2781. stock_max_number = warehouseInfoList.StockMaxNumber
  2782. stock_min_number = warehouseInfoList.StockMinNumber
  2783. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2784. }
  2785. if out_count > 0 {
  2786. if (number_count - device_number) > in_count {
  2787. tx.Rollback()
  2788. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2789. return
  2790. }
  2791. }
  2792. // 未出库
  2793. if out_count == 0 {
  2794. var sum_in_count int64
  2795. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2796. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2797. if sum_in_count == 0 {
  2798. tx.Rollback()
  2799. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2800. return
  2801. }
  2802. //如果修改的数量大于有库存的第一个批次
  2803. if number_count > sum_in_count {
  2804. tx.Rollback()
  2805. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2806. return
  2807. }
  2808. }
  2809. }
  2810. }
  2811. }
  2812. }
  2813. }
  2814. }
  2815. }
  2816. }
  2817. }
  2818. }
  2819. }
  2820. }
  2821. }
  2822. //校验耗材库存
  2823. if goodOutConfig.IsOpen == 1 {
  2824. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2825. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2826. if len(prescriptions) > 0 {
  2827. for _, item := range prescriptions {
  2828. items := item.(map[string]interface{})
  2829. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2830. projects := items["project"].([]interface{})
  2831. if len(projects) > 0 {
  2832. for _, project := range projects {
  2833. var project_id int64
  2834. var project_type int64
  2835. var totals float64
  2836. var project_name string
  2837. var parsetotal int64
  2838. var id int64
  2839. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2840. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2841. }
  2842. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2843. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2844. }
  2845. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2846. total, _ := project.(map[string]interface{})["total"].(string)
  2847. totals, _ = strconv.ParseFloat(total, 64)
  2848. }
  2849. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2850. project_name = project.(map[string]interface{})["project_name"].(string)
  2851. }
  2852. if project_type == 3 {
  2853. //查找该耗材的出库记录
  2854. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2855. if len(goodWarehouseInfo) == 0 {
  2856. //查询耗材库存
  2857. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2858. var stock_count int64
  2859. for _, it := range list {
  2860. stock_count += it.StockCount
  2861. }
  2862. stock_counts := strconv.FormatInt(stock_count, 10)
  2863. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2864. if stock_total_count == 0 {
  2865. tx.Rollback()
  2866. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2867. return
  2868. }
  2869. if totals > stock_total_count {
  2870. tx.Rollback()
  2871. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2872. return
  2873. }
  2874. }
  2875. if len(goodWarehouseInfo) > 0 {
  2876. //查询该患者耗材的历史数据
  2877. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2878. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2879. //数量发生改变
  2880. if parsetotal != count {
  2881. //如果现在的数量大于历史数量,就要看库存是否足够
  2882. if parsetotal > count {
  2883. //查询耗材所有库存
  2884. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2885. var stock_count int64
  2886. for _, it := range list {
  2887. stock_count += it.StockCount
  2888. }
  2889. //库存不足
  2890. if stock_count == 0 {
  2891. tx.Rollback()
  2892. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2893. return
  2894. }
  2895. if (parsetotal - count) > stock_count {
  2896. tx.Rollback()
  2897. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2898. return
  2899. }
  2900. }
  2901. }
  2902. }
  2903. }
  2904. }
  2905. }
  2906. }
  2907. }
  2908. }
  2909. }
  2910. }
  2911. //不使用耗材保存处方出库
  2912. if goodOutConfig.IsOpen != 1 {
  2913. if stockConfig.IsOpen == 1 {
  2914. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2915. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2916. if len(prescriptions) > 0 {
  2917. for _, item := range prescriptions {
  2918. items := item.(map[string]interface{})
  2919. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2920. projects := items["project"].([]interface{})
  2921. if len(projects) > 0 {
  2922. for _, project := range projects {
  2923. var project_id int64
  2924. var project_type int64
  2925. var totals float64
  2926. var project_name string
  2927. var parsetotal int64
  2928. var id int64
  2929. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2930. id = int64(project.(map[string]interface{})["id"].(float64))
  2931. }
  2932. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2933. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2934. }
  2935. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2936. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2937. }
  2938. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2939. total, _ := project.(map[string]interface{})["total"].(string)
  2940. totals, _ = strconv.ParseFloat(total, 64)
  2941. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2942. }
  2943. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2944. project_name = project.(map[string]interface{})["project_name"].(string)
  2945. }
  2946. if project_type == 3 {
  2947. //查找该耗材的出库记录
  2948. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2949. //没有出库记录
  2950. if len(goodWarehouseInfo) == 0 {
  2951. //查询耗材库存
  2952. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2953. var stock_count int64
  2954. for _, it := range list {
  2955. stock_count += it.StockCount
  2956. }
  2957. stock_counts := strconv.FormatInt(stock_count, 10)
  2958. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2959. if stock_total_count == 0 {
  2960. tx.Rollback()
  2961. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2962. return
  2963. }
  2964. if totals > stock_total_count {
  2965. tx.Rollback()
  2966. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2967. return
  2968. }
  2969. //查找今日该患者已经出库的所有耗材
  2970. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2971. for _, item := range goodList {
  2972. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2973. var flush_count int64
  2974. for _, it := range goodListSix {
  2975. flush_count += it.StockCount
  2976. }
  2977. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2978. creater := adminInfo.AdminUser.Id
  2979. if errs != nil {
  2980. goodErrcode := models.XtGoodErrcode{
  2981. UserOrgId: item.OrgId,
  2982. Errcode: "手动出库更新剩余出库失败",
  2983. GoodId: item.GoodId,
  2984. Status: 1,
  2985. Ctime: time.Now().Unix(),
  2986. Mtime: 0,
  2987. Count: 0,
  2988. StockCount: 0,
  2989. Creater: creater,
  2990. BatchNumberId: 0,
  2991. WarehouseOutId: 0,
  2992. }
  2993. service.CreateGoodErrcode(goodErrcode)
  2994. }
  2995. }
  2996. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2997. }
  2998. //有出库记录
  2999. if len(goodWarehouseInfo) > 0 {
  3000. //查询该患者耗材的历史数据
  3001. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  3002. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  3003. //数量发生改变
  3004. if parsetotal != count {
  3005. //查找今日该患者已经出库的所有耗材
  3006. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  3007. for _, item := range goodList {
  3008. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  3009. var flush_count int64
  3010. for _, it := range goodListSix {
  3011. flush_count += it.StockCount
  3012. }
  3013. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  3014. //减少出库数量
  3015. creater := adminInfo.AdminUser.Id
  3016. if errs != nil {
  3017. goodErrcode := models.XtGoodErrcode{
  3018. UserOrgId: item.OrgId,
  3019. Errcode: "手动出库更新剩余出库失败",
  3020. GoodId: item.GoodId,
  3021. Status: 1,
  3022. Ctime: time.Now().Unix(),
  3023. Mtime: 0,
  3024. Count: 0,
  3025. StockCount: 0,
  3026. Creater: creater,
  3027. BatchNumberId: 0,
  3028. WarehouseOutId: 0,
  3029. }
  3030. service.CreateGoodErrcode(goodErrcode)
  3031. }
  3032. //查询默认仓库
  3033. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  3034. var total_count int64
  3035. for _, it := range stockList {
  3036. total_count += it.StockCount
  3037. }
  3038. //基础库插入数据
  3039. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  3040. }
  3041. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  3042. }
  3043. }
  3044. }
  3045. }
  3046. }
  3047. }
  3048. }
  3049. }
  3050. }
  3051. }
  3052. }
  3053. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3054. var hpInfo models.HisPrescriptionInfo
  3055. if info.ID == 0 {
  3056. var randNum int
  3057. randNum = rand.Intn(10000) + 1000
  3058. timestamp := time.Now().Unix()
  3059. tempTime := time.Unix(timestamp, 0)
  3060. timeFormat := tempTime.Format("20060102150405")
  3061. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3062. hpInfo = models.HisPrescriptionInfo{
  3063. HisPatientId: his_patient_id,
  3064. UserOrgId: adminInfo.CurrentOrgId,
  3065. RecordDate: theTime.Unix(),
  3066. PatientId: patient_id,
  3067. Status: 1,
  3068. Ctime: time.Now().Unix(),
  3069. Mtime: time.Now().Unix(),
  3070. Creator: adminInfo.AdminUser.Id,
  3071. Modifier: adminInfo.AdminUser.Id,
  3072. Diagnosis: diagnose,
  3073. SickHistory: sick_history,
  3074. Departments: department,
  3075. RegisterType: reg_type,
  3076. PrescriptionNumber: p_number,
  3077. PrescriptionStatus: 1,
  3078. Doctor: role.UserName,
  3079. DoctorId: doctor_id,
  3080. SickType: sick_type,
  3081. PType: p_type,
  3082. PatientDiagnosis: patient_diagnose,
  3083. }
  3084. service.SavePatientPrescriptionInfo(hpInfo)
  3085. //创建步骤表
  3086. finish := models.XtDialysisFinish{
  3087. IsFinish: 1,
  3088. UserOrgId: adminInfo.CurrentOrgId,
  3089. Status: 1,
  3090. Ctime: time.Now().Unix(),
  3091. Mtime: 0,
  3092. Module: 4,
  3093. RecordDate: theTime.Unix(),
  3094. Sourse: 1,
  3095. PatientId: patient_id,
  3096. }
  3097. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  3098. if dialysisFinish.ID == 0 {
  3099. service.CreateDialysisFinish(finish)
  3100. }
  3101. redis := service.RedisClient()
  3102. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3103. redis.Set(key, "", time.Second)
  3104. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3105. redis.Set(keyOne, "", time.Second)
  3106. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3107. redis.Set(keySeven, "", time.Second)
  3108. defer redis.Close()
  3109. } else {
  3110. hpInfo = models.HisPrescriptionInfo{
  3111. ID: info.ID,
  3112. UserOrgId: adminInfo.CurrentOrgId,
  3113. RecordDate: info.RecordDate,
  3114. PatientId: info.PatientId,
  3115. Status: 1,
  3116. Ctime: info.Ctime,
  3117. Mtime: time.Now().Unix(),
  3118. Creator: info.Creator,
  3119. Modifier: adminInfo.AdminUser.Id,
  3120. Diagnosis: diagnose,
  3121. SickHistory: sick_history,
  3122. Departments: department,
  3123. RegisterType: reg_type,
  3124. PrescriptionNumber: info.PrescriptionNumber,
  3125. Doctor: role.UserName,
  3126. PrescriptionStatus: info.PrescriptionStatus,
  3127. DoctorId: doctor_id,
  3128. SickType: sick_type,
  3129. PType: info.PType,
  3130. HisPatientId: info.HisPatientId,
  3131. PatientDiagnosis: patient_diagnose,
  3132. }
  3133. service.SavePatientPrescriptionInfo(hpInfo)
  3134. //创建步骤表
  3135. finish := models.XtDialysisFinish{
  3136. IsFinish: 1,
  3137. UserOrgId: adminInfo.CurrentOrgId,
  3138. Status: 1,
  3139. Ctime: time.Now().Unix(),
  3140. Mtime: 0,
  3141. Module: 4,
  3142. RecordDate: info.RecordDate,
  3143. Sourse: 1,
  3144. PatientId: info.PatientId,
  3145. }
  3146. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  3147. if dialysisFinish.ID == 0 {
  3148. service.CreateDialysisFinish(finish)
  3149. }
  3150. redis := service.RedisClient()
  3151. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3152. redis.Set(key, "", time.Second)
  3153. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3154. redis.Set(keyOne, "", time.Second)
  3155. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3156. redis.Set(keySeven, "", time.Second)
  3157. defer redis.Close()
  3158. }
  3159. //定义切片
  3160. var adviceList []models.HisDoctorAdviceInfo
  3161. var projectList []models.HisPrescriptionProject
  3162. 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 || adminInfo.CurrentOrgId == 10768 || adminInfo.CurrentOrgId == 10164 {
  3163. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3164. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3165. var tempPrescription *models.HisPrescription
  3166. if len(prescriptions) > 0 {
  3167. for _, item := range prescriptions {
  3168. // 开始外部循环的事务
  3169. tx := db.Begin()
  3170. // 在函数结束时处理事务回滚
  3171. defer func() {
  3172. if r := recover(); r != nil {
  3173. tx.Rollback()
  3174. }
  3175. }()
  3176. items := item.(map[string]interface{})
  3177. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3178. utils.ErrorLog("id")
  3179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3180. return
  3181. }
  3182. id := int64(items["id"].(float64))
  3183. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3184. tempPrescription = &new_prescription
  3185. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3186. utils.ErrorLog("type")
  3187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3188. return
  3189. }
  3190. types := int64(items["type"].(float64))
  3191. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3192. utils.ErrorLog("med_type")
  3193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3194. return
  3195. }
  3196. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3197. if med_type == "0" {
  3198. med_type = "14"
  3199. }
  3200. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3201. // utils.ErrorLog("diagnoses")
  3202. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3203. // return
  3204. //}
  3205. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3206. diagnoses, _ := items["diagnoses"].(string)
  3207. //if order_status == 0 {
  3208. // order_status = 1
  3209. //}
  3210. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3211. utils.ErrorLog("pre_time")
  3212. }
  3213. preTime, _ := items["pre_time"].(string)
  3214. fmt.Println("preTime", preTime)
  3215. timeLayout := "2006-01-02"
  3216. loc, _ := time.LoadLocation("Local")
  3217. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3218. //result := strings.Split(preTime, " ")
  3219. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3220. if err != nil {
  3221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3222. return
  3223. }
  3224. pTime := theTime2.Unix()
  3225. ctime := time.Now().Unix()
  3226. if tempPrescription.ID == 0 {
  3227. prescription := &models.HisPrescription{
  3228. ID: 0,
  3229. PatientId: patient_id,
  3230. UserOrgId: adminInfo.CurrentOrgId,
  3231. RecordDate: recordDateTime,
  3232. Ctime: ctime,
  3233. Mtime: ctime,
  3234. Type: types,
  3235. Modifier: adminInfo.AdminUser.Id,
  3236. Creator: adminInfo.AdminUser.Id,
  3237. Status: 1,
  3238. Doctor: role.UserName,
  3239. HisPatientId: his_patient_id,
  3240. OrderStatus: 1,
  3241. BatchNumber: "",
  3242. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3243. PreTime: pTime,
  3244. PType: p_type,
  3245. MedType: med_type,
  3246. Diagnose: diagnoses,
  3247. }
  3248. tempPrescription = prescription
  3249. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3250. redis := service.RedisClient()
  3251. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3252. redis.Set(key, "", time.Second)
  3253. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3254. redis.Set(keyOne, "", time.Second)
  3255. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3256. redis.Set(keySeven, "", time.Second)
  3257. defer redis.Close()
  3258. } else {
  3259. tempPrescription.ID = id
  3260. tempPrescription.Type = types
  3261. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3262. tempPrescription.Mtime = time.Now().Unix()
  3263. tempPrescription.Doctor = role.UserName
  3264. //tempPrescription.OrderStatus = order_status
  3265. tempPrescription.PreTime = pTime
  3266. tempPrescription.MedType = med_type
  3267. tempPrescription.Diagnose = diagnoses
  3268. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3269. redis := service.RedisClient()
  3270. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3271. redis.Set(key, "", time.Second)
  3272. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3273. redis.Set(keyOne, "", time.Second)
  3274. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3275. redis.Set(keySeven, "", time.Second)
  3276. defer redis.Close()
  3277. }
  3278. //service.SaveHisPrescription(prescription)
  3279. //更改患者挂号状态
  3280. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3281. fmt.Println("更改失败", err2)
  3282. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3283. advices := items["advices"].([]interface{})
  3284. groupNo := int64(0)
  3285. if len(advices) > 0 {
  3286. for _, advice := range advices {
  3287. tx := db.Begin()
  3288. // 在函数结束时处理事务回滚
  3289. defer func() {
  3290. if r := recover(); r != nil {
  3291. tx.Rollback()
  3292. }
  3293. }()
  3294. var s models.HisDoctorAdviceInfo
  3295. s.PrescriptionId = tempPrescription.ID
  3296. s.AdviceType = 2
  3297. s.AdviceDoctor = doctor_id
  3298. s.StopState = 2
  3299. s.ExecutionState = 2
  3300. s.AdviceDate = theTime3.Unix()
  3301. s.Status = 1
  3302. s.UserOrgId = adminInfo.CurrentOrgId
  3303. s.RecordDate = theTime3.Unix()
  3304. s.StartTime = tempPrescription.PreTime
  3305. s.Groupno = groupNo
  3306. s.PatientId = patient_id
  3307. s.HisPatientId = his_patient_id
  3308. s.StartTime = pTime
  3309. s.IsSettle = 2
  3310. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3311. if errcode > 0 {
  3312. c.ServeFailJSONWithSGJErrorCode(errcode)
  3313. return
  3314. }
  3315. s.StartTime = pTime
  3316. var total_count int64 //处方总库存
  3317. //查询改药品信息
  3318. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3319. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3320. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3321. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3322. total_count += prescribingNumberSeven * medical.MinNumber
  3323. }
  3324. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3325. total_count += prescribingNumberSeven
  3326. }
  3327. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3328. total_count += prescribingNumberSeven
  3329. }
  3330. //if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3331. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3332. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3333. // if s.Price != lastWarehouse.RetailPrice {
  3334. // s.Price = lastWarehouse.RetailPrice
  3335. // }
  3336. // if s.Price == 0 {
  3337. // if lastWarehouse.ID == 0 {
  3338. // lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3339. // s.Price = lastWarehouseTwo.RetailPrice
  3340. // }
  3341. //
  3342. // }
  3343. //}
  3344. //查询保存处方出库开关是否打开
  3345. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3346. if s.PatientId != 30038 {
  3347. if drugOutConfig.IsOpen == 1 {
  3348. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3349. // 查询该药品最后一次出库记录
  3350. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3351. var is_user_total int64
  3352. var no_user_total int64
  3353. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3354. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3355. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3356. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3357. }
  3358. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3359. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3360. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3361. no_user_total += prescribingNumberSevenTy
  3362. }
  3363. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3364. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3365. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3366. no_user_total += prescribingNumberSevenTy
  3367. }
  3368. if len(druginfo) > 0 {
  3369. for _, it := range druginfo {
  3370. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3371. it.Count = it.Count * drug.MinNumber
  3372. is_user_total += it.Count
  3373. }
  3374. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3375. is_user_total += it.Count
  3376. }
  3377. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3378. is_user_total += it.Count
  3379. }
  3380. }
  3381. }
  3382. //库存不足
  3383. if s.UserOrgId != 10206 {
  3384. //判断库存不足的地方
  3385. if s.ID == 0 {
  3386. //查询改药品是否已经停用
  3387. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3388. if base.ID > 0 {
  3389. tx.Rollback()
  3390. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3391. return
  3392. }
  3393. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3394. if drugMedical.SumCount == 0 {
  3395. tx.Rollback()
  3396. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3397. return
  3398. }
  3399. list, _ := service.GetLastDrugWarehouseInfoList(s.DrugId)
  3400. if len(list) == 0 {
  3401. tx.Rollback()
  3402. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3403. return
  3404. }
  3405. }
  3406. if s.ID > 0 {
  3407. //查询改药品是否已经停用
  3408. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3409. if base.ID > 0 {
  3410. tx.Rollback()
  3411. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3412. return
  3413. }
  3414. }
  3415. }
  3416. if is_user_total != no_user_total {
  3417. //出库
  3418. //针对御享天源
  3419. if drug.IsUse == 1 && s.UserOrgId == 10635 {
  3420. //查询改药品是否已经停用
  3421. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3422. if base.ID > 0 {
  3423. tx.Rollback()
  3424. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3425. return
  3426. }
  3427. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3428. if drugMedical.SumCount == 0 {
  3429. tx.Rollback()
  3430. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3431. return
  3432. }
  3433. creater := adminInfo.AdminUser.Id
  3434. newadviceInfo := &models.HisDoctorAdviceInfo{
  3435. ID: s.ID,
  3436. UserOrgId: s.UserOrgId,
  3437. PatientId: s.PatientId,
  3438. HisPatientId: s.HisPatientId,
  3439. AdviceType: s.AdviceType,
  3440. AdviceDate: s.AdviceDate,
  3441. StartTime: s.StartTime,
  3442. AdviceName: s.AdviceName,
  3443. AdviceDesc: s.AdviceDesc,
  3444. ReminderDate: s.ReminderDate,
  3445. SingleDose: s.SingleDose,
  3446. SingleDoseUnit: s.SingleDoseUnit,
  3447. PrescribingNumber: s.PrescribingNumber,
  3448. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3449. DeliveryWay: s.DeliveryWay,
  3450. ExecutionFrequency: s.ExecutionFrequency,
  3451. AdviceDoctor: s.AdviceDoctor,
  3452. Status: s.Status,
  3453. CreatedTime: s.CreatedTime,
  3454. UpdatedTime: s.UpdatedTime,
  3455. AdviceAffirm: s.AdviceAffirm,
  3456. Remark: s.Remark,
  3457. StopTime: s.StopTime,
  3458. StopReason: s.StopReason,
  3459. StopDoctor: s.StopDoctor,
  3460. StopState: s.StopState,
  3461. ParentId: s.ParentId,
  3462. ExecutionTime: s.ExecutionTime,
  3463. ExecutionStaff: s.ExecutionStaff,
  3464. ExecutionState: s.ExecutionState,
  3465. Checker: s.Checker,
  3466. RecordDate: s.RecordDate,
  3467. DialysisOrderId: s.DialysisOrderId,
  3468. CheckTime: s.CheckTime,
  3469. CheckState: s.CheckState,
  3470. DrugSpec: s.DrugSpec,
  3471. DrugSpecUnit: s.DrugSpecUnit,
  3472. Groupno: s.Groupno,
  3473. RemindType: s.RemindType,
  3474. FrequencyType: s.FrequencyType,
  3475. DayCount: s.DayCount,
  3476. WeekDay: s.WeekDay,
  3477. TemplateId: s.TemplateId,
  3478. Modifier: s.Modifier,
  3479. DrugId: s.DrugId,
  3480. Price: s.Price,
  3481. PrescriptionId: s.PrescriptionId,
  3482. MedListCodg: s.MedListCodg,
  3483. FeedetlSn: s.FeedetlSn,
  3484. Day: s.DayCount,
  3485. ChildDoctorAdvice: nil,
  3486. Drug: models.Drug{},
  3487. Diagnosis: s.Diagnosis,
  3488. Way: s.Way,
  3489. HospApprFlag: s.HospApprFlag,
  3490. LmtUsedFlag: s.LmtUsedFlag,
  3491. HisOrderInfo: models.HisOrderInfo{},
  3492. IsMedicine: s.IsMedicine,
  3493. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3494. Child: nil,
  3495. IsSettle: s.IsSettle,
  3496. IsMobile: s.IsMobile,
  3497. IsSelfDrug: s.IsSelfDrug,
  3498. DrugWayCount: s.DrugWayCount,
  3499. }
  3500. var history_count int64
  3501. var local_count int64
  3502. //查找已经开过的医嘱信息
  3503. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3504. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3505. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3506. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3507. local_count += prescribingNumberSevenTy * drug.MinNumber
  3508. }
  3509. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3510. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3511. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3512. local_count += prescribingNumberSevenTy
  3513. }
  3514. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3515. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3516. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3517. local_count += prescribingNumberSevenTy
  3518. }
  3519. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3520. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3521. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3522. history_count += prescribingNumberSevenTy * drug.MinNumber
  3523. }
  3524. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3525. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3526. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3527. history_count += prescribingNumberSevenTy
  3528. }
  3529. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3530. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3531. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3532. history_count += prescribingNumberSevenTy
  3533. }
  3534. //fmt.Println("local_count---------------", local_count)
  3535. //fmt.Println("history_count---------------", history_count)
  3536. //如果当前出库数量大于历史出库数量则需要出库
  3537. if local_count > history_count {
  3538. //按最小单位出库
  3539. var cha_count = local_count - history_count
  3540. newadviceInfo.PrescribingNumber = float64(cha_count)
  3541. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3542. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3543. }
  3544. //如果当前出库数量小于历史出库数量则需要退库
  3545. if local_count < history_count {
  3546. var cha_count = history_count - local_count
  3547. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3548. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3549. }
  3550. if local_count == history_count {
  3551. if is_user_total == 0 {
  3552. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3553. }
  3554. }
  3555. }
  3556. if drug.IsUse == 2 {
  3557. creater := adminInfo.AdminUser.Id
  3558. newadviceInfo := &models.HisDoctorAdviceInfo{
  3559. ID: s.ID,
  3560. UserOrgId: s.UserOrgId,
  3561. PatientId: s.PatientId,
  3562. HisPatientId: s.HisPatientId,
  3563. AdviceType: s.AdviceType,
  3564. AdviceDate: s.AdviceDate,
  3565. StartTime: s.StartTime,
  3566. AdviceName: s.AdviceName,
  3567. AdviceDesc: s.AdviceDesc,
  3568. ReminderDate: s.ReminderDate,
  3569. SingleDose: s.SingleDose,
  3570. SingleDoseUnit: s.SingleDoseUnit,
  3571. PrescribingNumber: s.PrescribingNumber,
  3572. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3573. DeliveryWay: s.DeliveryWay,
  3574. ExecutionFrequency: s.ExecutionFrequency,
  3575. AdviceDoctor: s.AdviceDoctor,
  3576. Status: s.Status,
  3577. CreatedTime: s.CreatedTime,
  3578. UpdatedTime: s.UpdatedTime,
  3579. AdviceAffirm: s.AdviceAffirm,
  3580. Remark: s.Remark,
  3581. StopTime: s.StopTime,
  3582. StopReason: s.StopReason,
  3583. StopDoctor: s.StopDoctor,
  3584. StopState: s.StopState,
  3585. ParentId: s.ParentId,
  3586. ExecutionTime: s.ExecutionTime,
  3587. ExecutionStaff: s.ExecutionStaff,
  3588. ExecutionState: s.ExecutionState,
  3589. Checker: s.Checker,
  3590. RecordDate: s.RecordDate,
  3591. DialysisOrderId: s.DialysisOrderId,
  3592. CheckTime: s.CheckTime,
  3593. CheckState: s.CheckState,
  3594. DrugSpec: s.DrugSpec,
  3595. DrugSpecUnit: s.DrugSpecUnit,
  3596. Groupno: s.Groupno,
  3597. RemindType: s.RemindType,
  3598. FrequencyType: s.FrequencyType,
  3599. DayCount: s.DayCount,
  3600. WeekDay: s.WeekDay,
  3601. TemplateId: s.TemplateId,
  3602. Modifier: s.Modifier,
  3603. DrugId: s.DrugId,
  3604. Price: s.Price,
  3605. PrescriptionId: s.PrescriptionId,
  3606. MedListCodg: s.MedListCodg,
  3607. FeedetlSn: s.FeedetlSn,
  3608. Day: s.DayCount,
  3609. ChildDoctorAdvice: nil,
  3610. Drug: models.Drug{},
  3611. Diagnosis: s.Diagnosis,
  3612. Way: s.Way,
  3613. HospApprFlag: s.HospApprFlag,
  3614. LmtUsedFlag: s.LmtUsedFlag,
  3615. HisOrderInfo: models.HisOrderInfo{},
  3616. IsMedicine: s.IsMedicine,
  3617. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3618. Child: nil,
  3619. IsSettle: s.IsSettle,
  3620. IsMobile: s.IsMobile,
  3621. IsSelfDrug: s.IsSelfDrug,
  3622. DrugWayCount: s.DrugWayCount,
  3623. }
  3624. var history_count int64
  3625. var local_count int64
  3626. //查找已经开过的医嘱信息
  3627. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3628. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3629. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3630. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3631. local_count += prescribingNumberSevenTy * drug.MinNumber
  3632. }
  3633. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3634. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3635. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3636. local_count += prescribingNumberSevenTy
  3637. }
  3638. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3639. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3640. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3641. local_count += prescribingNumberSevenTy
  3642. }
  3643. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3644. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3645. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3646. history_count += prescribingNumberSevenTy * drug.MinNumber
  3647. }
  3648. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3649. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3650. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3651. history_count += prescribingNumberSevenTy
  3652. }
  3653. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3654. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3655. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3656. history_count += prescribingNumberSevenTy
  3657. }
  3658. fmt.Println("local_count---------------", local_count)
  3659. fmt.Println("history_count---------------", history_count)
  3660. //如果当前出库数量大于历史出库数量则需要出库
  3661. if local_count > history_count {
  3662. //按最小单位出库
  3663. var cha_count = local_count - history_count
  3664. newadviceInfo.PrescribingNumber = float64(cha_count)
  3665. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3666. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3667. }
  3668. //如果当前出库数量小于历史出库数量则需要退库
  3669. if local_count < history_count {
  3670. var cha_count = history_count - local_count
  3671. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3672. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3673. }
  3674. if local_count == history_count {
  3675. if is_user_total == 0 {
  3676. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3677. }
  3678. }
  3679. }
  3680. //更新字典里面的库存
  3681. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3682. var sum_count int64
  3683. for _, its := range stockInfo {
  3684. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3685. if its.MaxUnit == baseDrug.MaxUnit {
  3686. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3687. }
  3688. sum_count += its.StockMaxNumber + its.StockMinNumber
  3689. }
  3690. //更新基础库存
  3691. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3692. //剩余库存
  3693. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3694. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3695. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3696. //创建医嘱
  3697. service.CreateHisDoctorAdviceOne(&s, tx)
  3698. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3699. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3700. if len(outInfoTwo) > 0 {
  3701. for _, item := range outInfoTwo {
  3702. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3703. }
  3704. }
  3705. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3706. if len(drugAutoDetail) > 0 {
  3707. for _, item := range drugAutoDetail {
  3708. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3709. }
  3710. }
  3711. }
  3712. }
  3713. }
  3714. //记录日志
  3715. byterequest, _ := json.Marshal(s)
  3716. adviceLog := models.XtDoctorAdviceLog{
  3717. UserOrgId: s.UserOrgId,
  3718. PatientId: s.PatientId,
  3719. AdminUserId: adminInfo.AdminUser.Id,
  3720. Module: 1,
  3721. ErrLog: string(byterequest),
  3722. Status: 1,
  3723. Ctime: time.Now().Unix(),
  3724. Mtime: 0,
  3725. Source: "电脑端新建his医嘱",
  3726. RecordDate: s.AdviceDate,
  3727. }
  3728. service.CreateDoctorAdviceLog(adviceLog)
  3729. //存储切片中
  3730. adviceList = append(adviceList, s)
  3731. redis := service.RedisClient()
  3732. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3733. redis.Set(key, "", time.Second)
  3734. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3735. redis.Set(keyOne, "", time.Second)
  3736. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3737. redis.Set(keySeven, "", time.Second)
  3738. var randNum int
  3739. randNum = rand.Intn(1000) + 1000
  3740. //timestamp := time.Now().Unix()
  3741. //tempTime := time.Unix(timestamp, 0)
  3742. //timeFormat := tempTime.Format("20060102150405")
  3743. s.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3744. //赤峰
  3745. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3746. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3747. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3748. if info.RetailPrice > 0 {
  3749. if s.DeliveryWay == "口服" {
  3750. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3751. s.Price = drug.RetailPrice
  3752. }
  3753. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3754. s.Price = info.RetailPrice
  3755. }
  3756. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3757. s.Price = info.RetailPrice
  3758. }
  3759. }
  3760. }
  3761. }
  3762. service.CreateHisDoctorAdviceOne(&s, tx)
  3763. tx.Commit()
  3764. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3765. redis.Set(keySix, "", time.Second)
  3766. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3767. redis.Set(keyFive, "", time.Second)
  3768. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3769. redis.Set(keyEight, "", time.Second)
  3770. defer redis.Close()
  3771. }
  3772. }
  3773. }
  3774. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3775. projects := items["project"].([]interface{})
  3776. if len(projects) > 0 {
  3777. for _, project := range projects {
  3778. tx := db.Begin()
  3779. // 在函数结束时处理事务回滚
  3780. defer func() {
  3781. if r := recover(); r != nil {
  3782. tx.Rollback()
  3783. }
  3784. }()
  3785. var p models.HisPrescriptionProject
  3786. p.PrescriptionId = tempPrescription.ID
  3787. p.PatientId = patient_id
  3788. p.RecordDate = theTime3.Unix()
  3789. p.Doctor = doctor_id
  3790. p.UserOrgId = adminInfo.CurrentOrgId
  3791. p.HisPatientId = his_patient_id
  3792. p.Status = 1
  3793. p.StartTime = pTime
  3794. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3795. if errcode > 0 {
  3796. tx.Rollback()
  3797. c.ServeFailJSONWithSGJErrorCode(errcode)
  3798. return
  3799. }
  3800. if p.ID == 0 {
  3801. p.IsOut = 2
  3802. }
  3803. if p.ID > 0 {
  3804. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3805. p.IsOut = projectDetail.IsOut
  3806. }
  3807. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3808. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3809. if p.Type == 3 {
  3810. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3811. if p.Price != lastWarehouse.PackingPrice {
  3812. p.Price = lastWarehouse.PackingPrice
  3813. }
  3814. if p.Price == 0 {
  3815. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3816. p.Price = lastWarehouseTwo.PackingPrice
  3817. }
  3818. if p.Unit == "" {
  3819. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3820. p.Unit = goodInfoOne.PackingUnit
  3821. }
  3822. }
  3823. }
  3824. if adminInfo.CurrentOrgId != 10206 {
  3825. if p.Type == 3 {
  3826. //判断耗材库存充不充足
  3827. if p.ID == 0 {
  3828. //查询该耗材是否停用
  3829. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3830. //表示该耗材已经停用,不能保存
  3831. if goodInfoSeven.ID == 0 {
  3832. tx.Rollback()
  3833. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3834. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3835. return
  3836. }
  3837. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3838. if goodInfoOne.SumCount == 0 {
  3839. tx.Rollback()
  3840. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3841. return
  3842. }
  3843. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3844. if len(goodListOne) == 0 {
  3845. tx.Rollback()
  3846. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3847. return
  3848. }
  3849. }
  3850. if p.ID > 0 {
  3851. //查询该耗材是否停用
  3852. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3853. //表示该耗材已经停用,不能保存
  3854. if goodInfoSeven.ID == 0 {
  3855. tx.Rollback()
  3856. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3857. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3858. return
  3859. }
  3860. //查询该耗材今日是否已经出过库
  3861. goodOutList, _ := service.GetGoodWareHouseOutInfoByGood(p.ProjectId, p.RecordDate, p.UserOrgId)
  3862. var his_count int64
  3863. if len(goodOutList) > 0 {
  3864. for _, item := range goodOutList {
  3865. his_count += item.Count
  3866. }
  3867. }
  3868. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3869. //如果当前的处方数量大于 历史出库数量 要判断库存够不够
  3870. if nowCount > his_count {
  3871. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3872. if goodInfoOne.SumCount == 0 {
  3873. tx.Rollback()
  3874. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3875. return
  3876. }
  3877. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3878. if len(goodListOne) == 0 {
  3879. tx.Rollback()
  3880. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3881. return
  3882. }
  3883. }
  3884. if len(goodOutList) == 0 {
  3885. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3886. if goodInfoOne.SumCount == 0 {
  3887. tx.Rollback()
  3888. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3889. return
  3890. }
  3891. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3892. if len(goodListOne) == 0 {
  3893. tx.Rollback()
  3894. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3895. return
  3896. }
  3897. }
  3898. }
  3899. }
  3900. }
  3901. //查询保存耗材出库开关是否打开
  3902. if p.PatientId != 30038 {
  3903. //用机构ID区分
  3904. if adminInfo.CurrentOrgId != 9671 {
  3905. if goodOutConfig.IsOpen == 1 {
  3906. //耗材出库
  3907. if p.Type == 3 {
  3908. //对比当前数据和历史出库数据
  3909. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3910. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3911. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3912. //如果当前处方数量大于历史数据,则需要出库
  3913. if nowCount > historyCount {
  3914. var cha_count int64
  3915. cha_count = nowCount - historyCount
  3916. timeStr := time.Now().Format("2006-01-02")
  3917. timeArr := strings.Split(timeStr, "-")
  3918. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3919. total = total + 1
  3920. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3921. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3922. number = number + total
  3923. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3924. operation_time := time.Now().Unix()
  3925. creater := c.GetAdminUserInfo().AdminUser.Id
  3926. recordDateStr := time.Now().Format("2006-01-02")
  3927. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3928. nowtime := recordDate.Unix()
  3929. warehouseOut := models.WarehouseOut{
  3930. WarehouseOutOrderNumber: warehousing_out_order,
  3931. OperationTime: operation_time,
  3932. OrgId: adminInfo.CurrentOrgId,
  3933. Creater: creater,
  3934. Ctime: time.Now().Unix(),
  3935. Status: 1,
  3936. WarehouseOutTime: nowtime,
  3937. Type: 1,
  3938. StorehouseId: storeConfig.StorehouseOutInfo,
  3939. IsCheck: 1,
  3940. IsSys: 1,
  3941. }
  3942. //查询是否生成出库单
  3943. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3944. if out.ID == 0 {
  3945. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3946. }
  3947. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3948. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3949. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3950. dialyPrepareOne := models.DialysisBeforePrepare{
  3951. GoodTypeId: goodObj.GoodTypeId,
  3952. GoodId: p.ProjectId,
  3953. PatientId: p.PatientId,
  3954. RecordDate: p.RecordDate,
  3955. UserOrgId: adminInfo.CurrentOrgId,
  3956. Count: cha_count,
  3957. Ctime: time.Now().Unix(),
  3958. Creater: creater,
  3959. Status: 1,
  3960. StorehouseId: houseConfig.StorehouseOutInfo,
  3961. ProjectId: p.ID,
  3962. }
  3963. //出库
  3964. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3965. }
  3966. //如果当前处方数量小于历史数据,怎需要退库
  3967. if nowCount < historyCount {
  3968. var cha_count int64
  3969. cha_count = historyCount - nowCount
  3970. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3971. creater := c.GetAdminUserInfo().AdminUser.Id
  3972. newPrescriptionProject := &models.HisPrescriptionProject{
  3973. ID: p.ID,
  3974. ProjectId: p.ProjectId,
  3975. Price: p.Price,
  3976. UserOrgId: p.UserOrgId,
  3977. Status: 1,
  3978. Ctime: time.Now().Unix(),
  3979. Mtime: time.Now().Unix(),
  3980. PatientId: p.PatientId,
  3981. HisPatientId: p.HisPatientId,
  3982. RecordDate: p.RecordDate,
  3983. PrescriptionId: p.PrescriptionId,
  3984. Count: p.Count,
  3985. FeedetlSn: p.FeedetlSn,
  3986. MedListCodg: p.MedListCodg,
  3987. SingleDose: p.SingleDose,
  3988. DeliveryWay: p.DeliveryWay,
  3989. ExecutionFrequency: p.ExecutionFrequency,
  3990. Day: p.Day,
  3991. HisProject: models.HisProject{},
  3992. GoodInfo: models.GoodInfo{},
  3993. Remark: p.Remark,
  3994. Unit: p.Unit,
  3995. Type: p.Type,
  3996. Doctor: p.Doctor,
  3997. ExecutionTime: p.ExecutionTime,
  3998. ExecutionStaff: p.ExecutionStaff,
  3999. ExecutionState: p.ExecutionState,
  4000. CheckTime: p.CheckTime,
  4001. CheckState: p.CheckState,
  4002. Checker: p.Checker,
  4003. StartTime: p.StartTime,
  4004. TeamId: p.TeamId,
  4005. XtHisProjectTeam: models.XtHisProjectTeam{},
  4006. FrequencyType: p.FrequencyType,
  4007. DayCount: p.DayCount,
  4008. WeekDay: p.WeekDay,
  4009. IsCheckTeam: p.IsCheckTeam,
  4010. HisOrderInfo: models.HisOrderInfo{},
  4011. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4012. IsOut: p.IsOut,
  4013. YbSyncStatus: p.YbSyncStatus,
  4014. }
  4015. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4016. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4017. }
  4018. if nowCount == historyCount {
  4019. if historyCount == 0 {
  4020. recordDateStr := time.Now().Format("2006-01-02")
  4021. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4022. nowtime := recordDate.Unix()
  4023. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4024. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4025. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4026. creater := c.GetAdminUserInfo().AdminUser.Id
  4027. dialyPrepareOne := models.DialysisBeforePrepare{
  4028. GoodTypeId: goodObj.GoodTypeId,
  4029. GoodId: p.ProjectId,
  4030. PatientId: p.PatientId,
  4031. RecordDate: p.RecordDate,
  4032. UserOrgId: adminInfo.CurrentOrgId,
  4033. Count: nowCount,
  4034. Ctime: time.Now().Unix(),
  4035. Creater: creater,
  4036. Status: 1,
  4037. StorehouseId: houseConfig.StorehouseOutInfo,
  4038. ProjectId: p.ID,
  4039. }
  4040. //出库
  4041. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4042. }
  4043. }
  4044. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4045. //查询历史出库数据
  4046. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4047. var out_count_five int64
  4048. for _, item := range flowGood {
  4049. out_count_five += item.Count
  4050. }
  4051. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4052. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4053. if out_count_five != parseIntCount {
  4054. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4055. detail := models.AutomaticReduceDetail{
  4056. WarehouseOutId: 0,
  4057. WarehouseOutOrderNumber: "",
  4058. PatientId: p.PatientId,
  4059. Ctime: time.Now().Unix(),
  4060. Mtime: 0,
  4061. Status: 1,
  4062. RecordTime: p.RecordDate,
  4063. OrgId: p.UserOrgId,
  4064. GoodId: p.ProjectId,
  4065. GoodTypeId: 0,
  4066. Count: parseIntCount,
  4067. Type: 0,
  4068. ProjectId: lastHisProject.ID,
  4069. StorehouseId: 0,
  4070. }
  4071. service.CreateNewAutoDetail(detail, tx)
  4072. }
  4073. // //查询耗材最后一次出库记录
  4074. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4075. // //查询默认出库仓库库存
  4076. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4077. // if len(wareOut) > 0 {
  4078. //
  4079. // for _, it := range wareOut {
  4080. // //回退库存
  4081. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4082. //
  4083. // //删除出库记录
  4084. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4085. //
  4086. // }
  4087. // }
  4088. //
  4089. // timeStr := time.Now().Format("2006-01-02")
  4090. // timeArr := strings.Split(timeStr, "-")
  4091. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4092. //
  4093. // total = total + 1
  4094. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4095. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4096. // number = number + total
  4097. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4098. //
  4099. // operation_time := time.Now().Unix()
  4100. // creater := c.GetAdminUserInfo().AdminUser.Id
  4101. //
  4102. // recordDateStr := time.Now().Format("2006-01-02")
  4103. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4104. // nowtime := recordDate.Unix()
  4105. // warehouseOut := models.WarehouseOut{
  4106. // WarehouseOutOrderNumber: warehousing_out_order,
  4107. // OperationTime: operation_time,
  4108. // OrgId: adminInfo.CurrentOrgId,
  4109. // Creater: creater,
  4110. // Ctime: time.Now().Unix(),
  4111. // Status: 1,
  4112. // WarehouseOutTime: nowtime,
  4113. // Type: 1,
  4114. // StorehouseId: storeConfig.StorehouseOutInfo,
  4115. // IsCheck: 1,
  4116. // IsSys: 1,
  4117. // }
  4118. // //查询是否生成出库单
  4119. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4120. // if out.ID == 0 {
  4121. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4122. // }
  4123. //
  4124. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4125. //
  4126. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4127. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4128. //
  4129. // dialyPrepareOne := models.DialysisBeforePrepare{
  4130. // GoodTypeId: goodObj.GoodTypeId,
  4131. // GoodId: p.ProjectId,
  4132. // PatientId: p.PatientId,
  4133. // RecordDate: p.RecordDate,
  4134. // UserOrgId: adminInfo.CurrentOrgId,
  4135. // Count: parseIntCount,
  4136. // Ctime: time.Now().Unix(),
  4137. // Creater: creater,
  4138. // Status: 1,
  4139. // StorehouseId: houseConfig.StorehouseOutInfo,
  4140. // ProjectId: lastHisProject.ID,
  4141. // }
  4142. // //判断是否是零用耗材(非零用)
  4143. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4144. //
  4145. // //查询历史出库数据
  4146. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4147. // var out_count int64
  4148. // for _, item := range flowGood {
  4149. // out_count += item.Count
  4150. // }
  4151. // //如果历史数和当前数据不想等才进行退库出库
  4152. // if out_count != parseIntCount {
  4153. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4154. //
  4155. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4156. // detail := models.AutomaticReduceDetail{
  4157. // WarehouseOutId: 0,
  4158. // WarehouseOutOrderNumber: "",
  4159. // PatientId: p.PatientId,
  4160. // Ctime: time.Now().Unix(),
  4161. // Mtime: 0,
  4162. // Status: 1,
  4163. // RecordTime: p.RecordDate,
  4164. // OrgId: p.UserOrgId,
  4165. // GoodId: p.ProjectId,
  4166. // GoodTypeId: 0,
  4167. // Count: parseIntCount,
  4168. // Type: 0,
  4169. // ProjectId: lastHisProject.ID,
  4170. // StorehouseId: 0,
  4171. // }
  4172. //
  4173. // service.CreateNewAutoDetail(detail, tx)
  4174. //
  4175. // //查询剩余库存
  4176. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4177. // var sum_count int64
  4178. // for _, item := range goodList {
  4179. // sum_count += item.StockCount
  4180. // }
  4181. //
  4182. // //更新剩余库存
  4183. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4184. //
  4185. // //耗材
  4186. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4187. //
  4188. // }
  4189. // //判断是否是零用耗材(零用但是是出库耗材)
  4190. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4191. //
  4192. // //查询历史出库数据
  4193. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4194. // var out_count int64
  4195. // for _, item := range flowGood {
  4196. // out_count += item.Count
  4197. // }
  4198. // //如果历史数和当前数据不想等才进行退库出库
  4199. // if out_count != parseIntCount {
  4200. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4201. //
  4202. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4203. // detail := models.AutomaticReduceDetail{
  4204. // WarehouseOutId: 0,
  4205. // WarehouseOutOrderNumber: "",
  4206. // PatientId: p.PatientId,
  4207. // Ctime: time.Now().Unix(),
  4208. // Mtime: 0,
  4209. // Status: 1,
  4210. // RecordTime: p.RecordDate,
  4211. // OrgId: p.UserOrgId,
  4212. // GoodId: p.ProjectId,
  4213. // GoodTypeId: 0,
  4214. // Count: parseIntCount,
  4215. // Type: 0,
  4216. // ProjectId: p.ID,
  4217. // StorehouseId: 0,
  4218. // }
  4219. //
  4220. // service.CreateNewAutoDetail(detail, tx)
  4221. //
  4222. // //查询剩余库存
  4223. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4224. // var sum_count int64
  4225. // for _, item := range goodList {
  4226. // sum_count += item.StockCount
  4227. // }
  4228. //
  4229. // //更新剩余库存
  4230. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4231. //
  4232. // //耗材
  4233. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4234. // }
  4235. //
  4236. // }
  4237. //
  4238. // }
  4239. //
  4240. //}
  4241. //记录日志
  4242. byterequest, _ := json.Marshal(p)
  4243. adviceLog := models.XtDoctorAdviceLog{
  4244. UserOrgId: p.UserOrgId,
  4245. PatientId: p.PatientId,
  4246. AdminUserId: adminInfo.AdminUser.Id,
  4247. Module: 1,
  4248. ErrLog: string(byterequest),
  4249. Status: 1,
  4250. Ctime: time.Now().Unix(),
  4251. Mtime: 0,
  4252. Source: "电脑端新建his项目",
  4253. RecordDate: p.RecordDate,
  4254. }
  4255. service.CreateDoctorAdviceLog(adviceLog)
  4256. projectList = append(projectList, p)
  4257. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4258. //新增或者编辑项目,修改对应的标签数据
  4259. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4260. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4261. var label models.HisLabelPrintInfo
  4262. project, _ := service.GetProjectDetail(p.ProjectId)
  4263. if project.CostClassify == 3 { //类别为检验检查
  4264. if p.TeamId > 0 { //检验检查组套
  4265. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4266. if tempLabel.ID == 0 {
  4267. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4268. label.Number = tempPrescription.PrescriptionNumber
  4269. label.ProjectId = project.ID
  4270. label.Status = 1
  4271. label.IsPrint = 2
  4272. label.DoctorId = info.DoctorId
  4273. label.UserOrgId = p.UserOrgId
  4274. label.PatientId = patient_id
  4275. label.RecordDate = recordDateTime
  4276. label.Ctime = time.Now().Unix()
  4277. label.Mtime = time.Now().Unix()
  4278. label.ItemId = p.TeamId
  4279. label.FeedetlSn = p.FeedetlSn
  4280. label.PProjectId = p.ID
  4281. label.ProjectName = team.ProjectTeam
  4282. label.PatientName = patient.Name
  4283. service.CreateNewHisLabelRecord(&label, tx)
  4284. }
  4285. } else { //单条检验检查项目
  4286. label.Number = tempPrescription.PrescriptionNumber
  4287. label.ProjectId = project.ID
  4288. label.Status = 1
  4289. label.DoctorId = info.DoctorId
  4290. label.UserOrgId = p.UserOrgId
  4291. label.PatientId = patient_id
  4292. label.RecordDate = recordDateTime
  4293. label.IsPrint = 2
  4294. label.Ctime = time.Now().Unix()
  4295. label.Mtime = time.Now().Unix()
  4296. label.FeedetlSn = p.FeedetlSn
  4297. label.PProjectId = p.ID
  4298. label.ItemId = p.TeamId
  4299. label.ProjectName = project.ProjectName
  4300. label.PatientName = patient.Name
  4301. service.CreateNewHisLabelRecord(&label, tx)
  4302. }
  4303. }
  4304. }
  4305. }
  4306. }
  4307. }
  4308. }
  4309. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  4310. //
  4311. // //耗材出库
  4312. // if p.Type == 3 {
  4313. //
  4314. // //对比当前数据和历史出库数据
  4315. //
  4316. // historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  4317. //
  4318. // historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  4319. //
  4320. // nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4321. //
  4322. // //如果当前处方数量大于历史数据,则需要出库
  4323. // if nowCount > historyCount {
  4324. //
  4325. // var cha_count int64
  4326. // cha_count = nowCount - historyCount
  4327. //
  4328. // timeStr := time.Now().Format("2006-01-02")
  4329. // timeArr := strings.Split(timeStr, "-")
  4330. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4331. //
  4332. // total = total + 1
  4333. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4334. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4335. // number = number + total
  4336. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4337. //
  4338. // operation_time := time.Now().Unix()
  4339. // creater := c.GetAdminUserInfo().AdminUser.Id
  4340. //
  4341. // recordDateStr := time.Now().Format("2006-01-02")
  4342. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4343. // nowtime := recordDate.Unix()
  4344. // warehouseOut := models.WarehouseOut{
  4345. // WarehouseOutOrderNumber: warehousing_out_order,
  4346. // OperationTime: operation_time,
  4347. // OrgId: adminInfo.CurrentOrgId,
  4348. // Creater: creater,
  4349. // Ctime: time.Now().Unix(),
  4350. // Status: 1,
  4351. // WarehouseOutTime: nowtime,
  4352. // Type: 1,
  4353. // StorehouseId: storeConfig.StorehouseOutInfo,
  4354. // IsCheck: 1,
  4355. // IsSys: 1,
  4356. // }
  4357. // //查询是否生成出库单
  4358. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4359. // if out.ID == 0 {
  4360. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4361. // }
  4362. //
  4363. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4364. //
  4365. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4366. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4367. //
  4368. // dialyPrepareOne := models.DialysisBeforePrepare{
  4369. // GoodTypeId: goodObj.GoodTypeId,
  4370. // GoodId: p.ProjectId,
  4371. // PatientId: p.PatientId,
  4372. // RecordDate: p.RecordDate,
  4373. // UserOrgId: adminInfo.CurrentOrgId,
  4374. // Count: cha_count,
  4375. // Ctime: time.Now().Unix(),
  4376. // Creater: creater,
  4377. // Status: 1,
  4378. // StorehouseId: houseConfig.StorehouseOutInfo,
  4379. // ProjectId: p.ID,
  4380. // }
  4381. // //出库
  4382. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4383. //
  4384. // }
  4385. //
  4386. // //如果当前处方数量小于历史数据,怎需要退库
  4387. // if nowCount < historyCount {
  4388. //
  4389. // var cha_count int64
  4390. // cha_count = historyCount - nowCount
  4391. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4392. // creater := c.GetAdminUserInfo().AdminUser.Id
  4393. //
  4394. // newPrescriptionProject := &models.HisPrescriptionProject{
  4395. // ID: p.ID,
  4396. // ProjectId: p.ProjectId,
  4397. // Price: p.Price,
  4398. // UserOrgId: p.UserOrgId,
  4399. // Status: 1,
  4400. // Ctime: time.Now().Unix(),
  4401. // Mtime: time.Now().Unix(),
  4402. // PatientId: p.PatientId,
  4403. // HisPatientId: p.HisPatientId,
  4404. // RecordDate: p.RecordDate,
  4405. // PrescriptionId: p.PrescriptionId,
  4406. // Count: p.Count,
  4407. // FeedetlSn: p.FeedetlSn,
  4408. // MedListCodg: p.MedListCodg,
  4409. // SingleDose: p.SingleDose,
  4410. // DeliveryWay: p.DeliveryWay,
  4411. // ExecutionFrequency: p.ExecutionFrequency,
  4412. // Day: p.Day,
  4413. // HisProject: models.HisProject{},
  4414. // GoodInfo: models.GoodInfo{},
  4415. // Remark: p.Remark,
  4416. // Unit: p.Unit,
  4417. // Type: p.Type,
  4418. // Doctor: p.Doctor,
  4419. // ExecutionTime: p.ExecutionTime,
  4420. // ExecutionStaff: p.ExecutionStaff,
  4421. // ExecutionState: p.ExecutionState,
  4422. // CheckTime: p.CheckTime,
  4423. // CheckState: p.CheckState,
  4424. // Checker: p.Checker,
  4425. // StartTime: p.StartTime,
  4426. // TeamId: p.TeamId,
  4427. // XtHisProjectTeam: models.XtHisProjectTeam{},
  4428. // FrequencyType: p.FrequencyType,
  4429. // DayCount: p.DayCount,
  4430. // WeekDay: p.WeekDay,
  4431. // IsCheckTeam: p.IsCheckTeam,
  4432. // HisOrderInfo: models.HisOrderInfo{},
  4433. // ExecutionFrequencyId: p.ExecutionFrequencyId,
  4434. // IsOut: p.IsOut,
  4435. // YbSyncStatus: p.YbSyncStatus,
  4436. // }
  4437. //
  4438. // service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4439. //
  4440. // service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4441. //
  4442. // }
  4443. //
  4444. // if nowCount == historyCount {
  4445. // if historyCount == 0 {
  4446. // recordDateStr := time.Now().Format("2006-01-02")
  4447. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4448. // nowtime := recordDate.Unix()
  4449. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4450. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4451. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4452. // creater := c.GetAdminUserInfo().AdminUser.Id
  4453. // dialyPrepareOne := models.DialysisBeforePrepare{
  4454. // GoodTypeId: goodObj.GoodTypeId,
  4455. // GoodId: p.ProjectId,
  4456. // PatientId: p.PatientId,
  4457. // RecordDate: p.RecordDate,
  4458. // UserOrgId: adminInfo.CurrentOrgId,
  4459. // Count: nowCount,
  4460. // Ctime: time.Now().Unix(),
  4461. // Creater: creater,
  4462. // Status: 1,
  4463. // StorehouseId: houseConfig.StorehouseOutInfo,
  4464. // ProjectId: p.ID,
  4465. // }
  4466. // //出库
  4467. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4468. // }
  4469. // }
  4470. //
  4471. // lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4472. // //查询历史出库数据
  4473. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4474. //
  4475. // var out_count_five int64
  4476. // for _, item := range flowGood {
  4477. // out_count_five += item.Count
  4478. // }
  4479. // parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4480. //
  4481. // //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4482. // if out_count_five != parseIntCount {
  4483. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4484. // detail := models.AutomaticReduceDetail{
  4485. // WarehouseOutId: 0,
  4486. // WarehouseOutOrderNumber: "",
  4487. // PatientId: p.PatientId,
  4488. // Ctime: time.Now().Unix(),
  4489. // Mtime: 0,
  4490. // Status: 1,
  4491. // RecordTime: p.RecordDate,
  4492. // OrgId: p.UserOrgId,
  4493. // GoodId: p.ProjectId,
  4494. // GoodTypeId: 0,
  4495. // Count: parseIntCount,
  4496. // Type: 0,
  4497. // ProjectId: lastHisProject.ID,
  4498. // StorehouseId: 0,
  4499. // }
  4500. //
  4501. // service.CreateNewAutoDetail(detail, tx)
  4502. // }
  4503. // // //查询耗材最后一次出库记录
  4504. // // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4505. // // //查询默认出库仓库库存
  4506. // // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4507. // // if len(wareOut) > 0 {
  4508. // //
  4509. // // for _, it := range wareOut {
  4510. // // //回退库存
  4511. // // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4512. // //
  4513. // // //删除出库记录
  4514. // // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4515. // //
  4516. // // }
  4517. // // }
  4518. // //
  4519. // // timeStr := time.Now().Format("2006-01-02")
  4520. // // timeArr := strings.Split(timeStr, "-")
  4521. // // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4522. // //
  4523. // // total = total + 1
  4524. // // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4525. // // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4526. // // number = number + total
  4527. // // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4528. // //
  4529. // // operation_time := time.Now().Unix()
  4530. // // creater := c.GetAdminUserInfo().AdminUser.Id
  4531. // //
  4532. // // recordDateStr := time.Now().Format("2006-01-02")
  4533. // // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4534. // // nowtime := recordDate.Unix()
  4535. // // warehouseOut := models.WarehouseOut{
  4536. // // WarehouseOutOrderNumber: warehousing_out_order,
  4537. // // OperationTime: operation_time,
  4538. // // OrgId: adminInfo.CurrentOrgId,
  4539. // // Creater: creater,
  4540. // // Ctime: time.Now().Unix(),
  4541. // // Status: 1,
  4542. // // WarehouseOutTime: nowtime,
  4543. // // Type: 1,
  4544. // // StorehouseId: storeConfig.StorehouseOutInfo,
  4545. // // IsCheck: 1,
  4546. // // IsSys: 1,
  4547. // // }
  4548. // // //查询是否生成出库单
  4549. // // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4550. // // if out.ID == 0 {
  4551. // // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4552. // // }
  4553. // //
  4554. // // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4555. // //
  4556. // // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4557. // // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4558. // //
  4559. // // dialyPrepareOne := models.DialysisBeforePrepare{
  4560. // // GoodTypeId: goodObj.GoodTypeId,
  4561. // // GoodId: p.ProjectId,
  4562. // // PatientId: p.PatientId,
  4563. // // RecordDate: p.RecordDate,
  4564. // // UserOrgId: adminInfo.CurrentOrgId,
  4565. // // Count: parseIntCount,
  4566. // // Ctime: time.Now().Unix(),
  4567. // // Creater: creater,
  4568. // // Status: 1,
  4569. // // StorehouseId: houseConfig.StorehouseOutInfo,
  4570. // // ProjectId: lastHisProject.ID,
  4571. // // }
  4572. // // //判断是否是零用耗材(非零用)
  4573. // // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4574. // //
  4575. // // //查询历史出库数据
  4576. // // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4577. // // var out_count int64
  4578. // // for _, item := range flowGood {
  4579. // // out_count += item.Count
  4580. // // }
  4581. // // //如果历史数和当前数据不想等才进行退库出库
  4582. // // if out_count != parseIntCount {
  4583. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4584. // //
  4585. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4586. // // detail := models.AutomaticReduceDetail{
  4587. // // WarehouseOutId: 0,
  4588. // // WarehouseOutOrderNumber: "",
  4589. // // PatientId: p.PatientId,
  4590. // // Ctime: time.Now().Unix(),
  4591. // // Mtime: 0,
  4592. // // Status: 1,
  4593. // // RecordTime: p.RecordDate,
  4594. // // OrgId: p.UserOrgId,
  4595. // // GoodId: p.ProjectId,
  4596. // // GoodTypeId: 0,
  4597. // // Count: parseIntCount,
  4598. // // Type: 0,
  4599. // // ProjectId: lastHisProject.ID,
  4600. // // StorehouseId: 0,
  4601. // // }
  4602. // //
  4603. // // service.CreateNewAutoDetail(detail, tx)
  4604. // //
  4605. // // //查询剩余库存
  4606. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4607. // // var sum_count int64
  4608. // // for _, item := range goodList {
  4609. // // sum_count += item.StockCount
  4610. // // }
  4611. // //
  4612. // // //更新剩余库存
  4613. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4614. // //
  4615. // // //耗材
  4616. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4617. // //
  4618. // // }
  4619. // // //判断是否是零用耗材(零用但是是出库耗材)
  4620. // // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4621. // //
  4622. // // //查询历史出库数据
  4623. // // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4624. // // var out_count int64
  4625. // // for _, item := range flowGood {
  4626. // // out_count += item.Count
  4627. // // }
  4628. // // //如果历史数和当前数据不想等才进行退库出库
  4629. // // if out_count != parseIntCount {
  4630. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4631. // //
  4632. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4633. // // detail := models.AutomaticReduceDetail{
  4634. // // WarehouseOutId: 0,
  4635. // // WarehouseOutOrderNumber: "",
  4636. // // PatientId: p.PatientId,
  4637. // // Ctime: time.Now().Unix(),
  4638. // // Mtime: 0,
  4639. // // Status: 1,
  4640. // // RecordTime: p.RecordDate,
  4641. // // OrgId: p.UserOrgId,
  4642. // // GoodId: p.ProjectId,
  4643. // // GoodTypeId: 0,
  4644. // // Count: parseIntCount,
  4645. // // Type: 0,
  4646. // // ProjectId: p.ID,
  4647. // // StorehouseId: 0,
  4648. // // }
  4649. // //
  4650. // // service.CreateNewAutoDetail(detail, tx)
  4651. // //
  4652. // // //查询剩余库存
  4653. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4654. // // var sum_count int64
  4655. // // for _, item := range goodList {
  4656. // // sum_count += item.StockCount
  4657. // // }
  4658. // //
  4659. // // //更新剩余库存
  4660. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4661. // //
  4662. // // //耗材
  4663. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4664. // // }
  4665. // //
  4666. // // }
  4667. // //
  4668. // // }
  4669. // //
  4670. // //}
  4671. //
  4672. // //记录日志
  4673. // byterequest, _ := json.Marshal(p)
  4674. // adviceLog := models.XtDoctorAdviceLog{
  4675. // UserOrgId: p.UserOrgId,
  4676. // PatientId: p.PatientId,
  4677. // AdminUserId: adminInfo.AdminUser.Id,
  4678. // Module: 1,
  4679. // ErrLog: string(byterequest),
  4680. // Status: 1,
  4681. // Ctime: time.Now().Unix(),
  4682. // Mtime: 0,
  4683. // Source: "电脑端新建his项目",
  4684. // RecordDate: p.RecordDate,
  4685. // }
  4686. // service.CreateDoctorAdviceLog(adviceLog)
  4687. //
  4688. // projectList = append(projectList, p)
  4689. //
  4690. // if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4691. // //新增或者编辑项目,修改对应的标签数据
  4692. // labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4693. // if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4694. // var label models.HisLabelPrintInfo
  4695. // project, _ := service.GetProjectDetail(p.ProjectId)
  4696. // if project.CostClassify == 3 { //类别为检验检查
  4697. // if p.TeamId > 0 { //检验检查组套
  4698. // tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4699. // if tempLabel.ID == 0 {
  4700. // team, _ := service.GetProjectTeamDetail(p.TeamId)
  4701. // label.Number = tempPrescription.PrescriptionNumber
  4702. // label.ProjectId = project.ID
  4703. // label.Status = 1
  4704. // label.IsPrint = 2
  4705. // label.DoctorId = info.DoctorId
  4706. // label.UserOrgId = p.UserOrgId
  4707. // label.PatientId = patient_id
  4708. // label.RecordDate = recordDateTime
  4709. // label.Ctime = time.Now().Unix()
  4710. // label.Mtime = time.Now().Unix()
  4711. // label.ItemId = p.TeamId
  4712. // label.FeedetlSn = p.FeedetlSn
  4713. // label.PProjectId = p.ID
  4714. // label.ProjectName = team.ProjectTeam
  4715. // label.PatientName = patient.Name
  4716. // service.CreateNewHisLabelRecord(&label, tx)
  4717. // }
  4718. // } else { //单条检验检查项目
  4719. // label.Number = tempPrescription.PrescriptionNumber
  4720. // label.ProjectId = project.ID
  4721. // label.Status = 1
  4722. // label.DoctorId = info.DoctorId
  4723. // label.UserOrgId = p.UserOrgId
  4724. // label.PatientId = patient_id
  4725. // label.RecordDate = recordDateTime
  4726. // label.IsPrint = 2
  4727. // label.Ctime = time.Now().Unix()
  4728. // label.Mtime = time.Now().Unix()
  4729. // label.FeedetlSn = p.FeedetlSn
  4730. // label.PProjectId = p.ID
  4731. // label.ItemId = p.TeamId
  4732. // label.ProjectName = project.ProjectName
  4733. // label.PatientName = patient.Name
  4734. // service.CreateNewHisLabelRecord(&label, tx)
  4735. // }
  4736. // }
  4737. // }
  4738. // }
  4739. //
  4740. // }
  4741. //}
  4742. }
  4743. //插入检验数据
  4744. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4745. //新增或者编辑项目,修改对应的标签数据
  4746. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4747. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4748. var label models.HisLabelPrintInfo
  4749. project, _ := service.GetProjectDetail(p.ProjectId)
  4750. if project.CostClassify == 3 { //类别为检验检查
  4751. if p.TeamId > 0 { //检验检查组套
  4752. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4753. if tempLabel.ID == 0 {
  4754. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4755. label.Number = tempPrescription.PrescriptionNumber
  4756. label.ProjectId = project.ID
  4757. label.Status = 1
  4758. label.IsPrint = 2
  4759. label.DoctorId = info.DoctorId
  4760. label.UserOrgId = p.UserOrgId
  4761. label.PatientId = patient_id
  4762. label.RecordDate = recordDateTime
  4763. label.Ctime = time.Now().Unix()
  4764. label.Mtime = time.Now().Unix()
  4765. label.ItemId = p.TeamId
  4766. label.FeedetlSn = p.FeedetlSn
  4767. label.PProjectId = p.ID
  4768. label.ProjectName = team.ProjectTeam
  4769. label.PatientName = patient.Name
  4770. service.CreateHisLabelRecord(&label)
  4771. }
  4772. } else { //单条检验检查项目
  4773. label.Number = tempPrescription.PrescriptionNumber
  4774. label.ProjectId = project.ID
  4775. label.Status = 1
  4776. label.DoctorId = info.DoctorId
  4777. label.UserOrgId = p.UserOrgId
  4778. label.PatientId = patient_id
  4779. label.RecordDate = recordDateTime
  4780. label.IsPrint = 2
  4781. label.Ctime = time.Now().Unix()
  4782. label.Mtime = time.Now().Unix()
  4783. label.FeedetlSn = p.FeedetlSn
  4784. label.PProjectId = p.ID
  4785. label.ItemId = p.TeamId
  4786. label.ProjectName = project.ProjectName
  4787. label.PatientName = patient.Name
  4788. service.CreateHisLabelRecord(&label)
  4789. }
  4790. }
  4791. }
  4792. }
  4793. service.CreateNewHisProjectTwo(&p, tx)
  4794. var randNum int
  4795. randNum = rand.Intn(1000) + 1000
  4796. p.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4797. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4798. if goodBase.ID > 0 {
  4799. tx.Rollback()
  4800. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4801. return
  4802. }
  4803. service.CreateNewHisProjectTwo(&p, tx)
  4804. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4805. //查询剩余库存
  4806. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4807. var sum_count int64
  4808. for _, item := range goodList {
  4809. sum_count += item.StockCount
  4810. }
  4811. //更新剩余库存
  4812. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4813. //耗材
  4814. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4815. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4816. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4817. if len(outInfoTwo) > 0 {
  4818. for _, item := range outInfoTwo {
  4819. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4820. }
  4821. }
  4822. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4823. if len(drugAutoDetail) > 0 {
  4824. for _, item := range drugAutoDetail {
  4825. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4826. }
  4827. }
  4828. tx.Commit()
  4829. }
  4830. }
  4831. }
  4832. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4833. // addition := items["addition"].([]interface{})
  4834. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4835. // ctime := time.Now().Unix()
  4836. // mtime := ctime
  4837. // if len(addition) > 0 {
  4838. // for _, item := range addition {
  4839. // var s models.HisAdditionalCharge
  4840. // s.PrescriptionId = tempPrescription.ID
  4841. // s.Status = 1
  4842. // s.UserOrgId = adminInfo.CurrentOrgId
  4843. // s.RecordDate = recordDateTime
  4844. // s.CreatedTime = ctime
  4845. // s.UpdatedTime = mtime
  4846. // s.PatientId = patient_id
  4847. // s.HisPatientId = his_patient_id
  4848. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4849. // if errcode > 0 {
  4850. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4851. // return
  4852. // }
  4853. // service.CreateAdditionalCharge(&s)
  4854. // var randNum int
  4855. // randNum = rand.Intn(10000) + 1000
  4856. // timestamp := time.Now().Unix()
  4857. // tempTime := time.Unix(timestamp, 0)
  4858. // timeFormat := tempTime.Format("20060102150405")
  4859. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4860. // service.CreateAdditionalCharge(&s)
  4861. //
  4862. // }
  4863. // }
  4864. //}
  4865. }
  4866. }
  4867. }
  4868. tx.Commit()
  4869. if err == nil {
  4870. c.ServeSuccessJSON(map[string]interface{}{
  4871. "msg": "保存成功",
  4872. })
  4873. return
  4874. } else {
  4875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4876. return
  4877. }
  4878. } else {
  4879. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4880. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4881. var tempPrescription *models.HisPrescription
  4882. if len(prescriptions) > 0 {
  4883. for _, item := range prescriptions {
  4884. items := item.(map[string]interface{})
  4885. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4886. utils.ErrorLog("id")
  4887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4888. return
  4889. }
  4890. id := int64(items["id"].(float64))
  4891. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4892. tempPrescription = &new_prescription
  4893. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4894. utils.ErrorLog("type")
  4895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4896. return
  4897. }
  4898. types := int64(items["type"].(float64))
  4899. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4900. utils.ErrorLog("med_type")
  4901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4902. return
  4903. }
  4904. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4905. if med_type == "0" {
  4906. med_type = "14"
  4907. }
  4908. //if order_status == 0 {
  4909. // order_status = 1
  4910. //}
  4911. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4912. // utils.ErrorLog("diagnoses")
  4913. //}
  4914. diagnoses, _ := items["diagnoses"].(string)
  4915. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4916. utils.ErrorLog("pre_time")
  4917. }
  4918. preTime, _ := items["pre_time"].(string)
  4919. timeLayout := "2006-01-02"
  4920. loc, _ := time.LoadLocation("Local")
  4921. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4922. //result := strings.Split(preTime, " ")
  4923. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4924. if err != nil {
  4925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4926. return
  4927. }
  4928. pTime := theTime2.Unix()
  4929. ctime := time.Now().Unix()
  4930. if tempPrescription.ID == 0 {
  4931. prescription := &models.HisPrescription{
  4932. ID: 0,
  4933. PatientId: patient_id,
  4934. UserOrgId: adminInfo.CurrentOrgId,
  4935. RecordDate: recordDateTime,
  4936. Ctime: ctime,
  4937. Mtime: ctime,
  4938. Type: types,
  4939. Modifier: adminInfo.AdminUser.Id,
  4940. Creator: adminInfo.AdminUser.Id,
  4941. Status: 1,
  4942. Doctor: role.UserName,
  4943. HisPatientId: his_patient_id,
  4944. OrderStatus: 1,
  4945. BatchNumber: "",
  4946. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4947. PreTime: pTime,
  4948. PType: p_type,
  4949. MedType: med_type,
  4950. Diagnose: diagnoses,
  4951. }
  4952. tempPrescription = prescription
  4953. service.SaveHisPrescription(tempPrescription)
  4954. redis := service.RedisClient()
  4955. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4956. redis.Set(key, "", time.Second)
  4957. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4958. redis.Set(keyOne, "", time.Second)
  4959. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4960. redis.Set(keySeven, "", time.Second)
  4961. defer redis.Close()
  4962. } else {
  4963. tempPrescription.ID = id
  4964. tempPrescription.Type = types
  4965. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4966. tempPrescription.Mtime = time.Now().Unix()
  4967. tempPrescription.Doctor = role.UserName
  4968. //tempPrescription.OrderStatus = order_status
  4969. tempPrescription.PreTime = pTime
  4970. tempPrescription.MedType = med_type
  4971. tempPrescription.Diagnose = diagnoses
  4972. service.SaveHisPrescription(tempPrescription)
  4973. redis := service.RedisClient()
  4974. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4975. redis.Set(key, "", time.Second)
  4976. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4977. redis.Set(keyOne, "", time.Second)
  4978. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4979. redis.Set(keySeven, "", time.Second)
  4980. defer redis.Close()
  4981. }
  4982. //service.SaveHisPrescription(prescription)
  4983. //更改患者挂号状态
  4984. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4985. fmt.Println("更改失败", err2)
  4986. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4987. advices := items["advices"].([]interface{})
  4988. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4989. groupNo := int64(0)
  4990. if len(advices) > 0 {
  4991. for _, advice := range advices {
  4992. var s models.HisDoctorAdviceInfo
  4993. s.PrescriptionId = tempPrescription.ID
  4994. s.AdviceType = 2
  4995. s.AdviceDoctor = doctor_id
  4996. s.StopState = 2
  4997. s.ExecutionState = 2
  4998. s.AdviceDate = theTime3.Unix()
  4999. s.Status = 1
  5000. s.UserOrgId = adminInfo.CurrentOrgId
  5001. s.RecordDate = theTime3.Unix()
  5002. s.StartTime = tempPrescription.PreTime
  5003. s.Groupno = groupNo
  5004. s.PatientId = patient_id
  5005. s.HisPatientId = his_patient_id
  5006. s.StartTime = pTime
  5007. s.IsSettle = 2
  5008. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  5009. if errcode > 0 {
  5010. c.ServeFailJSONWithSGJErrorCode(errcode)
  5011. return
  5012. }
  5013. s.StartTime = pTime
  5014. var total_count int64 //处方总库存
  5015. //查询改药品信息
  5016. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  5017. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  5018. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5019. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5020. total_count += prescribingNumberSeven * medical.MinNumber
  5021. }
  5022. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5023. total_count += prescribingNumberSeven
  5024. }
  5025. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  5026. total_count += prescribingNumberSeven
  5027. }
  5028. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5029. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5030. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5031. if s.Price != lastWarehouse.RetailPrice {
  5032. s.Price = lastWarehouse.RetailPrice
  5033. }
  5034. if s.Price == 0 {
  5035. if lastWarehouse.ID == 0 {
  5036. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  5037. s.Price = lastWarehouseTwo.RetailPrice
  5038. }
  5039. }
  5040. }
  5041. if adminInfo.CurrentOrgId != 10206 {
  5042. if s.ID == 0 {
  5043. //查询改药品是否已经停用
  5044. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  5045. if base.ID > 0 {
  5046. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  5047. return
  5048. }
  5049. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  5050. if drugMedical.SumCount == 0 {
  5051. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  5052. return
  5053. }
  5054. }
  5055. }
  5056. //赤峰
  5057. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  5058. drug, _ := service.GetDrugByGoodId(s.DrugId)
  5059. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  5060. if info.RetailPrice > 0 {
  5061. if s.DeliveryWay == "口服" {
  5062. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5063. s.Price = drug.RetailPrice
  5064. }
  5065. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5066. s.Price = info.RetailPrice
  5067. }
  5068. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5069. s.Price = info.RetailPrice
  5070. }
  5071. }
  5072. }
  5073. }
  5074. service.CreateHisDoctorAdvice(&s)
  5075. //记录日志
  5076. byterequest, _ := json.Marshal(s)
  5077. adviceLog := models.XtDoctorAdviceLog{
  5078. UserOrgId: s.UserOrgId,
  5079. PatientId: s.PatientId,
  5080. AdminUserId: adminInfo.AdminUser.Id,
  5081. Module: 1,
  5082. ErrLog: string(byterequest),
  5083. Status: 1,
  5084. Ctime: time.Now().Unix(),
  5085. Mtime: 0,
  5086. Source: "电脑端新建his医嘱",
  5087. RecordDate: s.AdviceDate,
  5088. }
  5089. service.CreateDoctorAdviceLog(adviceLog)
  5090. //存储切片中
  5091. adviceList = append(adviceList, s)
  5092. redis := service.RedisClient()
  5093. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5094. redis.Set(key, "", time.Second)
  5095. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5096. redis.Set(keyOne, "", time.Second)
  5097. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5098. redis.Set(keySeven, "", time.Second)
  5099. var randNum int
  5100. randNum = rand.Intn(1000) + 1000
  5101. //timestamp := time.Now().Unix()
  5102. //tempTime := time.Unix(timestamp, 0)
  5103. //timeFormat := tempTime.Format("20060102150405")
  5104. s.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  5105. service.CreateHisDoctorAdvice(&s)
  5106. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5107. redis.Set(keySix, "", time.Second)
  5108. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5109. redis.Set(keyFive, "", time.Second)
  5110. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5111. redis.Set(keyEight, "", time.Second)
  5112. defer redis.Close()
  5113. }
  5114. }
  5115. }
  5116. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5117. projects := items["project"].([]interface{})
  5118. if len(projects) > 0 {
  5119. for _, project := range projects {
  5120. var p models.HisPrescriptionProject
  5121. p.PrescriptionId = tempPrescription.ID
  5122. p.PatientId = patient_id
  5123. p.RecordDate = theTime3.Unix()
  5124. p.Doctor = doctor_id
  5125. p.UserOrgId = adminInfo.CurrentOrgId
  5126. p.HisPatientId = his_patient_id
  5127. p.Status = 1
  5128. p.StartTime = pTime
  5129. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  5130. if errcode > 0 {
  5131. c.ServeFailJSONWithSGJErrorCode(errcode)
  5132. return
  5133. }
  5134. if p.ID == 0 {
  5135. p.IsOut = 2
  5136. }
  5137. if p.ID > 0 {
  5138. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  5139. p.IsOut = projectDetail.IsOut
  5140. }
  5141. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5142. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5143. if p.Type == 3 {
  5144. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  5145. if p.Price != lastWarehouse.PackingPrice {
  5146. p.Price = lastWarehouse.PackingPrice
  5147. }
  5148. if p.Price == 0 {
  5149. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  5150. p.Price = lastWarehouseTwo.PackingPrice
  5151. }
  5152. if p.Unit == "" {
  5153. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5154. p.Unit = goodInfoOne.PackingUnit
  5155. }
  5156. }
  5157. }
  5158. if adminInfo.CurrentOrgId != 10206 {
  5159. if p.Type == 3 {
  5160. if p.ID == 0 {
  5161. //查询该耗材是否停用
  5162. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  5163. //表示该耗材已经停用,不能保存
  5164. if goodInfoSeven.ID == 0 {
  5165. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5166. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  5167. return
  5168. }
  5169. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5170. if goodInfoOne.SumCount == 0 {
  5171. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  5172. return
  5173. }
  5174. }
  5175. }
  5176. }
  5177. service.CreateHisProjectTwo(&p)
  5178. //记录日志
  5179. byterequest, _ := json.Marshal(p)
  5180. adviceLog := models.XtDoctorAdviceLog{
  5181. UserOrgId: p.UserOrgId,
  5182. PatientId: p.PatientId,
  5183. AdminUserId: adminInfo.AdminUser.Id,
  5184. Module: 1,
  5185. ErrLog: string(byterequest),
  5186. Status: 1,
  5187. Ctime: time.Now().Unix(),
  5188. Mtime: 0,
  5189. Source: "电脑端新建his项目",
  5190. RecordDate: p.RecordDate,
  5191. }
  5192. service.CreateDoctorAdviceLog(adviceLog)
  5193. projectList = append(projectList, p)
  5194. var randNum int
  5195. randNum = rand.Intn(1000) + 1000
  5196. p.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  5197. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  5198. //新增或者编辑项目,修改对应的标签数据
  5199. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  5200. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  5201. var label models.HisLabelPrintInfo
  5202. project, _ := service.GetProjectDetail(p.ProjectId)
  5203. if project.CostClassify == 3 { //类别为检验检查
  5204. if p.TeamId > 0 { //检验检查组套
  5205. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  5206. if tempLabel.ID == 0 {
  5207. team, _ := service.GetProjectTeamDetail(p.TeamId)
  5208. label.Number = tempPrescription.PrescriptionNumber
  5209. label.ProjectId = project.ID
  5210. label.Status = 1
  5211. label.IsPrint = 2
  5212. label.DoctorId = info.DoctorId
  5213. label.UserOrgId = p.UserOrgId
  5214. label.PatientId = patient_id
  5215. label.RecordDate = recordDateTime
  5216. label.Ctime = time.Now().Unix()
  5217. label.Mtime = time.Now().Unix()
  5218. label.ItemId = p.TeamId
  5219. label.FeedetlSn = p.FeedetlSn
  5220. label.PProjectId = p.ID
  5221. label.ProjectName = team.ProjectTeam
  5222. label.PatientName = patient.Name
  5223. service.CreateHisLabelRecord(&label)
  5224. }
  5225. } else { //单条检验检查项目
  5226. label.Number = tempPrescription.PrescriptionNumber
  5227. label.ProjectId = project.ID
  5228. label.Status = 1
  5229. label.DoctorId = info.DoctorId
  5230. label.UserOrgId = p.UserOrgId
  5231. label.PatientId = patient_id
  5232. label.RecordDate = recordDateTime
  5233. label.IsPrint = 2
  5234. label.Ctime = time.Now().Unix()
  5235. label.Mtime = time.Now().Unix()
  5236. label.FeedetlSn = p.FeedetlSn
  5237. label.PProjectId = p.ID
  5238. label.ItemId = p.TeamId
  5239. label.ProjectName = project.ProjectName
  5240. label.PatientName = patient.Name
  5241. service.CreateHisLabelRecord(&label)
  5242. }
  5243. }
  5244. }
  5245. }
  5246. service.SaveHisProjectTwo(&p)
  5247. }
  5248. }
  5249. }
  5250. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5251. // addition := items["addition"].([]interface{})
  5252. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5253. // ctime := time.Now().Unix()
  5254. // mtime := ctime
  5255. // if len(addition) > 0 {
  5256. // for _, item := range addition {
  5257. // var s models.HisAdditionalCharge
  5258. // s.PrescriptionId = tempPrescription.ID
  5259. // s.Status = 1
  5260. // s.UserOrgId = adminInfo.CurrentOrgId
  5261. // s.RecordDate = recordDateTime
  5262. // s.CreatedTime = ctime
  5263. // s.UpdatedTime = mtime
  5264. // s.PatientId = patient_id
  5265. // s.HisPatientId = his_patient_id
  5266. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5267. // if errcode > 0 {
  5268. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5269. // return
  5270. // }
  5271. // service.CreateAdditionalCharge(&s)
  5272. // var randNum int
  5273. // randNum = rand.Intn(10000) + 1000
  5274. // timestamp := time.Now().Unix()
  5275. // tempTime := time.Unix(timestamp, 0)
  5276. // timeFormat := tempTime.Format("20060102150405")
  5277. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  5278. // service.CreateAdditionalCharge(&s)
  5279. //
  5280. // }
  5281. // }
  5282. //}
  5283. }
  5284. }
  5285. //查询今日该患者开的药品处方
  5286. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5287. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  5288. //药品出库
  5289. if drugOutConfig.IsOpen == 1 {
  5290. for _, item := range hisdoctorlist {
  5291. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  5292. // 查询该药品最后一次出库记录
  5293. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  5294. if len(druginfo) > 0 {
  5295. //回退库存
  5296. for _, it := range druginfo {
  5297. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5298. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5299. }
  5300. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5301. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5302. }
  5303. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5304. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5305. }
  5306. }
  5307. }
  5308. //删除记录
  5309. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  5310. //查询最后一次数据
  5311. if drugOutConfig.IsOpen == 1 {
  5312. //出库
  5313. if drug.IsUse == 2 {
  5314. creater := adminInfo.AdminUser.Id
  5315. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  5316. }
  5317. //更新字典里面的库存
  5318. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5319. var sum_count int64
  5320. for _, its := range stockInfo {
  5321. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5322. if its.MaxUnit == baseDrug.MaxUnit {
  5323. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5324. }
  5325. sum_count += its.StockMaxNumber + its.StockMinNumber
  5326. }
  5327. //更新基础库存
  5328. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5329. //剩余库存
  5330. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  5331. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  5332. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  5333. }
  5334. }
  5335. }
  5336. //耗材保存处方出库
  5337. if goodOutConfig.IsOpen == 1 {
  5338. //查询今日耗材出库数量
  5339. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5340. for _, item := range hisgoodlist {
  5341. //查询历史出库数据
  5342. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5343. var out_count_five int64
  5344. for _, item := range flowGood {
  5345. out_count_five += item.Count
  5346. }
  5347. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  5348. if out_count_five != parseIntCount {
  5349. //查询耗材最后一次出库记录
  5350. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  5351. //查询默认出库仓库库存
  5352. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5353. if len(wareOut) > 0 {
  5354. for _, it := range wareOut {
  5355. //回退库存
  5356. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  5357. //删除出库记录
  5358. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  5359. }
  5360. }
  5361. timeStr := time.Now().Format("2006-01-02")
  5362. timeArr := strings.Split(timeStr, "-")
  5363. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  5364. total = total + 1
  5365. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5366. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5367. number = number + total
  5368. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5369. operation_time := time.Now().Unix()
  5370. creater := c.GetAdminUserInfo().AdminUser.Id
  5371. recordDateStr := time.Now().Format("2006-01-02")
  5372. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5373. nowtime := recordDate.Unix()
  5374. warehouseOut := models.WarehouseOut{
  5375. WarehouseOutOrderNumber: warehousing_out_order,
  5376. OperationTime: operation_time,
  5377. OrgId: adminInfo.CurrentOrgId,
  5378. Creater: creater,
  5379. Ctime: time.Now().Unix(),
  5380. Status: 1,
  5381. WarehouseOutTime: nowtime,
  5382. Type: 1,
  5383. StorehouseId: storeConfig.StorehouseOutInfo,
  5384. IsCheck: 1,
  5385. IsSys: 1,
  5386. }
  5387. //查询是否生成出库单
  5388. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5389. if out.ID == 0 {
  5390. service.AddSigleWarehouseOutOne(&warehouseOut)
  5391. }
  5392. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5393. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5394. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5395. dialyPrepareOne := models.DialysisBeforePrepare{
  5396. GoodTypeId: goodObj.GoodTypeId,
  5397. GoodId: item.ProjectId,
  5398. PatientId: item.PatientId,
  5399. RecordDate: item.RecordDate,
  5400. UserOrgId: adminInfo.CurrentOrgId,
  5401. Count: parseIntCount,
  5402. Ctime: time.Now().Unix(),
  5403. Creater: creater,
  5404. Status: 1,
  5405. StorehouseId: houseConfig.StorehouseOutInfo,
  5406. ProjectId: item.ID,
  5407. }
  5408. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5409. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5410. //查询历史出库数据
  5411. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5412. var out_count int64
  5413. for _, item := range flowGood {
  5414. out_count += item.Count
  5415. }
  5416. //如果历史数和当前数据不想等才进行退库出库
  5417. if out_count != parseIntCount {
  5418. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5419. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5420. detail := models.AutomaticReduceDetail{
  5421. WarehouseOutId: 0,
  5422. WarehouseOutOrderNumber: "",
  5423. PatientId: item.PatientId,
  5424. Ctime: time.Now().Unix(),
  5425. Mtime: 0,
  5426. Status: 1,
  5427. RecordTime: item.RecordDate,
  5428. OrgId: item.UserOrgId,
  5429. GoodId: item.ProjectId,
  5430. GoodTypeId: 0,
  5431. Count: parseIntCount,
  5432. Type: 0,
  5433. ProjectId: item.ID,
  5434. StorehouseId: 0,
  5435. }
  5436. service.CreateAutoDetail(detail)
  5437. //查询剩余库存
  5438. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5439. var sum_count int64
  5440. for _, item := range goodList {
  5441. sum_count += item.StockCount
  5442. }
  5443. //更新剩余库存
  5444. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5445. //耗材
  5446. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5447. }
  5448. }
  5449. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5450. //查询历史出库数据
  5451. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5452. var out_count int64
  5453. for _, item := range flowGood {
  5454. out_count += item.Count
  5455. }
  5456. //如果历史数和当前数据不想等才进行退库出库
  5457. if out_count != parseIntCount {
  5458. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5459. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5460. detail := models.AutomaticReduceDetail{
  5461. WarehouseOutId: 0,
  5462. WarehouseOutOrderNumber: "",
  5463. PatientId: item.PatientId,
  5464. Ctime: time.Now().Unix(),
  5465. Mtime: 0,
  5466. Status: 1,
  5467. RecordTime: item.RecordDate,
  5468. OrgId: item.UserOrgId,
  5469. GoodId: item.ProjectId,
  5470. GoodTypeId: 0,
  5471. Count: parseIntCount,
  5472. Type: 0,
  5473. ProjectId: item.ID,
  5474. StorehouseId: 0,
  5475. }
  5476. service.CreateAutoDetail(detail)
  5477. //查询剩余库存
  5478. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5479. var sum_count int64
  5480. for _, item := range goodList {
  5481. sum_count += item.StockCount
  5482. }
  5483. //更新剩余库存
  5484. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5485. //耗材
  5486. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5487. }
  5488. }
  5489. }
  5490. }
  5491. }
  5492. ////同步到自备药
  5493. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5494. if selfPrescriptionOpen.IsOpen == 1 {
  5495. timeStr := time.Now().Format("2006-01-02")
  5496. timeArr := strings.Split(timeStr, "-")
  5497. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5498. total = total + 1
  5499. operation_time := time.Now().Unix()
  5500. creater := adminInfo.AdminUser.Id
  5501. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5502. warehousing := models.XtSelfDrugWarehouse{
  5503. WarehousingOrder: warehousing_order,
  5504. OperationTime: operation_time,
  5505. OrgId: adminInfo.CurrentOrgId,
  5506. Creater: creater,
  5507. Ctime: time.Now().Unix(),
  5508. Status: 1,
  5509. WarehousingTime: recordDateTime,
  5510. Type: 0,
  5511. StorehouseId: 0,
  5512. IsCheck: 1,
  5513. PatientId: patient_id,
  5514. IsSys: 1,
  5515. }
  5516. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5517. if selfDrugWarehouse.ID == 0 {
  5518. service.AddSelfDrugWarehouse(&warehousing, tx)
  5519. }
  5520. if selfDrugWarehouse.ID > 0 {
  5521. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5522. }
  5523. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5524. fmt.Println(info)
  5525. for _, item := range hisdoctorlist {
  5526. //查询该病人的该药品是否已经入库
  5527. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5528. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5529. var in_count int64
  5530. if len(selfdruginfo) > 0 {
  5531. for _, item := range selfdruginfo {
  5532. var in_count_one int64
  5533. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5534. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5535. }
  5536. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5537. in_count_one = item.WarehousingCount
  5538. }
  5539. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5540. in_count_one = item.WarehousingCount
  5541. }
  5542. in_count += in_count_one
  5543. }
  5544. }
  5545. if selfBasedrug.IsSelfDrug == 1 {
  5546. var total_count int64
  5547. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5548. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5549. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5550. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5551. }
  5552. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5553. total_count += prescribingNumberSeven
  5554. }
  5555. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5556. total_count += prescribingNumberSeven
  5557. }
  5558. //入库
  5559. if total_count > in_count {
  5560. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5561. WarehousingOrder: warehousing_order,
  5562. WarehousingId: info.ID,
  5563. DrugId: item.DrugId,
  5564. Number: "",
  5565. ProductDate: 0,
  5566. ExpiryDate: 0,
  5567. WarehousingCount: total_count - in_count,
  5568. WarehouseingUnit: selfBasedrug.MinUnit,
  5569. Price: 0,
  5570. TotalPrice: 0,
  5571. Status: 1,
  5572. Ctime: time.Now().Unix(),
  5573. Remark: "",
  5574. OrgId: adminInfo.CurrentOrgId,
  5575. Type: 0,
  5576. Manufacturer: selfBasedrug.Manufacturer,
  5577. Dealer: selfBasedrug.Dealer,
  5578. StockMaxNumber: total_count - in_count,
  5579. RetailTotalPrice: 0,
  5580. BatchNumber: "",
  5581. MaxUnit: selfBasedrug.MinUnit,
  5582. MinUnit: selfBasedrug.MinUnit,
  5583. RetailPrice: 0,
  5584. StorehouseId: 0,
  5585. IsCheck: 1,
  5586. StockMinNumber: 0,
  5587. PatientId: patient_id,
  5588. IsSys: 1,
  5589. RecordDate: item.RecordDate,
  5590. AdviceId: item.ID,
  5591. }
  5592. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5593. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5594. Creator := adminInfo.AdminUser.Id
  5595. //查询默认仓库剩余多少库存
  5596. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5597. var sum_count int64
  5598. for _, it := range list {
  5599. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5600. if it.MaxUnit == baseDrug.MaxUnit {
  5601. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5602. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5603. }
  5604. sum_count += it.StockMaxNumber + it.StockMinNumber
  5605. }
  5606. flow := &models.XtSelfDrugFlow{
  5607. WarehousingId: info.ID,
  5608. DrugId: item.DrugId,
  5609. Number: "",
  5610. BatchNumber: "",
  5611. Count: total_count - in_count,
  5612. UserOrgId: adminInfo.CurrentOrgId,
  5613. PatientId: item.PatientId,
  5614. SystemTime: time.Now().Unix(),
  5615. ConsumableType: 1,
  5616. IsSys: 1,
  5617. WarehousingOrder: warehousing_order,
  5618. WarehouseOutId: 0,
  5619. WarehouseOutOrderNumber: "",
  5620. IsEdit: 0,
  5621. CancelStockId: 0,
  5622. CancelOrderNumber: "",
  5623. Manufacturer: selfBasedrug.Manufacturer,
  5624. Dealer: selfBasedrug.Dealer,
  5625. Creator: Creator,
  5626. UpdateCreator: Creator,
  5627. Status: 1,
  5628. Ctime: item.AdviceDate,
  5629. Mtime: 0,
  5630. Price: item.Price,
  5631. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5632. WarehouseOutDetailId: 0,
  5633. CancelOutDetailId: 0,
  5634. ExpireDate: 0,
  5635. ProductDate: 0,
  5636. MaxUnit: selfBasedrug.MinUnit,
  5637. MinUnit: selfBasedrug.MinUnit,
  5638. StorehouseId: 0,
  5639. OverCount: sum_count,
  5640. OperateTime: time.Now().Unix(),
  5641. AdviceId: item.ID,
  5642. }
  5643. service.CreateSelfDrugFlow(flow, tx)
  5644. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5645. var total_count int64 // 入库总数量
  5646. var over_count int64 //剩余库存
  5647. for _, it := range drugInfolist {
  5648. if it.MaxUnit == selfBasedrug.MaxUnit {
  5649. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5650. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5651. }
  5652. }
  5653. for _, it := range drugInfolist {
  5654. total_count += it.WarehousingCount
  5655. over_count += it.StockMaxNumber + it.StockMinNumber
  5656. }
  5657. //查询该仓库是否有默认数据
  5658. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5659. if selfDrugStock.ID == 0 {
  5660. drugStock := models.XtSelfDrugStockCount{
  5661. UserOrgId: item.UserOrgId,
  5662. PatientId: item.PatientId,
  5663. SumInCount: total_count,
  5664. SumOutCount: 0,
  5665. SumCancelCount: 0,
  5666. DrugId: item.DrugId,
  5667. Ctime: time.Now().Unix(),
  5668. Mtime: 0,
  5669. Status: 1,
  5670. FlushCount: over_count,
  5671. SumActOutCount: 0,
  5672. }
  5673. service.CreateSelfDrugStockSum(drugStock, tx)
  5674. }
  5675. if selfDrugStock.ID > 0 {
  5676. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5677. }
  5678. }
  5679. //查询这个单据的出库数量
  5680. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5681. var his_out_count int64
  5682. for _, item := range drugFlowList {
  5683. his_out_count += item.Count
  5684. }
  5685. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5686. if (total_count + his_out_count) <= in_count {
  5687. // 出库
  5688. if total_count < in_count {
  5689. var cha_count int64
  5690. cha_count = in_count - total_count
  5691. var stock_number int64 = 0
  5692. //查询库存是否充足
  5693. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5694. // 将该批次的剩余库存数量转换为拆零数量
  5695. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5696. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5697. }
  5698. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5699. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5700. }
  5701. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5702. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5703. }
  5704. if stock_number >= cha_count {
  5705. var maxNumber int64 = 0
  5706. var minNumber int64 = 0
  5707. maxNumber = cha_count / selfBasedrug.MinNumber
  5708. minNumber = cha_count % selfBasedrug.MinNumber
  5709. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5710. minNumber = maxNumber
  5711. }
  5712. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5713. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5715. return
  5716. }
  5717. }
  5718. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5719. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5720. }
  5721. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5722. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5723. }
  5724. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5725. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5726. }
  5727. if warehouse.StockMaxNumber < 0 {
  5728. warehouse.StockMaxNumber = 0
  5729. }
  5730. if warehouse.StockMinNumber < 0 {
  5731. warehouse.StockMinNumber = 0
  5732. }
  5733. warehouse.Mtime = time.Now().Unix()
  5734. if warehouse.StockMinNumber < minNumber {
  5735. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5736. if warehouse.MaxUnit != warehouse.MinUnit {
  5737. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5738. }
  5739. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5740. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5741. }
  5742. } else {
  5743. if minNumber > 0 {
  5744. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5745. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5746. }
  5747. }
  5748. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5749. if warehouse.StockMinNumber > 0 {
  5750. if warehouse.StockMinNumber-cha_count >= 0 {
  5751. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5752. }
  5753. }
  5754. }
  5755. }
  5756. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5757. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5758. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5759. }
  5760. }
  5761. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5762. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5764. return
  5765. }
  5766. }
  5767. if warehouse.StockMinNumber <= 0 {
  5768. warehouse.StockMinNumber = 0
  5769. }
  5770. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5771. //查询该药品剩余库存
  5772. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5773. var over_count int64
  5774. for _, its := range infolist {
  5775. if its.MaxUnit == selfBasedrug.MaxUnit {
  5776. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5777. }
  5778. over_count += its.StockMaxNumber + its.StockMinNumber
  5779. }
  5780. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5781. drugflow := models.XtSelfDrugFlow{
  5782. WarehouseOutId: 0,
  5783. WarehouseOutOrderNumber: warehousing_order,
  5784. WarehousingOrder: warehousing_order,
  5785. DrugId: item.DrugId,
  5786. Number: warehouse.Number,
  5787. ProductDate: warehouse.ProductDate,
  5788. ExpireDate: warehouse.ExpiryDate,
  5789. Count: cha_count,
  5790. Price: warehouse.RetailPrice,
  5791. Status: 1,
  5792. Ctime: item.AdviceDate,
  5793. Mtime: time.Now().Unix(),
  5794. UserOrgId: item.UserOrgId,
  5795. Manufacturer: warehouse.Manufacturer,
  5796. Dealer: warehouse.Dealer,
  5797. BatchNumber: warehouse.BatchNumber,
  5798. MaxUnit: selfBasedrug.MinUnit,
  5799. ConsumableType: 20,
  5800. IsEdit: 1,
  5801. Creator: 0,
  5802. IsSys: 3,
  5803. WarehouseOutDetailId: drugWareInfo.ID,
  5804. AdviceId: item.ID,
  5805. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5806. StorehouseId: 0,
  5807. AdminUserId: creater,
  5808. LastPrice: warehouse.Price,
  5809. StockCount: "",
  5810. WarehousingDetailId: 0,
  5811. OverCount: over_count,
  5812. RetailPrice: item.Price, //手动出库出库价格
  5813. WarehousingId: warehouse.ID,
  5814. SystemTime: item.AdviceDate,
  5815. PatientId: item.PatientId,
  5816. Remark: "保存处方入库数据差",
  5817. OperateTime: time.Now().Unix(),
  5818. }
  5819. if warehouse.RetailPrice == 0 {
  5820. drugflow.Price = item.Price
  5821. }
  5822. service.CreateSelfDrugFlowOne(drugflow, tx)
  5823. var out_count int64
  5824. out_count = in_count - total_count
  5825. //
  5826. //fmt.Println("in_count------------------", in_count)
  5827. //fmt.Println("total_count------------------", total_count)
  5828. //添加出库数量
  5829. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5830. //查询剩余库存
  5831. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5832. var sum_count int64
  5833. for _, its := range stockInfo {
  5834. if its.MaxUnit == selfBasedrug.MaxUnit {
  5835. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5836. }
  5837. sum_count += its.StockMaxNumber + its.StockMinNumber
  5838. }
  5839. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5840. } else {
  5841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5842. return
  5843. }
  5844. }
  5845. }
  5846. }
  5847. }
  5848. }
  5849. }
  5850. tx.Commit()
  5851. if err == nil {
  5852. c.ServeSuccessJSON(map[string]interface{}{
  5853. "msg": "保存成功",
  5854. })
  5855. return
  5856. } else {
  5857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5858. return
  5859. }
  5860. }
  5861. }
  5862. //func (c *HisApiController) EditHisPrescription() {
  5863. // record_date := c.GetString("record_date")
  5864. // patient_id, _ := c.GetInt64("patient_id")
  5865. // reg_type, _ := c.GetInt64("reg_type")
  5866. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5867. // diagnose := c.GetString("diagnose")
  5868. // sick_type, _ := c.GetInt64("sick_type")
  5869. // sick_history := c.GetString("sick_history")
  5870. // doctor_id, _ := c.GetInt64("doctor", 0)
  5871. // department, _ := c.GetInt64("department", 0)
  5872. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5873. // p_type, _ := c.GetInt64("p_type")
  5874. //
  5875. // dataBody := make(map[string]interface{}, 0)
  5876. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5877. // if err != nil {
  5878. // utils.ErrorLog(err.Error())
  5879. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5880. // return
  5881. // }
  5882. //
  5883. // timeLayout := "2006-01-02"
  5884. // loc, _ := time.LoadLocation("Local")
  5885. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5886. // if err != nil {
  5887. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5888. // return
  5889. // }
  5890. // adminInfo := c.GetAdminUserInfo()
  5891. // recordDateTime := theTime.Unix()
  5892. //
  5893. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5894. //
  5895. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5896. // var hpInfo models.HisPrescriptionInfo
  5897. // if info.ID == 0 {
  5898. // var randNum int
  5899. // randNum = rand.Intn(10000) + 1000
  5900. // timestamp := time.Now().Unix()
  5901. // tempTime := time.Unix(timestamp, 0)
  5902. // timeFormat := tempTime.Format("20060102150405")
  5903. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5904. //
  5905. // hpInfo = models.HisPrescriptionInfo{
  5906. // UserOrgId: adminInfo.CurrentOrgId,
  5907. // RecordDate: theTime.Unix(),
  5908. // PatientId: patient_id,
  5909. // Status: 1,
  5910. // Ctime: time.Now().Unix(),
  5911. // Mtime: time.Now().Unix(),
  5912. // Creator: adminInfo.AdminUser.Id,
  5913. // Modifier: adminInfo.AdminUser.Id,
  5914. // Diagnosis: diagnose,
  5915. // SickHistory: sick_history,
  5916. // Departments: department,
  5917. // RegisterType: reg_type,
  5918. // PrescriptionNumber: p_number,
  5919. // PrescriptionStatus: 1,
  5920. // Doctor: role.UserName,
  5921. // DoctorId: doctor_id,
  5922. // SickType: sick_type,
  5923. // PType: p_type,
  5924. // }
  5925. // service.SavePatientPrescriptionInfo(hpInfo)
  5926. //
  5927. // } else {
  5928. // hpInfo = models.HisPrescriptionInfo{
  5929. // ID: info.ID,
  5930. // UserOrgId: adminInfo.CurrentOrgId,
  5931. // RecordDate: info.RecordDate,
  5932. // PatientId: info.PatientId,
  5933. // Status: 1,
  5934. // Ctime: info.Ctime,
  5935. // Mtime: time.Now().Unix(),
  5936. // Creator: info.Creator,
  5937. // Modifier: adminInfo.AdminUser.Id,
  5938. // Diagnosis: diagnose,
  5939. // SickHistory: sick_history,
  5940. // Departments: department,
  5941. // RegisterType: reg_type,
  5942. // PrescriptionNumber: info.PrescriptionNumber,
  5943. // Doctor: role.UserName,
  5944. // PrescriptionStatus: info.PrescriptionStatus,
  5945. // DoctorId: doctor_id,
  5946. // SickType: sick_type,
  5947. // PType: info.PType,
  5948. // }
  5949. // service.SavePatientPrescriptionInfo(hpInfo)
  5950. // }
  5951. //
  5952. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5953. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5954. //
  5955. // if len(prescriptions) > 0 {
  5956. // for _, item := range prescriptions {
  5957. // items := item.(map[string]interface{})
  5958. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5959. // utils.ErrorLog("id")
  5960. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5961. // return
  5962. // }
  5963. // id := int64(items["id"].(float64))
  5964. //
  5965. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5966. // utils.ErrorLog("type")
  5967. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5968. // return
  5969. // }
  5970. // types := int64(items["type"].(float64))
  5971. //
  5972. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5973. // utils.ErrorLog("med_type")
  5974. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5975. // return
  5976. // }
  5977. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5978. //
  5979. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5980. //
  5981. // ctime := time.Now().Unix()
  5982. //
  5983. // prescription := &models.HisPrescription{
  5984. // ID: id,
  5985. // PatientId: patient_id,
  5986. // UserOrgId: adminInfo.CurrentOrgId,
  5987. // RecordDate: recordDateTime,
  5988. // Ctime: ctime,
  5989. // Mtime: ctime,
  5990. // Type: types,
  5991. // Modifier: adminInfo.AdminUser.Id,
  5992. // Creator: adminInfo.AdminUser.Id,
  5993. // Status: 1,
  5994. // Doctor: role.UserName,
  5995. // HisPatientId: his_patient_id,
  5996. // OrderStatus: 1,
  5997. // BatchNumber: "",
  5998. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5999. // PType: hpInfo.PType,
  6000. // MedType: med_type,
  6001. // }
  6002. //
  6003. // if historyPrescription.ID > 0 {
  6004. // prescription.PreTime = historyPrescription.PreTime
  6005. //
  6006. // }
  6007. //
  6008. // service.SaveHisPrescription(prescription)
  6009. //
  6010. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  6011. // advices := items["advices"].([]interface{})
  6012. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6013. // groupNo := int64(0)
  6014. // ctime := time.Now().Unix()
  6015. // mtime := ctime
  6016. // if len(advices) > 0 {
  6017. // for _, advice := range advices {
  6018. // var s models.HisDoctorAdviceInfo
  6019. // s.PrescriptionId = prescription.ID
  6020. // s.AdviceType = 2
  6021. // s.AdviceDoctor = adminInfo.AdminUser.Id
  6022. // s.StopState = 2
  6023. // s.ExecutionState = 2
  6024. // s.AdviceDate = recordDateTime
  6025. // s.Status = 1
  6026. // s.UserOrgId = adminInfo.CurrentOrgId
  6027. // s.RecordDate = recordDateTime
  6028. // s.StartTime = prescription.PreTime
  6029. // s.Groupno = groupNo
  6030. // s.CreatedTime = ctime
  6031. // s.UpdatedTime = mtime
  6032. // s.PatientId = patient_id
  6033. // s.HisPatientId = his_patient_id
  6034. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  6035. // if errcode > 0 {
  6036. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6037. // return
  6038. // }
  6039. //
  6040. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  6041. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  6042. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  6043. // if s.Price == 0 {
  6044. // s.Price = lastWarehouse.RetailPrice
  6045. // }
  6046. // }
  6047. //
  6048. // service.CreateHisDoctorAdvice(&s)
  6049. // //记录日志
  6050. // byterequest, _ := json.Marshal(s)
  6051. // adviceLog := models.XtDoctorAdviceLog{
  6052. // UserOrgId: s.UserOrgId,
  6053. // PatientId: s.PatientId,
  6054. // AdminUserId: adminInfo.AdminUser.Id,
  6055. // Module: 1,
  6056. // ErrLog: string(byterequest),
  6057. // Status: 1,
  6058. // Ctime: time.Now().Unix(),
  6059. // Mtime: 0,
  6060. // Source: "电脑端his医嘱修改",
  6061. // RecordDate: s.AdviceDate,
  6062. // }
  6063. // service.CreateDoctorAdviceLog(adviceLog)
  6064. // redis := service.RedisClient()
  6065. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  6066. // redis.Set(key, "", time.Second)
  6067. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  6068. // fmt.Println("keyOne", keyOne)
  6069. // redis.Set(keyOne, "", time.Second)
  6070. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  6071. // redis.Set(keySeven, "", time.Second)
  6072. // redis.Close()
  6073. //
  6074. // }
  6075. // }
  6076. // }
  6077. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  6078. // projects := items["project"].([]interface{})
  6079. // if len(projects) > 0 {
  6080. // for _, project := range projects {
  6081. // var p models.HisPrescriptionProject
  6082. // p.PrescriptionId = prescription.ID
  6083. // p.Ctime = time.Now().Unix()
  6084. // p.Mtime = time.Now().Unix()
  6085. // p.PatientId = patient_id
  6086. // p.RecordDate = recordDateTime
  6087. // p.UserOrgId = adminInfo.CurrentOrgId
  6088. // p.HisPatientId = his_patient_id
  6089. // p.Status = 1
  6090. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  6091. // if errcode > 0 {
  6092. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6093. // return
  6094. // }
  6095. // service.CreateHisProjectTwo(&p)
  6096. //
  6097. // //记录日志
  6098. // byterequest, _ := json.Marshal(p)
  6099. // adviceLog := models.XtDoctorAdviceLog{
  6100. // UserOrgId: p.UserOrgId,
  6101. // PatientId: p.PatientId,
  6102. // AdminUserId: adminInfo.AdminUser.Id,
  6103. // Module: 1,
  6104. // ErrLog: string(byterequest),
  6105. // Status: 1,
  6106. // Ctime: time.Now().Unix(),
  6107. // Mtime: 0,
  6108. // Source: "电脑端his项目修改",
  6109. // RecordDate: p.RecordDate,
  6110. // }
  6111. // service.CreateDoctorAdviceLog(adviceLog)
  6112. // }
  6113. // }
  6114. // }
  6115. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  6116. // addition := items["addition"].([]interface{})
  6117. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6118. // ctime := time.Now().Unix()
  6119. // mtime := ctime
  6120. // if len(addition) > 0 {
  6121. // for _, item := range addition {
  6122. // var s models.HisAdditionalCharge
  6123. // s.PrescriptionId = prescription.ID
  6124. // s.Status = 1
  6125. // s.UserOrgId = adminInfo.CurrentOrgId
  6126. // s.RecordDate = recordDateTime
  6127. // s.CreatedTime = ctime
  6128. // s.UpdatedTime = mtime
  6129. // s.PatientId = patient_id
  6130. // s.HisPatientId = his_patient_id
  6131. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  6132. // if errcode > 0 {
  6133. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6134. // return
  6135. // }
  6136. // service.CreateAdditionalCharge(&s)
  6137. // }
  6138. // }
  6139. // }
  6140. //
  6141. // }
  6142. // }
  6143. // }
  6144. // if err == nil {
  6145. // c.ServeSuccessJSON(map[string]interface{}{
  6146. // "msg": "保存成功",
  6147. // })
  6148. // return
  6149. //
  6150. // } else {
  6151. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6152. // return
  6153. // }
  6154. //}
  6155. func (c *HisApiController) DeletePrescription() {
  6156. prescription_id, _ := c.GetInt64("id")
  6157. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  6158. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  6159. ////同步到自备药
  6160. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6161. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6162. if selfPrescriptionOpen.IsOpen == 1 {
  6163. // 在函数结束时处理事务回滚
  6164. db := service.XTWriteDB()
  6165. tx := db.Begin()
  6166. defer func() {
  6167. if r := recover(); r != nil {
  6168. tx.Rollback()
  6169. } else {
  6170. tx.Commit()
  6171. }
  6172. }()
  6173. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  6174. for _, item := range advicesList {
  6175. timeStr := time.Now().Format("2006-01-02")
  6176. timeArr := strings.Split(timeStr, "-")
  6177. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6178. total = total + 1
  6179. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6180. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6181. number = number + total
  6182. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6183. operation_time := time.Now().Unix()
  6184. creater := c.GetAdminUserInfo().AdminUser.Id
  6185. //创建一个出库单
  6186. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6187. WarehouseOutOrderNumber: warehousing_out_order,
  6188. OperationTime: operation_time,
  6189. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6190. Creater: creater,
  6191. Ctime: time.Now().Unix(),
  6192. Status: 1,
  6193. WarehouseOutTime: item.AdviceDate,
  6194. Type: 0,
  6195. PatientId: item.PatientId,
  6196. IsCheck: 1,
  6197. }
  6198. //查询今日是否有出库数据
  6199. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  6200. if lastWarehouseOut.ID == 0 {
  6201. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6202. }
  6203. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  6204. var total_count int64
  6205. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  6206. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6207. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6208. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6209. }
  6210. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6211. total_count += prescribingNumberSeven
  6212. }
  6213. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6214. total_count += prescribingNumberSeven
  6215. }
  6216. //出库
  6217. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6218. WarehouseOutOrderNumber: warehousing_out_order,
  6219. WarehouseOutId: lastWarehouseOut.ID,
  6220. DrugId: item.DrugId,
  6221. Count: total_count,
  6222. Price: 0,
  6223. TotalPrice: 0,
  6224. Status: 1,
  6225. Ctime: item.AdviceDate,
  6226. Mtime: item.AdviceDate,
  6227. Remark: "",
  6228. OrgId: item.UserOrgId,
  6229. Type: 0,
  6230. Manufacturer: selfBasedrug.Manufacturer,
  6231. Dealer: selfBasedrug.Dealer,
  6232. RetailPrice: 0,
  6233. RetailTotalPrice: 0,
  6234. CountUnit: selfBasedrug.MinUnit,
  6235. ExpiryDate: 0,
  6236. ProductDate: 0,
  6237. Number: "",
  6238. BatchNumber: "",
  6239. IsSys: 1,
  6240. WarehouseInfoId: 0,
  6241. AdminUserId: 0,
  6242. StockCount: "",
  6243. IsCheck: 1,
  6244. SysRecordTime: item.AdviceDate,
  6245. PatientId: item.PatientId,
  6246. ClassType: "",
  6247. AdviceId: item.ID,
  6248. }
  6249. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6250. }
  6251. for _, it := range warehousingOutInfo {
  6252. //查询今日是否有出库数据
  6253. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  6254. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6255. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6256. //出库逻辑
  6257. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  6258. //查询剩余库存
  6259. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6260. var sum_count int64
  6261. for _, its := range stockInfo {
  6262. if its.MaxUnit == medical.MaxUnit {
  6263. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6264. }
  6265. sum_count += its.StockMaxNumber + its.StockMinNumber
  6266. }
  6267. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6268. }
  6269. }
  6270. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6271. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6272. //耗材保存处方出库
  6273. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6274. //已收费和已发药限制逻辑
  6275. isCharge := false
  6276. isMedicine := false
  6277. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6278. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6279. if new_prescription.IsMedicine == 1 {
  6280. isMedicine = true
  6281. }
  6282. for _, item := range new_prescriptions {
  6283. if item.OrderStatus == 4 {
  6284. isCharge = true
  6285. }
  6286. }
  6287. if p_err != nil {
  6288. if new_prescription.ID > 0 {
  6289. if new_prescription.OrderStatus == 2 {
  6290. isCharge = true
  6291. }
  6292. }
  6293. }
  6294. for _, item := range advices {
  6295. if item.IsMedicine == 1 {
  6296. isMedicine = true
  6297. }
  6298. }
  6299. if isCharge {
  6300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6301. return
  6302. }
  6303. if isMedicine {
  6304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6305. return
  6306. }
  6307. //已收费和已发药限制逻辑
  6308. if len(projects) > 0 {
  6309. for _, item := range projects {
  6310. service.DeletePrintInfo(item.ID) //删除打印信息
  6311. if goodOutConfig.IsOpen != 1 {
  6312. if stockConfig.IsOpen == 1 {
  6313. if item.Type == 3 && item.IsOut == 1 {
  6314. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6315. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6316. good.Total = good.Total + f_count
  6317. service.UpdateGoodInfo(&good)
  6318. operation_time := time.Now().Unix()
  6319. creater := c.GetAdminUserInfo().AdminUser.Id
  6320. //创建退库单
  6321. timeStr := time.Now().Format("2006-01-02")
  6322. timeArr := strings.Split(timeStr, "-")
  6323. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6324. total = total + 1
  6325. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6326. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6327. cancelStock := models.CancelStock{
  6328. OrderNumber: orderNumber,
  6329. OperaTime: operation_time,
  6330. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6331. Creater: creater,
  6332. Ctime: time.Now().Unix(),
  6333. Status: 1,
  6334. ReturnTime: item.RecordDate,
  6335. Type: 1,
  6336. StorehouseId: houseConfig.StorehouseOutInfo,
  6337. IsCheck: 1,
  6338. }
  6339. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6340. if msgerrkonde == gorm.ErrRecordNotFound {
  6341. service.AddSigleCancelStock(&cancelStock)
  6342. }
  6343. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6344. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6345. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6346. //查询该耗材是否出库
  6347. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6348. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6349. deaerler, _ := service.GetDealerById(info.Dealer)
  6350. var total_count int64
  6351. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6352. total_count += count
  6353. if info.ID > 0 {
  6354. if info.Count >= total_count {
  6355. //回退库存
  6356. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6357. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6358. var flush_count int64
  6359. for _, it := range goodList {
  6360. flush_count += it.StockCount
  6361. }
  6362. cancelStockInfo := models.CancelStockInfo{
  6363. GoodId: item.ProjectId,
  6364. CancelStockId: cancel.ID,
  6365. GoodTypeId: good.GoodTypeId,
  6366. Count: prescribingNumber,
  6367. Price: info.Price,
  6368. Total: 0,
  6369. ProductDate: info.ProductDate,
  6370. ExpiryDate: info.ExpiryDate,
  6371. Ctime: time.Now().Unix(),
  6372. Status: 1,
  6373. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6374. OrderNumber: cancel.OrderNumber,
  6375. Type: 0,
  6376. Dealer: deaerler.DealerName,
  6377. Manufacturer: manufacturer.ManufacturerName,
  6378. Number: info.Number,
  6379. RegisterAccount: "",
  6380. Remark: "",
  6381. WarehouseInfoId: info.WarehouseInfotId,
  6382. PatientId: info.PatientId,
  6383. RecordDate: info.SysRecordTime,
  6384. StorehouseId: houseConfig.StorehouseOutInfo,
  6385. IsCheck: 1,
  6386. }
  6387. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6388. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6389. flow := models.VmStockFlow{
  6390. WarehousingId: info.WarehouseInfotId,
  6391. GoodId: item.ProjectId,
  6392. Number: info.Number,
  6393. LicenseNumber: info.LicenseNumber,
  6394. Count: prescribingNumber,
  6395. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6396. PatientId: item.PatientId,
  6397. SystemTime: info.SysRecordTime,
  6398. ConsumableType: 7,
  6399. IsSys: 0,
  6400. WarehousingOrder: "",
  6401. WarehouseOutId: info.WarehouseOutId,
  6402. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6403. IsEdit: 0,
  6404. CancelStockId: cancel.ID,
  6405. CancelOrderNumber: cancel.OrderNumber,
  6406. Manufacturer: manufacturer.ID,
  6407. Dealer: 0,
  6408. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6409. UpdateCreator: 0,
  6410. Status: 1,
  6411. Ctime: time.Now().Unix(),
  6412. Mtime: 0,
  6413. Price: info.Price,
  6414. WarehousingDetailId: info.WarehouseInfotId,
  6415. WarehouseOutDetailId: info.ID,
  6416. CancelOutDetailId: cancelInfo.ID,
  6417. ProductDate: info.ProductDate,
  6418. ExpireDate: info.ExpiryDate,
  6419. StorehouseId: houseConfig.StorehouseOutInfo,
  6420. OverCount: flush_count,
  6421. OperateTime: time.Now().Unix(),
  6422. }
  6423. service.CreateStockFlowOne(flow)
  6424. //退库数量增加
  6425. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6426. //出库数量减少
  6427. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6428. }
  6429. if info.Count < total_count {
  6430. //回退库存
  6431. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6432. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6433. var flush_count int64
  6434. for _, it := range goodList {
  6435. flush_count += it.StockCount
  6436. }
  6437. cancelStockInfo := models.CancelStockInfo{
  6438. GoodId: item.ProjectId,
  6439. CancelStockId: cancel.ID,
  6440. GoodTypeId: good.GoodTypeId,
  6441. Count: info.Count,
  6442. Price: info.Price,
  6443. Total: 0,
  6444. ProductDate: info.ProductDate,
  6445. ExpiryDate: info.ExpiryDate,
  6446. Ctime: time.Now().Unix(),
  6447. Status: 1,
  6448. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6449. OrderNumber: cancel.OrderNumber,
  6450. Type: 0,
  6451. Dealer: deaerler.DealerName,
  6452. Manufacturer: manufacturer.ManufacturerName,
  6453. Number: info.Number,
  6454. RegisterAccount: "",
  6455. Remark: "",
  6456. WarehouseInfoId: info.WarehouseInfotId,
  6457. PatientId: info.PatientId,
  6458. RecordDate: info.SysRecordTime,
  6459. StorehouseId: houseConfig.StorehouseOutInfo,
  6460. IsCheck: 1,
  6461. }
  6462. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6463. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6464. flow := models.VmStockFlow{
  6465. WarehousingId: info.WarehouseInfotId,
  6466. GoodId: item.ProjectId,
  6467. Number: info.Number,
  6468. LicenseNumber: info.LicenseNumber,
  6469. Count: info.Count,
  6470. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6471. PatientId: item.PatientId,
  6472. SystemTime: info.SysRecordTime,
  6473. ConsumableType: 7,
  6474. IsSys: 0,
  6475. WarehousingOrder: "",
  6476. WarehouseOutId: info.WarehouseOutId,
  6477. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6478. IsEdit: 0,
  6479. CancelStockId: cancel.ID,
  6480. CancelOrderNumber: cancel.OrderNumber,
  6481. Manufacturer: manufacturer.ID,
  6482. Dealer: 0,
  6483. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6484. UpdateCreator: 0,
  6485. Status: 1,
  6486. Ctime: time.Now().Unix(),
  6487. Mtime: 0,
  6488. Price: info.Price,
  6489. WarehousingDetailId: info.WarehouseInfotId,
  6490. WarehouseOutDetailId: info.ID,
  6491. CancelOutDetailId: cancelInfo.ID,
  6492. ProductDate: info.ProductDate,
  6493. ExpireDate: info.ExpiryDate,
  6494. StorehouseId: houseConfig.StorehouseOutInfo,
  6495. OverCount: flush_count,
  6496. OperateTime: time.Now().Unix(),
  6497. }
  6498. service.CreateStockFlowOne(flow)
  6499. //退库数量增加
  6500. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6501. //出库数量减少
  6502. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6503. }
  6504. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6505. var flush_count int64
  6506. for _, it := range goodList {
  6507. flush_count += it.StockCount
  6508. }
  6509. //查询已出库数量
  6510. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6511. if prescribingNumber < dialysisInfo.Count {
  6512. //改变数量
  6513. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6514. }
  6515. if prescribingNumber >= dialysisInfo.Count {
  6516. //删除出库表
  6517. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6518. }
  6519. //更新库存
  6520. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6521. //更新基础库库存
  6522. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6523. }
  6524. }
  6525. }
  6526. }
  6527. //保存耗材出库
  6528. if goodOutConfig.IsOpen == 1 {
  6529. if item.Type == 3 {
  6530. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6531. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6532. good.Total = good.Total + f_count
  6533. service.UpdateGoodInfo(&good)
  6534. operation_time := time.Now().Unix()
  6535. creater := c.GetAdminUserInfo().AdminUser.Id
  6536. //创建退库单
  6537. timeStr := time.Now().Format("2006-01-02")
  6538. timeArr := strings.Split(timeStr, "-")
  6539. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6540. total = total + 1
  6541. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6542. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6543. cancelStock := models.CancelStock{
  6544. OrderNumber: orderNumber,
  6545. OperaTime: operation_time,
  6546. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6547. Creater: creater,
  6548. Ctime: time.Now().Unix(),
  6549. Status: 1,
  6550. ReturnTime: item.RecordDate,
  6551. Type: 1,
  6552. StorehouseId: houseConfig.StorehouseOutInfo,
  6553. IsCheck: 1,
  6554. }
  6555. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6556. if msgerrkonde == gorm.ErrRecordNotFound {
  6557. service.AddSigleCancelStock(&cancelStock)
  6558. }
  6559. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6560. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6561. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6562. //查询该耗材是否出库
  6563. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6564. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6565. deaerler, _ := service.GetDealerById(info.Dealer)
  6566. var total_count int64
  6567. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6568. total_count += count
  6569. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6570. var flush_count int64
  6571. for _, it := range goodList {
  6572. flush_count += it.StockCount
  6573. }
  6574. fmt.Println("历史出库数据", info.Count)
  6575. fmt.Println("出库数量", total_count)
  6576. if info.ID > 0 {
  6577. cancelStockInfo := models.CancelStockInfo{
  6578. GoodId: item.ProjectId,
  6579. CancelStockId: cancel.ID,
  6580. GoodTypeId: good.GoodTypeId,
  6581. Count: prescribingNumber,
  6582. Price: info.Price,
  6583. Total: 0,
  6584. ProductDate: info.ProductDate,
  6585. ExpiryDate: info.ExpiryDate,
  6586. Ctime: time.Now().Unix(),
  6587. Status: 1,
  6588. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6589. OrderNumber: cancel.OrderNumber,
  6590. Type: 0,
  6591. Dealer: deaerler.DealerName,
  6592. Manufacturer: manufacturer.ManufacturerName,
  6593. Number: info.Number,
  6594. RegisterAccount: "",
  6595. Remark: "",
  6596. WarehouseInfoId: info.WarehouseInfotId,
  6597. PatientId: info.PatientId,
  6598. RecordDate: info.SysRecordTime,
  6599. StorehouseId: houseConfig.StorehouseOutInfo,
  6600. IsCheck: 1,
  6601. }
  6602. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6603. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6604. //查询出库数量
  6605. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6606. //出库数据 大于 退库数量
  6607. if len(list) > 0 {
  6608. for _, it := range list {
  6609. //回退库存
  6610. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6611. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6612. var flush_count_one int64
  6613. for _, it := range goodList {
  6614. flush_count_one += it.StockCount
  6615. }
  6616. //查询该批次是否有退库数据
  6617. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6618. creater := c.GetAdminUserInfo().AdminUser.Id
  6619. flow := models.VmStockFlow{
  6620. WarehousingId: it.WarehouseInfotId,
  6621. GoodId: it.GoodId,
  6622. Number: it.Number,
  6623. LicenseNumber: it.LicenseNumber,
  6624. Count: it.Count,
  6625. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6626. PatientId: it.PatientId,
  6627. SystemTime: it.SysRecordTime,
  6628. ConsumableType: 7,
  6629. IsSys: 0,
  6630. WarehousingOrder: "",
  6631. WarehouseOutId: it.WarehouseOutId,
  6632. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6633. IsEdit: 0,
  6634. CancelStockId: cancel.ID,
  6635. CancelOrderNumber: cancel.OrderNumber,
  6636. Manufacturer: manufacturer.ID,
  6637. Dealer: 0,
  6638. Creator: creater,
  6639. UpdateCreator: 0,
  6640. Status: 1,
  6641. Ctime: time.Now().Unix(),
  6642. Mtime: 0,
  6643. Price: it.Price,
  6644. WarehousingDetailId: it.WarehouseInfotId,
  6645. WarehouseOutDetailId: it.ID,
  6646. CancelOutDetailId: cancelInfo.ID,
  6647. ProductDate: it.ProductDate,
  6648. ExpireDate: it.ExpiryDate,
  6649. StorehouseId: houseConfig.StorehouseOutInfo,
  6650. OverCount: flush_count_one,
  6651. OperateTime: time.Now().Unix(),
  6652. }
  6653. service.CreateStockFlowOne(flow)
  6654. //if flow.ID > 0 {
  6655. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6656. //}
  6657. }
  6658. }
  6659. //flow := models.VmStockFlow{
  6660. // WarehousingId: info.WarehouseInfotId,
  6661. // GoodId: item.ProjectId,
  6662. // Number: info.Number,
  6663. // LicenseNumber: info.LicenseNumber,
  6664. // Count: prescribingNumber,
  6665. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6666. // PatientId: item.PatientId,
  6667. // SystemTime: info.SysRecordTime,
  6668. // ConsumableType: 7,
  6669. // IsSys: 0,
  6670. // WarehousingOrder: "",
  6671. // WarehouseOutId: info.WarehouseOutId,
  6672. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6673. // IsEdit: 0,
  6674. // CancelStockId: cancel.ID,
  6675. // CancelOrderNumber: cancel.OrderNumber,
  6676. // Manufacturer: manufacturer.ID,
  6677. // Dealer: 0,
  6678. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6679. // UpdateCreator: 0,
  6680. // Status: 1,
  6681. // Ctime: time.Now().Unix(),
  6682. // Mtime: 0,
  6683. // Price: info.Price,
  6684. // WarehousingDetailId: info.WarehouseInfotId,
  6685. // WarehouseOutDetailId: info.ID,
  6686. // CancelOutDetailId: cancelInfo.ID,
  6687. // ProductDate: info.ProductDate,
  6688. // ExpireDate: info.ExpiryDate,
  6689. // StorehouseId: houseConfig.StorehouseOutInfo,
  6690. // OverCount: flush_count,
  6691. //}
  6692. //service.CreateStockFlowOne(flow)
  6693. //退库数量增加
  6694. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6695. //出库数量减少
  6696. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6697. //查询已出库数量
  6698. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6699. if prescribingNumber < dialysisInfo.Count {
  6700. //改变数量
  6701. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6702. }
  6703. if prescribingNumber >= dialysisInfo.Count {
  6704. //删除出库表
  6705. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6706. }
  6707. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6708. var flush_count_one int64
  6709. for _, it := range goodList {
  6710. flush_count_one += it.StockCount
  6711. }
  6712. //更新库存
  6713. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6714. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6715. //更新基础库库存
  6716. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6717. }
  6718. }
  6719. }
  6720. }
  6721. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6722. fmt.Println(err)
  6723. }
  6724. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6725. fmt.Println(err)
  6726. if len(advices) > 0 {
  6727. for _, item := range advices {
  6728. redis := service.RedisClient()
  6729. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6730. redis.Set(keyFive, "", time.Second)
  6731. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6732. redis.Set(keyOne, "", time.Second)
  6733. redis.Close()
  6734. }
  6735. }
  6736. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6737. if len(advices) > 0 {
  6738. for _, item := range advices {
  6739. creater := c.GetAdminUserInfo().AdminUser.Id
  6740. service.DrugAutoAddCancelInfo(item, creater)
  6741. }
  6742. }
  6743. } else {
  6744. if drugOutConfig.IsOpen == 1 {
  6745. if len(advices) > 0 {
  6746. for _, item := range advices {
  6747. creater := c.GetAdminUserInfo().AdminUser.Id
  6748. service.DrugAutoAddCancelInfo(item, creater)
  6749. }
  6750. }
  6751. } else {
  6752. if len(advices) > 0 {
  6753. for _, item := range advices {
  6754. creater := c.GetAdminUserInfo().AdminUser.Id
  6755. service.DrugAutoAddCancelInfo(item, creater)
  6756. }
  6757. }
  6758. }
  6759. }
  6760. c.ServeSuccessJSON(map[string]interface{}{
  6761. "msg": "删除成功",
  6762. })
  6763. return
  6764. }
  6765. func (c *HisApiController) DeleteDoctorAdvice() {
  6766. id, _ := c.GetInt64("id")
  6767. advice, _ := service.GetHisDoctorAdvicesById(id)
  6768. ////同步到自备药
  6769. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6770. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6771. if selfPrescriptionOpen.IsOpen == 1 {
  6772. db := service.XTWriteDB()
  6773. tx := db.Begin()
  6774. defer func() {
  6775. if r := recover(); r != nil {
  6776. tx.Rollback()
  6777. } else {
  6778. tx.Commit()
  6779. }
  6780. }()
  6781. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6782. var total_count int64
  6783. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6784. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6785. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6786. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6787. }
  6788. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6789. total_count += prescribingNumberSeven
  6790. }
  6791. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6792. total_count += prescribingNumberSeven
  6793. }
  6794. timeStr := time.Now().Format("2006-01-02")
  6795. timeArr := strings.Split(timeStr, "-")
  6796. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6797. total = total + 1
  6798. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6799. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6800. number = number + total
  6801. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6802. operation_time := time.Now().Unix()
  6803. creater := c.GetAdminUserInfo().AdminUser.Id
  6804. //创建一个出库单
  6805. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6806. WarehouseOutOrderNumber: warehousing_out_order,
  6807. OperationTime: operation_time,
  6808. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6809. Creater: creater,
  6810. Ctime: time.Now().Unix(),
  6811. Status: 1,
  6812. WarehouseOutTime: advice.AdviceDate,
  6813. Type: 0,
  6814. PatientId: advice.PatientId,
  6815. IsCheck: 1,
  6816. }
  6817. //查询今日是否有出库数据
  6818. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6819. if lastWarehouseOut.ID == 0 {
  6820. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6821. }
  6822. //出库
  6823. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6824. WarehouseOutId: lastWarehouseOut.ID,
  6825. WarehouseOutOrderNumber: warehousing_out_order,
  6826. DrugId: advice.DrugId,
  6827. Count: total_count,
  6828. Price: 0,
  6829. TotalPrice: 0,
  6830. Status: 1,
  6831. Ctime: advice.AdviceDate,
  6832. Mtime: advice.AdviceDate,
  6833. Remark: "",
  6834. OrgId: advice.UserOrgId,
  6835. Type: 0,
  6836. Manufacturer: selfBasedrug.Manufacturer,
  6837. Dealer: selfBasedrug.Dealer,
  6838. RetailPrice: 0,
  6839. RetailTotalPrice: 0,
  6840. CountUnit: advice.PrescribingNumberUnit,
  6841. ExpiryDate: 0,
  6842. ProductDate: 0,
  6843. Number: "",
  6844. BatchNumber: "",
  6845. IsSys: 0,
  6846. WarehouseInfoId: 0,
  6847. AdminUserId: 0,
  6848. StockCount: "",
  6849. IsCheck: 1,
  6850. SysRecordTime: advice.AdviceDate,
  6851. PatientId: advice.PatientId,
  6852. AdviceId: advice.ID,
  6853. ClassType: "",
  6854. }
  6855. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6856. for _, it := range warehousingOutInfo {
  6857. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6858. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6859. //出库逻辑
  6860. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6861. //查询剩余库存
  6862. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6863. var sum_count int64
  6864. for _, its := range stockInfo {
  6865. if its.MaxUnit == medical.MaxUnit {
  6866. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6867. }
  6868. sum_count += its.StockMaxNumber + its.StockMinNumber
  6869. }
  6870. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6871. }
  6872. }
  6873. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6874. //已收费和已发药的限制逻辑
  6875. isCharge := false
  6876. isMedicine := false
  6877. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6878. //获取今天该患者所有处方,判断是否发药或者收费
  6879. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6880. //for _, item := range new_prescriptions {
  6881. if new_prescription.IsMedicine == 1 {
  6882. isMedicine = true
  6883. }
  6884. //}
  6885. for _, item := range new_prescriptions {
  6886. if item.OrderStatus == 4 {
  6887. isCharge = true
  6888. }
  6889. }
  6890. if isMedicine {
  6891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6892. return
  6893. }
  6894. if isCharge {
  6895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6896. return
  6897. }
  6898. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6899. creater := c.GetAdminUserInfo().AdminUser.Id
  6900. for _, item := range advices {
  6901. if item.IsMedicine == 1 {
  6902. isMedicine = true
  6903. }
  6904. byterequest, _ := json.Marshal(item)
  6905. adviceLog := models.XtDoctorAdviceLog{
  6906. UserOrgId: item.UserOrgId,
  6907. PatientId: item.PatientId,
  6908. AdminUserId: creater,
  6909. Module: 1,
  6910. ErrLog: string(byterequest),
  6911. Status: 1,
  6912. Ctime: time.Now().Unix(),
  6913. Mtime: 0,
  6914. Source: "电脑端删除医嘱",
  6915. RecordDate: item.AdviceDate,
  6916. }
  6917. service.CreateDoctorAdviceLog(adviceLog)
  6918. }
  6919. if isMedicine {
  6920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6921. return
  6922. }
  6923. if new_prescription.ID > 0 {
  6924. if new_prescription.OrderStatus == 2 {
  6925. isCharge = true
  6926. }
  6927. }
  6928. if isCharge {
  6929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6930. return
  6931. }
  6932. //已收费和已发药的限制逻辑
  6933. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6934. redis := service.RedisClient()
  6935. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6936. redis.Set(keyFive, "", time.Second)
  6937. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6938. redis.Set(keyOne, "", time.Second)
  6939. defer redis.Close()
  6940. if err == nil {
  6941. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6942. //查询是否在处方中出库
  6943. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6944. if openConfig.IsOpen != 1 {
  6945. //判断该医嘱是否执行了
  6946. if advice.ExecutionState == 1 {
  6947. creater := c.GetAdminUserInfo().AdminUser.Id
  6948. service.DrugAutoAddCancelInfo(&advice, creater)
  6949. }
  6950. }
  6951. //开启保存处方扣减功能
  6952. if openConfig.IsOpen == 1 {
  6953. creater := c.GetAdminUserInfo().AdminUser.Id
  6954. service.DrugAutoAddCancelInfo(&advice, creater)
  6955. }
  6956. } else {
  6957. if drugOutConfig.IsOpen == 1 {
  6958. //查询是否在处方中出库
  6959. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6960. if openConfig.IsOpen != 1 {
  6961. //判断该医嘱是否执行了
  6962. if advice.ExecutionState == 1 {
  6963. creater := c.GetAdminUserInfo().AdminUser.Id
  6964. service.DrugAutoAddCancelInfo(&advice, creater)
  6965. }
  6966. }
  6967. //开启保存处方扣减功能
  6968. if openConfig.IsOpen == 1 {
  6969. creater := c.GetAdminUserInfo().AdminUser.Id
  6970. service.DrugAutoAddCancelInfo(&advice, creater)
  6971. }
  6972. } else {
  6973. //判断该医嘱是否执行了
  6974. if advice.ExecutionState == 1 {
  6975. creater := c.GetAdminUserInfo().AdminUser.Id
  6976. service.DrugAutoAddCancelInfo(&advice, creater)
  6977. }
  6978. }
  6979. }
  6980. c.ServeSuccessJSON(map[string]interface{}{
  6981. "msg": "删除成功",
  6982. })
  6983. return
  6984. } else {
  6985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6986. return
  6987. }
  6988. }
  6989. func (c *HisApiController) DeleteProject() {
  6990. id, _ := c.GetInt64("id")
  6991. adminInfo := c.GetAdminUserInfo()
  6992. project, _ := service.GetHisProjectByID(id)
  6993. // var consumable models.DialysisBeforePrepare
  6994. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6995. //耗材保存处方出库
  6996. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6997. isCharge := false
  6998. isMedicine := false
  6999. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  7000. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  7001. creater := c.GetAdminUserInfo().AdminUser.Id
  7002. for _, item := range new_prescriptions {
  7003. if item.IsMedicine == 1 {
  7004. isMedicine = true
  7005. }
  7006. byterequest, _ := json.Marshal(item)
  7007. adviceLog := models.XtDoctorAdviceLog{
  7008. UserOrgId: item.UserOrgId,
  7009. PatientId: item.PatientId,
  7010. AdminUserId: creater,
  7011. Module: 1,
  7012. ErrLog: string(byterequest),
  7013. Status: 1,
  7014. Ctime: time.Now().Unix(),
  7015. Mtime: 0,
  7016. Source: "电脑端删除医嘱",
  7017. RecordDate: item.RecordDate,
  7018. }
  7019. service.CreateDoctorAdviceLog(adviceLog)
  7020. }
  7021. for _, item := range new_prescriptions {
  7022. if item.OrderStatus == 4 {
  7023. isCharge = true
  7024. }
  7025. }
  7026. if isMedicine {
  7027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  7028. return
  7029. }
  7030. if isCharge {
  7031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  7032. return
  7033. }
  7034. if new_prescription.ID > 0 {
  7035. if new_prescription.OrderStatus == 2 {
  7036. isCharge = true
  7037. }
  7038. }
  7039. if isCharge {
  7040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  7041. return
  7042. }
  7043. service.DeletePrintInfo(id)
  7044. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  7045. label.Status = 0
  7046. service.CreateHisLabelRecordTwo(&label)
  7047. fmt.Println(goodOutConfig.IsOpen)
  7048. if goodOutConfig.IsOpen != 1 {
  7049. if stockConfig.IsOpen == 1 {
  7050. if project.Type == 2 {
  7051. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7052. fmt.Println(err)
  7053. }
  7054. if project.Type == 3 && project.IsOut == 1 {
  7055. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7056. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7057. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7058. operation_time := time.Now().Unix()
  7059. creater := adminInfo.AdminUser.Id
  7060. //创建退库单
  7061. timeStr := time.Now().Format("2006-01-02")
  7062. timeArr := strings.Split(timeStr, "-")
  7063. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7064. total = total + 1
  7065. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7066. cancelStock := models.CancelStock{
  7067. OrderNumber: orderNumber,
  7068. OperaTime: operation_time,
  7069. OrgId: adminInfo.CurrentOrgId,
  7070. Creater: creater,
  7071. Ctime: time.Now().Unix(),
  7072. Status: 1,
  7073. ReturnTime: project.RecordDate,
  7074. Type: 1,
  7075. StorehouseId: houseConfig.StorehouseOutInfo,
  7076. IsCheck: 1,
  7077. }
  7078. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7079. if msgerrkonde == gorm.ErrRecordNotFound {
  7080. service.AddSigleCancelStock(&cancelStock)
  7081. }
  7082. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7083. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7084. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7085. //查询是否有出库
  7086. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7087. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7088. deaerler, _ := service.GetDealerById(info.Dealer)
  7089. if info.ID > 0 {
  7090. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7091. if info.Count >= prescribingNumber {
  7092. cancelStockInfo := models.CancelStockInfo{
  7093. GoodId: project.ProjectId,
  7094. CancelStockId: cancel.ID,
  7095. GoodTypeId: good.GoodTypeId,
  7096. Count: prescribingNumber,
  7097. Price: info.Price,
  7098. Total: 0,
  7099. ProductDate: info.ProductDate,
  7100. ExpiryDate: info.ExpiryDate,
  7101. Ctime: time.Now().Unix(),
  7102. Status: 1,
  7103. OrgId: adminInfo.CurrentOrgId,
  7104. OrderNumber: cancel.OrderNumber,
  7105. Type: 0,
  7106. Dealer: deaerler.DealerName,
  7107. Manufacturer: manufacturer.ManufacturerName,
  7108. Number: info.Number,
  7109. RegisterAccount: "",
  7110. Remark: "",
  7111. WarehouseInfoId: info.WarehouseInfotId,
  7112. PatientId: info.PatientId,
  7113. RecordDate: info.SysRecordTime,
  7114. StorehouseId: houseConfig.StorehouseOutInfo,
  7115. IsCheck: 1,
  7116. }
  7117. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7118. //回退库存
  7119. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  7120. //退库数量增加
  7121. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7122. //出库数量减少
  7123. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7124. }
  7125. if info.Count < prescribingNumber {
  7126. cancelStockInfo := models.CancelStockInfo{
  7127. GoodId: project.ProjectId,
  7128. CancelStockId: cancel.ID,
  7129. GoodTypeId: good.GoodTypeId,
  7130. Count: info.Count,
  7131. Price: info.Price,
  7132. Total: 0,
  7133. ProductDate: info.ProductDate,
  7134. ExpiryDate: info.ExpiryDate,
  7135. Ctime: time.Now().Unix(),
  7136. Status: 1,
  7137. OrgId: adminInfo.CurrentOrgId,
  7138. OrderNumber: cancel.OrderNumber,
  7139. Type: 0,
  7140. Dealer: deaerler.DealerName,
  7141. Manufacturer: manufacturer.ManufacturerName,
  7142. Number: info.Number,
  7143. RegisterAccount: "",
  7144. Remark: "",
  7145. WarehouseInfoId: info.WarehouseInfotId,
  7146. PatientId: info.PatientId,
  7147. RecordDate: info.SysRecordTime,
  7148. StorehouseId: houseConfig.StorehouseOutInfo,
  7149. IsCheck: 1,
  7150. }
  7151. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7152. //回退库存
  7153. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7154. //退库数量增加
  7155. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  7156. //出库数量减少
  7157. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  7158. }
  7159. //查询剩余库存
  7160. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7161. var over_count int64
  7162. for _, it := range goodList {
  7163. over_count += it.StockCount
  7164. }
  7165. //出库数据 大于 退库数量
  7166. if info.Count >= prescribingNumber {
  7167. flow := models.VmStockFlow{
  7168. WarehousingId: info.WarehouseInfotId,
  7169. GoodId: project.ProjectId,
  7170. Number: info.Number,
  7171. LicenseNumber: info.LicenseNumber,
  7172. Count: prescribingNumber,
  7173. UserOrgId: adminInfo.CurrentOrgId,
  7174. PatientId: project.PatientId,
  7175. SystemTime: info.SysRecordTime,
  7176. ConsumableType: 7,
  7177. IsSys: 0,
  7178. WarehousingOrder: "",
  7179. WarehouseOutId: info.WarehouseOutId,
  7180. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7181. IsEdit: 0,
  7182. CancelStockId: cancel.ID,
  7183. CancelOrderNumber: cancel.OrderNumber,
  7184. Manufacturer: manufacturer.ID,
  7185. Dealer: 0,
  7186. Creator: adminInfo.AdminUser.Id,
  7187. UpdateCreator: 0,
  7188. Status: 1,
  7189. Ctime: time.Now().Unix(),
  7190. Mtime: 0,
  7191. Price: info.Price,
  7192. WarehousingDetailId: info.WarehouseInfotId,
  7193. WarehouseOutDetailId: info.ID,
  7194. CancelOutDetailId: cancelInfo.ID,
  7195. ProductDate: info.ProductDate,
  7196. ExpireDate: info.ExpiryDate,
  7197. StorehouseId: houseConfig.StorehouseOutInfo,
  7198. OverCount: over_count,
  7199. OperateTime: time.Now().Unix(),
  7200. }
  7201. service.CreateStockFlowOne(flow)
  7202. }
  7203. //出库数据小于退库数据
  7204. if info.Count < prescribingNumber {
  7205. flow := models.VmStockFlow{
  7206. WarehousingId: info.WarehouseInfotId,
  7207. GoodId: project.ProjectId,
  7208. Number: info.Number,
  7209. LicenseNumber: info.LicenseNumber,
  7210. Count: info.Count,
  7211. UserOrgId: adminInfo.CurrentOrgId,
  7212. PatientId: project.PatientId,
  7213. SystemTime: info.SysRecordTime,
  7214. ConsumableType: 7,
  7215. IsSys: 0,
  7216. WarehousingOrder: "",
  7217. WarehouseOutId: info.WarehouseOutId,
  7218. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7219. IsEdit: 0,
  7220. CancelStockId: cancel.ID,
  7221. CancelOrderNumber: cancel.OrderNumber,
  7222. Manufacturer: manufacturer.ID,
  7223. Dealer: 0,
  7224. Creator: adminInfo.AdminUser.Id,
  7225. UpdateCreator: 0,
  7226. Status: 1,
  7227. Ctime: time.Now().Unix(),
  7228. Mtime: 0,
  7229. Price: info.Price,
  7230. WarehousingDetailId: info.WarehouseInfotId,
  7231. WarehouseOutDetailId: info.ID,
  7232. CancelOutDetailId: cancelInfo.ID,
  7233. ProductDate: info.ProductDate,
  7234. ExpireDate: info.ExpiryDate,
  7235. StorehouseId: houseConfig.StorehouseOutInfo,
  7236. OverCount: over_count,
  7237. OperateTime: time.Now().Unix(),
  7238. }
  7239. service.CreateStockFlowOne(flow)
  7240. }
  7241. //查询已出库数量
  7242. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7243. if prescribingNumber < dialysisInfo.Count {
  7244. //改变数量
  7245. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7246. }
  7247. if prescribingNumber >= dialysisInfo.Count {
  7248. //删除出库表
  7249. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7250. }
  7251. //更新剩余库存
  7252. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7253. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7254. var total_count_one int64
  7255. for _, it := range stockList {
  7256. total_count_one += it.StockCount
  7257. }
  7258. //基础库插入数据
  7259. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7260. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7261. var flush_count int64
  7262. for _, it := range goodListOne {
  7263. flush_count += it.StockCount
  7264. }
  7265. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7266. if errs != nil {
  7267. goodErrcode := models.XtGoodErrcode{
  7268. UserOrgId: project.UserOrgId,
  7269. Errcode: "手动出库更新剩余出库失败",
  7270. GoodId: project.ProjectId,
  7271. Status: 1,
  7272. Ctime: time.Now().Unix(),
  7273. Mtime: 0,
  7274. Count: 0,
  7275. StockCount: 0,
  7276. Creater: creater,
  7277. BatchNumberId: 0,
  7278. WarehouseOutId: 0,
  7279. }
  7280. service.CreateGoodErrcode(goodErrcode)
  7281. }
  7282. }
  7283. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7284. fmt.Println(err)
  7285. } else {
  7286. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7287. fmt.Println(err)
  7288. }
  7289. } else {
  7290. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7291. fmt.Println(err)
  7292. }
  7293. }
  7294. //保存处方出库
  7295. if goodOutConfig.IsOpen == 1 {
  7296. if project.Type == 3 {
  7297. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7298. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7299. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7300. operation_time := time.Now().Unix()
  7301. creater := adminInfo.AdminUser.Id
  7302. //创建退库单
  7303. timeStr := time.Now().Format("2006-01-02")
  7304. timeArr := strings.Split(timeStr, "-")
  7305. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7306. total = total + 1
  7307. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7308. cancelStock := models.CancelStock{
  7309. OrderNumber: orderNumber,
  7310. OperaTime: operation_time,
  7311. OrgId: adminInfo.CurrentOrgId,
  7312. Creater: creater,
  7313. Ctime: time.Now().Unix(),
  7314. Status: 1,
  7315. ReturnTime: project.RecordDate,
  7316. Type: 1,
  7317. StorehouseId: houseConfig.StorehouseOutInfo,
  7318. IsCheck: 1,
  7319. }
  7320. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7321. if msgerrkonde == gorm.ErrRecordNotFound {
  7322. service.AddSigleCancelStock(&cancelStock)
  7323. }
  7324. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7325. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7326. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7327. //获取出库数据
  7328. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7329. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7330. deaerler, _ := service.GetDealerById(info.Dealer)
  7331. if info.ID > 0 {
  7332. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7333. if info.Count >= prescribingNumber {
  7334. cancelStockInfo := models.CancelStockInfo{
  7335. GoodId: project.ProjectId,
  7336. CancelStockId: cancel.ID,
  7337. GoodTypeId: good.GoodTypeId,
  7338. Count: prescribingNumber,
  7339. Price: info.Price,
  7340. Total: 0,
  7341. ProductDate: info.ProductDate,
  7342. ExpiryDate: info.ExpiryDate,
  7343. Ctime: time.Now().Unix(),
  7344. Status: 1,
  7345. OrgId: adminInfo.CurrentOrgId,
  7346. OrderNumber: cancel.OrderNumber,
  7347. Type: 0,
  7348. Dealer: deaerler.DealerName,
  7349. Manufacturer: manufacturer.ManufacturerName,
  7350. Number: info.Number,
  7351. RegisterAccount: "",
  7352. Remark: "",
  7353. WarehouseInfoId: info.WarehouseInfotId,
  7354. PatientId: info.PatientId,
  7355. RecordDate: info.SysRecordTime,
  7356. StorehouseId: houseConfig.StorehouseOutInfo,
  7357. IsCheck: 1,
  7358. }
  7359. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7360. //退库数量增加
  7361. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7362. //出库数量减少
  7363. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7364. }
  7365. if info.Count < prescribingNumber {
  7366. cancelStockInfo := models.CancelStockInfo{
  7367. GoodId: project.ProjectId,
  7368. CancelStockId: cancel.ID,
  7369. GoodTypeId: good.GoodTypeId,
  7370. Count: prescribingNumber,
  7371. Price: info.Price,
  7372. Total: 0,
  7373. ProductDate: info.ProductDate,
  7374. ExpiryDate: info.ExpiryDate,
  7375. Ctime: time.Now().Unix(),
  7376. Status: 1,
  7377. OrgId: adminInfo.CurrentOrgId,
  7378. OrderNumber: cancel.OrderNumber,
  7379. Type: 0,
  7380. Dealer: deaerler.DealerName,
  7381. Manufacturer: manufacturer.ManufacturerName,
  7382. Number: info.Number,
  7383. RegisterAccount: "",
  7384. Remark: "",
  7385. WarehouseInfoId: info.WarehouseInfotId,
  7386. PatientId: info.PatientId,
  7387. RecordDate: info.SysRecordTime,
  7388. StorehouseId: houseConfig.StorehouseOutInfo,
  7389. IsCheck: 1,
  7390. }
  7391. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7392. //回退库存
  7393. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7394. }
  7395. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7396. var over_count int64
  7397. for _, it := range goodList {
  7398. over_count += it.StockCount
  7399. }
  7400. //查询出库数量
  7401. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  7402. //出库数据 大于 退库数量
  7403. if len(list) > 0 {
  7404. for _, it := range list {
  7405. //回退库存
  7406. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  7407. //退库数量增加
  7408. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  7409. //出库数量减少
  7410. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  7411. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7412. var over_count_one int64
  7413. for _, it := range goodList {
  7414. over_count_one += it.StockCount
  7415. }
  7416. //查询该批次是否有退库数据
  7417. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  7418. flow := models.VmStockFlow{
  7419. WarehousingId: it.WarehouseInfotId,
  7420. GoodId: it.GoodId,
  7421. Number: it.Number,
  7422. LicenseNumber: it.LicenseNumber,
  7423. Count: it.Count,
  7424. UserOrgId: adminInfo.CurrentOrgId,
  7425. PatientId: it.PatientId,
  7426. SystemTime: it.SysRecordTime,
  7427. ConsumableType: 7,
  7428. IsSys: 0,
  7429. WarehousingOrder: "",
  7430. WarehouseOutId: it.WarehouseOutId,
  7431. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7432. IsEdit: 0,
  7433. CancelStockId: cancel.ID,
  7434. CancelOrderNumber: cancel.OrderNumber,
  7435. Manufacturer: manufacturer.ID,
  7436. Dealer: 0,
  7437. Creator: adminInfo.AdminUser.Id,
  7438. UpdateCreator: 0,
  7439. Status: 1,
  7440. Ctime: time.Now().Unix(),
  7441. Mtime: 0,
  7442. Price: it.Price,
  7443. WarehousingDetailId: it.WarehouseInfotId,
  7444. WarehouseOutDetailId: it.ID,
  7445. CancelOutDetailId: cancelInfo.ID,
  7446. ProductDate: it.ProductDate,
  7447. ExpireDate: it.ExpiryDate,
  7448. StorehouseId: houseConfig.StorehouseOutInfo,
  7449. OverCount: over_count_one,
  7450. OperateTime: time.Now().Unix(),
  7451. }
  7452. service.CreateStockFlowOne(flow)
  7453. }
  7454. }
  7455. //查询已出库数量
  7456. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7457. if prescribingNumber < dialysisInfo.Count {
  7458. //改变数量
  7459. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7460. }
  7461. if prescribingNumber >= dialysisInfo.Count {
  7462. //删除出库表
  7463. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7464. }
  7465. //更新剩余库存
  7466. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7467. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7468. var total_count_one int64
  7469. for _, it := range stockList {
  7470. total_count_one += it.StockCount
  7471. }
  7472. //基础库插入数据
  7473. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7474. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7475. var flush_count int64
  7476. for _, it := range goodListOne {
  7477. flush_count += it.StockCount
  7478. }
  7479. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7480. if errs != nil {
  7481. goodErrcode := models.XtGoodErrcode{
  7482. UserOrgId: project.UserOrgId,
  7483. Errcode: "手动出库更新剩余出库失败",
  7484. GoodId: project.ProjectId,
  7485. Status: 1,
  7486. Ctime: time.Now().Unix(),
  7487. Mtime: 0,
  7488. Count: 0,
  7489. StockCount: 0,
  7490. Creater: creater,
  7491. BatchNumberId: 0,
  7492. WarehouseOutId: 0,
  7493. }
  7494. service.CreateGoodErrcode(goodErrcode)
  7495. }
  7496. }
  7497. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7498. fmt.Println(err)
  7499. } else {
  7500. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7501. fmt.Println(err)
  7502. }
  7503. }
  7504. c.ServeSuccessJSON(map[string]interface{}{
  7505. "msg": "删除成功",
  7506. })
  7507. return
  7508. }
  7509. func (c *HisApiController) CreateHisAdditionalCharge() {
  7510. his_patient_id, _ := c.GetInt64("his_patient_id")
  7511. patient_id, _ := c.GetInt64("patient_id")
  7512. record_date := c.GetString("record_date")
  7513. timeLayout := "2006-01-02"
  7514. loc, _ := time.LoadLocation("Local")
  7515. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7516. if err != nil {
  7517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7518. return
  7519. }
  7520. adminInfo := c.GetAdminUserInfo()
  7521. recordDateTime := theTime.Unix()
  7522. dataBody := make(map[string]interface{}, 0)
  7523. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7524. if err != nil {
  7525. utils.ErrorLog(err.Error())
  7526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7527. return
  7528. }
  7529. var additions []*models.HisAdditionalCharge
  7530. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7531. additions, _ := dataBody["addition"].([]interface{})
  7532. if len(additions) > 0 {
  7533. for _, item := range additions {
  7534. items := item.(map[string]interface{})
  7535. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7536. utils.ErrorLog("item_id")
  7537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7538. return
  7539. }
  7540. item_id := int64(items["item_id"].(float64))
  7541. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7542. utils.ErrorLog("item_name")
  7543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7544. return
  7545. }
  7546. item_name := items["item_name"].(string)
  7547. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7548. utils.ErrorLog("price")
  7549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7550. return
  7551. }
  7552. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7553. ctime := time.Now().Unix()
  7554. additional := &models.HisAdditionalCharge{
  7555. PatientId: patient_id,
  7556. HisPatientId: his_patient_id,
  7557. UserOrgId: adminInfo.CurrentOrgId,
  7558. RecordDate: recordDateTime,
  7559. CreatedTime: ctime,
  7560. UpdatedTime: ctime,
  7561. Modifier: adminInfo.AdminUser.Id,
  7562. Creator: adminInfo.AdminUser.Id,
  7563. Price: price,
  7564. ItemName: item_name,
  7565. ItemId: item_id,
  7566. Status: 1,
  7567. }
  7568. additions = append(additions, additional)
  7569. }
  7570. }
  7571. }
  7572. for _, item := range additions {
  7573. service.CreateAddtionalCharge(item)
  7574. }
  7575. c.ServeSuccessJSON(map[string]interface{}{
  7576. "msg": "创建成功",
  7577. })
  7578. }
  7579. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7580. blood_fat := c.GetString("blood_fat")
  7581. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7582. blood_sugar := c.GetString("blood_sugar")
  7583. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7584. chief_conplaint := c.GetString("chief_conplaint")
  7585. dbp := c.GetString("dbp")
  7586. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7587. delivery_way, _ := c.GetInt64("delivery_way")
  7588. diagnostic := c.GetString("diagnostic")
  7589. family_history := c.GetString("family_history")
  7590. height := c.GetString("height")
  7591. history_of_present_illness := c.GetString("history_of_present_illness")
  7592. is_infect, _ := c.GetInt64("is_infect")
  7593. past_history := c.GetString("past_history")
  7594. patient_id, _ := c.GetInt64("patient_id")
  7595. his_patient_id, _ := c.GetInt64("his_patient_id")
  7596. personal_history := c.GetString("personal_history")
  7597. pulse := c.GetString("pulse")
  7598. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7599. sbp := c.GetString("sbp")
  7600. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7601. heightfloat, _ := strconv.ParseFloat(height, 64)
  7602. sicktype := c.GetString("sick_type")
  7603. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7604. symptom := c.GetString("symptom")
  7605. sick_date := c.GetString("sick_date")
  7606. temperatures := c.GetString("temperature")
  7607. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7608. record_date := c.GetString("record_date")
  7609. breathing := c.GetString("breathing")
  7610. doctor_advice := c.GetString("doctor_advice")
  7611. remark := c.GetString("remark")
  7612. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7613. sick, _ := c.GetInt64("sick")
  7614. diagnose, _ := c.GetInt64("diagnose")
  7615. //id, _ := c.GetInt64("id")
  7616. timeLayout := "2006-01-02"
  7617. loc, _ := time.LoadLocation("Local")
  7618. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7619. allergic_history := c.GetString("allergic_history")
  7620. if err != nil {
  7621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7622. return
  7623. }
  7624. recordDateTime := theTime.Unix()
  7625. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7626. if err != nil {
  7627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7628. return
  7629. }
  7630. sickTimes := sickTime.Unix()
  7631. ctime := time.Now().Unix()
  7632. primary_disease := c.GetString("primary_disease")
  7633. confirm_failure_date := c.GetString("confirm_failure_date")
  7634. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7635. drug_allergy_history := c.GetString("drug_allergy_history")
  7636. physical_examination := c.GetString("physical_examination")
  7637. special_inspection := c.GetString("special_inspection")
  7638. lab_apparatus := c.GetString("lab_apparatus")
  7639. caseHistory := models.HisPatientCaseHistory{
  7640. HisPatientId: his_patient_id,
  7641. PatientId: patient_id,
  7642. Temperature: temperature,
  7643. BloodSugar: bloodsugarfloat,
  7644. Pulse: pulsefloat,
  7645. Sbp: sbpfloat,
  7646. Dbp: dbpfloat,
  7647. Height: heightfloat,
  7648. BloodFat: bloodfatfloat,
  7649. SickType: sick_type,
  7650. Symptom: symptom,
  7651. SickDate: sickTimes,
  7652. IsInfect: is_infect,
  7653. HistoryOfPresentIllness: history_of_present_illness,
  7654. PastHistory: past_history,
  7655. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7656. ChiefConplaint: chief_conplaint,
  7657. PersonalHistory: personal_history,
  7658. FamilyHistory: family_history,
  7659. Diagnostic: diagnostic,
  7660. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7661. Status: 1,
  7662. Ctime: ctime,
  7663. Mtime: ctime,
  7664. RecordDate: recordDateTime,
  7665. DeliveryWay: delivery_way,
  7666. Breathing: breathingfloat,
  7667. DoctorAdvice: doctor_advice,
  7668. Remark: remark,
  7669. Sick: sick,
  7670. Diagnose: diagnose,
  7671. AllergicHistory: allergic_history,
  7672. PrimaryDisease: primary_disease,
  7673. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7674. DrugAllergyHistory: drug_allergy_history,
  7675. PhysicalExamination: physical_examination,
  7676. SpecialInspection: special_inspection,
  7677. LabApparatus: lab_apparatus,
  7678. }
  7679. //查询该患者是否有病历
  7680. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7681. if errcodes == gorm.ErrRecordNotFound {
  7682. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7683. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7684. if err != nil {
  7685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7686. return
  7687. }
  7688. c.ServeSuccessJSON(map[string]interface{}{
  7689. "caseHistory": caseHistory,
  7690. "historyInfo": historyInfo,
  7691. })
  7692. return
  7693. } else if errcodes == nil {
  7694. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7695. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7696. if err != nil {
  7697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7698. return
  7699. }
  7700. c.ServeSuccessJSON(map[string]interface{}{
  7701. "caseHistory": caseHistory,
  7702. "historyInfo": historyInfo,
  7703. })
  7704. }
  7705. //查询该患者是否有病历
  7706. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7707. //if errcode == gorm.ErrRecordNotFound {
  7708. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7709. // if err != nil {
  7710. // c.ServeSuccessJSON(map[string]interface{}{
  7711. // "msg": "保存成功",
  7712. // })
  7713. // }
  7714. //} else if errcode == nil {
  7715. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7716. // return
  7717. //}
  7718. }
  7719. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7720. patient_id, _ := c.GetInt64("patient_id", 0)
  7721. adminUser := c.GetAdminUserInfo()
  7722. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7723. c.ServeSuccessJSON(map[string]interface{}{
  7724. "list": caseHistorys,
  7725. })
  7726. }
  7727. func (c *HisApiController) GetHisPatientCaseHistory() {
  7728. record_date, _ := c.GetInt64("record_date", 0)
  7729. patient_id, _ := c.GetInt64("patient_id", 0)
  7730. admin := c.GetAdminUserInfo()
  7731. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7732. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7733. c.ServeSuccessJSON(map[string]interface{}{
  7734. "info": info,
  7735. "case_history": case_history,
  7736. })
  7737. }
  7738. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7739. template_name := c.GetString("template_name")
  7740. template_remark := c.GetString("template_remark")
  7741. doctor := c.GetAdminUserInfo().AdminUser.Id
  7742. diagnostic := c.GetString("diagnostic")
  7743. chief_conplaint := c.GetString("chief_conplain")
  7744. history_of_present_illness := c.GetString("history_of_present_illness")
  7745. past_history := c.GetString("past_history")
  7746. personal_history := c.GetString("personal_history")
  7747. family_history := c.GetString("family_history")
  7748. user_name := c.GetString("user_name")
  7749. doctor_advice := c.GetString("doctor_advice")
  7750. remark := c.GetString("remark")
  7751. //record_date := c.GetString("record_date")
  7752. //fmt.Println("record_date--------",record_date)
  7753. //timeLayout := "2006-01-02"
  7754. //loc, _ := time.LoadLocation("Local")
  7755. //
  7756. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7757. //if err != nil {
  7758. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7759. // return
  7760. //}
  7761. //recordDateTime := theTime.Unix()
  7762. ctime := time.Now().Unix()
  7763. template := models.HisCaseHistoryTemplate{
  7764. HistoryOfPresentIllness: history_of_present_illness,
  7765. PastHistory: past_history,
  7766. ChiefConplaint: chief_conplaint,
  7767. PersonalHistory: personal_history,
  7768. FamilyHistory: family_history,
  7769. Diagnostic: diagnostic,
  7770. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7771. Status: 1,
  7772. Ctime: ctime,
  7773. Mtime: ctime,
  7774. RecordDate: time.Now().Unix(),
  7775. TemplateName: template_name,
  7776. TemplateRemark: template_remark,
  7777. Creator: doctor,
  7778. Modifier: doctor,
  7779. UserName: user_name,
  7780. DoctorAdvice: doctor_advice,
  7781. Remark: remark,
  7782. }
  7783. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7784. if err == nil {
  7785. c.ServeSuccessJSON(map[string]interface{}{
  7786. "msg": "保存成功",
  7787. })
  7788. } else {
  7789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7790. return
  7791. }
  7792. }
  7793. func (c *HisApiController) GetCaseHistoryTemplate() {
  7794. timeLayout := "2006-01-02"
  7795. loc, _ := time.LoadLocation("Local")
  7796. keyword := c.GetString("keyword")
  7797. start_time := c.GetString("start_time")
  7798. end_time := c.GetString("end_time")
  7799. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7800. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7801. admin := c.GetAdminUserInfo()
  7802. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7803. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7804. c.ServeSuccessJSON(map[string]interface{}{
  7805. "template": template,
  7806. //"history": history,
  7807. })
  7808. }
  7809. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7810. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7811. utils.ErrorLog("drug_name")
  7812. return enums.ErrorCodeParamWrong
  7813. }
  7814. adviceName, _ := json["drug_name"].(string)
  7815. if len(adviceName) == 0 {
  7816. utils.ErrorLog("len(advice_name) == 0")
  7817. return enums.ErrorCodeParamWrong
  7818. }
  7819. advice.AdviceName = adviceName
  7820. adviceDesc, _ := json["advice_desc"].(string)
  7821. advice.AdviceDesc = adviceDesc
  7822. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7823. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7824. advice.DrugSpec = drugSpec
  7825. }
  7826. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7827. remark, _ := json["remark"].(string)
  7828. advice.Remark = remark
  7829. }
  7830. if json["id"] == nil {
  7831. advice.DrugId = 0
  7832. } else {
  7833. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7834. drug_id := int64(json["id"].(float64))
  7835. advice.DrugId = drug_id
  7836. }
  7837. }
  7838. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7839. advice_id := int64(json["advice_id"].(float64))
  7840. advice.ID = advice_id
  7841. if advice.ID > 0 {
  7842. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7843. if err == nil {
  7844. if hisAdvice.ID > 0 {
  7845. advice.ExecutionTime = hisAdvice.ExecutionTime
  7846. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7847. advice.ExecutionState = hisAdvice.ExecutionState
  7848. advice.CheckTime = hisAdvice.CheckTime
  7849. advice.Checker = hisAdvice.Checker
  7850. advice.CheckState = hisAdvice.CheckState
  7851. advice.StartTime = hisAdvice.StartTime
  7852. advice.FeedetlSn = hisAdvice.FeedetlSn
  7853. }
  7854. }
  7855. }
  7856. }
  7857. //
  7858. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7859. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7860. // advice.ExecutionTime = execution_time
  7861. //}
  7862. //
  7863. //
  7864. //
  7865. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7866. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7867. // advice.ExecutionStaff = execution_staff
  7868. //}
  7869. //
  7870. //
  7871. //
  7872. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7873. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7874. // advice.ExecutionState = execution_state
  7875. //}
  7876. //
  7877. //
  7878. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7879. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7880. // advice.CheckTime = check_time
  7881. //}
  7882. //
  7883. //
  7884. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7885. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7886. // advice.CheckState = check_state
  7887. //}
  7888. //
  7889. //
  7890. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7891. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7892. // advice.Checker = checker
  7893. //}
  7894. //
  7895. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7896. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7897. // advice.StartTime = start_time
  7898. //}
  7899. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7900. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7901. advice.IsSelfDrug = is_self_drug
  7902. }
  7903. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7904. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7905. drug_way_count, _ := json["drug_way_count"].(string)
  7906. advice.DrugWayCount = drug_way_count
  7907. }
  7908. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7909. drugSpecUnit, _ := json["min_unit"].(string)
  7910. advice.DrugSpecUnit = drugSpecUnit
  7911. }
  7912. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7913. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7914. advice.SingleDose = singleDose
  7915. }
  7916. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7917. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7918. advice.SingleDoseUnit = singleDoseUnit
  7919. }
  7920. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7921. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7922. advice.PrescribingNumber = prescribingNumber
  7923. }
  7924. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7925. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7926. advice.PrescribingNumberUnit = prescribingNumberUnit
  7927. }
  7928. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7929. deliveryWay, _ := json["delivery_way"].(string)
  7930. advice.DeliveryWay = deliveryWay
  7931. }
  7932. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7933. executionFrequency, _ := json["execution_frequency"].(string)
  7934. advice.ExecutionFrequency = executionFrequency
  7935. }
  7936. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7937. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7938. advice.Price = price
  7939. }
  7940. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7941. med_list_codg, _ := json["medical_insurance_number"].(string)
  7942. advice.MedListCodg = med_list_codg
  7943. }
  7944. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7945. day := int64(json["day"].(float64))
  7946. advice.Day = day
  7947. }
  7948. return 0
  7949. }
  7950. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7951. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7952. id := int64(json["id"].(float64))
  7953. project.ID = id
  7954. historyProject, _ := service.GetHisProjectByID(id)
  7955. project.FeedetlSn = historyProject.FeedetlSn
  7956. }
  7957. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7958. project_id := int64(json["project_id"].(float64))
  7959. project.ProjectId = project_id
  7960. }
  7961. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7962. // price := int64(json["price"].(float64))
  7963. // formatInt_price := strconv.FormatInt(price, 10)
  7964. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7965. // project.Price = float_price
  7966. // }
  7967. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7968. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7969. project.Price = price
  7970. }
  7971. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7972. total, _ := json["total"].(string)
  7973. project.Count = total
  7974. }
  7975. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7976. medical_code, _ := json["medical_code"].(string)
  7977. project.MedListCodg = medical_code
  7978. }
  7979. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7980. single_dose, _ := json["single_dose"].(string)
  7981. project.SingleDose = single_dose
  7982. }
  7983. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7984. delivery_way, _ := json["delivery_way"].(string)
  7985. project.DeliveryWay = delivery_way
  7986. }
  7987. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7988. execution_frequency, _ := json["execution_frequency"].(string)
  7989. project.ExecutionFrequency = execution_frequency
  7990. }
  7991. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7992. remark, _ := json["remark"].(string)
  7993. project.Remark = remark
  7994. }
  7995. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7996. day, _ := json["number_days"].(string)
  7997. project.Day = day
  7998. }
  7999. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8000. unit, _ := json["unit"].(string)
  8001. project.Unit = unit
  8002. }
  8003. return 0
  8004. }
  8005. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8006. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8007. id := int64(json["id"].(float64))
  8008. historyAddtions, _ := service.GetHisAdditionByID(id)
  8009. additionalCharge.ID = id
  8010. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  8011. }
  8012. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8013. item_id := int64(json["item_id"].(float64))
  8014. additionalCharge.ItemId = item_id
  8015. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8016. if config.ID > 0 {
  8017. if len(config.Code) > 0 {
  8018. additionalCharge.MedListCodg = config.Code
  8019. }
  8020. }
  8021. }
  8022. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8023. // price := int64(json["price"].(float64))
  8024. // formatInt_price := strconv.FormatInt(price, 10)
  8025. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8026. // additionalCharge.Price = float_price
  8027. // }
  8028. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8029. // price := int64(json["price"].(float64))
  8030. // formatInt_price := strconv.FormatInt(price, 10)
  8031. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8032. // additionalCharge.Price = float_price
  8033. //}
  8034. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8035. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8036. additionalCharge.Price = price
  8037. }
  8038. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8039. count, _ := json["count"].(string)
  8040. counts, _ := strconv.ParseInt(count, 10, 64)
  8041. additionalCharge.Count = counts
  8042. }
  8043. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8044. item_name, _ := json["item_name"].(string)
  8045. additionalCharge.ItemName = item_name
  8046. }
  8047. return 0
  8048. }
  8049. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8050. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8051. utils.ErrorLog("drug_name")
  8052. return enums.ErrorCodeParamWrong
  8053. }
  8054. adviceName, _ := json["drug_name"].(string)
  8055. if len(adviceName) == 0 {
  8056. utils.ErrorLog("len(advice_name) == 0")
  8057. return enums.ErrorCodeParamWrong
  8058. }
  8059. advice.AdviceName = adviceName
  8060. adviceDesc, _ := json["advice_desc"].(string)
  8061. advice.AdviceDesc = adviceDesc
  8062. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8063. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8064. advice.DrugSpec = drugSpec
  8065. }
  8066. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8067. remark, _ := json["remark"].(string)
  8068. advice.Remark = remark
  8069. }
  8070. if json["id"] == nil {
  8071. advice.DrugId = 0
  8072. } else {
  8073. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8074. drug_id := int64(json["id"].(float64))
  8075. advice.DrugId = drug_id
  8076. }
  8077. }
  8078. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8079. groupno := int64(json["groupno"].(float64))
  8080. advice.Groupno = groupno
  8081. }
  8082. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8083. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8084. advice.IsSelfDrug = is_self_drug
  8085. }
  8086. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8087. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8088. drug_way_count, _ := json["drug_way_count"].(string)
  8089. advice.DrugWayCount = drug_way_count
  8090. }
  8091. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8092. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8093. advice.HospApprFlag = hosp_appr_flag
  8094. }
  8095. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8096. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8097. advice.PrescribingNumber = prescribingNumber
  8098. }
  8099. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8100. // frequency_type := int64(json["frequency_type"].(float64))
  8101. // advice.FrequencyType = frequency_type
  8102. //}
  8103. //
  8104. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8105. // day_count := int64(json["day_count"].(float64))
  8106. // advice.DayCount = day_count
  8107. //}
  8108. //
  8109. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8110. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8111. // week_day, _ := json["week_day"].(string)
  8112. // advice.WeekDay = week_day
  8113. //}
  8114. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8115. drugSpecUnit, _ := json["min_unit"].(string)
  8116. advice.DrugSpecUnit = drugSpecUnit
  8117. }
  8118. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8119. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8120. advice.SingleDose = singleDose
  8121. }
  8122. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8123. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8124. advice.SingleDoseUnit = singleDoseUnit
  8125. }
  8126. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8127. deliveryWay, _ := json["delivery_way"].(string)
  8128. advice.DeliveryWay = deliveryWay
  8129. }
  8130. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8131. executionFrequency, _ := json["execution_frequency"].(string)
  8132. advice.ExecutionFrequency = executionFrequency
  8133. }
  8134. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8135. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8136. advice.Price = price
  8137. }
  8138. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8139. med_list_codg, _ := json["medical_insurance_number"].(string)
  8140. advice.MedListCodg = med_list_codg
  8141. }
  8142. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8143. day := int64(json["day"].(float64))
  8144. advice.Day = day
  8145. }
  8146. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8147. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8148. advice.PrescribingNumberUnit = prescribingNumberUnit
  8149. }
  8150. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8151. advice_id := int64(json["advice_id"].(float64))
  8152. advice.ID = advice_id
  8153. if advice.ID > 0 {
  8154. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8155. if err == nil {
  8156. if hisAdvice.ID > 0 {
  8157. advice.ExecutionTime = hisAdvice.ExecutionTime
  8158. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8159. advice.ExecutionState = hisAdvice.ExecutionState
  8160. advice.CheckTime = hisAdvice.CheckTime
  8161. advice.Checker = hisAdvice.Checker
  8162. advice.CheckState = hisAdvice.CheckState
  8163. advice.StartTime = hisAdvice.StartTime
  8164. advice.HospApprFlag = hisAdvice.HospApprFlag
  8165. advice.IsMedicine = hisAdvice.IsMedicine
  8166. if hisAdvice.UserOrgId == 10028 {
  8167. 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 {
  8168. advice.ExecutionTime = 0
  8169. advice.ExecutionStaff = 0
  8170. advice.ExecutionState = 2
  8171. advice.CheckTime = 0
  8172. advice.Checker = 0
  8173. advice.CheckState = 2
  8174. }
  8175. } else {
  8176. 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 {
  8177. advice.ExecutionTime = 0
  8178. advice.ExecutionStaff = 0
  8179. advice.ExecutionState = 2
  8180. advice.CheckTime = 0
  8181. advice.Checker = 0
  8182. advice.CheckState = 2
  8183. advice.UpdatedTime = time.Now().Unix()
  8184. }
  8185. }
  8186. //advice.Groupno = hisAdvice.Groupno
  8187. }
  8188. }
  8189. }
  8190. }
  8191. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8192. //
  8193. //if drugStockConfig.IsOpen == 1 {
  8194. //
  8195. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8196. // if advice.ID == 0 { //医嘱不存在
  8197. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8198. // drug.Total = drug.Total - advice.PrescribingNumber
  8199. // service.UpdateBaseDrugLib(&drug)
  8200. //
  8201. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8202. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8203. // drug.Total = drug.Total - num
  8204. // service.UpdateBaseDrugLib(&drug)
  8205. // }
  8206. //
  8207. // } else if advice.ID > 0 { //医嘱存在
  8208. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8209. // var num float64
  8210. //
  8211. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8212. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8213. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8214. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8215. // drug.Total = drug.Total + num
  8216. // service.UpdateBaseDrugLib(&drug)
  8217. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8218. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8219. // drug.Total = drug.Total - num
  8220. // service.UpdateBaseDrugLib(&drug)
  8221. // }
  8222. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8223. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8224. // if num2 > advice.PrescribingNumber {
  8225. // num = num2 - advice.PrescribingNumber
  8226. // drug.Total = drug.Total + num
  8227. // service.UpdateBaseDrugLib(&drug)
  8228. // } else if num2 < advice.PrescribingNumber {
  8229. // num = advice.PrescribingNumber - num2
  8230. // drug.Total = drug.Total - num
  8231. // service.UpdateBaseDrugLib(&drug)
  8232. // }
  8233. //
  8234. // }
  8235. //
  8236. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8237. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8238. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8239. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8240. // if num1 > num2 {
  8241. // num = num1 - num2
  8242. // drug.Total = drug.Total + num
  8243. // service.UpdateBaseDrugLib(&drug)
  8244. // } else if num1 < num2 {
  8245. // num = num2 - num1
  8246. // drug.Total = drug.Total - num
  8247. // service.UpdateBaseDrugLib(&drug)
  8248. // }
  8249. //
  8250. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8251. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8252. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8253. // if hisAdvice.PrescribingNumber > num2 {
  8254. // num = hisAdvice.PrescribingNumber - num2
  8255. // drug.Total = drug.Total + num
  8256. // service.UpdateBaseDrugLib(&drug)
  8257. // } else if num2 < advice.PrescribingNumber {
  8258. // num = num2 - hisAdvice.PrescribingNumber
  8259. // drug.Total = drug.Total - num
  8260. // service.UpdateBaseDrugLib(&drug)
  8261. // }
  8262. //
  8263. // }
  8264. // }
  8265. // }
  8266. //}
  8267. //
  8268. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8269. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8270. // advice.ExecutionTime = execution_time
  8271. //}
  8272. //
  8273. //
  8274. //
  8275. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8276. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8277. // advice.ExecutionStaff = execution_staff
  8278. //}
  8279. //
  8280. //
  8281. //
  8282. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8283. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8284. // advice.ExecutionState = execution_state
  8285. //}
  8286. //
  8287. //
  8288. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8289. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8290. // advice.CheckTime = check_time
  8291. //}
  8292. //
  8293. //
  8294. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8295. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8296. // advice.CheckState = check_state
  8297. //}
  8298. //
  8299. //
  8300. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8301. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8302. // advice.Checker = checker
  8303. //}
  8304. //
  8305. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8306. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8307. // advice.StartTime = start_time
  8308. //}
  8309. return 0
  8310. }
  8311. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8312. project.ExecutionStaff = 0
  8313. project.ExecutionState = 2
  8314. project.ExecutionTime = 0
  8315. project.Checker = 0
  8316. project.CheckState = 2
  8317. project.CheckTime = 0
  8318. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8319. id := int64(json["id"].(float64))
  8320. project.ID = id
  8321. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8322. project.ExecutionStaff = temp_project.ExecutionStaff
  8323. project.ExecutionState = temp_project.ExecutionState
  8324. project.ExecutionTime = temp_project.ExecutionTime
  8325. project.Checker = temp_project.Checker
  8326. project.CheckState = temp_project.CheckState
  8327. project.CheckTime = temp_project.CheckTime
  8328. project.TeamId = temp_project.TeamId
  8329. }
  8330. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8331. types := int64(json["type"].(float64))
  8332. project.Type = types
  8333. }
  8334. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8335. project_id := int64(json["project_id"].(float64))
  8336. project.ProjectId = project_id
  8337. }
  8338. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8339. team_id := int64(json["team_id"].(float64))
  8340. project.TeamId = team_id
  8341. }
  8342. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8343. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8344. project.Price = price
  8345. }
  8346. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8347. total, _ := json["total"].(string)
  8348. //totals, _ := strconv.ParseInt(total, 10, 64)
  8349. project.Count = total
  8350. }
  8351. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8352. medical_code, _ := json["medical_code"].(string)
  8353. project.MedListCodg = medical_code
  8354. }
  8355. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8356. single_dose, _ := json["single_dose"].(string)
  8357. project.SingleDose = single_dose
  8358. }
  8359. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8360. delivery_way, _ := json["delivery_way"].(string)
  8361. project.DeliveryWay = delivery_way
  8362. }
  8363. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8364. execution_frequency, _ := json["execution_frequency"].(string)
  8365. project.ExecutionFrequency = execution_frequency
  8366. }
  8367. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8368. remark, _ := json["remark"].(string)
  8369. project.Remark = remark
  8370. }
  8371. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8372. day, _ := json["number_days"].(string)
  8373. project.Day = day
  8374. }
  8375. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8376. unit, _ := json["unit"].(string)
  8377. project.Unit = unit
  8378. }
  8379. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8380. // frequency_type := int64(json["frequency_type"].(float64))
  8381. // project.FrequencyType = frequency_type
  8382. //}
  8383. //
  8384. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8385. // day_count := int64(json["day_count"].(float64))
  8386. // project.DayCount = day_count
  8387. //}
  8388. //
  8389. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8390. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8391. // week_day, _ := json["week_day"].(string)
  8392. // project.WeekDay = week_day
  8393. //}
  8394. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8395. //
  8396. //if project.ID == 0 {
  8397. // if stockConfig.IsOpen == 1 {
  8398. // if project.Type == 3 {
  8399. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8400. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8401. // good.Total = good.Total - f_count
  8402. // service.UpdateGoodInfo(&good)
  8403. // }
  8404. // }
  8405. //
  8406. //} else {
  8407. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8408. //
  8409. // if stockConfig.IsOpen == 1 {
  8410. // if project.Type == 3 {
  8411. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8412. // if project.Count < temp_project.Count {
  8413. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8414. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8415. //
  8416. // other_count := f_count_two - f_count_one
  8417. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8418. // good.Total = good.Total + other_count_two
  8419. // service.UpdateGoodInfo(&good)
  8420. // } else if project.Count > temp_project.Count {
  8421. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8422. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8423. //
  8424. // other_count := f_count_one - f_count_two
  8425. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8426. // good.Total = good.Total - other_count_two
  8427. // service.UpdateGoodInfo(&good)
  8428. // }
  8429. //
  8430. // }
  8431. // }
  8432. //
  8433. //}
  8434. return 0
  8435. }
  8436. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8437. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8438. utils.ErrorLog("drug_name")
  8439. return enums.ErrorCodeParamWrong
  8440. }
  8441. adviceName, _ := json["drug_name"].(string)
  8442. if len(adviceName) == 0 {
  8443. utils.ErrorLog("len(advice_name) == 0")
  8444. return enums.ErrorCodeParamWrong
  8445. }
  8446. advice.AdviceName = adviceName
  8447. adviceDesc, _ := json["advice_desc"].(string)
  8448. advice.AdviceDesc = adviceDesc
  8449. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8450. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8451. advice.DrugSpec = drugSpec
  8452. }
  8453. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8454. remark, _ := json["remark"].(string)
  8455. advice.Remark = remark
  8456. }
  8457. if json["id"] == nil {
  8458. advice.DrugId = 0
  8459. } else {
  8460. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8461. drug_id := int64(json["id"].(float64))
  8462. advice.DrugId = drug_id
  8463. }
  8464. }
  8465. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8466. groupno := int64(json["groupno"].(float64))
  8467. advice.Groupno = groupno
  8468. }
  8469. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8470. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8471. advice.IsSelfDrug = is_self_drug
  8472. }
  8473. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8474. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8475. drug_way_count, _ := json["drug_way_count"].(string)
  8476. advice.DrugWayCount = drug_way_count
  8477. }
  8478. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8479. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8480. advice.HospApprFlag = hosp_appr_flag
  8481. }
  8482. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8483. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8484. advice.PrescribingNumber = prescribingNumber
  8485. }
  8486. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8487. // frequency_type := int64(json["frequency_type"].(float64))
  8488. // advice.FrequencyType = frequency_type
  8489. //}
  8490. //
  8491. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8492. // day_count := int64(json["day_count"].(float64))
  8493. // advice.DayCount = day_count
  8494. //}
  8495. //
  8496. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8497. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8498. // week_day, _ := json["week_day"].(string)
  8499. // advice.WeekDay = week_day
  8500. //}
  8501. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8502. drugSpecUnit, _ := json["min_unit"].(string)
  8503. advice.DrugSpecUnit = drugSpecUnit
  8504. }
  8505. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8506. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8507. advice.SingleDose = singleDose
  8508. }
  8509. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8510. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8511. advice.SingleDoseUnit = singleDoseUnit
  8512. }
  8513. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8514. deliveryWay, _ := json["delivery_way"].(string)
  8515. advice.DeliveryWay = deliveryWay
  8516. }
  8517. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8518. executionFrequency, _ := json["execution_frequency"].(string)
  8519. advice.ExecutionFrequency = executionFrequency
  8520. }
  8521. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8522. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8523. advice.Price = price
  8524. }
  8525. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8526. med_list_codg, _ := json["medical_insurance_number"].(string)
  8527. advice.MedListCodg = med_list_codg
  8528. }
  8529. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8530. day := int64(json["day"].(float64))
  8531. advice.Day = day
  8532. }
  8533. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8534. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8535. advice.PrescribingNumberUnit = prescribingNumberUnit
  8536. }
  8537. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8538. advice_id := int64(json["advice_id"].(float64))
  8539. advice.ID = advice_id
  8540. if advice.ID > 0 {
  8541. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8542. if err == nil {
  8543. if hisAdvice.ID > 0 {
  8544. advice.ExecutionTime = hisAdvice.ExecutionTime
  8545. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8546. advice.ExecutionState = hisAdvice.ExecutionState
  8547. advice.CheckTime = hisAdvice.CheckTime
  8548. advice.Checker = hisAdvice.Checker
  8549. advice.DrugCode = hisAdvice.DrugCode
  8550. advice.CheckState = hisAdvice.CheckState
  8551. advice.StartTime = hisAdvice.StartTime
  8552. advice.HospApprFlag = hisAdvice.HospApprFlag
  8553. advice.IsMedicine = hisAdvice.IsMedicine
  8554. if hisAdvice.UserOrgId == 10028 {
  8555. 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 {
  8556. advice.ExecutionTime = 0
  8557. advice.ExecutionStaff = 0
  8558. advice.ExecutionState = 2
  8559. advice.CheckTime = 0
  8560. advice.Checker = 0
  8561. advice.CheckState = 2
  8562. }
  8563. } else {
  8564. 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 {
  8565. advice.ExecutionTime = 0
  8566. advice.ExecutionStaff = 0
  8567. advice.ExecutionState = 2
  8568. advice.CheckTime = 0
  8569. advice.Checker = 0
  8570. advice.CheckState = 2
  8571. //advice.UpdatedTime = time.Now().Unix()
  8572. advice.CreatedTime = hisAdvice.CreatedTime
  8573. advice.UpdatedTime = time.Now().Unix()
  8574. } else {
  8575. advice.CreatedTime = hisAdvice.CreatedTime
  8576. advice.UpdatedTime = hisAdvice.UpdatedTime
  8577. }
  8578. }
  8579. //advice.Groupno = hisAdvice.Groupno
  8580. } else {
  8581. advice.IsMedicine = 0
  8582. ctime := time.Now().Unix()
  8583. advice.CreatedTime = ctime
  8584. advice.UpdatedTime = ctime
  8585. }
  8586. }
  8587. } else {
  8588. advice.IsMedicine = 0
  8589. ctime := time.Now().Unix()
  8590. advice.CreatedTime = ctime
  8591. advice.UpdatedTime = ctime
  8592. }
  8593. }
  8594. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8595. //
  8596. //if drugStockConfig.IsOpen == 1 {
  8597. //
  8598. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8599. // if advice.ID == 0 { //医嘱不存在
  8600. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8601. // drug.Total = drug.Total - advice.PrescribingNumber
  8602. // service.UpdateBaseDrugLib(&drug)
  8603. //
  8604. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8605. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8606. // drug.Total = drug.Total - num
  8607. // service.UpdateBaseDrugLib(&drug)
  8608. // }
  8609. //
  8610. // } else if advice.ID > 0 { //医嘱存在
  8611. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8612. // var num float64
  8613. //
  8614. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8615. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8616. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8617. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8618. // drug.Total = drug.Total + num
  8619. // service.UpdateBaseDrugLib(&drug)
  8620. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8621. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8622. // drug.Total = drug.Total - num
  8623. // service.UpdateBaseDrugLib(&drug)
  8624. // }
  8625. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8626. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8627. // if num2 > advice.PrescribingNumber {
  8628. // num = num2 - advice.PrescribingNumber
  8629. // drug.Total = drug.Total + num
  8630. // service.UpdateBaseDrugLib(&drug)
  8631. // } else if num2 < advice.PrescribingNumber {
  8632. // num = advice.PrescribingNumber - num2
  8633. // drug.Total = drug.Total - num
  8634. // service.UpdateBaseDrugLib(&drug)
  8635. // }
  8636. //
  8637. // }
  8638. //
  8639. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8640. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8641. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8642. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8643. // if num1 > num2 {
  8644. // num = num1 - num2
  8645. // drug.Total = drug.Total + num
  8646. // service.UpdateBaseDrugLib(&drug)
  8647. // } else if num1 < num2 {
  8648. // num = num2 - num1
  8649. // drug.Total = drug.Total - num
  8650. // service.UpdateBaseDrugLib(&drug)
  8651. // }
  8652. //
  8653. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8654. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8655. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8656. // if hisAdvice.PrescribingNumber > num2 {
  8657. // num = hisAdvice.PrescribingNumber - num2
  8658. // drug.Total = drug.Total + num
  8659. // service.UpdateBaseDrugLib(&drug)
  8660. // } else if num2 < advice.PrescribingNumber {
  8661. // num = num2 - hisAdvice.PrescribingNumber
  8662. // drug.Total = drug.Total - num
  8663. // service.UpdateBaseDrugLib(&drug)
  8664. // }
  8665. //
  8666. // }
  8667. // }
  8668. // }
  8669. //}
  8670. //
  8671. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8672. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8673. // advice.ExecutionTime = execution_time
  8674. //}
  8675. //
  8676. //
  8677. //
  8678. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8679. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8680. // advice.ExecutionStaff = execution_staff
  8681. //}
  8682. //
  8683. //
  8684. //
  8685. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8686. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8687. // advice.ExecutionState = execution_state
  8688. //}
  8689. //
  8690. //
  8691. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8692. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8693. // advice.CheckTime = check_time
  8694. //}
  8695. //
  8696. //
  8697. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8698. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8699. // advice.CheckState = check_state
  8700. //}
  8701. //
  8702. //
  8703. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8704. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8705. // advice.Checker = checker
  8706. //}
  8707. //
  8708. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8709. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8710. // advice.StartTime = start_time
  8711. //}
  8712. return 0
  8713. }
  8714. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8715. project.ExecutionStaff = 0
  8716. project.ExecutionState = 2
  8717. project.ExecutionTime = 0
  8718. project.Checker = 0
  8719. project.CheckState = 2
  8720. project.CheckTime = 0
  8721. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8722. id := int64(json["id"].(float64))
  8723. project.ID = id
  8724. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8725. project.ExecutionStaff = temp_project.ExecutionStaff
  8726. project.ExecutionState = temp_project.ExecutionState
  8727. project.ExecutionTime = temp_project.ExecutionTime
  8728. project.Checker = temp_project.Checker
  8729. project.CheckState = temp_project.CheckState
  8730. project.CheckTime = temp_project.CheckTime
  8731. project.TeamId = temp_project.TeamId
  8732. }
  8733. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8734. types := int64(json["type"].(float64))
  8735. project.Type = types
  8736. }
  8737. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8738. project_id := int64(json["project_id"].(float64))
  8739. project.ProjectId = project_id
  8740. }
  8741. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8742. team_id := int64(json["team_id"].(float64))
  8743. project.TeamId = team_id
  8744. }
  8745. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8746. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8747. project.Price = price
  8748. }
  8749. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8750. total, _ := json["total"].(string)
  8751. //totals, _ := strconv.ParseInt(total, 10, 64)
  8752. project.Count = total
  8753. }
  8754. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8755. medical_code, _ := json["medical_code"].(string)
  8756. project.MedListCodg = medical_code
  8757. }
  8758. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8759. single_dose, _ := json["single_dose"].(string)
  8760. project.SingleDose = single_dose
  8761. }
  8762. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8763. delivery_way, _ := json["delivery_way"].(string)
  8764. project.DeliveryWay = delivery_way
  8765. }
  8766. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8767. execution_frequency, _ := json["execution_frequency"].(string)
  8768. project.ExecutionFrequency = execution_frequency
  8769. }
  8770. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8771. remark, _ := json["remark"].(string)
  8772. project.Remark = remark
  8773. }
  8774. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8775. day, _ := json["number_days"].(string)
  8776. project.Day = day
  8777. }
  8778. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8779. unit, _ := json["unit"].(string)
  8780. project.Unit = unit
  8781. }
  8782. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8783. // frequency_type := int64(json["frequency_type"].(float64))
  8784. // project.FrequencyType = frequency_type
  8785. //}
  8786. //
  8787. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8788. // day_count := int64(json["day_count"].(float64))
  8789. // project.DayCount = day_count
  8790. //}
  8791. //
  8792. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8793. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8794. // week_day, _ := json["week_day"].(string)
  8795. // project.WeekDay = week_day
  8796. //}
  8797. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8798. //
  8799. //if project.ID == 0 {
  8800. // if stockConfig.IsOpen == 1 {
  8801. // if project.Type == 3 {
  8802. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8803. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8804. // good.Total = good.Total - f_count
  8805. // service.UpdateGoodInfo(&good)
  8806. // }
  8807. // }
  8808. //
  8809. //} else {
  8810. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8811. //
  8812. // if stockConfig.IsOpen == 1 {
  8813. // if project.Type == 3 {
  8814. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8815. // if project.Count < temp_project.Count {
  8816. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8817. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8818. //
  8819. // other_count := f_count_two - f_count_one
  8820. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8821. // good.Total = good.Total + other_count_two
  8822. // service.UpdateGoodInfo(&good)
  8823. // } else if project.Count > temp_project.Count {
  8824. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8825. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8826. //
  8827. // other_count := f_count_one - f_count_two
  8828. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8829. // good.Total = good.Total - other_count_two
  8830. // service.UpdateGoodInfo(&good)
  8831. // }
  8832. //
  8833. // }
  8834. // }
  8835. //
  8836. //}
  8837. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8838. id := int64(json["id"].(float64))
  8839. if id > 0 {
  8840. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8841. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8842. fmt.Println("666666")
  8843. project.Mtime = time.Now().Unix()
  8844. project.Ctime = temp_project.Ctime
  8845. } else {
  8846. project.Mtime = temp_project.Mtime
  8847. project.Ctime = temp_project.Ctime
  8848. }
  8849. } else {
  8850. ctime := time.Now().Unix()
  8851. project.Mtime = ctime
  8852. project.Ctime = ctime
  8853. }
  8854. }
  8855. return 0
  8856. }
  8857. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8858. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8859. id := int64(json["id"].(float64))
  8860. additionalCharge.ID = id
  8861. }
  8862. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8863. item_id := int64(json["item_id"].(float64))
  8864. additionalCharge.ItemId = item_id
  8865. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8866. if config.ID > 0 {
  8867. if len(config.Code) > 0 {
  8868. additionalCharge.MedListCodg = config.Code
  8869. }
  8870. }
  8871. }
  8872. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8873. // price := int64(json["price"].(float64))
  8874. // formatInt_price := strconv.FormatInt(price, 10)
  8875. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8876. // additionalCharge.Price = float_price
  8877. // }
  8878. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8879. // price := int64(json["price"].(float64))
  8880. // formatInt_price := strconv.FormatInt(price, 10)
  8881. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8882. // additionalCharge.Price = float_price
  8883. //}
  8884. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8885. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8886. additionalCharge.Price = price
  8887. }
  8888. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8889. count, _ := json["count"].(string)
  8890. counts, _ := strconv.ParseInt(count, 10, 64)
  8891. additionalCharge.Count = counts
  8892. }
  8893. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8894. item_name, _ := json["item_name"].(string)
  8895. additionalCharge.ItemName = item_name
  8896. }
  8897. return 0
  8898. }
  8899. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8900. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8901. utils.ErrorLog("drug_name")
  8902. return enums.ErrorCodeParamWrong
  8903. }
  8904. adviceName, _ := json["drug_name"].(string)
  8905. if len(adviceName) == 0 {
  8906. utils.ErrorLog("len(advice_name) == 0")
  8907. return enums.ErrorCodeParamWrong
  8908. }
  8909. advice.AdviceName = adviceName
  8910. adviceDesc, _ := json["advice_desc"].(string)
  8911. advice.AdviceDesc = adviceDesc
  8912. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8913. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8914. advice.DrugSpec = drugSpec
  8915. }
  8916. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8917. remark, _ := json["remark"].(string)
  8918. advice.Remark = remark
  8919. }
  8920. if json["id"] == nil {
  8921. advice.DrugId = 0
  8922. } else {
  8923. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8924. drug_id := int64(json["id"].(float64))
  8925. advice.DrugId = drug_id
  8926. }
  8927. }
  8928. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8929. groupno := int64(json["groupno"].(float64))
  8930. advice.Groupno = groupno
  8931. }
  8932. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8933. drugSpecUnit, _ := json["min_unit"].(string)
  8934. advice.DrugSpecUnit = drugSpecUnit
  8935. }
  8936. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8937. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8938. advice.SingleDose = singleDose
  8939. }
  8940. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8941. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8942. advice.SingleDoseUnit = singleDoseUnit
  8943. }
  8944. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8945. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8946. advice.PrescribingNumber = prescribingNumber
  8947. }
  8948. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8949. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8950. advice.PrescribingNumberUnit = prescribingNumberUnit
  8951. }
  8952. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8953. deliveryWay, _ := json["delivery_way"].(string)
  8954. advice.DeliveryWay = deliveryWay
  8955. }
  8956. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8957. executionFrequency, _ := json["execution_frequency"].(string)
  8958. advice.ExecutionFrequency = executionFrequency
  8959. }
  8960. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8961. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8962. advice.Price = price
  8963. }
  8964. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8965. med_list_codg, _ := json["medical_insurance_number"].(string)
  8966. advice.MedListCodg = med_list_codg
  8967. }
  8968. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8969. day := int64(json["day"].(float64))
  8970. advice.Day = day
  8971. }
  8972. advice.FrequencyType = 1
  8973. return 0
  8974. }
  8975. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8976. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8977. types := int64(json["type"].(float64))
  8978. project.Type = types
  8979. }
  8980. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8981. project_id := int64(json["project_id"].(float64))
  8982. project.ProjectId = project_id
  8983. }
  8984. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8985. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8986. project.Price = price
  8987. }
  8988. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8989. total, _ := json["total"].(string)
  8990. //totals, _ := strconv.ParseInt(total, 10, 64)
  8991. project.Count = total
  8992. }
  8993. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8994. medical_code, _ := json["medical_code"].(string)
  8995. project.MedListCodg = medical_code
  8996. }
  8997. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8998. single_dose, _ := json["single_dose"].(string)
  8999. project.SingleDose = single_dose
  9000. }
  9001. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  9002. delivery_way, _ := json["delivery_way"].(string)
  9003. project.DeliveryWay = delivery_way
  9004. }
  9005. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  9006. execution_frequency, _ := json["execution_frequency"].(string)
  9007. project.ExecutionFrequency = execution_frequency
  9008. }
  9009. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  9010. remark, _ := json["remark"].(string)
  9011. project.Remark = remark
  9012. }
  9013. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  9014. day, _ := json["number_days"].(string)
  9015. project.Day = day
  9016. }
  9017. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  9018. unit, _ := json["unit"].(string)
  9019. project.Unit = unit
  9020. }
  9021. project.FrequencyType = 1
  9022. return 0
  9023. }
  9024. func (c *HisApiController) GetHisOrderListTwo() {
  9025. start_time := c.GetString("start_time")
  9026. end_time := c.GetString("end_time")
  9027. timeLayout := "2006-01-02"
  9028. loc, _ := time.LoadLocation("Local")
  9029. var startTime int64
  9030. if len(start_time) > 0 {
  9031. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9032. if err != nil {
  9033. //fmt.Println(err)
  9034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9035. return
  9036. }
  9037. startTime = theTime.Unix()
  9038. }
  9039. var endTime int64
  9040. if len(end_time) > 0 {
  9041. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9042. if err != nil {
  9043. utils.ErrorLog(err.Error())
  9044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9045. return
  9046. }
  9047. endTime = theTime.Unix()
  9048. }
  9049. adminUser := c.GetAdminUserInfo()
  9050. org_id := adminUser.CurrentOrgId
  9051. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  9052. if err == nil {
  9053. c.ServeSuccessJSON(map[string]interface{}{
  9054. "order2": order,
  9055. })
  9056. } else {
  9057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9058. return
  9059. }
  9060. }
  9061. func (c *HisApiController) GetHisOrderList() {
  9062. page, _ := c.GetInt64("page", -1)
  9063. limit, _ := c.GetInt64("limit", -1)
  9064. start_time := c.GetString("start_time")
  9065. end_time := c.GetString("end_time")
  9066. types, _ := c.GetInt64("type", 0)
  9067. keywords := c.GetString("keywords")
  9068. p_type, _ := c.GetInt64("p_type", 0)
  9069. sort_type, _ := c.GetInt64("sort_type", 0)
  9070. charge_type, _ := c.GetInt64("charge_type", 0)
  9071. sch_type, _ := c.GetInt64("sch_type", 0)
  9072. zone_type, _ := c.GetInt64("zone_type", 0)
  9073. med_type, _ := c.GetInt64("med_type", 0)
  9074. fee_type, _ := c.GetInt64("fee_type", 0)
  9075. timeLayout := "2006-01-02"
  9076. loc, _ := time.LoadLocation("Local")
  9077. var startTime int64
  9078. if len(start_time) > 0 {
  9079. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9080. if err != nil {
  9081. //fmt.Println(err)
  9082. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9083. return
  9084. }
  9085. startTime = theTime.Unix()
  9086. }
  9087. var endTime int64
  9088. if len(end_time) > 0 {
  9089. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9090. if err != nil {
  9091. utils.ErrorLog(err.Error())
  9092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9093. return
  9094. }
  9095. endTime = theTime.Unix()
  9096. }
  9097. adminUser := c.GetAdminUserInfo()
  9098. org_id := adminUser.CurrentOrgId
  9099. 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, fee_type)
  9100. for _, item := range order {
  9101. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  9102. item.DoctorName = info.Doctor
  9103. item.DepartmentName = info.XtHisDepartment.Name
  9104. }
  9105. if err == nil {
  9106. c.ServeSuccessJSON(map[string]interface{}{
  9107. "order": order,
  9108. "total": total,
  9109. })
  9110. } else {
  9111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9112. return
  9113. }
  9114. }
  9115. func (c *HisApiController) GetHisOrder() {
  9116. patient_id, _ := c.GetInt64("patient_id", 0)
  9117. number := c.GetString("number")
  9118. adminInfo := c.GetAdminUserInfo()
  9119. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  9120. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  9121. if err == nil {
  9122. c.ServeSuccessJSON(map[string]interface{}{
  9123. "order": order,
  9124. "prescription": prescriptions,
  9125. })
  9126. } else {
  9127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9128. return
  9129. }
  9130. }
  9131. func (c *HisApiController) GetHisPrescriptionList() {
  9132. record_date := c.GetString("record_date")
  9133. keywords := c.GetString("keywords")
  9134. page, _ := c.GetInt64("page")
  9135. limit, _ := c.GetInt64("limit")
  9136. sch_type, _ := c.GetInt64("sch_type")
  9137. timeLayout := "2006-01-02"
  9138. loc, _ := time.LoadLocation("Local")
  9139. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9140. if err != nil {
  9141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9142. return
  9143. }
  9144. recordDateTime := theTime.Unix()
  9145. adminInfo := c.GetAdminUserInfo()
  9146. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  9147. //adminInfo := c.GetAdminUserInfo()
  9148. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  9149. //fmt.Println(prescriptionOrder)
  9150. if err == nil {
  9151. c.ServeSuccessJSON(map[string]interface{}{
  9152. "order": prescriptionOrder,
  9153. "total": total,
  9154. })
  9155. } else {
  9156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9157. return
  9158. }
  9159. }
  9160. func (c *HisApiController) GetHisPrescriptionInfo() {
  9161. id, _ := c.GetInt64("id")
  9162. adminInfo := c.GetAdminUserInfo()
  9163. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  9164. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  9165. if err == nil {
  9166. c.ServeSuccessJSON(map[string]interface{}{
  9167. "order": prescriptionOrder,
  9168. "prescription": prescription,
  9169. })
  9170. } else {
  9171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9172. return
  9173. }
  9174. }
  9175. func (c *HisApiController) GetMedicalInsuranceConfig() {
  9176. adminUser := c.GetAdminUserInfo()
  9177. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  9178. c.ServeSuccessJSON(map[string]interface{}{
  9179. "config": config,
  9180. })
  9181. }
  9182. type ResultTwo struct {
  9183. ErrMsg interface{} `json:"err_msg"`
  9184. InfRefmsgid string `json:"inf_refmsgid"`
  9185. Infcode int64 `json:"infcode"`
  9186. Output struct {
  9187. Baseinfo struct {
  9188. Age float64 `json:"age"`
  9189. Brdy string `json:"brdy"`
  9190. Certno string `json:"certno"`
  9191. Gend string `json:"gend"`
  9192. Naty string `json:"naty"`
  9193. PsnCertType string `json:"psn_cert_type"`
  9194. PsnName string `json:"psn_name"`
  9195. PsnNo string `json:"psn_no"`
  9196. } `json:"baseinfo"`
  9197. Idetinfo []interface{} `json:"idetinfo"`
  9198. Iinfo []struct {
  9199. Balc float64 `json:"balc"`
  9200. CvlservFlag string `json:"cvlserv_flag"`
  9201. EmpName string `json:"emp_name"`
  9202. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  9203. Insutype string `json:"insutype"`
  9204. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  9205. PausInsuDate interface{} `json:"paus_insu_date"`
  9206. PsnInsuDate string `json:"psn_insu_date"`
  9207. PsnInsuStas string `json:"psn_insu_stas"`
  9208. PsnType string `json:"psn_type"`
  9209. } `json:"insuinfo"`
  9210. } `json:"output"`
  9211. RefmsgTime string `json:"refmsg_time"`
  9212. RespondTime string `json:"respond_time"`
  9213. Signtype interface{} `json:"signtype"`
  9214. WarnInfo interface{} `json:"warn_info"`
  9215. }
  9216. type ResultThree struct {
  9217. Cainfo interface{} `json:"cainfo"`
  9218. ErrMsg interface{} `json:"err_msg"`
  9219. InfRefmsgid string `json:"inf_refmsgid"`
  9220. Infcode int64 `json:"infcode"`
  9221. Output struct {
  9222. Data struct {
  9223. IptOtpNo string `json:"ipt_otp_no"`
  9224. MdtrtID string `json:"mdtrt_id"`
  9225. PsnNo string `json:"psn_no"`
  9226. } `json:"data"`
  9227. } `json:"output"`
  9228. RefmsgTime string `json:"refmsg_time"`
  9229. RespondTime string `json:"respond_time"`
  9230. Signtype interface{} `json:"signtype"`
  9231. WarnMsg interface{} `json:"warn_msg"`
  9232. }
  9233. type ResultFour struct {
  9234. Cainfo string `json:"cainfo"`
  9235. ErrMsg string `json:"err_msg"`
  9236. InfRefmsgid string `json:"inf_refmsgid"`
  9237. Infcode int64 `json:"infcode"`
  9238. Output struct {
  9239. Result []struct {
  9240. BasMednFlag string `json:"bas_medn_flag"`
  9241. ChldMedcFlag string `json:"chld_medc_flag"`
  9242. ChrgitmLv string `json:"chrgitm_lv"`
  9243. Cnt float64 `json:"cnt"`
  9244. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  9245. DrtReimFlag string `json:"drt_reim_flag"`
  9246. FeedetlSn string `json:"feedetl_sn"`
  9247. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9248. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  9249. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9250. ListSpItemFlag string `json:"list_sp_item_flag"`
  9251. LmtUsedFlag string `json:"lmt_used_flag"`
  9252. MedChrgitmType string `json:"med_chrgitm_type"`
  9253. Memo string `json:"memo"`
  9254. OverlmtAmt float64 `json:"overlmt_amt"`
  9255. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9256. Pric float64 `json:"pric"`
  9257. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  9258. SelfpayProp float64 `json:"selfpay_prop"`
  9259. } `json:"result"`
  9260. } `json:"output"`
  9261. RefmsgTime string `json:"refmsg_time"`
  9262. RespondTime string `json:"respond_time"`
  9263. Signtype string `json:"signtype"`
  9264. WarnMsg string `json:"warn_msg"`
  9265. }
  9266. type ResultFive struct {
  9267. Insutype string `json:"insutype"`
  9268. }
  9269. type ResultSix struct {
  9270. Cainfo interface{} `json:"cainfo"`
  9271. ErrMsg interface{} `json:"err_msg"`
  9272. InfRefmsgid string `json:"inf_refmsgid"`
  9273. Infcode int64 `json:"infcode"`
  9274. Output struct {
  9275. } `json:"output"`
  9276. RefmsgTime string `json:"refmsg_time"`
  9277. RespondTime string `json:"respond_time"`
  9278. Signtype interface{} `json:"signtype"`
  9279. WarnMsg interface{} `json:"warn_msg"`
  9280. }
  9281. type ResultSeven struct {
  9282. Cainfo string `json:"cainfo"`
  9283. ErrMsg string `json:"err_msg"`
  9284. InfRefmsgid string `json:"inf_refmsgid"`
  9285. Infcode int64 `json:"infcode"`
  9286. Output struct {
  9287. Setldetail []interface{} `json:"setldetail"`
  9288. Setlinfo struct {
  9289. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9290. AcctPay float64 `json:"acct_pay"`
  9291. ActPayDedc float64 `json:"act_pay_dedc"`
  9292. Age float64 `json:"age"`
  9293. Balc float64 `json:"balc"`
  9294. Brdy string `json:"brdy"`
  9295. Certno string `json:"certno"`
  9296. ClrOptins string `json:"clr_optins"`
  9297. ClrType string `json:"clr_type"`
  9298. ClrWay string `json:"clr_way"`
  9299. CvlservFlag string `json:"cvlserv_flag"`
  9300. CvlservPay float64 `json:"cvlserv_pay"`
  9301. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9302. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9303. Gend string `json:"gend"`
  9304. HifesPay float64 `json:"hifes_pay"`
  9305. HifmiPay float64 `json:"hifmi_pay"`
  9306. HifobPay float64 `json:"hifob_pay"`
  9307. HifpPay float64 `json:"hifp_pay"`
  9308. HospPartAmt float64 `json:"hosp_part_amt"`
  9309. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9310. Insutype string `json:"insutype"`
  9311. MafPay float64 `json:"maf_pay"`
  9312. MdtrtCertType string `json:"mdtrt_cert_type"`
  9313. MdtrtID string `json:"mdtrt_id"`
  9314. MedType string `json:"med_type"`
  9315. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9316. MedinsSetlID string `json:"medins_setl_id"`
  9317. Naty string `json:"naty"`
  9318. OthPay float64 `json:"oth_pay"`
  9319. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9320. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9321. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9322. PsnCashPay float64 `json:"psn_cash_pay"`
  9323. PsnCertType string `json:"psn_cert_type"`
  9324. PsnName string `json:"psn_name"`
  9325. PsnNo string `json:"psn_no"`
  9326. PsnPartAmt float64 `json:"psn_part_amt"`
  9327. PsnType string `json:"psn_type"`
  9328. SetlID string `json:"setl_id"`
  9329. SetlTime string `json:"setl_time"`
  9330. } `json:"setlinfo"`
  9331. } `json:"output"`
  9332. RefmsgTime string `json:"refmsg_time"`
  9333. RespondTime string `json:"respond_time"`
  9334. Signtype interface{} `json:"signtype"`
  9335. WarnMsg interface{} `json:"warn_msg"`
  9336. }
  9337. type ResultEight struct {
  9338. Cainfo string `json:"cainfo"`
  9339. ErrMsg string `json:"err_msg"`
  9340. InfRefmsgid string `json:"inf_refmsgid"`
  9341. Infcode int64 `json:"infcode"`
  9342. Output struct {
  9343. Stmtinfo struct {
  9344. SetlOptins string `json:"setl_optins"`
  9345. StmtRslt string `json:"stmt_rslt"`
  9346. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  9347. } `json:"stmtinfo"`
  9348. } `json:"output"`
  9349. RefmsgTime string `json:"refmsg_time"`
  9350. RespondTime string `json:"respond_time"`
  9351. Signtype interface{} `json:"signtype"`
  9352. WarnMsg interface{} `json:"warn_msg"`
  9353. }
  9354. type ResultNine struct {
  9355. Cainfo string `json:"cainfo"`
  9356. ErrMsg string `json:"err_msg"`
  9357. InfRefmsgid string `json:"inf_refmsgid"`
  9358. Infcode int64 `json:"infcode"`
  9359. Output struct {
  9360. FileQuryNo string `json:"file_qury_no"`
  9361. } `json:"output"`
  9362. RefmsgTime string `json:"refmsg_time"`
  9363. RespondTime string `json:"respond_time"`
  9364. Signtype interface{} `json:"signtype"`
  9365. WarnMsg interface{} `json:"warn_msg"`
  9366. }
  9367. type ResultTen struct {
  9368. Cainfo string `json:"cainfo"`
  9369. ErrMsg string `json:"err_msg"`
  9370. InfRefmsgid string `json:"inf_refmsgid"`
  9371. Infcode int64 `json:"infcode"`
  9372. Output struct {
  9373. DldEndtime string `json:"dld_endtime"`
  9374. FileQuryNo string `json:"file_qury_no"`
  9375. Filename string `json:"filename"`
  9376. } `json:"output"`
  9377. RefmsgTime string `json:"refmsg_time"`
  9378. RespondTime string `json:"respond_time"`
  9379. Signtype interface{} `json:"signtype"`
  9380. WarnMsg interface{} `json:"warn_msg"`
  9381. }
  9382. type ResultEleven struct {
  9383. Cainfo string `json:"cainfo"`
  9384. ErrMsg string `json:"err_msg"`
  9385. InfRefmsgid string `json:"inf_refmsgid"`
  9386. Infcode int64 `json:"infcode"`
  9387. Output struct {
  9388. Setlinfo struct {
  9389. FixmedinsName string `json:"fixmedins_name"`
  9390. FixmedinsCode string `json:"fixmedins_code"`
  9391. PsnNo string `json:"psn_no"`
  9392. PsnName string `json:"psn_name"`
  9393. HifobPay float64 `json:"hifob_pay"`
  9394. Gend string `json:"gend"`
  9395. Brdy string `json:"brdy"`
  9396. PsnCertType string `json:"psn_cert_type"`
  9397. PsnType string `json:"psn_type"`
  9398. EmpName string `json:"emp_name"`
  9399. Certno string `json:"certno"`
  9400. Insutype string `json:"insutype"`
  9401. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9402. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9403. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9404. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9405. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9406. ActPayDedc float64 `json:"act_pay_dedc"`
  9407. HifpPay float64 `json:"hifp_pay"`
  9408. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9409. CvlservPay float64 `json:"cvlserv_pay"`
  9410. HifesPay float64 `json:"hifes_pay"`
  9411. HifmiPay float64 `json:"hifmi_pay"`
  9412. MafPay float64 `json:"maf_pay"`
  9413. OthPay float64 `json:"oth_pay"`
  9414. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9415. PsnPay float64 `json:"psn_pay"`
  9416. AcctPay float64 `json:"acct_pay"`
  9417. CashPayamt float64 `json:"cash_payamt"`
  9418. Balc float64 `json:"balc"`
  9419. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9420. MedinsSetlId string `json:"medins_setl_id"`
  9421. RefdSetlFlag string `json:"refd_setl_flag"`
  9422. SetlTime string `json:"setl_time"`
  9423. MedType string `json:"med_type"`
  9424. } `json:"setlinfo"`
  9425. } `json:"output"`
  9426. RefmsgTime string `json:"refmsg_time"`
  9427. RespondTime string `json:"respond_time"`
  9428. Signtype interface{} `json:"signtype"`
  9429. WarnMsg interface{} `json:"warn_msg"`
  9430. }
  9431. type Custom struct {
  9432. DetItemFeeSumamt string
  9433. Cut string
  9434. FeedetlSn string
  9435. Price string
  9436. MedListCodg string
  9437. Type int64
  9438. AdviceId int64
  9439. ProjectId int64
  9440. ItemId int64
  9441. CostType int64
  9442. }
  9443. // 获取个人信息----挂号-----上传就诊信息
  9444. func (c *HisApiController) GetRegisterInfo() {
  9445. id, _ := c.GetInt64("id")
  9446. record_time := c.GetString("record_time")
  9447. settlementValue, _ := c.GetInt64("settlement_value")
  9448. medical_insurance_card := c.GetString("medical_insurance_card")
  9449. name := c.GetString("name")
  9450. id_card_type, _ := c.GetInt64("id_card_type")
  9451. certificates, _ := c.GetInt64("certificates")
  9452. medical_care, _ := c.GetInt64("medical_care")
  9453. birthday := c.GetString("birthday")
  9454. age, _ := c.GetInt64("age")
  9455. id_card := c.GetString("id_card")
  9456. register_type, _ := c.GetInt64("register")
  9457. doctor, _ := c.GetInt64("doctor")
  9458. department, _ := c.GetInt64("department")
  9459. gender, _ := c.GetInt64("sex")
  9460. phone := c.GetString("phone")
  9461. registration_fee, _ := c.GetFloat("registration_fee")
  9462. medical_expenses, _ := c.GetFloat("medical_expenses")
  9463. social_type, _ := c.GetInt64("social_type")
  9464. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9465. diagnosis_ids := c.GetString("diagnosis")
  9466. sick_type, _ := c.GetInt64("sick_type")
  9467. reg_type := c.GetString("p_type")
  9468. timeLayout := "2006-01-02"
  9469. loc, _ := time.LoadLocation("Local")
  9470. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9471. birthUnix := birthdays.Unix()
  9472. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9473. if err != nil {
  9474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9475. return
  9476. }
  9477. recordDateTime := theTime.Unix()
  9478. adminInfo := c.GetAdminUserInfo()
  9479. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9480. if tempPatient.ID == 0 {
  9481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9482. return
  9483. }
  9484. var patient service.Patients
  9485. if id == 0 {
  9486. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9487. } else {
  9488. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9489. }
  9490. if patient.ID == 0 {
  9491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9492. return
  9493. }
  9494. if len(patient.IdCardNo) == 0 {
  9495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9496. return
  9497. }
  9498. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9499. if len(his) >= 1 {
  9500. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9501. if len(his) >= 1 && order.ID == 0 {
  9502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9503. return
  9504. }
  9505. }
  9506. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9507. fmt.Println(timeStr)
  9508. timeArr := strings.Split(timeStr, " ")
  9509. fmt.Println(timeArr)
  9510. timeArrTwo := strings.Split(timeArr[0], "-")
  9511. timeArrThree := strings.Split(timeArr[1], ":")
  9512. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9513. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9514. if len(lists) == 0 {
  9515. var hisPatient models.XtHisPatient
  9516. hisPatient = models.XtHisPatient{
  9517. Name: name,
  9518. Age: age,
  9519. Gender: gender,
  9520. Birthday: birthUnix,
  9521. Phone: phone,
  9522. MedicalTreatmentType: medical_care,
  9523. IdType: certificates,
  9524. IdCardNo: id_card,
  9525. BalanceAccountsType: settlementValue,
  9526. SocialType: social_type,
  9527. MedicalInsuranceNumber: medical_insurance_card,
  9528. RegisterType: register_type,
  9529. RegisterCost: registration_fee,
  9530. TreatmentCost: medical_expenses,
  9531. AdminUserId: adminInfo.AdminUser.Id,
  9532. UserOrgId: adminInfo.CurrentOrgId,
  9533. Status: 1,
  9534. RecordDate: recordDateTime,
  9535. IsReturn: 1,
  9536. PatientId: patient.ID,
  9537. Ctime: time.Now().Unix(),
  9538. Mtime: time.Now().Unix(),
  9539. Number: str,
  9540. IdCardType: id_card_type,
  9541. Departments: department,
  9542. Doctor: doctor,
  9543. PType: reg_type,
  9544. Diagnosis: diagnosis_ids,
  9545. SickType: sick_type,
  9546. }
  9547. service.CreateHisPatient(&hisPatient)
  9548. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9549. c.ServeSuccessJSON(map[string]interface{}{
  9550. "his_info": hisPatient,
  9551. })
  9552. } else {
  9553. //chrgBchno := rand.Intn(1000000) + 10000
  9554. var hisPatient models.XtHisPatient
  9555. hisPatient = models.XtHisPatient{
  9556. Name: name,
  9557. Age: age,
  9558. Gender: gender,
  9559. Birthday: birthUnix,
  9560. Phone: phone,
  9561. MedicalTreatmentType: medical_care,
  9562. IdType: certificates,
  9563. IdCardNo: id_card,
  9564. BalanceAccountsType: settlementValue,
  9565. SocialType: social_type,
  9566. MedicalInsuranceNumber: medical_insurance_card,
  9567. RegisterType: register_type,
  9568. RegisterCost: registration_fee,
  9569. TreatmentCost: medical_expenses,
  9570. AdminUserId: adminInfo.AdminUser.Id,
  9571. UserOrgId: adminInfo.CurrentOrgId,
  9572. Status: 1,
  9573. RecordDate: recordDateTime,
  9574. IsReturn: 1,
  9575. PatientId: patient.ID,
  9576. Ctime: time.Now().Unix(),
  9577. Mtime: time.Now().Unix(),
  9578. Number: str,
  9579. IdCardType: id_card_type,
  9580. Departments: department,
  9581. Doctor: doctor,
  9582. PType: reg_type,
  9583. Diagnosis: diagnosis_ids,
  9584. SickType: sick_type,
  9585. }
  9586. service.CreateHisPatient(&hisPatient)
  9587. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9588. c.ServeSuccessJSON(map[string]interface{}{
  9589. "his_info": hisPatient,
  9590. })
  9591. }
  9592. }
  9593. // 上传明细----结算
  9594. func (c *HisApiController) GetUploadInfo() {
  9595. id, _ := c.GetInt64("id")
  9596. record_time := c.GetString("record_time")
  9597. his_patient_id, _ := c.GetInt64("his_patient_id")
  9598. oth_desc := c.GetString("oth_desc")
  9599. pay_way, _ := c.GetInt64("pay_way")
  9600. pay_ways := c.GetString("pay_ways")
  9601. pay_price, _ := c.GetFloat("pay_price")
  9602. pay_card_no := c.GetString("pay_card_no")
  9603. discount_price, _ := c.GetFloat("discount_price")
  9604. preferential_price, _ := c.GetFloat("preferential_price")
  9605. reality_price, _ := c.GetFloat("reality_price")
  9606. found_price, _ := c.GetFloat("found_price")
  9607. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9608. private_price, _ := c.GetFloat("private_price")
  9609. timeLayout := "2006-01-02"
  9610. loc, _ := time.LoadLocation("Local")
  9611. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9612. fapiao_code := c.GetString("fapiao_code")
  9613. fapiao_number := c.GetString("fapiao_number")
  9614. diagnosis_id := c.GetString("diagnosis")
  9615. sick_type, _ := c.GetInt64("sick_type")
  9616. reg_type, _ := c.GetInt64("p_type")
  9617. order_id, _ := c.GetInt64("order_id")
  9618. cash_pay := c.GetString("cash_pay")
  9619. wechat_pay := c.GetString("wechat_pay")
  9620. ali_pay := c.GetString("ali_pay")
  9621. jifen_pay := c.GetString("jifen_pay")
  9622. card_desc := c.GetString("card_desc")
  9623. band_card_pay := c.GetString("band_card_pay")
  9624. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9625. tmp_decimal := c.GetString("tmp_decimal")
  9626. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9627. var decimal float64 //本次使用的押金
  9628. var errmsg error
  9629. tx := service.XTWriteDB().Begin() //开了事务
  9630. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9631. defer func() {
  9632. if errmsg != nil {
  9633. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9634. tx.Rollback()
  9635. } else {
  9636. tx.Commit()
  9637. }
  9638. }()
  9639. fmt.Println("dec_way", dec_way)
  9640. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9641. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9642. return
  9643. }
  9644. if len(tmp_decimal) > 0 {
  9645. if tmp_decimal[0] == 45 {
  9646. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9647. return
  9648. }
  9649. }
  9650. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9651. fmt.Println(errs)
  9652. decimal = tt
  9653. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9654. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9655. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9656. if err != nil {
  9657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9658. return
  9659. }
  9660. recordDateTime := theTime.Unix()
  9661. adminUser := c.GetAdminUserInfo()
  9662. var prescriptions []*models.HisPrescription
  9663. var prescriptionsOne []*models.HisPrescription
  9664. var start_time int64
  9665. var end_time int64
  9666. ids_str := c.GetString("ids")
  9667. ids_arr := strings.Split(ids_str, ",")
  9668. if tempOrder.ID == 0 {
  9669. if settle_accounts_type == 1 { //日结
  9670. fmt.Println(reg_type)
  9671. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9672. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9673. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9674. } else {
  9675. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9676. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9677. }
  9678. } else { //月结
  9679. start_time_str := c.GetString("start_time")
  9680. end_time_str := c.GetString("end_time")
  9681. timeLayout := "2006-01-02"
  9682. loc, _ := time.LoadLocation("Local")
  9683. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9684. if err != nil {
  9685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9686. return
  9687. }
  9688. recordStartTime := theStartTime.Unix()
  9689. start_time = recordStartTime
  9690. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9691. if err != nil {
  9692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9693. return
  9694. }
  9695. recordEndTime := theEndTime.Unix()
  9696. end_time = recordEndTime
  9697. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9698. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9699. }
  9700. var goods []*models.DialysisBeforePrepareGoods
  9701. var newGoods []*models.NewDialysisBeforePrepareGoods
  9702. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9703. var infos []*models.HisDoctorAdviceInfo
  9704. var infoList []*models.HisDoctorAdviceInfo
  9705. var hisAdvice []*models.HisDoctorAdviceInfo
  9706. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9707. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9708. //判断库存不足
  9709. //结算出库开关
  9710. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9711. if settConfig.IsOpen == 1 {
  9712. //判断库存的地方
  9713. for _, info := range prescriptions {
  9714. if info.Type == 1 {
  9715. infos = append(infos, info.HisDoctorAdviceInfo...)
  9716. }
  9717. if info.Type == 2 {
  9718. for _, sumItem := range info.HisPrescriptionProject {
  9719. if sumItem.Type == 3 {
  9720. var good models.DialysisBeforePrepareGoods
  9721. var newGood models.NewDialysisBeforePrepareGoods
  9722. good.GoodId = sumItem.GoodInfo.ID
  9723. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9724. count, _ := strconv.Atoi(sumItem.Count)
  9725. good.Count = int64(count)
  9726. good.StorehouseId = houseConfig.StorehouseOutInfo
  9727. good.ProjectId = sumItem.ID
  9728. goods = append(goods, &good)
  9729. newGood.GoodId = sumItem.GoodInfo.ID
  9730. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9731. count2, _ := strconv.Atoi(sumItem.Count)
  9732. newGood.Count = int64(count2)
  9733. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9734. newGood.ProjectId = sumItem.ID
  9735. newGoods = append(newGoods, &newGood)
  9736. }
  9737. }
  9738. }
  9739. }
  9740. for _, info := range prescriptionsOne {
  9741. if info.Type == 1 {
  9742. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9743. }
  9744. if info.Type == 2 {
  9745. for _, sumItem := range info.HisPrescriptionProject {
  9746. if sumItem.Type == 3 {
  9747. var newGood models.NewDialysisBeforePrepareGoods
  9748. newGood.GoodId = sumItem.GoodInfo.ID
  9749. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9750. count2, _ := strconv.Atoi(sumItem.Count)
  9751. newGood.Count = int64(count2)
  9752. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9753. newGood.ProjectId = sumItem.ID
  9754. newGoodOne = append(newGoodOne, &newGood)
  9755. }
  9756. }
  9757. }
  9758. }
  9759. //判断
  9760. for _, itemOne := range infos {
  9761. for _, itemTwo := range hisAdvice {
  9762. if itemOne.DrugId == itemTwo.DrugId {
  9763. itemTwo.Child = append(itemTwo.Child, itemOne)
  9764. }
  9765. }
  9766. }
  9767. for _, itemTwo := range hisAdvice {
  9768. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9769. var sum_out_count int64
  9770. for _, itemThree := range itemTwo.Child {
  9771. var prescribing_number int64
  9772. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9773. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9774. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9775. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9776. }
  9777. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9778. prescribing_number = parseIntPrescribingNumber
  9779. }
  9780. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9781. prescribing_number = parseIntPrescribingNumber
  9782. }
  9783. sum_out_count += prescribing_number
  9784. }
  9785. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9786. if sum_out_count > drugStockOut.FlushCount {
  9787. c.ServeSuccessJSON(map[string]interface{}{
  9788. "msg": "2",
  9789. "drug": medical,
  9790. })
  9791. return
  9792. }
  9793. }
  9794. for _, itemOne := range newGoods {
  9795. for _, item := range newGoodOne {
  9796. if itemOne.GoodId == item.GoodId {
  9797. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9798. }
  9799. }
  9800. }
  9801. for _, item := range newGoodOne {
  9802. var sum_out_count_one int64
  9803. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9804. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9805. sum_out_count_one += itemOne.Count
  9806. }
  9807. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9808. fmt.Println("sum_out_count_one", sum_out_count_one)
  9809. fmt.Println("list.FlushCount", list.FlushCount)
  9810. if sum_out_count_one > list.FlushCount {
  9811. c.ServeSuccessJSON(map[string]interface{}{
  9812. "msg": "3",
  9813. "good": good,
  9814. })
  9815. return
  9816. }
  9817. }
  9818. }
  9819. timestamp := time.Now().Unix()
  9820. tempTime := time.Unix(timestamp, 0)
  9821. timeFormat := tempTime.Format("20060102150405")
  9822. chrgBchno := rand.Intn(100000) + 10000
  9823. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9824. strconv.FormatInt(his.PatientId, 10)
  9825. var ids []int64
  9826. for _, item := range prescriptions {
  9827. ids = append(ids, item.ID)
  9828. }
  9829. var total float64
  9830. for _, item := range prescriptions {
  9831. fmt.Println(item)
  9832. if item.Type == 1 { //药品
  9833. for _, subItem := range item.HisDoctorAdviceInfo {
  9834. if subItem.Drug.IsUser != 1 {
  9835. total = total + (subItem.Price * subItem.PrescribingNumber)
  9836. }
  9837. }
  9838. }
  9839. if item.Type == 2 { //项目
  9840. for _, subItem := range item.HisPrescriptionProject {
  9841. if subItem.Type == 2 {
  9842. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9843. total = total + (subItem.Price * cnt)
  9844. } else {
  9845. if subItem.GoodInfo.IsUser != 1 {
  9846. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9847. total = total + (subItem.Price * cnt)
  9848. }
  9849. }
  9850. }
  9851. }
  9852. for _, subItem := range item.HisAdditionalCharge {
  9853. total = total + (subItem.Price * float64(subItem.Count))
  9854. }
  9855. }
  9856. if reg_type == 1111 || reg_type == 1112 {
  9857. reg_type = 11
  9858. }
  9859. tm := time.Unix(time.Now().Unix(), 0)
  9860. allTotal := fmt.Sprintf("%.4f", total)
  9861. totals, _ := strconv.ParseFloat(allTotal, 64)
  9862. order := &models.HisOrder{
  9863. UserOrgId: adminUser.CurrentOrgId,
  9864. HisPatientId: his.ID,
  9865. PatientId: id,
  9866. SettleAccountsDate: recordDateTime,
  9867. Ctime: time.Now().Unix(),
  9868. Mtime: time.Now().Unix(),
  9869. Status: 1,
  9870. OrderStatus: 2,
  9871. MdtrtId: his.Number,
  9872. Number: chrg_bchno,
  9873. MedfeeSumamt: totals,
  9874. PayWay: pay_way,
  9875. PayWays: pay_ways,
  9876. PayPrice: pay_price,
  9877. MedType: strconv.Itoa(int(reg_type)),
  9878. PayCardNo: pay_card_no,
  9879. DiscountPrice: discount_price,
  9880. PreferentialPrice: preferential_price,
  9881. RealityPrice: reality_price,
  9882. FoundPrice: found_price,
  9883. MedicalInsurancePrice: medical_insurance_price,
  9884. PrivatePrice: private_price,
  9885. SettleEndTime: end_time,
  9886. SettleStartTime: start_time,
  9887. PsnPartAmt: totals,
  9888. PsnCashPay: totals,
  9889. SettleType: settle_accounts_type,
  9890. FaPiaoCode: fapiao_code,
  9891. FaPiaoNumber: fapiao_number,
  9892. Diagnosis: diagnosis_id,
  9893. PType: 2,
  9894. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9895. Decimal: decimal,
  9896. OthDesc: oth_desc,
  9897. CashPay: cash_pay,
  9898. WechatPay: wechat_pay,
  9899. AliPay: ali_pay,
  9900. JifenPay: jifen_pay,
  9901. BandCardPay: band_card_pay,
  9902. Creator: adminUser.AdminUser.Id,
  9903. CardDesc: card_desc,
  9904. }
  9905. err = service.CreateOrderTX(order, tx)
  9906. if err != nil {
  9907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9908. return
  9909. }
  9910. var customs []*Custom
  9911. for _, item := range prescriptions {
  9912. if item.Type == 1 { //药品a
  9913. for _, subItem := range item.HisDoctorAdviceInfo {
  9914. if subItem.Drug.IsUser != 1 {
  9915. cus := &Custom{
  9916. AdviceId: subItem.ID,
  9917. ProjectId: 0,
  9918. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9919. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9920. FeedetlSn: subItem.FeedetlSn,
  9921. Price: fmt.Sprintf("%.4f", subItem.Price),
  9922. MedListCodg: subItem.MedListCodg,
  9923. Type: 1,
  9924. CostType: 9,
  9925. }
  9926. customs = append(customs, cus)
  9927. }
  9928. }
  9929. }
  9930. if item.Type == 2 { //项目
  9931. for _, subItem := range item.HisPrescriptionProject {
  9932. if subItem.Type == 2 {
  9933. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9934. cus := &Custom{
  9935. AdviceId: 0,
  9936. ProjectId: subItem.ID,
  9937. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9938. Cut: fmt.Sprintf("%.4f", cnt),
  9939. FeedetlSn: subItem.FeedetlSn,
  9940. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9941. MedListCodg: subItem.MedListCodg,
  9942. Type: 2,
  9943. CostType: subItem.HisProject.CostClassify,
  9944. }
  9945. customs = append(customs, cus)
  9946. } else {
  9947. if subItem.GoodInfo.IsUser != 1 {
  9948. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9949. cus := &Custom{
  9950. AdviceId: 0,
  9951. ProjectId: subItem.ID,
  9952. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9953. Cut: fmt.Sprintf("%.4f", cnt),
  9954. FeedetlSn: subItem.FeedetlSn,
  9955. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9956. MedListCodg: subItem.MedListCodg,
  9957. Type: 3,
  9958. CostType: subItem.HisProject.CostClassify,
  9959. }
  9960. customs = append(customs, cus)
  9961. }
  9962. }
  9963. }
  9964. }
  9965. for _, item := range item.HisAdditionalCharge {
  9966. cus := &Custom{
  9967. ItemId: item.ID,
  9968. AdviceId: 0,
  9969. ProjectId: 0,
  9970. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9971. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9972. FeedetlSn: item.FeedetlSn,
  9973. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9974. MedListCodg: item.XtHisAddtionConfig.Code,
  9975. Type: 3,
  9976. CostType: 5,
  9977. }
  9978. customs = append(customs, cus)
  9979. }
  9980. }
  9981. for _, item := range customs {
  9982. var advice_id int64 = 0
  9983. var project_id int64 = 0
  9984. var item_id int64 = 0
  9985. var types int64 = 0
  9986. var med_chrgitm_type string
  9987. if item.Type == 1 {
  9988. advice_id = item.AdviceId
  9989. project_id = 0
  9990. item_id = 0
  9991. med_chrgitm_type = "09"
  9992. } else if item.Type == 2 {
  9993. med_chrgitm_type = "05"
  9994. if item.CostType == 3 {
  9995. med_chrgitm_type = "04"
  9996. }
  9997. if item.CostType == 8 {
  9998. med_chrgitm_type = "03"
  9999. }
  10000. advice_id = 0
  10001. item_id = 0
  10002. project_id = item.ProjectId
  10003. } else if item.Type == 3 {
  10004. advice_id = 0
  10005. item_id = item.ItemId
  10006. project_id = 0
  10007. med_chrgitm_type = "08"
  10008. }
  10009. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10010. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10011. pric, _ := strconv.ParseFloat(item.Price, 32)
  10012. info := &models.HisOrderInfo{
  10013. OrderNumber: order.Number,
  10014. UploadDate: time.Now().Unix(),
  10015. AdviceId: advice_id,
  10016. DetItemFeeSumamt: detItemFeeSumamt,
  10017. MedChrgitmType: med_chrgitm_type,
  10018. Cnt: cut,
  10019. Pric: pric,
  10020. PatientId: id,
  10021. Status: 1,
  10022. Mtime: time.Now().Unix(),
  10023. Ctime: time.Now().Unix(),
  10024. UserOrgId: adminUser.CurrentOrgId,
  10025. HisPatientId: his.ID,
  10026. OrderId: order.ID,
  10027. ProjectId: project_id,
  10028. Type: types,
  10029. ItemId: item_id,
  10030. }
  10031. service.CreateOrderInfoTX(info, tx)
  10032. }
  10033. his.Diagnosis = diagnosis_id
  10034. his.SickType = sick_type
  10035. his.RegisterType = reg_type
  10036. his.MedicalTreatmentType = reg_type
  10037. service.UpdataHisPateintTX(&his, tx)
  10038. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  10039. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  10040. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  10041. //判断是否使用了押金
  10042. if dec_way == "true" {
  10043. tmpstring := strconv.FormatInt(order.ID, 10)
  10044. //扣押金
  10045. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  10046. order.Decimal = decimal
  10047. service.UpDateOrderTwo(order, tx)
  10048. if errmsg != nil {
  10049. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  10050. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10051. return
  10052. }
  10053. }
  10054. if err == nil {
  10055. for _, info := range prescriptions {
  10056. if info.Type == 1 {
  10057. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  10058. }
  10059. if info.Type == 2 {
  10060. for _, sumItem := range info.HisPrescriptionProject {
  10061. if sumItem.Type == 3 {
  10062. var good models.DialysisBeforePrepareGoods
  10063. var newGood models.NewDialysisBeforePrepareGoods
  10064. var oldGood models.OldDialysisBeforePrepareGoods
  10065. good.GoodId = sumItem.GoodInfo.ID
  10066. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10067. count, _ := strconv.Atoi(sumItem.Count)
  10068. good.Count = int64(count)
  10069. good.StorehouseId = houseConfig.StorehouseOutInfo
  10070. good.ProjectId = sumItem.ID
  10071. good.PatientId = sumItem.PatientId
  10072. goods = append(goods, &good)
  10073. newGood.GoodId = sumItem.GoodInfo.ID
  10074. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10075. count2, _ := strconv.Atoi(sumItem.Count)
  10076. newGood.Count = int64(count2)
  10077. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10078. newGood.ProjectId = sumItem.ID
  10079. newGood.PatientId = sumItem.HisPatientId
  10080. newGoods = append(newGoods, &newGood)
  10081. oldGood.GoodId = sumItem.GoodInfo.ID
  10082. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10083. count3, _ := strconv.Atoi(sumItem.Count)
  10084. oldGood.Count = int64(count3)
  10085. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  10086. oldGood.ProjectId = sumItem.ID
  10087. oldGood.RecordDate = sumItem.RecordDate
  10088. oldGood.PatientId = sumItem.HisPatientId
  10089. oldGoods = append(oldGoods, &oldGood)
  10090. }
  10091. }
  10092. }
  10093. }
  10094. if settConfig.IsOpen == 1 {
  10095. for _, item := range infoList {
  10096. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  10097. if medical.IsUse == 2 {
  10098. //药品出库
  10099. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  10100. //查询默认仓库
  10101. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  10102. //查询默认仓库剩余多少库存
  10103. var sum_count int64
  10104. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  10105. for _, its := range stockInfo {
  10106. if its.MaxUnit == medical.MaxUnit {
  10107. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  10108. }
  10109. sum_count += its.StockMaxNumber + its.StockMinNumber
  10110. }
  10111. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  10112. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  10113. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  10114. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  10115. }
  10116. }
  10117. orgId := c.GetAdminUserInfo().CurrentOrgId
  10118. if len(oldGoods) > 0 {
  10119. timeStr := time.Now().Format("2006-01-02")
  10120. timeArr := strings.Split(timeStr, "-")
  10121. total, _ := service.FindAllWarehouseOut(orgId)
  10122. total = total + 1
  10123. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  10124. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  10125. number = number + total
  10126. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  10127. operation_time := time.Now().Unix()
  10128. creater := c.GetAdminUserInfo().AdminUser.Id
  10129. //查询默认出库仓库库存
  10130. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  10131. recordDateStr := time.Now().Format("2006-01-02")
  10132. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  10133. nowtime := recordDate.Unix()
  10134. warehouseOut := models.WarehouseOut{
  10135. WarehouseOutOrderNumber: warehousing_out_order,
  10136. OperationTime: operation_time,
  10137. OrgId: orgId,
  10138. Creater: creater,
  10139. Ctime: time.Now().Unix(),
  10140. Status: 1,
  10141. WarehouseOutTime: nowtime,
  10142. Type: 1,
  10143. StorehouseId: storeConfig.StorehouseOutInfo,
  10144. IsCheck: 1,
  10145. OrderId: order.ID,
  10146. IsSys: 5,
  10147. }
  10148. //查询是否生成出库单
  10149. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10150. if out.ID == 0 {
  10151. service.AddSigleWarehouseOutOne(&warehouseOut)
  10152. }
  10153. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10154. for _, item := range oldGoods {
  10155. dialyPrepareOne := models.DialysisBeforePrepare{
  10156. GoodTypeId: item.GoodTypeId,
  10157. GoodId: item.GoodId,
  10158. PatientId: his.PatientId,
  10159. RecordDate: item.RecordDate,
  10160. UserOrgId: adminUser.CurrentOrgId,
  10161. Count: item.Count,
  10162. Ctime: time.Now().Unix(),
  10163. Creater: adminUser.AdminUser.Id,
  10164. CommdityCode: item.CommdityCode,
  10165. Status: 1,
  10166. StorehouseId: houseConfig.StorehouseOutInfo,
  10167. }
  10168. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  10169. //非零用
  10170. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  10171. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10172. //查询剩余库存
  10173. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10174. var sum_count int64
  10175. for _, item := range goodList {
  10176. sum_count += item.StockCount
  10177. }
  10178. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10179. //耗材
  10180. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10181. }
  10182. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  10183. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10184. //查询剩余库存
  10185. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10186. var sum_count int64
  10187. for _, item := range goodList {
  10188. sum_count += item.StockCount
  10189. }
  10190. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10191. //耗材
  10192. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10193. }
  10194. }
  10195. }
  10196. }
  10197. c.ServeSuccessJSON(map[string]interface{}{
  10198. "msg": "结算成功",
  10199. })
  10200. }
  10201. }
  10202. }
  10203. // 退款
  10204. func (c *HisApiController) Refund() {
  10205. order_id, _ := c.GetInt64("order_id")
  10206. order, _ := service.GetHisOrderByID(order_id)
  10207. adminUser := c.GetAdminUserInfo()
  10208. orgid := c.GetAdminUserInfo().CurrentOrgId
  10209. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  10210. if err != nil {
  10211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10212. return
  10213. }
  10214. tmp := strconv.FormatInt(order.ID, 10)
  10215. //当押金不为零时产生退费记录
  10216. if order.Decimal != 0 {
  10217. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  10218. if err != nil {
  10219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10220. return
  10221. }
  10222. }
  10223. fapiao, _ := service.GetFaPiaoHisOrderByID(order_id)
  10224. if fapiao.ID > 0 {
  10225. c.ServeSuccessJSON(map[string]interface{}{
  10226. "failed_code": -10,
  10227. "msg": "该结算已经开具发票无法退费,请先红冲发票",
  10228. })
  10229. return
  10230. }
  10231. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  10232. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  10233. var goods []*models.DialysisBeforePrepareGoods
  10234. var newGoods []*models.NewDialysisBeforePrepareGoods
  10235. var infos []*models.HisDoctorAdviceInfo
  10236. for _, info := range orders {
  10237. if info.AdviceId > 0 && info.ProjectId == 0 {
  10238. infos = append(infos, &info.HisDoctorAdviceInfo)
  10239. }
  10240. if info.ProjectId > 0 && info.AdviceId == 0 {
  10241. if info.HisPrescriptionProject.Type == 3 {
  10242. var good models.DialysisBeforePrepareGoods
  10243. var newGood models.NewDialysisBeforePrepareGoods
  10244. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10245. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10246. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10247. good.Count = int64(count)
  10248. good.StorehouseId = houseConfig.StorehouseOutInfo
  10249. good.ProjectId = info.HisPrescriptionProject.ID
  10250. good.PatientId = info.PatientId
  10251. good.OrderId = order_id
  10252. goods = append(goods, &good)
  10253. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10254. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10255. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10256. newGood.Count = int64(count2)
  10257. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10258. newGood.ProjectId = info.HisPrescriptionProject.ID
  10259. newGood.RecordDate = order.SettleAccountsDate
  10260. newGood.UserOrgId = order.UserOrgId
  10261. newGood.PatientId = info.PatientId
  10262. newGood.OrderId = order_id
  10263. newGoods = append(newGoods, &newGood)
  10264. }
  10265. }
  10266. }
  10267. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  10268. if settConfig.IsOpen == 1 {
  10269. for _, item := range infos {
  10270. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10271. }
  10272. for _, item := range newGoods {
  10273. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10274. }
  10275. }
  10276. c.ServeSuccessJSON(map[string]interface{}{
  10277. "msg": "退费成功",
  10278. })
  10279. }
  10280. func (c *HisApiController) RefundNumber() {
  10281. his_patient_id, _ := c.GetInt64("id")
  10282. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10283. info.Status = 0
  10284. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  10285. if count > 0 {
  10286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  10287. return
  10288. }
  10289. err := service.SaveHisPatient(info)
  10290. if err == nil {
  10291. c.ServeSuccessJSON(map[string]interface{}{
  10292. "msg": "退号成功",
  10293. })
  10294. } else {
  10295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10296. return
  10297. }
  10298. }
  10299. func (this *HisApiController) AdditionalCharge() {
  10300. dataBody := make(map[string]interface{}, 0)
  10301. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10302. fmt.Println(err)
  10303. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  10304. patient_id := int64(dataBody["patient_id"].(float64))
  10305. medicineData, _ := dataBody["medicineData"].([]interface{})
  10306. adminUserInfo := this.GetAdminUserInfo()
  10307. orgId := adminUserInfo.CurrentOrgId
  10308. admin_user_id := adminUserInfo.AdminUser.Id
  10309. timeStr := time.Now().Format("2006-01-02")
  10310. timeLayout := "2006-01-02 15:04:05"
  10311. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10312. timenow := timeStringToTime.Unix()
  10313. var additionalCharges []*models.HisAdditionalCharge
  10314. for _, item := range medicineData {
  10315. var randNum int
  10316. randNum = rand.Intn(10000) + 1000
  10317. timestamp := time.Now().Unix()
  10318. tempTime := time.Unix(timestamp, 0)
  10319. timeFormat := tempTime.Format("20060102150405")
  10320. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  10321. items := item.(map[string]interface{})
  10322. money := items["price"].(string)
  10323. item_id_str := items["item_id"].(string)
  10324. name := items["name"].(string)
  10325. id_str := items["id"].(string)
  10326. moneys, _ := strconv.ParseInt(money, 10, 64)
  10327. monStr := strconv.FormatInt(moneys, 10)
  10328. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  10329. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  10330. id, _ := strconv.ParseInt(id_str, 10, 64)
  10331. additionalCharge := &models.HisAdditionalCharge{
  10332. ID: id,
  10333. HisPatientId: his_patient_id,
  10334. UserOrgId: orgId,
  10335. PatientId: patient_id,
  10336. RecordDate: timenow,
  10337. Price: monneyStr,
  10338. Status: 1,
  10339. ItemName: name,
  10340. ItemId: item_id,
  10341. AdminUserId: admin_user_id,
  10342. CreatedTime: time.Now().Unix(),
  10343. OrderStatus: 0,
  10344. PrescriptionNumber: "",
  10345. BatchNumber: "",
  10346. FeedetlSn: p_number,
  10347. }
  10348. service.CreateAdditionalCharge(additionalCharge)
  10349. additionalCharges = append(additionalCharges, additionalCharge)
  10350. }
  10351. this.ServeSuccessJSON(map[string]interface{}{
  10352. "msg": "添加成功",
  10353. "additional_charges": additionalCharges,
  10354. })
  10355. }
  10356. func (this *HisApiController) DeleteAddition() {
  10357. id, _ := this.GetInt64("id")
  10358. //TODO 需要判断是否已经结算
  10359. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  10360. if err == nil {
  10361. this.ServeSuccessJSON(map[string]interface{}{
  10362. "msg": "删除成功",
  10363. })
  10364. return
  10365. } else {
  10366. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10367. return
  10368. }
  10369. }
  10370. func (this *HisApiController) GetAdminUsers() {
  10371. adminUser := this.GetAdminUserInfo()
  10372. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  10373. this.ServeSuccessJSON(map[string]interface{}{
  10374. "doctors": doctors,
  10375. })
  10376. }
  10377. func (this *HisApiController) GetLastOrNextHisPrescription() {
  10378. change_type, _ := this.GetInt64("type", 0)
  10379. record_date := this.GetString("record_time")
  10380. patient_id, _ := this.GetInt64("patient_id", 0)
  10381. p_type, _ := this.GetInt64("p_type", 0)
  10382. timeLayout := "2006-01-02"
  10383. loc, _ := time.LoadLocation("Local")
  10384. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  10385. record_time := theAdviceRecordTime.Unix()
  10386. adminUserInfo := this.GetAdminUserInfo()
  10387. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  10388. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10389. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10390. if config.ID > 0 && config.IsOpen == 1 {
  10391. for _, subitems := range prescriptions {
  10392. for _, item := range subitems.VMHisPrescription {
  10393. for _, subItem := range item.HisDoctorAdviceInfo {
  10394. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10395. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10396. if info.RetailPrice > 0 {
  10397. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10398. subItem.Drug.RetailPrice = drug.RetailPrice
  10399. }
  10400. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10401. subItem.Drug.MinPrice = info.RetailPrice
  10402. subItem.Drug.RetailPrice = info.RetailPrice
  10403. }
  10404. }
  10405. }
  10406. }
  10407. }
  10408. }
  10409. if config.ID > 0 && config.IsOpen == 1 {
  10410. for _, subitems := range prescriptions {
  10411. for _, item := range subitems.VMHisPrescription {
  10412. for _, subItem := range item.HisPrescriptionProject {
  10413. if subItem.Type == 3 {
  10414. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10415. if info.Price > 0 {
  10416. subItem.GoodInfo.PackingPrice = info.Price
  10417. }
  10418. }
  10419. }
  10420. }
  10421. }
  10422. }
  10423. }
  10424. if err == nil {
  10425. if len(prescriptions) == 0 {
  10426. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  10427. return
  10428. } else {
  10429. this.ServeSuccessJSON(map[string]interface{}{
  10430. "prescriptions": prescriptions,
  10431. })
  10432. return
  10433. }
  10434. } else {
  10435. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10436. return
  10437. }
  10438. }
  10439. func RemoveRepeatedPurviewElementByHP(arr []service.VMOtherHisPrescriptionInfo) (newArr []service.VMOtherHisPrescriptionInfo) {
  10440. newArr = make([]service.VMOtherHisPrescriptionInfo, 0)
  10441. for i := 0; i < len(arr); i++ {
  10442. repeat := false
  10443. for j := i + 1; j < len(arr); j++ {
  10444. if arr[i].PatientId == arr[j].PatientId && arr[i].RecordDate == arr[j].RecordDate {
  10445. repeat = true
  10446. break
  10447. }
  10448. }
  10449. if !repeat {
  10450. newArr = append(newArr, arr[i])
  10451. }
  10452. }
  10453. return
  10454. }
  10455. func (this *HisApiController) GetCallHisPrescription() {
  10456. patient_id, _ := this.GetInt64("patient_id", 0)
  10457. timeLayout := "2006-01-02"
  10458. loc, _ := time.LoadLocation("Local")
  10459. start_time := this.GetString("start_time")
  10460. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10461. end_time := this.GetString("end_time")
  10462. p_type, _ := this.GetInt64("p_type")
  10463. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10464. adminUserInfo := this.GetAdminUserInfo()
  10465. new_prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  10466. prescriptions := RemoveRepeatedPurviewElementByHP(new_prescriptions)
  10467. //if
  10468. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  10469. //
  10470. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  10471. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10472. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10473. if config.ID > 0 && config.IsOpen == 1 {
  10474. for _, subitems := range prescriptions {
  10475. for _, item := range subitems.VMHisPrescription {
  10476. for _, subItem := range item.HisDoctorAdviceInfo {
  10477. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10478. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10479. if info.RetailPrice > 0 {
  10480. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10481. subItem.Drug.RetailPrice = drug.RetailPrice
  10482. }
  10483. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10484. subItem.Drug.MinPrice = info.RetailPrice
  10485. subItem.Drug.RetailPrice = info.RetailPrice
  10486. }
  10487. }
  10488. }
  10489. }
  10490. }
  10491. }
  10492. if config.ID > 0 && config.IsOpen == 1 {
  10493. for _, subitems := range prescriptions {
  10494. for _, item := range subitems.VMHisPrescription {
  10495. for _, subItem := range item.HisPrescriptionProject {
  10496. if subItem.Type == 3 {
  10497. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10498. if info.Price > 0 {
  10499. subItem.GoodInfo.PackingPrice = info.Price
  10500. }
  10501. }
  10502. }
  10503. }
  10504. }
  10505. }
  10506. }
  10507. if err == nil {
  10508. this.ServeSuccessJSON(map[string]interface{}{
  10509. "prescriptions": prescriptions,
  10510. })
  10511. return
  10512. } else {
  10513. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10514. return
  10515. }
  10516. }
  10517. func (this *HisApiController) GetHisDayPrescription() {
  10518. timeLayout := "2006-01-02"
  10519. loc, _ := time.LoadLocation("Local")
  10520. start_time := this.GetString("start_time")
  10521. patient_id, _ := this.GetInt64("patient_id", 0)
  10522. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10523. end_time := this.GetString("end_time")
  10524. p_type, _ := this.GetInt64("p_type")
  10525. order_status, _ := this.GetInt64("type")
  10526. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10527. adminUserInfo := this.GetAdminUserInfo()
  10528. var dayHisPrescription []*models.HisPrescription
  10529. var err error
  10530. if order_status == 1 || order_status == 0 {
  10531. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10532. } else if order_status == 2 {
  10533. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10534. }
  10535. var settle_total float64
  10536. for _, item := range dayHisPrescription {
  10537. if len(item.HisPrescriptionProject) > 0 {
  10538. for _, subItem := range item.HisPrescriptionProject {
  10539. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10540. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10541. settle_total = settle_total + total
  10542. }
  10543. }
  10544. if len(item.HisDoctorAdviceInfo) > 0 {
  10545. for _, subItem := range item.HisDoctorAdviceInfo {
  10546. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10547. settle_total = settle_total + total
  10548. }
  10549. }
  10550. }
  10551. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10552. if err == nil {
  10553. this.ServeSuccessJSON(map[string]interface{}{
  10554. "day_prescription": dayHisPrescription,
  10555. "settle_total": settle_total,
  10556. })
  10557. return
  10558. } else {
  10559. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10560. return
  10561. }
  10562. }
  10563. func (c *HisApiController) GetHisChargePatientList() {
  10564. record_date := c.GetString("record_date")
  10565. order_status, _ := c.GetInt64("type")
  10566. sch_type, _ := c.GetInt64("sch_type")
  10567. timeLayout := "2006-01-02"
  10568. loc, _ := time.LoadLocation("Local")
  10569. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10570. if err != nil {
  10571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10572. return
  10573. }
  10574. recordDateTime := theTime.Unix()
  10575. adminInfo := c.GetAdminUserInfo()
  10576. var tempPatients []*service.NewTempPatients
  10577. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10578. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10579. if order_status != 2 {
  10580. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10581. } else {
  10582. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10583. }
  10584. } else {
  10585. if order_status != 2 {
  10586. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10587. } else {
  10588. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10589. }
  10590. }
  10591. var patients []*service.NewTempPatients
  10592. var patients_two []*service.NewTempPatients
  10593. for _, item := range tempPatients {
  10594. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10595. //过滤掉没挂号的和没开处方的
  10596. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10597. patients = append(patients, item)
  10598. }
  10599. //过滤掉没挂号的
  10600. if len(item.HisPatient) > 0 {
  10601. patients_two = append(patients_two, item)
  10602. }
  10603. } else {
  10604. if len(item.HisPrescription) > 0 {
  10605. patients = append(patients, item)
  10606. }
  10607. }
  10608. }
  10609. c.ServeSuccessJSON(map[string]interface{}{
  10610. "list": patients,
  10611. "list_two": patients_two,
  10612. })
  10613. }
  10614. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10615. record_date := c.GetString("record_date")
  10616. timeLayout := "2006-01-02"
  10617. loc, _ := time.LoadLocation("Local")
  10618. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10619. if err != nil {
  10620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10621. return
  10622. }
  10623. recordDateTime := theTime.Unix()
  10624. adminUser := c.GetAdminUserInfo()
  10625. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10626. var patients []*service.Patients
  10627. for _, item := range tempPatients {
  10628. if item.HisPatient.ID == 0 {
  10629. patients = append(patients, item)
  10630. }
  10631. }
  10632. c.ServeSuccessJSON(map[string]interface{}{
  10633. "list": patients,
  10634. //"list_two": patients_two,
  10635. })
  10636. }
  10637. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10638. newArr = make([]*service.Patients, 0)
  10639. for i := 0; i < len(patient); i++ {
  10640. repeat := false
  10641. for j := i + 1; j < len(patient); j++ {
  10642. if patient[i].ID == patient[j].ID {
  10643. repeat = true
  10644. break
  10645. }
  10646. }
  10647. if !repeat {
  10648. newArr = append(newArr, patient[i])
  10649. }
  10650. }
  10651. return
  10652. }
  10653. func (c *HisApiController) GetHisChargePatientInfo() {
  10654. patient_id, _ := c.GetInt64("patient_id")
  10655. his_patient_id, _ := c.GetInt64("his_patient_id")
  10656. record_date := c.GetString("record_date")
  10657. //start_time := c.GetString("start_time")
  10658. //end_time := c.GetString("end_time")
  10659. order_status, _ := c.GetInt64("type", 0)
  10660. p_type, _ := c.GetInt64("p_type", 0)
  10661. order_id, _ := c.GetInt64("order_id", 0)
  10662. timeLayout := "2006-01-02"
  10663. loc, _ := time.LoadLocation("Local")
  10664. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10665. if err != nil {
  10666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10667. return
  10668. }
  10669. recordDateTime := theTime.Unix()
  10670. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10671. //if err != nil {
  10672. //
  10673. //}
  10674. //startRecordDateTime := startTime.Unix()
  10675. //
  10676. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10677. //if err != nil {
  10678. //
  10679. //}
  10680. //endRecordDateTime := endTime.Unix()
  10681. admin := c.GetAdminUserInfo()
  10682. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10683. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10684. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10685. var prescriptions []*models.HisPrescription
  10686. //var unChargeMonthPrescriptions []*models.HisPrescription
  10687. order, _ := service.GetHisOrderByID(order_id)
  10688. if order_status == 1 || order_status == 0 {
  10689. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10690. } else if order_status == 2 {
  10691. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10692. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10693. }
  10694. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10695. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10696. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10697. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10698. //获取所有科室信息
  10699. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10700. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10701. c.ServeSuccessJSON(map[string]interface{}{
  10702. "his_info": his_patient_info,
  10703. "last_his_patient_info": last_his_patient_info,
  10704. "xt_info": xt_patient_info,
  10705. "prescription": prescriptions,
  10706. "case_history": case_history,
  10707. "info": patientPrescriptionInfo,
  10708. "last_info": lastPatientPrescriptionInfo,
  10709. "order": order,
  10710. "doctors": doctors,
  10711. "department": department,
  10712. "sch": sch,
  10713. })
  10714. return
  10715. }
  10716. func (c *HisApiController) GetAllOrderDetail() {
  10717. order_id, _ := c.GetInt64("id", 0)
  10718. order, _ := service.GetHisOrderByID(order_id)
  10719. if order.ID == 0 {
  10720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10721. return
  10722. }
  10723. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10724. org_id := c.GetAdminUserInfo().CurrentOrgId
  10725. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10726. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10727. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10728. c.ServeSuccessJSON(map[string]interface{}{
  10729. "order": order,
  10730. "order_info": order_info,
  10731. "patient": patient,
  10732. "admin_info": adminInfo,
  10733. "hospital_record": record,
  10734. })
  10735. return
  10736. }
  10737. func (c *HisApiController) GetAllOrderDetailCollect() {
  10738. order_id, _ := c.GetInt64("id", 0)
  10739. order, _ := service.GetHisOrderByID(order_id)
  10740. if order.ID == 0 {
  10741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10742. return
  10743. }
  10744. org_id := c.GetAdminUserInfo().CurrentOrgId
  10745. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10746. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10747. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10748. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10749. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10750. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10751. var bedCostTotal float64 = 0 //床位总费
  10752. //var bedCostSelfTotal float64 = 0 //床位自费
  10753. var operationCostTotal float64 = 0 //手术费
  10754. //var operationCostSelfTotal float64 = 0 //手术费
  10755. var otherCostTotal float64 = 0 //其他费用
  10756. //var otherCostSelfTotal float64 = 0 //其他费用
  10757. var materialCostTotal float64 = 0 //材料费
  10758. //var materialCostSelfTotal float64 = 0 //材料费
  10759. var westernMedicineCostTotal float64 = 0 //西药费
  10760. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10761. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10762. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10763. var checkCostTotal float64 = 0 //检查费
  10764. //var checkCostSelfTotal float64 = 0 //检查费
  10765. var laboratoryCostTotal float64 = 0 //化验费
  10766. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10767. var treatCostTotal float64 = 0 //治疗费用
  10768. //var treatCostSelfTotal float64 = 0 //治疗费用
  10769. var zhenChaCostTotal float64 = 0 //其他费用
  10770. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10771. decimal.DivisionPrecision = 2
  10772. var BalanceAccountsType int64
  10773. if his.ID > 0 {
  10774. BalanceAccountsType = his.BalanceAccountsType
  10775. } else {
  10776. BalanceAccountsType = record.BalanceAccountsType
  10777. }
  10778. if BalanceAccountsType != 2 {
  10779. for _, item := range order_info {
  10780. if org_id == 10215 {
  10781. if item.MedChrgitmType == "01" { //床位费
  10782. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10783. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10784. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10785. }
  10786. if item.MedChrgitmType == "02" { //诊察费
  10787. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10788. //zhenChaCostSelfTotal = zhenChaCostTotal
  10789. }
  10790. if item.MedChrgitmType == "03" { //检查费
  10791. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10792. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10793. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10794. }
  10795. //if item.MedChrgitmType == "02" { //检查费
  10796. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10797. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10798. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10799. //}
  10800. if item.MedChrgitmType == "04" { //化验费
  10801. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10802. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10803. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10804. }
  10805. if item.MedChrgitmType == "05" { //治疗费
  10806. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10807. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10808. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10809. }
  10810. if item.MedChrgitmType == "06" { //手术费
  10811. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10812. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10813. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10814. }
  10815. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10816. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10817. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10818. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10819. }
  10820. if item.MedChrgitmType == "09" { //西药费
  10821. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10822. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10823. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10824. }
  10825. if item.MedChrgitmType == "11" { //中成费
  10826. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10827. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10828. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10829. }
  10830. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10831. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10832. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10833. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10834. }
  10835. } else if org_id == 10188 || org_id == 10217 {
  10836. if item.MedChrgitmType == "01" { //床位费
  10837. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10838. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10839. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10840. }
  10841. if item.MedChrgitmType == "02" { //诊察费
  10842. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10843. //zhenChaCostSelfTotal = zhenChaCostTotal
  10844. }
  10845. if item.MedChrgitmType == "03" { //检查费
  10846. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10847. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10848. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10849. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10850. }
  10851. //if item.MedChrgitmType == "02" { //检查费
  10852. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10853. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10854. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10855. //}
  10856. if item.MedChrgitmType == "04" { //化验费
  10857. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10858. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10859. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10860. }
  10861. if item.MedChrgitmType == "05" { //治疗费
  10862. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10863. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10864. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10865. }
  10866. if item.MedChrgitmType == "06" { //手术费
  10867. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10868. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10869. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10870. }
  10871. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10872. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10873. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10874. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10875. }
  10876. if item.MedChrgitmType == "09" { //西药费
  10877. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10878. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10879. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10880. }
  10881. if item.MedChrgitmType == "11" { //中成费
  10882. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10883. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10884. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10885. }
  10886. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10887. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10888. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10889. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10890. }
  10891. } else {
  10892. if item.MedChrgitmType == "01" { //床位费
  10893. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10894. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10895. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10896. }
  10897. //if item.MedChrgitmType == "02" { //诊察费
  10898. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10899. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10900. //}
  10901. if item.MedChrgitmType == "03" { //检查费
  10902. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10903. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10904. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10905. }
  10906. //if item.MedChrgitmType == "02" { //检查费
  10907. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10908. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10909. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10910. //}
  10911. if item.MedChrgitmType == "04" { //化验费
  10912. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10913. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10914. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10915. }
  10916. if item.MedChrgitmType == "05" { //治疗费
  10917. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10918. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10919. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10920. }
  10921. if item.MedChrgitmType == "06" { //手术费
  10922. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10923. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10924. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10925. }
  10926. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10927. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10928. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10929. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10930. }
  10931. if item.MedChrgitmType == "09" { //西药费
  10932. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10933. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10934. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10935. }
  10936. if item.MedChrgitmType == "11" { //中成费
  10937. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10938. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10939. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10940. }
  10941. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10942. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10943. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10944. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10945. }
  10946. }
  10947. }
  10948. c.ServeSuccessJSON(map[string]interface{}{
  10949. "order": order,
  10950. "order_info": order_info,
  10951. "patient": patient,
  10952. "admin_info": adminInfo,
  10953. "his_hospital": record,
  10954. "bedCostTotal": bedCostTotal,
  10955. "operationCostTotal": operationCostTotal,
  10956. "otherCostTotal": otherCostTotal,
  10957. "materialCostTotal": materialCostTotal,
  10958. "westernMedicineCostTotal": westernMedicineCostTotal,
  10959. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10960. "checkCostTotal": checkCostTotal,
  10961. "zhenChaCostTotal": zhenChaCostTotal,
  10962. "laboratoryCostTotal": laboratoryCostTotal,
  10963. "treatCostTotal": treatCostTotal,
  10964. })
  10965. } else {
  10966. for _, item := range order_info {
  10967. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10968. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10969. item.MedChrgitmType = "09"
  10970. }
  10971. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10972. if item.HisPrescriptionProject.Type == 2 {
  10973. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10974. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10975. case 0:
  10976. item.MedChrgitmType = "0"
  10977. break
  10978. case 1:
  10979. item.MedChrgitmType = "14"
  10980. break
  10981. case 2:
  10982. item.MedChrgitmType = "05"
  10983. break
  10984. case 3:
  10985. item.MedChrgitmType = "03"
  10986. break
  10987. case 4:
  10988. item.MedChrgitmType = "03"
  10989. break
  10990. case 5:
  10991. item.MedChrgitmType = "08"
  10992. break
  10993. case 6:
  10994. item.MedChrgitmType = "14"
  10995. break
  10996. case 7:
  10997. item.MedChrgitmType = "14"
  10998. break
  10999. case 8:
  11000. item.MedChrgitmType = "03"
  11001. break
  11002. case 9:
  11003. item.MedChrgitmType = "14"
  11004. break
  11005. case 10:
  11006. item.MedChrgitmType = "14"
  11007. break
  11008. case 11:
  11009. item.MedChrgitmType = "06"
  11010. break
  11011. case 12:
  11012. item.MedChrgitmType = "12"
  11013. break
  11014. case 13:
  11015. item.MedChrgitmType = "01"
  11016. break
  11017. case 14:
  11018. item.MedChrgitmType = "04"
  11019. break
  11020. case 15:
  11021. item.MedChrgitmType = "14"
  11022. break
  11023. }
  11024. } else {
  11025. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11026. case 1:
  11027. item.MedChrgitmType = "14"
  11028. break
  11029. case 2:
  11030. item.MedChrgitmType = "05"
  11031. break
  11032. case 3:
  11033. item.MedChrgitmType = "04"
  11034. break
  11035. case 4:
  11036. item.MedChrgitmType = "14"
  11037. break
  11038. case 5:
  11039. item.MedChrgitmType = "08"
  11040. break
  11041. case 6:
  11042. item.MedChrgitmType = "14"
  11043. break
  11044. case 7:
  11045. item.MedChrgitmType = "14"
  11046. break
  11047. case 8:
  11048. item.MedChrgitmType = "03"
  11049. break
  11050. case 9:
  11051. item.MedChrgitmType = "14"
  11052. break
  11053. }
  11054. }
  11055. } else if item.HisPrescriptionProject.Type == 3 {
  11056. item.MedChrgitmType = "08"
  11057. }
  11058. }
  11059. }
  11060. for _, item := range order_info {
  11061. if org_id == 10215 {
  11062. if item.MedChrgitmType == "01" { //床位费
  11063. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11064. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11065. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11066. }
  11067. if item.MedChrgitmType == "02" { //诊察费
  11068. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11069. //zhenChaCostSelfTotal = zhenChaCostTotal
  11070. }
  11071. if item.MedChrgitmType == "03" { //检查费
  11072. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11073. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11074. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11075. }
  11076. //if item.MedChrgitmType == "02" { //检查费
  11077. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11078. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11079. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11080. //}
  11081. if item.MedChrgitmType == "04" { //化验费
  11082. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11083. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11084. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11085. }
  11086. if item.MedChrgitmType == "05" { //治疗费
  11087. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11088. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11089. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11090. }
  11091. if item.MedChrgitmType == "06" { //手术费
  11092. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11093. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11094. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11095. }
  11096. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11097. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11098. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11099. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11100. }
  11101. if item.MedChrgitmType == "09" { //西药费
  11102. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11103. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11104. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11105. }
  11106. if item.MedChrgitmType == "11" { //中成费
  11107. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11108. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11109. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11110. }
  11111. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11112. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11113. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11114. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11115. }
  11116. } else {
  11117. if item.MedChrgitmType == "01" { //床位费
  11118. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11119. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11120. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11121. }
  11122. //if item.MedChrgitmType == "02" { //诊察费
  11123. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11124. // //zhenChaCostSelfTotal = zhenChaCostTotal
  11125. //}
  11126. if item.MedChrgitmType == "03" { //检查费
  11127. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11128. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11129. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11130. }
  11131. //if item.MedChrgitmType == "02" { //检查费
  11132. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11133. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11134. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11135. //}
  11136. if item.MedChrgitmType == "04" { //化验费
  11137. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11138. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11139. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11140. }
  11141. if item.MedChrgitmType == "05" { //治疗费
  11142. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11143. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11144. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11145. }
  11146. if item.MedChrgitmType == "06" { //手术费
  11147. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11148. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11149. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11150. }
  11151. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11152. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11153. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11154. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11155. }
  11156. if item.MedChrgitmType == "09" { //西药费
  11157. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11158. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11159. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11160. }
  11161. if item.MedChrgitmType == "11" { //中成费
  11162. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11163. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11164. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11165. }
  11166. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11167. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11168. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11169. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11170. }
  11171. }
  11172. }
  11173. c.ServeSuccessJSON(map[string]interface{}{
  11174. "order": order,
  11175. "order_info": order_info,
  11176. "patient": patient,
  11177. "admin_info": adminInfo,
  11178. "his_hospital": record,
  11179. "bedCostTotal": bedCostTotal,
  11180. "operationCostTotal": operationCostTotal,
  11181. "otherCostTotal": otherCostTotal,
  11182. "materialCostTotal": materialCostTotal,
  11183. "westernMedicineCostTotal": westernMedicineCostTotal,
  11184. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11185. "checkCostTotal": checkCostTotal,
  11186. "zhenChaCostTotal": zhenChaCostTotal,
  11187. "laboratoryCostTotal": laboratoryCostTotal,
  11188. "treatCostTotal": treatCostTotal,
  11189. })
  11190. }
  11191. }
  11192. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  11193. page, _ := c.GetInt64("page")
  11194. limit, _ := c.GetInt64("limit")
  11195. keywords := c.GetString("keywords")
  11196. start_time := c.GetString("start_time")
  11197. end_time := c.GetString("end_time")
  11198. //clr_type := c.GetString("clr_type")
  11199. insutype := c.GetString("insutype")
  11200. timeLayout := "2006-01-02"
  11201. loc, _ := time.LoadLocation("Local")
  11202. var theStartTIme int64
  11203. if len(start_time) > 0 {
  11204. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11205. theStartTIme = theTime.Unix()
  11206. }
  11207. var theEndtTIme int64
  11208. if len(end_time) > 0 {
  11209. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11210. theEndtTIme = theTime.Unix()
  11211. }
  11212. if page <= 0 {
  11213. page = 1
  11214. }
  11215. if limit <= 0 {
  11216. limit = 10
  11217. }
  11218. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  11219. c.ServeSuccessJSON(map[string]interface{}{
  11220. "total": total,
  11221. "list": list,
  11222. })
  11223. return
  11224. }
  11225. func (c *HisApiController) GetPutOnRecordList() {
  11226. page, _ := c.GetInt64("page")
  11227. limit, _ := c.GetInt64("limit")
  11228. keywords := c.GetString("keywords")
  11229. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  11230. if page <= 0 {
  11231. page = 1
  11232. }
  11233. if limit <= 0 {
  11234. limit = 10
  11235. }
  11236. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  11237. c.ServeSuccessJSON(map[string]interface{}{
  11238. "total": total,
  11239. "list": list,
  11240. })
  11241. return
  11242. }
  11243. func (c *HisApiController) GetCompareData() {
  11244. start_time := c.GetString("start_time")
  11245. end_time := c.GetString("end_time")
  11246. insutype := c.GetString("insutype")
  11247. clr_type := c.GetString("clr_type")
  11248. timeLayout := "2006-01-02"
  11249. loc, _ := time.LoadLocation("Local")
  11250. var theStartTIme int64
  11251. if len(start_time) > 0 {
  11252. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11253. if err != nil {
  11254. theStartTIme = 0
  11255. }
  11256. theStartTIme = theTime.Unix()
  11257. }
  11258. var theEndtTIme int64
  11259. if len(end_time) > 0 {
  11260. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11261. if err != nil {
  11262. theEndtTIme = 0
  11263. }
  11264. theEndtTIme = theTime.Unix()
  11265. }
  11266. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  11267. fmt.Println(err)
  11268. if err == nil {
  11269. c.ServeSuccessJSON(map[string]interface{}{
  11270. "list": formData,
  11271. })
  11272. } else {
  11273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  11274. return
  11275. }
  11276. }
  11277. func (c *HisApiController) GetFaPiaoData() {
  11278. order_id, _ := c.GetInt64("order_id")
  11279. patient_id, _ := c.GetInt64("patient_id")
  11280. //number := c.GetString("number")
  11281. adminUser := c.GetAdminUserInfo()
  11282. order, _ := service.GetHisOrderByID(order_id)
  11283. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11284. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11285. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11286. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11287. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  11288. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  11289. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11290. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11291. var bedCostTotal float64 = 0 //床位总费
  11292. var bedCostSelfTotal float64 = 0 //床位自费
  11293. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11294. var operationCostTotal float64 = 0 //手术费
  11295. var operationCostSelfTotal float64 = 0 //手术费
  11296. var operationCostPartSelfTotal float64 = 0 //手术费
  11297. var otherCostTotal float64 = 0 //其他费用
  11298. var otherCostSelfTotal float64 = 0 //其他费用
  11299. var otherCostPartSelfTotal float64 = 0 //其他费用
  11300. var materialCostTotal float64 = 0 //材料费
  11301. var materialCostSelfTotal float64 = 0 //材料费
  11302. var materialCostPartSelfTotal float64 = 0 //材料费
  11303. var westernMedicineCostTotal float64 = 0 //西药费
  11304. var westernMedicineCostSelfTotal float64 = 0 //西药费
  11305. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11306. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11307. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11308. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11309. var checkCostTotal float64 = 0 //检查费
  11310. var checkCostSelfTotal float64 = 0 //检查费
  11311. var checkCostPartSelfTotal float64 = 0 //检查费
  11312. var hiliCostTotal float64 = 0 //护理费
  11313. var hiliCostSelfTotal float64 = 0 //护理费
  11314. var hiliCostPartSelfTotal float64 = 0 //护理费
  11315. var laboratoryCostTotal float64 = 0 //化验费
  11316. var laboratoryCostSelfTotal float64 = 0 //化验费
  11317. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11318. var treatCostTotal float64 = 0 //治疗费用
  11319. var treatCostSelfTotal float64 = 0 //治疗费用
  11320. var treatCostPartSelfTotal float64 = 0 //治疗费用
  11321. var zhenChaCostTotal float64 = 0 //其他费用
  11322. var zhenChaCostSelfTotal float64 = 0 //其他费用
  11323. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11324. decimal.DivisionPrecision = 2
  11325. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11326. var balanceAccountsType int64
  11327. if his.ID > 0 {
  11328. balanceAccountsType = his.BalanceAccountsType
  11329. } else {
  11330. balanceAccountsType = his_hospital_record.BalanceAccountsType
  11331. }
  11332. if balanceAccountsType == 2 {
  11333. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11334. for _, item := range orderInfos_two {
  11335. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11336. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11337. item.MedChrgitmType = "09"
  11338. }
  11339. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11340. if item.HisPrescriptionProject.Type == 2 {
  11341. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11342. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11343. case 0:
  11344. item.MedChrgitmType = "0"
  11345. break
  11346. case 1:
  11347. item.MedChrgitmType = "14"
  11348. break
  11349. case 2:
  11350. item.MedChrgitmType = "05"
  11351. break
  11352. case 3:
  11353. item.MedChrgitmType = "03"
  11354. break
  11355. case 4:
  11356. item.MedChrgitmType = "03"
  11357. break
  11358. case 5:
  11359. item.MedChrgitmType = "08"
  11360. break
  11361. case 6:
  11362. item.MedChrgitmType = "14"
  11363. break
  11364. case 7:
  11365. item.MedChrgitmType = "14"
  11366. break
  11367. case 8:
  11368. item.MedChrgitmType = "03"
  11369. break
  11370. case 9:
  11371. item.MedChrgitmType = "14"
  11372. break
  11373. case 10:
  11374. item.MedChrgitmType = "14"
  11375. break
  11376. case 11:
  11377. item.MedChrgitmType = "06"
  11378. break
  11379. case 12:
  11380. item.MedChrgitmType = "12"
  11381. break
  11382. case 13:
  11383. item.MedChrgitmType = "01"
  11384. break
  11385. case 14:
  11386. item.MedChrgitmType = "04"
  11387. break
  11388. case 15:
  11389. item.MedChrgitmType = "02"
  11390. break
  11391. }
  11392. } else {
  11393. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11394. case 1:
  11395. item.MedChrgitmType = "14"
  11396. break
  11397. case 2:
  11398. item.MedChrgitmType = "05"
  11399. break
  11400. case 3:
  11401. item.MedChrgitmType = "04"
  11402. break
  11403. case 4:
  11404. item.MedChrgitmType = "03"
  11405. break
  11406. case 5:
  11407. item.MedChrgitmType = "08"
  11408. break
  11409. case 6:
  11410. item.MedChrgitmType = "14"
  11411. break
  11412. case 7:
  11413. item.MedChrgitmType = "14"
  11414. break
  11415. case 8:
  11416. item.MedChrgitmType = "03"
  11417. break
  11418. case 9:
  11419. item.MedChrgitmType = "14"
  11420. break
  11421. }
  11422. }
  11423. } else if item.HisPrescriptionProject.Type == 3 {
  11424. item.MedChrgitmType = "08"
  11425. }
  11426. }
  11427. }
  11428. for _, item := range orderInfos_two {
  11429. fmt.Println(item.MedChrgitmType)
  11430. if item.MedChrgitmType == "07" { //床位费
  11431. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11432. hiliCostSelfTotal = hiliCostTotal
  11433. }
  11434. if item.MedChrgitmType == "01" { //床位费
  11435. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11436. bedCostSelfTotal = bedCostTotal
  11437. }
  11438. if item.MedChrgitmType == "02" { //诊察费
  11439. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11440. zhenChaCostSelfTotal = zhenChaCostTotal
  11441. }
  11442. if item.MedChrgitmType == "03" { //检查费
  11443. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11444. checkCostSelfTotal = checkCostTotal
  11445. }
  11446. if item.MedChrgitmType == "04" { //化验费
  11447. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11448. laboratoryCostSelfTotal = laboratoryCostTotal
  11449. }
  11450. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11451. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11452. treatCostSelfTotal = treatCostTotal
  11453. }
  11454. if item.MedChrgitmType == "06" { //手术费
  11455. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11456. operationCostSelfTotal = treatCostTotal
  11457. }
  11458. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  11459. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11460. materialCostSelfTotal = materialCostTotal
  11461. }
  11462. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11463. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11464. westernMedicineCostSelfTotal = westernMedicineCostTotal
  11465. }
  11466. if item.MedChrgitmType == "11" { //中成费
  11467. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11468. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11469. }
  11470. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11471. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11472. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11473. otherCostSelfTotal = otherCostTotal
  11474. }
  11475. } else {
  11476. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11477. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11478. otherCostSelfTotal = otherCostTotal
  11479. }
  11480. }
  11481. }
  11482. } else {
  11483. for _, item := range orderInfos {
  11484. if item.MedChrgitmType == "01" { //床位费
  11485. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11486. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11487. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11488. }
  11489. if item.MedChrgitmType == "02" { //诊察费
  11490. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11491. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11492. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11493. }
  11494. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11495. if item.MedChrgitmType == "03" { //检查费
  11496. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11497. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11498. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11499. }
  11500. } else {
  11501. if item.MedChrgitmType == "03" { //检查费
  11502. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11503. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11504. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11505. }
  11506. }
  11507. if item.MedChrgitmType == "04" { //化验费
  11508. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11509. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11510. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11511. }
  11512. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11513. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11514. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11515. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11516. }
  11517. if item.MedChrgitmType == "06" { //手术费
  11518. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11519. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11520. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11521. }
  11522. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11523. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11524. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11525. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11526. }
  11527. if item.MedChrgitmType == "07" { //护理
  11528. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11529. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11530. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11531. }
  11532. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11533. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11534. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11535. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11536. }
  11537. if item.MedChrgitmType == "11" { //中成费
  11538. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11539. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11540. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11541. }
  11542. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11543. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11544. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11545. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11546. }
  11547. }
  11548. }
  11549. timeLayout := "2006-01-02"
  11550. loc, _ := time.LoadLocation("Local")
  11551. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11552. if err != nil {
  11553. }
  11554. startRecordDateTime := startTime.Unix()
  11555. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11556. if err != nil {
  11557. }
  11558. endRecordDateTime := endTime.Unix()
  11559. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11560. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11561. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11562. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11563. c.ServeSuccessJSON(map[string]interface{}{
  11564. "charge_admin_name": charge_admin.UserName,
  11565. "order_number": order.Number, //业务流水号
  11566. "id_card_no": his.IdCardNo, //社会保障号
  11567. "patient": patient,
  11568. "department_name": department.Name, //科室
  11569. "number": his.Number, //门诊号
  11570. "date": order.SettleAccountsDate, //结算日期
  11571. "name": order.PsnName, //姓名
  11572. "gender": patient.Gender, //性别
  11573. "psn_cash_money": order.PsnCashPay, //个人支付
  11574. "pay_way": "门诊", //结算方式
  11575. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11576. "admin_user_name": admin.UserName, //收款员
  11577. "order": order,
  11578. "order_info": orderInfos_two,
  11579. "his": his,
  11580. "bedCostTotal": bedCostTotal,
  11581. "bedCostSelfTotal": bedCostSelfTotal,
  11582. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11583. "operationCostTotal": operationCostTotal,
  11584. "operationCostSelfTotal": operationCostSelfTotal,
  11585. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11586. "otherCostTotal": otherCostTotal,
  11587. "otherCostSelfTotal": otherCostSelfTotal,
  11588. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11589. "materialCostTotal": materialCostTotal,
  11590. "materialCostSelfTotal": materialCostSelfTotal,
  11591. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11592. "westernMedicineCostTotal": westernMedicineCostTotal,
  11593. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11594. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11595. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11596. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11597. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11598. "checkCostTotal": checkCostTotal,
  11599. "checkCostSelfTotal": checkCostSelfTotal,
  11600. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11601. "laboratoryCostTotal": laboratoryCostTotal,
  11602. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11603. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11604. "treatCostTotal": treatCostTotal,
  11605. "treatCostSelfTotal": treatCostSelfTotal,
  11606. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11607. "zhenChaCostTotal": zhenChaCostTotal,
  11608. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11609. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11610. "his_hospital_record": his_hospital_record,
  11611. "pre_pay_money": pre_pay_money,
  11612. "refund_sum": sum,
  11613. "doctor_info": doctor_info,
  11614. "hiliCostTotal": hiliCostTotal,
  11615. "hiliCostSelfTotal": hiliCostSelfTotal,
  11616. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11617. })
  11618. }
  11619. //func (c *HisApiController) GetFaPiaoDatas() {
  11620. // order_ids := c.GetString("order_ids")
  11621. // patient_id, _ := c.GetInt64("patient_id")
  11622. // adminUser := c.GetAdminUserInfo()
  11623. //
  11624. // orders := strings.Split(order_ids, ",")
  11625. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11626. //
  11627. // for _, item := range orders {
  11628. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11629. // order, _ := service.GetHisOrderByID(order_id)
  11630. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11631. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11632. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11633. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11634. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11635. //
  11636. // }
  11637. //
  11638. // var bedCostTotal float64 = 0 //床位总费
  11639. // var bedCostSelfTotal float64 = 0 //床位自费
  11640. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11641. //
  11642. // var operationCostTotal float64 = 0 //手术费
  11643. // var operationCostSelfTotal float64 = 0 //手术费
  11644. // var operationCostPartSelfTotal float64 = 0 //手术费
  11645. //
  11646. // var otherCostTotal float64 = 0 //其他费用
  11647. // var otherCostSelfTotal float64 = 0 //其他费用
  11648. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11649. //
  11650. // var materialCostTotal float64 = 0 //材料费
  11651. // var materialCostSelfTotal float64 = 0 //材料费
  11652. // var materialCostPartSelfTotal float64 = 0 //材料费
  11653. //
  11654. // var westernMedicineCostTotal float64 = 0 //西药费
  11655. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11656. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11657. //
  11658. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11659. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11660. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11661. //
  11662. // var checkCostTotal float64 = 0 //检查费
  11663. // var checkCostSelfTotal float64 = 0 //检查费
  11664. // var checkCostPartSelfTotal float64 = 0 //检查费
  11665. //
  11666. // var laboratoryCostTotal float64 = 0 //化验费
  11667. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11668. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11669. //
  11670. // var treatCostTotal float64 = 0 //治疗费用
  11671. // var treatCostSelfTotal float64 = 0 //治疗费用
  11672. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11673. //
  11674. // var zhenChaCostTotal float64 = 0 //其他费用
  11675. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11676. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11677. //
  11678. // decimal.DivisionPrecision = 2
  11679. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11680. //
  11681. // var balanceAccountsType int64
  11682. // if his.ID > 0 {
  11683. // balanceAccountsType = his.BalanceAccountsType
  11684. // } else {
  11685. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11686. // }
  11687. // if balanceAccountsType == 2 {
  11688. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11689. // for _, item := range orderInfos_two {
  11690. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11691. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11692. // item.MedChrgitmType = "09"
  11693. // }
  11694. //
  11695. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11696. // if item.HisPrescriptionProject.Type == 2 {
  11697. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11698. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11699. // case 0:
  11700. // item.MedChrgitmType = "0"
  11701. // break
  11702. // case 1:
  11703. // item.MedChrgitmType = "14"
  11704. // break
  11705. // case 2:
  11706. // item.MedChrgitmType = "05"
  11707. //
  11708. // break
  11709. // case 3:
  11710. // item.MedChrgitmType = "03"
  11711. //
  11712. // break
  11713. // case 4:
  11714. // item.MedChrgitmType = "03"
  11715. //
  11716. // break
  11717. // case 5:
  11718. // item.MedChrgitmType = "08"
  11719. //
  11720. // break
  11721. // case 6:
  11722. // item.MedChrgitmType = "14"
  11723. //
  11724. // break
  11725. // case 7:
  11726. // item.MedChrgitmType = "14"
  11727. //
  11728. // break
  11729. // case 8:
  11730. // item.MedChrgitmType = "03"
  11731. // break
  11732. // case 9:
  11733. // item.MedChrgitmType = "14"
  11734. // break
  11735. // case 10:
  11736. // item.MedChrgitmType = "14"
  11737. // break
  11738. // case 11:
  11739. // item.MedChrgitmType = "06"
  11740. // break
  11741. // case 12:
  11742. // item.MedChrgitmType = "12"
  11743. // break
  11744. // case 13:
  11745. // item.MedChrgitmType = "01"
  11746. // break
  11747. // case 14:
  11748. // item.MedChrgitmType = "04"
  11749. // break
  11750. // case 15:
  11751. // item.MedChrgitmType = "02"
  11752. // break
  11753. //
  11754. // }
  11755. //
  11756. // } else {
  11757. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11758. //
  11759. // case 1:
  11760. // item.MedChrgitmType = "14"
  11761. // break
  11762. // case 2:
  11763. // item.MedChrgitmType = "05"
  11764. //
  11765. // break
  11766. // case 3:
  11767. // item.MedChrgitmType = "03"
  11768. //
  11769. // break
  11770. // case 4:
  11771. // item.MedChrgitmType = "03"
  11772. //
  11773. // break
  11774. // case 5:
  11775. // item.MedChrgitmType = "08"
  11776. //
  11777. // break
  11778. // case 6:
  11779. // item.MedChrgitmType = "14"
  11780. //
  11781. // break
  11782. // case 7:
  11783. // item.MedChrgitmType = "14"
  11784. //
  11785. // break
  11786. // case 8:
  11787. // item.MedChrgitmType = "03"
  11788. // break
  11789. // case 9:
  11790. // item.MedChrgitmType = "14"
  11791. // break
  11792. //
  11793. // }
  11794. //
  11795. // }
  11796. //
  11797. // } else if item.HisPrescriptionProject.Type == 3 {
  11798. // item.MedChrgitmType = "08"
  11799. // }
  11800. // }
  11801. // }
  11802. //
  11803. // for _, item := range orderInfos_two {
  11804. // fmt.Println(item.MedChrgitmType)
  11805. // if item.MedChrgitmType == "01" { //床位费
  11806. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11807. // bedCostSelfTotal = bedCostTotal
  11808. // }
  11809. //
  11810. // if item.MedChrgitmType == "02" { //诊察费
  11811. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11812. // zhenChaCostSelfTotal = zhenChaCostTotal
  11813. // }
  11814. //
  11815. // if item.MedChrgitmType == "03" { //检查费
  11816. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11817. // checkCostSelfTotal = checkCostTotal
  11818. // }
  11819. //
  11820. // if item.MedChrgitmType == "04" { //化验费
  11821. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11822. // laboratoryCostSelfTotal = laboratoryCostTotal
  11823. // }
  11824. //
  11825. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11826. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11827. // treatCostSelfTotal = treatCostTotal
  11828. // }
  11829. //
  11830. // if item.MedChrgitmType == "06" { //手术费
  11831. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11832. // operationCostSelfTotal = treatCostTotal
  11833. // }
  11834. //
  11835. // if item.MedChrgitmType == "08" { //材料费
  11836. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11837. // materialCostSelfTotal = materialCostTotal
  11838. // }
  11839. //
  11840. // if item.MedChrgitmType == "09" { //西药费
  11841. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11842. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11843. // }
  11844. //
  11845. // if item.MedChrgitmType == "11" { //中成费
  11846. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11847. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11848. // }
  11849. //
  11850. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11851. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11852. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11853. // otherCostSelfTotal = otherCostTotal
  11854. // }
  11855. // } else {
  11856. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11857. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11858. // otherCostSelfTotal = otherCostTotal
  11859. // }
  11860. //
  11861. // }
  11862. //
  11863. // }
  11864. //
  11865. // } else {
  11866. // for _, item := range orderInfos {
  11867. // if item.MedChrgitmType == "01" { //床位费
  11868. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11869. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11870. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11871. // }
  11872. //
  11873. // if item.MedChrgitmType == "02" { //诊察费
  11874. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11875. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11876. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11877. // }
  11878. //
  11879. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11880. // if item.MedChrgitmType == "03" { //检查费
  11881. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11882. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11883. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11884. //
  11885. // }
  11886. // } else {
  11887. // if item.MedChrgitmType == "03" { //检查费
  11888. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11889. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11890. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11891. // }
  11892. //
  11893. // }
  11894. //
  11895. // if item.MedChrgitmType == "04" { //化验费
  11896. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11897. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11898. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11899. //
  11900. // }
  11901. //
  11902. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11903. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11904. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11905. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11906. //
  11907. // }
  11908. //
  11909. // if item.MedChrgitmType == "06" { //手术费
  11910. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11911. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11912. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11913. // }
  11914. //
  11915. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11916. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11917. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11918. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11919. // }
  11920. //
  11921. // if item.MedChrgitmType == "09" { //西药费
  11922. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11923. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11924. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11925. // }
  11926. //
  11927. // if item.MedChrgitmType == "11" { //中成费
  11928. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11929. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11930. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11931. // }
  11932. //
  11933. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11934. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11935. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11936. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11937. // }
  11938. //
  11939. // }
  11940. // }
  11941. // timeLayout := "2006-01-02"
  11942. // loc, _ := time.LoadLocation("Local")
  11943. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11944. // if err != nil {
  11945. // }
  11946. // startRecordDateTime := startTime.Unix()
  11947. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11948. // if err != nil {
  11949. // }
  11950. // endRecordDateTime := endTime.Unix()
  11951. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11952. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11953. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11954. //
  11955. // c.ServeSuccessJSON(map[string]interface{}{
  11956. // "order_number": order.Number, //业务流水号
  11957. // "id_card_no": his.IdCardNo, //社会保障号
  11958. // "department_name": department.Name, //科室
  11959. // "number": his.Number, //门诊号
  11960. // "date": order.SettleAccountsDate, //结算日期
  11961. // "name": order.PsnName, //姓名
  11962. // "gender": patient.Gender, //性别
  11963. // "psn_cash_money": order.PsnCashPay, //个人支付
  11964. // "pay_way": "门诊", //结算方式
  11965. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11966. // "admin_user_name": admin.UserName, //收款员
  11967. // "order": order,
  11968. // "order_info": orderInfos_two,
  11969. // "his": his,
  11970. // "bedCostTotal": bedCostTotal,
  11971. // "bedCostSelfTotal": bedCostSelfTotal,
  11972. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11973. // "operationCostTotal": operationCostTotal,
  11974. // "operationCostSelfTotal": operationCostSelfTotal,
  11975. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11976. // "otherCostTotal": otherCostTotal,
  11977. // "otherCostSelfTotal": otherCostSelfTotal,
  11978. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11979. // "materialCostTotal": materialCostTotal,
  11980. // "materialCostSelfTotal": materialCostSelfTotal,
  11981. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11982. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11983. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11984. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11985. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11986. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11987. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11988. // "checkCostTotal": checkCostTotal,
  11989. // "checkCostSelfTotal": checkCostSelfTotal,
  11990. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11991. // "laboratoryCostTotal": laboratoryCostTotal,
  11992. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11993. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11994. // "treatCostTotal": treatCostTotal,
  11995. // "treatCostSelfTotal": treatCostSelfTotal,
  11996. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11997. // "zhenChaCostTotal": zhenChaCostTotal,
  11998. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11999. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  12000. // "his_hospital_record": his_hospital_record,
  12001. // "pre_pay_money": pre_pay_money,
  12002. // "refund_sum": sum,
  12003. // })
  12004. //
  12005. //}
  12006. func (this *HisApiController) GetIncomeStatisticsData() {
  12007. start_time := this.GetString("start_time")
  12008. end_time := this.GetString("end_time")
  12009. key_words := this.GetString("key_words")
  12010. limit, _ := this.GetInt64("limit")
  12011. page, _ := this.GetInt64("page")
  12012. if page <= 0 {
  12013. page = 1
  12014. }
  12015. if limit <= 0 {
  12016. limit = 10
  12017. }
  12018. statistics_type, _ := this.GetInt64("statistics_type")
  12019. admin := this.GetAdminUserInfo()
  12020. timeLayout := "2006-01-02"
  12021. loc, _ := time.LoadLocation("Local")
  12022. var theStartTIme int64
  12023. if len(start_time) > 0 {
  12024. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12025. if err != nil {
  12026. theStartTIme = 0
  12027. }
  12028. theStartTIme = theTime.Unix()
  12029. }
  12030. var theEndtTIme int64
  12031. if len(end_time) > 0 {
  12032. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12033. if err != nil {
  12034. theEndtTIme = 0
  12035. }
  12036. theEndtTIme = theTime.Unix()
  12037. }
  12038. if statistics_type == 1 {
  12039. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  12040. this.ServeSuccessJSON(map[string]interface{}{
  12041. "list": list,
  12042. "total": total,
  12043. })
  12044. } else {
  12045. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  12046. this.ServeSuccessJSON(map[string]interface{}{
  12047. "list": list,
  12048. "total": total,
  12049. })
  12050. }
  12051. }
  12052. func (c *HisApiController) PostProjectInformation() {
  12053. adminUser := c.GetAdminUserInfo()
  12054. orgId := adminUser.CurrentOrgId
  12055. dataBody := make(map[string]interface{}, 0)
  12056. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12057. if err != nil {
  12058. utils.ErrorLog(err.Error())
  12059. return
  12060. }
  12061. utils.ErrorLog("%v", dataBody)
  12062. var projectList []*models.HisProject
  12063. var total_goods []interface{}
  12064. tempProjects := dataBody["projects"].([]interface{})
  12065. total_goods = tempProjects
  12066. for index, projectMap := range tempProjects {
  12067. projectM := projectMap.(map[string]interface{})
  12068. var project models.HisProject
  12069. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  12070. utils.ErrorLog("project_name")
  12071. return
  12072. }
  12073. project_name, _ := projectM["project_name"].(string)
  12074. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  12075. err_log := models.ExportErrLog{
  12076. LogType: 6,
  12077. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12078. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  12079. Status: 1,
  12080. CreateTime: time.Now().Unix(),
  12081. UpdateTime: time.Now().Unix(),
  12082. ExportTime: time.Now().Unix(),
  12083. }
  12084. service.CreateExportErrLog(&err_log)
  12085. continue
  12086. }
  12087. project.ProjectName = project_name
  12088. prices := projectM["price"].(string)
  12089. price, _ := strconv.ParseFloat(prices, 64)
  12090. if price <= 0 { //名字为空则生成一条导入错误日志
  12091. err_log := models.ExportErrLog{
  12092. LogType: 6,
  12093. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12094. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  12095. Status: 1,
  12096. CreateTime: time.Now().Unix(),
  12097. UpdateTime: time.Now().Unix(),
  12098. ExportTime: time.Now().Unix(),
  12099. }
  12100. service.CreateExportErrLog(&err_log)
  12101. continue
  12102. }
  12103. project.Price = price
  12104. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  12105. utils.ErrorLog("unit_id")
  12106. return
  12107. }
  12108. unit := projectM["unit"].(string)
  12109. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  12110. err_log := models.ExportErrLog{
  12111. LogType: 6,
  12112. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12113. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  12114. Status: 1,
  12115. CreateTime: time.Now().Unix(),
  12116. UpdateTime: time.Now().Unix(),
  12117. ExportTime: time.Now().Unix(),
  12118. }
  12119. service.CreateExportErrLog(&err_log)
  12120. continue
  12121. }
  12122. project.Unit = unit
  12123. cost_classify := projectM["cost_classify"].(string)
  12124. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  12125. err_log := models.ExportErrLog{
  12126. LogType: 6,
  12127. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12128. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12129. Status: 1,
  12130. CreateTime: time.Now().Unix(),
  12131. UpdateTime: time.Now().Unix(),
  12132. ExportTime: time.Now().Unix(),
  12133. }
  12134. service.CreateExportErrLog(&err_log)
  12135. continue
  12136. }
  12137. var costClassify = "费用类别"
  12138. var cost_classify_id int64
  12139. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  12140. if len(cost_classify) != 0 {
  12141. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  12142. if errcode == gorm.ErrRecordNotFound {
  12143. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  12144. dataconfig := models.DictDataconfig{
  12145. ParentId: costClassifyConfig.ID,
  12146. Module: "system",
  12147. OrgId: orgId,
  12148. Name: cost_classify,
  12149. FieldName: "",
  12150. Value: costConfig.Value + 1,
  12151. CreatedTime: "",
  12152. UpdatedTime: "",
  12153. CreateUserId: adminUser.AdminUser.Id,
  12154. Status: 1,
  12155. Remark: "",
  12156. DeleteIdSystem: 0,
  12157. Title: "",
  12158. Content: "",
  12159. Order: 0,
  12160. Code: "",
  12161. }
  12162. service.CreatedDicConfig(&dataconfig)
  12163. }
  12164. }
  12165. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  12166. for _, it := range costClassList {
  12167. if cost_classify == it.Name {
  12168. cost_classify_id = int64(it.Value)
  12169. }
  12170. }
  12171. project.CostClassify = cost_classify_id
  12172. executive_section := projectM["executive_section"].(string)
  12173. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  12174. err_log := models.ExportErrLog{
  12175. LogType: 6,
  12176. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12177. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  12178. Status: 1,
  12179. CreateTime: time.Now().Unix(),
  12180. UpdateTime: time.Now().Unix(),
  12181. ExportTime: time.Now().Unix(),
  12182. }
  12183. service.CreateExportErrLog(&err_log)
  12184. continue
  12185. }
  12186. if len(executive_section) != 0 {
  12187. //查找科室是否有内容
  12188. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  12189. if errcodedepart == gorm.ErrRecordNotFound {
  12190. department := models.XtHisDepartment{
  12191. Name: executive_section,
  12192. Status: 1,
  12193. UserOrgId: adminUser.CurrentOrgId,
  12194. CreatedTime: time.Now().Unix(),
  12195. }
  12196. service.CreateDePartment(&department)
  12197. }
  12198. }
  12199. var executive_section_id int64
  12200. departMentList, _ := service.GetAllDepartMent(orgId)
  12201. for _, it := range departMentList {
  12202. if executive_section == it.Name {
  12203. executive_section_id = it.ID
  12204. }
  12205. }
  12206. project.ExecutiveSection = executive_section_id
  12207. medical_coverage := projectM["medical_coverage"].(string)
  12208. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  12209. err_log := models.ExportErrLog{
  12210. LogType: 6,
  12211. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12212. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12213. Status: 1,
  12214. CreateTime: time.Now().Unix(),
  12215. UpdateTime: time.Now().Unix(),
  12216. ExportTime: time.Now().Unix(),
  12217. }
  12218. service.CreateExportErrLog(&err_log)
  12219. continue
  12220. }
  12221. var medicalCoverage = "医保等级"
  12222. var medical_coverage_id int64
  12223. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  12224. if len(medical_coverage) != 0 {
  12225. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  12226. if errormedicalcoverage == gorm.ErrRecordNotFound {
  12227. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  12228. dataconfig := models.DictDataconfig{
  12229. ParentId: medicalCoverageConfig.ID,
  12230. Module: "system",
  12231. OrgId: orgId,
  12232. Name: medical_coverage,
  12233. FieldName: "",
  12234. Value: medicalCoverageConfig.Value + 1,
  12235. CreatedTime: "",
  12236. UpdatedTime: "",
  12237. CreateUserId: adminUser.AdminUser.Id,
  12238. Status: 1,
  12239. Remark: "",
  12240. DeleteIdSystem: 0,
  12241. Title: "",
  12242. Content: "",
  12243. Order: 0,
  12244. Code: "",
  12245. }
  12246. service.CreatedDicConfig(&dataconfig)
  12247. }
  12248. }
  12249. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  12250. for _, it := range medicalCoverageList {
  12251. if medical_coverage == it.Name {
  12252. medical_coverage_id = int64(it.Value)
  12253. }
  12254. }
  12255. project.MedicalCoverage = medical_coverage_id
  12256. pinyin := projectM["pinyin"].(string)
  12257. project.Pinyin = pinyin
  12258. wubi := projectM["wubi"].(string)
  12259. project.Wubi = wubi
  12260. statistical_classification := projectM["statistical_classification"].(string)
  12261. var statisticalClassification = "统计分类"
  12262. var statistical_classification_id int64
  12263. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  12264. if len(statistical_classification) != 0 {
  12265. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  12266. if classificationerrcodes == gorm.ErrRecordNotFound {
  12267. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  12268. dataconfig := models.DictDataconfig{
  12269. ParentId: classiFication.ID,
  12270. Module: "system",
  12271. OrgId: orgId,
  12272. Name: statistical_classification,
  12273. FieldName: "",
  12274. Value: classiFicationConfig.Value + 1,
  12275. CreatedTime: "",
  12276. UpdatedTime: "",
  12277. CreateUserId: adminUser.AdminUser.Id,
  12278. Status: 1,
  12279. Remark: "",
  12280. DeleteIdSystem: 0,
  12281. Title: "",
  12282. Content: "",
  12283. Order: 0,
  12284. Code: "",
  12285. }
  12286. service.CreatedDicConfig(&dataconfig)
  12287. }
  12288. }
  12289. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  12290. for _, it := range classiFicationList {
  12291. if statistical_classification == it.Name {
  12292. statistical_classification_id = int64(it.Value)
  12293. }
  12294. }
  12295. project.StatisticalClassification = statistical_classification_id
  12296. disease_directory := int64(projectM["disease_directory"].(float64))
  12297. project.DiseaseDirectory = disease_directory
  12298. is_record := int64(projectM["is_record"].(float64))
  12299. project.IsRecord = is_record
  12300. medical_code := projectM["medical_code"].(string)
  12301. project.MedicalCode = medical_code
  12302. tube_color := projectM["tube_color"].(string)
  12303. var tubeColor = "试管颜色"
  12304. var tube_color_id int64
  12305. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  12306. if len(tube_color) != 0 {
  12307. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  12308. if errcodetube == gorm.ErrRecordNotFound {
  12309. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  12310. dataconfig := models.DictDataconfig{
  12311. ParentId: tubeColorConfig.ID,
  12312. Module: "system",
  12313. OrgId: orgId,
  12314. Name: tube_color,
  12315. FieldName: "",
  12316. Value: tubeConfig.Value + 1,
  12317. CreatedTime: "",
  12318. UpdatedTime: "",
  12319. CreateUserId: adminUser.AdminUser.Id,
  12320. Status: 1,
  12321. Remark: "",
  12322. DeleteIdSystem: 0,
  12323. Title: "",
  12324. Content: "",
  12325. Order: 0,
  12326. Code: "",
  12327. }
  12328. service.CreatedDicConfig(&dataconfig)
  12329. }
  12330. }
  12331. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  12332. for _, it := range tubeColorList {
  12333. if tube_color == it.Name {
  12334. tube_color_id = int64(it.Value)
  12335. }
  12336. }
  12337. project.TubeColor = tube_color_id
  12338. single_dose := projectM["single_dose"].(string)
  12339. project.SingleDose = single_dose
  12340. execution_frequency := projectM["execution_frequency"].(string)
  12341. project.ExecutionFrequency = execution_frequency
  12342. delivery_way := projectM["delivery_way"].(string)
  12343. project.DeliveryWay = delivery_way
  12344. number_days := projectM["number_days"].(string)
  12345. project.NumberDays = number_days
  12346. total := projectM["total"].(string)
  12347. project.Total = total
  12348. medical_status := int64(projectM["medical_status"].(float64))
  12349. project.MedicalStatus = medical_status
  12350. category := int64(projectM["category"].(float64))
  12351. project.Category = category
  12352. specail_project := int64(projectM["specail_project"].(float64))
  12353. project.SpecailProject = specail_project
  12354. social_security_directory_code := projectM["social_security_directory_code"].(string)
  12355. project.SocialSecurityDirectoryCode = social_security_directory_code
  12356. remark := projectM["remark"].(string)
  12357. project.Remark = remark
  12358. record_date := projectM["record_date"].(string)
  12359. timeLayout := "2006-01-02"
  12360. loc, _ := time.LoadLocation("Local")
  12361. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12362. project.RecordDate = theTime.Unix()
  12363. projectList = append(projectList, &project)
  12364. }
  12365. export_time := time.Now().Unix()
  12366. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  12367. if len(projectList) > 0 {
  12368. for _, item := range projectList {
  12369. hans := item.ProjectName // 要转换的汉字字符串
  12370. // 创建一个拼音转换器
  12371. p := pinyin.NewArgs()
  12372. // 将汉字转为拼音
  12373. pinyinSlice := pinyin.Pinyin(hans, p)
  12374. // 输出拼音
  12375. fmt.Println("Pinyin:", pinyinSlice)
  12376. // 获取首字母
  12377. firstLetter := ""
  12378. for _, py := range pinyinSlice {
  12379. if len(py) > 0 {
  12380. firstLetter += string(py[0][0])
  12381. }
  12382. }
  12383. item.FirstLetter = firstLetter
  12384. project := models.HisProject{
  12385. ProjectName: item.ProjectName,
  12386. Price: item.Price,
  12387. Unit: item.Unit,
  12388. CostClassify: item.CostClassify,
  12389. ExecutiveSection: item.ExecutiveSection,
  12390. MedicalCoverage: item.MedicalCoverage,
  12391. UserOrgId: orgId,
  12392. Status: 1,
  12393. CreatedTime: time.Now().Unix(),
  12394. Pinyin: item.Pinyin,
  12395. Wubi: item.Wubi,
  12396. StatisticalClassification: item.StatisticalClassification,
  12397. DiseaseDirectory: item.DiseaseDirectory,
  12398. IsRecord: item.IsRecord,
  12399. MedicalCode: item.MedicalCode,
  12400. TubeColor: item.TubeColor,
  12401. SingleDose: item.SingleDose,
  12402. DeliveryWay: item.DeliveryWay,
  12403. NumberDays: item.NumberDays,
  12404. Total: item.Total,
  12405. Category: item.Category,
  12406. MedicalStatus: item.MedicalStatus,
  12407. SpecailProject: item.SpecailProject,
  12408. RecordDate: item.RecordDate,
  12409. Remark: item.Remark,
  12410. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  12411. ExecutionFrequency: item.ExecutionFrequency,
  12412. FirstLetter: item.FirstLetter,
  12413. }
  12414. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  12415. if errcodeproject == gorm.ErrRecordNotFound {
  12416. service.CreateProjectInfomation(&project)
  12417. } else if errcodeproject == nil {
  12418. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  12419. }
  12420. log := models.ExportLog{
  12421. LogType: 6,
  12422. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12423. TotalNum: int64(len(total_goods)),
  12424. FailNum: int64(len(errLogs)),
  12425. SuccessNum: int64(len(projectList)),
  12426. CreateTime: time.Now().Unix(),
  12427. UpdateTime: time.Now().Unix(),
  12428. ExportTime: export_time,
  12429. Status: 1,
  12430. }
  12431. service.CreateExportLog(&log)
  12432. c.ServeSuccessJSON(map[string]interface{}{
  12433. "msg": "导入成功",
  12434. "total_num": len(total_goods),
  12435. "success_num": len(projectList),
  12436. "fail_num": int64(len(errLogs)),
  12437. })
  12438. }
  12439. } else {
  12440. log := models.ExportLog{
  12441. LogType: 6,
  12442. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12443. TotalNum: int64(len(total_goods)),
  12444. FailNum: int64(len(errLogs)),
  12445. SuccessNum: int64(len(projectList)),
  12446. CreateTime: time.Now().Unix(),
  12447. UpdateTime: time.Now().Unix(),
  12448. ExportTime: export_time,
  12449. Status: 1,
  12450. }
  12451. service.CreateExportLog(&log)
  12452. c.ServeSuccessJSON(map[string]interface{}{
  12453. "msg": "导入成功",
  12454. "total_num": len(total_goods),
  12455. "success_num": len(projectList),
  12456. "fail_num": int64(len(errLogs)),
  12457. })
  12458. }
  12459. }
  12460. //func (this *HisApiController) EditProjectInformation(){
  12461. //
  12462. // id, _ := this.GetInt64("id")
  12463. // project_team := this.GetString("project_team")
  12464. // price := this.GetString("price")
  12465. // price_float, _ := strconv.ParseFloat(price, 64)
  12466. // pinyin := this.GetString("pinyin")
  12467. // wubi := this.GetString("wubi")
  12468. // tube_color, _ := this.GetInt64("tube_color")
  12469. // team_type, _ := this.GetInt64("team_type")
  12470. // remark := this.GetString("remark")
  12471. // ids := this.GetString("ids")
  12472. // item_id := this.GetString("item_id")
  12473. // projectTeam := models.XtHisProjectTeam{
  12474. // ProjectTeam: project_team,
  12475. // Price: price_float,
  12476. // Pinyin: pinyin,
  12477. // Wubi: wubi,
  12478. // TubeColor: tube_color,
  12479. // TeamType: team_type,
  12480. // Remark: remark,
  12481. // ProjectId: ids,
  12482. // ItemId: item_id,
  12483. // }
  12484. //
  12485. //
  12486. // dataBody := make(map[string]interface{}, 0)
  12487. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12488. // if err != nil {
  12489. // utils.ErrorLog(err.Error())
  12490. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12491. // return
  12492. // }
  12493. //
  12494. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12495. //
  12496. //
  12497. // if err != nil {
  12498. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12499. // return
  12500. // }
  12501. //
  12502. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12503. // infos, _ := dataBody["info"].([]interface{})
  12504. // if len(infos) > 0 {
  12505. // var ids []string
  12506. //
  12507. // for _, item := range infos {
  12508. // items := item.(map[string]interface{})
  12509. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12510. // utils.ErrorLog("id")
  12511. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12512. // return
  12513. // }
  12514. // id := int64(items["id"].(float64))
  12515. //
  12516. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12517. // utils.ErrorLog("type")
  12518. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12519. // return
  12520. // }
  12521. // types := int64(items["type"].(float64))
  12522. //
  12523. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12524. // utils.ErrorLog("number")
  12525. // }
  12526. //
  12527. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12528. //
  12529. // projectList := models.XtHisProjectList{
  12530. // Number: number,
  12531. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12532. // ProjectId: id,
  12533. // Status: 1,
  12534. // CreatedTime: time.Now().Unix(),
  12535. // UpdatedTime: time.Now().Unix(),
  12536. // TeamId: projectTeam.ID,
  12537. // Type: types,
  12538. // }
  12539. // list := projectList
  12540. //
  12541. // service.CreateProjectList(&list)
  12542. //
  12543. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12544. //
  12545. // }
  12546. // ids_str := strings.Join(ids, ",")
  12547. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12548. // service.SaveProjectTeam(&projectTeam)
  12549. // this.ServeSuccessJSON(map[string]interface{}{
  12550. // "projectTeam": projectTeam,
  12551. // })
  12552. // }
  12553. // }
  12554. //}
  12555. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12556. name := c.GetString("name")
  12557. mode_id, _ := c.GetInt64("mode", 0)
  12558. types, _ := c.GetInt64("type", 0)
  12559. patient_id, _ := c.GetInt64("patient_id", 0)
  12560. types = 1
  12561. adminInfo := c.GetAdminUserInfo()
  12562. template := &models.HisPrescriptionTemplate{
  12563. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12564. PatientId: patient_id,
  12565. Type: types,
  12566. Status: 1,
  12567. Ctime: time.Now().Unix(),
  12568. Mtime: time.Now().Unix(),
  12569. Name: name,
  12570. Mode: mode_id,
  12571. }
  12572. dataBody := make(map[string]interface{}, 0)
  12573. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12574. if err != nil {
  12575. utils.ErrorLog(err.Error())
  12576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12577. return
  12578. }
  12579. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12580. //如果已经存在记录则删除处方
  12581. if template_one.ID > 0 {
  12582. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12583. var ids []int64
  12584. var org_id int64
  12585. for _, item := range ps {
  12586. org_id = c.GetAdminUserInfo().CurrentOrgId
  12587. ids = append(ids, item.ID)
  12588. }
  12589. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12590. if err2 == nil {
  12591. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12592. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12593. if len(prescriptions) > 0 {
  12594. for _, item := range prescriptions {
  12595. items := item.(map[string]interface{})
  12596. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12597. utils.ErrorLog("type")
  12598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12599. return
  12600. }
  12601. types := int64(items["type"].(float64))
  12602. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12603. utils.ErrorLog("med_type")
  12604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12605. return
  12606. }
  12607. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12608. ctime := time.Now().Unix()
  12609. prescription := &models.HisPrescriptionInfoTemplate{
  12610. PatientId: patient_id,
  12611. UserOrgId: adminInfo.CurrentOrgId,
  12612. Ctime: ctime,
  12613. Mtime: ctime,
  12614. Type: types,
  12615. Modifier: adminInfo.AdminUser.Id,
  12616. Creator: adminInfo.AdminUser.Id,
  12617. Status: 1,
  12618. PTemplateId: template_one.ID,
  12619. MedType: med_type,
  12620. }
  12621. service.CreateHisPrescriptionInfoTemplate(prescription)
  12622. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12623. advices := items["advices"].([]interface{})
  12624. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12625. ctime := time.Now().Unix()
  12626. mtime := ctime
  12627. if len(advices) > 0 {
  12628. for _, advice := range advices {
  12629. var s models.HisPrescriptionAdviceTemplate
  12630. s.PrescriptionId = prescription.ID
  12631. s.AdviceType = 2
  12632. s.StopState = 2
  12633. s.ExecutionState = 2
  12634. s.Status = 1
  12635. s.UserOrgId = adminInfo.CurrentOrgId
  12636. s.CreatedTime = ctime
  12637. s.UpdatedTime = mtime
  12638. s.PatientId = patient_id
  12639. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12640. if errcode > 0 {
  12641. c.ServeFailJSONWithSGJErrorCode(errcode)
  12642. return
  12643. }
  12644. service.CreateHisPrescriptionAdviceTemplate(&s)
  12645. }
  12646. }
  12647. }
  12648. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12649. projects := items["project"].([]interface{})
  12650. if len(projects) > 0 {
  12651. for _, project := range projects {
  12652. var p models.HisPrescriptionProjectTemplate
  12653. p.PrescriptionId = prescription.ID
  12654. p.Ctime = time.Now().Unix()
  12655. p.Mtime = time.Now().Unix()
  12656. p.PatientId = patient_id
  12657. p.UserOrgId = adminInfo.CurrentOrgId
  12658. p.Status = 1
  12659. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12660. if errcode > 0 {
  12661. c.ServeFailJSONWithSGJErrorCode(errcode)
  12662. return
  12663. }
  12664. service.CreateHisPrescriptionProjectTemplate(&p)
  12665. }
  12666. }
  12667. }
  12668. }
  12669. c.ServeSuccessJSON(map[string]interface{}{
  12670. "msg": "创建成功",
  12671. })
  12672. }
  12673. }
  12674. } else {
  12675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12676. return
  12677. }
  12678. } else {
  12679. err3 := service.CreateHisPrescriptionTemplate(template)
  12680. if err3 == nil {
  12681. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12682. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12683. if len(prescriptions) > 0 {
  12684. for _, item := range prescriptions {
  12685. items := item.(map[string]interface{})
  12686. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12687. utils.ErrorLog("type")
  12688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12689. return
  12690. }
  12691. types := int64(items["type"].(float64))
  12692. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12693. utils.ErrorLog("med_type")
  12694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12695. return
  12696. }
  12697. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12698. ctime := time.Now().Unix()
  12699. prescription := &models.HisPrescriptionInfoTemplate{
  12700. PatientId: patient_id,
  12701. UserOrgId: adminInfo.CurrentOrgId,
  12702. Ctime: ctime,
  12703. Mtime: ctime,
  12704. Type: types,
  12705. Modifier: adminInfo.AdminUser.Id,
  12706. Creator: adminInfo.AdminUser.Id,
  12707. Status: 1,
  12708. PTemplateId: template.ID,
  12709. MedType: med_type,
  12710. }
  12711. service.CreateHisPrescriptionInfoTemplate(prescription)
  12712. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12713. advices := items["advices"].([]interface{})
  12714. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12715. ctime := time.Now().Unix()
  12716. mtime := ctime
  12717. if len(advices) > 0 {
  12718. for _, advice := range advices {
  12719. var s models.HisPrescriptionAdviceTemplate
  12720. s.PrescriptionId = prescription.ID
  12721. s.AdviceType = 2
  12722. s.StopState = 2
  12723. s.ExecutionState = 2
  12724. s.Status = 1
  12725. s.UserOrgId = adminInfo.CurrentOrgId
  12726. s.CreatedTime = ctime
  12727. s.UpdatedTime = mtime
  12728. s.PatientId = patient_id
  12729. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12730. if errcode > 0 {
  12731. c.ServeFailJSONWithSGJErrorCode(errcode)
  12732. return
  12733. }
  12734. service.CreateHisPrescriptionAdviceTemplate(&s)
  12735. }
  12736. }
  12737. }
  12738. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12739. projects := items["project"].([]interface{})
  12740. if len(projects) > 0 {
  12741. for _, project := range projects {
  12742. var p models.HisPrescriptionProjectTemplate
  12743. p.PrescriptionId = prescription.ID
  12744. p.Ctime = time.Now().Unix()
  12745. p.Mtime = time.Now().Unix()
  12746. p.PatientId = patient_id
  12747. p.UserOrgId = adminInfo.CurrentOrgId
  12748. p.Status = 1
  12749. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12750. if errcode > 0 {
  12751. c.ServeFailJSONWithSGJErrorCode(errcode)
  12752. return
  12753. }
  12754. service.CreateHisPrescriptionProjectTemplate(&p)
  12755. }
  12756. }
  12757. }
  12758. }
  12759. c.ServeSuccessJSON(map[string]interface{}{
  12760. "msg": "创建成功",
  12761. })
  12762. }
  12763. }
  12764. } else {
  12765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12766. return
  12767. }
  12768. }
  12769. }
  12770. func (c *HisApiController) PreSettle() {
  12771. id, _ := c.GetInt64("id")
  12772. record_time := c.GetString("record_time")
  12773. his_patient_id, _ := c.GetInt64("his_patient_id")
  12774. timeLayout := "2006-01-02"
  12775. loc, _ := time.LoadLocation("Local")
  12776. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12777. diagnosis_id := c.GetString("diagnosis")
  12778. sick_type, _ := c.GetInt64("sick_type")
  12779. reg_type, _ := c.GetInt64("p_type")
  12780. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12781. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12782. if err != nil {
  12783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12784. return
  12785. }
  12786. recordDateTime := theTime.Unix()
  12787. adminUser := c.GetAdminUserInfo()
  12788. var prescriptions []*models.HisPrescription
  12789. var start_time int64
  12790. var end_time int64
  12791. ids_str := c.GetString("ids")
  12792. ids_arr := strings.Split(ids_str, ",")
  12793. fmt.Println(reg_type)
  12794. if settle_accounts_type == 1 { //日结
  12795. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12796. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12797. } else {
  12798. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12799. }
  12800. fmt.Println(prescriptions)
  12801. } else { //月结
  12802. start_time_str := c.GetString("start_time")
  12803. end_time_str := c.GetString("end_time")
  12804. timeLayout := "2006-01-02"
  12805. loc, _ := time.LoadLocation("Local")
  12806. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12807. if err != nil {
  12808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12809. return
  12810. }
  12811. recordStartTime := theStartTime.Unix()
  12812. start_time = recordStartTime
  12813. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12814. if err != nil {
  12815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12816. return
  12817. }
  12818. recordEndTime := theEndTime.Unix()
  12819. end_time = recordEndTime
  12820. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12821. }
  12822. if reg_type == 1111 || reg_type == 1112 {
  12823. reg_type = 11
  12824. }
  12825. timestamp := time.Now().Unix()
  12826. tempTime := time.Unix(timestamp, 0)
  12827. timeFormat := tempTime.Format("20060102150405")
  12828. chrgBchno := rand.Intn(100000) + 10000
  12829. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12830. strconv.FormatInt(his.PatientId, 10)
  12831. var ids []int64
  12832. for _, item := range prescriptions {
  12833. ids = append(ids, item.ID)
  12834. }
  12835. fmt.Println(ids)
  12836. var total float64
  12837. for _, item := range prescriptions {
  12838. fmt.Println(item)
  12839. if item.Type == 1 { //药品
  12840. for _, subItem := range item.HisDoctorAdviceInfo {
  12841. total = total + (subItem.Price * subItem.PrescribingNumber)
  12842. }
  12843. }
  12844. if item.Type == 2 { //项目
  12845. for _, subItem := range item.HisPrescriptionProject {
  12846. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12847. total = total + (subItem.Price * cnt)
  12848. }
  12849. }
  12850. for _, subItem := range item.HisAdditionalCharge {
  12851. total = total + (subItem.Price * float64(subItem.Count))
  12852. }
  12853. }
  12854. allTotal := fmt.Sprintf("%.2f", total)
  12855. totals, _ := strconv.ParseFloat(allTotal, 64)
  12856. order := &models.HisOrder{
  12857. UserOrgId: adminUser.CurrentOrgId,
  12858. HisPatientId: his.ID,
  12859. PatientId: id,
  12860. SettleAccountsDate: recordDateTime,
  12861. Ctime: time.Now().Unix(),
  12862. Mtime: time.Now().Unix(),
  12863. Status: 1,
  12864. OrderStatus: 1,
  12865. MdtrtId: his.Number,
  12866. Number: chrg_bchno,
  12867. MedfeeSumamt: totals,
  12868. SettleEndTime: end_time,
  12869. SettleStartTime: start_time,
  12870. SettleType: settle_accounts_type,
  12871. PsnPartAmt: totals,
  12872. PsnCashPay: totals,
  12873. PType: 2,
  12874. IsPre: 1,
  12875. MedType: strconv.Itoa(int(reg_type)),
  12876. Diagnosis: diagnosis_id,
  12877. }
  12878. err = service.CreateOrder(order)
  12879. if err != nil {
  12880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12881. return
  12882. }
  12883. var customs []*Custom
  12884. for _, item := range prescriptions {
  12885. fmt.Println(item.Type)
  12886. if item.Type == 1 { //药品
  12887. for _, subItem := range item.HisDoctorAdviceInfo {
  12888. cus := &Custom{
  12889. AdviceId: subItem.ID,
  12890. ProjectId: 0,
  12891. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12892. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12893. FeedetlSn: subItem.FeedetlSn,
  12894. Price: fmt.Sprintf("%.2f", subItem.Price),
  12895. MedListCodg: subItem.MedListCodg,
  12896. Type: 1,
  12897. }
  12898. customs = append(customs, cus)
  12899. }
  12900. }
  12901. if item.Type == 2 { //项目
  12902. for _, subItem := range item.HisPrescriptionProject {
  12903. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12904. cus := &Custom{
  12905. AdviceId: 0,
  12906. ProjectId: subItem.ID,
  12907. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12908. Cut: fmt.Sprintf("%.2f", cnt),
  12909. FeedetlSn: subItem.FeedetlSn,
  12910. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12911. MedListCodg: subItem.MedListCodg,
  12912. Type: 2,
  12913. }
  12914. customs = append(customs, cus)
  12915. }
  12916. }
  12917. for _, item := range item.HisAdditionalCharge {
  12918. cus := &Custom{
  12919. ItemId: item.ID,
  12920. AdviceId: 0,
  12921. ProjectId: 0,
  12922. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12923. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12924. FeedetlSn: item.FeedetlSn,
  12925. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12926. MedListCodg: item.XtHisAddtionConfig.Code,
  12927. Type: 3,
  12928. }
  12929. customs = append(customs, cus)
  12930. }
  12931. }
  12932. fmt.Println(customs)
  12933. for _, item := range customs {
  12934. var advice_id int64 = 0
  12935. var project_id int64 = 0
  12936. var item_id int64 = 0
  12937. var types int64 = 0
  12938. if item.Type == 1 {
  12939. advice_id = item.AdviceId
  12940. project_id = 0
  12941. item_id = 0
  12942. } else if item.Type == 2 {
  12943. advice_id = 0
  12944. item_id = 0
  12945. project_id = item.ProjectId
  12946. } else if item.Type == 3 {
  12947. advice_id = 0
  12948. item_id = item.ItemId
  12949. project_id = 0
  12950. }
  12951. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12952. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12953. pric, _ := strconv.ParseFloat(item.Price, 32)
  12954. info := &models.HisOrderInfo{
  12955. OrderNumber: order.Number,
  12956. UploadDate: time.Now().Unix(),
  12957. AdviceId: advice_id,
  12958. DetItemFeeSumamt: detItemFeeSumamt,
  12959. Cnt: cut,
  12960. Pric: pric,
  12961. PatientId: id,
  12962. Status: 1,
  12963. Mtime: time.Now().Unix(),
  12964. Ctime: time.Now().Unix(),
  12965. UserOrgId: adminUser.CurrentOrgId,
  12966. HisPatientId: his.ID,
  12967. OrderId: order.ID,
  12968. ProjectId: project_id,
  12969. Type: types,
  12970. ItemId: item_id,
  12971. }
  12972. service.CreateOrderInfo(info)
  12973. }
  12974. his.SickType = sick_type
  12975. service.UpdataHisPateint(&his)
  12976. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12977. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12978. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12979. if err == nil {
  12980. c.ServeSuccessJSON(map[string]interface{}{
  12981. "msg": "结算成功",
  12982. })
  12983. }
  12984. }
  12985. type CustomOrderInfo struct {
  12986. Name string
  12987. Spec string
  12988. Unit string
  12989. Count float64
  12990. Price float64
  12991. Total float64
  12992. }
  12993. func (c *HisApiController) GetPrivateExpensesInfo() {
  12994. order_id, _ := c.GetInt64("id", 0)
  12995. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12996. order, _ := service.GetHisOrderByID(order_id)
  12997. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12998. if order.ID == 0 {
  12999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  13000. return
  13001. }
  13002. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  13003. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  13004. org_id := c.GetAdminUserInfo().CurrentOrgId
  13005. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  13006. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  13007. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  13008. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  13009. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  13010. //var orderInfos_four []*models.HisOrderInfoTwo
  13011. //for _, item := range orderInfos_three {
  13012. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  13013. // item.HisPrescriptionProject.IsCheckTeam = 1
  13014. // orderInfos_four = append(orderInfos_four, item)
  13015. //
  13016. // }
  13017. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  13018. // item.HisPrescriptionProject.IsCheckTeam = 2
  13019. // orderInfos_two = append(orderInfos_two, item)
  13020. // }
  13021. //}
  13022. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  13023. //var cus_slice []CustomOrderInfo
  13024. //for _, item := range new_order_info {
  13025. // var cus CustomOrderInfo
  13026. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  13027. // cus.Unit = ""
  13028. // cus.Spec = ""
  13029. // var total float64
  13030. // for _, subItem := range orderInfos_four {
  13031. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  13032. // total = total + subItem.DetItemFeeSumamt
  13033. // fmt.Println(subItem.DetItemFeeSumamt)
  13034. // }
  13035. // }
  13036. // cus.Count = 1
  13037. // cus.Total = total
  13038. // cus_slice = append(cus_slice, cus)
  13039. //}
  13040. orderInfos = append(orderInfos, orderInfos_two...)
  13041. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  13042. //orderInfos = append(orderInfos, orderInfos_three...)
  13043. //}/**/
  13044. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  13045. c.ServeSuccessJSON(map[string]interface{}{
  13046. "order": order,
  13047. "order_info": orderInfos,
  13048. "patient": patient,
  13049. "admin_info": adminInfo,
  13050. "his": his,
  13051. "current_admin": role,
  13052. "org_config": miConfig,
  13053. //"new_order_info": cus_slice,
  13054. })
  13055. }
  13056. func (this *HisApiController) ChangeMedType() {
  13057. med_type := this.GetString("med_type")
  13058. old_med_type := this.GetString("old_med_type")
  13059. ids := this.GetString("ids")
  13060. settle_type, _ := this.GetInt64("settle_type")
  13061. start_time := this.GetString("start_time")
  13062. end_time := this.GetString("end_time")
  13063. ids_arr := strings.Split(ids, ",")
  13064. if settle_type == 1 { //日结
  13065. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  13066. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  13067. prescription.MedType = med_type
  13068. err := service.SaveHisPrescriptionTwo(&prescription)
  13069. if err == nil {
  13070. this.ServeSuccessJSON(map[string]interface{}{
  13071. "msg": "修改成功",
  13072. })
  13073. } else {
  13074. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  13075. return
  13076. }
  13077. } else if settle_type == 2 {
  13078. timeLayout := "2006-01-02"
  13079. loc, _ := time.LoadLocation("Local")
  13080. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13081. if err != nil {
  13082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13083. return
  13084. }
  13085. recordStartTime := theStartTime.Unix()
  13086. start_time_timestamp := recordStartTime
  13087. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  13088. if err != nil {
  13089. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13090. return
  13091. }
  13092. recordEndTime := theEndTime.Unix()
  13093. end_time_timestamp := recordEndTime
  13094. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  13095. if updateErr == nil {
  13096. this.ServeSuccessJSON(map[string]interface{}{
  13097. "msg": "修改成功",
  13098. })
  13099. } else {
  13100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  13101. return
  13102. }
  13103. }
  13104. }
  13105. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  13106. patient_id, _ := c.GetInt64("patient_id")
  13107. his_patient_id, _ := c.GetInt64("his_patient_id")
  13108. record_date := c.GetString("record_date")
  13109. start_time := c.GetString("start_time")
  13110. end_time := c.GetString("end_time")
  13111. order_status, _ := c.GetInt64("type", 0)
  13112. p_type, _ := c.GetInt64("p_type", 0)
  13113. order_id, _ := c.GetInt64("order_id", 0)
  13114. timeLayout := "2006-01-02"
  13115. loc, _ := time.LoadLocation("Local")
  13116. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13117. if err != nil {
  13118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13119. return
  13120. }
  13121. recordDateTime := theTime.Unix()
  13122. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13123. if err != nil {
  13124. }
  13125. startRecordDateTime := startTime.Unix()
  13126. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13127. if err != nil {
  13128. }
  13129. endRecordDateTime := endTime.Unix()
  13130. admin := c.GetAdminUserInfo()
  13131. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  13132. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13133. order, _ := service.GetHisOrderByID(order_id)
  13134. var monthPrescriptions []*models.HisPrescription
  13135. if order_status == 1 || order_status == 0 {
  13136. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13137. } else if order_status == 2 {
  13138. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  13139. }
  13140. var settle_total float64
  13141. for _, item := range monthPrescriptions {
  13142. if len(item.HisPrescriptionProject) > 0 {
  13143. for _, subItem := range item.HisPrescriptionProject {
  13144. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13145. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13146. settle_total = settle_total + total
  13147. }
  13148. }
  13149. if len(item.HisDoctorAdviceInfo) > 0 {
  13150. for _, subItem := range item.HisDoctorAdviceInfo {
  13151. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13152. settle_total = settle_total + total
  13153. }
  13154. }
  13155. }
  13156. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13157. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13158. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13159. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13160. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13161. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13162. //获取所有科室信息
  13163. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13164. var dia string
  13165. for _, item := range month_p_info {
  13166. if len(dia) == 0 {
  13167. dia = item.Diagnosis
  13168. } else {
  13169. dia = dia + "," + item.Diagnosis
  13170. }
  13171. }
  13172. dia_arr := removeDuplicates(strings.Split(dia, ","))
  13173. dia_arr = removeEmptyStrings(dia_arr)
  13174. c.ServeSuccessJSON(map[string]interface{}{
  13175. "his_info": his_patient_info,
  13176. "xt_info": xt_patient_info,
  13177. "case_history": case_history,
  13178. "info": patientPrescriptionInfo,
  13179. "last_info": lastPatientPrescriptionInfo,
  13180. "month_prescriptions": monthPrescriptions,
  13181. "order": order,
  13182. "doctors": doctors,
  13183. "department": department,
  13184. "settle_total": settle_total,
  13185. "dia_arr": dia_arr,
  13186. })
  13187. return
  13188. }
  13189. func removeEmptyStrings(input []string) []string {
  13190. var output []string
  13191. for _, s := range input {
  13192. if s != "" {
  13193. output = append(output, s)
  13194. }
  13195. }
  13196. return output
  13197. }
  13198. func removeDuplicates(input []string) []string {
  13199. seen := make(map[string]bool)
  13200. output := []string{}
  13201. for _, s := range input {
  13202. if _, exists := seen[s]; !exists {
  13203. seen[s] = true
  13204. output = append(output, s)
  13205. }
  13206. }
  13207. return output
  13208. }
  13209. func (c *HisApiController) GetHisMonthPatientInfo() {
  13210. patient_id, _ := c.GetInt64("patient_id")
  13211. his_patient_id, _ := c.GetInt64("his_patient_id")
  13212. record_date := c.GetString("record_date")
  13213. number := c.GetString("number")
  13214. start_time := c.GetString("start_time")
  13215. end_time := c.GetString("end_time")
  13216. p_type, _ := c.GetInt64("p_type")
  13217. timeLayout := "2006-01-02"
  13218. loc, _ := time.LoadLocation("Local")
  13219. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13220. if err != nil {
  13221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13222. return
  13223. }
  13224. recordDateTime := theTime.Unix()
  13225. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13226. if err != nil {
  13227. }
  13228. startRecordDateTime := startTime.Unix()
  13229. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13230. if err != nil {
  13231. }
  13232. endRecordDateTime := endTime.Unix()
  13233. admin := c.GetAdminUserInfo()
  13234. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  13235. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13236. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  13237. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13238. var settle_total float64
  13239. for _, item := range monthPrescriptions {
  13240. if len(item.HisPrescriptionProject) > 0 {
  13241. for _, subItem := range item.HisPrescriptionProject {
  13242. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13243. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13244. settle_total = settle_total + total
  13245. }
  13246. }
  13247. if len(item.HisDoctorAdviceInfo) > 0 {
  13248. for _, subItem := range item.HisDoctorAdviceInfo {
  13249. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13250. settle_total = settle_total + total
  13251. }
  13252. }
  13253. }
  13254. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13255. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13256. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13257. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13258. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  13259. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13260. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  13261. //获取所有科室信息
  13262. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13263. c.ServeSuccessJSON(map[string]interface{}{
  13264. "his_info": his_patient_info,
  13265. "xt_info": xt_patient_info,
  13266. "case_history": case_history,
  13267. "info": patientPrescriptionInfo,
  13268. "month_prescriptions": monthPrescriptions,
  13269. "order": order,
  13270. "doctors": doctors,
  13271. "department": department,
  13272. "count": count,
  13273. "drugStockConfig": drugStockConfig,
  13274. "last_info": lastPatientPrescriptionInfo,
  13275. "settle_total": settle_total,
  13276. })
  13277. return
  13278. }
  13279. func (c *HisApiController) GetAllOrder() {
  13280. org_id := c.GetAdminUserInfo().CurrentOrgId
  13281. orders, _ := service.GetNewHisOrderList(org_id)
  13282. c.ServeSuccessJSON(map[string]interface{}{
  13283. "order": orders,
  13284. })
  13285. return
  13286. }
  13287. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  13288. newArr = make([]*models.HisOrderInfoTwo, 0)
  13289. for i := 0; i < len(arr); i++ {
  13290. repeat := false
  13291. for j := i + 1; j < len(arr); j++ {
  13292. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  13293. repeat = true
  13294. break
  13295. }
  13296. }
  13297. if !repeat {
  13298. newArr = append(newArr, arr[i])
  13299. }
  13300. }
  13301. return
  13302. }
  13303. // 修改处方退库操作 参数传修改之前的处方数据
  13304. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  13305. if advice.ExecutionState == 1 {
  13306. //查询该病人该药品是否有库存记录
  13307. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  13308. if errcode == gorm.ErrRecordNotFound {
  13309. } else {
  13310. //退库
  13311. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  13312. if advice.PrescribingNumberUnit == drug.MinUnit {
  13313. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13314. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13315. //退库
  13316. warehouseInfo := models.DrugWarehouseInfo{
  13317. StockMinNumber: prescribingNumber,
  13318. }
  13319. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  13320. operation_time := time.Now().Unix()
  13321. creater := advice.AdviceDoctor
  13322. ctime := time.Now().Unix()
  13323. timeStr := time.Now().Format("2006-01-02")
  13324. timeArr := strings.Split(timeStr, "-")
  13325. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13326. total = total + 1
  13327. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13328. cancelStock := models.DrugCancelStock{
  13329. OrderNumber: orderNumber,
  13330. OperaTime: operation_time,
  13331. OrgId: advice.UserOrgId,
  13332. Creater: creater,
  13333. Ctime: ctime,
  13334. Status: 1,
  13335. ReturnTime: advice.AdviceDate,
  13336. Dealer: info.Dealer,
  13337. Manufacturer: info.Manufacturer,
  13338. Type: 1,
  13339. }
  13340. service.AddSigleDrugCancelStock(&cancelStock)
  13341. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13342. dealer, _ := service.GetDealerById(info.Dealer)
  13343. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13344. cancelStockInfo := models.DrugCancelStockInfo{
  13345. OrderNumber: cancelInfo.OrderNumber,
  13346. CancelStockId: cancelInfo.ID,
  13347. DrugId: info.DrugId,
  13348. Count: info.Count,
  13349. Status: 1,
  13350. Ctime: ctime,
  13351. OrgId: advice.UserOrgId,
  13352. Type: 1,
  13353. Manufacturer: manufactureName.ManufacturerName,
  13354. Dealer: dealer.DealerName,
  13355. Total: 0,
  13356. RetailPrice: info.RetailPrice,
  13357. RetailTotalPrice: info.RetailTotalPrice,
  13358. Price: info.Price,
  13359. RegisterAccount: "",
  13360. Remark: info.Remark,
  13361. BatchNumber: info.BatchNumber,
  13362. MaxUnit: info.CountUnit,
  13363. ProductDate: info.ProductDate,
  13364. ExpiryDate: info.ExpiryDate,
  13365. BatchNumberId: info.WarehouseInfoId,
  13366. }
  13367. flow := models.DrugFlow{
  13368. WarehousingId: 0,
  13369. DrugId: info.DrugId,
  13370. Number: "",
  13371. BatchNumber: info.BatchNumber,
  13372. Count: info.Count,
  13373. UserOrgId: advice.UserOrgId,
  13374. PatientId: 0,
  13375. SystemTime: ctime,
  13376. ConsumableType: 4,
  13377. IsSys: 0,
  13378. WarehousingOrder: "",
  13379. WarehouseOutId: 0,
  13380. WarehouseOutOrderNumber: "",
  13381. IsEdit: 0,
  13382. CancelStockId: cancelStock.ID,
  13383. CancelOrderNumber: cancelStock.OrderNumber,
  13384. Manufacturer: info.Manufacturer,
  13385. Dealer: info.Dealer,
  13386. Creator: advice.UserOrgId,
  13387. UpdateCreator: 0,
  13388. Status: 1,
  13389. Ctime: time.Now().Unix(),
  13390. Mtime: 0,
  13391. Price: info.Price,
  13392. WarehousingDetailId: 0,
  13393. WarehouseOutDetailId: 0,
  13394. CancelOutDetailId: 0,
  13395. ExpireDate: info.ExpiryDate,
  13396. ProductDate: info.ProductDate,
  13397. MaxUnit: info.CountUnit,
  13398. MinUnit: "",
  13399. }
  13400. service.CreatedCancelStock(cancelStockInfo)
  13401. service.CreateDrugFlowOne(flow)
  13402. } else {
  13403. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13404. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13405. if advice.PrescribingNumberUnit == drug.MaxUnit {
  13406. warehouseInfo := models.DrugWarehouseInfo{
  13407. StockMinNumber: prescribingNumber,
  13408. }
  13409. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  13410. }
  13411. operation_time := time.Now().Unix()
  13412. creater := advice.AdviceDoctor
  13413. ctime := time.Now().Unix()
  13414. timeStr := time.Now().Format("2006-01-02")
  13415. timeArr := strings.Split(timeStr, "-")
  13416. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13417. total = total + 1
  13418. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13419. cancelStock := models.DrugCancelStock{
  13420. OrderNumber: orderNumber,
  13421. OperaTime: operation_time,
  13422. OrgId: advice.UserOrgId,
  13423. Creater: creater,
  13424. Ctime: ctime,
  13425. Status: 1,
  13426. ReturnTime: advice.AdviceDate,
  13427. Dealer: info.Dealer,
  13428. Manufacturer: info.Manufacturer,
  13429. Type: 1,
  13430. }
  13431. service.AddSigleDrugCancelStock(&cancelStock)
  13432. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13433. dealer, _ := service.GetDealerById(info.Dealer)
  13434. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13435. cancelStockInfo := models.DrugCancelStockInfo{
  13436. OrderNumber: cancelInfo.OrderNumber,
  13437. CancelStockId: cancelInfo.ID,
  13438. DrugId: info.DrugId,
  13439. Count: info.Count,
  13440. Status: 1,
  13441. Ctime: ctime,
  13442. OrgId: advice.UserOrgId,
  13443. Type: 1,
  13444. Manufacturer: manufactureName.ManufacturerName,
  13445. Dealer: dealer.DealerName,
  13446. Total: 0,
  13447. RetailPrice: info.RetailPrice,
  13448. RetailTotalPrice: info.RetailTotalPrice,
  13449. Price: info.Price,
  13450. RegisterAccount: "",
  13451. Remark: info.Remark,
  13452. BatchNumber: info.BatchNumber,
  13453. MaxUnit: info.CountUnit,
  13454. ProductDate: info.ProductDate,
  13455. ExpiryDate: info.ExpiryDate,
  13456. BatchNumberId: info.WarehouseInfoId,
  13457. }
  13458. flow := models.DrugFlow{
  13459. WarehousingId: 0,
  13460. DrugId: info.DrugId,
  13461. Number: "",
  13462. BatchNumber: info.BatchNumber,
  13463. Count: info.Count,
  13464. UserOrgId: advice.UserOrgId,
  13465. PatientId: 0,
  13466. SystemTime: ctime,
  13467. ConsumableType: 4,
  13468. IsSys: 0,
  13469. WarehousingOrder: "",
  13470. WarehouseOutId: 0,
  13471. WarehouseOutOrderNumber: "",
  13472. IsEdit: 0,
  13473. CancelStockId: cancelStock.ID,
  13474. CancelOrderNumber: cancelStock.OrderNumber,
  13475. Manufacturer: info.Manufacturer,
  13476. Dealer: info.Dealer,
  13477. Creator: advice.AdviceDoctor,
  13478. UpdateCreator: 0,
  13479. Status: 1,
  13480. Ctime: time.Now().Unix(),
  13481. Mtime: 0,
  13482. Price: info.Price,
  13483. WarehousingDetailId: 0,
  13484. WarehouseOutDetailId: 0,
  13485. CancelOutDetailId: 0,
  13486. ExpireDate: info.ExpiryDate,
  13487. ProductDate: info.ProductDate,
  13488. MaxUnit: info.CountUnit,
  13489. MinUnit: "",
  13490. }
  13491. service.CreatedCancelStock(cancelStockInfo)
  13492. service.CreateDrugFlowOne(flow)
  13493. }
  13494. }
  13495. }
  13496. return err
  13497. }
  13498. func (this *HisApiController) DeleteNCDS() {
  13499. id, _ := this.GetInt64("id", 0)
  13500. if id > 0 {
  13501. service.DeletePsnNCDSRecordById(id)
  13502. this.ServeSuccessJSON(map[string]interface{}{
  13503. "msg": "删除成功",
  13504. })
  13505. } else {
  13506. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13507. return
  13508. }
  13509. }
  13510. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13511. id, _ := c.GetInt64("id")
  13512. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13513. c.ServeSuccessJSON(map[string]interface{}{
  13514. "advice": advice,
  13515. })
  13516. return
  13517. }
  13518. func (c *HisApiController) GetHisMonthChargePatientList() {
  13519. record_date := c.GetString("record_date")
  13520. start_time := c.GetString("start_time")
  13521. end_time := c.GetString("end_time")
  13522. timeLayout := "2006-01-02"
  13523. loc, _ := time.LoadLocation("Local")
  13524. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13525. if err != nil {
  13526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13527. return
  13528. }
  13529. if err != nil {
  13530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13531. return
  13532. }
  13533. recordDateTime := theTime.Unix()
  13534. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13535. if err != nil {
  13536. }
  13537. startRecordDateTime := startTime.Unix()
  13538. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13539. if err != nil {
  13540. }
  13541. endRecordDateTime := endTime.Unix()
  13542. adminInfo := c.GetAdminUserInfo()
  13543. var tempMonthChargePatients []*service.MonthChargePatients
  13544. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13545. for _, item := range tempPatients {
  13546. //过滤没有处方的
  13547. if len(item.HisPrescription) == 0 {
  13548. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13549. }
  13550. }
  13551. c.ServeSuccessJSON(map[string]interface{}{
  13552. "list": tempMonthChargePatients,
  13553. })
  13554. }
  13555. // PrescriptionDifference 医嘱数量差值结构体
  13556. type PrescriptionDrugDifference struct {
  13557. DrugID int64 //基础库药品id
  13558. ID int64 //医嘱id
  13559. Difference float64 //差值
  13560. Unit string //单位
  13561. }
  13562. type PrescriptionGoodDifference struct {
  13563. GoodID int64 //基础库项目耗材id
  13564. ID int64 //医嘱id
  13565. Difference int64 //差值
  13566. Unit string //单位
  13567. Type int64 //类型
  13568. }
  13569. type EditCustomData struct {
  13570. adviceList []*models.HisDoctorAdviceInfo
  13571. projectList []*models.HisPrescriptionProject
  13572. }
  13573. type SrcCustomData struct {
  13574. adviceList []*models.HisDoctorAdviceInfo
  13575. projectList []*models.HisPrescriptionProject
  13576. }
  13577. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13578. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13579. differences := make([]*PrescriptionDrugDifference, 0)
  13580. // 创建一个 map 来存储第一个切片中的药品信息
  13581. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13582. for _, advice := range firstPrescription {
  13583. firstMap[advice.DrugId] = advice
  13584. }
  13585. // 遍历第二个切片中的药品信息,并比较数量差值
  13586. for _, advice := range secondPrescription {
  13587. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13588. diff := &PrescriptionDrugDifference{
  13589. DrugID: advice.DrugId,
  13590. ID: firstAdvice.ID,
  13591. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13592. Unit: firstAdvice.PrescribingNumberUnit,
  13593. }
  13594. differences = append(differences, diff)
  13595. }
  13596. }
  13597. return differences
  13598. }
  13599. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13600. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13601. differences := make([]*PrescriptionGoodDifference, 0)
  13602. // 创建一个 map 来存储第一个切片中的耗材信息
  13603. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13604. for _, good := range firstPrescription {
  13605. firstMap[good.ProjectId] = good
  13606. }
  13607. // 遍历第二个切片中的耗材信息,并比较数量差值
  13608. for _, good := range secondPrescription {
  13609. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13610. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13611. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13612. diff := &PrescriptionGoodDifference{
  13613. GoodID: good.ProjectId,
  13614. ID: firstGood.ID,
  13615. Difference: count - firstCount,
  13616. Unit: firstGood.Unit,
  13617. Type: firstGood.Type,
  13618. }
  13619. differences = append(differences, diff)
  13620. }
  13621. }
  13622. return differences
  13623. }
  13624. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13625. var adviceList []*models.HisDoctorAdviceInfo
  13626. var projectList []*models.HisPrescriptionProject
  13627. var advice_ids []int64
  13628. var project_ids []int64
  13629. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13630. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13631. //var tempPrescription *models.HisPrescriptionProjectscription
  13632. if len(prescriptions) > 0 {
  13633. for _, item := range prescriptions {
  13634. items := item.(map[string]interface{})
  13635. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13636. advices := items["advices"].([]interface{})
  13637. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13638. groupNo := int64(0)
  13639. ctime := time.Now().Unix()
  13640. mtime := ctime
  13641. if len(advices) > 0 {
  13642. for _, advice := range advices {
  13643. var s models.HisDoctorAdviceInfo
  13644. s.AdviceType = 2
  13645. s.StopState = 2
  13646. s.ExecutionState = 2
  13647. s.Status = 1
  13648. s.Groupno = groupNo
  13649. s.CreatedTime = ctime
  13650. s.UpdatedTime = mtime
  13651. s.IsSettle = 2
  13652. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13653. //存储切片中
  13654. if s.ID > 0 {
  13655. advice_ids = append(advice_ids, s.ID)
  13656. adviceList = append(adviceList, &s)
  13657. }
  13658. }
  13659. }
  13660. }
  13661. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13662. projects := items["project"].([]interface{})
  13663. if len(projects) > 0 {
  13664. for _, project := range projects {
  13665. var p models.HisPrescriptionProject
  13666. p.Ctime = time.Now().Unix()
  13667. p.Mtime = time.Now().Unix()
  13668. p.Status = 1
  13669. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13670. if p.ID > 0 {
  13671. project_ids = append(project_ids, p.ID)
  13672. projectList = append(projectList, &p)
  13673. }
  13674. }
  13675. }
  13676. }
  13677. }
  13678. }
  13679. }
  13680. editCustomData.projectList = projectList
  13681. editCustomData.adviceList = adviceList
  13682. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13683. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13684. srcCustomData.adviceList = list
  13685. srcCustomData.projectList = list2
  13686. return
  13687. }
  13688. func (c *HisApiController) GetAllGoodInforList() {
  13689. orgId := c.GetAdminUserInfo().CurrentOrgId
  13690. goodList, _ := service.GetAllGoodList(orgId)
  13691. c.ServeSuccessJSON(map[string]interface{}{
  13692. "goodList": goodList,
  13693. })
  13694. return
  13695. }
  13696. func (this *HisApiController) SaveGoodList() {
  13697. project_name := this.GetString("project_name")
  13698. sort, _ := this.GetInt64("sort")
  13699. orgId := this.GetAdminUserInfo().CurrentOrgId
  13700. dataBody := make(map[string]interface{}, 0)
  13701. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13702. if err != nil {
  13703. utils.ErrorLog(err.Error())
  13704. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13705. return
  13706. }
  13707. goodTeam := models.XtGoodTeam{
  13708. ProjectName: project_name,
  13709. Sort: sort,
  13710. UserOrgId: orgId,
  13711. Status: 1,
  13712. Ctime: time.Now().Unix(),
  13713. Mtime: time.Now().Unix(),
  13714. }
  13715. service.CreateGoodTeam(goodTeam)
  13716. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13717. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13718. infos, _ := dataBody["info"].([]interface{})
  13719. if len(infos) > 0 {
  13720. for _, item := range infos {
  13721. items := item.(map[string]interface{})
  13722. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13723. utils.ErrorLog("good_id")
  13724. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13725. return
  13726. }
  13727. good_id := int64(items["good_id"].(float64))
  13728. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13729. utils.ErrorLog("number")
  13730. }
  13731. number := int64(items["number"].(float64))
  13732. xtGoodTeamList := models.XtGoodTeamList{
  13733. GoodId: good_id,
  13734. Count: number,
  13735. TeamId: lastGoodTeam.ID,
  13736. UserOrgId: orgId,
  13737. Status: 1,
  13738. Ctime: time.Now().Unix(),
  13739. Mtime: time.Now().Unix(),
  13740. }
  13741. service.CreateGoodList(xtGoodTeamList)
  13742. }
  13743. this.ServeSuccessJSON(map[string]interface{}{
  13744. "lastGoodTeam": lastGoodTeam,
  13745. })
  13746. }
  13747. }
  13748. return
  13749. }
  13750. func (this *HisApiController) GetGoodList() {
  13751. orgId := this.GetAdminUserInfo().CurrentOrgId
  13752. limit, _ := this.GetInt64("limit")
  13753. page, _ := this.GetInt64("page")
  13754. keyword := this.GetString("keyword")
  13755. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13756. this.ServeSuccessJSON(map[string]interface{}{
  13757. "list": list,
  13758. "total": total,
  13759. })
  13760. }
  13761. func (this *HisApiController) GetGoodNameDetail() {
  13762. id, _ := this.GetInt64("id")
  13763. orgId := this.GetAdminUserInfo().CurrentOrgId
  13764. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13765. goodList, _ := service.GetAllGoodList(orgId)
  13766. this.ServeSuccessJSON(map[string]interface{}{
  13767. "goodNameDetail": goodNameDetail,
  13768. "goodList": goodList,
  13769. })
  13770. }
  13771. func (this *HisApiController) UpdateGoodList() {
  13772. project_name := this.GetString("project_name")
  13773. sort, _ := this.GetInt64("sort")
  13774. id, _ := this.GetInt64("id")
  13775. orgId := this.GetAdminUserInfo().CurrentOrgId
  13776. dataBody := make(map[string]interface{}, 0)
  13777. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13778. if err != nil {
  13779. utils.ErrorLog(err.Error())
  13780. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13781. return
  13782. }
  13783. goodTeam := models.XtGoodTeam{
  13784. ProjectName: project_name,
  13785. Sort: sort,
  13786. UserOrgId: orgId,
  13787. Status: 1,
  13788. Ctime: time.Now().Unix(),
  13789. Mtime: time.Now().Unix(),
  13790. ID: id,
  13791. }
  13792. service.SaveGoodTeam(goodTeam)
  13793. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13794. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13795. infos, _ := dataBody["info"].([]interface{})
  13796. if len(infos) > 0 {
  13797. for _, item := range infos {
  13798. items := item.(map[string]interface{})
  13799. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13800. utils.ErrorLog("good_id")
  13801. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13802. return
  13803. }
  13804. good_id := int64(items["good_id"].(float64))
  13805. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13806. utils.ErrorLog("id")
  13807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13808. return
  13809. }
  13810. id := int64(items["id"].(float64))
  13811. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13812. utils.ErrorLog("number")
  13813. }
  13814. number := int64(items["number"].(float64))
  13815. xtGoodTeamList := models.XtGoodTeamList{
  13816. ID: id,
  13817. GoodId: good_id,
  13818. Count: number,
  13819. TeamId: lastGoodTeam.ID,
  13820. UserOrgId: orgId,
  13821. Status: 1,
  13822. Ctime: time.Now().Unix(),
  13823. Mtime: time.Now().Unix(),
  13824. }
  13825. service.SaveGoodList(xtGoodTeamList)
  13826. }
  13827. this.ServeSuccessJSON(map[string]interface{}{
  13828. "lastGoodTeam": lastGoodTeam,
  13829. })
  13830. }
  13831. }
  13832. return
  13833. }
  13834. func (this *HisApiController) DeleteGoodTeam() {
  13835. id, _ := this.GetInt64("id")
  13836. team, _ := service.DeleteGoodTeam(id)
  13837. this.ServeSuccessJSON(map[string]interface{}{
  13838. "team": team,
  13839. })
  13840. }
  13841. func (this *HisApiController) DeleteGood() {
  13842. id, _ := this.GetInt64("id")
  13843. good, _ := service.DeleteGood(id)
  13844. this.ServeSuccessJSON(map[string]interface{}{
  13845. "good": good,
  13846. })
  13847. }