his_api_controller.go 585KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  91. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  92. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  93. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  94. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  95. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  96. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  97. }
  98. func (c *HisApiController) CheckHisPatient() {
  99. record_date := c.GetString("record_date")
  100. patient_id, _ := c.GetInt64("patient_id")
  101. timeLayout := "2006-01-02"
  102. loc, _ := time.LoadLocation("Local")
  103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  104. if err != nil {
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. recordDateTime := theTime.Unix()
  109. adminInfo := c.GetAdminUserInfo()
  110. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  111. if len(patients) > 1 {
  112. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  113. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "status": 1,
  116. "msg": "关联",
  117. "ps": ps,
  118. "his_patient_id": patients[len(patients)-1].ID,
  119. "patient_id": patients[len(patients)-1].PatientId,
  120. })
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. }
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. return
  133. }
  134. }
  135. func (c *HisApiController) AssociationHisPrescription() {
  136. record_date := c.GetString("record_date")
  137. his_patient_id, _ := c.GetInt64("his_patient_id")
  138. patient_id, _ := c.GetInt64("patient_id")
  139. p_ids := c.GetString("p_ids")
  140. p_ids_arr := strings.Split(p_ids, ",")
  141. timeLayout := "2006-01-02"
  142. loc, _ := time.LoadLocation("Local")
  143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  144. if err != nil {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. recordDateTime := theTime.Unix()
  149. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  150. if his_patient_id == 0 || his_patient.ID == 0 {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  155. if err == nil {
  156. c.ServeSuccessJSON(map[string]interface{}{
  157. "msg": "关联处方成功",
  158. })
  159. return
  160. } else {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  162. return
  163. }
  164. }
  165. //func (c *HisApiController) AssociationHisPrescription() {
  166. // record_date, _ := c.GetInt64("record_date")
  167. // his_patient_id, _ := c.GetInt64("his_patient_id")
  168. // patient_id, _ := c.GetInt64("patient_id")
  169. // p_ids := c.GetString("p_ids")
  170. // p_ids_arr := strings.Split(p_ids, ",")
  171. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  172. // if his_patient_id == 0 || his_patient.ID == 0 {
  173. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. // return
  175. // }
  176. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  177. // if err == nil {
  178. // c.ServeSuccessJSON(map[string]interface{}{
  179. // "msg": "关联处方成功",
  180. // })
  181. // return
  182. // } else {
  183. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  184. // return
  185. // }
  186. //}
  187. func (c *HisApiController) GetFaPiaoNumber() {
  188. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  189. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  190. fmt.Println(count)
  191. var zero string
  192. number := count + 1
  193. //if number >= 1000 {
  194. // zero = "0000" + strconv.FormatInt(number, 10)
  195. //} else if number >= 10000 {
  196. // zero = "000" + strconv.FormatInt(number, 10)
  197. //} else if number >= 100000 {
  198. // zero = "00" + strconv.FormatInt(number, 10)
  199. //} else if number >= 1000000 {
  200. // zero = "0" + strconv.FormatInt(number, 10)
  201. //} else {
  202. zero = "0" + strconv.FormatInt(number, 10)
  203. //}
  204. c.ServeSuccessJSON(map[string]interface{}{
  205. "fapiao_number": zero,
  206. })
  207. return
  208. }
  209. func (c *HisApiController) ChangeOrderDesc() {
  210. id, _ := c.GetInt64("id")
  211. desc := c.GetString("desc")
  212. change_type := c.GetString("change_type")
  213. order, _ := service.GetHisOrderByID(id)
  214. if order.ID == 0 {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  216. return
  217. }
  218. switch change_type {
  219. case "oth_desc":
  220. order.OthDesc = desc
  221. break
  222. case "cash_pay":
  223. order.CashPay = desc
  224. break
  225. case "jifen_pay":
  226. order.JifenPay = desc
  227. break
  228. case "card_desc":
  229. order.CardDesc = desc
  230. break
  231. case "band_card_pay":
  232. order.BandCardPay = desc
  233. break
  234. case "ali_pay":
  235. order.AliPay = desc
  236. break
  237. case "wechat_pay":
  238. order.WechatPay = desc
  239. break
  240. case "fa_piao_number":
  241. order.FaPiaoNumber = desc
  242. break
  243. case "fa_piao_code":
  244. order.FaPiaoCode = desc
  245. break
  246. }
  247. err := service.SaveHisOrder(&order)
  248. if err == nil {
  249. c.ServeSuccessJSON(map[string]interface{}{
  250. "msg": "修改成功",
  251. })
  252. return
  253. } else {
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  255. return
  256. }
  257. }
  258. func (c *HisApiController) GetMonthHisPatient() {
  259. record_date := c.GetString("record_date")
  260. //order_status, _ := c.GetInt64("type")
  261. timeLayout := "2006-01-02"
  262. loc, _ := time.LoadLocation("Local")
  263. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  264. if err != nil {
  265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  266. return
  267. }
  268. recordDateTime := theTime.Unix()
  269. adminInfo := c.GetAdminUserInfo()
  270. var tempPatients []service.NewTempPatients
  271. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  272. // 获取当前时间
  273. now := time.Now()
  274. // 获取本月的第一天
  275. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  276. // 获取下个月的第一天
  277. nextMonth := firstDay.AddDate(0, 1, 0)
  278. // 获取本月的最后一天
  279. lastDay := nextMonth.Add(-time.Nanosecond)
  280. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  281. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  282. var patients []service.NewTempPatients
  283. var patients_two []service.NewTempPatients
  284. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  285. for _, item := range tempPatients {
  286. //过滤掉没挂号的和没开处方的
  287. if len(item.HisPrescription) > 0 {
  288. patients = append(patients, item)
  289. patients_two = append(patients_two, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. //}
  294. }
  295. } else {
  296. for _, item := range tempPatients {
  297. //过滤掉没挂号的和没开处方的
  298. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  299. patients = append(patients, item)
  300. }
  301. ////过滤掉没挂号的
  302. //if len(item.HisPatient) > 0 {
  303. // patients_two = append(patients_two, item)
  304. //}
  305. }
  306. }
  307. c.ServeSuccessJSON(map[string]interface{}{
  308. "list": patients,
  309. "list_two": patients_two,
  310. "chargePatients": chargePatients,
  311. })
  312. }
  313. func (c *HisApiController) GetBatchSettleAccounts() {
  314. order_ids := c.GetString("order_ids")
  315. admin_user_id, _ := c.GetInt64("admin_user_id")
  316. adminUser := c.GetAdminUserInfo()
  317. orders := strings.Split(order_ids, ",")
  318. var newOrders []models.Orders
  319. for _, item := range orders {
  320. order, _ := service.GetHisOrderByIDTenOne(item)
  321. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  322. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  323. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  324. orderInfos = append(orderInfos, orderInfos_two...)
  325. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  326. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  327. var diagnosis_ids []string
  328. if his.ID > 0 {
  329. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  330. } else {
  331. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  332. }
  333. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  334. var dia_config []*models.HisXtDiagnoseConfig
  335. var name string
  336. for _, item := range diagnosis_ids {
  337. id, _ := strconv.ParseInt(item, 10, 64)
  338. diagnosisConfig, _ := service.FindDiagnoseById(id)
  339. dia_config = append(dia_config, diagnosisConfig)
  340. if len(name) == 0 {
  341. name = diagnosisConfig.ClassName
  342. } else {
  343. name = name + "," + diagnosisConfig.ClassName
  344. }
  345. }
  346. var bedCostTotal float64 = 0 //床位总费
  347. var bedCostSelfTotal float64 = 0 //床位自费
  348. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  349. var bedSelfTotal float64 = 0 //床位部分项目自费
  350. var bedInscpTotal float64 = 0 //床位部分项目自费
  351. var operationCostTotal float64 = 0 //手术费
  352. var operationCostSelfTotal float64 = 0 //手术费
  353. var operationCostPartSelfTotal float64 = 0 //手术费
  354. var operationSelfTotal float64 = 0 //床位部分项目自费
  355. var operationInscpTotal float64 = 0 //床位部分项目自费
  356. var otherCostTotal float64 = 0 //其他费用
  357. var otherCostSelfTotal float64 = 0 //其他费用
  358. var otherCostPartSelfTotal float64 = 0 //其他费用
  359. var otherSelfTotal float64 = 0 //床位部分项目自费
  360. var otherInscpTotal float64 = 0 //床位部分项目自费
  361. var materialCostTotal float64 = 0 //材料费
  362. var materialCostSelfTotal float64 = 0 //材料费
  363. var materialCostPartSelfTotal float64 = 0 //材料费
  364. var materialSelfTotal float64 = 0 //床位部分项目自费
  365. var materialInscpTotal float64 = 0 //床位部分项目自费
  366. var westernMedicineCostTotal float64 = 0 //西药费
  367. var westernMedicineCostSelfTotal float64 = 0 //西药费
  368. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  369. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  370. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  371. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  372. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  373. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  374. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  375. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  376. var checkCostTotal float64 = 0 //检查费
  377. var checkCostSelfTotal float64 = 0 //检查费
  378. var checkCostPartSelfTotal float64 = 0 //检查费
  379. var checkSelfTotal float64 = 0 //床位部分项目自费
  380. var checkInscpTotal float64 = 0 //床位部分项目自费
  381. var laboratoryCostTotal float64 = 0 //化验费
  382. var laboratoryCostSelfTotal float64 = 0 //化验费
  383. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  384. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  385. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  386. var treatCostTotal float64 = 0 //治疗费用
  387. var treatCostSelfTotal float64 = 0 //治疗费用
  388. var treatCostPartSelfTotal float64 = 0 //治疗费用
  389. var treatSelfTotal float64 = 0 //床位部分项目自费
  390. var treatInscpTotal float64 = 0 //床位部分项目自费
  391. decimal.DivisionPrecision = 2
  392. for _, item := range orderInfos {
  393. if item.MedChrgitmType == "01" { //床位费
  394. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  395. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  396. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  397. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  398. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  399. }
  400. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  401. if item.MedChrgitmType == "03" { //检查费
  402. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  403. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  404. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  405. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  406. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  407. }
  408. } else {
  409. if item.MedChrgitmType == "03" { //检查费
  410. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  411. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  412. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  413. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  414. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  415. }
  416. }
  417. if item.MedChrgitmType == "04" { //化验费
  418. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  419. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  420. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  421. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  422. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  423. }
  424. if item.MedChrgitmType == "05" { //治疗费
  425. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  426. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  427. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  428. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  429. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  430. }
  431. if item.MedChrgitmType == "06" { //手术费
  432. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  433. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  434. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  435. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  436. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  437. }
  438. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  439. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  440. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  441. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  442. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  443. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  444. }
  445. if item.MedChrgitmType == "09" { //西药费
  446. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  447. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  448. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  449. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  450. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  451. }
  452. if item.MedChrgitmType == "11" { //中成费
  453. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  454. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  455. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  456. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  457. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  458. }
  459. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  460. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  461. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  462. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  463. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  464. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  465. }
  466. }
  467. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  468. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  469. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  470. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  471. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  472. var doctor_name string
  473. if roles.ID == 0 {
  474. doctor_name = "管理员"
  475. } else {
  476. doctor_name = roles.UserName
  477. }
  478. yiliao_leibie := ""
  479. switch order.MedType {
  480. case "11":
  481. yiliao_leibie = "普通门诊"
  482. break
  483. case "12":
  484. yiliao_leibie = "门诊挂号"
  485. break
  486. case "13":
  487. yiliao_leibie = "急诊"
  488. break
  489. case "14":
  490. yiliao_leibie = "门诊特殊病"
  491. break
  492. case "15":
  493. yiliao_leibie = "门诊统筹"
  494. break
  495. case "16":
  496. yiliao_leibie = "门诊慢性病"
  497. break
  498. case "21":
  499. yiliao_leibie = "普通住院"
  500. break
  501. }
  502. var newOrder models.Orders
  503. newOrder.Diagnosis = name
  504. newOrder.OrderInfos = orderInfos
  505. newOrder.Number = order.MdtrtId
  506. newOrder.Date = order.SettleAccountsDate
  507. newOrder.ChargeAdmin = charge_admin
  508. newOrder.PrintorAdmin = printor_admin
  509. newOrder.Order = order
  510. newOrder.BedCostTotal = bedCostTotal
  511. newOrder.BedCostSelfTotal = bedCostSelfTotal
  512. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  513. newOrder.BedSelfTotal = bedSelfTotal
  514. newOrder.BedInscpTotal = bedInscpTotal
  515. newOrder.OperationCostTotal = operationCostTotal
  516. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  517. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  518. newOrder.OperationSelfTotal = operationSelfTotal
  519. newOrder.OperationInscpTotal = operationInscpTotal
  520. newOrder.OtherCostTotal = otherCostTotal
  521. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  522. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  523. newOrder.OtherSelfTotal = otherSelfTotal
  524. newOrder.OtherInscpTotal = otherInscpTotal
  525. newOrder.MaterialCostTotal = materialCostTotal
  526. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  527. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  528. newOrder.MaterialSelfTotal = materialSelfTotal
  529. newOrder.MaterialInscpTotal = materialInscpTotal
  530. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  531. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  532. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  533. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  534. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  535. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  536. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  537. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  538. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  539. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  540. newOrder.CheckCostTotal = checkCostTotal
  541. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  542. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  543. newOrder.CheckSelfTotal = checkSelfTotal
  544. newOrder.CheckInscpTotal = checkInscpTotal
  545. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  546. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  547. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  548. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  549. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  550. newOrder.TreatCostTotal = treatCostTotal
  551. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  552. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  553. newOrder.TreatSelfTotal = treatSelfTotal
  554. newOrder.TreatInscpTotal = treatInscpTotal
  555. newOrder.DoctorInfo = doctor_info
  556. newOrder.DoctorName = doctor_name
  557. newOrder.HealthCardNo = order.PsnNo
  558. newOrder.YiliaoLeibie = yiliao_leibie
  559. newOrder.Patient = patient
  560. newOrder.OrgName = miConfig.OrgName
  561. newOrder.OrgCode = miConfig.Code
  562. newOrder.OrderNumber = order.Number
  563. newOrder.HisPatient = his
  564. newOrder.DiaConfig = dia_config
  565. newOrders = append(newOrders, newOrder)
  566. }
  567. c.ServeSuccessJSON(map[string]interface{}{
  568. "orders": newOrders,
  569. })
  570. }
  571. func (c *HisApiController) GetTestOrder() {
  572. order_id, _ := c.GetInt64("order_id")
  573. admin_user_id, _ := c.GetInt64("admin_user_id")
  574. adminUser := c.GetAdminUserInfo()
  575. order, _ := service.GetHisOrderByID(order_id)
  576. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  577. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  578. orderInfos = append(orderInfos, orderInfos_two...)
  579. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  580. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  581. var dia_config []*models.HisXtDiagnoseConfig
  582. var name string
  583. var bedCostTotal float64 = 0 //床位总费
  584. var bedCostSelfTotal float64 = 0 //床位自费
  585. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  586. var bedSelfTotal float64 = 0 //床位部分项目自费
  587. var bedInscpTotal float64 = 0 //床位部分项目自费
  588. var operationCostTotal float64 = 0 //手术费
  589. var operationCostSelfTotal float64 = 0 //手术费
  590. var operationCostPartSelfTotal float64 = 0 //手术费
  591. var operationSelfTotal float64 = 0 //床位部分项目自费
  592. var operationInscpTotal float64 = 0 //床位部分项目自费
  593. var otherCostTotal float64 = 0 //其他费用
  594. var otherCostSelfTotal float64 = 0 //其他费用
  595. var otherCostPartSelfTotal float64 = 0 //其他费用
  596. var otherSelfTotal float64 = 0 //床位部分项目自费
  597. var otherInscpTotal float64 = 0 //床位部分项目自费
  598. var materialCostTotal float64 = 0 //材料费
  599. var materialCostSelfTotal float64 = 0 //材料费
  600. var materialCostPartSelfTotal float64 = 0 //材料费
  601. var materialSelfTotal float64 = 0 //床位部分项目自费
  602. var materialInscpTotal float64 = 0 //床位部分项目自费
  603. var westernMedicineCostTotal float64 = 0 //西药费
  604. var westernMedicineCostSelfTotal float64 = 0 //西药费
  605. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  606. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  607. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  608. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  609. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  610. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  611. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  612. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  613. var checkCostTotal float64 = 0 //检查费
  614. var checkCostSelfTotal float64 = 0 //检查费
  615. var checkCostPartSelfTotal float64 = 0 //检查费
  616. var checkSelfTotal float64 = 0 //床位部分项目自费
  617. var checkInscpTotal float64 = 0 //床位部分项目自费
  618. var laboratoryCostTotal float64 = 0 //化验费
  619. var laboratoryCostSelfTotal float64 = 0 //化验费
  620. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  621. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  622. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  623. var treatCostTotal float64 = 0 //治疗费用
  624. var treatCostSelfTotal float64 = 0 //治疗费用
  625. var treatCostPartSelfTotal float64 = 0 //治疗费用
  626. var treatSelfTotal float64 = 0 //床位部分项目自费
  627. var treatInscpTotal float64 = 0 //床位部分项目自费
  628. decimal.DivisionPrecision = 2
  629. for _, item := range orderInfos {
  630. if item.MedChrgitmType == "01" { //床位费
  631. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  632. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  633. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  634. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  635. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  636. }
  637. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  638. if item.MedChrgitmType == "03" { //检查费
  639. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  640. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  641. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  642. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  643. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  644. }
  645. } else {
  646. if item.MedChrgitmType == "03" { //检查费
  647. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  648. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  649. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  650. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  651. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  652. }
  653. }
  654. if item.MedChrgitmType == "04" { //化验费
  655. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  656. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  657. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  658. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  659. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  660. }
  661. if item.MedChrgitmType == "05" { //治疗费
  662. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  663. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  664. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  665. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  666. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  667. }
  668. if item.MedChrgitmType == "06" { //手术费
  669. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  670. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  671. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  672. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  673. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  674. }
  675. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  676. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  677. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  678. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  679. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  680. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  681. }
  682. if item.MedChrgitmType == "09" { //西药费
  683. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  684. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  685. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  686. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  687. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  688. }
  689. if item.MedChrgitmType == "11" { //中成费
  690. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  691. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  692. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  693. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  694. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  695. }
  696. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  697. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  698. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  699. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  700. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  701. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  702. }
  703. }
  704. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  705. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  706. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  707. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  708. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  709. var doctor_name string
  710. if roles.ID == 0 {
  711. doctor_name = "管理员"
  712. } else {
  713. doctor_name = roles.UserName
  714. }
  715. yiliao_leibie := ""
  716. switch order.MedType {
  717. case "11":
  718. yiliao_leibie = "普通门诊"
  719. break
  720. case "12":
  721. yiliao_leibie = "门诊挂号"
  722. break
  723. case "13":
  724. yiliao_leibie = "急诊"
  725. break
  726. case "14":
  727. yiliao_leibie = "门诊特殊病"
  728. break
  729. case "15":
  730. yiliao_leibie = "门诊统筹"
  731. break
  732. case "16":
  733. yiliao_leibie = "门诊慢性病"
  734. break
  735. case "21":
  736. yiliao_leibie = "普通住院"
  737. break
  738. }
  739. c.ServeSuccessJSON(map[string]interface{}{
  740. "diagnosis": name,
  741. "order_infos": orderInfos,
  742. "number": order.MdtrtId,
  743. "date": order.SettleAccountsDate,
  744. "charge_admin": charge_admin,
  745. "printor_admin": printor_admin,
  746. "info": order,
  747. "order": order,
  748. "bedCostTotal": bedCostTotal,
  749. "bedCostSelfTotal": bedCostSelfTotal,
  750. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  751. "bedSelfTotal": bedSelfTotal,
  752. "bedInscpTotal": bedInscpTotal,
  753. "operationCostTotal": operationCostTotal,
  754. "operationCostSelfTotal": operationCostSelfTotal,
  755. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  756. "operationSelfTotal": operationSelfTotal,
  757. "operationInscpTotal": operationInscpTotal,
  758. "otherCostTotal": otherCostTotal,
  759. "otherCostSelfTotal": otherCostSelfTotal,
  760. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  761. "otherSelfTotal": otherSelfTotal,
  762. "otherInscpTotal": otherInscpTotal,
  763. "materialCostTotal": materialCostTotal,
  764. "materialCostSelfTotal": materialCostSelfTotal,
  765. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  766. "materialSelfTotal": materialSelfTotal,
  767. "materialInscpTotal": materialInscpTotal,
  768. "westernMedicineCostTotal": westernMedicineCostTotal,
  769. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  770. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  771. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  772. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  773. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  774. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  775. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  776. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  777. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  778. "checkCostTotal": checkCostTotal,
  779. "checkCostSelfTotal": checkCostSelfTotal,
  780. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  781. "checkSelfTotal": checkSelfTotal,
  782. "checkInscpTotal": checkInscpTotal,
  783. "laboratoryCostTotal": laboratoryCostTotal,
  784. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  785. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  786. "laboratorySelfTotal": laboratorySelfTotal,
  787. "laboratoryInscpTotal": laboratoryInscpTotal,
  788. "treatCostTotal": treatCostTotal,
  789. "treatCostSelfTotal": treatCostSelfTotal,
  790. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  791. "treatSelfTotal": treatSelfTotal,
  792. "treatInscpTotal": treatInscpTotal,
  793. "doctor_info": doctor_info,
  794. "doctor_name": doctor_name,
  795. "health_card_no": order.PsnNo,
  796. "yiliao_leibie": yiliao_leibie,
  797. "patient": patient,
  798. "org_name": miConfig.OrgName,
  799. "org_code": miConfig.Code,
  800. "order_number": order.Number,
  801. "his_hospital": his_hospital,
  802. "dia_config": dia_config,
  803. })
  804. }
  805. type CustomFundPay struct {
  806. FundPayType string `json:"fund_pay_type"`
  807. FundPayamt float64 `json:"fund_payamt"`
  808. InscpScpAmt float64 `json:"inscp_scp_amt"`
  809. }
  810. func (c *PublicApiController) GetBaiLinExportData() {
  811. data := service.GetBaiLinOrderData()
  812. fmt.Println(len(data))
  813. var new_data []*models.NewCustomHisOrder
  814. for _, item := range data {
  815. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  816. new_data = append(new_data, item)
  817. }
  818. }
  819. fmt.Println(len(new_data))
  820. c.ServeSuccessJSON(map[string]interface{}{
  821. "list": new_data,
  822. })
  823. }
  824. func (c *HisApiController) GetHisUnChargePatientList() {
  825. record_date := c.GetString("record_date")
  826. sch_type, _ := c.GetInt64("sch_type")
  827. timeLayout := "2006-01-02"
  828. loc, _ := time.LoadLocation("Local")
  829. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  830. if err != nil {
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  832. return
  833. }
  834. recordDateTime := theTime.Unix()
  835. adminInfo := c.GetAdminUserInfo()
  836. var tempPatients []*service.NewTempPatients
  837. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  838. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  839. var patients []*service.NewTempPatients
  840. var patients_two []*service.NewTempPatients
  841. for _, item := range tempPatients {
  842. //过滤掉没挂号的和没开处方的
  843. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  844. patients = append(patients, item)
  845. }
  846. //过滤掉没挂号的
  847. if len(item.HisPatient) > 0 {
  848. patients_two = append(patients_two, item)
  849. }
  850. }
  851. c.ServeSuccessJSON(map[string]interface{}{
  852. "list": patients,
  853. "list_two": patients_two,
  854. })
  855. }
  856. func (c *HisApiController) GetPrivateExpensesOrder() {
  857. //id, _ := c.GetInt64("id")
  858. //record_time := c.GetString("record_time")
  859. order_id, _ := c.GetInt64("order_id")
  860. admin_user_id, _ := c.GetInt64("admin_user_id")
  861. //timeLayout := "2006-01-02"
  862. //loc, _ := time.LoadLocation("Local")
  863. //
  864. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  865. //if err != nil {
  866. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  867. // return
  868. //}
  869. //recordDateTime := theTime.Unix()
  870. adminUser := c.GetAdminUserInfo()
  871. order, _ := service.GetHisOrderByID(order_id)
  872. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  873. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  874. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  875. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  876. //var config []*models.HisXtDiagnoseConfig
  877. var name string
  878. if order.PType == 1 {
  879. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  880. for _, item := range diagnosis_ids {
  881. id, _ := strconv.ParseInt(item, 10, 64)
  882. diagnosisConfig, _ := service.FindDiagnoseById(id)
  883. if len(name) == 0 {
  884. name = diagnosisConfig.ClassName
  885. } else {
  886. name = name + "," + diagnosisConfig.ClassName
  887. }
  888. }
  889. } else {
  890. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  891. for _, item := range diagnosis_ids {
  892. id, _ := strconv.ParseInt(item, 10, 64)
  893. diagnosisConfig, _ := service.FindDiagnoseById(id)
  894. if len(name) == 0 {
  895. name = diagnosisConfig.ClassName
  896. } else {
  897. name = name + "," + diagnosisConfig.ClassName
  898. }
  899. }
  900. }
  901. var bedCostTotal float64 = 0 //床位总费
  902. //var bedCostSelfTotal float64 = 0 //床位自费
  903. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  904. var operationCostTotal float64 = 0 //手术费
  905. //var operationCostSelfTotal float64 = 0 //手术费
  906. var operationCostPartSelfTotal float64 = 0 //手术费
  907. var otherCostTotal float64 = 0 //其他费用
  908. //var otherCostSelfTotal float64 = 0 //其他费用
  909. var otherCostPartSelfTotal float64 = 0 //其他费用
  910. var materialCostTotal float64 = 0 //材料费
  911. //var materialCostSelfTotal float64 = 0 //材料费
  912. var materialCostPartSelfTotal float64 = 0 //材料费
  913. var westernMedicineCostTotal float64 = 0 //西药费
  914. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  915. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  916. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  917. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  918. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  919. var checkCostTotal float64 = 0 //检查费
  920. //var checkCostSelfTotal float64 = 0 //检查费
  921. var checkCostPartSelfTotal float64 = 0 //检查费
  922. var laboratoryCostTotal float64 = 0 //化验费
  923. //var laboratoryCostSelfTotal float64 = 0 //化验费
  924. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  925. var treatCostTotal float64 = 0 //治疗费用
  926. //var treatCostSelfTotal float64 = 0 //治疗费用
  927. var treatCostPartSelfTotal float64 = 0 //治疗费用
  928. var zhenChaCostTotal float64 = 0 //其他费用
  929. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  930. decimal.DivisionPrecision = 2
  931. for _, item := range orderInfos {
  932. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  933. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  934. item.MedChrgitmType = "09"
  935. }
  936. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  937. if item.HisPrescriptionProject.Type == 2 {
  938. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  939. fmt.Println("CostClassify")
  940. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  941. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  942. case 0:
  943. item.MedChrgitmType = "0"
  944. break
  945. case 1:
  946. item.MedChrgitmType = "14"
  947. break
  948. case 2:
  949. item.MedChrgitmType = "05"
  950. break
  951. case 3:
  952. item.MedChrgitmType = "03"
  953. break
  954. case 4:
  955. item.MedChrgitmType = "03"
  956. break
  957. case 5:
  958. item.MedChrgitmType = "08"
  959. break
  960. case 6:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 7:
  964. item.MedChrgitmType = "14"
  965. break
  966. case 8:
  967. item.MedChrgitmType = "03"
  968. break
  969. case 9:
  970. item.MedChrgitmType = "14"
  971. break
  972. case 10:
  973. item.MedChrgitmType = "14"
  974. break
  975. case 11:
  976. item.MedChrgitmType = "06"
  977. break
  978. case 12:
  979. item.MedChrgitmType = "12"
  980. break
  981. case 13:
  982. item.MedChrgitmType = "01"
  983. break
  984. case 14:
  985. item.MedChrgitmType = "04"
  986. break
  987. case 15:
  988. item.MedChrgitmType = "14"
  989. break
  990. }
  991. } else {
  992. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  993. case 1:
  994. item.MedChrgitmType = "14"
  995. break
  996. case 2:
  997. item.MedChrgitmType = "05"
  998. break
  999. case 3:
  1000. item.MedChrgitmType = "04"
  1001. break
  1002. case 4:
  1003. item.MedChrgitmType = "14"
  1004. break
  1005. case 5:
  1006. item.MedChrgitmType = "08"
  1007. break
  1008. case 6:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. case 7:
  1012. item.MedChrgitmType = "14"
  1013. break
  1014. case 8:
  1015. item.MedChrgitmType = "03"
  1016. break
  1017. case 9:
  1018. item.MedChrgitmType = "14"
  1019. break
  1020. default:
  1021. item.MedChrgitmType = "14"
  1022. break
  1023. }
  1024. }
  1025. } else if item.HisPrescriptionProject.Type == 3 {
  1026. item.MedChrgitmType = "08"
  1027. }
  1028. }
  1029. }
  1030. if order.IsMedicineInsurance != 1 {
  1031. order.PsnCashPay = order.MedfeeSumamt
  1032. }
  1033. for _, item := range orderInfos {
  1034. if item.MedChrgitmType == "01" { //床位费
  1035. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1036. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1037. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1038. }
  1039. if item.MedChrgitmType == "02" { //诊察费
  1040. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1041. //zhenChaCostSelfTotal = zhenChaCostTotal
  1042. }
  1043. if item.MedChrgitmType == "03" { //检查费
  1044. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1045. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1046. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1047. }
  1048. if item.MedChrgitmType == "02" { //检查费
  1049. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1050. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1051. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1052. }
  1053. if item.MedChrgitmType == "04" { //化验费
  1054. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1055. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1056. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1057. }
  1058. if item.MedChrgitmType == "05" { //治疗费
  1059. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1060. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1061. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1062. }
  1063. if item.MedChrgitmType == "06" { //手术费
  1064. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1065. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1066. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1067. }
  1068. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1069. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1070. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1071. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1072. }
  1073. if item.MedChrgitmType == "09" { //西药费
  1074. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1075. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1076. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1077. }
  1078. if item.MedChrgitmType == "11" { //中成费
  1079. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1080. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1081. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1082. }
  1083. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1084. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1085. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1086. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1087. }
  1088. }
  1089. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1090. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1091. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1092. var dia_config []*models.HisXtDiagnoseConfig
  1093. var diagnosis_ids []string
  1094. if his.ID > 0 {
  1095. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1096. } else {
  1097. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1098. }
  1099. for _, item := range diagnosis_ids {
  1100. id, _ := strconv.ParseInt(item, 10, 64)
  1101. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1102. dia_config = append(dia_config, diagnosisConfig)
  1103. }
  1104. var rf []CustomFundPay
  1105. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1106. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1107. c.ServeSuccessJSON(map[string]interface{}{
  1108. "patient": patient,
  1109. "order_infos": orderInfos,
  1110. "diagnosis": name,
  1111. "bedCostTotal": bedCostTotal,
  1112. "bedCostSelfTotal": bedCostTotal,
  1113. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1114. "operationCostTotal": operationCostTotal,
  1115. "operationCostSelfTotal": operationCostTotal,
  1116. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1117. "otherCostTotal": otherCostTotal,
  1118. "otherCostSelfTotal": otherCostTotal,
  1119. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1120. "materialCostTotal": materialCostTotal,
  1121. "materialCostSelfTotal": materialCostTotal,
  1122. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1123. "westernMedicineCostTotal": westernMedicineCostTotal,
  1124. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1125. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1126. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1127. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1128. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1129. "checkCostTotal": checkCostTotal,
  1130. "checkCostSelfTotal": checkCostTotal,
  1131. "zhenChaCostTotal": zhenChaCostTotal,
  1132. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1133. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1134. "laboratoryCostTotal": laboratoryCostTotal,
  1135. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1136. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1137. "treatCostTotal": treatCostTotal,
  1138. "treatCostSelfTotal": treatCostTotal,
  1139. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1140. "charge_admin": charge_admin,
  1141. "printor_admin": printor_admin,
  1142. "org_name": org.OrgName,
  1143. "org_code": miConfig.Code,
  1144. "name": patient.Name,
  1145. "number": order.MdtrtId,
  1146. "date": order.SettleAccountsDate,
  1147. "info": order,
  1148. "new_order": order,
  1149. "his_hospital": his_hospital,
  1150. "his": his,
  1151. "funds": rf,
  1152. "dia_config": dia_config,
  1153. })
  1154. }
  1155. func (c *HisApiController) RefudDetail() {
  1156. order_id, _ := c.GetInt64("order_id")
  1157. order, _ := service.GetHisOrderByID(order_id)
  1158. adminUser := c.GetAdminUserInfo()
  1159. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1160. c.ServeSuccessJSON(map[string]interface{}{
  1161. "msg": "撤销成功",
  1162. })
  1163. }
  1164. func (c *HisApiController) Sscard() {
  1165. //r := CardInit()
  1166. //if r == 0 {
  1167. // GetBaseInfo()
  1168. //}
  1169. //c.ServeSuccessJSON(map[string]interface{}{
  1170. // "list": "11",
  1171. //})
  1172. }
  1173. func GetBaseInfo() error {
  1174. //handle := syscall.MustLoadDLL("SSCard.dll")
  1175. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1176. //
  1177. //str := make([]byte, 256)
  1178. //str1 := make([]byte, 256)
  1179. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1180. //if ferr != nil {
  1181. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1182. // return ferr
  1183. //}
  1184. //
  1185. //fmt.Println(string(str))
  1186. //
  1187. //fmt.Println(r)
  1188. return nil
  1189. }
  1190. func CardInit() int {
  1191. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1192. //add := DllTestDef.MustFindProc("Init")
  1193. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1194. //if err != nil {
  1195. // fmt.Println("SSCard的运算结果为:", ret)
  1196. //}
  1197. //result := int(ret)
  1198. return 0
  1199. }
  1200. func IntPtr(n int) uintptr {
  1201. return uintptr(n)
  1202. }
  1203. func StrPtr(s string) uintptr {
  1204. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1205. }
  1206. func (c *HisApiController) GetHisPatientList() {
  1207. record_date := c.GetString("record_date")
  1208. sch_type, _ := c.GetInt64("sch_type")
  1209. patient_type, _ := c.GetInt64("patient_type")
  1210. fmt.Println("patient_type")
  1211. fmt.Println(patient_type)
  1212. timeLayout := "2006-01-02"
  1213. loc, _ := time.LoadLocation("Local")
  1214. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1215. if err != nil {
  1216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1217. return
  1218. }
  1219. recordDateTime := theTime.Unix()
  1220. adminInfo := c.GetAdminUserInfo()
  1221. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1222. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1223. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1224. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1225. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1226. fmt.Println(patients_three)
  1227. //获取当前用户的信息
  1228. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1229. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1230. //获取所有科室信息
  1231. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1232. //var aa []service.PatientThree
  1233. noElementsSlice := make([]service.PatientThree, 0)
  1234. c.ServeSuccessJSON(map[string]interface{}{
  1235. "list": patients_three,
  1236. "list_two": patients_four,
  1237. "list_three": noElementsSlice,
  1238. "info": adminUserInfo,
  1239. "doctors": doctors,
  1240. "department": department,
  1241. })
  1242. } else {
  1243. //获取当前用户的信息
  1244. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1245. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1246. //获取所有科室信息
  1247. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1248. //var aa []service.PatientThree
  1249. noElementsSlice := make([]service.PatientThree, 0)
  1250. c.ServeSuccessJSON(map[string]interface{}{
  1251. "list": patients,
  1252. "list_two": patients_two,
  1253. "list_three": noElementsSlice,
  1254. "info": adminUserInfo,
  1255. "doctors": doctors,
  1256. "department": department,
  1257. })
  1258. }
  1259. }
  1260. type CustomTemplate struct {
  1261. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1262. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1263. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1264. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1265. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1266. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1267. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1268. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1269. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1270. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1271. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1272. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1273. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1274. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1275. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1276. }
  1277. func (c *HisApiController) GetHisPatientInfo() {
  1278. patient_id, _ := c.GetInt64("patient_id")
  1279. his_patient_id, _ := c.GetInt64("his_patient_id")
  1280. record_date := c.GetString("record_date")
  1281. number := c.GetString("number")
  1282. //start_time := c.GetString("start_time")
  1283. //end_time := c.GetString("end_time")
  1284. p_type, _ := c.GetInt64("p_type")
  1285. timeLayout := "2006-01-02"
  1286. loc, _ := time.LoadLocation("Local")
  1287. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1288. if err != nil {
  1289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1290. return
  1291. }
  1292. recordDateTime := theTime.Unix()
  1293. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1294. //if err != nil {
  1295. //
  1296. //}
  1297. //startRecordDateTime := startTime.Unix()
  1298. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1299. //if err != nil {
  1300. //
  1301. //}
  1302. //endRecordDateTime := endTime.Unix()
  1303. admin := c.GetAdminUserInfo()
  1304. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1305. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1306. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1307. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1308. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1309. var prescriptions []*models.HisPrescription
  1310. var last_prescriptions []*models.HisPrescription
  1311. var sch_prescriptions []CustomTemplate
  1312. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1313. if p_type == 1 { //住院
  1314. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1315. for _, item := range prescriptions {
  1316. for _, subItem := range item.HisDoctorAdviceInfo {
  1317. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1318. if info.RetailPrice > 0 {
  1319. subItem.Drug.MinPrice = info.RetailPrice
  1320. }
  1321. }
  1322. }
  1323. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1324. } else { //门诊
  1325. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1326. for _, item := range prescriptions {
  1327. for _, subItem := range item.HisDoctorAdviceInfo {
  1328. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1329. if info.RetailPrice > 0 {
  1330. subItem.Drug.MinPrice = info.RetailPrice
  1331. }
  1332. }
  1333. }
  1334. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1335. }
  1336. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1337. if sch.ID > 0 {
  1338. var week string
  1339. t := time.Now()
  1340. switch t.Weekday().String() {
  1341. case "Monday":
  1342. week = "周一"
  1343. break
  1344. case "Tuesday":
  1345. week = "周二"
  1346. break
  1347. case "Wednesday":
  1348. week = "周三"
  1349. break
  1350. case "Thursday":
  1351. week = "周四"
  1352. break
  1353. case "Friday":
  1354. week = "周五"
  1355. break
  1356. case "Saturday":
  1357. week = "周六"
  1358. break
  1359. case "Sunday":
  1360. week = "周日"
  1361. break
  1362. }
  1363. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1364. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1365. //根据推送频率组装新的数组
  1366. for _, item := range temp_sch_prescriptions {
  1367. var cus CustomTemplate
  1368. cus.ID = item.ID
  1369. cus.UserOrgId = item.UserOrgId
  1370. cus.PatientId = item.PatientId
  1371. cus.MedType = item.MedType
  1372. cus.RecordDate = item.RecordDate
  1373. cus.Type = item.Type
  1374. cus.PType = item.PType
  1375. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1376. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1377. if subItem.FrequencyType == 1 { //每次必推
  1378. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1379. }
  1380. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1381. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1382. }
  1383. if subItem.FrequencyType == 2 { //按照天数频率
  1384. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1385. now := p.Unix()
  1386. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1387. dayStr2 := "-" + dayStr
  1388. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1389. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1390. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1391. if len(advices) == 0 {
  1392. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1393. }
  1394. }
  1395. }
  1396. }
  1397. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1398. if subItem.Type == 2 {
  1399. if subItem.XtHisProject.MedicalStatus != 1 {
  1400. if subItem.FrequencyType == 1 {
  1401. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1402. }
  1403. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1404. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1405. }
  1406. if subItem.FrequencyType == 2 {
  1407. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1408. now := p.Unix()
  1409. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1410. dayStr2 := "-" + dayStr
  1411. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1412. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1413. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1414. if len(projects) == 0 {
  1415. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1416. }
  1417. }
  1418. }
  1419. } else if subItem.Type == 3 {
  1420. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1421. if subItem.FrequencyType == 1 {
  1422. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1423. }
  1424. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1425. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1426. }
  1427. if subItem.FrequencyType == 2 {
  1428. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1429. now := p.Unix()
  1430. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1431. dayStr2 := "-" + dayStr
  1432. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1433. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1434. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1435. if len(projects) == 0 {
  1436. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1437. }
  1438. }
  1439. }
  1440. }
  1441. }
  1442. sch_prescriptions = append(sch_prescriptions, cus)
  1443. }
  1444. for _, item := range sch_prescriptions {
  1445. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1446. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1447. }
  1448. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1449. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1450. }
  1451. }
  1452. }
  1453. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1454. if config.ID > 0 && config.IsOpen == 1 {
  1455. for _, item := range sch_prescriptions {
  1456. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1457. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1458. if info.RetailPrice > 0 {
  1459. subItem.Drug.MinPrice = info.RetailPrice
  1460. if admin.CurrentOrgId != 10598 {
  1461. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1462. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1463. }
  1464. }
  1465. }
  1466. }
  1467. }
  1468. if config.ID > 0 && config.IsOpen == 1 {
  1469. for _, item := range sch_prescriptions {
  1470. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1471. if subItem.Type == 3 {
  1472. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1473. if info.Price > 0 {
  1474. subItem.GoodInfo.PackingPrice = info.Price
  1475. if admin.CurrentOrgId != 10598 {
  1476. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1477. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1478. }
  1479. }
  1480. }
  1481. }
  1482. }
  1483. }
  1484. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1485. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1486. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1487. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1488. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1489. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1490. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1491. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1492. //获取所有科室信息
  1493. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1494. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1495. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1496. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1497. fmt.Println(prescriptions)
  1498. fmt.Println(sch_prescriptions)
  1499. fmt.Println(last_prescriptions)
  1500. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1501. if len(sch_prescriptions) > 0 {
  1502. var index = 0
  1503. for subindex, item := range sch_prescriptions {
  1504. if item.Type == 2 {
  1505. index = subindex
  1506. }
  1507. }
  1508. fmt.Println(index)
  1509. fmt.Println(len(sch_prescriptions))
  1510. if index >= 0 && index < len(sch_prescriptions) {
  1511. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1512. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1513. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1514. if one.ID > 0 {
  1515. var hpt models.HisPrescriptionProjectTemplate
  1516. hpt.Type = 3
  1517. hpt.ID = 0
  1518. hpt.PatientId = sch_prescriptions[index].PatientId
  1519. hpt.Status = 1
  1520. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1521. hpt.Mtime = time.Now().Unix()
  1522. hpt.Ctime = time.Now().Unix()
  1523. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1524. hpt.Count = "1"
  1525. hpt.Price = one.RetailPrice
  1526. hpt.ProjectId = one.ID
  1527. hpt.FeedetlSn = ""
  1528. hpt.PrescriptionId = sch_prescriptions[index].ID
  1529. hpt.Unit = one.PackingUnit
  1530. hpt.Day = "1"
  1531. hpt.SingleDose = "1"
  1532. hpt.GoodInfo = one
  1533. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1534. }
  1535. if two.ID > 0 {
  1536. var hpt models.HisPrescriptionProjectTemplate
  1537. hpt.Type = 3
  1538. hpt.ID = 0
  1539. hpt.PatientId = sch_prescriptions[index].PatientId
  1540. hpt.Status = 1
  1541. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1542. hpt.Mtime = time.Now().Unix()
  1543. hpt.Ctime = time.Now().Unix()
  1544. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1545. hpt.Count = "1"
  1546. hpt.Price = two.RetailPrice
  1547. hpt.ProjectId = two.ID
  1548. hpt.FeedetlSn = ""
  1549. hpt.PrescriptionId = sch_prescriptions[index].ID
  1550. hpt.Unit = two.PackingUnit
  1551. hpt.Day = "1"
  1552. hpt.SingleDose = "1"
  1553. hpt.GoodInfo = two
  1554. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1555. }
  1556. //if three.ID > 0 {
  1557. // var hpt models.HisPrescriptionProjectTemplate
  1558. // hpt.Type = 3
  1559. // hpt.ID = 0
  1560. // hpt.PatientId = sch_prescriptions[index].PatientId
  1561. // hpt.Status = 1
  1562. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1563. // hpt.Mtime = time.Now().Unix()
  1564. // hpt.Ctime = time.Now().Unix()
  1565. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1566. // hpt.Count = "1"
  1567. // hpt.Price = three.RetailPrice
  1568. // hpt.ProjectId = three.ID
  1569. // hpt.FeedetlSn = ""
  1570. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1571. // hpt.Unit = three.PackingUnit
  1572. // hpt.Day = "1"
  1573. // hpt.SingleDose = "1"
  1574. // hpt.GoodInfo = three
  1575. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1576. //}
  1577. fmt.Println(sch_prescriptions)
  1578. }
  1579. } else {
  1580. if len(last_prescriptions) > 0 {
  1581. var index = 0
  1582. for subindex, item := range last_prescriptions {
  1583. if item.Type == 2 {
  1584. index = subindex
  1585. }
  1586. }
  1587. if index >= 0 && index < len(last_prescriptions) {
  1588. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1589. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1590. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1591. if one.ID > 0 {
  1592. var hpt models.HisPrescriptionProject
  1593. hpt.Type = 3
  1594. hpt.ID = 0
  1595. hpt.PatientId = last_prescriptions[index].PatientId
  1596. hpt.Status = 1
  1597. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1598. hpt.Mtime = time.Now().Unix()
  1599. hpt.Ctime = time.Now().Unix()
  1600. hpt.RecordDate = last_prescriptions[index].RecordDate
  1601. hpt.Count = "1"
  1602. hpt.Price = one.RetailPrice
  1603. hpt.ProjectId = one.ID
  1604. hpt.FeedetlSn = ""
  1605. hpt.PrescriptionId = last_prescriptions[index].ID
  1606. hpt.Unit = one.PackingUnit
  1607. hpt.Day = "1"
  1608. hpt.SingleDose = "1"
  1609. hpt.GoodInfo = one
  1610. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1611. }
  1612. if two.ID > 0 {
  1613. var hpt models.HisPrescriptionProject
  1614. hpt.Type = 3
  1615. hpt.ID = 0
  1616. hpt.PatientId = last_prescriptions[index].PatientId
  1617. hpt.Status = 1
  1618. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1619. hpt.Mtime = time.Now().Unix()
  1620. hpt.Ctime = time.Now().Unix()
  1621. hpt.RecordDate = last_prescriptions[index].RecordDate
  1622. hpt.Count = "1"
  1623. hpt.Price = two.RetailPrice
  1624. hpt.ProjectId = two.ID
  1625. hpt.FeedetlSn = ""
  1626. hpt.PrescriptionId = last_prescriptions[index].ID
  1627. hpt.Unit = two.PackingUnit
  1628. hpt.Day = "1"
  1629. hpt.SingleDose = "1"
  1630. hpt.GoodInfo = two
  1631. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1632. }
  1633. //if three.ID > 0 {
  1634. // var hpt models.HisPrescriptionProject
  1635. // hpt.Type = 3
  1636. // hpt.ID = 0
  1637. // hpt.PatientId = last_prescriptions[index].PatientId
  1638. // hpt.Status = 1
  1639. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1640. // hpt.Mtime = time.Now().Unix()
  1641. // hpt.Ctime = time.Now().Unix()
  1642. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1643. // hpt.Count = "1"
  1644. // hpt.Price = three.RetailPrice
  1645. // hpt.ProjectId = three.ID
  1646. // hpt.FeedetlSn = ""
  1647. // hpt.PrescriptionId = last_prescriptions[index].ID
  1648. // hpt.Unit = three.PackingUnit
  1649. // hpt.Day = "1"
  1650. // hpt.SingleDose = "1"
  1651. // hpt.GoodInfo = three
  1652. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1653. //}
  1654. }
  1655. }
  1656. }
  1657. }
  1658. c.ServeSuccessJSON(map[string]interface{}{
  1659. "his_info": his_patient_info,
  1660. "xt_info": xt_patient_info,
  1661. "prescription": prescriptions,
  1662. "case_history": case_history,
  1663. "info": patientPrescriptionInfo,
  1664. //"month_prescriptions": monthPrescriptions,
  1665. "order": order,
  1666. "doctors": doctors,
  1667. "department": department,
  1668. "sch_prescriptions": sch_prescriptions,
  1669. "last_prescriptions": last_prescriptions,
  1670. "schedule": sch,
  1671. "count": count,
  1672. "drugStockConfig": drugStockConfig,
  1673. "last_info": lastPatientPrescriptionInfo,
  1674. "befor": beforThrity,
  1675. "LastCaseHistory": LastCaseHistory,
  1676. "prescriptionInfo": prescriptionInfo,
  1677. })
  1678. return
  1679. }
  1680. func (c *HisApiController) GetHisPrescriptionConfig() {
  1681. adminInfo := c.GetAdminUserInfo()
  1682. //获取医嘱模版
  1683. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1684. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1685. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1686. //获取所有基础药
  1687. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1688. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1689. if config.ID > 0 && config.IsOpen == 1 {
  1690. for _, item := range drugs {
  1691. var index = 0
  1692. for _, subItem := range item.OtherDrugWarehouseInfo {
  1693. if index == 0 {
  1694. index = index + 1
  1695. if subItem.RetailPrice > 0 {
  1696. item.MinPrice = subItem.RetailPrice
  1697. }
  1698. }
  1699. }
  1700. }
  1701. }
  1702. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1703. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1704. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1705. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1706. //获取所有科室信息
  1707. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1708. //获取诊断信息
  1709. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1710. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1711. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1712. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1713. //获取是否开启保存耗材出库的开关
  1714. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1715. c.ServeSuccessJSON(map[string]interface{}{
  1716. "drugs": drugs,
  1717. "advices_template": advices,
  1718. "drugways": drugways,
  1719. "efs": efs,
  1720. "doctors": doctors,
  1721. "department": department,
  1722. "sick": sick,
  1723. "additions": additions,
  1724. "diagnose": diagnose,
  1725. "manufacturers": manufacturers,
  1726. "goodOutOpen": goodOutOpen,
  1727. "patientDiagnose": patientDiagnose,
  1728. })
  1729. }
  1730. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1731. //获取所有基础药
  1732. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1733. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1734. if config.ID > 0 && config.IsOpen == 1 {
  1735. for _, item := range drugs {
  1736. var index = 0
  1737. for _, subItem := range item.OtherDrugWarehouseInfo {
  1738. if index == 0 {
  1739. index = index + 1
  1740. if subItem.RetailPrice > 0 {
  1741. item.MinPrice = subItem.RetailPrice
  1742. }
  1743. }
  1744. }
  1745. }
  1746. }
  1747. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1748. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1749. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1750. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1751. //获取所有科室信息
  1752. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1753. //获取诊断信息
  1754. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1755. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1756. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1757. //获取是否开启保存耗材出库的开关
  1758. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1759. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1760. c.ServeSuccessJSON(map[string]interface{}{
  1761. "drugs": drugs,
  1762. "advices_template": advices,
  1763. "drugways": drugways,
  1764. "efs": efs,
  1765. "doctors": doctors,
  1766. "department": department,
  1767. "sick": sick,
  1768. "additions": additions,
  1769. "diagnose": diagnose,
  1770. "manufacturers": manufacturers,
  1771. "goodOutOpen": goodOutOpen,
  1772. "patientDiagnose": patientDiagnose,
  1773. })
  1774. }
  1775. }
  1776. func (c *HisApiController) CreateHisPrescription() {
  1777. record_date := c.GetString("record_date")
  1778. patient_id, _ := c.GetInt64("patient_id")
  1779. reg_type, _ := c.GetInt64("reg_type")
  1780. diagnose := c.GetString("diagnose")
  1781. sick_type, _ := c.GetInt64("sick_type")
  1782. sick_history := c.GetString("sick_history")
  1783. doctor_id, _ := c.GetInt64("doctor", 0)
  1784. department, _ := c.GetInt64("department", 0)
  1785. his_patient_id, _ := c.GetInt64("his_patient_id")
  1786. p_type, _ := c.GetInt64("p_type")
  1787. patient_diagnose := c.GetString("patient_diagnose")
  1788. dataBody := make(map[string]interface{}, 0)
  1789. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1790. if err != nil {
  1791. utils.ErrorLog(err.Error())
  1792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1793. return
  1794. }
  1795. //edit, src := GetCompareData(dataBody)
  1796. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1797. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1798. //fmt.Println(drugResult)
  1799. //fmt.Println(goodResult)
  1800. timeLayout := "2006-01-02"
  1801. loc, _ := time.LoadLocation("Local")
  1802. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1803. if err != nil {
  1804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1805. return
  1806. }
  1807. adminInfo := c.GetAdminUserInfo()
  1808. recordDateTime := theTime.Unix()
  1809. //查询默认出库仓库库存
  1810. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1811. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1812. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1813. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1814. if len(lists) == 1 {
  1815. his_patient_id = lists[0].ID
  1816. }
  1817. }
  1818. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1819. //自动出库的开关开启
  1820. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1821. //自动出库
  1822. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1823. //耗材保存处方出库
  1824. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1825. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1826. //已发药和已收费限制逻辑
  1827. isMidicine := false
  1828. isCharge := false
  1829. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1830. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1831. if len(prescriptions) > 0 {
  1832. for _, item := range prescriptions {
  1833. items := item.(map[string]interface{})
  1834. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1835. utils.ErrorLog("id")
  1836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1837. return
  1838. }
  1839. id := int64(items["id"].(float64))
  1840. if id > 0 {
  1841. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1842. if err != nil {
  1843. if new_prescription.OrderStatus == 4 {
  1844. isCharge = true
  1845. }
  1846. }
  1847. }
  1848. }
  1849. }
  1850. }
  1851. if isMidicine == true {
  1852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1853. return
  1854. }
  1855. if isCharge == true {
  1856. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1857. return
  1858. }
  1859. // 开始主事务
  1860. db := service.XTWriteDB()
  1861. tx := db.Begin()
  1862. // 在函数结束时处理事务回滚
  1863. defer func() {
  1864. if r := recover(); r != nil {
  1865. tx.Rollback()
  1866. }
  1867. }()
  1868. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1869. //药品发药出库
  1870. if pharmacyConfig.IsOpen == 1 {
  1871. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1872. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1873. if len(prescriptions) > 0 {
  1874. for _, item := range prescriptions {
  1875. items := item.(map[string]interface{})
  1876. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1877. advices := items["advices"].([]interface{})
  1878. if len(advices) > 0 {
  1879. for _, advice := range advices {
  1880. var drug_id int64
  1881. var prescribing_number float64
  1882. var prescribingNumberUnit string
  1883. var adviceId int64
  1884. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1885. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1886. }
  1887. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1888. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1889. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1890. }
  1891. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1892. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1893. }
  1894. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1895. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1896. }
  1897. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1898. if drug.ID == 0 {
  1899. tx.Rollback()
  1900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1901. return
  1902. }
  1903. //查询药品的所有库存
  1904. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1905. var total_count int64
  1906. for _, it := range list {
  1907. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1908. }
  1909. totals := strconv.FormatInt(total_count, 10)
  1910. //查询该药品是否存在开药记录
  1911. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1912. //新增处方盘点库存是否充足
  1913. if advicelist.ID == 0 {
  1914. all_count, _ := strconv.ParseFloat(totals, 64)
  1915. if prescribingNumberUnit == drug.MinUnit {
  1916. if drug.IsUse != 1 {
  1917. if drug.IsProject == 0 || drug.IsProject == 2 {
  1918. if all_count == 0 {
  1919. tx.Rollback()
  1920. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1921. return
  1922. }
  1923. if prescribing_number > all_count {
  1924. tx.Rollback()
  1925. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1926. return
  1927. }
  1928. }
  1929. }
  1930. }
  1931. if prescribingNumberUnit == drug.MaxUnit {
  1932. num := prescribing_number * float64(drug.MinNumber)
  1933. if drug.IsUse != 1 {
  1934. if drug.IsProject == 0 || drug.IsProject == 2 {
  1935. if all_count == 0 {
  1936. tx.Rollback()
  1937. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1938. return
  1939. }
  1940. if num > all_count {
  1941. tx.Rollback()
  1942. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1943. return
  1944. }
  1945. }
  1946. }
  1947. }
  1948. }
  1949. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1950. //不使用保存处方出库
  1951. if drugOutConfig.IsOpen != 1 {
  1952. //修改处方
  1953. for _, advice := range advices {
  1954. var drug_id int64
  1955. var prescribing_number float64
  1956. var prescribingNumberUnit string
  1957. var prescribingNumber string
  1958. var adviceId 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. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1963. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1964. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1965. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1966. }
  1967. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1968. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1969. }
  1970. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1971. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1972. }
  1973. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1974. if drug.ID == 0 {
  1975. tx.Rollback()
  1976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1977. return
  1978. }
  1979. //查询药品的所有库存
  1980. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1981. var total_count int64
  1982. for _, it := range list {
  1983. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1984. }
  1985. totals := strconv.FormatInt(total_count, 10)
  1986. //查询该药品是否存在开药记录
  1987. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1988. //新增处方
  1989. if advicelist.ID == 0 {
  1990. all_count, _ := strconv.ParseFloat(totals, 64)
  1991. if prescribingNumberUnit == drug.MinUnit {
  1992. if drug.IsUse != 1 {
  1993. if drug.IsProject == 0 || drug.IsProject == 2 {
  1994. if all_count == 0 {
  1995. tx.Rollback()
  1996. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1997. return
  1998. }
  1999. if prescribing_number > all_count {
  2000. tx.Rollback()
  2001. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2002. return
  2003. }
  2004. }
  2005. }
  2006. } else {
  2007. if prescribingNumberUnit == drug.MaxUnit {
  2008. num := prescribing_number * float64(drug.MinNumber)
  2009. if drug.IsUse != 1 {
  2010. if drug.IsProject == 0 || drug.IsProject == 2 {
  2011. if all_count == 0 {
  2012. tx.Rollback()
  2013. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2014. return
  2015. }
  2016. if num > all_count {
  2017. tx.Rollback()
  2018. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2019. return
  2020. }
  2021. }
  2022. }
  2023. }
  2024. }
  2025. }
  2026. //修改处方
  2027. if advicelist.ID > 0 {
  2028. var device_number int64
  2029. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2030. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2031. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2032. device_number = prescribingNumberInt * drug.MinNumber
  2033. }
  2034. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2035. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2036. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2037. device_number = prescribingNumberInt
  2038. }
  2039. var number_count int64
  2040. if prescribingNumberUnit == drug.MaxUnit {
  2041. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2042. number_count = prescribingNumberInt * drug.MinNumber
  2043. }
  2044. if prescribingNumberUnit == drug.MinUnit {
  2045. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2046. number_count = prescribingNumberInt
  2047. }
  2048. //如果修改的数量大于之前修改的数量
  2049. if (number_count - device_number) > 0 {
  2050. //如果修改的差数量 大于库存数量
  2051. if drug.IsUse != 1 {
  2052. if (number_count - device_number) > total_count {
  2053. tx.Rollback()
  2054. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2055. return
  2056. }
  2057. }
  2058. }
  2059. }
  2060. }
  2061. }
  2062. }
  2063. }
  2064. }
  2065. }
  2066. }
  2067. }
  2068. }
  2069. //已发药和已收费限制逻辑
  2070. //执行出库的逻辑
  2071. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2072. //校验库存总量
  2073. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2074. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2075. if len(prescriptions) > 0 {
  2076. for _, item := range prescriptions {
  2077. items := item.(map[string]interface{})
  2078. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2079. advices := items["advices"].([]interface{})
  2080. if len(advices) > 0 {
  2081. for _, advice := range advices {
  2082. var drug_id int64
  2083. var prescribing_number float64
  2084. var prescribingNumberUnit string
  2085. var adviceId int64
  2086. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2087. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2088. }
  2089. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2090. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2091. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2092. }
  2093. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2094. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2095. }
  2096. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2097. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2098. }
  2099. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2100. if drug.ID == 0 {
  2101. tx.Rollback()
  2102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2103. return
  2104. }
  2105. //查询药品的所有库存
  2106. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2107. var total_count int64
  2108. for _, it := range list {
  2109. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2110. }
  2111. totals := strconv.FormatInt(total_count, 10)
  2112. //查询该药品是否存在开药记录
  2113. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2114. //查询最新批次库存
  2115. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2116. var batch_number_count int64
  2117. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2118. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2119. //新增处方
  2120. if advicelist.ID == 0 {
  2121. all_count, _ := strconv.ParseFloat(totals, 64)
  2122. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2123. if prescribingNumberUnit == drug.MinUnit {
  2124. if drug.IsUse != 1 {
  2125. if drug.IsProject == 0 || drug.IsProject == 2 {
  2126. if all_count == 0 {
  2127. tx.Rollback()
  2128. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2129. return
  2130. }
  2131. if prescribing_number > all_count {
  2132. tx.Rollback()
  2133. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2134. return
  2135. }
  2136. }
  2137. if adminInfo.CurrentOrgId == 10215 {
  2138. if prescribing_number > batch_number_all_count {
  2139. tx.Rollback()
  2140. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2141. return
  2142. }
  2143. }
  2144. }
  2145. }
  2146. if prescribingNumberUnit == drug.MaxUnit {
  2147. num := prescribing_number * float64(drug.MinNumber)
  2148. if drug.IsUse != 1 {
  2149. if drug.IsProject == 0 || drug.IsProject == 2 {
  2150. if all_count == 0 {
  2151. tx.Rollback()
  2152. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2153. return
  2154. }
  2155. if num > all_count {
  2156. tx.Rollback()
  2157. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2158. return
  2159. }
  2160. }
  2161. if adminInfo.CurrentOrgId == 10215 {
  2162. if num > batch_number_all_count {
  2163. tx.Rollback()
  2164. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2165. return
  2166. }
  2167. }
  2168. }
  2169. }
  2170. }
  2171. //不是保存处方出库
  2172. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2173. if drugOutConfig.IsOpen != 1 {
  2174. //修改处方
  2175. for _, advice := range advices {
  2176. var drug_id int64
  2177. var prescribing_number float64
  2178. var prescribingNumberUnit string
  2179. var prescribingNumber string
  2180. var adviceId int64
  2181. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2182. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2183. }
  2184. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2185. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2186. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2187. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2188. }
  2189. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2190. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2191. }
  2192. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2193. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2194. }
  2195. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2196. if drug.ID == 0 {
  2197. tx.Rollback()
  2198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2199. return
  2200. }
  2201. //查询药品的所有库存
  2202. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2203. var total_count int64
  2204. for _, it := range list {
  2205. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2206. }
  2207. totals := strconv.FormatInt(total_count, 10)
  2208. //查询该药品是否存在开药记录
  2209. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2210. //新增处方
  2211. if advicelist.ID == 0 {
  2212. //查询最新批次库存
  2213. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2214. var batch_number_count int64
  2215. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2216. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2217. all_count, _ := strconv.ParseFloat(totals, 64)
  2218. if all_count == 0 {
  2219. tx.Rollback()
  2220. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2221. return
  2222. }
  2223. if prescribingNumberUnit == drug.MinUnit {
  2224. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2225. if drug.IsUse != 1 {
  2226. if drug.IsProject == 0 || drug.IsProject == 2 {
  2227. if all_count == 0 {
  2228. tx.Rollback()
  2229. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2230. return
  2231. }
  2232. if prescribing_number > all_count {
  2233. tx.Rollback()
  2234. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2235. return
  2236. }
  2237. }
  2238. if adminInfo.CurrentOrgId == 10215 {
  2239. if prescribing_number > batch_number_all_count {
  2240. tx.Rollback()
  2241. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2242. return
  2243. }
  2244. }
  2245. }
  2246. } else {
  2247. if prescribingNumberUnit == drug.MaxUnit {
  2248. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2249. num := prescribing_number * float64(drug.MinNumber)
  2250. if drug.IsUse != 1 {
  2251. if drug.IsProject == 0 || drug.IsProject == 2 {
  2252. if all_count == 0 {
  2253. tx.Rollback()
  2254. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2255. return
  2256. }
  2257. if num > all_count {
  2258. tx.Rollback()
  2259. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2260. return
  2261. }
  2262. }
  2263. if adminInfo.CurrentOrgId == 10215 {
  2264. if prescribing_number > batch_number_all_count {
  2265. tx.Rollback()
  2266. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2267. return
  2268. }
  2269. }
  2270. }
  2271. }
  2272. }
  2273. }
  2274. //修改处方
  2275. if advicelist.ID > 0 {
  2276. //查询最新批次库存
  2277. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2278. var batch_number_count int64
  2279. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2280. var device_number int64
  2281. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2282. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2283. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2284. device_number = prescribingNumberInt * drug.MinNumber
  2285. }
  2286. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2287. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2288. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2289. device_number = prescribingNumberInt
  2290. //回退库存
  2291. }
  2292. var number_count int64
  2293. if prescribingNumberUnit == drug.MaxUnit {
  2294. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2295. number_count = prescribingNumberInt * drug.MinNumber
  2296. //回退库存
  2297. }
  2298. if prescribingNumberUnit == drug.MinUnit {
  2299. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2300. number_count = prescribingNumberInt
  2301. //回退库存
  2302. }
  2303. //如果修改的数量大于之前修改的数量
  2304. if (number_count - device_number) > 0 {
  2305. //如果修改的差数量 大于库存数量
  2306. if drug.IsUse != 1 {
  2307. if drug.IsProject == 0 || drug.IsProject == 2 {
  2308. if total_count == 0 {
  2309. tx.Rollback()
  2310. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2311. return
  2312. }
  2313. if (number_count - device_number) > total_count {
  2314. tx.Rollback()
  2315. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2316. return
  2317. }
  2318. if (number_count - device_number) > batch_number_count {
  2319. tx.Rollback()
  2320. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2321. return
  2322. }
  2323. }
  2324. if adminInfo.CurrentOrgId == 10215 {
  2325. // 查询该药品最后一次出库记录
  2326. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2327. var out_count int64
  2328. var in_count int64
  2329. var stock_max_number int64
  2330. var stock_min_number int64
  2331. for _, it := range outInfo {
  2332. if it.CountUnit == drug.MaxUnit {
  2333. it.Count = it.Count * drug.MinNumber
  2334. }
  2335. out_count += it.Count
  2336. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2337. stock_max_number = warehouseInfoList.StockMaxNumber
  2338. stock_min_number = warehouseInfoList.StockMinNumber
  2339. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2340. }
  2341. if out_count > 0 {
  2342. if (number_count - device_number) > in_count {
  2343. tx.Rollback()
  2344. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2345. return
  2346. }
  2347. }
  2348. // 未出库
  2349. if out_count == 0 {
  2350. var sum_in_count int64
  2351. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2352. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2353. //如果修改的数量大于有库存的第一个批次
  2354. if number_count > sum_in_count {
  2355. tx.Rollback()
  2356. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2357. return
  2358. }
  2359. }
  2360. }
  2361. }
  2362. }
  2363. //药品发药
  2364. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2365. //不使用药品发药的功能
  2366. //if pharmacyConfig.IsOpen != 1 {
  2367. // if device_number != number_count {
  2368. //
  2369. // //查询该药品的出库记录
  2370. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2371. // if len(outListExport) > 0 {
  2372. // //
  2373. // for _, item := range outListExport {
  2374. // //回退库存
  2375. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2376. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2377. // }
  2378. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2379. // var stock_max_number int64
  2380. // var stock_min_number int64
  2381. //
  2382. // if number_count >= drug.MinNumber {
  2383. //
  2384. // stock_max_number = device_number / drug.MinNumber
  2385. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2386. //
  2387. // stock_min_number = device_number % drug.MinNumber
  2388. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2389. //
  2390. // } else {
  2391. //
  2392. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2393. //
  2394. // }
  2395. // }
  2396. //
  2397. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2398. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2399. // }
  2400. // }
  2401. // }
  2402. //
  2403. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2404. // var sum_count int64
  2405. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2406. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2407. // for _, its := range stockInfo {
  2408. // if its.MaxUnit == drug.MaxUnit {
  2409. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2410. // }
  2411. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2412. // }
  2413. // //更新字典里面的库存
  2414. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2415. //
  2416. // //剩余库存
  2417. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2418. //
  2419. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2420. // //减少出库数量
  2421. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2422. //
  2423. // }
  2424. //}
  2425. }
  2426. }
  2427. }
  2428. //保存处方开药
  2429. if drugOutConfig.IsOpen == 1 {
  2430. //修改处方
  2431. for _, advice := range advices {
  2432. var drug_id int64
  2433. var prescribing_number float64
  2434. var prescribingNumberUnit string
  2435. var prescribingNumber string
  2436. var adviceId int64
  2437. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2438. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2439. }
  2440. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2441. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2442. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2443. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2444. }
  2445. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2446. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2447. }
  2448. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2449. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2450. }
  2451. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2452. if drug.ID == 0 {
  2453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2454. return
  2455. }
  2456. //查询药品的所有库存
  2457. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2458. var total_count int64
  2459. for _, it := range list {
  2460. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2461. }
  2462. totals := strconv.FormatInt(total_count, 10)
  2463. //查询该药品是否存在开药记录
  2464. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2465. //新增处方
  2466. if advicelist.ID == 0 {
  2467. //查询最新批次库存
  2468. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2469. var batch_number_count int64
  2470. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2471. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2472. all_count, _ := strconv.ParseFloat(totals, 64)
  2473. if prescribingNumberUnit == drug.MinUnit {
  2474. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2475. if drug.IsUse != 1 {
  2476. if drug.IsProject == 0 || drug.IsProject == 2 {
  2477. if all_count == 0 {
  2478. tx.Rollback()
  2479. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2480. return
  2481. }
  2482. if prescribing_number > all_count {
  2483. tx.Rollback()
  2484. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2485. return
  2486. }
  2487. }
  2488. if adminInfo.CurrentOrgId == 10215 {
  2489. if prescribing_number > batch_number_all_count {
  2490. tx.Rollback()
  2491. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2492. return
  2493. }
  2494. }
  2495. }
  2496. } else {
  2497. if prescribingNumberUnit == drug.MaxUnit {
  2498. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2499. num := prescribing_number * float64(drug.MinNumber)
  2500. if drug.IsUse != 1 {
  2501. if drug.IsProject == 0 || drug.IsProject == 2 {
  2502. if all_count == 0 {
  2503. tx.Rollback()
  2504. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2505. return
  2506. }
  2507. if num > all_count {
  2508. tx.Rollback()
  2509. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2510. return
  2511. }
  2512. }
  2513. if adminInfo.CurrentOrgId == 10215 {
  2514. if prescribing_number > batch_number_all_count {
  2515. tx.Rollback()
  2516. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2517. return
  2518. }
  2519. }
  2520. }
  2521. }
  2522. }
  2523. }
  2524. //修改处方
  2525. if advicelist.ID > 0 {
  2526. //查询最新批次库存
  2527. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2528. var batch_number_count int64
  2529. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2530. var device_number int64
  2531. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2532. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2533. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2534. device_number = prescribingNumberInt * drug.MinNumber
  2535. }
  2536. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2537. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2538. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2539. device_number = prescribingNumberInt
  2540. }
  2541. var number_count int64
  2542. if prescribingNumberUnit == drug.MaxUnit {
  2543. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2544. number_count = prescribingNumberInt * drug.MinNumber
  2545. }
  2546. if prescribingNumberUnit == drug.MinUnit {
  2547. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2548. number_count = prescribingNumberInt
  2549. }
  2550. //如果修改的数量大于之前修改的数量
  2551. if (number_count - device_number) > 0 {
  2552. //如果修改的差数量 大于库存数量
  2553. if drug.IsUse != 1 {
  2554. if drug.IsProject == 0 || drug.IsProject == 2 {
  2555. if total_count == 0 {
  2556. tx.Rollback()
  2557. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2558. return
  2559. }
  2560. if (number_count - device_number) > total_count {
  2561. tx.Rollback()
  2562. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2563. return
  2564. }
  2565. }
  2566. if adminInfo.CurrentOrgId == 10215 {
  2567. if (number_count - device_number) > batch_number_count {
  2568. tx.Rollback()
  2569. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2570. return
  2571. }
  2572. }
  2573. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2574. //查询历史出库数据总批次
  2575. // 查询该药品最后一次出库记录
  2576. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2577. var out_count int64
  2578. var in_count int64
  2579. var stock_max_number int64
  2580. var stock_min_number int64
  2581. for _, it := range outInfo {
  2582. if it.CountUnit == drug.MaxUnit {
  2583. it.Count = it.Count * drug.MinNumber
  2584. }
  2585. out_count += it.Count
  2586. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2587. stock_max_number = warehouseInfoList.StockMaxNumber
  2588. stock_min_number = warehouseInfoList.StockMinNumber
  2589. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2590. }
  2591. if out_count > 0 {
  2592. if (number_count - device_number) > in_count {
  2593. tx.Rollback()
  2594. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2595. return
  2596. }
  2597. }
  2598. // 未出库
  2599. if out_count == 0 {
  2600. var sum_in_count int64
  2601. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2602. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2603. if sum_in_count == 0 {
  2604. tx.Rollback()
  2605. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2606. return
  2607. }
  2608. //如果修改的数量大于有库存的第一个批次
  2609. if number_count > sum_in_count {
  2610. tx.Rollback()
  2611. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2612. return
  2613. }
  2614. }
  2615. }
  2616. }
  2617. }
  2618. }
  2619. }
  2620. }
  2621. }
  2622. }
  2623. }
  2624. }
  2625. }
  2626. }
  2627. }
  2628. //校验耗材库存
  2629. if goodOutConfig.IsOpen == 1 {
  2630. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2631. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2632. if len(prescriptions) > 0 {
  2633. for _, item := range prescriptions {
  2634. items := item.(map[string]interface{})
  2635. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2636. projects := items["project"].([]interface{})
  2637. if len(projects) > 0 {
  2638. for _, project := range projects {
  2639. var project_id int64
  2640. var project_type int64
  2641. var totals float64
  2642. var project_name string
  2643. var parsetotal int64
  2644. var id int64
  2645. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2646. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2647. }
  2648. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2649. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2650. }
  2651. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2652. total, _ := project.(map[string]interface{})["total"].(string)
  2653. totals, _ = strconv.ParseFloat(total, 64)
  2654. }
  2655. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2656. project_name = project.(map[string]interface{})["project_name"].(string)
  2657. }
  2658. if project_type == 3 {
  2659. //查找该耗材的出库记录
  2660. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2661. if len(goodWarehouseInfo) == 0 {
  2662. //查询耗材库存
  2663. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2664. var stock_count int64
  2665. for _, it := range list {
  2666. stock_count += it.StockCount
  2667. }
  2668. stock_counts := strconv.FormatInt(stock_count, 10)
  2669. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2670. if stock_total_count == 0 {
  2671. tx.Rollback()
  2672. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2673. return
  2674. }
  2675. if totals > stock_total_count {
  2676. tx.Rollback()
  2677. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2678. return
  2679. }
  2680. }
  2681. if len(goodWarehouseInfo) > 0 {
  2682. //查询该患者耗材的历史数据
  2683. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2684. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2685. //数量发生改变
  2686. if parsetotal != count {
  2687. //如果现在的数量大于历史数量,就要看库存是否足够
  2688. if parsetotal > count {
  2689. //查询耗材所有库存
  2690. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2691. var stock_count int64
  2692. for _, it := range list {
  2693. stock_count += it.StockCount
  2694. }
  2695. //库存不足
  2696. if stock_count == 0 {
  2697. tx.Rollback()
  2698. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2699. return
  2700. }
  2701. if (parsetotal - count) > stock_count {
  2702. tx.Rollback()
  2703. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2704. return
  2705. }
  2706. }
  2707. }
  2708. }
  2709. }
  2710. }
  2711. }
  2712. }
  2713. }
  2714. }
  2715. }
  2716. }
  2717. //不使用耗材保存处方出库
  2718. if goodOutConfig.IsOpen != 1 {
  2719. if stockConfig.IsOpen == 1 {
  2720. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2721. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2722. if len(prescriptions) > 0 {
  2723. for _, item := range prescriptions {
  2724. items := item.(map[string]interface{})
  2725. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2726. projects := items["project"].([]interface{})
  2727. if len(projects) > 0 {
  2728. for _, project := range projects {
  2729. var project_id int64
  2730. var project_type int64
  2731. var totals float64
  2732. var project_name string
  2733. var parsetotal int64
  2734. var id int64
  2735. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2736. id = int64(project.(map[string]interface{})["id"].(float64))
  2737. }
  2738. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2739. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2740. }
  2741. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2742. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2743. }
  2744. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2745. total, _ := project.(map[string]interface{})["total"].(string)
  2746. totals, _ = strconv.ParseFloat(total, 64)
  2747. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2748. }
  2749. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2750. project_name = project.(map[string]interface{})["project_name"].(string)
  2751. }
  2752. if project_type == 3 {
  2753. //查找该耗材的出库记录
  2754. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2755. //没有出库记录
  2756. if len(goodWarehouseInfo) == 0 {
  2757. //查询耗材库存
  2758. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2759. var stock_count int64
  2760. for _, it := range list {
  2761. stock_count += it.StockCount
  2762. }
  2763. stock_counts := strconv.FormatInt(stock_count, 10)
  2764. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2765. if stock_total_count == 0 {
  2766. tx.Rollback()
  2767. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2768. return
  2769. }
  2770. if totals > stock_total_count {
  2771. tx.Rollback()
  2772. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2773. return
  2774. }
  2775. //查找今日该患者已经出库的所有耗材
  2776. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2777. for _, item := range goodList {
  2778. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2779. var flush_count int64
  2780. for _, it := range goodListSix {
  2781. flush_count += it.StockCount
  2782. }
  2783. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2784. creater := adminInfo.AdminUser.Id
  2785. if errs != nil {
  2786. goodErrcode := models.XtGoodErrcode{
  2787. UserOrgId: item.OrgId,
  2788. Errcode: "手动出库更新剩余出库失败",
  2789. GoodId: item.GoodId,
  2790. Status: 1,
  2791. Ctime: time.Now().Unix(),
  2792. Mtime: 0,
  2793. Count: 0,
  2794. StockCount: 0,
  2795. Creater: creater,
  2796. BatchNumberId: 0,
  2797. WarehouseOutId: 0,
  2798. }
  2799. service.CreateGoodErrcode(goodErrcode)
  2800. }
  2801. }
  2802. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2803. }
  2804. //有出库记录
  2805. if len(goodWarehouseInfo) > 0 {
  2806. //查询该患者耗材的历史数据
  2807. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2808. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2809. //数量发生改变
  2810. if parsetotal != count {
  2811. //查找今日该患者已经出库的所有耗材
  2812. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2813. for _, item := range goodList {
  2814. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2815. var flush_count int64
  2816. for _, it := range goodListSix {
  2817. flush_count += it.StockCount
  2818. }
  2819. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2820. //减少出库数量
  2821. creater := adminInfo.AdminUser.Id
  2822. if errs != nil {
  2823. goodErrcode := models.XtGoodErrcode{
  2824. UserOrgId: item.OrgId,
  2825. Errcode: "手动出库更新剩余出库失败",
  2826. GoodId: item.GoodId,
  2827. Status: 1,
  2828. Ctime: time.Now().Unix(),
  2829. Mtime: 0,
  2830. Count: 0,
  2831. StockCount: 0,
  2832. Creater: creater,
  2833. BatchNumberId: 0,
  2834. WarehouseOutId: 0,
  2835. }
  2836. service.CreateGoodErrcode(goodErrcode)
  2837. }
  2838. //查询默认仓库
  2839. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2840. var total_count int64
  2841. for _, it := range stockList {
  2842. total_count += it.StockCount
  2843. }
  2844. //基础库插入数据
  2845. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2846. }
  2847. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2848. }
  2849. }
  2850. }
  2851. }
  2852. }
  2853. }
  2854. }
  2855. }
  2856. }
  2857. }
  2858. }
  2859. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2860. var hpInfo models.HisPrescriptionInfo
  2861. if info.ID == 0 {
  2862. var randNum int
  2863. randNum = rand.Intn(10000) + 1000
  2864. timestamp := time.Now().Unix()
  2865. tempTime := time.Unix(timestamp, 0)
  2866. timeFormat := tempTime.Format("20060102150405")
  2867. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2868. hpInfo = models.HisPrescriptionInfo{
  2869. HisPatientId: his_patient_id,
  2870. UserOrgId: adminInfo.CurrentOrgId,
  2871. RecordDate: theTime.Unix(),
  2872. PatientId: patient_id,
  2873. Status: 1,
  2874. Ctime: time.Now().Unix(),
  2875. Mtime: time.Now().Unix(),
  2876. Creator: adminInfo.AdminUser.Id,
  2877. Modifier: adminInfo.AdminUser.Id,
  2878. Diagnosis: diagnose,
  2879. SickHistory: sick_history,
  2880. Departments: department,
  2881. RegisterType: reg_type,
  2882. PrescriptionNumber: p_number,
  2883. PrescriptionStatus: 1,
  2884. Doctor: role.UserName,
  2885. DoctorId: doctor_id,
  2886. SickType: sick_type,
  2887. PType: p_type,
  2888. PatientDiagnosis: patient_diagnose,
  2889. }
  2890. service.SavePatientPrescriptionInfo(hpInfo)
  2891. //创建步骤表
  2892. finish := models.XtDialysisFinish{
  2893. IsFinish: 1,
  2894. UserOrgId: adminInfo.CurrentOrgId,
  2895. Status: 1,
  2896. Ctime: time.Now().Unix(),
  2897. Mtime: 0,
  2898. Module: 4,
  2899. RecordDate: theTime.Unix(),
  2900. Sourse: 1,
  2901. PatientId: patient_id,
  2902. }
  2903. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2904. if dialysisFinish.ID == 0 {
  2905. service.CreateDialysisFinish(finish)
  2906. }
  2907. redis := service.RedisClient()
  2908. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2909. redis.Set(key, "", time.Second)
  2910. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2911. redis.Set(keyOne, "", time.Second)
  2912. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2913. redis.Set(keySeven, "", time.Second)
  2914. defer redis.Close()
  2915. } else {
  2916. hpInfo = models.HisPrescriptionInfo{
  2917. ID: info.ID,
  2918. UserOrgId: adminInfo.CurrentOrgId,
  2919. RecordDate: info.RecordDate,
  2920. PatientId: info.PatientId,
  2921. Status: 1,
  2922. Ctime: info.Ctime,
  2923. Mtime: time.Now().Unix(),
  2924. Creator: info.Creator,
  2925. Modifier: adminInfo.AdminUser.Id,
  2926. Diagnosis: diagnose,
  2927. SickHistory: sick_history,
  2928. Departments: department,
  2929. RegisterType: reg_type,
  2930. PrescriptionNumber: info.PrescriptionNumber,
  2931. Doctor: role.UserName,
  2932. PrescriptionStatus: info.PrescriptionStatus,
  2933. DoctorId: doctor_id,
  2934. SickType: sick_type,
  2935. PType: info.PType,
  2936. HisPatientId: info.HisPatientId,
  2937. PatientDiagnosis: patient_diagnose,
  2938. }
  2939. service.SavePatientPrescriptionInfo(hpInfo)
  2940. //创建步骤表
  2941. finish := models.XtDialysisFinish{
  2942. IsFinish: 1,
  2943. UserOrgId: adminInfo.CurrentOrgId,
  2944. Status: 1,
  2945. Ctime: time.Now().Unix(),
  2946. Mtime: 0,
  2947. Module: 4,
  2948. RecordDate: info.RecordDate,
  2949. Sourse: 1,
  2950. PatientId: info.PatientId,
  2951. }
  2952. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2953. if dialysisFinish.ID == 0 {
  2954. service.CreateDialysisFinish(finish)
  2955. }
  2956. redis := service.RedisClient()
  2957. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2958. redis.Set(key, "", time.Second)
  2959. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2960. redis.Set(keyOne, "", time.Second)
  2961. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2962. redis.Set(keySeven, "", time.Second)
  2963. defer redis.Close()
  2964. }
  2965. //定义切片
  2966. var adviceList []models.HisDoctorAdviceInfo
  2967. var projectList []models.HisPrescriptionProject
  2968. 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 {
  2969. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2970. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2971. var tempPrescription *models.HisPrescription
  2972. if len(prescriptions) > 0 {
  2973. for _, item := range prescriptions {
  2974. // 开始外部循环的事务
  2975. tx := db.Begin()
  2976. // 在函数结束时处理事务回滚
  2977. defer func() {
  2978. if r := recover(); r != nil {
  2979. tx.Rollback()
  2980. }
  2981. }()
  2982. items := item.(map[string]interface{})
  2983. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2984. utils.ErrorLog("id")
  2985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2986. return
  2987. }
  2988. id := int64(items["id"].(float64))
  2989. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2990. tempPrescription = &new_prescription
  2991. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2992. utils.ErrorLog("type")
  2993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2994. return
  2995. }
  2996. types := int64(items["type"].(float64))
  2997. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2998. utils.ErrorLog("med_type")
  2999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3000. return
  3001. }
  3002. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3003. if med_type == "0" {
  3004. med_type = "14"
  3005. }
  3006. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3007. // utils.ErrorLog("diagnoses")
  3008. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3009. // return
  3010. //}
  3011. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3012. diagnoses, _ := items["diagnoses"].(string)
  3013. //if order_status == 0 {
  3014. // order_status = 1
  3015. //}
  3016. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3017. utils.ErrorLog("pre_time")
  3018. }
  3019. preTime, _ := items["pre_time"].(string)
  3020. fmt.Println("preTime", preTime)
  3021. timeLayout := "2006-01-02"
  3022. loc, _ := time.LoadLocation("Local")
  3023. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3024. //result := strings.Split(preTime, " ")
  3025. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3026. if err != nil {
  3027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3028. return
  3029. }
  3030. pTime := theTime2.Unix()
  3031. ctime := time.Now().Unix()
  3032. if tempPrescription.ID == 0 {
  3033. prescription := &models.HisPrescription{
  3034. ID: 0,
  3035. PatientId: patient_id,
  3036. UserOrgId: adminInfo.CurrentOrgId,
  3037. RecordDate: recordDateTime,
  3038. Ctime: ctime,
  3039. Mtime: ctime,
  3040. Type: types,
  3041. Modifier: adminInfo.AdminUser.Id,
  3042. Creator: adminInfo.AdminUser.Id,
  3043. Status: 1,
  3044. Doctor: role.UserName,
  3045. HisPatientId: his_patient_id,
  3046. OrderStatus: 1,
  3047. BatchNumber: "",
  3048. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3049. PreTime: pTime,
  3050. PType: p_type,
  3051. MedType: med_type,
  3052. Diagnose: diagnoses,
  3053. }
  3054. tempPrescription = prescription
  3055. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3056. redis := service.RedisClient()
  3057. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3058. redis.Set(key, "", time.Second)
  3059. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3060. redis.Set(keyOne, "", time.Second)
  3061. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3062. redis.Set(keySeven, "", time.Second)
  3063. defer redis.Close()
  3064. } else {
  3065. tempPrescription.ID = id
  3066. tempPrescription.Type = types
  3067. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3068. tempPrescription.Mtime = time.Now().Unix()
  3069. tempPrescription.Doctor = role.UserName
  3070. //tempPrescription.OrderStatus = order_status
  3071. tempPrescription.PreTime = pTime
  3072. tempPrescription.MedType = med_type
  3073. tempPrescription.Diagnose = diagnoses
  3074. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3075. redis := service.RedisClient()
  3076. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3077. redis.Set(key, "", time.Second)
  3078. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3079. redis.Set(keyOne, "", time.Second)
  3080. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3081. redis.Set(keySeven, "", time.Second)
  3082. defer redis.Close()
  3083. }
  3084. //service.SaveHisPrescription(prescription)
  3085. //更改患者挂号状态
  3086. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3087. fmt.Println("更改失败", err2)
  3088. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3089. advices := items["advices"].([]interface{})
  3090. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3091. groupNo := int64(0)
  3092. if len(advices) > 0 {
  3093. for _, advice := range advices {
  3094. tx := db.Begin()
  3095. // 在函数结束时处理事务回滚
  3096. defer func() {
  3097. if r := recover(); r != nil {
  3098. tx.Rollback()
  3099. }
  3100. }()
  3101. var s models.HisDoctorAdviceInfo
  3102. s.PrescriptionId = tempPrescription.ID
  3103. s.AdviceType = 2
  3104. s.AdviceDoctor = doctor_id
  3105. s.StopState = 2
  3106. s.ExecutionState = 2
  3107. s.AdviceDate = theTime3.Unix()
  3108. s.Status = 1
  3109. s.UserOrgId = adminInfo.CurrentOrgId
  3110. s.RecordDate = theTime3.Unix()
  3111. s.StartTime = tempPrescription.PreTime
  3112. s.Groupno = groupNo
  3113. s.PatientId = patient_id
  3114. s.HisPatientId = his_patient_id
  3115. s.StartTime = pTime
  3116. s.IsSettle = 2
  3117. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3118. if errcode > 0 {
  3119. c.ServeFailJSONWithSGJErrorCode(errcode)
  3120. return
  3121. }
  3122. s.StartTime = pTime
  3123. var total_count int64 //处方总库存
  3124. //查询改药品信息
  3125. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3126. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3127. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3128. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3129. total_count += prescribingNumberSeven * medical.MinNumber
  3130. }
  3131. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3132. total_count += prescribingNumberSeven
  3133. }
  3134. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3135. total_count += prescribingNumberSeven
  3136. }
  3137. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3138. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3139. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3140. if s.Price != lastWarehouse.RetailPrice {
  3141. s.Price = lastWarehouse.RetailPrice
  3142. }
  3143. if s.Price == 0 {
  3144. if lastWarehouse.ID == 0 {
  3145. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3146. s.Price = lastWarehouseTwo.RetailPrice
  3147. }
  3148. }
  3149. }
  3150. //查询保存处方出库开关是否打开
  3151. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3152. if s.PatientId != 30038 {
  3153. if drugOutConfig.IsOpen == 1 {
  3154. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3155. // 查询该药品最后一次出库记录
  3156. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3157. var is_user_total int64
  3158. var no_user_total int64
  3159. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3160. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3161. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3162. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3163. }
  3164. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3165. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3166. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3167. no_user_total += prescribingNumberSevenTy
  3168. }
  3169. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3170. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3171. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3172. no_user_total += prescribingNumberSevenTy
  3173. }
  3174. if len(druginfo) > 0 {
  3175. for _, it := range druginfo {
  3176. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3177. it.Count = it.Count * drug.MinNumber
  3178. is_user_total += it.Count
  3179. }
  3180. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3181. is_user_total += it.Count
  3182. }
  3183. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3184. is_user_total += it.Count
  3185. }
  3186. }
  3187. }
  3188. //fmt.Println("药品名称----------------------", drug.DrugName)
  3189. //fmt.Println("药品名称----------------------", drug.IsUse)
  3190. //fmt.Println("is_user_total-------------------------", is_user_total)
  3191. //fmt.Println("no_user_total-------------------------", no_user_total)
  3192. if is_user_total != no_user_total {
  3193. //出库
  3194. if drug.IsUse == 2 {
  3195. creater := adminInfo.AdminUser.Id
  3196. newadviceInfo := &models.HisDoctorAdviceInfo{
  3197. ID: s.ID,
  3198. UserOrgId: s.UserOrgId,
  3199. PatientId: s.PatientId,
  3200. HisPatientId: s.HisPatientId,
  3201. AdviceType: s.AdviceType,
  3202. AdviceDate: s.AdviceDate,
  3203. StartTime: s.StartTime,
  3204. AdviceName: s.AdviceName,
  3205. AdviceDesc: s.AdviceDesc,
  3206. ReminderDate: s.ReminderDate,
  3207. SingleDose: s.SingleDose,
  3208. SingleDoseUnit: s.SingleDoseUnit,
  3209. PrescribingNumber: s.PrescribingNumber,
  3210. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3211. DeliveryWay: s.DeliveryWay,
  3212. ExecutionFrequency: s.ExecutionFrequency,
  3213. AdviceDoctor: s.AdviceDoctor,
  3214. Status: s.Status,
  3215. CreatedTime: s.CreatedTime,
  3216. UpdatedTime: s.UpdatedTime,
  3217. AdviceAffirm: s.AdviceAffirm,
  3218. Remark: s.Remark,
  3219. StopTime: s.StopTime,
  3220. StopReason: s.StopReason,
  3221. StopDoctor: s.StopDoctor,
  3222. StopState: s.StopState,
  3223. ParentId: s.ParentId,
  3224. ExecutionTime: s.ExecutionTime,
  3225. ExecutionStaff: s.ExecutionStaff,
  3226. ExecutionState: s.ExecutionState,
  3227. Checker: s.Checker,
  3228. RecordDate: s.RecordDate,
  3229. DialysisOrderId: s.DialysisOrderId,
  3230. CheckTime: s.CheckTime,
  3231. CheckState: s.CheckState,
  3232. DrugSpec: s.DrugSpec,
  3233. DrugSpecUnit: s.DrugSpecUnit,
  3234. Groupno: s.Groupno,
  3235. RemindType: s.RemindType,
  3236. FrequencyType: s.FrequencyType,
  3237. DayCount: s.DayCount,
  3238. WeekDay: s.WeekDay,
  3239. TemplateId: s.TemplateId,
  3240. Modifier: s.Modifier,
  3241. DrugId: s.DrugId,
  3242. Price: s.Price,
  3243. PrescriptionId: s.PrescriptionId,
  3244. MedListCodg: s.MedListCodg,
  3245. FeedetlSn: s.FeedetlSn,
  3246. Day: s.DayCount,
  3247. ChildDoctorAdvice: nil,
  3248. Drug: models.Drug{},
  3249. Diagnosis: s.Diagnosis,
  3250. Way: s.Way,
  3251. HospApprFlag: s.HospApprFlag,
  3252. LmtUsedFlag: s.LmtUsedFlag,
  3253. HisOrderInfo: models.HisOrderInfo{},
  3254. IsMedicine: s.IsMedicine,
  3255. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3256. Child: nil,
  3257. IsSettle: s.IsSettle,
  3258. IsMobile: s.IsMobile,
  3259. IsSelfDrug: s.IsSelfDrug,
  3260. DrugWayCount: s.DrugWayCount,
  3261. }
  3262. var history_count int64
  3263. var local_count int64
  3264. //查找已经开过的医嘱信息
  3265. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3266. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3267. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3268. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3269. local_count += prescribingNumberSevenTy * drug.MinNumber
  3270. }
  3271. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3272. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3273. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3274. local_count += prescribingNumberSevenTy
  3275. }
  3276. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3277. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3278. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3279. local_count += prescribingNumberSevenTy
  3280. }
  3281. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3282. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3283. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3284. history_count += prescribingNumberSevenTy * drug.MinNumber
  3285. }
  3286. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3287. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3288. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3289. history_count += prescribingNumberSevenTy
  3290. }
  3291. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3292. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3293. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3294. history_count += prescribingNumberSevenTy
  3295. }
  3296. //如果当前出库数量大于历史出库数量则需要出库
  3297. if local_count > history_count {
  3298. //按最小单位出库
  3299. var cha_count = local_count - history_count
  3300. newadviceInfo.PrescribingNumber = float64(cha_count)
  3301. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3302. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3303. }
  3304. //如果当前出库数量小于历史出库数量则需要退库
  3305. if local_count < history_count {
  3306. var cha_count = history_count - local_count
  3307. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3308. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3309. }
  3310. if local_count == history_count {
  3311. if is_user_total == 0 {
  3312. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3313. }
  3314. }
  3315. }
  3316. //更新字典里面的库存
  3317. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3318. var sum_count int64
  3319. for _, its := range stockInfo {
  3320. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3321. if its.MaxUnit == baseDrug.MaxUnit {
  3322. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3323. }
  3324. sum_count += its.StockMaxNumber + its.StockMinNumber
  3325. }
  3326. //更新基础库存
  3327. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3328. //剩余库存
  3329. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3330. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3331. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3332. //创建医嘱
  3333. service.CreateHisDoctorAdviceOne(&s, tx)
  3334. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3335. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3336. if len(outInfoTwo) > 0 {
  3337. for _, item := range outInfoTwo {
  3338. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3339. }
  3340. }
  3341. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3342. if len(drugAutoDetail) > 0 {
  3343. for _, item := range drugAutoDetail {
  3344. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3345. }
  3346. }
  3347. }
  3348. }
  3349. }
  3350. //记录日志
  3351. byterequest, _ := json.Marshal(s)
  3352. adviceLog := models.XtDoctorAdviceLog{
  3353. UserOrgId: s.UserOrgId,
  3354. PatientId: s.PatientId,
  3355. AdminUserId: adminInfo.AdminUser.Id,
  3356. Module: 1,
  3357. ErrLog: string(byterequest),
  3358. Status: 1,
  3359. Ctime: time.Now().Unix(),
  3360. Mtime: 0,
  3361. Source: "电脑端新建his医嘱",
  3362. RecordDate: s.AdviceDate,
  3363. }
  3364. service.CreateDoctorAdviceLog(adviceLog)
  3365. //存储切片中
  3366. adviceList = append(adviceList, s)
  3367. redis := service.RedisClient()
  3368. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3369. redis.Set(key, "", time.Second)
  3370. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3371. redis.Set(keyOne, "", time.Second)
  3372. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3373. redis.Set(keySeven, "", time.Second)
  3374. var randNum int
  3375. randNum = rand.Intn(10000) + 1000
  3376. timestamp := time.Now().Unix()
  3377. tempTime := time.Unix(timestamp, 0)
  3378. timeFormat := tempTime.Format("20060102150405")
  3379. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3380. if s.UserOrgId != 10206 {
  3381. if s.ID == 0 {
  3382. //查询改药品是否已经停用
  3383. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3384. if base.ID > 0 {
  3385. tx.Rollback()
  3386. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3387. return
  3388. }
  3389. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3390. if drugMedical.SumCount == 0 {
  3391. tx.Rollback()
  3392. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3393. return
  3394. }
  3395. }
  3396. if s.ID > 0 {
  3397. //查询改药品是否已经停用
  3398. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3399. if base.ID > 0 {
  3400. tx.Rollback()
  3401. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3402. return
  3403. }
  3404. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3405. if drugMedical.SumCount == 0 {
  3406. tx.Rollback()
  3407. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3408. return
  3409. }
  3410. }
  3411. }
  3412. //赤峰
  3413. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3414. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3415. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3416. if info.RetailPrice > 0 {
  3417. if s.DeliveryWay == "口服" {
  3418. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3419. s.Price = drug.RetailPrice
  3420. }
  3421. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3422. s.Price = info.RetailPrice
  3423. }
  3424. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3425. s.Price = info.RetailPrice
  3426. }
  3427. }
  3428. }
  3429. }
  3430. service.CreateHisDoctorAdviceOne(&s, tx)
  3431. tx.Commit()
  3432. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3433. redis.Set(keySix, "", time.Second)
  3434. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3435. redis.Set(keyFive, "", time.Second)
  3436. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3437. redis.Set(keyEight, "", time.Second)
  3438. defer redis.Close()
  3439. }
  3440. }
  3441. }
  3442. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3443. projects := items["project"].([]interface{})
  3444. if len(projects) > 0 {
  3445. for _, project := range projects {
  3446. tx := db.Begin()
  3447. // 在函数结束时处理事务回滚
  3448. defer func() {
  3449. if r := recover(); r != nil {
  3450. tx.Rollback()
  3451. }
  3452. }()
  3453. var p models.HisPrescriptionProject
  3454. p.PrescriptionId = tempPrescription.ID
  3455. p.PatientId = patient_id
  3456. p.RecordDate = theTime3.Unix()
  3457. p.Doctor = doctor_id
  3458. p.UserOrgId = adminInfo.CurrentOrgId
  3459. p.HisPatientId = his_patient_id
  3460. p.Status = 1
  3461. p.StartTime = pTime
  3462. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3463. if errcode > 0 {
  3464. tx.Rollback()
  3465. c.ServeFailJSONWithSGJErrorCode(errcode)
  3466. return
  3467. }
  3468. if p.ID == 0 {
  3469. p.IsOut = 2
  3470. }
  3471. if p.ID > 0 {
  3472. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3473. p.IsOut = projectDetail.IsOut
  3474. }
  3475. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3476. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3477. if p.Type == 3 {
  3478. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3479. if p.Price != lastWarehouse.PackingPrice {
  3480. p.Price = lastWarehouse.PackingPrice
  3481. }
  3482. if p.Price == 0 {
  3483. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3484. p.Price = lastWarehouseTwo.PackingPrice
  3485. }
  3486. if p.Unit == "" {
  3487. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3488. p.Unit = goodInfoOne.PackingUnit
  3489. }
  3490. }
  3491. }
  3492. if adminInfo.CurrentOrgId != 10206 {
  3493. if p.Type == 3 {
  3494. if p.ID == 0 {
  3495. //查询该耗材是否停用
  3496. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3497. //表示该耗材已经停用,不能保存
  3498. if goodInfoSeven.ID == 0 {
  3499. tx.Rollback()
  3500. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3501. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3502. return
  3503. }
  3504. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3505. if goodInfoOne.SumCount == 0 {
  3506. tx.Rollback()
  3507. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3508. return
  3509. }
  3510. }
  3511. if p.ID > 0 {
  3512. //查询该耗材是否停用
  3513. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3514. //表示该耗材已经停用,不能保存
  3515. if goodInfoSeven.ID == 0 {
  3516. tx.Rollback()
  3517. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3518. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3519. return
  3520. }
  3521. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3522. if goodInfoOne.SumCount == 0 {
  3523. tx.Rollback()
  3524. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3525. return
  3526. }
  3527. }
  3528. }
  3529. }
  3530. //查询保存耗材出库开关是否打开
  3531. if p.PatientId != 30038 {
  3532. //用机构ID区分
  3533. if adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10164 {
  3534. if goodOutConfig.IsOpen == 1 {
  3535. //耗材出库
  3536. if p.Type == 3 {
  3537. //对比当前数据和历史出库数据
  3538. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3539. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3540. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3541. //如果当前处方数量大于历史数据,则需要出库
  3542. if nowCount > historyCount {
  3543. var cha_count int64
  3544. cha_count = nowCount - historyCount
  3545. timeStr := time.Now().Format("2006-01-02")
  3546. timeArr := strings.Split(timeStr, "-")
  3547. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3548. total = total + 1
  3549. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3550. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3551. number = number + total
  3552. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3553. operation_time := time.Now().Unix()
  3554. creater := c.GetAdminUserInfo().AdminUser.Id
  3555. recordDateStr := time.Now().Format("2006-01-02")
  3556. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3557. nowtime := recordDate.Unix()
  3558. warehouseOut := models.WarehouseOut{
  3559. WarehouseOutOrderNumber: warehousing_out_order,
  3560. OperationTime: operation_time,
  3561. OrgId: adminInfo.CurrentOrgId,
  3562. Creater: creater,
  3563. Ctime: time.Now().Unix(),
  3564. Status: 1,
  3565. WarehouseOutTime: nowtime,
  3566. Type: 1,
  3567. StorehouseId: storeConfig.StorehouseOutInfo,
  3568. IsCheck: 1,
  3569. IsSys: 1,
  3570. }
  3571. //查询是否生成出库单
  3572. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3573. if out.ID == 0 {
  3574. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3575. }
  3576. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3577. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3578. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3579. dialyPrepareOne := models.DialysisBeforePrepare{
  3580. GoodTypeId: goodObj.GoodTypeId,
  3581. GoodId: p.ProjectId,
  3582. PatientId: p.PatientId,
  3583. RecordDate: p.RecordDate,
  3584. UserOrgId: adminInfo.CurrentOrgId,
  3585. Count: cha_count,
  3586. Ctime: time.Now().Unix(),
  3587. Creater: creater,
  3588. Status: 1,
  3589. StorehouseId: houseConfig.StorehouseOutInfo,
  3590. ProjectId: p.ID,
  3591. }
  3592. //出库
  3593. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3594. }
  3595. //如果当前处方数量小于历史数据,怎需要退库
  3596. if nowCount < historyCount {
  3597. var cha_count int64
  3598. cha_count = historyCount - nowCount
  3599. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3600. creater := c.GetAdminUserInfo().AdminUser.Id
  3601. newPrescriptionProject := &models.HisPrescriptionProject{
  3602. ID: p.ID,
  3603. ProjectId: p.ProjectId,
  3604. Price: p.Price,
  3605. UserOrgId: p.UserOrgId,
  3606. Status: 1,
  3607. Ctime: time.Now().Unix(),
  3608. Mtime: time.Now().Unix(),
  3609. PatientId: p.PatientId,
  3610. HisPatientId: p.HisPatientId,
  3611. RecordDate: p.RecordDate,
  3612. PrescriptionId: p.PrescriptionId,
  3613. Count: p.Count,
  3614. FeedetlSn: p.FeedetlSn,
  3615. MedListCodg: p.MedListCodg,
  3616. SingleDose: p.SingleDose,
  3617. DeliveryWay: p.DeliveryWay,
  3618. ExecutionFrequency: p.ExecutionFrequency,
  3619. Day: p.Day,
  3620. HisProject: models.HisProject{},
  3621. GoodInfo: models.GoodInfo{},
  3622. Remark: p.Remark,
  3623. Unit: p.Unit,
  3624. Type: p.Type,
  3625. Doctor: p.Doctor,
  3626. ExecutionTime: p.ExecutionTime,
  3627. ExecutionStaff: p.ExecutionStaff,
  3628. ExecutionState: p.ExecutionState,
  3629. CheckTime: p.CheckTime,
  3630. CheckState: p.CheckState,
  3631. Checker: p.Checker,
  3632. StartTime: p.StartTime,
  3633. TeamId: p.TeamId,
  3634. XtHisProjectTeam: models.XtHisProjectTeam{},
  3635. FrequencyType: p.FrequencyType,
  3636. DayCount: p.DayCount,
  3637. WeekDay: p.WeekDay,
  3638. IsCheckTeam: p.IsCheckTeam,
  3639. HisOrderInfo: models.HisOrderInfo{},
  3640. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3641. IsOut: p.IsOut,
  3642. YbSyncStatus: p.YbSyncStatus,
  3643. }
  3644. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3645. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3646. }
  3647. if nowCount == historyCount {
  3648. if historyCount == 0 {
  3649. recordDateStr := time.Now().Format("2006-01-02")
  3650. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3651. nowtime := recordDate.Unix()
  3652. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3653. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3654. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3655. creater := c.GetAdminUserInfo().AdminUser.Id
  3656. dialyPrepareOne := models.DialysisBeforePrepare{
  3657. GoodTypeId: goodObj.GoodTypeId,
  3658. GoodId: p.ProjectId,
  3659. PatientId: p.PatientId,
  3660. RecordDate: p.RecordDate,
  3661. UserOrgId: adminInfo.CurrentOrgId,
  3662. Count: nowCount,
  3663. Ctime: time.Now().Unix(),
  3664. Creater: creater,
  3665. Status: 1,
  3666. StorehouseId: houseConfig.StorehouseOutInfo,
  3667. ProjectId: p.ID,
  3668. }
  3669. //出库
  3670. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3671. }
  3672. }
  3673. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3674. //查询历史出库数据
  3675. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3676. var out_count_five int64
  3677. for _, item := range flowGood {
  3678. out_count_five += item.Count
  3679. }
  3680. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3681. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3682. if out_count_five != parseIntCount {
  3683. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3684. detail := models.AutomaticReduceDetail{
  3685. WarehouseOutId: 0,
  3686. WarehouseOutOrderNumber: "",
  3687. PatientId: p.PatientId,
  3688. Ctime: time.Now().Unix(),
  3689. Mtime: 0,
  3690. Status: 1,
  3691. RecordTime: p.RecordDate,
  3692. OrgId: p.UserOrgId,
  3693. GoodId: p.ProjectId,
  3694. GoodTypeId: 0,
  3695. Count: parseIntCount,
  3696. Type: 0,
  3697. ProjectId: lastHisProject.ID,
  3698. StorehouseId: 0,
  3699. }
  3700. service.CreateNewAutoDetail(detail, tx)
  3701. }
  3702. // //查询耗材最后一次出库记录
  3703. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3704. // //查询默认出库仓库库存
  3705. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3706. // if len(wareOut) > 0 {
  3707. //
  3708. // for _, it := range wareOut {
  3709. // //回退库存
  3710. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3711. //
  3712. // //删除出库记录
  3713. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3714. //
  3715. // }
  3716. // }
  3717. //
  3718. // timeStr := time.Now().Format("2006-01-02")
  3719. // timeArr := strings.Split(timeStr, "-")
  3720. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3721. //
  3722. // total = total + 1
  3723. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3724. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3725. // number = number + total
  3726. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3727. //
  3728. // operation_time := time.Now().Unix()
  3729. // creater := c.GetAdminUserInfo().AdminUser.Id
  3730. //
  3731. // recordDateStr := time.Now().Format("2006-01-02")
  3732. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3733. // nowtime := recordDate.Unix()
  3734. // warehouseOut := models.WarehouseOut{
  3735. // WarehouseOutOrderNumber: warehousing_out_order,
  3736. // OperationTime: operation_time,
  3737. // OrgId: adminInfo.CurrentOrgId,
  3738. // Creater: creater,
  3739. // Ctime: time.Now().Unix(),
  3740. // Status: 1,
  3741. // WarehouseOutTime: nowtime,
  3742. // Type: 1,
  3743. // StorehouseId: storeConfig.StorehouseOutInfo,
  3744. // IsCheck: 1,
  3745. // IsSys: 1,
  3746. // }
  3747. // //查询是否生成出库单
  3748. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3749. // if out.ID == 0 {
  3750. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3751. // }
  3752. //
  3753. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3754. //
  3755. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3756. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3757. //
  3758. // dialyPrepareOne := models.DialysisBeforePrepare{
  3759. // GoodTypeId: goodObj.GoodTypeId,
  3760. // GoodId: p.ProjectId,
  3761. // PatientId: p.PatientId,
  3762. // RecordDate: p.RecordDate,
  3763. // UserOrgId: adminInfo.CurrentOrgId,
  3764. // Count: parseIntCount,
  3765. // Ctime: time.Now().Unix(),
  3766. // Creater: creater,
  3767. // Status: 1,
  3768. // StorehouseId: houseConfig.StorehouseOutInfo,
  3769. // ProjectId: lastHisProject.ID,
  3770. // }
  3771. // //判断是否是零用耗材(非零用)
  3772. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3773. //
  3774. // //查询历史出库数据
  3775. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3776. // var out_count int64
  3777. // for _, item := range flowGood {
  3778. // out_count += item.Count
  3779. // }
  3780. // //如果历史数和当前数据不想等才进行退库出库
  3781. // if out_count != parseIntCount {
  3782. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3783. //
  3784. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3785. // detail := models.AutomaticReduceDetail{
  3786. // WarehouseOutId: 0,
  3787. // WarehouseOutOrderNumber: "",
  3788. // PatientId: p.PatientId,
  3789. // Ctime: time.Now().Unix(),
  3790. // Mtime: 0,
  3791. // Status: 1,
  3792. // RecordTime: p.RecordDate,
  3793. // OrgId: p.UserOrgId,
  3794. // GoodId: p.ProjectId,
  3795. // GoodTypeId: 0,
  3796. // Count: parseIntCount,
  3797. // Type: 0,
  3798. // ProjectId: lastHisProject.ID,
  3799. // StorehouseId: 0,
  3800. // }
  3801. //
  3802. // service.CreateNewAutoDetail(detail, tx)
  3803. //
  3804. // //查询剩余库存
  3805. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3806. // var sum_count int64
  3807. // for _, item := range goodList {
  3808. // sum_count += item.StockCount
  3809. // }
  3810. //
  3811. // //更新剩余库存
  3812. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3813. //
  3814. // //耗材
  3815. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3816. //
  3817. // }
  3818. // //判断是否是零用耗材(零用但是是出库耗材)
  3819. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3820. //
  3821. // //查询历史出库数据
  3822. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3823. // var out_count int64
  3824. // for _, item := range flowGood {
  3825. // out_count += item.Count
  3826. // }
  3827. // //如果历史数和当前数据不想等才进行退库出库
  3828. // if out_count != parseIntCount {
  3829. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3830. //
  3831. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3832. // detail := models.AutomaticReduceDetail{
  3833. // WarehouseOutId: 0,
  3834. // WarehouseOutOrderNumber: "",
  3835. // PatientId: p.PatientId,
  3836. // Ctime: time.Now().Unix(),
  3837. // Mtime: 0,
  3838. // Status: 1,
  3839. // RecordTime: p.RecordDate,
  3840. // OrgId: p.UserOrgId,
  3841. // GoodId: p.ProjectId,
  3842. // GoodTypeId: 0,
  3843. // Count: parseIntCount,
  3844. // Type: 0,
  3845. // ProjectId: p.ID,
  3846. // StorehouseId: 0,
  3847. // }
  3848. //
  3849. // service.CreateNewAutoDetail(detail, tx)
  3850. //
  3851. // //查询剩余库存
  3852. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3853. // var sum_count int64
  3854. // for _, item := range goodList {
  3855. // sum_count += item.StockCount
  3856. // }
  3857. //
  3858. // //更新剩余库存
  3859. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3860. //
  3861. // //耗材
  3862. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3863. // }
  3864. //
  3865. // }
  3866. //
  3867. // }
  3868. //
  3869. //}
  3870. //记录日志
  3871. byterequest, _ := json.Marshal(p)
  3872. adviceLog := models.XtDoctorAdviceLog{
  3873. UserOrgId: p.UserOrgId,
  3874. PatientId: p.PatientId,
  3875. AdminUserId: adminInfo.AdminUser.Id,
  3876. Module: 1,
  3877. ErrLog: string(byterequest),
  3878. Status: 1,
  3879. Ctime: time.Now().Unix(),
  3880. Mtime: 0,
  3881. Source: "电脑端新建his项目",
  3882. RecordDate: p.RecordDate,
  3883. }
  3884. service.CreateDoctorAdviceLog(adviceLog)
  3885. projectList = append(projectList, p)
  3886. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3887. //新增或者编辑项目,修改对应的标签数据
  3888. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3889. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3890. var label models.HisLabelPrintInfo
  3891. project, _ := service.GetProjectDetail(p.ProjectId)
  3892. if project.CostClassify == 3 { //类别为检验检查
  3893. if p.TeamId > 0 { //检验检查组套
  3894. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3895. if tempLabel.ID == 0 {
  3896. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3897. label.Number = tempPrescription.PrescriptionNumber
  3898. label.ProjectId = project.ID
  3899. label.Status = 1
  3900. label.IsPrint = 2
  3901. label.DoctorId = info.DoctorId
  3902. label.UserOrgId = p.UserOrgId
  3903. label.PatientId = patient_id
  3904. label.RecordDate = recordDateTime
  3905. label.Ctime = time.Now().Unix()
  3906. label.Mtime = time.Now().Unix()
  3907. label.ItemId = p.TeamId
  3908. label.FeedetlSn = p.FeedetlSn
  3909. label.PProjectId = p.ID
  3910. label.ProjectName = team.ProjectTeam
  3911. label.PatientName = patient.Name
  3912. service.CreateNewHisLabelRecord(&label, tx)
  3913. }
  3914. } else { //单条检验检查项目
  3915. label.Number = tempPrescription.PrescriptionNumber
  3916. label.ProjectId = project.ID
  3917. label.Status = 1
  3918. label.DoctorId = info.DoctorId
  3919. label.UserOrgId = p.UserOrgId
  3920. label.PatientId = patient_id
  3921. label.RecordDate = recordDateTime
  3922. label.IsPrint = 2
  3923. label.Ctime = time.Now().Unix()
  3924. label.Mtime = time.Now().Unix()
  3925. label.FeedetlSn = p.FeedetlSn
  3926. label.PProjectId = p.ID
  3927. label.ItemId = p.TeamId
  3928. label.ProjectName = project.ProjectName
  3929. label.PatientName = patient.Name
  3930. service.CreateNewHisLabelRecord(&label, tx)
  3931. }
  3932. }
  3933. }
  3934. }
  3935. }
  3936. }
  3937. }
  3938. if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  3939. //耗材出库
  3940. if p.Type == 3 {
  3941. //对比当前数据和历史出库数据
  3942. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3943. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3944. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3945. //如果当前处方数量大于历史数据,则需要出库
  3946. if nowCount > historyCount {
  3947. var cha_count int64
  3948. cha_count = nowCount - historyCount
  3949. timeStr := time.Now().Format("2006-01-02")
  3950. timeArr := strings.Split(timeStr, "-")
  3951. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3952. total = total + 1
  3953. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3954. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3955. number = number + total
  3956. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3957. operation_time := time.Now().Unix()
  3958. creater := c.GetAdminUserInfo().AdminUser.Id
  3959. recordDateStr := time.Now().Format("2006-01-02")
  3960. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3961. nowtime := recordDate.Unix()
  3962. warehouseOut := models.WarehouseOut{
  3963. WarehouseOutOrderNumber: warehousing_out_order,
  3964. OperationTime: operation_time,
  3965. OrgId: adminInfo.CurrentOrgId,
  3966. Creater: creater,
  3967. Ctime: time.Now().Unix(),
  3968. Status: 1,
  3969. WarehouseOutTime: nowtime,
  3970. Type: 1,
  3971. StorehouseId: storeConfig.StorehouseOutInfo,
  3972. IsCheck: 1,
  3973. IsSys: 1,
  3974. }
  3975. //查询是否生成出库单
  3976. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3977. if out.ID == 0 {
  3978. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3979. }
  3980. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3981. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3982. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3983. dialyPrepareOne := models.DialysisBeforePrepare{
  3984. GoodTypeId: goodObj.GoodTypeId,
  3985. GoodId: p.ProjectId,
  3986. PatientId: p.PatientId,
  3987. RecordDate: p.RecordDate,
  3988. UserOrgId: adminInfo.CurrentOrgId,
  3989. Count: cha_count,
  3990. Ctime: time.Now().Unix(),
  3991. Creater: creater,
  3992. Status: 1,
  3993. StorehouseId: houseConfig.StorehouseOutInfo,
  3994. ProjectId: p.ID,
  3995. }
  3996. //出库
  3997. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3998. }
  3999. //如果当前处方数量小于历史数据,怎需要退库
  4000. if nowCount < historyCount {
  4001. var cha_count int64
  4002. cha_count = historyCount - nowCount
  4003. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4004. creater := c.GetAdminUserInfo().AdminUser.Id
  4005. newPrescriptionProject := &models.HisPrescriptionProject{
  4006. ID: p.ID,
  4007. ProjectId: p.ProjectId,
  4008. Price: p.Price,
  4009. UserOrgId: p.UserOrgId,
  4010. Status: 1,
  4011. Ctime: time.Now().Unix(),
  4012. Mtime: time.Now().Unix(),
  4013. PatientId: p.PatientId,
  4014. HisPatientId: p.HisPatientId,
  4015. RecordDate: p.RecordDate,
  4016. PrescriptionId: p.PrescriptionId,
  4017. Count: p.Count,
  4018. FeedetlSn: p.FeedetlSn,
  4019. MedListCodg: p.MedListCodg,
  4020. SingleDose: p.SingleDose,
  4021. DeliveryWay: p.DeliveryWay,
  4022. ExecutionFrequency: p.ExecutionFrequency,
  4023. Day: p.Day,
  4024. HisProject: models.HisProject{},
  4025. GoodInfo: models.GoodInfo{},
  4026. Remark: p.Remark,
  4027. Unit: p.Unit,
  4028. Type: p.Type,
  4029. Doctor: p.Doctor,
  4030. ExecutionTime: p.ExecutionTime,
  4031. ExecutionStaff: p.ExecutionStaff,
  4032. ExecutionState: p.ExecutionState,
  4033. CheckTime: p.CheckTime,
  4034. CheckState: p.CheckState,
  4035. Checker: p.Checker,
  4036. StartTime: p.StartTime,
  4037. TeamId: p.TeamId,
  4038. XtHisProjectTeam: models.XtHisProjectTeam{},
  4039. FrequencyType: p.FrequencyType,
  4040. DayCount: p.DayCount,
  4041. WeekDay: p.WeekDay,
  4042. IsCheckTeam: p.IsCheckTeam,
  4043. HisOrderInfo: models.HisOrderInfo{},
  4044. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4045. IsOut: p.IsOut,
  4046. YbSyncStatus: p.YbSyncStatus,
  4047. }
  4048. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4049. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4050. }
  4051. if nowCount == historyCount {
  4052. if historyCount == 0 {
  4053. recordDateStr := time.Now().Format("2006-01-02")
  4054. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4055. nowtime := recordDate.Unix()
  4056. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4057. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4058. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4059. creater := c.GetAdminUserInfo().AdminUser.Id
  4060. dialyPrepareOne := models.DialysisBeforePrepare{
  4061. GoodTypeId: goodObj.GoodTypeId,
  4062. GoodId: p.ProjectId,
  4063. PatientId: p.PatientId,
  4064. RecordDate: p.RecordDate,
  4065. UserOrgId: adminInfo.CurrentOrgId,
  4066. Count: nowCount,
  4067. Ctime: time.Now().Unix(),
  4068. Creater: creater,
  4069. Status: 1,
  4070. StorehouseId: houseConfig.StorehouseOutInfo,
  4071. ProjectId: p.ID,
  4072. }
  4073. //出库
  4074. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4075. }
  4076. }
  4077. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4078. //查询历史出库数据
  4079. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4080. var out_count_five int64
  4081. for _, item := range flowGood {
  4082. out_count_five += item.Count
  4083. }
  4084. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4085. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4086. if out_count_five != parseIntCount {
  4087. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4088. detail := models.AutomaticReduceDetail{
  4089. WarehouseOutId: 0,
  4090. WarehouseOutOrderNumber: "",
  4091. PatientId: p.PatientId,
  4092. Ctime: time.Now().Unix(),
  4093. Mtime: 0,
  4094. Status: 1,
  4095. RecordTime: p.RecordDate,
  4096. OrgId: p.UserOrgId,
  4097. GoodId: p.ProjectId,
  4098. GoodTypeId: 0,
  4099. Count: parseIntCount,
  4100. Type: 0,
  4101. ProjectId: lastHisProject.ID,
  4102. StorehouseId: 0,
  4103. }
  4104. service.CreateNewAutoDetail(detail, tx)
  4105. }
  4106. // //查询耗材最后一次出库记录
  4107. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4108. // //查询默认出库仓库库存
  4109. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4110. // if len(wareOut) > 0 {
  4111. //
  4112. // for _, it := range wareOut {
  4113. // //回退库存
  4114. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4115. //
  4116. // //删除出库记录
  4117. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4118. //
  4119. // }
  4120. // }
  4121. //
  4122. // timeStr := time.Now().Format("2006-01-02")
  4123. // timeArr := strings.Split(timeStr, "-")
  4124. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4125. //
  4126. // total = total + 1
  4127. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4128. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4129. // number = number + total
  4130. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4131. //
  4132. // operation_time := time.Now().Unix()
  4133. // creater := c.GetAdminUserInfo().AdminUser.Id
  4134. //
  4135. // recordDateStr := time.Now().Format("2006-01-02")
  4136. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4137. // nowtime := recordDate.Unix()
  4138. // warehouseOut := models.WarehouseOut{
  4139. // WarehouseOutOrderNumber: warehousing_out_order,
  4140. // OperationTime: operation_time,
  4141. // OrgId: adminInfo.CurrentOrgId,
  4142. // Creater: creater,
  4143. // Ctime: time.Now().Unix(),
  4144. // Status: 1,
  4145. // WarehouseOutTime: nowtime,
  4146. // Type: 1,
  4147. // StorehouseId: storeConfig.StorehouseOutInfo,
  4148. // IsCheck: 1,
  4149. // IsSys: 1,
  4150. // }
  4151. // //查询是否生成出库单
  4152. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4153. // if out.ID == 0 {
  4154. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4155. // }
  4156. //
  4157. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4158. //
  4159. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4160. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4161. //
  4162. // dialyPrepareOne := models.DialysisBeforePrepare{
  4163. // GoodTypeId: goodObj.GoodTypeId,
  4164. // GoodId: p.ProjectId,
  4165. // PatientId: p.PatientId,
  4166. // RecordDate: p.RecordDate,
  4167. // UserOrgId: adminInfo.CurrentOrgId,
  4168. // Count: parseIntCount,
  4169. // Ctime: time.Now().Unix(),
  4170. // Creater: creater,
  4171. // Status: 1,
  4172. // StorehouseId: houseConfig.StorehouseOutInfo,
  4173. // ProjectId: lastHisProject.ID,
  4174. // }
  4175. // //判断是否是零用耗材(非零用)
  4176. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4177. //
  4178. // //查询历史出库数据
  4179. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4180. // var out_count int64
  4181. // for _, item := range flowGood {
  4182. // out_count += item.Count
  4183. // }
  4184. // //如果历史数和当前数据不想等才进行退库出库
  4185. // if out_count != parseIntCount {
  4186. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4187. //
  4188. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4189. // detail := models.AutomaticReduceDetail{
  4190. // WarehouseOutId: 0,
  4191. // WarehouseOutOrderNumber: "",
  4192. // PatientId: p.PatientId,
  4193. // Ctime: time.Now().Unix(),
  4194. // Mtime: 0,
  4195. // Status: 1,
  4196. // RecordTime: p.RecordDate,
  4197. // OrgId: p.UserOrgId,
  4198. // GoodId: p.ProjectId,
  4199. // GoodTypeId: 0,
  4200. // Count: parseIntCount,
  4201. // Type: 0,
  4202. // ProjectId: lastHisProject.ID,
  4203. // StorehouseId: 0,
  4204. // }
  4205. //
  4206. // service.CreateNewAutoDetail(detail, tx)
  4207. //
  4208. // //查询剩余库存
  4209. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4210. // var sum_count int64
  4211. // for _, item := range goodList {
  4212. // sum_count += item.StockCount
  4213. // }
  4214. //
  4215. // //更新剩余库存
  4216. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4217. //
  4218. // //耗材
  4219. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4220. //
  4221. // }
  4222. // //判断是否是零用耗材(零用但是是出库耗材)
  4223. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4224. //
  4225. // //查询历史出库数据
  4226. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4227. // var out_count int64
  4228. // for _, item := range flowGood {
  4229. // out_count += item.Count
  4230. // }
  4231. // //如果历史数和当前数据不想等才进行退库出库
  4232. // if out_count != parseIntCount {
  4233. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4234. //
  4235. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4236. // detail := models.AutomaticReduceDetail{
  4237. // WarehouseOutId: 0,
  4238. // WarehouseOutOrderNumber: "",
  4239. // PatientId: p.PatientId,
  4240. // Ctime: time.Now().Unix(),
  4241. // Mtime: 0,
  4242. // Status: 1,
  4243. // RecordTime: p.RecordDate,
  4244. // OrgId: p.UserOrgId,
  4245. // GoodId: p.ProjectId,
  4246. // GoodTypeId: 0,
  4247. // Count: parseIntCount,
  4248. // Type: 0,
  4249. // ProjectId: p.ID,
  4250. // StorehouseId: 0,
  4251. // }
  4252. //
  4253. // service.CreateNewAutoDetail(detail, tx)
  4254. //
  4255. // //查询剩余库存
  4256. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4257. // var sum_count int64
  4258. // for _, item := range goodList {
  4259. // sum_count += item.StockCount
  4260. // }
  4261. //
  4262. // //更新剩余库存
  4263. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4264. //
  4265. // //耗材
  4266. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4267. // }
  4268. //
  4269. // }
  4270. //
  4271. // }
  4272. //
  4273. //}
  4274. //记录日志
  4275. byterequest, _ := json.Marshal(p)
  4276. adviceLog := models.XtDoctorAdviceLog{
  4277. UserOrgId: p.UserOrgId,
  4278. PatientId: p.PatientId,
  4279. AdminUserId: adminInfo.AdminUser.Id,
  4280. Module: 1,
  4281. ErrLog: string(byterequest),
  4282. Status: 1,
  4283. Ctime: time.Now().Unix(),
  4284. Mtime: 0,
  4285. Source: "电脑端新建his项目",
  4286. RecordDate: p.RecordDate,
  4287. }
  4288. service.CreateDoctorAdviceLog(adviceLog)
  4289. projectList = append(projectList, p)
  4290. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4291. //新增或者编辑项目,修改对应的标签数据
  4292. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4293. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4294. var label models.HisLabelPrintInfo
  4295. project, _ := service.GetProjectDetail(p.ProjectId)
  4296. if project.CostClassify == 3 { //类别为检验检查
  4297. if p.TeamId > 0 { //检验检查组套
  4298. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4299. if tempLabel.ID == 0 {
  4300. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4301. label.Number = tempPrescription.PrescriptionNumber
  4302. label.ProjectId = project.ID
  4303. label.Status = 1
  4304. label.IsPrint = 2
  4305. label.DoctorId = info.DoctorId
  4306. label.UserOrgId = p.UserOrgId
  4307. label.PatientId = patient_id
  4308. label.RecordDate = recordDateTime
  4309. label.Ctime = time.Now().Unix()
  4310. label.Mtime = time.Now().Unix()
  4311. label.ItemId = p.TeamId
  4312. label.FeedetlSn = p.FeedetlSn
  4313. label.PProjectId = p.ID
  4314. label.ProjectName = team.ProjectTeam
  4315. label.PatientName = patient.Name
  4316. service.CreateNewHisLabelRecord(&label, tx)
  4317. }
  4318. } else { //单条检验检查项目
  4319. label.Number = tempPrescription.PrescriptionNumber
  4320. label.ProjectId = project.ID
  4321. label.Status = 1
  4322. label.DoctorId = info.DoctorId
  4323. label.UserOrgId = p.UserOrgId
  4324. label.PatientId = patient_id
  4325. label.RecordDate = recordDateTime
  4326. label.IsPrint = 2
  4327. label.Ctime = time.Now().Unix()
  4328. label.Mtime = time.Now().Unix()
  4329. label.FeedetlSn = p.FeedetlSn
  4330. label.PProjectId = p.ID
  4331. label.ItemId = p.TeamId
  4332. label.ProjectName = project.ProjectName
  4333. label.PatientName = patient.Name
  4334. service.CreateNewHisLabelRecord(&label, tx)
  4335. }
  4336. }
  4337. }
  4338. }
  4339. }
  4340. }
  4341. }
  4342. //插入检验数据
  4343. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4344. //新增或者编辑项目,修改对应的标签数据
  4345. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4346. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4347. var label models.HisLabelPrintInfo
  4348. project, _ := service.GetProjectDetail(p.ProjectId)
  4349. if project.CostClassify == 3 { //类别为检验检查
  4350. if p.TeamId > 0 { //检验检查组套
  4351. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4352. if tempLabel.ID == 0 {
  4353. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4354. label.Number = tempPrescription.PrescriptionNumber
  4355. label.ProjectId = project.ID
  4356. label.Status = 1
  4357. label.IsPrint = 2
  4358. label.DoctorId = info.DoctorId
  4359. label.UserOrgId = p.UserOrgId
  4360. label.PatientId = patient_id
  4361. label.RecordDate = recordDateTime
  4362. label.Ctime = time.Now().Unix()
  4363. label.Mtime = time.Now().Unix()
  4364. label.ItemId = p.TeamId
  4365. label.FeedetlSn = p.FeedetlSn
  4366. label.PProjectId = p.ID
  4367. label.ProjectName = team.ProjectTeam
  4368. label.PatientName = patient.Name
  4369. service.CreateHisLabelRecord(&label)
  4370. }
  4371. } else { //单条检验检查项目
  4372. label.Number = tempPrescription.PrescriptionNumber
  4373. label.ProjectId = project.ID
  4374. label.Status = 1
  4375. label.DoctorId = info.DoctorId
  4376. label.UserOrgId = p.UserOrgId
  4377. label.PatientId = patient_id
  4378. label.RecordDate = recordDateTime
  4379. label.IsPrint = 2
  4380. label.Ctime = time.Now().Unix()
  4381. label.Mtime = time.Now().Unix()
  4382. label.FeedetlSn = p.FeedetlSn
  4383. label.PProjectId = p.ID
  4384. label.ItemId = p.TeamId
  4385. label.ProjectName = project.ProjectName
  4386. label.PatientName = patient.Name
  4387. service.CreateHisLabelRecord(&label)
  4388. }
  4389. }
  4390. }
  4391. }
  4392. service.CreateNewHisProjectTwo(&p, tx)
  4393. var randNum int
  4394. randNum = rand.Intn(10000) + 1000
  4395. timestamp := time.Now().Unix()
  4396. tempTime := time.Unix(timestamp, 0)
  4397. timeFormat := tempTime.Format("20060102150405")
  4398. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4399. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4400. if goodBase.ID > 0 {
  4401. tx.Rollback()
  4402. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4403. return
  4404. }
  4405. service.CreateNewHisProjectTwo(&p, tx)
  4406. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4407. //查询剩余库存
  4408. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4409. var sum_count int64
  4410. for _, item := range goodList {
  4411. sum_count += item.StockCount
  4412. }
  4413. //更新剩余库存
  4414. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4415. //耗材
  4416. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4417. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4418. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4419. if len(outInfoTwo) > 0 {
  4420. for _, item := range outInfoTwo {
  4421. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4422. }
  4423. }
  4424. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4425. if len(drugAutoDetail) > 0 {
  4426. for _, item := range drugAutoDetail {
  4427. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4428. }
  4429. }
  4430. tx.Commit()
  4431. }
  4432. }
  4433. }
  4434. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4435. // addition := items["addition"].([]interface{})
  4436. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4437. // ctime := time.Now().Unix()
  4438. // mtime := ctime
  4439. // if len(addition) > 0 {
  4440. // for _, item := range addition {
  4441. // var s models.HisAdditionalCharge
  4442. // s.PrescriptionId = tempPrescription.ID
  4443. // s.Status = 1
  4444. // s.UserOrgId = adminInfo.CurrentOrgId
  4445. // s.RecordDate = recordDateTime
  4446. // s.CreatedTime = ctime
  4447. // s.UpdatedTime = mtime
  4448. // s.PatientId = patient_id
  4449. // s.HisPatientId = his_patient_id
  4450. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4451. // if errcode > 0 {
  4452. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4453. // return
  4454. // }
  4455. // service.CreateAdditionalCharge(&s)
  4456. // var randNum int
  4457. // randNum = rand.Intn(10000) + 1000
  4458. // timestamp := time.Now().Unix()
  4459. // tempTime := time.Unix(timestamp, 0)
  4460. // timeFormat := tempTime.Format("20060102150405")
  4461. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4462. // service.CreateAdditionalCharge(&s)
  4463. //
  4464. // }
  4465. // }
  4466. //}
  4467. }
  4468. }
  4469. }
  4470. tx.Commit()
  4471. if err == nil {
  4472. c.ServeSuccessJSON(map[string]interface{}{
  4473. "msg": "保存成功",
  4474. })
  4475. return
  4476. } else {
  4477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4478. return
  4479. }
  4480. } else {
  4481. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4482. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4483. var tempPrescription *models.HisPrescription
  4484. if len(prescriptions) > 0 {
  4485. for _, item := range prescriptions {
  4486. items := item.(map[string]interface{})
  4487. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4488. utils.ErrorLog("id")
  4489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4490. return
  4491. }
  4492. id := int64(items["id"].(float64))
  4493. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4494. tempPrescription = &new_prescription
  4495. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4496. utils.ErrorLog("type")
  4497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4498. return
  4499. }
  4500. types := int64(items["type"].(float64))
  4501. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4502. utils.ErrorLog("med_type")
  4503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4504. return
  4505. }
  4506. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4507. if med_type == "0" {
  4508. med_type = "14"
  4509. }
  4510. //if order_status == 0 {
  4511. // order_status = 1
  4512. //}
  4513. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4514. // utils.ErrorLog("diagnoses")
  4515. //}
  4516. diagnoses, _ := items["diagnoses"].(string)
  4517. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4518. utils.ErrorLog("pre_time")
  4519. }
  4520. preTime, _ := items["pre_time"].(string)
  4521. timeLayout := "2006-01-02"
  4522. loc, _ := time.LoadLocation("Local")
  4523. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4524. //result := strings.Split(preTime, " ")
  4525. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4526. if err != nil {
  4527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4528. return
  4529. }
  4530. pTime := theTime2.Unix()
  4531. ctime := time.Now().Unix()
  4532. if tempPrescription.ID == 0 {
  4533. prescription := &models.HisPrescription{
  4534. ID: 0,
  4535. PatientId: patient_id,
  4536. UserOrgId: adminInfo.CurrentOrgId,
  4537. RecordDate: recordDateTime,
  4538. Ctime: ctime,
  4539. Mtime: ctime,
  4540. Type: types,
  4541. Modifier: adminInfo.AdminUser.Id,
  4542. Creator: adminInfo.AdminUser.Id,
  4543. Status: 1,
  4544. Doctor: role.UserName,
  4545. HisPatientId: his_patient_id,
  4546. OrderStatus: 1,
  4547. BatchNumber: "",
  4548. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4549. PreTime: pTime,
  4550. PType: p_type,
  4551. MedType: med_type,
  4552. Diagnose: diagnoses,
  4553. }
  4554. tempPrescription = prescription
  4555. service.SaveHisPrescription(tempPrescription)
  4556. redis := service.RedisClient()
  4557. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4558. redis.Set(key, "", time.Second)
  4559. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4560. redis.Set(keyOne, "", time.Second)
  4561. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4562. redis.Set(keySeven, "", time.Second)
  4563. defer redis.Close()
  4564. } else {
  4565. tempPrescription.ID = id
  4566. tempPrescription.Type = types
  4567. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4568. tempPrescription.Mtime = time.Now().Unix()
  4569. tempPrescription.Doctor = role.UserName
  4570. //tempPrescription.OrderStatus = order_status
  4571. tempPrescription.PreTime = pTime
  4572. tempPrescription.MedType = med_type
  4573. tempPrescription.Diagnose = diagnoses
  4574. service.SaveHisPrescription(tempPrescription)
  4575. redis := service.RedisClient()
  4576. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4577. redis.Set(key, "", time.Second)
  4578. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4579. redis.Set(keyOne, "", time.Second)
  4580. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4581. redis.Set(keySeven, "", time.Second)
  4582. defer redis.Close()
  4583. }
  4584. //service.SaveHisPrescription(prescription)
  4585. //更改患者挂号状态
  4586. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4587. fmt.Println("更改失败", err2)
  4588. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4589. advices := items["advices"].([]interface{})
  4590. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4591. groupNo := int64(0)
  4592. if len(advices) > 0 {
  4593. for _, advice := range advices {
  4594. var s models.HisDoctorAdviceInfo
  4595. s.PrescriptionId = tempPrescription.ID
  4596. s.AdviceType = 2
  4597. s.AdviceDoctor = doctor_id
  4598. s.StopState = 2
  4599. s.ExecutionState = 2
  4600. s.AdviceDate = theTime3.Unix()
  4601. s.Status = 1
  4602. s.UserOrgId = adminInfo.CurrentOrgId
  4603. s.RecordDate = theTime3.Unix()
  4604. s.StartTime = tempPrescription.PreTime
  4605. s.Groupno = groupNo
  4606. s.PatientId = patient_id
  4607. s.HisPatientId = his_patient_id
  4608. s.StartTime = pTime
  4609. s.IsSettle = 2
  4610. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4611. if errcode > 0 {
  4612. c.ServeFailJSONWithSGJErrorCode(errcode)
  4613. return
  4614. }
  4615. s.StartTime = pTime
  4616. var total_count int64 //处方总库存
  4617. //查询改药品信息
  4618. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  4619. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  4620. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4621. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4622. total_count += prescribingNumberSeven * medical.MinNumber
  4623. }
  4624. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4625. total_count += prescribingNumberSeven
  4626. }
  4627. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4628. total_count += prescribingNumberSeven
  4629. }
  4630. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4631. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4632. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4633. if s.Price != lastWarehouse.RetailPrice {
  4634. s.Price = lastWarehouse.RetailPrice
  4635. }
  4636. if s.Price == 0 {
  4637. if lastWarehouse.ID == 0 {
  4638. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4639. s.Price = lastWarehouseTwo.RetailPrice
  4640. }
  4641. }
  4642. }
  4643. if adminInfo.CurrentOrgId != 10206 {
  4644. if s.ID == 0 {
  4645. //查询改药品是否已经停用
  4646. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4647. if base.ID > 0 {
  4648. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4649. return
  4650. }
  4651. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4652. if drugMedical.SumCount == 0 {
  4653. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4654. return
  4655. }
  4656. }
  4657. }
  4658. //赤峰
  4659. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4660. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4661. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4662. if info.RetailPrice > 0 {
  4663. if s.DeliveryWay == "口服" {
  4664. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4665. s.Price = drug.RetailPrice
  4666. }
  4667. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4668. s.Price = info.RetailPrice
  4669. }
  4670. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4671. s.Price = info.RetailPrice
  4672. }
  4673. }
  4674. }
  4675. }
  4676. service.CreateHisDoctorAdvice(&s)
  4677. //记录日志
  4678. byterequest, _ := json.Marshal(s)
  4679. adviceLog := models.XtDoctorAdviceLog{
  4680. UserOrgId: s.UserOrgId,
  4681. PatientId: s.PatientId,
  4682. AdminUserId: adminInfo.AdminUser.Id,
  4683. Module: 1,
  4684. ErrLog: string(byterequest),
  4685. Status: 1,
  4686. Ctime: time.Now().Unix(),
  4687. Mtime: 0,
  4688. Source: "电脑端新建his医嘱",
  4689. RecordDate: s.AdviceDate,
  4690. }
  4691. service.CreateDoctorAdviceLog(adviceLog)
  4692. //存储切片中
  4693. adviceList = append(adviceList, s)
  4694. redis := service.RedisClient()
  4695. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4696. redis.Set(key, "", time.Second)
  4697. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4698. redis.Set(keyOne, "", time.Second)
  4699. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4700. redis.Set(keySeven, "", time.Second)
  4701. var randNum int
  4702. randNum = rand.Intn(10000) + 1000
  4703. timestamp := time.Now().Unix()
  4704. tempTime := time.Unix(timestamp, 0)
  4705. timeFormat := tempTime.Format("20060102150405")
  4706. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4707. service.CreateHisDoctorAdvice(&s)
  4708. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4709. redis.Set(keySix, "", time.Second)
  4710. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4711. redis.Set(keyFive, "", time.Second)
  4712. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4713. redis.Set(keyEight, "", time.Second)
  4714. defer redis.Close()
  4715. }
  4716. }
  4717. }
  4718. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4719. projects := items["project"].([]interface{})
  4720. if len(projects) > 0 {
  4721. for _, project := range projects {
  4722. var p models.HisPrescriptionProject
  4723. p.PrescriptionId = tempPrescription.ID
  4724. p.PatientId = patient_id
  4725. p.RecordDate = theTime3.Unix()
  4726. p.Doctor = doctor_id
  4727. p.UserOrgId = adminInfo.CurrentOrgId
  4728. p.HisPatientId = his_patient_id
  4729. p.Status = 1
  4730. p.StartTime = pTime
  4731. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4732. if errcode > 0 {
  4733. c.ServeFailJSONWithSGJErrorCode(errcode)
  4734. return
  4735. }
  4736. if p.ID == 0 {
  4737. p.IsOut = 2
  4738. }
  4739. if p.ID > 0 {
  4740. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4741. p.IsOut = projectDetail.IsOut
  4742. }
  4743. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4744. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4745. if p.Type == 3 {
  4746. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4747. if p.Price != lastWarehouse.PackingPrice {
  4748. p.Price = lastWarehouse.PackingPrice
  4749. }
  4750. if p.Price == 0 {
  4751. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4752. p.Price = lastWarehouseTwo.PackingPrice
  4753. }
  4754. if p.Unit == "" {
  4755. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4756. p.Unit = goodInfoOne.PackingUnit
  4757. }
  4758. }
  4759. }
  4760. if adminInfo.CurrentOrgId != 10206 {
  4761. if p.Type == 3 {
  4762. if p.ID == 0 {
  4763. //查询该耗材是否停用
  4764. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4765. //表示该耗材已经停用,不能保存
  4766. if goodInfoSeven.ID == 0 {
  4767. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4768. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4769. return
  4770. }
  4771. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4772. if goodInfoOne.SumCount == 0 {
  4773. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4774. return
  4775. }
  4776. }
  4777. }
  4778. }
  4779. service.CreateHisProjectTwo(&p)
  4780. //记录日志
  4781. byterequest, _ := json.Marshal(p)
  4782. adviceLog := models.XtDoctorAdviceLog{
  4783. UserOrgId: p.UserOrgId,
  4784. PatientId: p.PatientId,
  4785. AdminUserId: adminInfo.AdminUser.Id,
  4786. Module: 1,
  4787. ErrLog: string(byterequest),
  4788. Status: 1,
  4789. Ctime: time.Now().Unix(),
  4790. Mtime: 0,
  4791. Source: "电脑端新建his项目",
  4792. RecordDate: p.RecordDate,
  4793. }
  4794. service.CreateDoctorAdviceLog(adviceLog)
  4795. projectList = append(projectList, p)
  4796. var randNum int
  4797. randNum = rand.Intn(10000) + 1000
  4798. timestamp := time.Now().Unix()
  4799. tempTime := time.Unix(timestamp, 0)
  4800. timeFormat := tempTime.Format("20060102150405")
  4801. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4802. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4803. //新增或者编辑项目,修改对应的标签数据
  4804. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4805. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4806. var label models.HisLabelPrintInfo
  4807. project, _ := service.GetProjectDetail(p.ProjectId)
  4808. if project.CostClassify == 3 { //类别为检验检查
  4809. if p.TeamId > 0 { //检验检查组套
  4810. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4811. if tempLabel.ID == 0 {
  4812. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4813. label.Number = tempPrescription.PrescriptionNumber
  4814. label.ProjectId = project.ID
  4815. label.Status = 1
  4816. label.IsPrint = 2
  4817. label.DoctorId = info.DoctorId
  4818. label.UserOrgId = p.UserOrgId
  4819. label.PatientId = patient_id
  4820. label.RecordDate = recordDateTime
  4821. label.Ctime = time.Now().Unix()
  4822. label.Mtime = time.Now().Unix()
  4823. label.ItemId = p.TeamId
  4824. label.FeedetlSn = p.FeedetlSn
  4825. label.PProjectId = p.ID
  4826. label.ProjectName = team.ProjectTeam
  4827. label.PatientName = patient.Name
  4828. service.CreateHisLabelRecord(&label)
  4829. }
  4830. } else { //单条检验检查项目
  4831. label.Number = tempPrescription.PrescriptionNumber
  4832. label.ProjectId = project.ID
  4833. label.Status = 1
  4834. label.DoctorId = info.DoctorId
  4835. label.UserOrgId = p.UserOrgId
  4836. label.PatientId = patient_id
  4837. label.RecordDate = recordDateTime
  4838. label.IsPrint = 2
  4839. label.Ctime = time.Now().Unix()
  4840. label.Mtime = time.Now().Unix()
  4841. label.FeedetlSn = p.FeedetlSn
  4842. label.PProjectId = p.ID
  4843. label.ItemId = p.TeamId
  4844. label.ProjectName = project.ProjectName
  4845. label.PatientName = patient.Name
  4846. service.CreateHisLabelRecord(&label)
  4847. }
  4848. }
  4849. }
  4850. }
  4851. service.SaveHisProjectTwo(&p)
  4852. }
  4853. }
  4854. }
  4855. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4856. // addition := items["addition"].([]interface{})
  4857. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4858. // ctime := time.Now().Unix()
  4859. // mtime := ctime
  4860. // if len(addition) > 0 {
  4861. // for _, item := range addition {
  4862. // var s models.HisAdditionalCharge
  4863. // s.PrescriptionId = tempPrescription.ID
  4864. // s.Status = 1
  4865. // s.UserOrgId = adminInfo.CurrentOrgId
  4866. // s.RecordDate = recordDateTime
  4867. // s.CreatedTime = ctime
  4868. // s.UpdatedTime = mtime
  4869. // s.PatientId = patient_id
  4870. // s.HisPatientId = his_patient_id
  4871. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4872. // if errcode > 0 {
  4873. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4874. // return
  4875. // }
  4876. // service.CreateAdditionalCharge(&s)
  4877. // var randNum int
  4878. // randNum = rand.Intn(10000) + 1000
  4879. // timestamp := time.Now().Unix()
  4880. // tempTime := time.Unix(timestamp, 0)
  4881. // timeFormat := tempTime.Format("20060102150405")
  4882. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4883. // service.CreateAdditionalCharge(&s)
  4884. //
  4885. // }
  4886. // }
  4887. //}
  4888. }
  4889. }
  4890. //查询今日该患者开的药品处方
  4891. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4892. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4893. //药品出库
  4894. if drugOutConfig.IsOpen == 1 {
  4895. for _, item := range hisdoctorlist {
  4896. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4897. // 查询该药品最后一次出库记录
  4898. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4899. if len(druginfo) > 0 {
  4900. //回退库存
  4901. for _, it := range druginfo {
  4902. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4903. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4904. }
  4905. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4906. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4907. }
  4908. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4909. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4910. }
  4911. }
  4912. }
  4913. //删除记录
  4914. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4915. //查询最后一次数据
  4916. if drugOutConfig.IsOpen == 1 {
  4917. //出库
  4918. if drug.IsUse == 2 {
  4919. creater := adminInfo.AdminUser.Id
  4920. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4921. }
  4922. //更新字典里面的库存
  4923. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4924. var sum_count int64
  4925. for _, its := range stockInfo {
  4926. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4927. if its.MaxUnit == baseDrug.MaxUnit {
  4928. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4929. }
  4930. sum_count += its.StockMaxNumber + its.StockMinNumber
  4931. }
  4932. //更新基础库存
  4933. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4934. //剩余库存
  4935. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4936. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4937. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4938. }
  4939. }
  4940. }
  4941. //耗材保存处方出库
  4942. if goodOutConfig.IsOpen == 1 {
  4943. //查询今日耗材出库数量
  4944. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4945. for _, item := range hisgoodlist {
  4946. //查询历史出库数据
  4947. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4948. var out_count_five int64
  4949. for _, item := range flowGood {
  4950. out_count_five += item.Count
  4951. }
  4952. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4953. if out_count_five != parseIntCount {
  4954. //查询耗材最后一次出库记录
  4955. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4956. //查询默认出库仓库库存
  4957. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4958. if len(wareOut) > 0 {
  4959. for _, it := range wareOut {
  4960. //回退库存
  4961. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4962. //删除出库记录
  4963. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4964. }
  4965. }
  4966. timeStr := time.Now().Format("2006-01-02")
  4967. timeArr := strings.Split(timeStr, "-")
  4968. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4969. total = total + 1
  4970. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4971. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4972. number = number + total
  4973. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4974. operation_time := time.Now().Unix()
  4975. creater := c.GetAdminUserInfo().AdminUser.Id
  4976. recordDateStr := time.Now().Format("2006-01-02")
  4977. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4978. nowtime := recordDate.Unix()
  4979. warehouseOut := models.WarehouseOut{
  4980. WarehouseOutOrderNumber: warehousing_out_order,
  4981. OperationTime: operation_time,
  4982. OrgId: adminInfo.CurrentOrgId,
  4983. Creater: creater,
  4984. Ctime: time.Now().Unix(),
  4985. Status: 1,
  4986. WarehouseOutTime: nowtime,
  4987. Type: 1,
  4988. StorehouseId: storeConfig.StorehouseOutInfo,
  4989. IsCheck: 1,
  4990. IsSys: 1,
  4991. }
  4992. //查询是否生成出库单
  4993. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4994. if out.ID == 0 {
  4995. service.AddSigleWarehouseOut(&warehouseOut)
  4996. }
  4997. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4998. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4999. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5000. dialyPrepareOne := models.DialysisBeforePrepare{
  5001. GoodTypeId: goodObj.GoodTypeId,
  5002. GoodId: item.ProjectId,
  5003. PatientId: item.PatientId,
  5004. RecordDate: item.RecordDate,
  5005. UserOrgId: adminInfo.CurrentOrgId,
  5006. Count: parseIntCount,
  5007. Ctime: time.Now().Unix(),
  5008. Creater: creater,
  5009. Status: 1,
  5010. StorehouseId: houseConfig.StorehouseOutInfo,
  5011. ProjectId: item.ID,
  5012. }
  5013. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5014. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5015. //查询历史出库数据
  5016. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5017. var out_count int64
  5018. for _, item := range flowGood {
  5019. out_count += item.Count
  5020. }
  5021. //如果历史数和当前数据不想等才进行退库出库
  5022. if out_count != parseIntCount {
  5023. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5024. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5025. detail := models.AutomaticReduceDetail{
  5026. WarehouseOutId: 0,
  5027. WarehouseOutOrderNumber: "",
  5028. PatientId: item.PatientId,
  5029. Ctime: time.Now().Unix(),
  5030. Mtime: 0,
  5031. Status: 1,
  5032. RecordTime: item.RecordDate,
  5033. OrgId: item.UserOrgId,
  5034. GoodId: item.ProjectId,
  5035. GoodTypeId: 0,
  5036. Count: parseIntCount,
  5037. Type: 0,
  5038. ProjectId: item.ID,
  5039. StorehouseId: 0,
  5040. }
  5041. service.CreateAutoDetail(detail)
  5042. //查询剩余库存
  5043. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5044. var sum_count int64
  5045. for _, item := range goodList {
  5046. sum_count += item.StockCount
  5047. }
  5048. //更新剩余库存
  5049. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5050. //耗材
  5051. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5052. }
  5053. }
  5054. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5055. //查询历史出库数据
  5056. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5057. var out_count int64
  5058. for _, item := range flowGood {
  5059. out_count += item.Count
  5060. }
  5061. //如果历史数和当前数据不想等才进行退库出库
  5062. if out_count != parseIntCount {
  5063. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5064. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5065. detail := models.AutomaticReduceDetail{
  5066. WarehouseOutId: 0,
  5067. WarehouseOutOrderNumber: "",
  5068. PatientId: item.PatientId,
  5069. Ctime: time.Now().Unix(),
  5070. Mtime: 0,
  5071. Status: 1,
  5072. RecordTime: item.RecordDate,
  5073. OrgId: item.UserOrgId,
  5074. GoodId: item.ProjectId,
  5075. GoodTypeId: 0,
  5076. Count: parseIntCount,
  5077. Type: 0,
  5078. ProjectId: item.ID,
  5079. StorehouseId: 0,
  5080. }
  5081. service.CreateAutoDetail(detail)
  5082. //查询剩余库存
  5083. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5084. var sum_count int64
  5085. for _, item := range goodList {
  5086. sum_count += item.StockCount
  5087. }
  5088. //更新剩余库存
  5089. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5090. //耗材
  5091. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5092. }
  5093. }
  5094. }
  5095. }
  5096. }
  5097. ////同步到自备药
  5098. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5099. if selfPrescriptionOpen.IsOpen == 1 {
  5100. timeStr := time.Now().Format("2006-01-02")
  5101. timeArr := strings.Split(timeStr, "-")
  5102. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5103. total = total + 1
  5104. operation_time := time.Now().Unix()
  5105. creater := adminInfo.AdminUser.Id
  5106. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5107. warehousing := models.XtSelfDrugWarehouse{
  5108. WarehousingOrder: warehousing_order,
  5109. OperationTime: operation_time,
  5110. OrgId: adminInfo.CurrentOrgId,
  5111. Creater: creater,
  5112. Ctime: time.Now().Unix(),
  5113. Status: 1,
  5114. WarehousingTime: recordDateTime,
  5115. Type: 0,
  5116. StorehouseId: 0,
  5117. IsCheck: 1,
  5118. PatientId: patient_id,
  5119. IsSys: 1,
  5120. }
  5121. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5122. if selfDrugWarehouse.ID == 0 {
  5123. service.AddSelfDrugWarehouse(&warehousing, tx)
  5124. }
  5125. if selfDrugWarehouse.ID > 0 {
  5126. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5127. }
  5128. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5129. fmt.Println(info)
  5130. for _, item := range hisdoctorlist {
  5131. //查询该病人的该药品是否已经入库
  5132. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5133. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5134. var in_count int64
  5135. if len(selfdruginfo) > 0 {
  5136. for _, item := range selfdruginfo {
  5137. var in_count_one int64
  5138. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5139. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5140. }
  5141. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5142. in_count_one = item.WarehousingCount
  5143. }
  5144. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5145. in_count_one = item.WarehousingCount
  5146. }
  5147. in_count += in_count_one
  5148. }
  5149. }
  5150. if selfBasedrug.IsSelfDrug == 1 {
  5151. var total_count int64
  5152. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5153. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5154. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5155. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5156. }
  5157. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5158. total_count += prescribingNumberSeven
  5159. }
  5160. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5161. total_count += prescribingNumberSeven
  5162. }
  5163. //入库
  5164. if total_count > in_count {
  5165. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5166. WarehousingOrder: warehousing_order,
  5167. WarehousingId: info.ID,
  5168. DrugId: item.DrugId,
  5169. Number: "",
  5170. ProductDate: 0,
  5171. ExpiryDate: 0,
  5172. WarehousingCount: total_count - in_count,
  5173. WarehouseingUnit: selfBasedrug.MinUnit,
  5174. Price: 0,
  5175. TotalPrice: 0,
  5176. Status: 1,
  5177. Ctime: time.Now().Unix(),
  5178. Remark: "",
  5179. OrgId: adminInfo.CurrentOrgId,
  5180. Type: 0,
  5181. Manufacturer: selfBasedrug.Manufacturer,
  5182. Dealer: selfBasedrug.Dealer,
  5183. StockMaxNumber: total_count - in_count,
  5184. RetailTotalPrice: 0,
  5185. BatchNumber: "",
  5186. MaxUnit: selfBasedrug.MinUnit,
  5187. MinUnit: selfBasedrug.MinUnit,
  5188. RetailPrice: 0,
  5189. StorehouseId: 0,
  5190. IsCheck: 1,
  5191. StockMinNumber: 0,
  5192. PatientId: patient_id,
  5193. IsSys: 1,
  5194. RecordDate: item.RecordDate,
  5195. AdviceId: item.ID,
  5196. }
  5197. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5198. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5199. Creator := adminInfo.AdminUser.Id
  5200. //查询默认仓库剩余多少库存
  5201. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5202. var sum_count int64
  5203. for _, it := range list {
  5204. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5205. if it.MaxUnit == baseDrug.MaxUnit {
  5206. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5207. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5208. }
  5209. sum_count += it.StockMaxNumber + it.StockMinNumber
  5210. }
  5211. flow := &models.XtSelfDrugFlow{
  5212. WarehousingId: info.ID,
  5213. DrugId: item.DrugId,
  5214. Number: "",
  5215. BatchNumber: "",
  5216. Count: total_count - in_count,
  5217. UserOrgId: adminInfo.CurrentOrgId,
  5218. PatientId: item.PatientId,
  5219. SystemTime: time.Now().Unix(),
  5220. ConsumableType: 1,
  5221. IsSys: 1,
  5222. WarehousingOrder: warehousing_order,
  5223. WarehouseOutId: 0,
  5224. WarehouseOutOrderNumber: "",
  5225. IsEdit: 0,
  5226. CancelStockId: 0,
  5227. CancelOrderNumber: "",
  5228. Manufacturer: selfBasedrug.Manufacturer,
  5229. Dealer: selfBasedrug.Dealer,
  5230. Creator: Creator,
  5231. UpdateCreator: Creator,
  5232. Status: 1,
  5233. Ctime: item.AdviceDate,
  5234. Mtime: 0,
  5235. Price: item.Price,
  5236. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5237. WarehouseOutDetailId: 0,
  5238. CancelOutDetailId: 0,
  5239. ExpireDate: 0,
  5240. ProductDate: 0,
  5241. MaxUnit: selfBasedrug.MinUnit,
  5242. MinUnit: selfBasedrug.MinUnit,
  5243. StorehouseId: 0,
  5244. OverCount: sum_count,
  5245. OperateTime: time.Now().Unix(),
  5246. AdviceId: item.ID,
  5247. }
  5248. service.CreateSelfDrugFlow(flow, tx)
  5249. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5250. var total_count int64 // 入库总数量
  5251. var over_count int64 //剩余库存
  5252. for _, it := range drugInfolist {
  5253. if it.MaxUnit == selfBasedrug.MaxUnit {
  5254. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5255. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5256. }
  5257. }
  5258. for _, it := range drugInfolist {
  5259. total_count += it.WarehousingCount
  5260. over_count += it.StockMaxNumber + it.StockMinNumber
  5261. }
  5262. //查询该仓库是否有默认数据
  5263. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5264. if selfDrugStock.ID == 0 {
  5265. drugStock := models.XtSelfDrugStockCount{
  5266. UserOrgId: item.UserOrgId,
  5267. PatientId: item.PatientId,
  5268. SumInCount: total_count,
  5269. SumOutCount: 0,
  5270. SumCancelCount: 0,
  5271. DrugId: item.DrugId,
  5272. Ctime: time.Now().Unix(),
  5273. Mtime: 0,
  5274. Status: 1,
  5275. FlushCount: over_count,
  5276. SumActOutCount: 0,
  5277. }
  5278. service.CreateSelfDrugStockSum(drugStock, tx)
  5279. }
  5280. if selfDrugStock.ID > 0 {
  5281. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5282. }
  5283. }
  5284. //查询这个单据的出库数量
  5285. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5286. var his_out_count int64
  5287. for _, item := range drugFlowList {
  5288. his_out_count += item.Count
  5289. }
  5290. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5291. if (total_count + his_out_count) <= in_count {
  5292. // 出库
  5293. if total_count < in_count {
  5294. var cha_count int64
  5295. cha_count = in_count - total_count
  5296. var stock_number int64 = 0
  5297. //查询库存是否充足
  5298. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5299. // 将该批次的剩余库存数量转换为拆零数量
  5300. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5301. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5302. }
  5303. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5304. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5305. }
  5306. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5307. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5308. }
  5309. if stock_number >= cha_count {
  5310. var maxNumber int64 = 0
  5311. var minNumber int64 = 0
  5312. maxNumber = cha_count / selfBasedrug.MinNumber
  5313. minNumber = cha_count % selfBasedrug.MinNumber
  5314. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5315. minNumber = maxNumber
  5316. }
  5317. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5318. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5320. return
  5321. }
  5322. }
  5323. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5324. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5325. }
  5326. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5327. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5328. }
  5329. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5330. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5331. }
  5332. if warehouse.StockMaxNumber < 0 {
  5333. warehouse.StockMaxNumber = 0
  5334. }
  5335. if warehouse.StockMinNumber < 0 {
  5336. warehouse.StockMinNumber = 0
  5337. }
  5338. warehouse.Mtime = time.Now().Unix()
  5339. if warehouse.StockMinNumber < minNumber {
  5340. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5341. if warehouse.MaxUnit != warehouse.MinUnit {
  5342. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5343. }
  5344. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5345. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5346. }
  5347. } else {
  5348. if minNumber > 0 {
  5349. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5350. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5351. }
  5352. }
  5353. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5354. if warehouse.StockMinNumber > 0 {
  5355. if warehouse.StockMinNumber-cha_count >= 0 {
  5356. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5357. }
  5358. }
  5359. }
  5360. }
  5361. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5362. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5363. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5364. }
  5365. }
  5366. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5367. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5369. return
  5370. }
  5371. }
  5372. if warehouse.StockMinNumber <= 0 {
  5373. warehouse.StockMinNumber = 0
  5374. }
  5375. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5376. //查询该药品剩余库存
  5377. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5378. var over_count int64
  5379. for _, its := range infolist {
  5380. if its.MaxUnit == selfBasedrug.MaxUnit {
  5381. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5382. }
  5383. over_count += its.StockMaxNumber + its.StockMinNumber
  5384. }
  5385. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5386. drugflow := models.XtSelfDrugFlow{
  5387. WarehouseOutId: 0,
  5388. WarehouseOutOrderNumber: warehousing_order,
  5389. WarehousingOrder: warehousing_order,
  5390. DrugId: item.DrugId,
  5391. Number: warehouse.Number,
  5392. ProductDate: warehouse.ProductDate,
  5393. ExpireDate: warehouse.ExpiryDate,
  5394. Count: cha_count,
  5395. Price: warehouse.RetailPrice,
  5396. Status: 1,
  5397. Ctime: item.AdviceDate,
  5398. Mtime: time.Now().Unix(),
  5399. UserOrgId: item.UserOrgId,
  5400. Manufacturer: warehouse.Manufacturer,
  5401. Dealer: warehouse.Dealer,
  5402. BatchNumber: warehouse.BatchNumber,
  5403. MaxUnit: selfBasedrug.MinUnit,
  5404. ConsumableType: 20,
  5405. IsEdit: 1,
  5406. Creator: 0,
  5407. IsSys: 3,
  5408. WarehouseOutDetailId: drugWareInfo.ID,
  5409. AdviceId: item.ID,
  5410. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5411. StorehouseId: 0,
  5412. AdminUserId: creater,
  5413. LastPrice: warehouse.Price,
  5414. StockCount: "",
  5415. WarehousingDetailId: 0,
  5416. OverCount: over_count,
  5417. RetailPrice: item.Price, //手动出库出库价格
  5418. WarehousingId: warehouse.ID,
  5419. SystemTime: item.AdviceDate,
  5420. PatientId: item.PatientId,
  5421. Remark: "保存处方入库数据差",
  5422. OperateTime: time.Now().Unix(),
  5423. }
  5424. if warehouse.RetailPrice == 0 {
  5425. drugflow.Price = item.Price
  5426. }
  5427. service.CreateSelfDrugFlowOne(drugflow, tx)
  5428. var out_count int64
  5429. out_count = in_count - total_count
  5430. //
  5431. //fmt.Println("in_count------------------", in_count)
  5432. //fmt.Println("total_count------------------", total_count)
  5433. //添加出库数量
  5434. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5435. //查询剩余库存
  5436. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5437. var sum_count int64
  5438. for _, its := range stockInfo {
  5439. if its.MaxUnit == selfBasedrug.MaxUnit {
  5440. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5441. }
  5442. sum_count += its.StockMaxNumber + its.StockMinNumber
  5443. }
  5444. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5445. } else {
  5446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5447. return
  5448. }
  5449. }
  5450. }
  5451. }
  5452. }
  5453. }
  5454. }
  5455. tx.Commit()
  5456. if err == nil {
  5457. c.ServeSuccessJSON(map[string]interface{}{
  5458. "msg": "保存成功",
  5459. })
  5460. return
  5461. } else {
  5462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5463. return
  5464. }
  5465. }
  5466. }
  5467. //func (c *HisApiController) EditHisPrescription() {
  5468. // record_date := c.GetString("record_date")
  5469. // patient_id, _ := c.GetInt64("patient_id")
  5470. // reg_type, _ := c.GetInt64("reg_type")
  5471. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5472. // diagnose := c.GetString("diagnose")
  5473. // sick_type, _ := c.GetInt64("sick_type")
  5474. // sick_history := c.GetString("sick_history")
  5475. // doctor_id, _ := c.GetInt64("doctor", 0)
  5476. // department, _ := c.GetInt64("department", 0)
  5477. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5478. // p_type, _ := c.GetInt64("p_type")
  5479. //
  5480. // dataBody := make(map[string]interface{}, 0)
  5481. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5482. // if err != nil {
  5483. // utils.ErrorLog(err.Error())
  5484. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5485. // return
  5486. // }
  5487. //
  5488. // timeLayout := "2006-01-02"
  5489. // loc, _ := time.LoadLocation("Local")
  5490. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5491. // if err != nil {
  5492. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5493. // return
  5494. // }
  5495. // adminInfo := c.GetAdminUserInfo()
  5496. // recordDateTime := theTime.Unix()
  5497. //
  5498. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5499. //
  5500. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5501. // var hpInfo models.HisPrescriptionInfo
  5502. // if info.ID == 0 {
  5503. // var randNum int
  5504. // randNum = rand.Intn(10000) + 1000
  5505. // timestamp := time.Now().Unix()
  5506. // tempTime := time.Unix(timestamp, 0)
  5507. // timeFormat := tempTime.Format("20060102150405")
  5508. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5509. //
  5510. // hpInfo = models.HisPrescriptionInfo{
  5511. // UserOrgId: adminInfo.CurrentOrgId,
  5512. // RecordDate: theTime.Unix(),
  5513. // PatientId: patient_id,
  5514. // Status: 1,
  5515. // Ctime: time.Now().Unix(),
  5516. // Mtime: time.Now().Unix(),
  5517. // Creator: adminInfo.AdminUser.Id,
  5518. // Modifier: adminInfo.AdminUser.Id,
  5519. // Diagnosis: diagnose,
  5520. // SickHistory: sick_history,
  5521. // Departments: department,
  5522. // RegisterType: reg_type,
  5523. // PrescriptionNumber: p_number,
  5524. // PrescriptionStatus: 1,
  5525. // Doctor: role.UserName,
  5526. // DoctorId: doctor_id,
  5527. // SickType: sick_type,
  5528. // PType: p_type,
  5529. // }
  5530. // service.SavePatientPrescriptionInfo(hpInfo)
  5531. //
  5532. // } else {
  5533. // hpInfo = models.HisPrescriptionInfo{
  5534. // ID: info.ID,
  5535. // UserOrgId: adminInfo.CurrentOrgId,
  5536. // RecordDate: info.RecordDate,
  5537. // PatientId: info.PatientId,
  5538. // Status: 1,
  5539. // Ctime: info.Ctime,
  5540. // Mtime: time.Now().Unix(),
  5541. // Creator: info.Creator,
  5542. // Modifier: adminInfo.AdminUser.Id,
  5543. // Diagnosis: diagnose,
  5544. // SickHistory: sick_history,
  5545. // Departments: department,
  5546. // RegisterType: reg_type,
  5547. // PrescriptionNumber: info.PrescriptionNumber,
  5548. // Doctor: role.UserName,
  5549. // PrescriptionStatus: info.PrescriptionStatus,
  5550. // DoctorId: doctor_id,
  5551. // SickType: sick_type,
  5552. // PType: info.PType,
  5553. // }
  5554. // service.SavePatientPrescriptionInfo(hpInfo)
  5555. // }
  5556. //
  5557. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5558. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5559. //
  5560. // if len(prescriptions) > 0 {
  5561. // for _, item := range prescriptions {
  5562. // items := item.(map[string]interface{})
  5563. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5564. // utils.ErrorLog("id")
  5565. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5566. // return
  5567. // }
  5568. // id := int64(items["id"].(float64))
  5569. //
  5570. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5571. // utils.ErrorLog("type")
  5572. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5573. // return
  5574. // }
  5575. // types := int64(items["type"].(float64))
  5576. //
  5577. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5578. // utils.ErrorLog("med_type")
  5579. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5580. // return
  5581. // }
  5582. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5583. //
  5584. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5585. //
  5586. // ctime := time.Now().Unix()
  5587. //
  5588. // prescription := &models.HisPrescription{
  5589. // ID: id,
  5590. // PatientId: patient_id,
  5591. // UserOrgId: adminInfo.CurrentOrgId,
  5592. // RecordDate: recordDateTime,
  5593. // Ctime: ctime,
  5594. // Mtime: ctime,
  5595. // Type: types,
  5596. // Modifier: adminInfo.AdminUser.Id,
  5597. // Creator: adminInfo.AdminUser.Id,
  5598. // Status: 1,
  5599. // Doctor: role.UserName,
  5600. // HisPatientId: his_patient_id,
  5601. // OrderStatus: 1,
  5602. // BatchNumber: "",
  5603. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5604. // PType: hpInfo.PType,
  5605. // MedType: med_type,
  5606. // }
  5607. //
  5608. // if historyPrescription.ID > 0 {
  5609. // prescription.PreTime = historyPrescription.PreTime
  5610. //
  5611. // }
  5612. //
  5613. // service.SaveHisPrescription(prescription)
  5614. //
  5615. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5616. // advices := items["advices"].([]interface{})
  5617. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5618. // groupNo := int64(0)
  5619. // ctime := time.Now().Unix()
  5620. // mtime := ctime
  5621. // if len(advices) > 0 {
  5622. // for _, advice := range advices {
  5623. // var s models.HisDoctorAdviceInfo
  5624. // s.PrescriptionId = prescription.ID
  5625. // s.AdviceType = 2
  5626. // s.AdviceDoctor = adminInfo.AdminUser.Id
  5627. // s.StopState = 2
  5628. // s.ExecutionState = 2
  5629. // s.AdviceDate = recordDateTime
  5630. // s.Status = 1
  5631. // s.UserOrgId = adminInfo.CurrentOrgId
  5632. // s.RecordDate = recordDateTime
  5633. // s.StartTime = prescription.PreTime
  5634. // s.Groupno = groupNo
  5635. // s.CreatedTime = ctime
  5636. // s.UpdatedTime = mtime
  5637. // s.PatientId = patient_id
  5638. // s.HisPatientId = his_patient_id
  5639. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5640. // if errcode > 0 {
  5641. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5642. // return
  5643. // }
  5644. //
  5645. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5646. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5647. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5648. // if s.Price == 0 {
  5649. // s.Price = lastWarehouse.RetailPrice
  5650. // }
  5651. // }
  5652. //
  5653. // service.CreateHisDoctorAdvice(&s)
  5654. // //记录日志
  5655. // byterequest, _ := json.Marshal(s)
  5656. // adviceLog := models.XtDoctorAdviceLog{
  5657. // UserOrgId: s.UserOrgId,
  5658. // PatientId: s.PatientId,
  5659. // AdminUserId: adminInfo.AdminUser.Id,
  5660. // Module: 1,
  5661. // ErrLog: string(byterequest),
  5662. // Status: 1,
  5663. // Ctime: time.Now().Unix(),
  5664. // Mtime: 0,
  5665. // Source: "电脑端his医嘱修改",
  5666. // RecordDate: s.AdviceDate,
  5667. // }
  5668. // service.CreateDoctorAdviceLog(adviceLog)
  5669. // redis := service.RedisClient()
  5670. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5671. // redis.Set(key, "", time.Second)
  5672. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5673. // fmt.Println("keyOne", keyOne)
  5674. // redis.Set(keyOne, "", time.Second)
  5675. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5676. // redis.Set(keySeven, "", time.Second)
  5677. // redis.Close()
  5678. //
  5679. // }
  5680. // }
  5681. // }
  5682. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5683. // projects := items["project"].([]interface{})
  5684. // if len(projects) > 0 {
  5685. // for _, project := range projects {
  5686. // var p models.HisPrescriptionProject
  5687. // p.PrescriptionId = prescription.ID
  5688. // p.Ctime = time.Now().Unix()
  5689. // p.Mtime = time.Now().Unix()
  5690. // p.PatientId = patient_id
  5691. // p.RecordDate = recordDateTime
  5692. // p.UserOrgId = adminInfo.CurrentOrgId
  5693. // p.HisPatientId = his_patient_id
  5694. // p.Status = 1
  5695. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5696. // if errcode > 0 {
  5697. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5698. // return
  5699. // }
  5700. // service.CreateHisProjectTwo(&p)
  5701. //
  5702. // //记录日志
  5703. // byterequest, _ := json.Marshal(p)
  5704. // adviceLog := models.XtDoctorAdviceLog{
  5705. // UserOrgId: p.UserOrgId,
  5706. // PatientId: p.PatientId,
  5707. // AdminUserId: adminInfo.AdminUser.Id,
  5708. // Module: 1,
  5709. // ErrLog: string(byterequest),
  5710. // Status: 1,
  5711. // Ctime: time.Now().Unix(),
  5712. // Mtime: 0,
  5713. // Source: "电脑端his项目修改",
  5714. // RecordDate: p.RecordDate,
  5715. // }
  5716. // service.CreateDoctorAdviceLog(adviceLog)
  5717. // }
  5718. // }
  5719. // }
  5720. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5721. // addition := items["addition"].([]interface{})
  5722. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5723. // ctime := time.Now().Unix()
  5724. // mtime := ctime
  5725. // if len(addition) > 0 {
  5726. // for _, item := range addition {
  5727. // var s models.HisAdditionalCharge
  5728. // s.PrescriptionId = prescription.ID
  5729. // s.Status = 1
  5730. // s.UserOrgId = adminInfo.CurrentOrgId
  5731. // s.RecordDate = recordDateTime
  5732. // s.CreatedTime = ctime
  5733. // s.UpdatedTime = mtime
  5734. // s.PatientId = patient_id
  5735. // s.HisPatientId = his_patient_id
  5736. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5737. // if errcode > 0 {
  5738. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5739. // return
  5740. // }
  5741. // service.CreateAdditionalCharge(&s)
  5742. // }
  5743. // }
  5744. // }
  5745. //
  5746. // }
  5747. // }
  5748. // }
  5749. // if err == nil {
  5750. // c.ServeSuccessJSON(map[string]interface{}{
  5751. // "msg": "保存成功",
  5752. // })
  5753. // return
  5754. //
  5755. // } else {
  5756. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5757. // return
  5758. // }
  5759. //}
  5760. func (c *HisApiController) DeletePrescription() {
  5761. prescription_id, _ := c.GetInt64("id")
  5762. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5763. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5764. ////同步到自备药
  5765. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5766. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5767. if selfPrescriptionOpen.IsOpen == 1 {
  5768. // 在函数结束时处理事务回滚
  5769. db := service.XTWriteDB()
  5770. tx := db.Begin()
  5771. defer func() {
  5772. if r := recover(); r != nil {
  5773. tx.Rollback()
  5774. } else {
  5775. tx.Commit()
  5776. }
  5777. }()
  5778. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5779. for _, item := range advicesList {
  5780. timeStr := time.Now().Format("2006-01-02")
  5781. timeArr := strings.Split(timeStr, "-")
  5782. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5783. total = total + 1
  5784. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5785. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5786. number = number + total
  5787. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5788. operation_time := time.Now().Unix()
  5789. creater := c.GetAdminUserInfo().AdminUser.Id
  5790. //创建一个出库单
  5791. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5792. WarehouseOutOrderNumber: warehousing_out_order,
  5793. OperationTime: operation_time,
  5794. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5795. Creater: creater,
  5796. Ctime: time.Now().Unix(),
  5797. Status: 1,
  5798. WarehouseOutTime: item.AdviceDate,
  5799. Type: 0,
  5800. PatientId: item.PatientId,
  5801. IsCheck: 1,
  5802. }
  5803. //查询今日是否有出库数据
  5804. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5805. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5806. if lastWarehouseOut.ID == 0 {
  5807. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5808. }
  5809. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5810. var total_count int64
  5811. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5812. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5813. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5814. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5815. }
  5816. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5817. total_count += prescribingNumberSeven
  5818. }
  5819. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5820. total_count += prescribingNumberSeven
  5821. }
  5822. //出库
  5823. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5824. WarehouseOutOrderNumber: warehousing_out_order,
  5825. WarehouseOutId: lastWarehouseOut.ID,
  5826. DrugId: item.DrugId,
  5827. Count: total_count,
  5828. Price: 0,
  5829. TotalPrice: 0,
  5830. Status: 1,
  5831. Ctime: item.AdviceDate,
  5832. Mtime: item.AdviceDate,
  5833. Remark: "",
  5834. OrgId: item.UserOrgId,
  5835. Type: 0,
  5836. Manufacturer: selfBasedrug.Manufacturer,
  5837. Dealer: selfBasedrug.Dealer,
  5838. RetailPrice: 0,
  5839. RetailTotalPrice: 0,
  5840. CountUnit: selfBasedrug.MinUnit,
  5841. ExpiryDate: 0,
  5842. ProductDate: 0,
  5843. Number: "",
  5844. BatchNumber: "",
  5845. IsSys: 1,
  5846. WarehouseInfoId: 0,
  5847. AdminUserId: 0,
  5848. StockCount: "",
  5849. IsCheck: 1,
  5850. SysRecordTime: item.AdviceDate,
  5851. PatientId: item.PatientId,
  5852. ClassType: "",
  5853. AdviceId: item.ID,
  5854. }
  5855. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5856. }
  5857. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5858. for _, it := range warehousingOutInfo {
  5859. //查询今日是否有出库数据
  5860. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5861. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5862. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5863. //出库逻辑
  5864. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5865. //查询剩余库存
  5866. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5867. var sum_count int64
  5868. for _, its := range stockInfo {
  5869. if its.MaxUnit == medical.MaxUnit {
  5870. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5871. }
  5872. sum_count += its.StockMaxNumber + its.StockMinNumber
  5873. }
  5874. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5875. }
  5876. }
  5877. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5878. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5879. //耗材保存处方出库
  5880. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5881. //已收费和已发药限制逻辑
  5882. isCharge := false
  5883. isMedicine := false
  5884. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5885. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5886. if new_prescription.IsMedicine == 1 {
  5887. isMedicine = true
  5888. }
  5889. for _, item := range new_prescriptions {
  5890. if item.OrderStatus == 4 {
  5891. isCharge = true
  5892. }
  5893. }
  5894. if p_err != nil {
  5895. if new_prescription.ID > 0 {
  5896. if new_prescription.OrderStatus == 2 {
  5897. isCharge = true
  5898. }
  5899. }
  5900. }
  5901. for _, item := range advices {
  5902. if item.IsMedicine == 1 {
  5903. isMedicine = true
  5904. }
  5905. }
  5906. if isCharge {
  5907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5908. return
  5909. }
  5910. if isMedicine {
  5911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5912. return
  5913. }
  5914. //已收费和已发药限制逻辑
  5915. if len(projects) > 0 {
  5916. for _, item := range projects {
  5917. service.DeletePrintInfo(item.ID) //删除打印信息
  5918. if goodOutConfig.IsOpen != 1 {
  5919. if stockConfig.IsOpen == 1 {
  5920. if item.Type == 3 && item.IsOut == 1 {
  5921. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5922. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5923. good.Total = good.Total + f_count
  5924. service.UpdateGoodInfo(&good)
  5925. operation_time := time.Now().Unix()
  5926. creater := c.GetAdminUserInfo().AdminUser.Id
  5927. //创建退库单
  5928. timeStr := time.Now().Format("2006-01-02")
  5929. timeArr := strings.Split(timeStr, "-")
  5930. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5931. total = total + 1
  5932. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5933. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5934. cancelStock := models.CancelStock{
  5935. OrderNumber: orderNumber,
  5936. OperaTime: operation_time,
  5937. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5938. Creater: creater,
  5939. Ctime: time.Now().Unix(),
  5940. Status: 1,
  5941. ReturnTime: item.RecordDate,
  5942. Type: 1,
  5943. StorehouseId: houseConfig.StorehouseOutInfo,
  5944. IsCheck: 1,
  5945. }
  5946. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5947. if msgerrkonde == gorm.ErrRecordNotFound {
  5948. service.AddSigleCancelStock(&cancelStock)
  5949. }
  5950. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5951. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5952. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5953. //查询该耗材是否出库
  5954. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5955. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5956. deaerler, _ := service.GetDealerById(info.Dealer)
  5957. var total_count int64
  5958. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5959. total_count += count
  5960. if info.ID > 0 {
  5961. if info.Count >= total_count {
  5962. //回退库存
  5963. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5964. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5965. var flush_count int64
  5966. for _, it := range goodList {
  5967. flush_count += it.StockCount
  5968. }
  5969. cancelStockInfo := models.CancelStockInfo{
  5970. GoodId: item.ProjectId,
  5971. CancelStockId: cancel.ID,
  5972. GoodTypeId: good.GoodTypeId,
  5973. Count: prescribingNumber,
  5974. Price: info.Price,
  5975. Total: 0,
  5976. ProductDate: info.ProductDate,
  5977. ExpiryDate: info.ExpiryDate,
  5978. Ctime: time.Now().Unix(),
  5979. Status: 1,
  5980. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5981. OrderNumber: cancel.OrderNumber,
  5982. Type: 0,
  5983. Dealer: deaerler.DealerName,
  5984. Manufacturer: manufacturer.ManufacturerName,
  5985. Number: info.Number,
  5986. RegisterAccount: "",
  5987. Remark: "",
  5988. WarehouseInfoId: info.WarehouseInfotId,
  5989. PatientId: info.PatientId,
  5990. RecordDate: info.SysRecordTime,
  5991. StorehouseId: houseConfig.StorehouseOutInfo,
  5992. IsCheck: 1,
  5993. }
  5994. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5995. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5996. flow := models.VmStockFlow{
  5997. WarehousingId: info.WarehouseInfotId,
  5998. GoodId: item.ProjectId,
  5999. Number: info.Number,
  6000. LicenseNumber: info.LicenseNumber,
  6001. Count: prescribingNumber,
  6002. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6003. PatientId: item.PatientId,
  6004. SystemTime: info.SysRecordTime,
  6005. ConsumableType: 7,
  6006. IsSys: 0,
  6007. WarehousingOrder: "",
  6008. WarehouseOutId: info.WarehouseOutId,
  6009. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6010. IsEdit: 0,
  6011. CancelStockId: cancel.ID,
  6012. CancelOrderNumber: cancel.OrderNumber,
  6013. Manufacturer: manufacturer.ID,
  6014. Dealer: 0,
  6015. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6016. UpdateCreator: 0,
  6017. Status: 1,
  6018. Ctime: time.Now().Unix(),
  6019. Mtime: 0,
  6020. Price: info.Price,
  6021. WarehousingDetailId: info.WarehouseInfotId,
  6022. WarehouseOutDetailId: info.ID,
  6023. CancelOutDetailId: cancelInfo.ID,
  6024. ProductDate: info.ProductDate,
  6025. ExpireDate: info.ExpiryDate,
  6026. StorehouseId: houseConfig.StorehouseOutInfo,
  6027. OverCount: flush_count,
  6028. OperateTime: time.Now().Unix(),
  6029. }
  6030. service.CreateStockFlowOne(flow)
  6031. //退库数量增加
  6032. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6033. //出库数量减少
  6034. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6035. }
  6036. if info.Count < total_count {
  6037. //回退库存
  6038. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6039. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6040. var flush_count int64
  6041. for _, it := range goodList {
  6042. flush_count += it.StockCount
  6043. }
  6044. cancelStockInfo := models.CancelStockInfo{
  6045. GoodId: item.ProjectId,
  6046. CancelStockId: cancel.ID,
  6047. GoodTypeId: good.GoodTypeId,
  6048. Count: info.Count,
  6049. Price: info.Price,
  6050. Total: 0,
  6051. ProductDate: info.ProductDate,
  6052. ExpiryDate: info.ExpiryDate,
  6053. Ctime: time.Now().Unix(),
  6054. Status: 1,
  6055. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6056. OrderNumber: cancel.OrderNumber,
  6057. Type: 0,
  6058. Dealer: deaerler.DealerName,
  6059. Manufacturer: manufacturer.ManufacturerName,
  6060. Number: info.Number,
  6061. RegisterAccount: "",
  6062. Remark: "",
  6063. WarehouseInfoId: info.WarehouseInfotId,
  6064. PatientId: info.PatientId,
  6065. RecordDate: info.SysRecordTime,
  6066. StorehouseId: houseConfig.StorehouseOutInfo,
  6067. IsCheck: 1,
  6068. }
  6069. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6070. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6071. flow := models.VmStockFlow{
  6072. WarehousingId: info.WarehouseInfotId,
  6073. GoodId: item.ProjectId,
  6074. Number: info.Number,
  6075. LicenseNumber: info.LicenseNumber,
  6076. Count: info.Count,
  6077. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6078. PatientId: item.PatientId,
  6079. SystemTime: info.SysRecordTime,
  6080. ConsumableType: 7,
  6081. IsSys: 0,
  6082. WarehousingOrder: "",
  6083. WarehouseOutId: info.WarehouseOutId,
  6084. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6085. IsEdit: 0,
  6086. CancelStockId: cancel.ID,
  6087. CancelOrderNumber: cancel.OrderNumber,
  6088. Manufacturer: manufacturer.ID,
  6089. Dealer: 0,
  6090. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6091. UpdateCreator: 0,
  6092. Status: 1,
  6093. Ctime: time.Now().Unix(),
  6094. Mtime: 0,
  6095. Price: info.Price,
  6096. WarehousingDetailId: info.WarehouseInfotId,
  6097. WarehouseOutDetailId: info.ID,
  6098. CancelOutDetailId: cancelInfo.ID,
  6099. ProductDate: info.ProductDate,
  6100. ExpireDate: info.ExpiryDate,
  6101. StorehouseId: houseConfig.StorehouseOutInfo,
  6102. OverCount: flush_count,
  6103. OperateTime: time.Now().Unix(),
  6104. }
  6105. service.CreateStockFlowOne(flow)
  6106. //退库数量增加
  6107. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6108. //出库数量减少
  6109. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6110. }
  6111. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6112. var flush_count int64
  6113. for _, it := range goodList {
  6114. flush_count += it.StockCount
  6115. }
  6116. //查询已出库数量
  6117. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6118. if prescribingNumber < dialysisInfo.Count {
  6119. //改变数量
  6120. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6121. }
  6122. if prescribingNumber >= dialysisInfo.Count {
  6123. //删除出库表
  6124. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6125. }
  6126. //更新库存
  6127. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6128. //更新基础库库存
  6129. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6130. }
  6131. }
  6132. }
  6133. }
  6134. //保存耗材出库
  6135. if goodOutConfig.IsOpen == 1 {
  6136. if item.Type == 3 {
  6137. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6138. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6139. good.Total = good.Total + f_count
  6140. service.UpdateGoodInfo(&good)
  6141. operation_time := time.Now().Unix()
  6142. creater := c.GetAdminUserInfo().AdminUser.Id
  6143. //创建退库单
  6144. timeStr := time.Now().Format("2006-01-02")
  6145. timeArr := strings.Split(timeStr, "-")
  6146. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6147. total = total + 1
  6148. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6149. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6150. cancelStock := models.CancelStock{
  6151. OrderNumber: orderNumber,
  6152. OperaTime: operation_time,
  6153. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6154. Creater: creater,
  6155. Ctime: time.Now().Unix(),
  6156. Status: 1,
  6157. ReturnTime: item.RecordDate,
  6158. Type: 1,
  6159. StorehouseId: houseConfig.StorehouseOutInfo,
  6160. IsCheck: 1,
  6161. }
  6162. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6163. if msgerrkonde == gorm.ErrRecordNotFound {
  6164. service.AddSigleCancelStock(&cancelStock)
  6165. }
  6166. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6167. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6168. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6169. //查询该耗材是否出库
  6170. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6171. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6172. deaerler, _ := service.GetDealerById(info.Dealer)
  6173. var total_count int64
  6174. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6175. total_count += count
  6176. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6177. var flush_count int64
  6178. for _, it := range goodList {
  6179. flush_count += it.StockCount
  6180. }
  6181. fmt.Println("历史出库数据", info.Count)
  6182. fmt.Println("出库数量", total_count)
  6183. if info.ID > 0 {
  6184. cancelStockInfo := models.CancelStockInfo{
  6185. GoodId: item.ProjectId,
  6186. CancelStockId: cancel.ID,
  6187. GoodTypeId: good.GoodTypeId,
  6188. Count: prescribingNumber,
  6189. Price: info.Price,
  6190. Total: 0,
  6191. ProductDate: info.ProductDate,
  6192. ExpiryDate: info.ExpiryDate,
  6193. Ctime: time.Now().Unix(),
  6194. Status: 1,
  6195. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6196. OrderNumber: cancel.OrderNumber,
  6197. Type: 0,
  6198. Dealer: deaerler.DealerName,
  6199. Manufacturer: manufacturer.ManufacturerName,
  6200. Number: info.Number,
  6201. RegisterAccount: "",
  6202. Remark: "",
  6203. WarehouseInfoId: info.WarehouseInfotId,
  6204. PatientId: info.PatientId,
  6205. RecordDate: info.SysRecordTime,
  6206. StorehouseId: houseConfig.StorehouseOutInfo,
  6207. IsCheck: 1,
  6208. }
  6209. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6210. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6211. //查询出库数量
  6212. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6213. //出库数据 大于 退库数量
  6214. if len(list) > 0 {
  6215. for _, it := range list {
  6216. //回退库存
  6217. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6218. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6219. var flush_count_one int64
  6220. for _, it := range goodList {
  6221. flush_count_one += it.StockCount
  6222. }
  6223. //查询该批次是否有退库数据
  6224. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6225. creater := c.GetAdminUserInfo().AdminUser.Id
  6226. flow := models.VmStockFlow{
  6227. WarehousingId: it.WarehouseInfotId,
  6228. GoodId: it.GoodId,
  6229. Number: it.Number,
  6230. LicenseNumber: it.LicenseNumber,
  6231. Count: it.Count,
  6232. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6233. PatientId: it.PatientId,
  6234. SystemTime: it.SysRecordTime,
  6235. ConsumableType: 7,
  6236. IsSys: 0,
  6237. WarehousingOrder: "",
  6238. WarehouseOutId: it.WarehouseOutId,
  6239. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6240. IsEdit: 0,
  6241. CancelStockId: cancel.ID,
  6242. CancelOrderNumber: cancel.OrderNumber,
  6243. Manufacturer: manufacturer.ID,
  6244. Dealer: 0,
  6245. Creator: creater,
  6246. UpdateCreator: 0,
  6247. Status: 1,
  6248. Ctime: time.Now().Unix(),
  6249. Mtime: 0,
  6250. Price: it.Price,
  6251. WarehousingDetailId: it.WarehouseInfotId,
  6252. WarehouseOutDetailId: it.ID,
  6253. CancelOutDetailId: cancelInfo.ID,
  6254. ProductDate: it.ProductDate,
  6255. ExpireDate: it.ExpiryDate,
  6256. StorehouseId: houseConfig.StorehouseOutInfo,
  6257. OverCount: flush_count_one,
  6258. OperateTime: time.Now().Unix(),
  6259. }
  6260. service.CreateStockFlowOne(flow)
  6261. //if flow.ID > 0 {
  6262. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6263. //}
  6264. }
  6265. }
  6266. //flow := models.VmStockFlow{
  6267. // WarehousingId: info.WarehouseInfotId,
  6268. // GoodId: item.ProjectId,
  6269. // Number: info.Number,
  6270. // LicenseNumber: info.LicenseNumber,
  6271. // Count: prescribingNumber,
  6272. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6273. // PatientId: item.PatientId,
  6274. // SystemTime: info.SysRecordTime,
  6275. // ConsumableType: 7,
  6276. // IsSys: 0,
  6277. // WarehousingOrder: "",
  6278. // WarehouseOutId: info.WarehouseOutId,
  6279. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6280. // IsEdit: 0,
  6281. // CancelStockId: cancel.ID,
  6282. // CancelOrderNumber: cancel.OrderNumber,
  6283. // Manufacturer: manufacturer.ID,
  6284. // Dealer: 0,
  6285. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6286. // UpdateCreator: 0,
  6287. // Status: 1,
  6288. // Ctime: time.Now().Unix(),
  6289. // Mtime: 0,
  6290. // Price: info.Price,
  6291. // WarehousingDetailId: info.WarehouseInfotId,
  6292. // WarehouseOutDetailId: info.ID,
  6293. // CancelOutDetailId: cancelInfo.ID,
  6294. // ProductDate: info.ProductDate,
  6295. // ExpireDate: info.ExpiryDate,
  6296. // StorehouseId: houseConfig.StorehouseOutInfo,
  6297. // OverCount: flush_count,
  6298. //}
  6299. //service.CreateStockFlowOne(flow)
  6300. //退库数量增加
  6301. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6302. //出库数量减少
  6303. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6304. //查询已出库数量
  6305. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6306. if prescribingNumber < dialysisInfo.Count {
  6307. //改变数量
  6308. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6309. }
  6310. if prescribingNumber >= dialysisInfo.Count {
  6311. //删除出库表
  6312. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6313. }
  6314. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6315. var flush_count_one int64
  6316. for _, it := range goodList {
  6317. flush_count_one += it.StockCount
  6318. }
  6319. //更新库存
  6320. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6321. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6322. //更新基础库库存
  6323. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6324. }
  6325. }
  6326. }
  6327. }
  6328. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6329. fmt.Println(err)
  6330. }
  6331. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6332. fmt.Println(err)
  6333. if len(advices) > 0 {
  6334. for _, item := range advices {
  6335. redis := service.RedisClient()
  6336. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6337. redis.Set(keyFive, "", time.Second)
  6338. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6339. redis.Set(keyOne, "", time.Second)
  6340. redis.Close()
  6341. }
  6342. }
  6343. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6344. if len(advices) > 0 {
  6345. for _, item := range advices {
  6346. creater := c.GetAdminUserInfo().AdminUser.Id
  6347. service.DrugAutoAddCancelInfo(item, creater)
  6348. }
  6349. }
  6350. } else {
  6351. if drugOutConfig.IsOpen == 1 {
  6352. if len(advices) > 0 {
  6353. for _, item := range advices {
  6354. creater := c.GetAdminUserInfo().AdminUser.Id
  6355. service.DrugAutoAddCancelInfo(item, creater)
  6356. }
  6357. }
  6358. } else {
  6359. if len(advices) > 0 {
  6360. for _, item := range advices {
  6361. creater := c.GetAdminUserInfo().AdminUser.Id
  6362. service.DrugAutoAddCancelInfo(item, creater)
  6363. }
  6364. }
  6365. }
  6366. }
  6367. c.ServeSuccessJSON(map[string]interface{}{
  6368. "msg": "删除成功",
  6369. })
  6370. return
  6371. }
  6372. func (c *HisApiController) DeleteDoctorAdvice() {
  6373. id, _ := c.GetInt64("id")
  6374. advice, _ := service.GetHisDoctorAdvicesById(id)
  6375. ////同步到自备药
  6376. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6377. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6378. if selfPrescriptionOpen.IsOpen == 1 {
  6379. db := service.XTWriteDB()
  6380. tx := db.Begin()
  6381. defer func() {
  6382. if r := recover(); r != nil {
  6383. tx.Rollback()
  6384. } else {
  6385. tx.Commit()
  6386. }
  6387. }()
  6388. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6389. var total_count int64
  6390. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6391. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6392. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6393. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6394. }
  6395. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6396. total_count += prescribingNumberSeven
  6397. }
  6398. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6399. total_count += prescribingNumberSeven
  6400. }
  6401. timeStr := time.Now().Format("2006-01-02")
  6402. timeArr := strings.Split(timeStr, "-")
  6403. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6404. total = total + 1
  6405. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6406. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6407. number = number + total
  6408. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6409. operation_time := time.Now().Unix()
  6410. creater := c.GetAdminUserInfo().AdminUser.Id
  6411. //创建一个出库单
  6412. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6413. WarehouseOutOrderNumber: warehousing_out_order,
  6414. OperationTime: operation_time,
  6415. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6416. Creater: creater,
  6417. Ctime: time.Now().Unix(),
  6418. Status: 1,
  6419. WarehouseOutTime: advice.AdviceDate,
  6420. Type: 0,
  6421. PatientId: advice.PatientId,
  6422. IsCheck: 1,
  6423. }
  6424. //查询今日是否有出库数据
  6425. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6426. if lastWarehouseOut.ID == 0 {
  6427. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6428. }
  6429. //出库
  6430. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6431. WarehouseOutId: lastWarehouseOut.ID,
  6432. WarehouseOutOrderNumber: warehousing_out_order,
  6433. DrugId: advice.DrugId,
  6434. Count: total_count,
  6435. Price: 0,
  6436. TotalPrice: 0,
  6437. Status: 1,
  6438. Ctime: advice.AdviceDate,
  6439. Mtime: advice.AdviceDate,
  6440. Remark: "",
  6441. OrgId: advice.UserOrgId,
  6442. Type: 0,
  6443. Manufacturer: selfBasedrug.Manufacturer,
  6444. Dealer: selfBasedrug.Dealer,
  6445. RetailPrice: 0,
  6446. RetailTotalPrice: 0,
  6447. CountUnit: advice.PrescribingNumberUnit,
  6448. ExpiryDate: 0,
  6449. ProductDate: 0,
  6450. Number: "",
  6451. BatchNumber: "",
  6452. IsSys: 0,
  6453. WarehouseInfoId: 0,
  6454. AdminUserId: 0,
  6455. StockCount: "",
  6456. IsCheck: 1,
  6457. SysRecordTime: advice.AdviceDate,
  6458. PatientId: advice.PatientId,
  6459. AdviceId: advice.ID,
  6460. ClassType: "",
  6461. }
  6462. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6463. for _, it := range warehousingOutInfo {
  6464. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6465. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6466. //出库逻辑
  6467. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6468. //查询剩余库存
  6469. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6470. var sum_count int64
  6471. for _, its := range stockInfo {
  6472. if its.MaxUnit == medical.MaxUnit {
  6473. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6474. }
  6475. sum_count += its.StockMaxNumber + its.StockMinNumber
  6476. }
  6477. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6478. }
  6479. }
  6480. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6481. //已收费和已发药的限制逻辑
  6482. isCharge := false
  6483. isMedicine := false
  6484. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6485. //获取今天该患者所有处方,判断是否发药或者收费
  6486. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6487. //for _, item := range new_prescriptions {
  6488. if new_prescription.IsMedicine == 1 {
  6489. isMedicine = true
  6490. }
  6491. //}
  6492. for _, item := range new_prescriptions {
  6493. if item.OrderStatus == 4 {
  6494. isCharge = true
  6495. }
  6496. }
  6497. if isMedicine {
  6498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6499. return
  6500. }
  6501. if isCharge {
  6502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6503. return
  6504. }
  6505. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6506. for _, item := range advices {
  6507. if item.IsMedicine == 1 {
  6508. isMedicine = true
  6509. }
  6510. }
  6511. if isMedicine {
  6512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6513. return
  6514. }
  6515. if new_prescription.ID > 0 {
  6516. if new_prescription.OrderStatus == 2 {
  6517. isCharge = true
  6518. }
  6519. }
  6520. if isCharge {
  6521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6522. return
  6523. }
  6524. //已收费和已发药的限制逻辑
  6525. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6526. redis := service.RedisClient()
  6527. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6528. redis.Set(keyFive, "", time.Second)
  6529. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6530. redis.Set(keyOne, "", time.Second)
  6531. defer redis.Close()
  6532. if err == nil {
  6533. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6534. //查询是否在处方中出库
  6535. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6536. if openConfig.IsOpen != 1 {
  6537. //判断该医嘱是否执行了
  6538. if advice.ExecutionState == 1 {
  6539. creater := c.GetAdminUserInfo().AdminUser.Id
  6540. service.DrugAutoAddCancelInfo(&advice, creater)
  6541. }
  6542. }
  6543. //开启保存处方扣减功能
  6544. if openConfig.IsOpen == 1 {
  6545. creater := c.GetAdminUserInfo().AdminUser.Id
  6546. service.DrugAutoAddCancelInfo(&advice, creater)
  6547. }
  6548. } else {
  6549. if drugOutConfig.IsOpen == 1 {
  6550. //查询是否在处方中出库
  6551. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6552. if openConfig.IsOpen != 1 {
  6553. //判断该医嘱是否执行了
  6554. if advice.ExecutionState == 1 {
  6555. creater := c.GetAdminUserInfo().AdminUser.Id
  6556. service.DrugAutoAddCancelInfo(&advice, creater)
  6557. }
  6558. }
  6559. //开启保存处方扣减功能
  6560. if openConfig.IsOpen == 1 {
  6561. creater := c.GetAdminUserInfo().AdminUser.Id
  6562. service.DrugAutoAddCancelInfo(&advice, creater)
  6563. }
  6564. } else {
  6565. //判断该医嘱是否执行了
  6566. if advice.ExecutionState == 1 {
  6567. creater := c.GetAdminUserInfo().AdminUser.Id
  6568. service.DrugAutoAddCancelInfo(&advice, creater)
  6569. }
  6570. }
  6571. }
  6572. c.ServeSuccessJSON(map[string]interface{}{
  6573. "msg": "删除成功",
  6574. })
  6575. return
  6576. } else {
  6577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6578. return
  6579. }
  6580. }
  6581. func (c *HisApiController) DeleteProject() {
  6582. id, _ := c.GetInt64("id")
  6583. adminInfo := c.GetAdminUserInfo()
  6584. project, _ := service.GetHisProjectByID(id)
  6585. // var consumable models.DialysisBeforePrepare
  6586. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6587. //耗材保存处方出库
  6588. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6589. isCharge := false
  6590. isMedicine := false
  6591. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6592. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6593. for _, item := range new_prescriptions {
  6594. if item.IsMedicine == 1 {
  6595. isMedicine = true
  6596. }
  6597. }
  6598. for _, item := range new_prescriptions {
  6599. if item.OrderStatus == 4 {
  6600. isCharge = true
  6601. }
  6602. }
  6603. if isMedicine {
  6604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6605. return
  6606. }
  6607. if isCharge {
  6608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6609. return
  6610. }
  6611. if new_prescription.ID > 0 {
  6612. if new_prescription.OrderStatus == 2 {
  6613. isCharge = true
  6614. }
  6615. }
  6616. if isCharge {
  6617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6618. return
  6619. }
  6620. service.DeletePrintInfo(id)
  6621. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  6622. label.Status = 0
  6623. service.CreateHisLabelRecordTwo(&label)
  6624. fmt.Println(goodOutConfig.IsOpen)
  6625. if goodOutConfig.IsOpen != 1 {
  6626. if stockConfig.IsOpen == 1 {
  6627. if project.Type == 2 {
  6628. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6629. fmt.Println(err)
  6630. }
  6631. if project.Type == 3 && project.IsOut == 1 {
  6632. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6633. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6634. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6635. operation_time := time.Now().Unix()
  6636. creater := adminInfo.AdminUser.Id
  6637. //创建退库单
  6638. timeStr := time.Now().Format("2006-01-02")
  6639. timeArr := strings.Split(timeStr, "-")
  6640. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6641. total = total + 1
  6642. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6643. cancelStock := models.CancelStock{
  6644. OrderNumber: orderNumber,
  6645. OperaTime: operation_time,
  6646. OrgId: adminInfo.CurrentOrgId,
  6647. Creater: creater,
  6648. Ctime: time.Now().Unix(),
  6649. Status: 1,
  6650. ReturnTime: project.RecordDate,
  6651. Type: 1,
  6652. StorehouseId: houseConfig.StorehouseOutInfo,
  6653. IsCheck: 1,
  6654. }
  6655. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6656. if msgerrkonde == gorm.ErrRecordNotFound {
  6657. service.AddSigleCancelStock(&cancelStock)
  6658. }
  6659. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6660. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6661. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6662. //查询是否有出库
  6663. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6664. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6665. deaerler, _ := service.GetDealerById(info.Dealer)
  6666. if info.ID > 0 {
  6667. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6668. if info.Count >= prescribingNumber {
  6669. cancelStockInfo := models.CancelStockInfo{
  6670. GoodId: project.ProjectId,
  6671. CancelStockId: cancel.ID,
  6672. GoodTypeId: good.GoodTypeId,
  6673. Count: prescribingNumber,
  6674. Price: info.Price,
  6675. Total: 0,
  6676. ProductDate: info.ProductDate,
  6677. ExpiryDate: info.ExpiryDate,
  6678. Ctime: time.Now().Unix(),
  6679. Status: 1,
  6680. OrgId: adminInfo.CurrentOrgId,
  6681. OrderNumber: cancel.OrderNumber,
  6682. Type: 0,
  6683. Dealer: deaerler.DealerName,
  6684. Manufacturer: manufacturer.ManufacturerName,
  6685. Number: info.Number,
  6686. RegisterAccount: "",
  6687. Remark: "",
  6688. WarehouseInfoId: info.WarehouseInfotId,
  6689. PatientId: info.PatientId,
  6690. RecordDate: info.SysRecordTime,
  6691. StorehouseId: houseConfig.StorehouseOutInfo,
  6692. IsCheck: 1,
  6693. }
  6694. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6695. //回退库存
  6696. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6697. //退库数量增加
  6698. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6699. //出库数量减少
  6700. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6701. }
  6702. if info.Count < prescribingNumber {
  6703. cancelStockInfo := models.CancelStockInfo{
  6704. GoodId: project.ProjectId,
  6705. CancelStockId: cancel.ID,
  6706. GoodTypeId: good.GoodTypeId,
  6707. Count: info.Count,
  6708. Price: info.Price,
  6709. Total: 0,
  6710. ProductDate: info.ProductDate,
  6711. ExpiryDate: info.ExpiryDate,
  6712. Ctime: time.Now().Unix(),
  6713. Status: 1,
  6714. OrgId: adminInfo.CurrentOrgId,
  6715. OrderNumber: cancel.OrderNumber,
  6716. Type: 0,
  6717. Dealer: deaerler.DealerName,
  6718. Manufacturer: manufacturer.ManufacturerName,
  6719. Number: info.Number,
  6720. RegisterAccount: "",
  6721. Remark: "",
  6722. WarehouseInfoId: info.WarehouseInfotId,
  6723. PatientId: info.PatientId,
  6724. RecordDate: info.SysRecordTime,
  6725. StorehouseId: houseConfig.StorehouseOutInfo,
  6726. IsCheck: 1,
  6727. }
  6728. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6729. //回退库存
  6730. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6731. //退库数量增加
  6732. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6733. //出库数量减少
  6734. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6735. }
  6736. //查询剩余库存
  6737. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6738. var over_count int64
  6739. for _, it := range goodList {
  6740. over_count += it.StockCount
  6741. }
  6742. //出库数据 大于 退库数量
  6743. if info.Count >= prescribingNumber {
  6744. flow := models.VmStockFlow{
  6745. WarehousingId: info.WarehouseInfotId,
  6746. GoodId: project.ProjectId,
  6747. Number: info.Number,
  6748. LicenseNumber: info.LicenseNumber,
  6749. Count: prescribingNumber,
  6750. UserOrgId: adminInfo.CurrentOrgId,
  6751. PatientId: project.PatientId,
  6752. SystemTime: info.SysRecordTime,
  6753. ConsumableType: 7,
  6754. IsSys: 0,
  6755. WarehousingOrder: "",
  6756. WarehouseOutId: info.WarehouseOutId,
  6757. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6758. IsEdit: 0,
  6759. CancelStockId: cancel.ID,
  6760. CancelOrderNumber: cancel.OrderNumber,
  6761. Manufacturer: manufacturer.ID,
  6762. Dealer: 0,
  6763. Creator: adminInfo.AdminUser.Id,
  6764. UpdateCreator: 0,
  6765. Status: 1,
  6766. Ctime: time.Now().Unix(),
  6767. Mtime: 0,
  6768. Price: info.Price,
  6769. WarehousingDetailId: info.WarehouseInfotId,
  6770. WarehouseOutDetailId: info.ID,
  6771. CancelOutDetailId: cancelInfo.ID,
  6772. ProductDate: info.ProductDate,
  6773. ExpireDate: info.ExpiryDate,
  6774. StorehouseId: houseConfig.StorehouseOutInfo,
  6775. OverCount: over_count,
  6776. OperateTime: time.Now().Unix(),
  6777. }
  6778. service.CreateStockFlowOne(flow)
  6779. }
  6780. //出库数据小于退库数据
  6781. if info.Count < prescribingNumber {
  6782. flow := models.VmStockFlow{
  6783. WarehousingId: info.WarehouseInfotId,
  6784. GoodId: project.ProjectId,
  6785. Number: info.Number,
  6786. LicenseNumber: info.LicenseNumber,
  6787. Count: info.Count,
  6788. UserOrgId: adminInfo.CurrentOrgId,
  6789. PatientId: project.PatientId,
  6790. SystemTime: info.SysRecordTime,
  6791. ConsumableType: 7,
  6792. IsSys: 0,
  6793. WarehousingOrder: "",
  6794. WarehouseOutId: info.WarehouseOutId,
  6795. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6796. IsEdit: 0,
  6797. CancelStockId: cancel.ID,
  6798. CancelOrderNumber: cancel.OrderNumber,
  6799. Manufacturer: manufacturer.ID,
  6800. Dealer: 0,
  6801. Creator: adminInfo.AdminUser.Id,
  6802. UpdateCreator: 0,
  6803. Status: 1,
  6804. Ctime: time.Now().Unix(),
  6805. Mtime: 0,
  6806. Price: info.Price,
  6807. WarehousingDetailId: info.WarehouseInfotId,
  6808. WarehouseOutDetailId: info.ID,
  6809. CancelOutDetailId: cancelInfo.ID,
  6810. ProductDate: info.ProductDate,
  6811. ExpireDate: info.ExpiryDate,
  6812. StorehouseId: houseConfig.StorehouseOutInfo,
  6813. OverCount: over_count,
  6814. OperateTime: time.Now().Unix(),
  6815. }
  6816. service.CreateStockFlowOne(flow)
  6817. }
  6818. //查询已出库数量
  6819. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6820. if prescribingNumber < dialysisInfo.Count {
  6821. //改变数量
  6822. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6823. }
  6824. if prescribingNumber >= dialysisInfo.Count {
  6825. //删除出库表
  6826. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6827. }
  6828. //更新剩余库存
  6829. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6830. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6831. var total_count_one int64
  6832. for _, it := range stockList {
  6833. total_count_one += it.StockCount
  6834. }
  6835. //基础库插入数据
  6836. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6837. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6838. var flush_count int64
  6839. for _, it := range goodListOne {
  6840. flush_count += it.StockCount
  6841. }
  6842. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6843. if errs != nil {
  6844. goodErrcode := models.XtGoodErrcode{
  6845. UserOrgId: project.UserOrgId,
  6846. Errcode: "手动出库更新剩余出库失败",
  6847. GoodId: project.ProjectId,
  6848. Status: 1,
  6849. Ctime: time.Now().Unix(),
  6850. Mtime: 0,
  6851. Count: 0,
  6852. StockCount: 0,
  6853. Creater: creater,
  6854. BatchNumberId: 0,
  6855. WarehouseOutId: 0,
  6856. }
  6857. service.CreateGoodErrcode(goodErrcode)
  6858. }
  6859. }
  6860. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6861. fmt.Println(err)
  6862. } else {
  6863. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6864. fmt.Println(err)
  6865. }
  6866. } else {
  6867. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6868. fmt.Println(err)
  6869. }
  6870. }
  6871. //保存处方出库
  6872. if goodOutConfig.IsOpen == 1 {
  6873. if project.Type == 3 {
  6874. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6875. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6876. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6877. operation_time := time.Now().Unix()
  6878. creater := adminInfo.AdminUser.Id
  6879. //创建退库单
  6880. timeStr := time.Now().Format("2006-01-02")
  6881. timeArr := strings.Split(timeStr, "-")
  6882. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6883. total = total + 1
  6884. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6885. cancelStock := models.CancelStock{
  6886. OrderNumber: orderNumber,
  6887. OperaTime: operation_time,
  6888. OrgId: adminInfo.CurrentOrgId,
  6889. Creater: creater,
  6890. Ctime: time.Now().Unix(),
  6891. Status: 1,
  6892. ReturnTime: project.RecordDate,
  6893. Type: 1,
  6894. StorehouseId: houseConfig.StorehouseOutInfo,
  6895. IsCheck: 1,
  6896. }
  6897. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6898. if msgerrkonde == gorm.ErrRecordNotFound {
  6899. service.AddSigleCancelStock(&cancelStock)
  6900. }
  6901. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6902. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6903. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6904. //获取出库数据
  6905. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6906. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6907. deaerler, _ := service.GetDealerById(info.Dealer)
  6908. if info.ID > 0 {
  6909. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6910. if info.Count >= prescribingNumber {
  6911. cancelStockInfo := models.CancelStockInfo{
  6912. GoodId: project.ProjectId,
  6913. CancelStockId: cancel.ID,
  6914. GoodTypeId: good.GoodTypeId,
  6915. Count: prescribingNumber,
  6916. Price: info.Price,
  6917. Total: 0,
  6918. ProductDate: info.ProductDate,
  6919. ExpiryDate: info.ExpiryDate,
  6920. Ctime: time.Now().Unix(),
  6921. Status: 1,
  6922. OrgId: adminInfo.CurrentOrgId,
  6923. OrderNumber: cancel.OrderNumber,
  6924. Type: 0,
  6925. Dealer: deaerler.DealerName,
  6926. Manufacturer: manufacturer.ManufacturerName,
  6927. Number: info.Number,
  6928. RegisterAccount: "",
  6929. Remark: "",
  6930. WarehouseInfoId: info.WarehouseInfotId,
  6931. PatientId: info.PatientId,
  6932. RecordDate: info.SysRecordTime,
  6933. StorehouseId: houseConfig.StorehouseOutInfo,
  6934. IsCheck: 1,
  6935. }
  6936. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6937. //退库数量增加
  6938. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6939. //出库数量减少
  6940. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6941. }
  6942. if info.Count < prescribingNumber {
  6943. cancelStockInfo := models.CancelStockInfo{
  6944. GoodId: project.ProjectId,
  6945. CancelStockId: cancel.ID,
  6946. GoodTypeId: good.GoodTypeId,
  6947. Count: prescribingNumber,
  6948. Price: info.Price,
  6949. Total: 0,
  6950. ProductDate: info.ProductDate,
  6951. ExpiryDate: info.ExpiryDate,
  6952. Ctime: time.Now().Unix(),
  6953. Status: 1,
  6954. OrgId: adminInfo.CurrentOrgId,
  6955. OrderNumber: cancel.OrderNumber,
  6956. Type: 0,
  6957. Dealer: deaerler.DealerName,
  6958. Manufacturer: manufacturer.ManufacturerName,
  6959. Number: info.Number,
  6960. RegisterAccount: "",
  6961. Remark: "",
  6962. WarehouseInfoId: info.WarehouseInfotId,
  6963. PatientId: info.PatientId,
  6964. RecordDate: info.SysRecordTime,
  6965. StorehouseId: houseConfig.StorehouseOutInfo,
  6966. IsCheck: 1,
  6967. }
  6968. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6969. //回退库存
  6970. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6971. }
  6972. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6973. var over_count int64
  6974. for _, it := range goodList {
  6975. over_count += it.StockCount
  6976. }
  6977. //查询出库数量
  6978. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6979. //出库数据 大于 退库数量
  6980. if len(list) > 0 {
  6981. for _, it := range list {
  6982. //回退库存
  6983. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6984. //退库数量增加
  6985. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6986. //出库数量减少
  6987. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6988. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6989. var over_count_one int64
  6990. for _, it := range goodList {
  6991. over_count_one += it.StockCount
  6992. }
  6993. //查询该批次是否有退库数据
  6994. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6995. flow := models.VmStockFlow{
  6996. WarehousingId: it.WarehouseInfotId,
  6997. GoodId: it.GoodId,
  6998. Number: it.Number,
  6999. LicenseNumber: it.LicenseNumber,
  7000. Count: it.Count,
  7001. UserOrgId: adminInfo.CurrentOrgId,
  7002. PatientId: it.PatientId,
  7003. SystemTime: it.SysRecordTime,
  7004. ConsumableType: 7,
  7005. IsSys: 0,
  7006. WarehousingOrder: "",
  7007. WarehouseOutId: it.WarehouseOutId,
  7008. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7009. IsEdit: 0,
  7010. CancelStockId: cancel.ID,
  7011. CancelOrderNumber: cancel.OrderNumber,
  7012. Manufacturer: manufacturer.ID,
  7013. Dealer: 0,
  7014. Creator: adminInfo.AdminUser.Id,
  7015. UpdateCreator: 0,
  7016. Status: 1,
  7017. Ctime: time.Now().Unix(),
  7018. Mtime: 0,
  7019. Price: it.Price,
  7020. WarehousingDetailId: it.WarehouseInfotId,
  7021. WarehouseOutDetailId: it.ID,
  7022. CancelOutDetailId: cancelInfo.ID,
  7023. ProductDate: it.ProductDate,
  7024. ExpireDate: it.ExpiryDate,
  7025. StorehouseId: houseConfig.StorehouseOutInfo,
  7026. OverCount: over_count_one,
  7027. OperateTime: time.Now().Unix(),
  7028. }
  7029. service.CreateStockFlowOne(flow)
  7030. }
  7031. }
  7032. //查询已出库数量
  7033. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7034. if prescribingNumber < dialysisInfo.Count {
  7035. //改变数量
  7036. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7037. }
  7038. if prescribingNumber >= dialysisInfo.Count {
  7039. //删除出库表
  7040. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7041. }
  7042. //更新剩余库存
  7043. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7044. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7045. var total_count_one int64
  7046. for _, it := range stockList {
  7047. total_count_one += it.StockCount
  7048. }
  7049. //基础库插入数据
  7050. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7051. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7052. var flush_count int64
  7053. for _, it := range goodListOne {
  7054. flush_count += it.StockCount
  7055. }
  7056. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7057. if errs != nil {
  7058. goodErrcode := models.XtGoodErrcode{
  7059. UserOrgId: project.UserOrgId,
  7060. Errcode: "手动出库更新剩余出库失败",
  7061. GoodId: project.ProjectId,
  7062. Status: 1,
  7063. Ctime: time.Now().Unix(),
  7064. Mtime: 0,
  7065. Count: 0,
  7066. StockCount: 0,
  7067. Creater: creater,
  7068. BatchNumberId: 0,
  7069. WarehouseOutId: 0,
  7070. }
  7071. service.CreateGoodErrcode(goodErrcode)
  7072. }
  7073. }
  7074. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7075. fmt.Println(err)
  7076. } else {
  7077. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7078. fmt.Println(err)
  7079. }
  7080. }
  7081. c.ServeSuccessJSON(map[string]interface{}{
  7082. "msg": "删除成功",
  7083. })
  7084. return
  7085. }
  7086. func (c *HisApiController) CreateHisAdditionalCharge() {
  7087. his_patient_id, _ := c.GetInt64("his_patient_id")
  7088. patient_id, _ := c.GetInt64("patient_id")
  7089. record_date := c.GetString("record_date")
  7090. timeLayout := "2006-01-02"
  7091. loc, _ := time.LoadLocation("Local")
  7092. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7093. if err != nil {
  7094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7095. return
  7096. }
  7097. adminInfo := c.GetAdminUserInfo()
  7098. recordDateTime := theTime.Unix()
  7099. dataBody := make(map[string]interface{}, 0)
  7100. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7101. if err != nil {
  7102. utils.ErrorLog(err.Error())
  7103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7104. return
  7105. }
  7106. var additions []*models.HisAdditionalCharge
  7107. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7108. additions, _ := dataBody["addition"].([]interface{})
  7109. if len(additions) > 0 {
  7110. for _, item := range additions {
  7111. items := item.(map[string]interface{})
  7112. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7113. utils.ErrorLog("item_id")
  7114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7115. return
  7116. }
  7117. item_id := int64(items["item_id"].(float64))
  7118. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7119. utils.ErrorLog("item_name")
  7120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7121. return
  7122. }
  7123. item_name := items["item_name"].(string)
  7124. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7125. utils.ErrorLog("price")
  7126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7127. return
  7128. }
  7129. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7130. ctime := time.Now().Unix()
  7131. additional := &models.HisAdditionalCharge{
  7132. PatientId: patient_id,
  7133. HisPatientId: his_patient_id,
  7134. UserOrgId: adminInfo.CurrentOrgId,
  7135. RecordDate: recordDateTime,
  7136. CreatedTime: ctime,
  7137. UpdatedTime: ctime,
  7138. Modifier: adminInfo.AdminUser.Id,
  7139. Creator: adminInfo.AdminUser.Id,
  7140. Price: price,
  7141. ItemName: item_name,
  7142. ItemId: item_id,
  7143. Status: 1,
  7144. }
  7145. additions = append(additions, additional)
  7146. }
  7147. }
  7148. }
  7149. for _, item := range additions {
  7150. service.CreateAddtionalCharge(item)
  7151. }
  7152. c.ServeSuccessJSON(map[string]interface{}{
  7153. "msg": "创建成功",
  7154. })
  7155. }
  7156. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7157. blood_fat := c.GetString("blood_fat")
  7158. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7159. blood_sugar := c.GetString("blood_sugar")
  7160. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7161. chief_conplaint := c.GetString("chief_conplaint")
  7162. dbp := c.GetString("dbp")
  7163. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7164. delivery_way, _ := c.GetInt64("delivery_way")
  7165. diagnostic := c.GetString("diagnostic")
  7166. family_history := c.GetString("family_history")
  7167. height := c.GetString("height")
  7168. history_of_present_illness := c.GetString("history_of_present_illness")
  7169. is_infect, _ := c.GetInt64("is_infect")
  7170. past_history := c.GetString("past_history")
  7171. patient_id, _ := c.GetInt64("patient_id")
  7172. his_patient_id, _ := c.GetInt64("his_patient_id")
  7173. personal_history := c.GetString("personal_history")
  7174. pulse := c.GetString("pulse")
  7175. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7176. sbp := c.GetString("sbp")
  7177. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7178. heightfloat, _ := strconv.ParseFloat(height, 64)
  7179. sicktype := c.GetString("sick_type")
  7180. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7181. symptom := c.GetString("symptom")
  7182. sick_date := c.GetString("sick_date")
  7183. temperatures := c.GetString("temperature")
  7184. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7185. record_date := c.GetString("record_date")
  7186. breathing := c.GetString("breathing")
  7187. doctor_advice := c.GetString("doctor_advice")
  7188. remark := c.GetString("remark")
  7189. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7190. sick, _ := c.GetInt64("sick")
  7191. diagnose, _ := c.GetInt64("diagnose")
  7192. //id, _ := c.GetInt64("id")
  7193. timeLayout := "2006-01-02"
  7194. loc, _ := time.LoadLocation("Local")
  7195. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7196. allergic_history := c.GetString("allergic_history")
  7197. if err != nil {
  7198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7199. return
  7200. }
  7201. recordDateTime := theTime.Unix()
  7202. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7203. if err != nil {
  7204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7205. return
  7206. }
  7207. sickTimes := sickTime.Unix()
  7208. ctime := time.Now().Unix()
  7209. primary_disease := c.GetString("primary_disease")
  7210. confirm_failure_date := c.GetString("confirm_failure_date")
  7211. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7212. drug_allergy_history := c.GetString("drug_allergy_history")
  7213. physical_examination := c.GetString("physical_examination")
  7214. special_inspection := c.GetString("special_inspection")
  7215. lab_apparatus := c.GetString("lab_apparatus")
  7216. caseHistory := models.HisPatientCaseHistory{
  7217. HisPatientId: his_patient_id,
  7218. PatientId: patient_id,
  7219. Temperature: temperature,
  7220. BloodSugar: bloodsugarfloat,
  7221. Pulse: pulsefloat,
  7222. Sbp: sbpfloat,
  7223. Dbp: dbpfloat,
  7224. Height: heightfloat,
  7225. BloodFat: bloodfatfloat,
  7226. SickType: sick_type,
  7227. Symptom: symptom,
  7228. SickDate: sickTimes,
  7229. IsInfect: is_infect,
  7230. HistoryOfPresentIllness: history_of_present_illness,
  7231. PastHistory: past_history,
  7232. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7233. ChiefConplaint: chief_conplaint,
  7234. PersonalHistory: personal_history,
  7235. FamilyHistory: family_history,
  7236. Diagnostic: diagnostic,
  7237. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7238. Status: 1,
  7239. Ctime: ctime,
  7240. Mtime: ctime,
  7241. RecordDate: recordDateTime,
  7242. DeliveryWay: delivery_way,
  7243. Breathing: breathingfloat,
  7244. DoctorAdvice: doctor_advice,
  7245. Remark: remark,
  7246. Sick: sick,
  7247. Diagnose: diagnose,
  7248. AllergicHistory: allergic_history,
  7249. PrimaryDisease: primary_disease,
  7250. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7251. DrugAllergyHistory: drug_allergy_history,
  7252. PhysicalExamination: physical_examination,
  7253. SpecialInspection: special_inspection,
  7254. LabApparatus: lab_apparatus,
  7255. }
  7256. //查询该患者是否有病历
  7257. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7258. if errcodes == gorm.ErrRecordNotFound {
  7259. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7260. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7261. if err != nil {
  7262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7263. return
  7264. }
  7265. c.ServeSuccessJSON(map[string]interface{}{
  7266. "caseHistory": caseHistory,
  7267. "historyInfo": historyInfo,
  7268. })
  7269. return
  7270. } else if errcodes == nil {
  7271. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7272. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7273. if err != nil {
  7274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7275. return
  7276. }
  7277. c.ServeSuccessJSON(map[string]interface{}{
  7278. "caseHistory": caseHistory,
  7279. "historyInfo": historyInfo,
  7280. })
  7281. }
  7282. //查询该患者是否有病历
  7283. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7284. //if errcode == gorm.ErrRecordNotFound {
  7285. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7286. // if err != nil {
  7287. // c.ServeSuccessJSON(map[string]interface{}{
  7288. // "msg": "保存成功",
  7289. // })
  7290. // }
  7291. //} else if errcode == nil {
  7292. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7293. // return
  7294. //}
  7295. }
  7296. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7297. patient_id, _ := c.GetInt64("patient_id", 0)
  7298. adminUser := c.GetAdminUserInfo()
  7299. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7300. c.ServeSuccessJSON(map[string]interface{}{
  7301. "list": caseHistorys,
  7302. })
  7303. }
  7304. func (c *HisApiController) GetHisPatientCaseHistory() {
  7305. record_date, _ := c.GetInt64("record_date", 0)
  7306. patient_id, _ := c.GetInt64("patient_id", 0)
  7307. admin := c.GetAdminUserInfo()
  7308. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7309. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7310. c.ServeSuccessJSON(map[string]interface{}{
  7311. "info": info,
  7312. "case_history": case_history,
  7313. })
  7314. }
  7315. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7316. template_name := c.GetString("template_name")
  7317. template_remark := c.GetString("template_remark")
  7318. doctor := c.GetAdminUserInfo().AdminUser.Id
  7319. diagnostic := c.GetString("diagnostic")
  7320. chief_conplaint := c.GetString("chief_conplain")
  7321. history_of_present_illness := c.GetString("history_of_present_illness")
  7322. past_history := c.GetString("past_history")
  7323. personal_history := c.GetString("personal_history")
  7324. family_history := c.GetString("family_history")
  7325. user_name := c.GetString("user_name")
  7326. doctor_advice := c.GetString("doctor_advice")
  7327. remark := c.GetString("remark")
  7328. //record_date := c.GetString("record_date")
  7329. //fmt.Println("record_date--------",record_date)
  7330. //timeLayout := "2006-01-02"
  7331. //loc, _ := time.LoadLocation("Local")
  7332. //
  7333. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7334. //if err != nil {
  7335. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7336. // return
  7337. //}
  7338. //recordDateTime := theTime.Unix()
  7339. ctime := time.Now().Unix()
  7340. template := models.HisCaseHistoryTemplate{
  7341. HistoryOfPresentIllness: history_of_present_illness,
  7342. PastHistory: past_history,
  7343. ChiefConplaint: chief_conplaint,
  7344. PersonalHistory: personal_history,
  7345. FamilyHistory: family_history,
  7346. Diagnostic: diagnostic,
  7347. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7348. Status: 1,
  7349. Ctime: ctime,
  7350. Mtime: ctime,
  7351. RecordDate: time.Now().Unix(),
  7352. TemplateName: template_name,
  7353. TemplateRemark: template_remark,
  7354. Creator: doctor,
  7355. Modifier: doctor,
  7356. UserName: user_name,
  7357. DoctorAdvice: doctor_advice,
  7358. Remark: remark,
  7359. }
  7360. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7361. if err == nil {
  7362. c.ServeSuccessJSON(map[string]interface{}{
  7363. "msg": "保存成功",
  7364. })
  7365. } else {
  7366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7367. return
  7368. }
  7369. }
  7370. func (c *HisApiController) GetCaseHistoryTemplate() {
  7371. timeLayout := "2006-01-02"
  7372. loc, _ := time.LoadLocation("Local")
  7373. keyword := c.GetString("keyword")
  7374. start_time := c.GetString("start_time")
  7375. end_time := c.GetString("end_time")
  7376. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7377. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7378. admin := c.GetAdminUserInfo()
  7379. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7380. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7381. c.ServeSuccessJSON(map[string]interface{}{
  7382. "template": template,
  7383. //"history": history,
  7384. })
  7385. }
  7386. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7387. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7388. utils.ErrorLog("drug_name")
  7389. return enums.ErrorCodeParamWrong
  7390. }
  7391. adviceName, _ := json["drug_name"].(string)
  7392. if len(adviceName) == 0 {
  7393. utils.ErrorLog("len(advice_name) == 0")
  7394. return enums.ErrorCodeParamWrong
  7395. }
  7396. advice.AdviceName = adviceName
  7397. adviceDesc, _ := json["advice_desc"].(string)
  7398. advice.AdviceDesc = adviceDesc
  7399. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7400. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7401. advice.DrugSpec = drugSpec
  7402. }
  7403. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7404. remark, _ := json["remark"].(string)
  7405. advice.Remark = remark
  7406. }
  7407. if json["id"] == nil {
  7408. advice.DrugId = 0
  7409. } else {
  7410. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7411. drug_id := int64(json["id"].(float64))
  7412. advice.DrugId = drug_id
  7413. }
  7414. }
  7415. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7416. advice_id := int64(json["advice_id"].(float64))
  7417. advice.ID = advice_id
  7418. if advice.ID > 0 {
  7419. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7420. if err == nil {
  7421. if hisAdvice.ID > 0 {
  7422. advice.ExecutionTime = hisAdvice.ExecutionTime
  7423. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7424. advice.ExecutionState = hisAdvice.ExecutionState
  7425. advice.CheckTime = hisAdvice.CheckTime
  7426. advice.Checker = hisAdvice.Checker
  7427. advice.CheckState = hisAdvice.CheckState
  7428. advice.StartTime = hisAdvice.StartTime
  7429. advice.FeedetlSn = hisAdvice.FeedetlSn
  7430. }
  7431. }
  7432. }
  7433. }
  7434. //
  7435. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7436. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7437. // advice.ExecutionTime = execution_time
  7438. //}
  7439. //
  7440. //
  7441. //
  7442. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7443. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7444. // advice.ExecutionStaff = execution_staff
  7445. //}
  7446. //
  7447. //
  7448. //
  7449. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7450. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7451. // advice.ExecutionState = execution_state
  7452. //}
  7453. //
  7454. //
  7455. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7456. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7457. // advice.CheckTime = check_time
  7458. //}
  7459. //
  7460. //
  7461. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7462. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7463. // advice.CheckState = check_state
  7464. //}
  7465. //
  7466. //
  7467. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7468. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7469. // advice.Checker = checker
  7470. //}
  7471. //
  7472. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7473. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7474. // advice.StartTime = start_time
  7475. //}
  7476. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7477. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7478. advice.IsSelfDrug = is_self_drug
  7479. }
  7480. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7481. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7482. drug_way_count, _ := json["drug_way_count"].(string)
  7483. advice.DrugWayCount = drug_way_count
  7484. }
  7485. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7486. drugSpecUnit, _ := json["min_unit"].(string)
  7487. advice.DrugSpecUnit = drugSpecUnit
  7488. }
  7489. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7490. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7491. advice.SingleDose = singleDose
  7492. }
  7493. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7494. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7495. advice.SingleDoseUnit = singleDoseUnit
  7496. }
  7497. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7498. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7499. advice.PrescribingNumber = prescribingNumber
  7500. }
  7501. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7502. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7503. advice.PrescribingNumberUnit = prescribingNumberUnit
  7504. }
  7505. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7506. deliveryWay, _ := json["delivery_way"].(string)
  7507. advice.DeliveryWay = deliveryWay
  7508. }
  7509. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7510. executionFrequency, _ := json["execution_frequency"].(string)
  7511. advice.ExecutionFrequency = executionFrequency
  7512. }
  7513. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7514. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7515. advice.Price = price
  7516. }
  7517. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7518. med_list_codg, _ := json["medical_insurance_number"].(string)
  7519. advice.MedListCodg = med_list_codg
  7520. }
  7521. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7522. day := int64(json["day"].(float64))
  7523. advice.Day = day
  7524. }
  7525. return 0
  7526. }
  7527. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7528. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7529. id := int64(json["id"].(float64))
  7530. project.ID = id
  7531. historyProject, _ := service.GetHisProjectByID(id)
  7532. project.FeedetlSn = historyProject.FeedetlSn
  7533. }
  7534. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7535. project_id := int64(json["project_id"].(float64))
  7536. project.ProjectId = project_id
  7537. }
  7538. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7539. // price := int64(json["price"].(float64))
  7540. // formatInt_price := strconv.FormatInt(price, 10)
  7541. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7542. // project.Price = float_price
  7543. // }
  7544. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7545. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7546. project.Price = price
  7547. }
  7548. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7549. total, _ := json["total"].(string)
  7550. project.Count = total
  7551. }
  7552. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7553. medical_code, _ := json["medical_code"].(string)
  7554. project.MedListCodg = medical_code
  7555. }
  7556. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7557. single_dose, _ := json["single_dose"].(string)
  7558. project.SingleDose = single_dose
  7559. }
  7560. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7561. delivery_way, _ := json["delivery_way"].(string)
  7562. project.DeliveryWay = delivery_way
  7563. }
  7564. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7565. execution_frequency, _ := json["execution_frequency"].(string)
  7566. project.ExecutionFrequency = execution_frequency
  7567. }
  7568. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7569. remark, _ := json["remark"].(string)
  7570. project.Remark = remark
  7571. }
  7572. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7573. day, _ := json["number_days"].(string)
  7574. project.Day = day
  7575. }
  7576. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7577. unit, _ := json["unit"].(string)
  7578. project.Unit = unit
  7579. }
  7580. return 0
  7581. }
  7582. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7583. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7584. id := int64(json["id"].(float64))
  7585. historyAddtions, _ := service.GetHisAdditionByID(id)
  7586. additionalCharge.ID = id
  7587. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  7588. }
  7589. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7590. item_id := int64(json["item_id"].(float64))
  7591. additionalCharge.ItemId = item_id
  7592. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7593. if config.ID > 0 {
  7594. if len(config.Code) > 0 {
  7595. additionalCharge.MedListCodg = config.Code
  7596. }
  7597. }
  7598. }
  7599. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7600. // price := int64(json["price"].(float64))
  7601. // formatInt_price := strconv.FormatInt(price, 10)
  7602. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7603. // additionalCharge.Price = float_price
  7604. // }
  7605. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7606. // price := int64(json["price"].(float64))
  7607. // formatInt_price := strconv.FormatInt(price, 10)
  7608. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7609. // additionalCharge.Price = float_price
  7610. //}
  7611. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7612. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7613. additionalCharge.Price = price
  7614. }
  7615. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7616. count, _ := json["count"].(string)
  7617. counts, _ := strconv.ParseInt(count, 10, 64)
  7618. additionalCharge.Count = counts
  7619. }
  7620. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7621. item_name, _ := json["item_name"].(string)
  7622. additionalCharge.ItemName = item_name
  7623. }
  7624. return 0
  7625. }
  7626. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7627. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7628. utils.ErrorLog("drug_name")
  7629. return enums.ErrorCodeParamWrong
  7630. }
  7631. adviceName, _ := json["drug_name"].(string)
  7632. if len(adviceName) == 0 {
  7633. utils.ErrorLog("len(advice_name) == 0")
  7634. return enums.ErrorCodeParamWrong
  7635. }
  7636. advice.AdviceName = adviceName
  7637. adviceDesc, _ := json["advice_desc"].(string)
  7638. advice.AdviceDesc = adviceDesc
  7639. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7640. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7641. advice.DrugSpec = drugSpec
  7642. }
  7643. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7644. remark, _ := json["remark"].(string)
  7645. advice.Remark = remark
  7646. }
  7647. if json["id"] == nil {
  7648. advice.DrugId = 0
  7649. } else {
  7650. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7651. drug_id := int64(json["id"].(float64))
  7652. advice.DrugId = drug_id
  7653. }
  7654. }
  7655. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7656. groupno := int64(json["groupno"].(float64))
  7657. advice.Groupno = groupno
  7658. }
  7659. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7660. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7661. advice.IsSelfDrug = is_self_drug
  7662. }
  7663. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7664. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7665. drug_way_count, _ := json["drug_way_count"].(string)
  7666. advice.DrugWayCount = drug_way_count
  7667. }
  7668. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7669. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7670. advice.HospApprFlag = hosp_appr_flag
  7671. }
  7672. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7673. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7674. advice.PrescribingNumber = prescribingNumber
  7675. }
  7676. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7677. // frequency_type := int64(json["frequency_type"].(float64))
  7678. // advice.FrequencyType = frequency_type
  7679. //}
  7680. //
  7681. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7682. // day_count := int64(json["day_count"].(float64))
  7683. // advice.DayCount = day_count
  7684. //}
  7685. //
  7686. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7687. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7688. // week_day, _ := json["week_day"].(string)
  7689. // advice.WeekDay = week_day
  7690. //}
  7691. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7692. drugSpecUnit, _ := json["min_unit"].(string)
  7693. advice.DrugSpecUnit = drugSpecUnit
  7694. }
  7695. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7696. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7697. advice.SingleDose = singleDose
  7698. }
  7699. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7700. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7701. advice.SingleDoseUnit = singleDoseUnit
  7702. }
  7703. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7704. deliveryWay, _ := json["delivery_way"].(string)
  7705. advice.DeliveryWay = deliveryWay
  7706. }
  7707. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7708. executionFrequency, _ := json["execution_frequency"].(string)
  7709. advice.ExecutionFrequency = executionFrequency
  7710. }
  7711. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7712. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7713. advice.Price = price
  7714. }
  7715. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7716. med_list_codg, _ := json["medical_insurance_number"].(string)
  7717. advice.MedListCodg = med_list_codg
  7718. }
  7719. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7720. day := int64(json["day"].(float64))
  7721. advice.Day = day
  7722. }
  7723. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7724. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7725. advice.PrescribingNumberUnit = prescribingNumberUnit
  7726. }
  7727. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7728. advice_id := int64(json["advice_id"].(float64))
  7729. advice.ID = advice_id
  7730. if advice.ID > 0 {
  7731. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7732. if err == nil {
  7733. if hisAdvice.ID > 0 {
  7734. advice.ExecutionTime = hisAdvice.ExecutionTime
  7735. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7736. advice.ExecutionState = hisAdvice.ExecutionState
  7737. advice.CheckTime = hisAdvice.CheckTime
  7738. advice.Checker = hisAdvice.Checker
  7739. advice.CheckState = hisAdvice.CheckState
  7740. advice.StartTime = hisAdvice.StartTime
  7741. advice.HospApprFlag = hisAdvice.HospApprFlag
  7742. advice.IsMedicine = hisAdvice.IsMedicine
  7743. if hisAdvice.UserOrgId == 10028 {
  7744. 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 {
  7745. advice.ExecutionTime = 0
  7746. advice.ExecutionStaff = 0
  7747. advice.ExecutionState = 2
  7748. advice.CheckTime = 0
  7749. advice.Checker = 0
  7750. advice.CheckState = 2
  7751. }
  7752. } else {
  7753. 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 {
  7754. advice.ExecutionTime = 0
  7755. advice.ExecutionStaff = 0
  7756. advice.ExecutionState = 2
  7757. advice.CheckTime = 0
  7758. advice.Checker = 0
  7759. advice.CheckState = 2
  7760. advice.UpdatedTime = time.Now().Unix()
  7761. }
  7762. }
  7763. //advice.Groupno = hisAdvice.Groupno
  7764. }
  7765. }
  7766. }
  7767. }
  7768. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7769. //
  7770. //if drugStockConfig.IsOpen == 1 {
  7771. //
  7772. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7773. // if advice.ID == 0 { //医嘱不存在
  7774. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7775. // drug.Total = drug.Total - advice.PrescribingNumber
  7776. // service.UpdateBaseDrugLib(&drug)
  7777. //
  7778. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7779. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7780. // drug.Total = drug.Total - num
  7781. // service.UpdateBaseDrugLib(&drug)
  7782. // }
  7783. //
  7784. // } else if advice.ID > 0 { //医嘱存在
  7785. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7786. // var num float64
  7787. //
  7788. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7789. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7790. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7791. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7792. // drug.Total = drug.Total + num
  7793. // service.UpdateBaseDrugLib(&drug)
  7794. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7795. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7796. // drug.Total = drug.Total - num
  7797. // service.UpdateBaseDrugLib(&drug)
  7798. // }
  7799. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7800. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7801. // if num2 > advice.PrescribingNumber {
  7802. // num = num2 - advice.PrescribingNumber
  7803. // drug.Total = drug.Total + num
  7804. // service.UpdateBaseDrugLib(&drug)
  7805. // } else if num2 < advice.PrescribingNumber {
  7806. // num = advice.PrescribingNumber - num2
  7807. // drug.Total = drug.Total - num
  7808. // service.UpdateBaseDrugLib(&drug)
  7809. // }
  7810. //
  7811. // }
  7812. //
  7813. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7814. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7815. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7816. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7817. // if num1 > num2 {
  7818. // num = num1 - num2
  7819. // drug.Total = drug.Total + num
  7820. // service.UpdateBaseDrugLib(&drug)
  7821. // } else if num1 < num2 {
  7822. // num = num2 - num1
  7823. // drug.Total = drug.Total - num
  7824. // service.UpdateBaseDrugLib(&drug)
  7825. // }
  7826. //
  7827. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7828. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7829. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7830. // if hisAdvice.PrescribingNumber > num2 {
  7831. // num = hisAdvice.PrescribingNumber - num2
  7832. // drug.Total = drug.Total + num
  7833. // service.UpdateBaseDrugLib(&drug)
  7834. // } else if num2 < advice.PrescribingNumber {
  7835. // num = num2 - hisAdvice.PrescribingNumber
  7836. // drug.Total = drug.Total - num
  7837. // service.UpdateBaseDrugLib(&drug)
  7838. // }
  7839. //
  7840. // }
  7841. // }
  7842. // }
  7843. //}
  7844. //
  7845. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7846. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7847. // advice.ExecutionTime = execution_time
  7848. //}
  7849. //
  7850. //
  7851. //
  7852. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7853. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7854. // advice.ExecutionStaff = execution_staff
  7855. //}
  7856. //
  7857. //
  7858. //
  7859. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7860. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7861. // advice.ExecutionState = execution_state
  7862. //}
  7863. //
  7864. //
  7865. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7866. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7867. // advice.CheckTime = check_time
  7868. //}
  7869. //
  7870. //
  7871. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7872. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7873. // advice.CheckState = check_state
  7874. //}
  7875. //
  7876. //
  7877. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7878. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7879. // advice.Checker = checker
  7880. //}
  7881. //
  7882. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7883. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7884. // advice.StartTime = start_time
  7885. //}
  7886. return 0
  7887. }
  7888. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7889. project.ExecutionStaff = 0
  7890. project.ExecutionState = 2
  7891. project.ExecutionTime = 0
  7892. project.Checker = 0
  7893. project.CheckState = 2
  7894. project.CheckTime = 0
  7895. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7896. id := int64(json["id"].(float64))
  7897. project.ID = id
  7898. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7899. project.ExecutionStaff = temp_project.ExecutionStaff
  7900. project.ExecutionState = temp_project.ExecutionState
  7901. project.ExecutionTime = temp_project.ExecutionTime
  7902. project.Checker = temp_project.Checker
  7903. project.CheckState = temp_project.CheckState
  7904. project.CheckTime = temp_project.CheckTime
  7905. project.TeamId = temp_project.TeamId
  7906. }
  7907. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7908. types := int64(json["type"].(float64))
  7909. project.Type = types
  7910. }
  7911. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7912. project_id := int64(json["project_id"].(float64))
  7913. project.ProjectId = project_id
  7914. }
  7915. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7916. team_id := int64(json["team_id"].(float64))
  7917. project.TeamId = team_id
  7918. }
  7919. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7920. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7921. project.Price = price
  7922. }
  7923. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7924. total, _ := json["total"].(string)
  7925. //totals, _ := strconv.ParseInt(total, 10, 64)
  7926. project.Count = total
  7927. }
  7928. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7929. medical_code, _ := json["medical_code"].(string)
  7930. project.MedListCodg = medical_code
  7931. }
  7932. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7933. single_dose, _ := json["single_dose"].(string)
  7934. project.SingleDose = single_dose
  7935. }
  7936. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7937. delivery_way, _ := json["delivery_way"].(string)
  7938. project.DeliveryWay = delivery_way
  7939. }
  7940. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7941. execution_frequency, _ := json["execution_frequency"].(string)
  7942. project.ExecutionFrequency = execution_frequency
  7943. }
  7944. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7945. remark, _ := json["remark"].(string)
  7946. project.Remark = remark
  7947. }
  7948. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7949. day, _ := json["number_days"].(string)
  7950. project.Day = day
  7951. }
  7952. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7953. unit, _ := json["unit"].(string)
  7954. project.Unit = unit
  7955. }
  7956. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7957. // frequency_type := int64(json["frequency_type"].(float64))
  7958. // project.FrequencyType = frequency_type
  7959. //}
  7960. //
  7961. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7962. // day_count := int64(json["day_count"].(float64))
  7963. // project.DayCount = day_count
  7964. //}
  7965. //
  7966. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7967. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7968. // week_day, _ := json["week_day"].(string)
  7969. // project.WeekDay = week_day
  7970. //}
  7971. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7972. //
  7973. //if project.ID == 0 {
  7974. // if stockConfig.IsOpen == 1 {
  7975. // if project.Type == 3 {
  7976. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7977. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7978. // good.Total = good.Total - f_count
  7979. // service.UpdateGoodInfo(&good)
  7980. // }
  7981. // }
  7982. //
  7983. //} else {
  7984. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7985. //
  7986. // if stockConfig.IsOpen == 1 {
  7987. // if project.Type == 3 {
  7988. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7989. // if project.Count < temp_project.Count {
  7990. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7991. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7992. //
  7993. // other_count := f_count_two - f_count_one
  7994. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7995. // good.Total = good.Total + other_count_two
  7996. // service.UpdateGoodInfo(&good)
  7997. // } else if project.Count > temp_project.Count {
  7998. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7999. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8000. //
  8001. // other_count := f_count_one - f_count_two
  8002. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8003. // good.Total = good.Total - other_count_two
  8004. // service.UpdateGoodInfo(&good)
  8005. // }
  8006. //
  8007. // }
  8008. // }
  8009. //
  8010. //}
  8011. return 0
  8012. }
  8013. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8014. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8015. utils.ErrorLog("drug_name")
  8016. return enums.ErrorCodeParamWrong
  8017. }
  8018. adviceName, _ := json["drug_name"].(string)
  8019. if len(adviceName) == 0 {
  8020. utils.ErrorLog("len(advice_name) == 0")
  8021. return enums.ErrorCodeParamWrong
  8022. }
  8023. advice.AdviceName = adviceName
  8024. adviceDesc, _ := json["advice_desc"].(string)
  8025. advice.AdviceDesc = adviceDesc
  8026. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8027. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8028. advice.DrugSpec = drugSpec
  8029. }
  8030. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8031. remark, _ := json["remark"].(string)
  8032. advice.Remark = remark
  8033. }
  8034. if json["id"] == nil {
  8035. advice.DrugId = 0
  8036. } else {
  8037. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8038. drug_id := int64(json["id"].(float64))
  8039. advice.DrugId = drug_id
  8040. }
  8041. }
  8042. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8043. groupno := int64(json["groupno"].(float64))
  8044. advice.Groupno = groupno
  8045. }
  8046. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8047. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8048. advice.IsSelfDrug = is_self_drug
  8049. }
  8050. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8051. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8052. drug_way_count, _ := json["drug_way_count"].(string)
  8053. advice.DrugWayCount = drug_way_count
  8054. }
  8055. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8056. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8057. advice.HospApprFlag = hosp_appr_flag
  8058. }
  8059. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8060. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8061. advice.PrescribingNumber = prescribingNumber
  8062. }
  8063. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8064. // frequency_type := int64(json["frequency_type"].(float64))
  8065. // advice.FrequencyType = frequency_type
  8066. //}
  8067. //
  8068. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8069. // day_count := int64(json["day_count"].(float64))
  8070. // advice.DayCount = day_count
  8071. //}
  8072. //
  8073. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8074. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8075. // week_day, _ := json["week_day"].(string)
  8076. // advice.WeekDay = week_day
  8077. //}
  8078. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8079. drugSpecUnit, _ := json["min_unit"].(string)
  8080. advice.DrugSpecUnit = drugSpecUnit
  8081. }
  8082. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8083. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8084. advice.SingleDose = singleDose
  8085. }
  8086. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8087. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8088. advice.SingleDoseUnit = singleDoseUnit
  8089. }
  8090. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8091. deliveryWay, _ := json["delivery_way"].(string)
  8092. advice.DeliveryWay = deliveryWay
  8093. }
  8094. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8095. executionFrequency, _ := json["execution_frequency"].(string)
  8096. advice.ExecutionFrequency = executionFrequency
  8097. }
  8098. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8099. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8100. advice.Price = price
  8101. }
  8102. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8103. med_list_codg, _ := json["medical_insurance_number"].(string)
  8104. advice.MedListCodg = med_list_codg
  8105. }
  8106. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8107. day := int64(json["day"].(float64))
  8108. advice.Day = day
  8109. }
  8110. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8111. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8112. advice.PrescribingNumberUnit = prescribingNumberUnit
  8113. }
  8114. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8115. advice_id := int64(json["advice_id"].(float64))
  8116. advice.ID = advice_id
  8117. if advice.ID > 0 {
  8118. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8119. if err == nil {
  8120. if hisAdvice.ID > 0 {
  8121. advice.ExecutionTime = hisAdvice.ExecutionTime
  8122. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8123. advice.ExecutionState = hisAdvice.ExecutionState
  8124. advice.CheckTime = hisAdvice.CheckTime
  8125. advice.Checker = hisAdvice.Checker
  8126. advice.DrugCode = hisAdvice.DrugCode
  8127. advice.CheckState = hisAdvice.CheckState
  8128. advice.StartTime = hisAdvice.StartTime
  8129. advice.HospApprFlag = hisAdvice.HospApprFlag
  8130. advice.IsMedicine = hisAdvice.IsMedicine
  8131. if hisAdvice.UserOrgId == 10028 {
  8132. 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 {
  8133. advice.ExecutionTime = 0
  8134. advice.ExecutionStaff = 0
  8135. advice.ExecutionState = 2
  8136. advice.CheckTime = 0
  8137. advice.Checker = 0
  8138. advice.CheckState = 2
  8139. }
  8140. } else {
  8141. 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 {
  8142. advice.ExecutionTime = 0
  8143. advice.ExecutionStaff = 0
  8144. advice.ExecutionState = 2
  8145. advice.CheckTime = 0
  8146. advice.Checker = 0
  8147. advice.CheckState = 2
  8148. //advice.UpdatedTime = time.Now().Unix()
  8149. advice.CreatedTime = hisAdvice.CreatedTime
  8150. advice.UpdatedTime = time.Now().Unix()
  8151. } else {
  8152. advice.CreatedTime = hisAdvice.CreatedTime
  8153. advice.UpdatedTime = hisAdvice.UpdatedTime
  8154. }
  8155. }
  8156. //advice.Groupno = hisAdvice.Groupno
  8157. } else {
  8158. advice.IsMedicine = 0
  8159. ctime := time.Now().Unix()
  8160. advice.CreatedTime = ctime
  8161. advice.UpdatedTime = ctime
  8162. }
  8163. }
  8164. } else {
  8165. advice.IsMedicine = 0
  8166. ctime := time.Now().Unix()
  8167. advice.CreatedTime = ctime
  8168. advice.UpdatedTime = ctime
  8169. }
  8170. }
  8171. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8172. //
  8173. //if drugStockConfig.IsOpen == 1 {
  8174. //
  8175. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8176. // if advice.ID == 0 { //医嘱不存在
  8177. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8178. // drug.Total = drug.Total - advice.PrescribingNumber
  8179. // service.UpdateBaseDrugLib(&drug)
  8180. //
  8181. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8182. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8183. // drug.Total = drug.Total - num
  8184. // service.UpdateBaseDrugLib(&drug)
  8185. // }
  8186. //
  8187. // } else if advice.ID > 0 { //医嘱存在
  8188. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8189. // var num float64
  8190. //
  8191. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8192. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8193. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8194. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8195. // drug.Total = drug.Total + num
  8196. // service.UpdateBaseDrugLib(&drug)
  8197. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8198. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8199. // drug.Total = drug.Total - num
  8200. // service.UpdateBaseDrugLib(&drug)
  8201. // }
  8202. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8203. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8204. // if num2 > advice.PrescribingNumber {
  8205. // num = num2 - advice.PrescribingNumber
  8206. // drug.Total = drug.Total + num
  8207. // service.UpdateBaseDrugLib(&drug)
  8208. // } else if num2 < advice.PrescribingNumber {
  8209. // num = advice.PrescribingNumber - num2
  8210. // drug.Total = drug.Total - num
  8211. // service.UpdateBaseDrugLib(&drug)
  8212. // }
  8213. //
  8214. // }
  8215. //
  8216. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8217. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8218. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8219. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8220. // if num1 > num2 {
  8221. // num = num1 - num2
  8222. // drug.Total = drug.Total + num
  8223. // service.UpdateBaseDrugLib(&drug)
  8224. // } else if num1 < num2 {
  8225. // num = num2 - num1
  8226. // drug.Total = drug.Total - num
  8227. // service.UpdateBaseDrugLib(&drug)
  8228. // }
  8229. //
  8230. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8231. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8232. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8233. // if hisAdvice.PrescribingNumber > num2 {
  8234. // num = hisAdvice.PrescribingNumber - num2
  8235. // drug.Total = drug.Total + num
  8236. // service.UpdateBaseDrugLib(&drug)
  8237. // } else if num2 < advice.PrescribingNumber {
  8238. // num = num2 - hisAdvice.PrescribingNumber
  8239. // drug.Total = drug.Total - num
  8240. // service.UpdateBaseDrugLib(&drug)
  8241. // }
  8242. //
  8243. // }
  8244. // }
  8245. // }
  8246. //}
  8247. //
  8248. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8249. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8250. // advice.ExecutionTime = execution_time
  8251. //}
  8252. //
  8253. //
  8254. //
  8255. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8256. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8257. // advice.ExecutionStaff = execution_staff
  8258. //}
  8259. //
  8260. //
  8261. //
  8262. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8263. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8264. // advice.ExecutionState = execution_state
  8265. //}
  8266. //
  8267. //
  8268. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8269. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8270. // advice.CheckTime = check_time
  8271. //}
  8272. //
  8273. //
  8274. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8275. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8276. // advice.CheckState = check_state
  8277. //}
  8278. //
  8279. //
  8280. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8281. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8282. // advice.Checker = checker
  8283. //}
  8284. //
  8285. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8286. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8287. // advice.StartTime = start_time
  8288. //}
  8289. return 0
  8290. }
  8291. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8292. project.ExecutionStaff = 0
  8293. project.ExecutionState = 2
  8294. project.ExecutionTime = 0
  8295. project.Checker = 0
  8296. project.CheckState = 2
  8297. project.CheckTime = 0
  8298. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8299. id := int64(json["id"].(float64))
  8300. project.ID = id
  8301. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8302. project.ExecutionStaff = temp_project.ExecutionStaff
  8303. project.ExecutionState = temp_project.ExecutionState
  8304. project.ExecutionTime = temp_project.ExecutionTime
  8305. project.Checker = temp_project.Checker
  8306. project.CheckState = temp_project.CheckState
  8307. project.CheckTime = temp_project.CheckTime
  8308. project.TeamId = temp_project.TeamId
  8309. }
  8310. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8311. types := int64(json["type"].(float64))
  8312. project.Type = types
  8313. }
  8314. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8315. project_id := int64(json["project_id"].(float64))
  8316. project.ProjectId = project_id
  8317. }
  8318. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8319. team_id := int64(json["team_id"].(float64))
  8320. project.TeamId = team_id
  8321. }
  8322. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8323. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8324. project.Price = price
  8325. }
  8326. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8327. total, _ := json["total"].(string)
  8328. //totals, _ := strconv.ParseInt(total, 10, 64)
  8329. project.Count = total
  8330. }
  8331. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8332. medical_code, _ := json["medical_code"].(string)
  8333. project.MedListCodg = medical_code
  8334. }
  8335. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8336. single_dose, _ := json["single_dose"].(string)
  8337. project.SingleDose = single_dose
  8338. }
  8339. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8340. delivery_way, _ := json["delivery_way"].(string)
  8341. project.DeliveryWay = delivery_way
  8342. }
  8343. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8344. execution_frequency, _ := json["execution_frequency"].(string)
  8345. project.ExecutionFrequency = execution_frequency
  8346. }
  8347. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8348. remark, _ := json["remark"].(string)
  8349. project.Remark = remark
  8350. }
  8351. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8352. day, _ := json["number_days"].(string)
  8353. project.Day = day
  8354. }
  8355. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8356. unit, _ := json["unit"].(string)
  8357. project.Unit = unit
  8358. }
  8359. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8360. // frequency_type := int64(json["frequency_type"].(float64))
  8361. // project.FrequencyType = frequency_type
  8362. //}
  8363. //
  8364. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8365. // day_count := int64(json["day_count"].(float64))
  8366. // project.DayCount = day_count
  8367. //}
  8368. //
  8369. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8370. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8371. // week_day, _ := json["week_day"].(string)
  8372. // project.WeekDay = week_day
  8373. //}
  8374. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8375. //
  8376. //if project.ID == 0 {
  8377. // if stockConfig.IsOpen == 1 {
  8378. // if project.Type == 3 {
  8379. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8380. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8381. // good.Total = good.Total - f_count
  8382. // service.UpdateGoodInfo(&good)
  8383. // }
  8384. // }
  8385. //
  8386. //} else {
  8387. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8388. //
  8389. // if stockConfig.IsOpen == 1 {
  8390. // if project.Type == 3 {
  8391. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8392. // if project.Count < temp_project.Count {
  8393. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8394. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8395. //
  8396. // other_count := f_count_two - f_count_one
  8397. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8398. // good.Total = good.Total + other_count_two
  8399. // service.UpdateGoodInfo(&good)
  8400. // } else if project.Count > temp_project.Count {
  8401. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8402. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8403. //
  8404. // other_count := f_count_one - f_count_two
  8405. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8406. // good.Total = good.Total - other_count_two
  8407. // service.UpdateGoodInfo(&good)
  8408. // }
  8409. //
  8410. // }
  8411. // }
  8412. //
  8413. //}
  8414. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8415. id := int64(json["id"].(float64))
  8416. if id > 0 {
  8417. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8418. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8419. fmt.Println("666666")
  8420. project.Mtime = time.Now().Unix()
  8421. project.Ctime = temp_project.Ctime
  8422. } else {
  8423. project.Mtime = temp_project.Mtime
  8424. project.Ctime = temp_project.Ctime
  8425. }
  8426. } else {
  8427. ctime := time.Now().Unix()
  8428. project.Mtime = ctime
  8429. project.Ctime = ctime
  8430. }
  8431. }
  8432. return 0
  8433. }
  8434. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8435. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8436. id := int64(json["id"].(float64))
  8437. additionalCharge.ID = id
  8438. }
  8439. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8440. item_id := int64(json["item_id"].(float64))
  8441. additionalCharge.ItemId = item_id
  8442. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8443. if config.ID > 0 {
  8444. if len(config.Code) > 0 {
  8445. additionalCharge.MedListCodg = config.Code
  8446. }
  8447. }
  8448. }
  8449. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8450. // price := int64(json["price"].(float64))
  8451. // formatInt_price := strconv.FormatInt(price, 10)
  8452. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8453. // additionalCharge.Price = float_price
  8454. // }
  8455. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8456. // price := int64(json["price"].(float64))
  8457. // formatInt_price := strconv.FormatInt(price, 10)
  8458. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8459. // additionalCharge.Price = float_price
  8460. //}
  8461. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8462. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8463. additionalCharge.Price = price
  8464. }
  8465. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8466. count, _ := json["count"].(string)
  8467. counts, _ := strconv.ParseInt(count, 10, 64)
  8468. additionalCharge.Count = counts
  8469. }
  8470. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8471. item_name, _ := json["item_name"].(string)
  8472. additionalCharge.ItemName = item_name
  8473. }
  8474. return 0
  8475. }
  8476. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8477. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8478. utils.ErrorLog("drug_name")
  8479. return enums.ErrorCodeParamWrong
  8480. }
  8481. adviceName, _ := json["drug_name"].(string)
  8482. if len(adviceName) == 0 {
  8483. utils.ErrorLog("len(advice_name) == 0")
  8484. return enums.ErrorCodeParamWrong
  8485. }
  8486. advice.AdviceName = adviceName
  8487. adviceDesc, _ := json["advice_desc"].(string)
  8488. advice.AdviceDesc = adviceDesc
  8489. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8490. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8491. advice.DrugSpec = drugSpec
  8492. }
  8493. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8494. remark, _ := json["remark"].(string)
  8495. advice.Remark = remark
  8496. }
  8497. if json["id"] == nil {
  8498. advice.DrugId = 0
  8499. } else {
  8500. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8501. drug_id := int64(json["id"].(float64))
  8502. advice.DrugId = drug_id
  8503. }
  8504. }
  8505. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8506. groupno := int64(json["groupno"].(float64))
  8507. advice.Groupno = groupno
  8508. }
  8509. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8510. drugSpecUnit, _ := json["min_unit"].(string)
  8511. advice.DrugSpecUnit = drugSpecUnit
  8512. }
  8513. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8514. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8515. advice.SingleDose = singleDose
  8516. }
  8517. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8518. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8519. advice.SingleDoseUnit = singleDoseUnit
  8520. }
  8521. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8522. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8523. advice.PrescribingNumber = prescribingNumber
  8524. }
  8525. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8526. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8527. advice.PrescribingNumberUnit = prescribingNumberUnit
  8528. }
  8529. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8530. deliveryWay, _ := json["delivery_way"].(string)
  8531. advice.DeliveryWay = deliveryWay
  8532. }
  8533. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8534. executionFrequency, _ := json["execution_frequency"].(string)
  8535. advice.ExecutionFrequency = executionFrequency
  8536. }
  8537. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8538. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8539. advice.Price = price
  8540. }
  8541. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8542. med_list_codg, _ := json["medical_insurance_number"].(string)
  8543. advice.MedListCodg = med_list_codg
  8544. }
  8545. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8546. day := int64(json["day"].(float64))
  8547. advice.Day = day
  8548. }
  8549. advice.FrequencyType = 1
  8550. return 0
  8551. }
  8552. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8553. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8554. types := int64(json["type"].(float64))
  8555. project.Type = types
  8556. }
  8557. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8558. project_id := int64(json["project_id"].(float64))
  8559. project.ProjectId = project_id
  8560. }
  8561. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8562. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8563. project.Price = price
  8564. }
  8565. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8566. total, _ := json["total"].(string)
  8567. //totals, _ := strconv.ParseInt(total, 10, 64)
  8568. project.Count = total
  8569. }
  8570. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8571. medical_code, _ := json["medical_code"].(string)
  8572. project.MedListCodg = medical_code
  8573. }
  8574. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8575. single_dose, _ := json["single_dose"].(string)
  8576. project.SingleDose = single_dose
  8577. }
  8578. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8579. delivery_way, _ := json["delivery_way"].(string)
  8580. project.DeliveryWay = delivery_way
  8581. }
  8582. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8583. execution_frequency, _ := json["execution_frequency"].(string)
  8584. project.ExecutionFrequency = execution_frequency
  8585. }
  8586. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8587. remark, _ := json["remark"].(string)
  8588. project.Remark = remark
  8589. }
  8590. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8591. day, _ := json["number_days"].(string)
  8592. project.Day = day
  8593. }
  8594. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8595. unit, _ := json["unit"].(string)
  8596. project.Unit = unit
  8597. }
  8598. project.FrequencyType = 1
  8599. return 0
  8600. }
  8601. func (c *HisApiController) GetHisOrderListTwo() {
  8602. start_time := c.GetString("start_time")
  8603. end_time := c.GetString("end_time")
  8604. timeLayout := "2006-01-02"
  8605. loc, _ := time.LoadLocation("Local")
  8606. var startTime int64
  8607. if len(start_time) > 0 {
  8608. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8609. if err != nil {
  8610. //fmt.Println(err)
  8611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8612. return
  8613. }
  8614. startTime = theTime.Unix()
  8615. }
  8616. var endTime int64
  8617. if len(end_time) > 0 {
  8618. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8619. if err != nil {
  8620. utils.ErrorLog(err.Error())
  8621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8622. return
  8623. }
  8624. endTime = theTime.Unix()
  8625. }
  8626. adminUser := c.GetAdminUserInfo()
  8627. org_id := adminUser.CurrentOrgId
  8628. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  8629. if err == nil {
  8630. c.ServeSuccessJSON(map[string]interface{}{
  8631. "order2": order,
  8632. })
  8633. } else {
  8634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8635. return
  8636. }
  8637. }
  8638. func (c *HisApiController) GetHisOrderList() {
  8639. page, _ := c.GetInt64("page", -1)
  8640. limit, _ := c.GetInt64("limit", -1)
  8641. start_time := c.GetString("start_time")
  8642. end_time := c.GetString("end_time")
  8643. types, _ := c.GetInt64("type", 0)
  8644. keywords := c.GetString("keywords")
  8645. p_type, _ := c.GetInt64("p_type", 0)
  8646. sort_type, _ := c.GetInt64("sort_type", 0)
  8647. charge_type, _ := c.GetInt64("charge_type", 0)
  8648. sch_type, _ := c.GetInt64("sch_type", 0)
  8649. zone_type, _ := c.GetInt64("zone_type", 0)
  8650. med_type, _ := c.GetInt64("med_type", 0)
  8651. timeLayout := "2006-01-02"
  8652. loc, _ := time.LoadLocation("Local")
  8653. var startTime int64
  8654. if len(start_time) > 0 {
  8655. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8656. if err != nil {
  8657. //fmt.Println(err)
  8658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8659. return
  8660. }
  8661. startTime = theTime.Unix()
  8662. }
  8663. var endTime int64
  8664. if len(end_time) > 0 {
  8665. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8666. if err != nil {
  8667. utils.ErrorLog(err.Error())
  8668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8669. return
  8670. }
  8671. endTime = theTime.Unix()
  8672. }
  8673. adminUser := c.GetAdminUserInfo()
  8674. org_id := adminUser.CurrentOrgId
  8675. 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)
  8676. for _, item := range order {
  8677. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8678. item.DoctorName = info.Doctor
  8679. item.DepartmentName = info.XtHisDepartment.Name
  8680. }
  8681. if err == nil {
  8682. c.ServeSuccessJSON(map[string]interface{}{
  8683. "order": order,
  8684. "total": total,
  8685. })
  8686. } else {
  8687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8688. return
  8689. }
  8690. }
  8691. func (c *HisApiController) GetHisOrder() {
  8692. patient_id, _ := c.GetInt64("patient_id", 0)
  8693. number := c.GetString("number")
  8694. adminInfo := c.GetAdminUserInfo()
  8695. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8696. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8697. if err == nil {
  8698. c.ServeSuccessJSON(map[string]interface{}{
  8699. "order": order,
  8700. "prescription": prescriptions,
  8701. })
  8702. } else {
  8703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8704. return
  8705. }
  8706. }
  8707. func (c *HisApiController) GetHisPrescriptionList() {
  8708. record_date := c.GetString("record_date")
  8709. keywords := c.GetString("keywords")
  8710. page, _ := c.GetInt64("page")
  8711. limit, _ := c.GetInt64("limit")
  8712. sch_type, _ := c.GetInt64("sch_type")
  8713. timeLayout := "2006-01-02"
  8714. loc, _ := time.LoadLocation("Local")
  8715. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8716. if err != nil {
  8717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8718. return
  8719. }
  8720. recordDateTime := theTime.Unix()
  8721. adminInfo := c.GetAdminUserInfo()
  8722. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8723. //adminInfo := c.GetAdminUserInfo()
  8724. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8725. //fmt.Println(prescriptionOrder)
  8726. if err == nil {
  8727. c.ServeSuccessJSON(map[string]interface{}{
  8728. "order": prescriptionOrder,
  8729. "total": total,
  8730. })
  8731. } else {
  8732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8733. return
  8734. }
  8735. }
  8736. func (c *HisApiController) GetHisPrescriptionInfo() {
  8737. id, _ := c.GetInt64("id")
  8738. adminInfo := c.GetAdminUserInfo()
  8739. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8740. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8741. if err == nil {
  8742. c.ServeSuccessJSON(map[string]interface{}{
  8743. "order": prescriptionOrder,
  8744. "prescription": prescription,
  8745. })
  8746. } else {
  8747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8748. return
  8749. }
  8750. }
  8751. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8752. adminUser := c.GetAdminUserInfo()
  8753. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8754. c.ServeSuccessJSON(map[string]interface{}{
  8755. "config": config,
  8756. })
  8757. }
  8758. type ResultTwo struct {
  8759. ErrMsg interface{} `json:"err_msg"`
  8760. InfRefmsgid string `json:"inf_refmsgid"`
  8761. Infcode int64 `json:"infcode"`
  8762. Output struct {
  8763. Baseinfo struct {
  8764. Age float64 `json:"age"`
  8765. Brdy string `json:"brdy"`
  8766. Certno string `json:"certno"`
  8767. Gend string `json:"gend"`
  8768. Naty string `json:"naty"`
  8769. PsnCertType string `json:"psn_cert_type"`
  8770. PsnName string `json:"psn_name"`
  8771. PsnNo string `json:"psn_no"`
  8772. } `json:"baseinfo"`
  8773. Idetinfo []interface{} `json:"idetinfo"`
  8774. Iinfo []struct {
  8775. Balc float64 `json:"balc"`
  8776. CvlservFlag string `json:"cvlserv_flag"`
  8777. EmpName string `json:"emp_name"`
  8778. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8779. Insutype string `json:"insutype"`
  8780. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8781. PausInsuDate interface{} `json:"paus_insu_date"`
  8782. PsnInsuDate string `json:"psn_insu_date"`
  8783. PsnInsuStas string `json:"psn_insu_stas"`
  8784. PsnType string `json:"psn_type"`
  8785. } `json:"insuinfo"`
  8786. } `json:"output"`
  8787. RefmsgTime string `json:"refmsg_time"`
  8788. RespondTime string `json:"respond_time"`
  8789. Signtype interface{} `json:"signtype"`
  8790. WarnInfo interface{} `json:"warn_info"`
  8791. }
  8792. type ResultThree struct {
  8793. Cainfo interface{} `json:"cainfo"`
  8794. ErrMsg interface{} `json:"err_msg"`
  8795. InfRefmsgid string `json:"inf_refmsgid"`
  8796. Infcode int64 `json:"infcode"`
  8797. Output struct {
  8798. Data struct {
  8799. IptOtpNo string `json:"ipt_otp_no"`
  8800. MdtrtID string `json:"mdtrt_id"`
  8801. PsnNo string `json:"psn_no"`
  8802. } `json:"data"`
  8803. } `json:"output"`
  8804. RefmsgTime string `json:"refmsg_time"`
  8805. RespondTime string `json:"respond_time"`
  8806. Signtype interface{} `json:"signtype"`
  8807. WarnMsg interface{} `json:"warn_msg"`
  8808. }
  8809. type ResultFour struct {
  8810. Cainfo string `json:"cainfo"`
  8811. ErrMsg string `json:"err_msg"`
  8812. InfRefmsgid string `json:"inf_refmsgid"`
  8813. Infcode int64 `json:"infcode"`
  8814. Output struct {
  8815. Result []struct {
  8816. BasMednFlag string `json:"bas_medn_flag"`
  8817. ChldMedcFlag string `json:"chld_medc_flag"`
  8818. ChrgitmLv string `json:"chrgitm_lv"`
  8819. Cnt float64 `json:"cnt"`
  8820. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8821. DrtReimFlag string `json:"drt_reim_flag"`
  8822. FeedetlSn string `json:"feedetl_sn"`
  8823. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8824. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8825. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8826. ListSpItemFlag string `json:"list_sp_item_flag"`
  8827. LmtUsedFlag string `json:"lmt_used_flag"`
  8828. MedChrgitmType string `json:"med_chrgitm_type"`
  8829. Memo string `json:"memo"`
  8830. OverlmtAmt float64 `json:"overlmt_amt"`
  8831. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8832. Pric float64 `json:"pric"`
  8833. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8834. SelfpayProp float64 `json:"selfpay_prop"`
  8835. } `json:"result"`
  8836. } `json:"output"`
  8837. RefmsgTime string `json:"refmsg_time"`
  8838. RespondTime string `json:"respond_time"`
  8839. Signtype string `json:"signtype"`
  8840. WarnMsg string `json:"warn_msg"`
  8841. }
  8842. type ResultFive struct {
  8843. Insutype string `json:"insutype"`
  8844. }
  8845. type ResultSix struct {
  8846. Cainfo interface{} `json:"cainfo"`
  8847. ErrMsg interface{} `json:"err_msg"`
  8848. InfRefmsgid string `json:"inf_refmsgid"`
  8849. Infcode int64 `json:"infcode"`
  8850. Output struct {
  8851. } `json:"output"`
  8852. RefmsgTime string `json:"refmsg_time"`
  8853. RespondTime string `json:"respond_time"`
  8854. Signtype interface{} `json:"signtype"`
  8855. WarnMsg interface{} `json:"warn_msg"`
  8856. }
  8857. type ResultSeven struct {
  8858. Cainfo string `json:"cainfo"`
  8859. ErrMsg string `json:"err_msg"`
  8860. InfRefmsgid string `json:"inf_refmsgid"`
  8861. Infcode int64 `json:"infcode"`
  8862. Output struct {
  8863. Setldetail []interface{} `json:"setldetail"`
  8864. Setlinfo struct {
  8865. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8866. AcctPay float64 `json:"acct_pay"`
  8867. ActPayDedc float64 `json:"act_pay_dedc"`
  8868. Age float64 `json:"age"`
  8869. Balc float64 `json:"balc"`
  8870. Brdy string `json:"brdy"`
  8871. Certno string `json:"certno"`
  8872. ClrOptins string `json:"clr_optins"`
  8873. ClrType string `json:"clr_type"`
  8874. ClrWay string `json:"clr_way"`
  8875. CvlservFlag string `json:"cvlserv_flag"`
  8876. CvlservPay float64 `json:"cvlserv_pay"`
  8877. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8878. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8879. Gend string `json:"gend"`
  8880. HifesPay float64 `json:"hifes_pay"`
  8881. HifmiPay float64 `json:"hifmi_pay"`
  8882. HifobPay float64 `json:"hifob_pay"`
  8883. HifpPay float64 `json:"hifp_pay"`
  8884. HospPartAmt float64 `json:"hosp_part_amt"`
  8885. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8886. Insutype string `json:"insutype"`
  8887. MafPay float64 `json:"maf_pay"`
  8888. MdtrtCertType string `json:"mdtrt_cert_type"`
  8889. MdtrtID string `json:"mdtrt_id"`
  8890. MedType string `json:"med_type"`
  8891. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8892. MedinsSetlID string `json:"medins_setl_id"`
  8893. Naty string `json:"naty"`
  8894. OthPay float64 `json:"oth_pay"`
  8895. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8896. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8897. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8898. PsnCashPay float64 `json:"psn_cash_pay"`
  8899. PsnCertType string `json:"psn_cert_type"`
  8900. PsnName string `json:"psn_name"`
  8901. PsnNo string `json:"psn_no"`
  8902. PsnPartAmt float64 `json:"psn_part_amt"`
  8903. PsnType string `json:"psn_type"`
  8904. SetlID string `json:"setl_id"`
  8905. SetlTime string `json:"setl_time"`
  8906. } `json:"setlinfo"`
  8907. } `json:"output"`
  8908. RefmsgTime string `json:"refmsg_time"`
  8909. RespondTime string `json:"respond_time"`
  8910. Signtype interface{} `json:"signtype"`
  8911. WarnMsg interface{} `json:"warn_msg"`
  8912. }
  8913. type ResultEight struct {
  8914. Cainfo string `json:"cainfo"`
  8915. ErrMsg string `json:"err_msg"`
  8916. InfRefmsgid string `json:"inf_refmsgid"`
  8917. Infcode int64 `json:"infcode"`
  8918. Output struct {
  8919. Stmtinfo struct {
  8920. SetlOptins string `json:"setl_optins"`
  8921. StmtRslt string `json:"stmt_rslt"`
  8922. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8923. } `json:"stmtinfo"`
  8924. } `json:"output"`
  8925. RefmsgTime string `json:"refmsg_time"`
  8926. RespondTime string `json:"respond_time"`
  8927. Signtype interface{} `json:"signtype"`
  8928. WarnMsg interface{} `json:"warn_msg"`
  8929. }
  8930. type ResultNine struct {
  8931. Cainfo string `json:"cainfo"`
  8932. ErrMsg string `json:"err_msg"`
  8933. InfRefmsgid string `json:"inf_refmsgid"`
  8934. Infcode int64 `json:"infcode"`
  8935. Output struct {
  8936. FileQuryNo string `json:"file_qury_no"`
  8937. } `json:"output"`
  8938. RefmsgTime string `json:"refmsg_time"`
  8939. RespondTime string `json:"respond_time"`
  8940. Signtype interface{} `json:"signtype"`
  8941. WarnMsg interface{} `json:"warn_msg"`
  8942. }
  8943. type ResultTen struct {
  8944. Cainfo string `json:"cainfo"`
  8945. ErrMsg string `json:"err_msg"`
  8946. InfRefmsgid string `json:"inf_refmsgid"`
  8947. Infcode int64 `json:"infcode"`
  8948. Output struct {
  8949. DldEndtime string `json:"dld_endtime"`
  8950. FileQuryNo string `json:"file_qury_no"`
  8951. Filename string `json:"filename"`
  8952. } `json:"output"`
  8953. RefmsgTime string `json:"refmsg_time"`
  8954. RespondTime string `json:"respond_time"`
  8955. Signtype interface{} `json:"signtype"`
  8956. WarnMsg interface{} `json:"warn_msg"`
  8957. }
  8958. type ResultEleven struct {
  8959. Cainfo string `json:"cainfo"`
  8960. ErrMsg string `json:"err_msg"`
  8961. InfRefmsgid string `json:"inf_refmsgid"`
  8962. Infcode int64 `json:"infcode"`
  8963. Output struct {
  8964. Setlinfo struct {
  8965. FixmedinsName string `json:"fixmedins_name"`
  8966. FixmedinsCode string `json:"fixmedins_code"`
  8967. PsnNo string `json:"psn_no"`
  8968. PsnName string `json:"psn_name"`
  8969. HifobPay float64 `json:"hifob_pay"`
  8970. Gend string `json:"gend"`
  8971. Brdy string `json:"brdy"`
  8972. PsnCertType string `json:"psn_cert_type"`
  8973. PsnType string `json:"psn_type"`
  8974. EmpName string `json:"emp_name"`
  8975. Certno string `json:"certno"`
  8976. Insutype string `json:"insutype"`
  8977. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8978. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8979. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8980. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8981. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8982. ActPayDedc float64 `json:"act_pay_dedc"`
  8983. HifpPay float64 `json:"hifp_pay"`
  8984. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8985. CvlservPay float64 `json:"cvlserv_pay"`
  8986. HifesPay float64 `json:"hifes_pay"`
  8987. HifmiPay float64 `json:"hifmi_pay"`
  8988. MafPay float64 `json:"maf_pay"`
  8989. OthPay float64 `json:"oth_pay"`
  8990. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8991. PsnPay float64 `json:"psn_pay"`
  8992. AcctPay float64 `json:"acct_pay"`
  8993. CashPayamt float64 `json:"cash_payamt"`
  8994. Balc float64 `json:"balc"`
  8995. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8996. MedinsSetlId string `json:"medins_setl_id"`
  8997. RefdSetlFlag string `json:"refd_setl_flag"`
  8998. SetlTime string `json:"setl_time"`
  8999. MedType string `json:"med_type"`
  9000. } `json:"setlinfo"`
  9001. } `json:"output"`
  9002. RefmsgTime string `json:"refmsg_time"`
  9003. RespondTime string `json:"respond_time"`
  9004. Signtype interface{} `json:"signtype"`
  9005. WarnMsg interface{} `json:"warn_msg"`
  9006. }
  9007. type Custom struct {
  9008. DetItemFeeSumamt string
  9009. Cut string
  9010. FeedetlSn string
  9011. Price string
  9012. MedListCodg string
  9013. Type int64
  9014. AdviceId int64
  9015. ProjectId int64
  9016. ItemId int64
  9017. CostType int64
  9018. }
  9019. // 获取个人信息----挂号-----上传就诊信息
  9020. func (c *HisApiController) GetRegisterInfo() {
  9021. id, _ := c.GetInt64("id")
  9022. record_time := c.GetString("record_time")
  9023. settlementValue, _ := c.GetInt64("settlement_value")
  9024. medical_insurance_card := c.GetString("medical_insurance_card")
  9025. name := c.GetString("name")
  9026. id_card_type, _ := c.GetInt64("id_card_type")
  9027. certificates, _ := c.GetInt64("certificates")
  9028. medical_care, _ := c.GetInt64("medical_care")
  9029. birthday := c.GetString("birthday")
  9030. age, _ := c.GetInt64("age")
  9031. id_card := c.GetString("id_card")
  9032. register_type, _ := c.GetInt64("register")
  9033. doctor, _ := c.GetInt64("doctor")
  9034. department, _ := c.GetInt64("department")
  9035. gender, _ := c.GetInt64("sex")
  9036. phone := c.GetString("phone")
  9037. registration_fee, _ := c.GetFloat("registration_fee")
  9038. medical_expenses, _ := c.GetFloat("medical_expenses")
  9039. social_type, _ := c.GetInt64("social_type")
  9040. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9041. diagnosis_ids := c.GetString("diagnosis")
  9042. sick_type, _ := c.GetInt64("sick_type")
  9043. reg_type := c.GetString("p_type")
  9044. timeLayout := "2006-01-02"
  9045. loc, _ := time.LoadLocation("Local")
  9046. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9047. birthUnix := birthdays.Unix()
  9048. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9049. if err != nil {
  9050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9051. return
  9052. }
  9053. recordDateTime := theTime.Unix()
  9054. adminInfo := c.GetAdminUserInfo()
  9055. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9056. if tempPatient.ID == 0 {
  9057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9058. return
  9059. }
  9060. var patient service.Patients
  9061. if id == 0 {
  9062. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9063. } else {
  9064. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9065. }
  9066. if patient.ID == 0 {
  9067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9068. return
  9069. }
  9070. if len(patient.IdCardNo) == 0 {
  9071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9072. return
  9073. }
  9074. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9075. if len(his) >= 1 {
  9076. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9077. if len(his) >= 1 && order.ID == 0 {
  9078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9079. return
  9080. }
  9081. }
  9082. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9083. fmt.Println(timeStr)
  9084. timeArr := strings.Split(timeStr, " ")
  9085. fmt.Println(timeArr)
  9086. timeArrTwo := strings.Split(timeArr[0], "-")
  9087. timeArrThree := strings.Split(timeArr[1], ":")
  9088. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9089. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9090. if len(lists) == 0 {
  9091. var hisPatient models.XtHisPatient
  9092. hisPatient = models.XtHisPatient{
  9093. Name: name,
  9094. Age: age,
  9095. Gender: gender,
  9096. Birthday: birthUnix,
  9097. Phone: phone,
  9098. MedicalTreatmentType: medical_care,
  9099. IdType: certificates,
  9100. IdCardNo: id_card,
  9101. BalanceAccountsType: settlementValue,
  9102. SocialType: social_type,
  9103. MedicalInsuranceNumber: medical_insurance_card,
  9104. RegisterType: register_type,
  9105. RegisterCost: registration_fee,
  9106. TreatmentCost: medical_expenses,
  9107. AdminUserId: adminInfo.AdminUser.Id,
  9108. UserOrgId: adminInfo.CurrentOrgId,
  9109. Status: 1,
  9110. RecordDate: recordDateTime,
  9111. IsReturn: 1,
  9112. PatientId: patient.ID,
  9113. Ctime: time.Now().Unix(),
  9114. Mtime: time.Now().Unix(),
  9115. Number: str,
  9116. IdCardType: id_card_type,
  9117. Departments: department,
  9118. Doctor: doctor,
  9119. PType: reg_type,
  9120. Diagnosis: diagnosis_ids,
  9121. SickType: sick_type,
  9122. }
  9123. service.CreateHisPatient(&hisPatient)
  9124. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9125. c.ServeSuccessJSON(map[string]interface{}{
  9126. "his_info": hisPatient,
  9127. })
  9128. } else {
  9129. //chrgBchno := rand.Intn(1000000) + 10000
  9130. var hisPatient models.XtHisPatient
  9131. hisPatient = models.XtHisPatient{
  9132. Name: name,
  9133. Age: age,
  9134. Gender: gender,
  9135. Birthday: birthUnix,
  9136. Phone: phone,
  9137. MedicalTreatmentType: medical_care,
  9138. IdType: certificates,
  9139. IdCardNo: id_card,
  9140. BalanceAccountsType: settlementValue,
  9141. SocialType: social_type,
  9142. MedicalInsuranceNumber: medical_insurance_card,
  9143. RegisterType: register_type,
  9144. RegisterCost: registration_fee,
  9145. TreatmentCost: medical_expenses,
  9146. AdminUserId: adminInfo.AdminUser.Id,
  9147. UserOrgId: adminInfo.CurrentOrgId,
  9148. Status: 1,
  9149. RecordDate: recordDateTime,
  9150. IsReturn: 1,
  9151. PatientId: patient.ID,
  9152. Ctime: time.Now().Unix(),
  9153. Mtime: time.Now().Unix(),
  9154. Number: str,
  9155. IdCardType: id_card_type,
  9156. Departments: department,
  9157. Doctor: doctor,
  9158. PType: reg_type,
  9159. Diagnosis: diagnosis_ids,
  9160. SickType: sick_type,
  9161. }
  9162. service.CreateHisPatient(&hisPatient)
  9163. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9164. c.ServeSuccessJSON(map[string]interface{}{
  9165. "his_info": hisPatient,
  9166. })
  9167. }
  9168. }
  9169. // 上传明细----结算
  9170. func (c *HisApiController) GetUploadInfo() {
  9171. id, _ := c.GetInt64("id")
  9172. record_time := c.GetString("record_time")
  9173. his_patient_id, _ := c.GetInt64("his_patient_id")
  9174. oth_desc := c.GetString("oth_desc")
  9175. pay_way, _ := c.GetInt64("pay_way")
  9176. pay_ways := c.GetString("pay_ways")
  9177. pay_price, _ := c.GetFloat("pay_price")
  9178. pay_card_no := c.GetString("pay_card_no")
  9179. discount_price, _ := c.GetFloat("discount_price")
  9180. preferential_price, _ := c.GetFloat("preferential_price")
  9181. reality_price, _ := c.GetFloat("reality_price")
  9182. found_price, _ := c.GetFloat("found_price")
  9183. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9184. private_price, _ := c.GetFloat("private_price")
  9185. timeLayout := "2006-01-02"
  9186. loc, _ := time.LoadLocation("Local")
  9187. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9188. fapiao_code := c.GetString("fapiao_code")
  9189. fapiao_number := c.GetString("fapiao_number")
  9190. diagnosis_id := c.GetString("diagnosis")
  9191. sick_type, _ := c.GetInt64("sick_type")
  9192. reg_type, _ := c.GetInt64("p_type")
  9193. order_id, _ := c.GetInt64("order_id")
  9194. cash_pay := c.GetString("cash_pay")
  9195. wechat_pay := c.GetString("wechat_pay")
  9196. ali_pay := c.GetString("ali_pay")
  9197. jifen_pay := c.GetString("jifen_pay")
  9198. card_desc := c.GetString("card_desc")
  9199. band_card_pay := c.GetString("band_card_pay")
  9200. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9201. tmp_decimal := c.GetString("tmp_decimal")
  9202. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9203. var decimal float64 //本次使用的押金
  9204. var errmsg error
  9205. tx := service.XTWriteDB().Begin() //开了事务
  9206. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9207. defer func() {
  9208. if errmsg != nil {
  9209. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9210. tx.Rollback()
  9211. } else {
  9212. tx.Commit()
  9213. }
  9214. }()
  9215. fmt.Println("dec_way", dec_way)
  9216. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9217. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9218. return
  9219. }
  9220. if len(tmp_decimal) > 0 {
  9221. if tmp_decimal[0] == 45 {
  9222. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9223. return
  9224. }
  9225. }
  9226. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9227. fmt.Println(errs)
  9228. decimal = tt
  9229. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9230. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9231. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9232. if err != nil {
  9233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9234. return
  9235. }
  9236. recordDateTime := theTime.Unix()
  9237. adminUser := c.GetAdminUserInfo()
  9238. var prescriptions []*models.HisPrescription
  9239. var prescriptionsOne []*models.HisPrescription
  9240. var start_time int64
  9241. var end_time int64
  9242. ids_str := c.GetString("ids")
  9243. ids_arr := strings.Split(ids_str, ",")
  9244. if tempOrder.ID == 0 {
  9245. if settle_accounts_type == 1 { //日结
  9246. fmt.Println(reg_type)
  9247. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9248. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9249. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9250. } else {
  9251. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9252. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9253. }
  9254. } else { //月结
  9255. start_time_str := c.GetString("start_time")
  9256. end_time_str := c.GetString("end_time")
  9257. timeLayout := "2006-01-02"
  9258. loc, _ := time.LoadLocation("Local")
  9259. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9260. if err != nil {
  9261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9262. return
  9263. }
  9264. recordStartTime := theStartTime.Unix()
  9265. start_time = recordStartTime
  9266. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9267. if err != nil {
  9268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9269. return
  9270. }
  9271. recordEndTime := theEndTime.Unix()
  9272. end_time = recordEndTime
  9273. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9274. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9275. }
  9276. var goods []*models.DialysisBeforePrepareGoods
  9277. var newGoods []*models.NewDialysisBeforePrepareGoods
  9278. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9279. var infos []*models.HisDoctorAdviceInfo
  9280. var infoList []*models.HisDoctorAdviceInfo
  9281. var hisAdvice []*models.HisDoctorAdviceInfo
  9282. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9283. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9284. //判断库存不足
  9285. //结算出库开关
  9286. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9287. if settConfig.IsOpen == 1 {
  9288. //判断库存的地方
  9289. for _, info := range prescriptions {
  9290. if info.Type == 1 {
  9291. infos = append(infos, info.HisDoctorAdviceInfo...)
  9292. }
  9293. if info.Type == 2 {
  9294. for _, sumItem := range info.HisPrescriptionProject {
  9295. if sumItem.Type == 3 {
  9296. var good models.DialysisBeforePrepareGoods
  9297. var newGood models.NewDialysisBeforePrepareGoods
  9298. good.GoodId = sumItem.GoodInfo.ID
  9299. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9300. count, _ := strconv.Atoi(sumItem.Count)
  9301. good.Count = int64(count)
  9302. good.StorehouseId = houseConfig.StorehouseOutInfo
  9303. good.ProjectId = sumItem.ID
  9304. goods = append(goods, &good)
  9305. newGood.GoodId = sumItem.GoodInfo.ID
  9306. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9307. count2, _ := strconv.Atoi(sumItem.Count)
  9308. newGood.Count = int64(count2)
  9309. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9310. newGood.ProjectId = sumItem.ID
  9311. newGoods = append(newGoods, &newGood)
  9312. }
  9313. }
  9314. }
  9315. }
  9316. for _, info := range prescriptionsOne {
  9317. if info.Type == 1 {
  9318. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9319. }
  9320. if info.Type == 2 {
  9321. for _, sumItem := range info.HisPrescriptionProject {
  9322. if sumItem.Type == 3 {
  9323. var newGood models.NewDialysisBeforePrepareGoods
  9324. newGood.GoodId = sumItem.GoodInfo.ID
  9325. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9326. count2, _ := strconv.Atoi(sumItem.Count)
  9327. newGood.Count = int64(count2)
  9328. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9329. newGood.ProjectId = sumItem.ID
  9330. newGoodOne = append(newGoodOne, &newGood)
  9331. }
  9332. }
  9333. }
  9334. }
  9335. //判断
  9336. for _, itemOne := range infos {
  9337. for _, itemTwo := range hisAdvice {
  9338. if itemOne.DrugId == itemTwo.DrugId {
  9339. itemTwo.Child = append(itemTwo.Child, itemOne)
  9340. }
  9341. }
  9342. }
  9343. for _, itemTwo := range hisAdvice {
  9344. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9345. var sum_out_count int64
  9346. for _, itemThree := range itemTwo.Child {
  9347. var prescribing_number int64
  9348. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9349. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9350. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9351. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9352. }
  9353. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9354. prescribing_number = parseIntPrescribingNumber
  9355. }
  9356. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9357. prescribing_number = parseIntPrescribingNumber
  9358. }
  9359. sum_out_count += prescribing_number
  9360. }
  9361. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9362. if sum_out_count > drugStockOut.FlushCount {
  9363. c.ServeSuccessJSON(map[string]interface{}{
  9364. "msg": "2",
  9365. "drug": medical,
  9366. })
  9367. return
  9368. }
  9369. }
  9370. for _, itemOne := range newGoods {
  9371. for _, item := range newGoodOne {
  9372. if itemOne.GoodId == item.GoodId {
  9373. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9374. }
  9375. }
  9376. }
  9377. for _, item := range newGoodOne {
  9378. var sum_out_count_one int64
  9379. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9380. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9381. sum_out_count_one += itemOne.Count
  9382. }
  9383. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9384. fmt.Println("sum_out_count_one", sum_out_count_one)
  9385. fmt.Println("list.FlushCount", list.FlushCount)
  9386. if sum_out_count_one > list.FlushCount {
  9387. c.ServeSuccessJSON(map[string]interface{}{
  9388. "msg": "3",
  9389. "good": good,
  9390. })
  9391. return
  9392. }
  9393. }
  9394. }
  9395. timestamp := time.Now().Unix()
  9396. tempTime := time.Unix(timestamp, 0)
  9397. timeFormat := tempTime.Format("20060102150405")
  9398. chrgBchno := rand.Intn(100000) + 10000
  9399. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9400. strconv.FormatInt(his.PatientId, 10)
  9401. var ids []int64
  9402. for _, item := range prescriptions {
  9403. ids = append(ids, item.ID)
  9404. }
  9405. var total float64
  9406. for _, item := range prescriptions {
  9407. fmt.Println(item)
  9408. if item.Type == 1 { //药品
  9409. for _, subItem := range item.HisDoctorAdviceInfo {
  9410. total = total + (subItem.Price * subItem.PrescribingNumber)
  9411. }
  9412. }
  9413. if item.Type == 2 { //项目
  9414. for _, subItem := range item.HisPrescriptionProject {
  9415. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9416. total = total + (subItem.Price * cnt)
  9417. }
  9418. }
  9419. for _, subItem := range item.HisAdditionalCharge {
  9420. total = total + (subItem.Price * float64(subItem.Count))
  9421. }
  9422. }
  9423. if reg_type == 1111 || reg_type == 1112 {
  9424. reg_type = 11
  9425. }
  9426. tm := time.Unix(time.Now().Unix(), 0)
  9427. allTotal := fmt.Sprintf("%.4f", total)
  9428. totals, _ := strconv.ParseFloat(allTotal, 64)
  9429. order := &models.HisOrder{
  9430. UserOrgId: adminUser.CurrentOrgId,
  9431. HisPatientId: his.ID,
  9432. PatientId: id,
  9433. SettleAccountsDate: recordDateTime,
  9434. Ctime: time.Now().Unix(),
  9435. Mtime: time.Now().Unix(),
  9436. Status: 1,
  9437. OrderStatus: 2,
  9438. MdtrtId: his.Number,
  9439. Number: chrg_bchno,
  9440. MedfeeSumamt: totals,
  9441. PayWay: pay_way,
  9442. PayWays: pay_ways,
  9443. PayPrice: pay_price,
  9444. MedType: strconv.Itoa(int(reg_type)),
  9445. PayCardNo: pay_card_no,
  9446. DiscountPrice: discount_price,
  9447. PreferentialPrice: preferential_price,
  9448. RealityPrice: reality_price,
  9449. FoundPrice: found_price,
  9450. MedicalInsurancePrice: medical_insurance_price,
  9451. PrivatePrice: private_price,
  9452. SettleEndTime: end_time,
  9453. SettleStartTime: start_time,
  9454. PsnPartAmt: totals,
  9455. PsnCashPay: totals,
  9456. SettleType: settle_accounts_type,
  9457. FaPiaoCode: fapiao_code,
  9458. FaPiaoNumber: fapiao_number,
  9459. Diagnosis: diagnosis_id,
  9460. PType: 2,
  9461. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9462. Decimal: decimal,
  9463. OthDesc: oth_desc,
  9464. CashPay: cash_pay,
  9465. WechatPay: wechat_pay,
  9466. AliPay: ali_pay,
  9467. JifenPay: jifen_pay,
  9468. BandCardPay: band_card_pay,
  9469. Creator: adminUser.AdminUser.Id,
  9470. CardDesc: card_desc,
  9471. }
  9472. err = service.CreateOrderTX(order, tx)
  9473. if err != nil {
  9474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9475. return
  9476. }
  9477. var customs []*Custom
  9478. for _, item := range prescriptions {
  9479. if item.Type == 1 { //药品a
  9480. for _, subItem := range item.HisDoctorAdviceInfo {
  9481. cus := &Custom{
  9482. AdviceId: subItem.ID,
  9483. ProjectId: 0,
  9484. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9485. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9486. FeedetlSn: subItem.FeedetlSn,
  9487. Price: fmt.Sprintf("%.4f", subItem.Price),
  9488. MedListCodg: subItem.MedListCodg,
  9489. Type: 1,
  9490. CostType: 9,
  9491. }
  9492. customs = append(customs, cus)
  9493. }
  9494. }
  9495. if item.Type == 2 { //项目
  9496. for _, subItem := range item.HisPrescriptionProject {
  9497. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9498. cus := &Custom{
  9499. AdviceId: 0,
  9500. ProjectId: subItem.ID,
  9501. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9502. Cut: fmt.Sprintf("%.4f", cnt),
  9503. FeedetlSn: subItem.FeedetlSn,
  9504. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9505. MedListCodg: subItem.MedListCodg,
  9506. Type: 2,
  9507. CostType: subItem.HisProject.CostClassify,
  9508. }
  9509. customs = append(customs, cus)
  9510. }
  9511. }
  9512. for _, item := range item.HisAdditionalCharge {
  9513. cus := &Custom{
  9514. ItemId: item.ID,
  9515. AdviceId: 0,
  9516. ProjectId: 0,
  9517. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9518. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9519. FeedetlSn: item.FeedetlSn,
  9520. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9521. MedListCodg: item.XtHisAddtionConfig.Code,
  9522. Type: 3,
  9523. CostType: 5,
  9524. }
  9525. customs = append(customs, cus)
  9526. }
  9527. }
  9528. for _, item := range customs {
  9529. var advice_id int64 = 0
  9530. var project_id int64 = 0
  9531. var item_id int64 = 0
  9532. var types int64 = 0
  9533. var med_chrgitm_type string
  9534. if item.Type == 1 {
  9535. advice_id = item.AdviceId
  9536. project_id = 0
  9537. item_id = 0
  9538. med_chrgitm_type = "09"
  9539. } else if item.Type == 2 {
  9540. med_chrgitm_type = "05"
  9541. if item.CostType == 3 {
  9542. med_chrgitm_type = "04"
  9543. }
  9544. if item.CostType == 8 {
  9545. med_chrgitm_type = "03"
  9546. }
  9547. advice_id = 0
  9548. item_id = 0
  9549. project_id = item.ProjectId
  9550. } else if item.Type == 3 {
  9551. advice_id = 0
  9552. item_id = item.ItemId
  9553. project_id = 0
  9554. med_chrgitm_type = "08"
  9555. }
  9556. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9557. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9558. pric, _ := strconv.ParseFloat(item.Price, 32)
  9559. info := &models.HisOrderInfo{
  9560. OrderNumber: order.Number,
  9561. UploadDate: time.Now().Unix(),
  9562. AdviceId: advice_id,
  9563. DetItemFeeSumamt: detItemFeeSumamt,
  9564. MedChrgitmType: med_chrgitm_type,
  9565. Cnt: cut,
  9566. Pric: pric,
  9567. PatientId: id,
  9568. Status: 1,
  9569. Mtime: time.Now().Unix(),
  9570. Ctime: time.Now().Unix(),
  9571. UserOrgId: adminUser.CurrentOrgId,
  9572. HisPatientId: his.ID,
  9573. OrderId: order.ID,
  9574. ProjectId: project_id,
  9575. Type: types,
  9576. ItemId: item_id,
  9577. }
  9578. service.CreateOrderInfoTX(info, tx)
  9579. }
  9580. his.Diagnosis = diagnosis_id
  9581. his.SickType = sick_type
  9582. his.RegisterType = reg_type
  9583. his.MedicalTreatmentType = reg_type
  9584. service.UpdataHisPateintTX(&his, tx)
  9585. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  9586. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  9587. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  9588. //判断是否使用了押金
  9589. if dec_way == "true" {
  9590. tmpstring := strconv.FormatInt(order.ID, 10)
  9591. //扣押金
  9592. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  9593. order.Decimal = decimal
  9594. service.UpDateOrderTwo(order, tx)
  9595. if errmsg != nil {
  9596. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  9597. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9598. return
  9599. }
  9600. }
  9601. if err == nil {
  9602. for _, info := range prescriptions {
  9603. if info.Type == 1 {
  9604. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  9605. }
  9606. if info.Type == 2 {
  9607. for _, sumItem := range info.HisPrescriptionProject {
  9608. if sumItem.Type == 3 {
  9609. var good models.DialysisBeforePrepareGoods
  9610. var newGood models.NewDialysisBeforePrepareGoods
  9611. var oldGood models.OldDialysisBeforePrepareGoods
  9612. good.GoodId = sumItem.GoodInfo.ID
  9613. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9614. count, _ := strconv.Atoi(sumItem.Count)
  9615. good.Count = int64(count)
  9616. good.StorehouseId = houseConfig.StorehouseOutInfo
  9617. good.ProjectId = sumItem.ID
  9618. good.PatientId = sumItem.PatientId
  9619. goods = append(goods, &good)
  9620. newGood.GoodId = sumItem.GoodInfo.ID
  9621. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9622. count2, _ := strconv.Atoi(sumItem.Count)
  9623. newGood.Count = int64(count2)
  9624. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9625. newGood.ProjectId = sumItem.ID
  9626. newGood.PatientId = sumItem.HisPatientId
  9627. newGoods = append(newGoods, &newGood)
  9628. oldGood.GoodId = sumItem.GoodInfo.ID
  9629. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9630. count3, _ := strconv.Atoi(sumItem.Count)
  9631. oldGood.Count = int64(count3)
  9632. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9633. oldGood.ProjectId = sumItem.ID
  9634. oldGood.RecordDate = sumItem.RecordDate
  9635. oldGood.PatientId = sumItem.HisPatientId
  9636. oldGoods = append(oldGoods, &oldGood)
  9637. }
  9638. }
  9639. }
  9640. }
  9641. if settConfig.IsOpen == 1 {
  9642. for _, item := range infoList {
  9643. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9644. if medical.IsUse == 2 {
  9645. //药品出库
  9646. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9647. //查询默认仓库
  9648. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9649. //查询默认仓库剩余多少库存
  9650. var sum_count int64
  9651. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9652. for _, its := range stockInfo {
  9653. if its.MaxUnit == medical.MaxUnit {
  9654. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9655. }
  9656. sum_count += its.StockMaxNumber + its.StockMinNumber
  9657. }
  9658. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9659. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9660. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9661. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9662. }
  9663. }
  9664. orgId := c.GetAdminUserInfo().CurrentOrgId
  9665. if len(oldGoods) > 0 {
  9666. timeStr := time.Now().Format("2006-01-02")
  9667. timeArr := strings.Split(timeStr, "-")
  9668. total, _ := service.FindAllWarehouseOut(orgId)
  9669. total = total + 1
  9670. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9671. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9672. number = number + total
  9673. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9674. operation_time := time.Now().Unix()
  9675. creater := c.GetAdminUserInfo().AdminUser.Id
  9676. //查询默认出库仓库库存
  9677. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9678. recordDateStr := time.Now().Format("2006-01-02")
  9679. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9680. nowtime := recordDate.Unix()
  9681. warehouseOut := models.WarehouseOut{
  9682. WarehouseOutOrderNumber: warehousing_out_order,
  9683. OperationTime: operation_time,
  9684. OrgId: orgId,
  9685. Creater: creater,
  9686. Ctime: time.Now().Unix(),
  9687. Status: 1,
  9688. WarehouseOutTime: nowtime,
  9689. Type: 1,
  9690. StorehouseId: storeConfig.StorehouseOutInfo,
  9691. IsCheck: 1,
  9692. OrderId: order.ID,
  9693. IsSys: 5,
  9694. }
  9695. //查询是否生成出库单
  9696. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9697. if out.ID == 0 {
  9698. service.AddSigleWarehouseOut(&warehouseOut)
  9699. }
  9700. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9701. for _, item := range oldGoods {
  9702. dialyPrepareOne := models.DialysisBeforePrepare{
  9703. GoodTypeId: item.GoodTypeId,
  9704. GoodId: item.GoodId,
  9705. PatientId: his.PatientId,
  9706. RecordDate: item.RecordDate,
  9707. UserOrgId: adminUser.CurrentOrgId,
  9708. Count: item.Count,
  9709. Ctime: time.Now().Unix(),
  9710. Creater: adminUser.AdminUser.Id,
  9711. CommdityCode: item.CommdityCode,
  9712. Status: 1,
  9713. StorehouseId: houseConfig.StorehouseOutInfo,
  9714. }
  9715. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9716. //非零用
  9717. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9718. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9719. //查询剩余库存
  9720. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9721. var sum_count int64
  9722. for _, item := range goodList {
  9723. sum_count += item.StockCount
  9724. }
  9725. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9726. //耗材
  9727. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9728. }
  9729. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9730. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9731. //查询剩余库存
  9732. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9733. var sum_count int64
  9734. for _, item := range goodList {
  9735. sum_count += item.StockCount
  9736. }
  9737. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9738. //耗材
  9739. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9740. }
  9741. }
  9742. }
  9743. }
  9744. c.ServeSuccessJSON(map[string]interface{}{
  9745. "msg": "结算成功",
  9746. })
  9747. }
  9748. }
  9749. }
  9750. // 退款
  9751. func (c *HisApiController) Refund() {
  9752. order_id, _ := c.GetInt64("order_id")
  9753. order, _ := service.GetHisOrderByID(order_id)
  9754. adminUser := c.GetAdminUserInfo()
  9755. orgid := c.GetAdminUserInfo().CurrentOrgId
  9756. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9757. if err != nil {
  9758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9759. return
  9760. }
  9761. tmp := strconv.FormatInt(order.ID, 10)
  9762. //当押金不为零时产生退费记录
  9763. if order.Decimal != 0 {
  9764. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9765. if err != nil {
  9766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9767. return
  9768. }
  9769. }
  9770. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9771. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9772. var goods []*models.DialysisBeforePrepareGoods
  9773. var newGoods []*models.NewDialysisBeforePrepareGoods
  9774. var infos []*models.HisDoctorAdviceInfo
  9775. for _, info := range orders {
  9776. if info.AdviceId > 0 && info.ProjectId == 0 {
  9777. infos = append(infos, &info.HisDoctorAdviceInfo)
  9778. }
  9779. if info.ProjectId > 0 && info.AdviceId == 0 {
  9780. if info.HisPrescriptionProject.Type == 3 {
  9781. var good models.DialysisBeforePrepareGoods
  9782. var newGood models.NewDialysisBeforePrepareGoods
  9783. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9784. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9785. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9786. good.Count = int64(count)
  9787. good.StorehouseId = houseConfig.StorehouseOutInfo
  9788. good.ProjectId = info.HisPrescriptionProject.ID
  9789. good.PatientId = info.PatientId
  9790. good.OrderId = order_id
  9791. goods = append(goods, &good)
  9792. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9793. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9794. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9795. newGood.Count = int64(count2)
  9796. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9797. newGood.ProjectId = info.HisPrescriptionProject.ID
  9798. newGood.RecordDate = order.SettleAccountsDate
  9799. newGood.UserOrgId = order.UserOrgId
  9800. newGood.PatientId = info.PatientId
  9801. newGood.OrderId = order_id
  9802. newGoods = append(newGoods, &newGood)
  9803. }
  9804. }
  9805. }
  9806. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9807. if settConfig.IsOpen == 1 {
  9808. for _, item := range infos {
  9809. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9810. }
  9811. for _, item := range newGoods {
  9812. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9813. }
  9814. }
  9815. c.ServeSuccessJSON(map[string]interface{}{
  9816. "msg": "退费成功",
  9817. })
  9818. }
  9819. func (c *HisApiController) RefundNumber() {
  9820. his_patient_id, _ := c.GetInt64("id")
  9821. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9822. info.Status = 0
  9823. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9824. if count > 0 {
  9825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9826. return
  9827. }
  9828. err := service.SaveHisPatient(info)
  9829. if err == nil {
  9830. c.ServeSuccessJSON(map[string]interface{}{
  9831. "msg": "退号成功",
  9832. })
  9833. } else {
  9834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9835. return
  9836. }
  9837. }
  9838. func (this *HisApiController) AdditionalCharge() {
  9839. dataBody := make(map[string]interface{}, 0)
  9840. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9841. fmt.Println(err)
  9842. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9843. patient_id := int64(dataBody["patient_id"].(float64))
  9844. medicineData, _ := dataBody["medicineData"].([]interface{})
  9845. adminUserInfo := this.GetAdminUserInfo()
  9846. orgId := adminUserInfo.CurrentOrgId
  9847. admin_user_id := adminUserInfo.AdminUser.Id
  9848. timeStr := time.Now().Format("2006-01-02")
  9849. timeLayout := "2006-01-02 15:04:05"
  9850. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9851. timenow := timeStringToTime.Unix()
  9852. var additionalCharges []*models.HisAdditionalCharge
  9853. for _, item := range medicineData {
  9854. var randNum int
  9855. randNum = rand.Intn(10000) + 1000
  9856. timestamp := time.Now().Unix()
  9857. tempTime := time.Unix(timestamp, 0)
  9858. timeFormat := tempTime.Format("20060102150405")
  9859. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9860. items := item.(map[string]interface{})
  9861. money := items["price"].(string)
  9862. item_id_str := items["item_id"].(string)
  9863. name := items["name"].(string)
  9864. id_str := items["id"].(string)
  9865. moneys, _ := strconv.ParseInt(money, 10, 64)
  9866. monStr := strconv.FormatInt(moneys, 10)
  9867. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9868. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9869. id, _ := strconv.ParseInt(id_str, 10, 64)
  9870. additionalCharge := &models.HisAdditionalCharge{
  9871. ID: id,
  9872. HisPatientId: his_patient_id,
  9873. UserOrgId: orgId,
  9874. PatientId: patient_id,
  9875. RecordDate: timenow,
  9876. Price: monneyStr,
  9877. Status: 1,
  9878. ItemName: name,
  9879. ItemId: item_id,
  9880. AdminUserId: admin_user_id,
  9881. CreatedTime: time.Now().Unix(),
  9882. OrderStatus: 0,
  9883. PrescriptionNumber: "",
  9884. BatchNumber: "",
  9885. FeedetlSn: p_number,
  9886. }
  9887. service.CreateAdditionalCharge(additionalCharge)
  9888. additionalCharges = append(additionalCharges, additionalCharge)
  9889. }
  9890. this.ServeSuccessJSON(map[string]interface{}{
  9891. "msg": "添加成功",
  9892. "additional_charges": additionalCharges,
  9893. })
  9894. }
  9895. func (this *HisApiController) DeleteAddition() {
  9896. id, _ := this.GetInt64("id")
  9897. //TODO 需要判断是否已经结算
  9898. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9899. if err == nil {
  9900. this.ServeSuccessJSON(map[string]interface{}{
  9901. "msg": "删除成功",
  9902. })
  9903. return
  9904. } else {
  9905. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9906. return
  9907. }
  9908. }
  9909. func (this *HisApiController) GetAdminUsers() {
  9910. adminUser := this.GetAdminUserInfo()
  9911. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9912. this.ServeSuccessJSON(map[string]interface{}{
  9913. "doctors": doctors,
  9914. })
  9915. }
  9916. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9917. change_type, _ := this.GetInt64("type", 0)
  9918. record_date := this.GetString("record_time")
  9919. patient_id, _ := this.GetInt64("patient_id", 0)
  9920. p_type, _ := this.GetInt64("p_type", 0)
  9921. timeLayout := "2006-01-02"
  9922. loc, _ := time.LoadLocation("Local")
  9923. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9924. record_time := theAdviceRecordTime.Unix()
  9925. adminUserInfo := this.GetAdminUserInfo()
  9926. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9927. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9928. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9929. if config.ID > 0 && config.IsOpen == 1 {
  9930. for _, subitems := range prescriptions {
  9931. for _, item := range subitems.VMHisPrescription {
  9932. for _, subItem := range item.HisDoctorAdviceInfo {
  9933. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9934. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9935. if info.RetailPrice > 0 {
  9936. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9937. subItem.Drug.RetailPrice = drug.RetailPrice
  9938. }
  9939. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9940. subItem.Drug.MinPrice = info.RetailPrice
  9941. subItem.Drug.RetailPrice = info.RetailPrice
  9942. }
  9943. }
  9944. }
  9945. }
  9946. }
  9947. }
  9948. if config.ID > 0 && config.IsOpen == 1 {
  9949. for _, subitems := range prescriptions {
  9950. for _, item := range subitems.VMHisPrescription {
  9951. for _, subItem := range item.HisPrescriptionProject {
  9952. if subItem.Type == 3 {
  9953. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9954. if info.Price > 0 {
  9955. subItem.GoodInfo.PackingPrice = info.Price
  9956. }
  9957. }
  9958. }
  9959. }
  9960. }
  9961. }
  9962. }
  9963. if err == nil {
  9964. if len(prescriptions) == 0 {
  9965. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9966. return
  9967. } else {
  9968. this.ServeSuccessJSON(map[string]interface{}{
  9969. "prescriptions": prescriptions,
  9970. })
  9971. return
  9972. }
  9973. } else {
  9974. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9975. return
  9976. }
  9977. }
  9978. func (this *HisApiController) GetCallHisPrescription() {
  9979. patient_id, _ := this.GetInt64("patient_id", 0)
  9980. timeLayout := "2006-01-02"
  9981. loc, _ := time.LoadLocation("Local")
  9982. start_time := this.GetString("start_time")
  9983. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9984. end_time := this.GetString("end_time")
  9985. p_type, _ := this.GetInt64("p_type")
  9986. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9987. adminUserInfo := this.GetAdminUserInfo()
  9988. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9989. //if
  9990. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9991. //
  9992. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9993. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9994. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9995. if config.ID > 0 && config.IsOpen == 1 {
  9996. for _, subitems := range prescriptions {
  9997. for _, item := range subitems.VMHisPrescription {
  9998. for _, subItem := range item.HisDoctorAdviceInfo {
  9999. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10000. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10001. if info.RetailPrice > 0 {
  10002. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10003. subItem.Drug.RetailPrice = drug.RetailPrice
  10004. }
  10005. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10006. subItem.Drug.MinPrice = info.RetailPrice
  10007. subItem.Drug.RetailPrice = info.RetailPrice
  10008. }
  10009. }
  10010. }
  10011. }
  10012. }
  10013. }
  10014. if config.ID > 0 && config.IsOpen == 1 {
  10015. for _, subitems := range prescriptions {
  10016. for _, item := range subitems.VMHisPrescription {
  10017. for _, subItem := range item.HisPrescriptionProject {
  10018. if subItem.Type == 3 {
  10019. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10020. if info.Price > 0 {
  10021. subItem.GoodInfo.PackingPrice = info.Price
  10022. }
  10023. }
  10024. }
  10025. }
  10026. }
  10027. }
  10028. }
  10029. if err == nil {
  10030. this.ServeSuccessJSON(map[string]interface{}{
  10031. "prescriptions": prescriptions,
  10032. })
  10033. return
  10034. } else {
  10035. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10036. return
  10037. }
  10038. }
  10039. func (this *HisApiController) GetHisDayPrescription() {
  10040. timeLayout := "2006-01-02"
  10041. loc, _ := time.LoadLocation("Local")
  10042. start_time := this.GetString("start_time")
  10043. patient_id, _ := this.GetInt64("patient_id", 0)
  10044. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10045. end_time := this.GetString("end_time")
  10046. p_type, _ := this.GetInt64("p_type")
  10047. order_status, _ := this.GetInt64("type")
  10048. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10049. adminUserInfo := this.GetAdminUserInfo()
  10050. var dayHisPrescription []*models.HisPrescription
  10051. var err error
  10052. if order_status == 1 || order_status == 0 {
  10053. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10054. } else if order_status == 2 {
  10055. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10056. }
  10057. var settle_total float64
  10058. for _, item := range dayHisPrescription {
  10059. if len(item.HisPrescriptionProject) > 0 {
  10060. for _, subItem := range item.HisPrescriptionProject {
  10061. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10062. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10063. settle_total = settle_total + total
  10064. }
  10065. }
  10066. if len(item.HisDoctorAdviceInfo) > 0 {
  10067. for _, subItem := range item.HisDoctorAdviceInfo {
  10068. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10069. settle_total = settle_total + total
  10070. }
  10071. }
  10072. }
  10073. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10074. if err == nil {
  10075. this.ServeSuccessJSON(map[string]interface{}{
  10076. "day_prescription": dayHisPrescription,
  10077. "settle_total": settle_total,
  10078. })
  10079. return
  10080. } else {
  10081. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10082. return
  10083. }
  10084. }
  10085. func (c *HisApiController) GetHisChargePatientList() {
  10086. record_date := c.GetString("record_date")
  10087. order_status, _ := c.GetInt64("type")
  10088. sch_type, _ := c.GetInt64("sch_type")
  10089. timeLayout := "2006-01-02"
  10090. loc, _ := time.LoadLocation("Local")
  10091. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10092. if err != nil {
  10093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10094. return
  10095. }
  10096. recordDateTime := theTime.Unix()
  10097. adminInfo := c.GetAdminUserInfo()
  10098. var tempPatients []*service.NewTempPatients
  10099. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10100. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10101. if order_status != 2 {
  10102. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10103. } else {
  10104. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10105. }
  10106. } else {
  10107. if order_status != 2 {
  10108. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10109. } else {
  10110. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10111. }
  10112. }
  10113. var patients []*service.NewTempPatients
  10114. var patients_two []*service.NewTempPatients
  10115. for _, item := range tempPatients {
  10116. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10117. //过滤掉没挂号的和没开处方的
  10118. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10119. patients = append(patients, item)
  10120. }
  10121. //过滤掉没挂号的
  10122. if len(item.HisPatient) > 0 {
  10123. patients_two = append(patients_two, item)
  10124. }
  10125. } else {
  10126. if len(item.HisPrescription) > 0 {
  10127. patients = append(patients, item)
  10128. }
  10129. }
  10130. }
  10131. c.ServeSuccessJSON(map[string]interface{}{
  10132. "list": patients,
  10133. "list_two": patients_two,
  10134. })
  10135. }
  10136. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10137. record_date := c.GetString("record_date")
  10138. timeLayout := "2006-01-02"
  10139. loc, _ := time.LoadLocation("Local")
  10140. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10141. if err != nil {
  10142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10143. return
  10144. }
  10145. recordDateTime := theTime.Unix()
  10146. adminUser := c.GetAdminUserInfo()
  10147. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10148. var patients []*service.Patients
  10149. for _, item := range tempPatients {
  10150. if item.HisPatient.ID == 0 {
  10151. patients = append(patients, item)
  10152. }
  10153. }
  10154. c.ServeSuccessJSON(map[string]interface{}{
  10155. "list": patients,
  10156. //"list_two": patients_two,
  10157. })
  10158. }
  10159. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10160. newArr = make([]*service.Patients, 0)
  10161. for i := 0; i < len(patient); i++ {
  10162. repeat := false
  10163. for j := i + 1; j < len(patient); j++ {
  10164. if patient[i].ID == patient[j].ID {
  10165. repeat = true
  10166. break
  10167. }
  10168. }
  10169. if !repeat {
  10170. newArr = append(newArr, patient[i])
  10171. }
  10172. }
  10173. return
  10174. }
  10175. func (c *HisApiController) GetHisChargePatientInfo() {
  10176. patient_id, _ := c.GetInt64("patient_id")
  10177. his_patient_id, _ := c.GetInt64("his_patient_id")
  10178. record_date := c.GetString("record_date")
  10179. //start_time := c.GetString("start_time")
  10180. //end_time := c.GetString("end_time")
  10181. order_status, _ := c.GetInt64("type", 0)
  10182. p_type, _ := c.GetInt64("p_type", 0)
  10183. order_id, _ := c.GetInt64("order_id", 0)
  10184. timeLayout := "2006-01-02"
  10185. loc, _ := time.LoadLocation("Local")
  10186. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10187. if err != nil {
  10188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10189. return
  10190. }
  10191. recordDateTime := theTime.Unix()
  10192. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10193. //if err != nil {
  10194. //
  10195. //}
  10196. //startRecordDateTime := startTime.Unix()
  10197. //
  10198. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10199. //if err != nil {
  10200. //
  10201. //}
  10202. //endRecordDateTime := endTime.Unix()
  10203. admin := c.GetAdminUserInfo()
  10204. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10205. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10206. var prescriptions []*models.HisPrescription
  10207. //var unChargeMonthPrescriptions []*models.HisPrescription
  10208. order, _ := service.GetHisOrderByID(order_id)
  10209. if order_status == 1 || order_status == 0 {
  10210. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10211. } else if order_status == 2 {
  10212. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10213. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10214. }
  10215. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10216. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10217. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10218. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10219. //获取所有科室信息
  10220. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10221. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10222. c.ServeSuccessJSON(map[string]interface{}{
  10223. "his_info": his_patient_info,
  10224. "xt_info": xt_patient_info,
  10225. "prescription": prescriptions,
  10226. "case_history": case_history,
  10227. "info": patientPrescriptionInfo,
  10228. "last_info": lastPatientPrescriptionInfo,
  10229. "order": order,
  10230. "doctors": doctors,
  10231. "department": department,
  10232. "sch": sch,
  10233. })
  10234. return
  10235. }
  10236. func (c *HisApiController) GetAllOrderDetail() {
  10237. order_id, _ := c.GetInt64("id", 0)
  10238. order, _ := service.GetHisOrderByID(order_id)
  10239. if order.ID == 0 {
  10240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10241. return
  10242. }
  10243. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10244. org_id := c.GetAdminUserInfo().CurrentOrgId
  10245. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10246. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10247. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10248. c.ServeSuccessJSON(map[string]interface{}{
  10249. "order": order,
  10250. "order_info": order_info,
  10251. "patient": patient,
  10252. "admin_info": adminInfo,
  10253. "hospital_record": record,
  10254. })
  10255. return
  10256. }
  10257. func (c *HisApiController) GetAllOrderDetailCollect() {
  10258. order_id, _ := c.GetInt64("id", 0)
  10259. order, _ := service.GetHisOrderByID(order_id)
  10260. if order.ID == 0 {
  10261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10262. return
  10263. }
  10264. org_id := c.GetAdminUserInfo().CurrentOrgId
  10265. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10266. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10267. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10268. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10269. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10270. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10271. var bedCostTotal float64 = 0 //床位总费
  10272. //var bedCostSelfTotal float64 = 0 //床位自费
  10273. var operationCostTotal float64 = 0 //手术费
  10274. //var operationCostSelfTotal float64 = 0 //手术费
  10275. var otherCostTotal float64 = 0 //其他费用
  10276. //var otherCostSelfTotal float64 = 0 //其他费用
  10277. var materialCostTotal float64 = 0 //材料费
  10278. //var materialCostSelfTotal float64 = 0 //材料费
  10279. var westernMedicineCostTotal float64 = 0 //西药费
  10280. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10281. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10282. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10283. var checkCostTotal float64 = 0 //检查费
  10284. //var checkCostSelfTotal float64 = 0 //检查费
  10285. var laboratoryCostTotal float64 = 0 //化验费
  10286. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10287. var treatCostTotal float64 = 0 //治疗费用
  10288. //var treatCostSelfTotal float64 = 0 //治疗费用
  10289. var zhenChaCostTotal float64 = 0 //其他费用
  10290. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10291. decimal.DivisionPrecision = 2
  10292. var BalanceAccountsType int64
  10293. if his.ID > 0 {
  10294. BalanceAccountsType = his.BalanceAccountsType
  10295. } else {
  10296. BalanceAccountsType = record.BalanceAccountsType
  10297. }
  10298. if BalanceAccountsType != 2 {
  10299. for _, item := range order_info {
  10300. if org_id == 10215 {
  10301. if item.MedChrgitmType == "01" { //床位费
  10302. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10303. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10304. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10305. }
  10306. if item.MedChrgitmType == "02" { //诊察费
  10307. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10308. //zhenChaCostSelfTotal = zhenChaCostTotal
  10309. }
  10310. if item.MedChrgitmType == "03" { //检查费
  10311. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10312. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10313. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10314. }
  10315. //if item.MedChrgitmType == "02" { //检查费
  10316. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10317. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10318. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10319. //}
  10320. if item.MedChrgitmType == "04" { //化验费
  10321. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10322. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10323. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10324. }
  10325. if item.MedChrgitmType == "05" { //治疗费
  10326. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10327. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10328. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10329. }
  10330. if item.MedChrgitmType == "06" { //手术费
  10331. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10332. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10333. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10334. }
  10335. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10336. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10337. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10338. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10339. }
  10340. if item.MedChrgitmType == "09" { //西药费
  10341. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10342. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10343. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10344. }
  10345. if item.MedChrgitmType == "11" { //中成费
  10346. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10347. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10348. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10349. }
  10350. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10351. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10352. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10353. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10354. }
  10355. } else if org_id == 10188 || org_id == 10217 {
  10356. if item.MedChrgitmType == "01" { //床位费
  10357. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10358. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10359. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10360. }
  10361. if item.MedChrgitmType == "02" { //诊察费
  10362. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10363. //zhenChaCostSelfTotal = zhenChaCostTotal
  10364. }
  10365. if item.MedChrgitmType == "03" { //检查费
  10366. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10367. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10368. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10369. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10370. }
  10371. //if item.MedChrgitmType == "02" { //检查费
  10372. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10373. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10374. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10375. //}
  10376. if item.MedChrgitmType == "04" { //化验费
  10377. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10378. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10379. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10380. }
  10381. if item.MedChrgitmType == "05" { //治疗费
  10382. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10383. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10384. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10385. }
  10386. if item.MedChrgitmType == "06" { //手术费
  10387. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10388. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10389. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10390. }
  10391. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10392. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10393. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10394. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10395. }
  10396. if item.MedChrgitmType == "09" { //西药费
  10397. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10398. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10399. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10400. }
  10401. if item.MedChrgitmType == "11" { //中成费
  10402. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10403. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10404. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10405. }
  10406. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10407. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10408. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10409. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10410. }
  10411. } else {
  10412. if item.MedChrgitmType == "01" { //床位费
  10413. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10414. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10415. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10416. }
  10417. //if item.MedChrgitmType == "02" { //诊察费
  10418. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10419. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10420. //}
  10421. if item.MedChrgitmType == "03" { //检查费
  10422. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10423. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10424. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10425. }
  10426. //if item.MedChrgitmType == "02" { //检查费
  10427. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10428. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10429. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10430. //}
  10431. if item.MedChrgitmType == "04" { //化验费
  10432. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10433. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10434. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10435. }
  10436. if item.MedChrgitmType == "05" { //治疗费
  10437. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10438. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10439. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10440. }
  10441. if item.MedChrgitmType == "06" { //手术费
  10442. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10443. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10444. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10445. }
  10446. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10447. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10448. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10449. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10450. }
  10451. if item.MedChrgitmType == "09" { //西药费
  10452. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10453. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10454. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10455. }
  10456. if item.MedChrgitmType == "11" { //中成费
  10457. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10458. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10459. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10460. }
  10461. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10462. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10463. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10464. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10465. }
  10466. }
  10467. }
  10468. c.ServeSuccessJSON(map[string]interface{}{
  10469. "order": order,
  10470. "order_info": order_info,
  10471. "patient": patient,
  10472. "admin_info": adminInfo,
  10473. "his_hospital": record,
  10474. "bedCostTotal": bedCostTotal,
  10475. "operationCostTotal": operationCostTotal,
  10476. "otherCostTotal": otherCostTotal,
  10477. "materialCostTotal": materialCostTotal,
  10478. "westernMedicineCostTotal": westernMedicineCostTotal,
  10479. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10480. "checkCostTotal": checkCostTotal,
  10481. "zhenChaCostTotal": zhenChaCostTotal,
  10482. "laboratoryCostTotal": laboratoryCostTotal,
  10483. "treatCostTotal": treatCostTotal,
  10484. })
  10485. } else {
  10486. for _, item := range order_info {
  10487. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10488. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10489. item.MedChrgitmType = "09"
  10490. }
  10491. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10492. if item.HisPrescriptionProject.Type == 2 {
  10493. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10494. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10495. case 0:
  10496. item.MedChrgitmType = "0"
  10497. break
  10498. case 1:
  10499. item.MedChrgitmType = "14"
  10500. break
  10501. case 2:
  10502. item.MedChrgitmType = "05"
  10503. break
  10504. case 3:
  10505. item.MedChrgitmType = "03"
  10506. break
  10507. case 4:
  10508. item.MedChrgitmType = "03"
  10509. break
  10510. case 5:
  10511. item.MedChrgitmType = "08"
  10512. break
  10513. case 6:
  10514. item.MedChrgitmType = "14"
  10515. break
  10516. case 7:
  10517. item.MedChrgitmType = "14"
  10518. break
  10519. case 8:
  10520. item.MedChrgitmType = "03"
  10521. break
  10522. case 9:
  10523. item.MedChrgitmType = "14"
  10524. break
  10525. case 10:
  10526. item.MedChrgitmType = "14"
  10527. break
  10528. case 11:
  10529. item.MedChrgitmType = "06"
  10530. break
  10531. case 12:
  10532. item.MedChrgitmType = "12"
  10533. break
  10534. case 13:
  10535. item.MedChrgitmType = "01"
  10536. break
  10537. case 14:
  10538. item.MedChrgitmType = "04"
  10539. break
  10540. case 15:
  10541. item.MedChrgitmType = "14"
  10542. break
  10543. }
  10544. } else {
  10545. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10546. case 1:
  10547. item.MedChrgitmType = "14"
  10548. break
  10549. case 2:
  10550. item.MedChrgitmType = "05"
  10551. break
  10552. case 3:
  10553. item.MedChrgitmType = "04"
  10554. break
  10555. case 4:
  10556. item.MedChrgitmType = "14"
  10557. break
  10558. case 5:
  10559. item.MedChrgitmType = "08"
  10560. break
  10561. case 6:
  10562. item.MedChrgitmType = "14"
  10563. break
  10564. case 7:
  10565. item.MedChrgitmType = "14"
  10566. break
  10567. case 8:
  10568. item.MedChrgitmType = "03"
  10569. break
  10570. case 9:
  10571. item.MedChrgitmType = "14"
  10572. break
  10573. }
  10574. }
  10575. } else if item.HisPrescriptionProject.Type == 3 {
  10576. item.MedChrgitmType = "08"
  10577. }
  10578. }
  10579. }
  10580. for _, item := range order_info {
  10581. if org_id == 10215 {
  10582. if item.MedChrgitmType == "01" { //床位费
  10583. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10584. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10585. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10586. }
  10587. if item.MedChrgitmType == "02" { //诊察费
  10588. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10589. //zhenChaCostSelfTotal = zhenChaCostTotal
  10590. }
  10591. if item.MedChrgitmType == "03" { //检查费
  10592. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10593. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10594. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10595. }
  10596. //if item.MedChrgitmType == "02" { //检查费
  10597. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10598. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10599. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10600. //}
  10601. if item.MedChrgitmType == "04" { //化验费
  10602. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10603. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10604. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10605. }
  10606. if item.MedChrgitmType == "05" { //治疗费
  10607. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10608. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10609. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10610. }
  10611. if item.MedChrgitmType == "06" { //手术费
  10612. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10613. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10614. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10615. }
  10616. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10617. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10618. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10619. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10620. }
  10621. if item.MedChrgitmType == "09" { //西药费
  10622. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10623. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10624. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10625. }
  10626. if item.MedChrgitmType == "11" { //中成费
  10627. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10628. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10629. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10630. }
  10631. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10632. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10633. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10634. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10635. }
  10636. } else {
  10637. if item.MedChrgitmType == "01" { //床位费
  10638. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10639. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10640. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10641. }
  10642. //if item.MedChrgitmType == "02" { //诊察费
  10643. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10644. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10645. //}
  10646. if item.MedChrgitmType == "03" { //检查费
  10647. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10648. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10649. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10650. }
  10651. //if item.MedChrgitmType == "02" { //检查费
  10652. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10653. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10654. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10655. //}
  10656. if item.MedChrgitmType == "04" { //化验费
  10657. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10658. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10659. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10660. }
  10661. if item.MedChrgitmType == "05" { //治疗费
  10662. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10663. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10664. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10665. }
  10666. if item.MedChrgitmType == "06" { //手术费
  10667. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10668. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10669. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10670. }
  10671. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10672. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10673. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10674. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10675. }
  10676. if item.MedChrgitmType == "09" { //西药费
  10677. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10678. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10679. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10680. }
  10681. if item.MedChrgitmType == "11" { //中成费
  10682. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10683. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10684. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10685. }
  10686. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10687. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10688. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10689. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10690. }
  10691. }
  10692. }
  10693. c.ServeSuccessJSON(map[string]interface{}{
  10694. "order": order,
  10695. "order_info": order_info,
  10696. "patient": patient,
  10697. "admin_info": adminInfo,
  10698. "his_hospital": record,
  10699. "bedCostTotal": bedCostTotal,
  10700. "operationCostTotal": operationCostTotal,
  10701. "otherCostTotal": otherCostTotal,
  10702. "materialCostTotal": materialCostTotal,
  10703. "westernMedicineCostTotal": westernMedicineCostTotal,
  10704. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10705. "checkCostTotal": checkCostTotal,
  10706. "zhenChaCostTotal": zhenChaCostTotal,
  10707. "laboratoryCostTotal": laboratoryCostTotal,
  10708. "treatCostTotal": treatCostTotal,
  10709. })
  10710. }
  10711. }
  10712. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10713. page, _ := c.GetInt64("page")
  10714. limit, _ := c.GetInt64("limit")
  10715. keywords := c.GetString("keywords")
  10716. start_time := c.GetString("start_time")
  10717. end_time := c.GetString("end_time")
  10718. //clr_type := c.GetString("clr_type")
  10719. insutype := c.GetString("insutype")
  10720. timeLayout := "2006-01-02"
  10721. loc, _ := time.LoadLocation("Local")
  10722. var theStartTIme int64
  10723. if len(start_time) > 0 {
  10724. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10725. theStartTIme = theTime.Unix()
  10726. }
  10727. var theEndtTIme int64
  10728. if len(end_time) > 0 {
  10729. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10730. theEndtTIme = theTime.Unix()
  10731. }
  10732. if page <= 0 {
  10733. page = 1
  10734. }
  10735. if limit <= 0 {
  10736. limit = 10
  10737. }
  10738. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10739. c.ServeSuccessJSON(map[string]interface{}{
  10740. "total": total,
  10741. "list": list,
  10742. })
  10743. return
  10744. }
  10745. func (c *HisApiController) GetPutOnRecordList() {
  10746. page, _ := c.GetInt64("page")
  10747. limit, _ := c.GetInt64("limit")
  10748. keywords := c.GetString("keywords")
  10749. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10750. if page <= 0 {
  10751. page = 1
  10752. }
  10753. if limit <= 0 {
  10754. limit = 10
  10755. }
  10756. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10757. c.ServeSuccessJSON(map[string]interface{}{
  10758. "total": total,
  10759. "list": list,
  10760. })
  10761. return
  10762. }
  10763. func (c *HisApiController) GetCompareData() {
  10764. start_time := c.GetString("start_time")
  10765. end_time := c.GetString("end_time")
  10766. insutype := c.GetString("insutype")
  10767. clr_type := c.GetString("clr_type")
  10768. timeLayout := "2006-01-02"
  10769. loc, _ := time.LoadLocation("Local")
  10770. var theStartTIme int64
  10771. if len(start_time) > 0 {
  10772. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10773. if err != nil {
  10774. theStartTIme = 0
  10775. }
  10776. theStartTIme = theTime.Unix()
  10777. }
  10778. var theEndtTIme int64
  10779. if len(end_time) > 0 {
  10780. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10781. if err != nil {
  10782. theEndtTIme = 0
  10783. }
  10784. theEndtTIme = theTime.Unix()
  10785. }
  10786. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10787. fmt.Println(err)
  10788. if err == nil {
  10789. c.ServeSuccessJSON(map[string]interface{}{
  10790. "list": formData,
  10791. })
  10792. } else {
  10793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10794. return
  10795. }
  10796. }
  10797. func (c *HisApiController) GetFaPiaoData() {
  10798. order_id, _ := c.GetInt64("order_id")
  10799. patient_id, _ := c.GetInt64("patient_id")
  10800. //number := c.GetString("number")
  10801. adminUser := c.GetAdminUserInfo()
  10802. order, _ := service.GetHisOrderByID(order_id)
  10803. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10804. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10805. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10806. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10807. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10808. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10809. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10810. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10811. var bedCostTotal float64 = 0 //床位总费
  10812. var bedCostSelfTotal float64 = 0 //床位自费
  10813. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10814. var operationCostTotal float64 = 0 //手术费
  10815. var operationCostSelfTotal float64 = 0 //手术费
  10816. var operationCostPartSelfTotal float64 = 0 //手术费
  10817. var otherCostTotal float64 = 0 //其他费用
  10818. var otherCostSelfTotal float64 = 0 //其他费用
  10819. var otherCostPartSelfTotal float64 = 0 //其他费用
  10820. var materialCostTotal float64 = 0 //材料费
  10821. var materialCostSelfTotal float64 = 0 //材料费
  10822. var materialCostPartSelfTotal float64 = 0 //材料费
  10823. var westernMedicineCostTotal float64 = 0 //西药费
  10824. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10825. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10826. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10827. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10828. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10829. var checkCostTotal float64 = 0 //检查费
  10830. var checkCostSelfTotal float64 = 0 //检查费
  10831. var checkCostPartSelfTotal float64 = 0 //检查费
  10832. var hiliCostTotal float64 = 0 //护理费
  10833. var hiliCostSelfTotal float64 = 0 //护理费
  10834. var hiliCostPartSelfTotal float64 = 0 //护理费
  10835. var laboratoryCostTotal float64 = 0 //化验费
  10836. var laboratoryCostSelfTotal float64 = 0 //化验费
  10837. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10838. var treatCostTotal float64 = 0 //治疗费用
  10839. var treatCostSelfTotal float64 = 0 //治疗费用
  10840. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10841. var zhenChaCostTotal float64 = 0 //其他费用
  10842. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10843. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10844. decimal.DivisionPrecision = 2
  10845. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10846. var balanceAccountsType int64
  10847. if his.ID > 0 {
  10848. balanceAccountsType = his.BalanceAccountsType
  10849. } else {
  10850. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10851. }
  10852. if balanceAccountsType == 2 {
  10853. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10854. for _, item := range orderInfos_two {
  10855. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10856. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10857. item.MedChrgitmType = "09"
  10858. }
  10859. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10860. if item.HisPrescriptionProject.Type == 2 {
  10861. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10862. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10863. case 0:
  10864. item.MedChrgitmType = "0"
  10865. break
  10866. case 1:
  10867. item.MedChrgitmType = "14"
  10868. break
  10869. case 2:
  10870. item.MedChrgitmType = "05"
  10871. break
  10872. case 3:
  10873. item.MedChrgitmType = "03"
  10874. break
  10875. case 4:
  10876. item.MedChrgitmType = "03"
  10877. break
  10878. case 5:
  10879. item.MedChrgitmType = "08"
  10880. break
  10881. case 6:
  10882. item.MedChrgitmType = "14"
  10883. break
  10884. case 7:
  10885. item.MedChrgitmType = "14"
  10886. break
  10887. case 8:
  10888. item.MedChrgitmType = "03"
  10889. break
  10890. case 9:
  10891. item.MedChrgitmType = "14"
  10892. break
  10893. case 10:
  10894. item.MedChrgitmType = "14"
  10895. break
  10896. case 11:
  10897. item.MedChrgitmType = "06"
  10898. break
  10899. case 12:
  10900. item.MedChrgitmType = "12"
  10901. break
  10902. case 13:
  10903. item.MedChrgitmType = "01"
  10904. break
  10905. case 14:
  10906. item.MedChrgitmType = "04"
  10907. break
  10908. case 15:
  10909. item.MedChrgitmType = "02"
  10910. break
  10911. }
  10912. } else {
  10913. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10914. case 1:
  10915. item.MedChrgitmType = "14"
  10916. break
  10917. case 2:
  10918. item.MedChrgitmType = "05"
  10919. break
  10920. case 3:
  10921. item.MedChrgitmType = "04"
  10922. break
  10923. case 4:
  10924. item.MedChrgitmType = "03"
  10925. break
  10926. case 5:
  10927. item.MedChrgitmType = "08"
  10928. break
  10929. case 6:
  10930. item.MedChrgitmType = "14"
  10931. break
  10932. case 7:
  10933. item.MedChrgitmType = "14"
  10934. break
  10935. case 8:
  10936. item.MedChrgitmType = "03"
  10937. break
  10938. case 9:
  10939. item.MedChrgitmType = "14"
  10940. break
  10941. }
  10942. }
  10943. } else if item.HisPrescriptionProject.Type == 3 {
  10944. item.MedChrgitmType = "08"
  10945. }
  10946. }
  10947. }
  10948. for _, item := range orderInfos_two {
  10949. fmt.Println(item.MedChrgitmType)
  10950. if item.MedChrgitmType == "07" { //床位费
  10951. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10952. hiliCostSelfTotal = hiliCostTotal
  10953. }
  10954. if item.MedChrgitmType == "01" { //床位费
  10955. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10956. bedCostSelfTotal = bedCostTotal
  10957. }
  10958. if item.MedChrgitmType == "02" { //诊察费
  10959. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10960. zhenChaCostSelfTotal = zhenChaCostTotal
  10961. }
  10962. if item.MedChrgitmType == "03" { //检查费
  10963. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10964. checkCostSelfTotal = checkCostTotal
  10965. }
  10966. if item.MedChrgitmType == "04" { //化验费
  10967. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10968. laboratoryCostSelfTotal = laboratoryCostTotal
  10969. }
  10970. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10971. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10972. treatCostSelfTotal = treatCostTotal
  10973. }
  10974. if item.MedChrgitmType == "06" { //手术费
  10975. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10976. operationCostSelfTotal = treatCostTotal
  10977. }
  10978. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10979. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10980. materialCostSelfTotal = materialCostTotal
  10981. }
  10982. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10983. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10984. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10985. }
  10986. if item.MedChrgitmType == "11" { //中成费
  10987. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10988. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10989. }
  10990. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10991. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10992. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10993. otherCostSelfTotal = otherCostTotal
  10994. }
  10995. } else {
  10996. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10997. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10998. otherCostSelfTotal = otherCostTotal
  10999. }
  11000. }
  11001. }
  11002. } else {
  11003. for _, item := range orderInfos {
  11004. if item.MedChrgitmType == "01" { //床位费
  11005. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11006. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11007. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11008. }
  11009. if item.MedChrgitmType == "02" { //诊察费
  11010. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11011. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11012. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11013. }
  11014. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11015. if item.MedChrgitmType == "03" { //检查费
  11016. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11017. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11018. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11019. }
  11020. } else {
  11021. if item.MedChrgitmType == "03" { //检查费
  11022. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11023. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11024. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11025. }
  11026. }
  11027. if item.MedChrgitmType == "04" { //化验费
  11028. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11029. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11030. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11031. }
  11032. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11033. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11034. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11035. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11036. }
  11037. if item.MedChrgitmType == "06" { //手术费
  11038. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11039. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11040. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11041. }
  11042. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11043. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11044. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11045. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11046. }
  11047. if item.MedChrgitmType == "07" { //护理
  11048. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11049. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11050. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11051. }
  11052. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11053. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11054. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11055. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11056. }
  11057. if item.MedChrgitmType == "11" { //中成费
  11058. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11059. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11060. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11061. }
  11062. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11063. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11064. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11065. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11066. }
  11067. }
  11068. }
  11069. timeLayout := "2006-01-02"
  11070. loc, _ := time.LoadLocation("Local")
  11071. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11072. if err != nil {
  11073. }
  11074. startRecordDateTime := startTime.Unix()
  11075. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11076. if err != nil {
  11077. }
  11078. endRecordDateTime := endTime.Unix()
  11079. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11080. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11081. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11082. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11083. c.ServeSuccessJSON(map[string]interface{}{
  11084. "charge_admin_name": charge_admin.UserName,
  11085. "order_number": order.Number, //业务流水号
  11086. "id_card_no": his.IdCardNo, //社会保障号
  11087. "patient": patient,
  11088. "department_name": department.Name, //科室
  11089. "number": his.Number, //门诊号
  11090. "date": order.SettleAccountsDate, //结算日期
  11091. "name": order.PsnName, //姓名
  11092. "gender": patient.Gender, //性别
  11093. "psn_cash_money": order.PsnCashPay, //个人支付
  11094. "pay_way": "门诊", //结算方式
  11095. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11096. "admin_user_name": admin.UserName, //收款员
  11097. "order": order,
  11098. "order_info": orderInfos_two,
  11099. "his": his,
  11100. "bedCostTotal": bedCostTotal,
  11101. "bedCostSelfTotal": bedCostSelfTotal,
  11102. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11103. "operationCostTotal": operationCostTotal,
  11104. "operationCostSelfTotal": operationCostSelfTotal,
  11105. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11106. "otherCostTotal": otherCostTotal,
  11107. "otherCostSelfTotal": otherCostSelfTotal,
  11108. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11109. "materialCostTotal": materialCostTotal,
  11110. "materialCostSelfTotal": materialCostSelfTotal,
  11111. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11112. "westernMedicineCostTotal": westernMedicineCostTotal,
  11113. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11114. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11115. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11116. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11117. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11118. "checkCostTotal": checkCostTotal,
  11119. "checkCostSelfTotal": checkCostSelfTotal,
  11120. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11121. "laboratoryCostTotal": laboratoryCostTotal,
  11122. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11123. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11124. "treatCostTotal": treatCostTotal,
  11125. "treatCostSelfTotal": treatCostSelfTotal,
  11126. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11127. "zhenChaCostTotal": zhenChaCostTotal,
  11128. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11129. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11130. "his_hospital_record": his_hospital_record,
  11131. "pre_pay_money": pre_pay_money,
  11132. "refund_sum": sum,
  11133. "doctor_info": doctor_info,
  11134. "hiliCostTotal": hiliCostTotal,
  11135. "hiliCostSelfTotal": hiliCostSelfTotal,
  11136. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11137. })
  11138. }
  11139. //func (c *HisApiController) GetFaPiaoDatas() {
  11140. // order_ids := c.GetString("order_ids")
  11141. // patient_id, _ := c.GetInt64("patient_id")
  11142. // adminUser := c.GetAdminUserInfo()
  11143. //
  11144. // orders := strings.Split(order_ids, ",")
  11145. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11146. //
  11147. // for _, item := range orders {
  11148. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11149. // order, _ := service.GetHisOrderByID(order_id)
  11150. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11151. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11152. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11153. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11154. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11155. //
  11156. // }
  11157. //
  11158. // var bedCostTotal float64 = 0 //床位总费
  11159. // var bedCostSelfTotal float64 = 0 //床位自费
  11160. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11161. //
  11162. // var operationCostTotal float64 = 0 //手术费
  11163. // var operationCostSelfTotal float64 = 0 //手术费
  11164. // var operationCostPartSelfTotal float64 = 0 //手术费
  11165. //
  11166. // var otherCostTotal float64 = 0 //其他费用
  11167. // var otherCostSelfTotal float64 = 0 //其他费用
  11168. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11169. //
  11170. // var materialCostTotal float64 = 0 //材料费
  11171. // var materialCostSelfTotal float64 = 0 //材料费
  11172. // var materialCostPartSelfTotal float64 = 0 //材料费
  11173. //
  11174. // var westernMedicineCostTotal float64 = 0 //西药费
  11175. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11176. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11177. //
  11178. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11179. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11180. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11181. //
  11182. // var checkCostTotal float64 = 0 //检查费
  11183. // var checkCostSelfTotal float64 = 0 //检查费
  11184. // var checkCostPartSelfTotal float64 = 0 //检查费
  11185. //
  11186. // var laboratoryCostTotal float64 = 0 //化验费
  11187. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11188. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11189. //
  11190. // var treatCostTotal float64 = 0 //治疗费用
  11191. // var treatCostSelfTotal float64 = 0 //治疗费用
  11192. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11193. //
  11194. // var zhenChaCostTotal float64 = 0 //其他费用
  11195. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11196. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11197. //
  11198. // decimal.DivisionPrecision = 2
  11199. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11200. //
  11201. // var balanceAccountsType int64
  11202. // if his.ID > 0 {
  11203. // balanceAccountsType = his.BalanceAccountsType
  11204. // } else {
  11205. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11206. // }
  11207. // if balanceAccountsType == 2 {
  11208. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11209. // for _, item := range orderInfos_two {
  11210. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11211. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11212. // item.MedChrgitmType = "09"
  11213. // }
  11214. //
  11215. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11216. // if item.HisPrescriptionProject.Type == 2 {
  11217. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11218. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11219. // case 0:
  11220. // item.MedChrgitmType = "0"
  11221. // break
  11222. // case 1:
  11223. // item.MedChrgitmType = "14"
  11224. // break
  11225. // case 2:
  11226. // item.MedChrgitmType = "05"
  11227. //
  11228. // break
  11229. // case 3:
  11230. // item.MedChrgitmType = "03"
  11231. //
  11232. // break
  11233. // case 4:
  11234. // item.MedChrgitmType = "03"
  11235. //
  11236. // break
  11237. // case 5:
  11238. // item.MedChrgitmType = "08"
  11239. //
  11240. // break
  11241. // case 6:
  11242. // item.MedChrgitmType = "14"
  11243. //
  11244. // break
  11245. // case 7:
  11246. // item.MedChrgitmType = "14"
  11247. //
  11248. // break
  11249. // case 8:
  11250. // item.MedChrgitmType = "03"
  11251. // break
  11252. // case 9:
  11253. // item.MedChrgitmType = "14"
  11254. // break
  11255. // case 10:
  11256. // item.MedChrgitmType = "14"
  11257. // break
  11258. // case 11:
  11259. // item.MedChrgitmType = "06"
  11260. // break
  11261. // case 12:
  11262. // item.MedChrgitmType = "12"
  11263. // break
  11264. // case 13:
  11265. // item.MedChrgitmType = "01"
  11266. // break
  11267. // case 14:
  11268. // item.MedChrgitmType = "04"
  11269. // break
  11270. // case 15:
  11271. // item.MedChrgitmType = "02"
  11272. // break
  11273. //
  11274. // }
  11275. //
  11276. // } else {
  11277. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11278. //
  11279. // case 1:
  11280. // item.MedChrgitmType = "14"
  11281. // break
  11282. // case 2:
  11283. // item.MedChrgitmType = "05"
  11284. //
  11285. // break
  11286. // case 3:
  11287. // item.MedChrgitmType = "03"
  11288. //
  11289. // break
  11290. // case 4:
  11291. // item.MedChrgitmType = "03"
  11292. //
  11293. // break
  11294. // case 5:
  11295. // item.MedChrgitmType = "08"
  11296. //
  11297. // break
  11298. // case 6:
  11299. // item.MedChrgitmType = "14"
  11300. //
  11301. // break
  11302. // case 7:
  11303. // item.MedChrgitmType = "14"
  11304. //
  11305. // break
  11306. // case 8:
  11307. // item.MedChrgitmType = "03"
  11308. // break
  11309. // case 9:
  11310. // item.MedChrgitmType = "14"
  11311. // break
  11312. //
  11313. // }
  11314. //
  11315. // }
  11316. //
  11317. // } else if item.HisPrescriptionProject.Type == 3 {
  11318. // item.MedChrgitmType = "08"
  11319. // }
  11320. // }
  11321. // }
  11322. //
  11323. // for _, item := range orderInfos_two {
  11324. // fmt.Println(item.MedChrgitmType)
  11325. // if item.MedChrgitmType == "01" { //床位费
  11326. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11327. // bedCostSelfTotal = bedCostTotal
  11328. // }
  11329. //
  11330. // if item.MedChrgitmType == "02" { //诊察费
  11331. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11332. // zhenChaCostSelfTotal = zhenChaCostTotal
  11333. // }
  11334. //
  11335. // if item.MedChrgitmType == "03" { //检查费
  11336. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11337. // checkCostSelfTotal = checkCostTotal
  11338. // }
  11339. //
  11340. // if item.MedChrgitmType == "04" { //化验费
  11341. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11342. // laboratoryCostSelfTotal = laboratoryCostTotal
  11343. // }
  11344. //
  11345. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11346. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11347. // treatCostSelfTotal = treatCostTotal
  11348. // }
  11349. //
  11350. // if item.MedChrgitmType == "06" { //手术费
  11351. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11352. // operationCostSelfTotal = treatCostTotal
  11353. // }
  11354. //
  11355. // if item.MedChrgitmType == "08" { //材料费
  11356. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11357. // materialCostSelfTotal = materialCostTotal
  11358. // }
  11359. //
  11360. // if item.MedChrgitmType == "09" { //西药费
  11361. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11362. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11363. // }
  11364. //
  11365. // if item.MedChrgitmType == "11" { //中成费
  11366. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11367. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11368. // }
  11369. //
  11370. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11371. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11372. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11373. // otherCostSelfTotal = otherCostTotal
  11374. // }
  11375. // } else {
  11376. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11377. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11378. // otherCostSelfTotal = otherCostTotal
  11379. // }
  11380. //
  11381. // }
  11382. //
  11383. // }
  11384. //
  11385. // } else {
  11386. // for _, item := range orderInfos {
  11387. // if item.MedChrgitmType == "01" { //床位费
  11388. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11389. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11390. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11391. // }
  11392. //
  11393. // if item.MedChrgitmType == "02" { //诊察费
  11394. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11395. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11396. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11397. // }
  11398. //
  11399. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11400. // if item.MedChrgitmType == "03" { //检查费
  11401. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11402. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11403. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11404. //
  11405. // }
  11406. // } else {
  11407. // if item.MedChrgitmType == "03" { //检查费
  11408. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11409. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11410. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11411. // }
  11412. //
  11413. // }
  11414. //
  11415. // if item.MedChrgitmType == "04" { //化验费
  11416. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11417. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11418. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11419. //
  11420. // }
  11421. //
  11422. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11423. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11424. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11425. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11426. //
  11427. // }
  11428. //
  11429. // if item.MedChrgitmType == "06" { //手术费
  11430. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11431. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11432. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11433. // }
  11434. //
  11435. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11436. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11437. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11438. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11439. // }
  11440. //
  11441. // if item.MedChrgitmType == "09" { //西药费
  11442. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11443. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11444. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11445. // }
  11446. //
  11447. // if item.MedChrgitmType == "11" { //中成费
  11448. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11449. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11450. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11451. // }
  11452. //
  11453. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11454. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11455. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11456. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11457. // }
  11458. //
  11459. // }
  11460. // }
  11461. // timeLayout := "2006-01-02"
  11462. // loc, _ := time.LoadLocation("Local")
  11463. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11464. // if err != nil {
  11465. // }
  11466. // startRecordDateTime := startTime.Unix()
  11467. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11468. // if err != nil {
  11469. // }
  11470. // endRecordDateTime := endTime.Unix()
  11471. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11472. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11473. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11474. //
  11475. // c.ServeSuccessJSON(map[string]interface{}{
  11476. // "order_number": order.Number, //业务流水号
  11477. // "id_card_no": his.IdCardNo, //社会保障号
  11478. // "department_name": department.Name, //科室
  11479. // "number": his.Number, //门诊号
  11480. // "date": order.SettleAccountsDate, //结算日期
  11481. // "name": order.PsnName, //姓名
  11482. // "gender": patient.Gender, //性别
  11483. // "psn_cash_money": order.PsnCashPay, //个人支付
  11484. // "pay_way": "门诊", //结算方式
  11485. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11486. // "admin_user_name": admin.UserName, //收款员
  11487. // "order": order,
  11488. // "order_info": orderInfos_two,
  11489. // "his": his,
  11490. // "bedCostTotal": bedCostTotal,
  11491. // "bedCostSelfTotal": bedCostSelfTotal,
  11492. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11493. // "operationCostTotal": operationCostTotal,
  11494. // "operationCostSelfTotal": operationCostSelfTotal,
  11495. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11496. // "otherCostTotal": otherCostTotal,
  11497. // "otherCostSelfTotal": otherCostSelfTotal,
  11498. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11499. // "materialCostTotal": materialCostTotal,
  11500. // "materialCostSelfTotal": materialCostSelfTotal,
  11501. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11502. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11503. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11504. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11505. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11506. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11507. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11508. // "checkCostTotal": checkCostTotal,
  11509. // "checkCostSelfTotal": checkCostSelfTotal,
  11510. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11511. // "laboratoryCostTotal": laboratoryCostTotal,
  11512. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11513. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11514. // "treatCostTotal": treatCostTotal,
  11515. // "treatCostSelfTotal": treatCostSelfTotal,
  11516. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11517. // "zhenChaCostTotal": zhenChaCostTotal,
  11518. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11519. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11520. // "his_hospital_record": his_hospital_record,
  11521. // "pre_pay_money": pre_pay_money,
  11522. // "refund_sum": sum,
  11523. // })
  11524. //
  11525. //}
  11526. func (this *HisApiController) GetIncomeStatisticsData() {
  11527. start_time := this.GetString("start_time")
  11528. end_time := this.GetString("end_time")
  11529. key_words := this.GetString("key_words")
  11530. limit, _ := this.GetInt64("limit")
  11531. page, _ := this.GetInt64("page")
  11532. if page <= 0 {
  11533. page = 1
  11534. }
  11535. if limit <= 0 {
  11536. limit = 10
  11537. }
  11538. statistics_type, _ := this.GetInt64("statistics_type")
  11539. admin := this.GetAdminUserInfo()
  11540. timeLayout := "2006-01-02"
  11541. loc, _ := time.LoadLocation("Local")
  11542. var theStartTIme int64
  11543. if len(start_time) > 0 {
  11544. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11545. if err != nil {
  11546. theStartTIme = 0
  11547. }
  11548. theStartTIme = theTime.Unix()
  11549. }
  11550. var theEndtTIme int64
  11551. if len(end_time) > 0 {
  11552. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11553. if err != nil {
  11554. theEndtTIme = 0
  11555. }
  11556. theEndtTIme = theTime.Unix()
  11557. }
  11558. if statistics_type == 1 {
  11559. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11560. this.ServeSuccessJSON(map[string]interface{}{
  11561. "list": list,
  11562. "total": total,
  11563. })
  11564. } else {
  11565. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11566. this.ServeSuccessJSON(map[string]interface{}{
  11567. "list": list,
  11568. "total": total,
  11569. })
  11570. }
  11571. }
  11572. func (c *HisApiController) PostProjectInformation() {
  11573. adminUser := c.GetAdminUserInfo()
  11574. orgId := adminUser.CurrentOrgId
  11575. dataBody := make(map[string]interface{}, 0)
  11576. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11577. if err != nil {
  11578. utils.ErrorLog(err.Error())
  11579. return
  11580. }
  11581. utils.ErrorLog("%v", dataBody)
  11582. var projectList []*models.HisProject
  11583. var total_goods []interface{}
  11584. tempProjects := dataBody["projects"].([]interface{})
  11585. total_goods = tempProjects
  11586. for index, projectMap := range tempProjects {
  11587. projectM := projectMap.(map[string]interface{})
  11588. var project models.HisProject
  11589. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  11590. utils.ErrorLog("project_name")
  11591. return
  11592. }
  11593. project_name, _ := projectM["project_name"].(string)
  11594. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  11595. err_log := models.ExportErrLog{
  11596. LogType: 6,
  11597. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11598. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  11599. Status: 1,
  11600. CreateTime: time.Now().Unix(),
  11601. UpdateTime: time.Now().Unix(),
  11602. ExportTime: time.Now().Unix(),
  11603. }
  11604. service.CreateExportErrLog(&err_log)
  11605. continue
  11606. }
  11607. project.ProjectName = project_name
  11608. prices := projectM["price"].(string)
  11609. price, _ := strconv.ParseFloat(prices, 64)
  11610. if price <= 0 { //名字为空则生成一条导入错误日志
  11611. err_log := models.ExportErrLog{
  11612. LogType: 6,
  11613. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11614. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  11615. Status: 1,
  11616. CreateTime: time.Now().Unix(),
  11617. UpdateTime: time.Now().Unix(),
  11618. ExportTime: time.Now().Unix(),
  11619. }
  11620. service.CreateExportErrLog(&err_log)
  11621. continue
  11622. }
  11623. project.Price = price
  11624. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  11625. utils.ErrorLog("unit_id")
  11626. return
  11627. }
  11628. unit := projectM["unit"].(string)
  11629. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  11630. err_log := models.ExportErrLog{
  11631. LogType: 6,
  11632. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11633. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11634. Status: 1,
  11635. CreateTime: time.Now().Unix(),
  11636. UpdateTime: time.Now().Unix(),
  11637. ExportTime: time.Now().Unix(),
  11638. }
  11639. service.CreateExportErrLog(&err_log)
  11640. continue
  11641. }
  11642. project.Unit = unit
  11643. cost_classify := projectM["cost_classify"].(string)
  11644. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11645. err_log := models.ExportErrLog{
  11646. LogType: 6,
  11647. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11648. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11649. Status: 1,
  11650. CreateTime: time.Now().Unix(),
  11651. UpdateTime: time.Now().Unix(),
  11652. ExportTime: time.Now().Unix(),
  11653. }
  11654. service.CreateExportErrLog(&err_log)
  11655. continue
  11656. }
  11657. var costClassify = "费用类别"
  11658. var cost_classify_id int64
  11659. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11660. if len(cost_classify) != 0 {
  11661. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11662. if errcode == gorm.ErrRecordNotFound {
  11663. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11664. dataconfig := models.DictDataconfig{
  11665. ParentId: costClassifyConfig.ID,
  11666. Module: "system",
  11667. OrgId: orgId,
  11668. Name: cost_classify,
  11669. FieldName: "",
  11670. Value: costConfig.Value + 1,
  11671. CreatedTime: "",
  11672. UpdatedTime: "",
  11673. CreateUserId: adminUser.AdminUser.Id,
  11674. Status: 1,
  11675. Remark: "",
  11676. DeleteIdSystem: 0,
  11677. Title: "",
  11678. Content: "",
  11679. Order: 0,
  11680. Code: "",
  11681. }
  11682. service.CreatedDicConfig(&dataconfig)
  11683. }
  11684. }
  11685. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11686. for _, it := range costClassList {
  11687. if cost_classify == it.Name {
  11688. cost_classify_id = int64(it.Value)
  11689. }
  11690. }
  11691. project.CostClassify = cost_classify_id
  11692. executive_section := projectM["executive_section"].(string)
  11693. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11694. err_log := models.ExportErrLog{
  11695. LogType: 6,
  11696. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11697. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11698. Status: 1,
  11699. CreateTime: time.Now().Unix(),
  11700. UpdateTime: time.Now().Unix(),
  11701. ExportTime: time.Now().Unix(),
  11702. }
  11703. service.CreateExportErrLog(&err_log)
  11704. continue
  11705. }
  11706. if len(executive_section) != 0 {
  11707. //查找科室是否有内容
  11708. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11709. if errcodedepart == gorm.ErrRecordNotFound {
  11710. department := models.XtHisDepartment{
  11711. Name: executive_section,
  11712. Status: 1,
  11713. UserOrgId: adminUser.CurrentOrgId,
  11714. CreatedTime: time.Now().Unix(),
  11715. }
  11716. service.CreateDePartment(&department)
  11717. }
  11718. }
  11719. var executive_section_id int64
  11720. departMentList, _ := service.GetAllDepartMent(orgId)
  11721. for _, it := range departMentList {
  11722. if executive_section == it.Name {
  11723. executive_section_id = it.ID
  11724. }
  11725. }
  11726. project.ExecutiveSection = executive_section_id
  11727. medical_coverage := projectM["medical_coverage"].(string)
  11728. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11729. err_log := models.ExportErrLog{
  11730. LogType: 6,
  11731. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11732. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11733. Status: 1,
  11734. CreateTime: time.Now().Unix(),
  11735. UpdateTime: time.Now().Unix(),
  11736. ExportTime: time.Now().Unix(),
  11737. }
  11738. service.CreateExportErrLog(&err_log)
  11739. continue
  11740. }
  11741. var medicalCoverage = "医保等级"
  11742. var medical_coverage_id int64
  11743. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11744. if len(medical_coverage) != 0 {
  11745. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11746. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11747. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11748. dataconfig := models.DictDataconfig{
  11749. ParentId: medicalCoverageConfig.ID,
  11750. Module: "system",
  11751. OrgId: orgId,
  11752. Name: medical_coverage,
  11753. FieldName: "",
  11754. Value: medicalCoverageConfig.Value + 1,
  11755. CreatedTime: "",
  11756. UpdatedTime: "",
  11757. CreateUserId: adminUser.AdminUser.Id,
  11758. Status: 1,
  11759. Remark: "",
  11760. DeleteIdSystem: 0,
  11761. Title: "",
  11762. Content: "",
  11763. Order: 0,
  11764. Code: "",
  11765. }
  11766. service.CreatedDicConfig(&dataconfig)
  11767. }
  11768. }
  11769. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11770. for _, it := range medicalCoverageList {
  11771. if medical_coverage == it.Name {
  11772. medical_coverage_id = int64(it.Value)
  11773. }
  11774. }
  11775. project.MedicalCoverage = medical_coverage_id
  11776. pinyin := projectM["pinyin"].(string)
  11777. project.Pinyin = pinyin
  11778. wubi := projectM["wubi"].(string)
  11779. project.Wubi = wubi
  11780. statistical_classification := projectM["statistical_classification"].(string)
  11781. var statisticalClassification = "统计分类"
  11782. var statistical_classification_id int64
  11783. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11784. if len(statistical_classification) != 0 {
  11785. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11786. if classificationerrcodes == gorm.ErrRecordNotFound {
  11787. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11788. dataconfig := models.DictDataconfig{
  11789. ParentId: classiFication.ID,
  11790. Module: "system",
  11791. OrgId: orgId,
  11792. Name: statistical_classification,
  11793. FieldName: "",
  11794. Value: classiFicationConfig.Value + 1,
  11795. CreatedTime: "",
  11796. UpdatedTime: "",
  11797. CreateUserId: adminUser.AdminUser.Id,
  11798. Status: 1,
  11799. Remark: "",
  11800. DeleteIdSystem: 0,
  11801. Title: "",
  11802. Content: "",
  11803. Order: 0,
  11804. Code: "",
  11805. }
  11806. service.CreatedDicConfig(&dataconfig)
  11807. }
  11808. }
  11809. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11810. for _, it := range classiFicationList {
  11811. if statistical_classification == it.Name {
  11812. statistical_classification_id = int64(it.Value)
  11813. }
  11814. }
  11815. project.StatisticalClassification = statistical_classification_id
  11816. disease_directory := int64(projectM["disease_directory"].(float64))
  11817. project.DiseaseDirectory = disease_directory
  11818. is_record := int64(projectM["is_record"].(float64))
  11819. project.IsRecord = is_record
  11820. medical_code := projectM["medical_code"].(string)
  11821. project.MedicalCode = medical_code
  11822. tube_color := projectM["tube_color"].(string)
  11823. var tubeColor = "试管颜色"
  11824. var tube_color_id int64
  11825. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11826. if len(tube_color) != 0 {
  11827. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11828. if errcodetube == gorm.ErrRecordNotFound {
  11829. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11830. dataconfig := models.DictDataconfig{
  11831. ParentId: tubeColorConfig.ID,
  11832. Module: "system",
  11833. OrgId: orgId,
  11834. Name: tube_color,
  11835. FieldName: "",
  11836. Value: tubeConfig.Value + 1,
  11837. CreatedTime: "",
  11838. UpdatedTime: "",
  11839. CreateUserId: adminUser.AdminUser.Id,
  11840. Status: 1,
  11841. Remark: "",
  11842. DeleteIdSystem: 0,
  11843. Title: "",
  11844. Content: "",
  11845. Order: 0,
  11846. Code: "",
  11847. }
  11848. service.CreatedDicConfig(&dataconfig)
  11849. }
  11850. }
  11851. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11852. for _, it := range tubeColorList {
  11853. if tube_color == it.Name {
  11854. tube_color_id = int64(it.Value)
  11855. }
  11856. }
  11857. project.TubeColor = tube_color_id
  11858. single_dose := projectM["single_dose"].(string)
  11859. project.SingleDose = single_dose
  11860. execution_frequency := projectM["execution_frequency"].(string)
  11861. project.ExecutionFrequency = execution_frequency
  11862. delivery_way := projectM["delivery_way"].(string)
  11863. project.DeliveryWay = delivery_way
  11864. number_days := projectM["number_days"].(string)
  11865. project.NumberDays = number_days
  11866. total := projectM["total"].(string)
  11867. project.Total = total
  11868. medical_status := int64(projectM["medical_status"].(float64))
  11869. project.MedicalStatus = medical_status
  11870. category := int64(projectM["category"].(float64))
  11871. project.Category = category
  11872. specail_project := int64(projectM["specail_project"].(float64))
  11873. project.SpecailProject = specail_project
  11874. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11875. project.SocialSecurityDirectoryCode = social_security_directory_code
  11876. remark := projectM["remark"].(string)
  11877. project.Remark = remark
  11878. record_date := projectM["record_date"].(string)
  11879. timeLayout := "2006-01-02"
  11880. loc, _ := time.LoadLocation("Local")
  11881. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11882. project.RecordDate = theTime.Unix()
  11883. projectList = append(projectList, &project)
  11884. }
  11885. export_time := time.Now().Unix()
  11886. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11887. if len(projectList) > 0 {
  11888. for _, item := range projectList {
  11889. hans := item.ProjectName // 要转换的汉字字符串
  11890. // 创建一个拼音转换器
  11891. p := pinyin.NewArgs()
  11892. // 将汉字转为拼音
  11893. pinyinSlice := pinyin.Pinyin(hans, p)
  11894. // 输出拼音
  11895. fmt.Println("Pinyin:", pinyinSlice)
  11896. // 获取首字母
  11897. firstLetter := ""
  11898. for _, py := range pinyinSlice {
  11899. if len(py) > 0 {
  11900. firstLetter += string(py[0][0])
  11901. }
  11902. }
  11903. item.FirstLetter = firstLetter
  11904. project := models.HisProject{
  11905. ProjectName: item.ProjectName,
  11906. Price: item.Price,
  11907. Unit: item.Unit,
  11908. CostClassify: item.CostClassify,
  11909. ExecutiveSection: item.ExecutiveSection,
  11910. MedicalCoverage: item.MedicalCoverage,
  11911. UserOrgId: orgId,
  11912. Status: 1,
  11913. CreatedTime: time.Now().Unix(),
  11914. Pinyin: item.Pinyin,
  11915. Wubi: item.Wubi,
  11916. StatisticalClassification: item.StatisticalClassification,
  11917. DiseaseDirectory: item.DiseaseDirectory,
  11918. IsRecord: item.IsRecord,
  11919. MedicalCode: item.MedicalCode,
  11920. TubeColor: item.TubeColor,
  11921. SingleDose: item.SingleDose,
  11922. DeliveryWay: item.DeliveryWay,
  11923. NumberDays: item.NumberDays,
  11924. Total: item.Total,
  11925. Category: item.Category,
  11926. MedicalStatus: item.MedicalStatus,
  11927. SpecailProject: item.SpecailProject,
  11928. RecordDate: item.RecordDate,
  11929. Remark: item.Remark,
  11930. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11931. ExecutionFrequency: item.ExecutionFrequency,
  11932. FirstLetter: item.FirstLetter,
  11933. }
  11934. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11935. if errcodeproject == gorm.ErrRecordNotFound {
  11936. service.CreateProjectInfomation(&project)
  11937. } else if errcodeproject == nil {
  11938. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11939. }
  11940. log := models.ExportLog{
  11941. LogType: 6,
  11942. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11943. TotalNum: int64(len(total_goods)),
  11944. FailNum: int64(len(errLogs)),
  11945. SuccessNum: int64(len(projectList)),
  11946. CreateTime: time.Now().Unix(),
  11947. UpdateTime: time.Now().Unix(),
  11948. ExportTime: export_time,
  11949. Status: 1,
  11950. }
  11951. service.CreateExportLog(&log)
  11952. c.ServeSuccessJSON(map[string]interface{}{
  11953. "msg": "导入成功",
  11954. "total_num": len(total_goods),
  11955. "success_num": len(projectList),
  11956. "fail_num": int64(len(errLogs)),
  11957. })
  11958. }
  11959. } else {
  11960. log := models.ExportLog{
  11961. LogType: 6,
  11962. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11963. TotalNum: int64(len(total_goods)),
  11964. FailNum: int64(len(errLogs)),
  11965. SuccessNum: int64(len(projectList)),
  11966. CreateTime: time.Now().Unix(),
  11967. UpdateTime: time.Now().Unix(),
  11968. ExportTime: export_time,
  11969. Status: 1,
  11970. }
  11971. service.CreateExportLog(&log)
  11972. c.ServeSuccessJSON(map[string]interface{}{
  11973. "msg": "导入成功",
  11974. "total_num": len(total_goods),
  11975. "success_num": len(projectList),
  11976. "fail_num": int64(len(errLogs)),
  11977. })
  11978. }
  11979. }
  11980. //func (this *HisApiController) EditProjectInformation(){
  11981. //
  11982. // id, _ := this.GetInt64("id")
  11983. // project_team := this.GetString("project_team")
  11984. // price := this.GetString("price")
  11985. // price_float, _ := strconv.ParseFloat(price, 64)
  11986. // pinyin := this.GetString("pinyin")
  11987. // wubi := this.GetString("wubi")
  11988. // tube_color, _ := this.GetInt64("tube_color")
  11989. // team_type, _ := this.GetInt64("team_type")
  11990. // remark := this.GetString("remark")
  11991. // ids := this.GetString("ids")
  11992. // item_id := this.GetString("item_id")
  11993. // projectTeam := models.XtHisProjectTeam{
  11994. // ProjectTeam: project_team,
  11995. // Price: price_float,
  11996. // Pinyin: pinyin,
  11997. // Wubi: wubi,
  11998. // TubeColor: tube_color,
  11999. // TeamType: team_type,
  12000. // Remark: remark,
  12001. // ProjectId: ids,
  12002. // ItemId: item_id,
  12003. // }
  12004. //
  12005. //
  12006. // dataBody := make(map[string]interface{}, 0)
  12007. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12008. // if err != nil {
  12009. // utils.ErrorLog(err.Error())
  12010. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12011. // return
  12012. // }
  12013. //
  12014. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12015. //
  12016. //
  12017. // if err != nil {
  12018. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12019. // return
  12020. // }
  12021. //
  12022. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12023. // infos, _ := dataBody["info"].([]interface{})
  12024. // if len(infos) > 0 {
  12025. // var ids []string
  12026. //
  12027. // for _, item := range infos {
  12028. // items := item.(map[string]interface{})
  12029. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12030. // utils.ErrorLog("id")
  12031. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12032. // return
  12033. // }
  12034. // id := int64(items["id"].(float64))
  12035. //
  12036. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12037. // utils.ErrorLog("type")
  12038. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12039. // return
  12040. // }
  12041. // types := int64(items["type"].(float64))
  12042. //
  12043. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12044. // utils.ErrorLog("number")
  12045. // }
  12046. //
  12047. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12048. //
  12049. // projectList := models.XtHisProjectList{
  12050. // Number: number,
  12051. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12052. // ProjectId: id,
  12053. // Status: 1,
  12054. // CreatedTime: time.Now().Unix(),
  12055. // UpdatedTime: time.Now().Unix(),
  12056. // TeamId: projectTeam.ID,
  12057. // Type: types,
  12058. // }
  12059. // list := projectList
  12060. //
  12061. // service.CreateProjectList(&list)
  12062. //
  12063. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12064. //
  12065. // }
  12066. // ids_str := strings.Join(ids, ",")
  12067. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12068. // service.SaveProjectTeam(&projectTeam)
  12069. // this.ServeSuccessJSON(map[string]interface{}{
  12070. // "projectTeam": projectTeam,
  12071. // })
  12072. // }
  12073. // }
  12074. //}
  12075. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12076. name := c.GetString("name")
  12077. mode_id, _ := c.GetInt64("mode", 0)
  12078. types, _ := c.GetInt64("type", 0)
  12079. patient_id, _ := c.GetInt64("patient_id", 0)
  12080. types = 1
  12081. adminInfo := c.GetAdminUserInfo()
  12082. template := &models.HisPrescriptionTemplate{
  12083. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12084. PatientId: patient_id,
  12085. Type: types,
  12086. Status: 1,
  12087. Ctime: time.Now().Unix(),
  12088. Mtime: time.Now().Unix(),
  12089. Name: name,
  12090. Mode: mode_id,
  12091. }
  12092. dataBody := make(map[string]interface{}, 0)
  12093. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12094. if err != nil {
  12095. utils.ErrorLog(err.Error())
  12096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12097. return
  12098. }
  12099. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12100. //如果已经存在记录则删除处方
  12101. if template_one.ID > 0 {
  12102. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12103. var ids []int64
  12104. var org_id int64
  12105. for _, item := range ps {
  12106. org_id = c.GetAdminUserInfo().CurrentOrgId
  12107. ids = append(ids, item.ID)
  12108. }
  12109. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12110. if err2 == nil {
  12111. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12112. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12113. if len(prescriptions) > 0 {
  12114. for _, item := range prescriptions {
  12115. items := item.(map[string]interface{})
  12116. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12117. utils.ErrorLog("type")
  12118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12119. return
  12120. }
  12121. types := int64(items["type"].(float64))
  12122. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12123. utils.ErrorLog("med_type")
  12124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12125. return
  12126. }
  12127. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12128. ctime := time.Now().Unix()
  12129. prescription := &models.HisPrescriptionInfoTemplate{
  12130. PatientId: patient_id,
  12131. UserOrgId: adminInfo.CurrentOrgId,
  12132. Ctime: ctime,
  12133. Mtime: ctime,
  12134. Type: types,
  12135. Modifier: adminInfo.AdminUser.Id,
  12136. Creator: adminInfo.AdminUser.Id,
  12137. Status: 1,
  12138. PTemplateId: template_one.ID,
  12139. MedType: med_type,
  12140. }
  12141. service.CreateHisPrescriptionInfoTemplate(prescription)
  12142. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12143. advices := items["advices"].([]interface{})
  12144. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12145. ctime := time.Now().Unix()
  12146. mtime := ctime
  12147. if len(advices) > 0 {
  12148. for _, advice := range advices {
  12149. var s models.HisPrescriptionAdviceTemplate
  12150. s.PrescriptionId = prescription.ID
  12151. s.AdviceType = 2
  12152. s.StopState = 2
  12153. s.ExecutionState = 2
  12154. s.Status = 1
  12155. s.UserOrgId = adminInfo.CurrentOrgId
  12156. s.CreatedTime = ctime
  12157. s.UpdatedTime = mtime
  12158. s.PatientId = patient_id
  12159. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12160. if errcode > 0 {
  12161. c.ServeFailJSONWithSGJErrorCode(errcode)
  12162. return
  12163. }
  12164. service.CreateHisPrescriptionAdviceTemplate(&s)
  12165. }
  12166. }
  12167. }
  12168. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12169. projects := items["project"].([]interface{})
  12170. if len(projects) > 0 {
  12171. for _, project := range projects {
  12172. var p models.HisPrescriptionProjectTemplate
  12173. p.PrescriptionId = prescription.ID
  12174. p.Ctime = time.Now().Unix()
  12175. p.Mtime = time.Now().Unix()
  12176. p.PatientId = patient_id
  12177. p.UserOrgId = adminInfo.CurrentOrgId
  12178. p.Status = 1
  12179. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12180. if errcode > 0 {
  12181. c.ServeFailJSONWithSGJErrorCode(errcode)
  12182. return
  12183. }
  12184. service.CreateHisPrescriptionProjectTemplate(&p)
  12185. }
  12186. }
  12187. }
  12188. }
  12189. c.ServeSuccessJSON(map[string]interface{}{
  12190. "msg": "创建成功",
  12191. })
  12192. }
  12193. }
  12194. } else {
  12195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12196. return
  12197. }
  12198. } else {
  12199. err3 := service.CreateHisPrescriptionTemplate(template)
  12200. if err3 == nil {
  12201. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12202. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12203. if len(prescriptions) > 0 {
  12204. for _, item := range prescriptions {
  12205. items := item.(map[string]interface{})
  12206. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12207. utils.ErrorLog("type")
  12208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12209. return
  12210. }
  12211. types := int64(items["type"].(float64))
  12212. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12213. utils.ErrorLog("med_type")
  12214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12215. return
  12216. }
  12217. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12218. ctime := time.Now().Unix()
  12219. prescription := &models.HisPrescriptionInfoTemplate{
  12220. PatientId: patient_id,
  12221. UserOrgId: adminInfo.CurrentOrgId,
  12222. Ctime: ctime,
  12223. Mtime: ctime,
  12224. Type: types,
  12225. Modifier: adminInfo.AdminUser.Id,
  12226. Creator: adminInfo.AdminUser.Id,
  12227. Status: 1,
  12228. PTemplateId: template.ID,
  12229. MedType: med_type,
  12230. }
  12231. service.CreateHisPrescriptionInfoTemplate(prescription)
  12232. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12233. advices := items["advices"].([]interface{})
  12234. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12235. ctime := time.Now().Unix()
  12236. mtime := ctime
  12237. if len(advices) > 0 {
  12238. for _, advice := range advices {
  12239. var s models.HisPrescriptionAdviceTemplate
  12240. s.PrescriptionId = prescription.ID
  12241. s.AdviceType = 2
  12242. s.StopState = 2
  12243. s.ExecutionState = 2
  12244. s.Status = 1
  12245. s.UserOrgId = adminInfo.CurrentOrgId
  12246. s.CreatedTime = ctime
  12247. s.UpdatedTime = mtime
  12248. s.PatientId = patient_id
  12249. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12250. if errcode > 0 {
  12251. c.ServeFailJSONWithSGJErrorCode(errcode)
  12252. return
  12253. }
  12254. service.CreateHisPrescriptionAdviceTemplate(&s)
  12255. }
  12256. }
  12257. }
  12258. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12259. projects := items["project"].([]interface{})
  12260. if len(projects) > 0 {
  12261. for _, project := range projects {
  12262. var p models.HisPrescriptionProjectTemplate
  12263. p.PrescriptionId = prescription.ID
  12264. p.Ctime = time.Now().Unix()
  12265. p.Mtime = time.Now().Unix()
  12266. p.PatientId = patient_id
  12267. p.UserOrgId = adminInfo.CurrentOrgId
  12268. p.Status = 1
  12269. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12270. if errcode > 0 {
  12271. c.ServeFailJSONWithSGJErrorCode(errcode)
  12272. return
  12273. }
  12274. service.CreateHisPrescriptionProjectTemplate(&p)
  12275. }
  12276. }
  12277. }
  12278. }
  12279. c.ServeSuccessJSON(map[string]interface{}{
  12280. "msg": "创建成功",
  12281. })
  12282. }
  12283. }
  12284. } else {
  12285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12286. return
  12287. }
  12288. }
  12289. }
  12290. func (c *HisApiController) PreSettle() {
  12291. id, _ := c.GetInt64("id")
  12292. record_time := c.GetString("record_time")
  12293. his_patient_id, _ := c.GetInt64("his_patient_id")
  12294. timeLayout := "2006-01-02"
  12295. loc, _ := time.LoadLocation("Local")
  12296. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12297. diagnosis_id := c.GetString("diagnosis")
  12298. sick_type, _ := c.GetInt64("sick_type")
  12299. reg_type, _ := c.GetInt64("p_type")
  12300. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12301. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12302. if err != nil {
  12303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12304. return
  12305. }
  12306. recordDateTime := theTime.Unix()
  12307. adminUser := c.GetAdminUserInfo()
  12308. var prescriptions []*models.HisPrescription
  12309. var start_time int64
  12310. var end_time int64
  12311. ids_str := c.GetString("ids")
  12312. ids_arr := strings.Split(ids_str, ",")
  12313. fmt.Println(reg_type)
  12314. if settle_accounts_type == 1 { //日结
  12315. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12316. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12317. } else {
  12318. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12319. }
  12320. fmt.Println(prescriptions)
  12321. } else { //月结
  12322. start_time_str := c.GetString("start_time")
  12323. end_time_str := c.GetString("end_time")
  12324. timeLayout := "2006-01-02"
  12325. loc, _ := time.LoadLocation("Local")
  12326. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12327. if err != nil {
  12328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12329. return
  12330. }
  12331. recordStartTime := theStartTime.Unix()
  12332. start_time = recordStartTime
  12333. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12334. if err != nil {
  12335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12336. return
  12337. }
  12338. recordEndTime := theEndTime.Unix()
  12339. end_time = recordEndTime
  12340. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12341. }
  12342. if reg_type == 1111 || reg_type == 1112 {
  12343. reg_type = 11
  12344. }
  12345. timestamp := time.Now().Unix()
  12346. tempTime := time.Unix(timestamp, 0)
  12347. timeFormat := tempTime.Format("20060102150405")
  12348. chrgBchno := rand.Intn(100000) + 10000
  12349. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12350. strconv.FormatInt(his.PatientId, 10)
  12351. var ids []int64
  12352. for _, item := range prescriptions {
  12353. ids = append(ids, item.ID)
  12354. }
  12355. fmt.Println(ids)
  12356. var total float64
  12357. for _, item := range prescriptions {
  12358. fmt.Println(item)
  12359. if item.Type == 1 { //药品
  12360. for _, subItem := range item.HisDoctorAdviceInfo {
  12361. total = total + (subItem.Price * subItem.PrescribingNumber)
  12362. }
  12363. }
  12364. if item.Type == 2 { //项目
  12365. for _, subItem := range item.HisPrescriptionProject {
  12366. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12367. total = total + (subItem.Price * cnt)
  12368. }
  12369. }
  12370. for _, subItem := range item.HisAdditionalCharge {
  12371. total = total + (subItem.Price * float64(subItem.Count))
  12372. }
  12373. }
  12374. allTotal := fmt.Sprintf("%.2f", total)
  12375. totals, _ := strconv.ParseFloat(allTotal, 64)
  12376. order := &models.HisOrder{
  12377. UserOrgId: adminUser.CurrentOrgId,
  12378. HisPatientId: his.ID,
  12379. PatientId: id,
  12380. SettleAccountsDate: recordDateTime,
  12381. Ctime: time.Now().Unix(),
  12382. Mtime: time.Now().Unix(),
  12383. Status: 1,
  12384. OrderStatus: 1,
  12385. MdtrtId: his.Number,
  12386. Number: chrg_bchno,
  12387. MedfeeSumamt: totals,
  12388. SettleEndTime: end_time,
  12389. SettleStartTime: start_time,
  12390. SettleType: settle_accounts_type,
  12391. PsnPartAmt: totals,
  12392. PsnCashPay: totals,
  12393. PType: 2,
  12394. IsPre: 1,
  12395. MedType: strconv.Itoa(int(reg_type)),
  12396. Diagnosis: diagnosis_id,
  12397. }
  12398. err = service.CreateOrder(order)
  12399. if err != nil {
  12400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12401. return
  12402. }
  12403. var customs []*Custom
  12404. for _, item := range prescriptions {
  12405. fmt.Println(item.Type)
  12406. if item.Type == 1 { //药品
  12407. for _, subItem := range item.HisDoctorAdviceInfo {
  12408. cus := &Custom{
  12409. AdviceId: subItem.ID,
  12410. ProjectId: 0,
  12411. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12412. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12413. FeedetlSn: subItem.FeedetlSn,
  12414. Price: fmt.Sprintf("%.2f", subItem.Price),
  12415. MedListCodg: subItem.MedListCodg,
  12416. Type: 1,
  12417. }
  12418. customs = append(customs, cus)
  12419. }
  12420. }
  12421. if item.Type == 2 { //项目
  12422. for _, subItem := range item.HisPrescriptionProject {
  12423. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12424. cus := &Custom{
  12425. AdviceId: 0,
  12426. ProjectId: subItem.ID,
  12427. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12428. Cut: fmt.Sprintf("%.2f", cnt),
  12429. FeedetlSn: subItem.FeedetlSn,
  12430. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12431. MedListCodg: subItem.MedListCodg,
  12432. Type: 2,
  12433. }
  12434. customs = append(customs, cus)
  12435. }
  12436. }
  12437. for _, item := range item.HisAdditionalCharge {
  12438. cus := &Custom{
  12439. ItemId: item.ID,
  12440. AdviceId: 0,
  12441. ProjectId: 0,
  12442. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12443. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12444. FeedetlSn: item.FeedetlSn,
  12445. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12446. MedListCodg: item.XtHisAddtionConfig.Code,
  12447. Type: 3,
  12448. }
  12449. customs = append(customs, cus)
  12450. }
  12451. }
  12452. fmt.Println(customs)
  12453. for _, item := range customs {
  12454. var advice_id int64 = 0
  12455. var project_id int64 = 0
  12456. var item_id int64 = 0
  12457. var types int64 = 0
  12458. if item.Type == 1 {
  12459. advice_id = item.AdviceId
  12460. project_id = 0
  12461. item_id = 0
  12462. } else if item.Type == 2 {
  12463. advice_id = 0
  12464. item_id = 0
  12465. project_id = item.ProjectId
  12466. } else if item.Type == 3 {
  12467. advice_id = 0
  12468. item_id = item.ItemId
  12469. project_id = 0
  12470. }
  12471. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12472. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12473. pric, _ := strconv.ParseFloat(item.Price, 32)
  12474. info := &models.HisOrderInfo{
  12475. OrderNumber: order.Number,
  12476. UploadDate: time.Now().Unix(),
  12477. AdviceId: advice_id,
  12478. DetItemFeeSumamt: detItemFeeSumamt,
  12479. Cnt: cut,
  12480. Pric: pric,
  12481. PatientId: id,
  12482. Status: 1,
  12483. Mtime: time.Now().Unix(),
  12484. Ctime: time.Now().Unix(),
  12485. UserOrgId: adminUser.CurrentOrgId,
  12486. HisPatientId: his.ID,
  12487. OrderId: order.ID,
  12488. ProjectId: project_id,
  12489. Type: types,
  12490. ItemId: item_id,
  12491. }
  12492. service.CreateOrderInfo(info)
  12493. }
  12494. his.SickType = sick_type
  12495. service.UpdataHisPateint(&his)
  12496. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12497. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12498. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12499. if err == nil {
  12500. c.ServeSuccessJSON(map[string]interface{}{
  12501. "msg": "结算成功",
  12502. })
  12503. }
  12504. }
  12505. type CustomOrderInfo struct {
  12506. Name string
  12507. Spec string
  12508. Unit string
  12509. Count float64
  12510. Price float64
  12511. Total float64
  12512. }
  12513. func (c *HisApiController) GetPrivateExpensesInfo() {
  12514. order_id, _ := c.GetInt64("id", 0)
  12515. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12516. order, _ := service.GetHisOrderByID(order_id)
  12517. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12518. if order.ID == 0 {
  12519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12520. return
  12521. }
  12522. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12523. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12524. org_id := c.GetAdminUserInfo().CurrentOrgId
  12525. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12526. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12527. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12528. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12529. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12530. //var orderInfos_four []*models.HisOrderInfoTwo
  12531. //for _, item := range orderInfos_three {
  12532. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  12533. // item.HisPrescriptionProject.IsCheckTeam = 1
  12534. // orderInfos_four = append(orderInfos_four, item)
  12535. //
  12536. // }
  12537. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  12538. // item.HisPrescriptionProject.IsCheckTeam = 2
  12539. // orderInfos_two = append(orderInfos_two, item)
  12540. // }
  12541. //}
  12542. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  12543. //var cus_slice []CustomOrderInfo
  12544. //for _, item := range new_order_info {
  12545. // var cus CustomOrderInfo
  12546. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  12547. // cus.Unit = ""
  12548. // cus.Spec = ""
  12549. // var total float64
  12550. // for _, subItem := range orderInfos_four {
  12551. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  12552. // total = total + subItem.DetItemFeeSumamt
  12553. // fmt.Println(subItem.DetItemFeeSumamt)
  12554. // }
  12555. // }
  12556. // cus.Count = 1
  12557. // cus.Total = total
  12558. // cus_slice = append(cus_slice, cus)
  12559. //}
  12560. orderInfos = append(orderInfos, orderInfos_two...)
  12561. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  12562. //orderInfos = append(orderInfos, orderInfos_three...)
  12563. //}/**/
  12564. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  12565. c.ServeSuccessJSON(map[string]interface{}{
  12566. "order": order,
  12567. "order_info": orderInfos,
  12568. "patient": patient,
  12569. "admin_info": adminInfo,
  12570. "his": his,
  12571. "current_admin": role,
  12572. "org_config": miConfig,
  12573. //"new_order_info": cus_slice,
  12574. })
  12575. }
  12576. func (this *HisApiController) ChangeMedType() {
  12577. med_type := this.GetString("med_type")
  12578. old_med_type := this.GetString("old_med_type")
  12579. ids := this.GetString("ids")
  12580. settle_type, _ := this.GetInt64("settle_type")
  12581. start_time := this.GetString("start_time")
  12582. end_time := this.GetString("end_time")
  12583. ids_arr := strings.Split(ids, ",")
  12584. if settle_type == 1 { //日结
  12585. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  12586. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  12587. prescription.MedType = med_type
  12588. err := service.SaveHisPrescriptionTwo(&prescription)
  12589. if err == nil {
  12590. this.ServeSuccessJSON(map[string]interface{}{
  12591. "msg": "修改成功",
  12592. })
  12593. } else {
  12594. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12595. return
  12596. }
  12597. } else if settle_type == 2 {
  12598. timeLayout := "2006-01-02"
  12599. loc, _ := time.LoadLocation("Local")
  12600. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12601. if err != nil {
  12602. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12603. return
  12604. }
  12605. recordStartTime := theStartTime.Unix()
  12606. start_time_timestamp := recordStartTime
  12607. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  12608. if err != nil {
  12609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12610. return
  12611. }
  12612. recordEndTime := theEndTime.Unix()
  12613. end_time_timestamp := recordEndTime
  12614. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  12615. if updateErr == nil {
  12616. this.ServeSuccessJSON(map[string]interface{}{
  12617. "msg": "修改成功",
  12618. })
  12619. } else {
  12620. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12621. return
  12622. }
  12623. }
  12624. }
  12625. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  12626. patient_id, _ := c.GetInt64("patient_id")
  12627. his_patient_id, _ := c.GetInt64("his_patient_id")
  12628. record_date := c.GetString("record_date")
  12629. start_time := c.GetString("start_time")
  12630. end_time := c.GetString("end_time")
  12631. order_status, _ := c.GetInt64("type", 0)
  12632. p_type, _ := c.GetInt64("p_type", 0)
  12633. order_id, _ := c.GetInt64("order_id", 0)
  12634. timeLayout := "2006-01-02"
  12635. loc, _ := time.LoadLocation("Local")
  12636. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12637. if err != nil {
  12638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12639. return
  12640. }
  12641. recordDateTime := theTime.Unix()
  12642. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12643. if err != nil {
  12644. }
  12645. startRecordDateTime := startTime.Unix()
  12646. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12647. if err != nil {
  12648. }
  12649. endRecordDateTime := endTime.Unix()
  12650. admin := c.GetAdminUserInfo()
  12651. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12652. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12653. order, _ := service.GetHisOrderByID(order_id)
  12654. var monthPrescriptions []*models.HisPrescription
  12655. if order_status == 1 || order_status == 0 {
  12656. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12657. } else if order_status == 2 {
  12658. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12659. }
  12660. var settle_total float64
  12661. for _, item := range monthPrescriptions {
  12662. if len(item.HisPrescriptionProject) > 0 {
  12663. for _, subItem := range item.HisPrescriptionProject {
  12664. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12665. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12666. settle_total = settle_total + total
  12667. }
  12668. }
  12669. if len(item.HisDoctorAdviceInfo) > 0 {
  12670. for _, subItem := range item.HisDoctorAdviceInfo {
  12671. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12672. settle_total = settle_total + total
  12673. }
  12674. }
  12675. }
  12676. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12677. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12678. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12679. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12680. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12681. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12682. //获取所有科室信息
  12683. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12684. var dia string
  12685. for _, item := range month_p_info {
  12686. if len(dia) == 0 {
  12687. dia = item.Diagnosis
  12688. } else {
  12689. dia = dia + "," + item.Diagnosis
  12690. }
  12691. }
  12692. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12693. dia_arr = removeEmptyStrings(dia_arr)
  12694. c.ServeSuccessJSON(map[string]interface{}{
  12695. "his_info": his_patient_info,
  12696. "xt_info": xt_patient_info,
  12697. "case_history": case_history,
  12698. "info": patientPrescriptionInfo,
  12699. "last_info": lastPatientPrescriptionInfo,
  12700. "month_prescriptions": monthPrescriptions,
  12701. "order": order,
  12702. "doctors": doctors,
  12703. "department": department,
  12704. "settle_total": settle_total,
  12705. "dia_arr": dia_arr,
  12706. })
  12707. return
  12708. }
  12709. func removeEmptyStrings(input []string) []string {
  12710. var output []string
  12711. for _, s := range input {
  12712. if s != "" {
  12713. output = append(output, s)
  12714. }
  12715. }
  12716. return output
  12717. }
  12718. func removeDuplicates(input []string) []string {
  12719. seen := make(map[string]bool)
  12720. output := []string{}
  12721. for _, s := range input {
  12722. if _, exists := seen[s]; !exists {
  12723. seen[s] = true
  12724. output = append(output, s)
  12725. }
  12726. }
  12727. return output
  12728. }
  12729. func (c *HisApiController) GetHisMonthPatientInfo() {
  12730. patient_id, _ := c.GetInt64("patient_id")
  12731. his_patient_id, _ := c.GetInt64("his_patient_id")
  12732. record_date := c.GetString("record_date")
  12733. number := c.GetString("number")
  12734. start_time := c.GetString("start_time")
  12735. end_time := c.GetString("end_time")
  12736. p_type, _ := c.GetInt64("p_type")
  12737. timeLayout := "2006-01-02"
  12738. loc, _ := time.LoadLocation("Local")
  12739. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12740. if err != nil {
  12741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12742. return
  12743. }
  12744. recordDateTime := theTime.Unix()
  12745. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12746. if err != nil {
  12747. }
  12748. startRecordDateTime := startTime.Unix()
  12749. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12750. if err != nil {
  12751. }
  12752. endRecordDateTime := endTime.Unix()
  12753. admin := c.GetAdminUserInfo()
  12754. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12755. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12756. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12757. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12758. var settle_total float64
  12759. for _, item := range monthPrescriptions {
  12760. if len(item.HisPrescriptionProject) > 0 {
  12761. for _, subItem := range item.HisPrescriptionProject {
  12762. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12763. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12764. settle_total = settle_total + total
  12765. }
  12766. }
  12767. if len(item.HisDoctorAdviceInfo) > 0 {
  12768. for _, subItem := range item.HisDoctorAdviceInfo {
  12769. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12770. settle_total = settle_total + total
  12771. }
  12772. }
  12773. }
  12774. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12775. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12776. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12777. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12778. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12779. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12780. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12781. //获取所有科室信息
  12782. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12783. c.ServeSuccessJSON(map[string]interface{}{
  12784. "his_info": his_patient_info,
  12785. "xt_info": xt_patient_info,
  12786. "case_history": case_history,
  12787. "info": patientPrescriptionInfo,
  12788. "month_prescriptions": monthPrescriptions,
  12789. "order": order,
  12790. "doctors": doctors,
  12791. "department": department,
  12792. "count": count,
  12793. "drugStockConfig": drugStockConfig,
  12794. "last_info": lastPatientPrescriptionInfo,
  12795. "settle_total": settle_total,
  12796. })
  12797. return
  12798. }
  12799. func (c *HisApiController) GetAllOrder() {
  12800. org_id := c.GetAdminUserInfo().CurrentOrgId
  12801. orders, _ := service.GetNewHisOrderList(org_id)
  12802. c.ServeSuccessJSON(map[string]interface{}{
  12803. "order": orders,
  12804. })
  12805. return
  12806. }
  12807. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12808. newArr = make([]*models.HisOrderInfoTwo, 0)
  12809. for i := 0; i < len(arr); i++ {
  12810. repeat := false
  12811. for j := i + 1; j < len(arr); j++ {
  12812. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12813. repeat = true
  12814. break
  12815. }
  12816. }
  12817. if !repeat {
  12818. newArr = append(newArr, arr[i])
  12819. }
  12820. }
  12821. return
  12822. }
  12823. // 修改处方退库操作 参数传修改之前的处方数据
  12824. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12825. if advice.ExecutionState == 1 {
  12826. //查询该病人该药品是否有库存记录
  12827. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12828. if errcode == gorm.ErrRecordNotFound {
  12829. } else {
  12830. //退库
  12831. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12832. if advice.PrescribingNumberUnit == drug.MinUnit {
  12833. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12834. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12835. //退库
  12836. warehouseInfo := models.DrugWarehouseInfo{
  12837. StockMinNumber: prescribingNumber,
  12838. }
  12839. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12840. operation_time := time.Now().Unix()
  12841. creater := advice.AdviceDoctor
  12842. ctime := time.Now().Unix()
  12843. timeStr := time.Now().Format("2006-01-02")
  12844. timeArr := strings.Split(timeStr, "-")
  12845. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12846. total = total + 1
  12847. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12848. cancelStock := models.DrugCancelStock{
  12849. OrderNumber: orderNumber,
  12850. OperaTime: operation_time,
  12851. OrgId: advice.UserOrgId,
  12852. Creater: creater,
  12853. Ctime: ctime,
  12854. Status: 1,
  12855. ReturnTime: advice.AdviceDate,
  12856. Dealer: info.Dealer,
  12857. Manufacturer: info.Manufacturer,
  12858. Type: 1,
  12859. }
  12860. service.AddSigleDrugCancelStock(&cancelStock)
  12861. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12862. dealer, _ := service.GetDealerById(info.Dealer)
  12863. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12864. cancelStockInfo := models.DrugCancelStockInfo{
  12865. OrderNumber: cancelInfo.OrderNumber,
  12866. CancelStockId: cancelInfo.ID,
  12867. DrugId: info.DrugId,
  12868. Count: info.Count,
  12869. Status: 1,
  12870. Ctime: ctime,
  12871. OrgId: advice.UserOrgId,
  12872. Type: 1,
  12873. Manufacturer: manufactureName.ManufacturerName,
  12874. Dealer: dealer.DealerName,
  12875. Total: 0,
  12876. RetailPrice: info.RetailPrice,
  12877. RetailTotalPrice: info.RetailTotalPrice,
  12878. Price: info.Price,
  12879. RegisterAccount: "",
  12880. Remark: info.Remark,
  12881. BatchNumber: info.BatchNumber,
  12882. MaxUnit: info.CountUnit,
  12883. ProductDate: info.ProductDate,
  12884. ExpiryDate: info.ExpiryDate,
  12885. BatchNumberId: info.WarehouseInfoId,
  12886. }
  12887. flow := models.DrugFlow{
  12888. WarehousingId: 0,
  12889. DrugId: info.DrugId,
  12890. Number: "",
  12891. BatchNumber: info.BatchNumber,
  12892. Count: info.Count,
  12893. UserOrgId: advice.UserOrgId,
  12894. PatientId: 0,
  12895. SystemTime: ctime,
  12896. ConsumableType: 4,
  12897. IsSys: 0,
  12898. WarehousingOrder: "",
  12899. WarehouseOutId: 0,
  12900. WarehouseOutOrderNumber: "",
  12901. IsEdit: 0,
  12902. CancelStockId: cancelStock.ID,
  12903. CancelOrderNumber: cancelStock.OrderNumber,
  12904. Manufacturer: info.Manufacturer,
  12905. Dealer: info.Dealer,
  12906. Creator: advice.UserOrgId,
  12907. UpdateCreator: 0,
  12908. Status: 1,
  12909. Ctime: time.Now().Unix(),
  12910. Mtime: 0,
  12911. Price: info.Price,
  12912. WarehousingDetailId: 0,
  12913. WarehouseOutDetailId: 0,
  12914. CancelOutDetailId: 0,
  12915. ExpireDate: info.ExpiryDate,
  12916. ProductDate: info.ProductDate,
  12917. MaxUnit: info.CountUnit,
  12918. MinUnit: "",
  12919. }
  12920. service.CreatedCancelStock(cancelStockInfo)
  12921. service.CreateDrugFlowOne(flow)
  12922. } else {
  12923. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12924. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12925. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12926. warehouseInfo := models.DrugWarehouseInfo{
  12927. StockMinNumber: prescribingNumber,
  12928. }
  12929. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12930. }
  12931. operation_time := time.Now().Unix()
  12932. creater := advice.AdviceDoctor
  12933. ctime := time.Now().Unix()
  12934. timeStr := time.Now().Format("2006-01-02")
  12935. timeArr := strings.Split(timeStr, "-")
  12936. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12937. total = total + 1
  12938. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12939. cancelStock := models.DrugCancelStock{
  12940. OrderNumber: orderNumber,
  12941. OperaTime: operation_time,
  12942. OrgId: advice.UserOrgId,
  12943. Creater: creater,
  12944. Ctime: ctime,
  12945. Status: 1,
  12946. ReturnTime: advice.AdviceDate,
  12947. Dealer: info.Dealer,
  12948. Manufacturer: info.Manufacturer,
  12949. Type: 1,
  12950. }
  12951. service.AddSigleDrugCancelStock(&cancelStock)
  12952. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12953. dealer, _ := service.GetDealerById(info.Dealer)
  12954. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12955. cancelStockInfo := models.DrugCancelStockInfo{
  12956. OrderNumber: cancelInfo.OrderNumber,
  12957. CancelStockId: cancelInfo.ID,
  12958. DrugId: info.DrugId,
  12959. Count: info.Count,
  12960. Status: 1,
  12961. Ctime: ctime,
  12962. OrgId: advice.UserOrgId,
  12963. Type: 1,
  12964. Manufacturer: manufactureName.ManufacturerName,
  12965. Dealer: dealer.DealerName,
  12966. Total: 0,
  12967. RetailPrice: info.RetailPrice,
  12968. RetailTotalPrice: info.RetailTotalPrice,
  12969. Price: info.Price,
  12970. RegisterAccount: "",
  12971. Remark: info.Remark,
  12972. BatchNumber: info.BatchNumber,
  12973. MaxUnit: info.CountUnit,
  12974. ProductDate: info.ProductDate,
  12975. ExpiryDate: info.ExpiryDate,
  12976. BatchNumberId: info.WarehouseInfoId,
  12977. }
  12978. flow := models.DrugFlow{
  12979. WarehousingId: 0,
  12980. DrugId: info.DrugId,
  12981. Number: "",
  12982. BatchNumber: info.BatchNumber,
  12983. Count: info.Count,
  12984. UserOrgId: advice.UserOrgId,
  12985. PatientId: 0,
  12986. SystemTime: ctime,
  12987. ConsumableType: 4,
  12988. IsSys: 0,
  12989. WarehousingOrder: "",
  12990. WarehouseOutId: 0,
  12991. WarehouseOutOrderNumber: "",
  12992. IsEdit: 0,
  12993. CancelStockId: cancelStock.ID,
  12994. CancelOrderNumber: cancelStock.OrderNumber,
  12995. Manufacturer: info.Manufacturer,
  12996. Dealer: info.Dealer,
  12997. Creator: advice.AdviceDoctor,
  12998. UpdateCreator: 0,
  12999. Status: 1,
  13000. Ctime: time.Now().Unix(),
  13001. Mtime: 0,
  13002. Price: info.Price,
  13003. WarehousingDetailId: 0,
  13004. WarehouseOutDetailId: 0,
  13005. CancelOutDetailId: 0,
  13006. ExpireDate: info.ExpiryDate,
  13007. ProductDate: info.ProductDate,
  13008. MaxUnit: info.CountUnit,
  13009. MinUnit: "",
  13010. }
  13011. service.CreatedCancelStock(cancelStockInfo)
  13012. service.CreateDrugFlowOne(flow)
  13013. }
  13014. }
  13015. }
  13016. return err
  13017. }
  13018. func (this *HisApiController) DeleteNCDS() {
  13019. id, _ := this.GetInt64("id", 0)
  13020. if id > 0 {
  13021. service.DeletePsnNCDSRecordById(id)
  13022. this.ServeSuccessJSON(map[string]interface{}{
  13023. "msg": "删除成功",
  13024. })
  13025. } else {
  13026. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13027. return
  13028. }
  13029. }
  13030. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13031. id, _ := c.GetInt64("id")
  13032. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13033. c.ServeSuccessJSON(map[string]interface{}{
  13034. "advice": advice,
  13035. })
  13036. return
  13037. }
  13038. func (c *HisApiController) GetHisMonthChargePatientList() {
  13039. record_date := c.GetString("record_date")
  13040. start_time := c.GetString("start_time")
  13041. end_time := c.GetString("end_time")
  13042. timeLayout := "2006-01-02"
  13043. loc, _ := time.LoadLocation("Local")
  13044. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13045. if err != nil {
  13046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13047. return
  13048. }
  13049. if err != nil {
  13050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13051. return
  13052. }
  13053. recordDateTime := theTime.Unix()
  13054. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13055. if err != nil {
  13056. }
  13057. startRecordDateTime := startTime.Unix()
  13058. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13059. if err != nil {
  13060. }
  13061. endRecordDateTime := endTime.Unix()
  13062. adminInfo := c.GetAdminUserInfo()
  13063. var tempMonthChargePatients []*service.MonthChargePatients
  13064. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13065. for _, item := range tempPatients {
  13066. //过滤没有处方的
  13067. if len(item.HisPrescription) == 0 {
  13068. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13069. }
  13070. }
  13071. c.ServeSuccessJSON(map[string]interface{}{
  13072. "list": tempMonthChargePatients,
  13073. })
  13074. }
  13075. // PrescriptionDifference 医嘱数量差值结构体
  13076. type PrescriptionDrugDifference struct {
  13077. DrugID int64 //基础库药品id
  13078. ID int64 //医嘱id
  13079. Difference float64 //差值
  13080. Unit string //单位
  13081. }
  13082. type PrescriptionGoodDifference struct {
  13083. GoodID int64 //基础库项目耗材id
  13084. ID int64 //医嘱id
  13085. Difference int64 //差值
  13086. Unit string //单位
  13087. Type int64 //类型
  13088. }
  13089. type EditCustomData struct {
  13090. adviceList []*models.HisDoctorAdviceInfo
  13091. projectList []*models.HisPrescriptionProject
  13092. }
  13093. type SrcCustomData struct {
  13094. adviceList []*models.HisDoctorAdviceInfo
  13095. projectList []*models.HisPrescriptionProject
  13096. }
  13097. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13098. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13099. differences := make([]*PrescriptionDrugDifference, 0)
  13100. // 创建一个 map 来存储第一个切片中的药品信息
  13101. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13102. for _, advice := range firstPrescription {
  13103. firstMap[advice.DrugId] = advice
  13104. }
  13105. // 遍历第二个切片中的药品信息,并比较数量差值
  13106. for _, advice := range secondPrescription {
  13107. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13108. diff := &PrescriptionDrugDifference{
  13109. DrugID: advice.DrugId,
  13110. ID: firstAdvice.ID,
  13111. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13112. Unit: firstAdvice.PrescribingNumberUnit,
  13113. }
  13114. differences = append(differences, diff)
  13115. }
  13116. }
  13117. return differences
  13118. }
  13119. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13120. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13121. differences := make([]*PrescriptionGoodDifference, 0)
  13122. // 创建一个 map 来存储第一个切片中的耗材信息
  13123. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13124. for _, good := range firstPrescription {
  13125. firstMap[good.ProjectId] = good
  13126. }
  13127. // 遍历第二个切片中的耗材信息,并比较数量差值
  13128. for _, good := range secondPrescription {
  13129. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13130. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13131. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13132. diff := &PrescriptionGoodDifference{
  13133. GoodID: good.ProjectId,
  13134. ID: firstGood.ID,
  13135. Difference: count - firstCount,
  13136. Unit: firstGood.Unit,
  13137. Type: firstGood.Type,
  13138. }
  13139. differences = append(differences, diff)
  13140. }
  13141. }
  13142. return differences
  13143. }
  13144. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13145. var adviceList []*models.HisDoctorAdviceInfo
  13146. var projectList []*models.HisPrescriptionProject
  13147. var advice_ids []int64
  13148. var project_ids []int64
  13149. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13150. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13151. //var tempPrescription *models.HisPrescriptionProjectscription
  13152. if len(prescriptions) > 0 {
  13153. for _, item := range prescriptions {
  13154. items := item.(map[string]interface{})
  13155. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13156. advices := items["advices"].([]interface{})
  13157. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13158. groupNo := int64(0)
  13159. ctime := time.Now().Unix()
  13160. mtime := ctime
  13161. if len(advices) > 0 {
  13162. for _, advice := range advices {
  13163. var s models.HisDoctorAdviceInfo
  13164. s.AdviceType = 2
  13165. s.StopState = 2
  13166. s.ExecutionState = 2
  13167. s.Status = 1
  13168. s.Groupno = groupNo
  13169. s.CreatedTime = ctime
  13170. s.UpdatedTime = mtime
  13171. s.IsSettle = 2
  13172. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13173. //存储切片中
  13174. if s.ID > 0 {
  13175. advice_ids = append(advice_ids, s.ID)
  13176. adviceList = append(adviceList, &s)
  13177. }
  13178. }
  13179. }
  13180. }
  13181. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13182. projects := items["project"].([]interface{})
  13183. if len(projects) > 0 {
  13184. for _, project := range projects {
  13185. var p models.HisPrescriptionProject
  13186. p.Ctime = time.Now().Unix()
  13187. p.Mtime = time.Now().Unix()
  13188. p.Status = 1
  13189. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13190. if p.ID > 0 {
  13191. project_ids = append(project_ids, p.ID)
  13192. projectList = append(projectList, &p)
  13193. }
  13194. }
  13195. }
  13196. }
  13197. }
  13198. }
  13199. }
  13200. editCustomData.projectList = projectList
  13201. editCustomData.adviceList = adviceList
  13202. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13203. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13204. srcCustomData.adviceList = list
  13205. srcCustomData.projectList = list2
  13206. return
  13207. }
  13208. func (c *HisApiController) GetAllGoodInforList() {
  13209. orgId := c.GetAdminUserInfo().CurrentOrgId
  13210. goodList, _ := service.GetAllGoodList(orgId)
  13211. c.ServeSuccessJSON(map[string]interface{}{
  13212. "goodList": goodList,
  13213. })
  13214. return
  13215. }
  13216. func (this *HisApiController) SaveGoodList() {
  13217. project_name := this.GetString("project_name")
  13218. sort, _ := this.GetInt64("sort")
  13219. orgId := this.GetAdminUserInfo().CurrentOrgId
  13220. dataBody := make(map[string]interface{}, 0)
  13221. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13222. if err != nil {
  13223. utils.ErrorLog(err.Error())
  13224. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13225. return
  13226. }
  13227. goodTeam := models.XtGoodTeam{
  13228. ProjectName: project_name,
  13229. Sort: sort,
  13230. UserOrgId: orgId,
  13231. Status: 1,
  13232. Ctime: time.Now().Unix(),
  13233. Mtime: time.Now().Unix(),
  13234. }
  13235. service.CreateGoodTeam(goodTeam)
  13236. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13237. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13238. infos, _ := dataBody["info"].([]interface{})
  13239. if len(infos) > 0 {
  13240. for _, item := range infos {
  13241. items := item.(map[string]interface{})
  13242. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13243. utils.ErrorLog("good_id")
  13244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13245. return
  13246. }
  13247. good_id := int64(items["good_id"].(float64))
  13248. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13249. utils.ErrorLog("number")
  13250. }
  13251. number := int64(items["number"].(float64))
  13252. xtGoodTeamList := models.XtGoodTeamList{
  13253. GoodId: good_id,
  13254. Count: number,
  13255. TeamId: lastGoodTeam.ID,
  13256. UserOrgId: orgId,
  13257. Status: 1,
  13258. Ctime: time.Now().Unix(),
  13259. Mtime: time.Now().Unix(),
  13260. }
  13261. service.CreateGoodList(xtGoodTeamList)
  13262. }
  13263. this.ServeSuccessJSON(map[string]interface{}{
  13264. "lastGoodTeam": lastGoodTeam,
  13265. })
  13266. }
  13267. }
  13268. return
  13269. }
  13270. func (this *HisApiController) GetGoodList() {
  13271. orgId := this.GetAdminUserInfo().CurrentOrgId
  13272. limit, _ := this.GetInt64("limit")
  13273. page, _ := this.GetInt64("page")
  13274. keyword := this.GetString("keyword")
  13275. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13276. this.ServeSuccessJSON(map[string]interface{}{
  13277. "list": list,
  13278. "total": total,
  13279. })
  13280. }
  13281. func (this *HisApiController) GetGoodNameDetail() {
  13282. id, _ := this.GetInt64("id")
  13283. orgId := this.GetAdminUserInfo().CurrentOrgId
  13284. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13285. goodList, _ := service.GetAllGoodList(orgId)
  13286. this.ServeSuccessJSON(map[string]interface{}{
  13287. "goodNameDetail": goodNameDetail,
  13288. "goodList": goodList,
  13289. })
  13290. }
  13291. func (this *HisApiController) UpdateGoodList() {
  13292. project_name := this.GetString("project_name")
  13293. sort, _ := this.GetInt64("sort")
  13294. id, _ := this.GetInt64("id")
  13295. orgId := this.GetAdminUserInfo().CurrentOrgId
  13296. dataBody := make(map[string]interface{}, 0)
  13297. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13298. if err != nil {
  13299. utils.ErrorLog(err.Error())
  13300. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13301. return
  13302. }
  13303. goodTeam := models.XtGoodTeam{
  13304. ProjectName: project_name,
  13305. Sort: sort,
  13306. UserOrgId: orgId,
  13307. Status: 1,
  13308. Ctime: time.Now().Unix(),
  13309. Mtime: time.Now().Unix(),
  13310. ID: id,
  13311. }
  13312. service.SaveGoodTeam(goodTeam)
  13313. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13314. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13315. infos, _ := dataBody["info"].([]interface{})
  13316. if len(infos) > 0 {
  13317. for _, item := range infos {
  13318. items := item.(map[string]interface{})
  13319. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13320. utils.ErrorLog("good_id")
  13321. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13322. return
  13323. }
  13324. good_id := int64(items["good_id"].(float64))
  13325. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13326. utils.ErrorLog("id")
  13327. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13328. return
  13329. }
  13330. id := int64(items["id"].(float64))
  13331. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13332. utils.ErrorLog("number")
  13333. }
  13334. number := int64(items["number"].(float64))
  13335. xtGoodTeamList := models.XtGoodTeamList{
  13336. ID: id,
  13337. GoodId: good_id,
  13338. Count: number,
  13339. TeamId: lastGoodTeam.ID,
  13340. UserOrgId: orgId,
  13341. Status: 1,
  13342. Ctime: time.Now().Unix(),
  13343. Mtime: time.Now().Unix(),
  13344. }
  13345. service.SaveGoodList(xtGoodTeamList)
  13346. }
  13347. this.ServeSuccessJSON(map[string]interface{}{
  13348. "lastGoodTeam": lastGoodTeam,
  13349. })
  13350. }
  13351. }
  13352. return
  13353. }
  13354. func (this *HisApiController) DeleteGoodTeam() {
  13355. id, _ := this.GetInt64("id")
  13356. team, _ := service.DeleteGoodTeam(id)
  13357. this.ServeSuccessJSON(map[string]interface{}{
  13358. "team": team,
  13359. })
  13360. }
  13361. func (this *HisApiController) DeleteGood() {
  13362. id, _ := this.GetInt64("id")
  13363. good, _ := service.DeleteGood(id)
  13364. this.ServeSuccessJSON(map[string]interface{}{
  13365. "good": good,
  13366. })
  13367. }