his_api_controller.go 601KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  91. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  92. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  93. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  94. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  95. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  96. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  97. }
  98. func (c *HisApiController) CheckHisPatient() {
  99. record_date := c.GetString("record_date")
  100. patient_id, _ := c.GetInt64("patient_id")
  101. timeLayout := "2006-01-02"
  102. loc, _ := time.LoadLocation("Local")
  103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  104. if err != nil {
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. recordDateTime := theTime.Unix()
  109. adminInfo := c.GetAdminUserInfo()
  110. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  111. if len(patients) > 1 {
  112. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  113. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "status": 1,
  116. "msg": "关联",
  117. "ps": ps,
  118. "his_patient_id": patients[len(patients)-1].ID,
  119. "patient_id": patients[len(patients)-1].PatientId,
  120. })
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. }
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. return
  133. }
  134. }
  135. func (c *HisApiController) AssociationHisPrescription() {
  136. record_date := c.GetString("record_date")
  137. his_patient_id, _ := c.GetInt64("his_patient_id")
  138. patient_id, _ := c.GetInt64("patient_id")
  139. p_ids := c.GetString("p_ids")
  140. p_ids_arr := strings.Split(p_ids, ",")
  141. timeLayout := "2006-01-02"
  142. loc, _ := time.LoadLocation("Local")
  143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  144. if err != nil {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. recordDateTime := theTime.Unix()
  149. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  150. if his_patient_id == 0 || his_patient.ID == 0 {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  155. if err == nil {
  156. c.ServeSuccessJSON(map[string]interface{}{
  157. "msg": "关联处方成功",
  158. })
  159. return
  160. } else {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  162. return
  163. }
  164. }
  165. //func (c *HisApiController) AssociationHisPrescription() {
  166. // record_date, _ := c.GetInt64("record_date")
  167. // his_patient_id, _ := c.GetInt64("his_patient_id")
  168. // patient_id, _ := c.GetInt64("patient_id")
  169. // p_ids := c.GetString("p_ids")
  170. // p_ids_arr := strings.Split(p_ids, ",")
  171. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  172. // if his_patient_id == 0 || his_patient.ID == 0 {
  173. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. // return
  175. // }
  176. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  177. // if err == nil {
  178. // c.ServeSuccessJSON(map[string]interface{}{
  179. // "msg": "关联处方成功",
  180. // })
  181. // return
  182. // } else {
  183. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  184. // return
  185. // }
  186. //}
  187. func (c *HisApiController) GetFaPiaoNumber() {
  188. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  189. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  190. fmt.Println(count)
  191. var zero string
  192. number := count + 1
  193. //if number >= 1000 {
  194. // zero = "0000" + strconv.FormatInt(number, 10)
  195. //} else if number >= 10000 {
  196. // zero = "000" + strconv.FormatInt(number, 10)
  197. //} else if number >= 100000 {
  198. // zero = "00" + strconv.FormatInt(number, 10)
  199. //} else if number >= 1000000 {
  200. // zero = "0" + strconv.FormatInt(number, 10)
  201. //} else {
  202. zero = "0" + strconv.FormatInt(number, 10)
  203. //}
  204. c.ServeSuccessJSON(map[string]interface{}{
  205. "fapiao_number": zero,
  206. })
  207. return
  208. }
  209. func (c *HisApiController) ChangeOrderDesc() {
  210. id, _ := c.GetInt64("id")
  211. desc := c.GetString("desc")
  212. change_type := c.GetString("change_type")
  213. order, _ := service.GetHisOrderByID(id)
  214. if order.ID == 0 {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  216. return
  217. }
  218. switch change_type {
  219. case "oth_desc":
  220. order.OthDesc = desc
  221. break
  222. case "cash_pay":
  223. order.CashPay = desc
  224. break
  225. case "jifen_pay":
  226. order.JifenPay = desc
  227. break
  228. case "card_desc":
  229. order.CardDesc = desc
  230. break
  231. case "band_card_pay":
  232. order.BandCardPay = desc
  233. break
  234. case "ali_pay":
  235. order.AliPay = desc
  236. break
  237. case "wechat_pay":
  238. order.WechatPay = desc
  239. break
  240. case "fa_piao_number":
  241. order.FaPiaoNumber = desc
  242. break
  243. case "fa_piao_code":
  244. order.FaPiaoCode = desc
  245. break
  246. }
  247. err := service.SaveHisOrder(&order)
  248. if err == nil {
  249. c.ServeSuccessJSON(map[string]interface{}{
  250. "msg": "修改成功",
  251. })
  252. return
  253. } else {
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  255. return
  256. }
  257. }
  258. func (c *HisApiController) GetMonthHisPatient() {
  259. record_date := c.GetString("record_date")
  260. //order_status, _ := c.GetInt64("type")
  261. timeLayout := "2006-01-02"
  262. loc, _ := time.LoadLocation("Local")
  263. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  264. if err != nil {
  265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  266. return
  267. }
  268. recordDateTime := theTime.Unix()
  269. adminInfo := c.GetAdminUserInfo()
  270. var tempPatients []service.NewTempPatients
  271. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  272. // 获取当前时间
  273. now := time.Now()
  274. // 获取本月的第一天
  275. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  276. // 获取下个月的第一天
  277. nextMonth := firstDay.AddDate(0, 1, 0)
  278. // 获取本月的最后一天
  279. lastDay := nextMonth.Add(-time.Nanosecond)
  280. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  281. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  282. var patients []service.NewTempPatients
  283. var patients_two []service.NewTempPatients
  284. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  285. for _, item := range tempPatients {
  286. //过滤掉没挂号的和没开处方的
  287. if len(item.HisPrescription) > 0 {
  288. patients = append(patients, item)
  289. patients_two = append(patients_two, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. //}
  294. }
  295. } else {
  296. for _, item := range tempPatients {
  297. //过滤掉没挂号的和没开处方的
  298. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  299. patients = append(patients, item)
  300. }
  301. ////过滤掉没挂号的
  302. //if len(item.HisPatient) > 0 {
  303. // patients_two = append(patients_two, item)
  304. //}
  305. }
  306. }
  307. c.ServeSuccessJSON(map[string]interface{}{
  308. "list": patients,
  309. "list_two": patients_two,
  310. "chargePatients": chargePatients,
  311. })
  312. }
  313. func (c *HisApiController) GetBatchSettleAccounts() {
  314. order_ids := c.GetString("order_ids")
  315. admin_user_id, _ := c.GetInt64("admin_user_id")
  316. adminUser := c.GetAdminUserInfo()
  317. orders := strings.Split(order_ids, ",")
  318. var newOrders []models.Orders
  319. for _, item := range orders {
  320. order, _ := service.GetHisOrderByIDTenOne(item)
  321. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  322. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  323. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  324. orderInfos = append(orderInfos, orderInfos_two...)
  325. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  326. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  327. var diagnosis_ids []string
  328. if his.ID > 0 {
  329. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  330. } else {
  331. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  332. }
  333. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  334. var dia_config []*models.HisXtDiagnoseConfig
  335. var name string
  336. for _, item := range diagnosis_ids {
  337. id, _ := strconv.ParseInt(item, 10, 64)
  338. diagnosisConfig, _ := service.FindDiagnoseById(id)
  339. dia_config = append(dia_config, diagnosisConfig)
  340. if len(name) == 0 {
  341. name = diagnosisConfig.ClassName
  342. } else {
  343. name = name + "," + diagnosisConfig.ClassName
  344. }
  345. }
  346. var bedCostTotal float64 = 0 //床位总费
  347. var bedCostSelfTotal float64 = 0 //床位自费
  348. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  349. var bedSelfTotal float64 = 0 //床位部分项目自费
  350. var bedInscpTotal float64 = 0 //床位部分项目自费
  351. var operationCostTotal float64 = 0 //手术费
  352. var operationCostSelfTotal float64 = 0 //手术费
  353. var operationCostPartSelfTotal float64 = 0 //手术费
  354. var operationSelfTotal float64 = 0 //床位部分项目自费
  355. var operationInscpTotal float64 = 0 //床位部分项目自费
  356. var otherCostTotal float64 = 0 //其他费用
  357. var otherCostSelfTotal float64 = 0 //其他费用
  358. var otherCostPartSelfTotal float64 = 0 //其他费用
  359. var otherSelfTotal float64 = 0 //床位部分项目自费
  360. var otherInscpTotal float64 = 0 //床位部分项目自费
  361. var materialCostTotal float64 = 0 //材料费
  362. var materialCostSelfTotal float64 = 0 //材料费
  363. var materialCostPartSelfTotal float64 = 0 //材料费
  364. var materialSelfTotal float64 = 0 //床位部分项目自费
  365. var materialInscpTotal float64 = 0 //床位部分项目自费
  366. var westernMedicineCostTotal float64 = 0 //西药费
  367. var westernMedicineCostSelfTotal float64 = 0 //西药费
  368. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  369. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  370. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  371. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  372. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  373. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  374. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  375. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  376. var checkCostTotal float64 = 0 //检查费
  377. var checkCostSelfTotal float64 = 0 //检查费
  378. var checkCostPartSelfTotal float64 = 0 //检查费
  379. var checkSelfTotal float64 = 0 //床位部分项目自费
  380. var checkInscpTotal float64 = 0 //床位部分项目自费
  381. var laboratoryCostTotal float64 = 0 //化验费
  382. var laboratoryCostSelfTotal float64 = 0 //化验费
  383. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  384. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  385. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  386. var treatCostTotal float64 = 0 //治疗费用
  387. var treatCostSelfTotal float64 = 0 //治疗费用
  388. var treatCostPartSelfTotal float64 = 0 //治疗费用
  389. var treatSelfTotal float64 = 0 //床位部分项目自费
  390. var treatInscpTotal float64 = 0 //床位部分项目自费
  391. decimal.DivisionPrecision = 2
  392. for _, item := range orderInfos {
  393. if item.MedChrgitmType == "01" { //床位费
  394. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  395. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  396. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  397. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  398. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  399. }
  400. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  401. if item.MedChrgitmType == "03" { //检查费
  402. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  403. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  404. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  405. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  406. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  407. }
  408. } else {
  409. if item.MedChrgitmType == "03" { //检查费
  410. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  411. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  412. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  413. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  414. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  415. }
  416. }
  417. if item.MedChrgitmType == "04" { //化验费
  418. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  419. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  420. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  421. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  422. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  423. }
  424. if item.MedChrgitmType == "05" { //治疗费
  425. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  426. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  427. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  428. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  429. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  430. }
  431. if item.MedChrgitmType == "06" { //手术费
  432. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  433. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  434. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  435. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  436. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  437. }
  438. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  439. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  440. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  441. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  442. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  443. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  444. }
  445. if item.MedChrgitmType == "09" { //西药费
  446. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  447. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  448. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  449. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  450. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  451. }
  452. if item.MedChrgitmType == "11" { //中成费
  453. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  454. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  455. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  456. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  457. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  458. }
  459. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  460. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  461. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  462. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  463. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  464. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  465. }
  466. }
  467. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  468. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  469. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  470. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  471. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  472. var doctor_name string
  473. if roles.ID == 0 {
  474. doctor_name = "管理员"
  475. } else {
  476. doctor_name = roles.UserName
  477. }
  478. yiliao_leibie := ""
  479. switch order.MedType {
  480. case "11":
  481. yiliao_leibie = "普通门诊"
  482. break
  483. case "12":
  484. yiliao_leibie = "门诊挂号"
  485. break
  486. case "13":
  487. yiliao_leibie = "急诊"
  488. break
  489. case "14":
  490. yiliao_leibie = "门诊特殊病"
  491. break
  492. case "15":
  493. yiliao_leibie = "门诊统筹"
  494. break
  495. case "16":
  496. yiliao_leibie = "门诊慢性病"
  497. break
  498. case "21":
  499. yiliao_leibie = "普通住院"
  500. break
  501. }
  502. var newOrder models.Orders
  503. newOrder.Diagnosis = name
  504. newOrder.OrderInfos = orderInfos
  505. newOrder.Number = order.MdtrtId
  506. newOrder.Date = order.SettleAccountsDate
  507. newOrder.ChargeAdmin = charge_admin
  508. newOrder.PrintorAdmin = printor_admin
  509. newOrder.Order = order
  510. newOrder.BedCostTotal = bedCostTotal
  511. newOrder.BedCostSelfTotal = bedCostSelfTotal
  512. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  513. newOrder.BedSelfTotal = bedSelfTotal
  514. newOrder.BedInscpTotal = bedInscpTotal
  515. newOrder.OperationCostTotal = operationCostTotal
  516. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  517. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  518. newOrder.OperationSelfTotal = operationSelfTotal
  519. newOrder.OperationInscpTotal = operationInscpTotal
  520. newOrder.OtherCostTotal = otherCostTotal
  521. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  522. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  523. newOrder.OtherSelfTotal = otherSelfTotal
  524. newOrder.OtherInscpTotal = otherInscpTotal
  525. newOrder.MaterialCostTotal = materialCostTotal
  526. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  527. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  528. newOrder.MaterialSelfTotal = materialSelfTotal
  529. newOrder.MaterialInscpTotal = materialInscpTotal
  530. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  531. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  532. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  533. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  534. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  535. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  536. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  537. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  538. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  539. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  540. newOrder.CheckCostTotal = checkCostTotal
  541. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  542. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  543. newOrder.CheckSelfTotal = checkSelfTotal
  544. newOrder.CheckInscpTotal = checkInscpTotal
  545. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  546. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  547. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  548. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  549. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  550. newOrder.TreatCostTotal = treatCostTotal
  551. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  552. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  553. newOrder.TreatSelfTotal = treatSelfTotal
  554. newOrder.TreatInscpTotal = treatInscpTotal
  555. newOrder.DoctorInfo = doctor_info
  556. newOrder.DoctorName = doctor_name
  557. newOrder.HealthCardNo = order.PsnNo
  558. newOrder.YiliaoLeibie = yiliao_leibie
  559. newOrder.Patient = patient
  560. newOrder.OrgName = miConfig.OrgName
  561. newOrder.OrgCode = miConfig.Code
  562. newOrder.OrderNumber = order.Number
  563. newOrder.HisPatient = his
  564. newOrder.DiaConfig = dia_config
  565. newOrders = append(newOrders, newOrder)
  566. }
  567. c.ServeSuccessJSON(map[string]interface{}{
  568. "orders": newOrders,
  569. })
  570. }
  571. func (c *HisApiController) GetTestOrder() {
  572. order_id, _ := c.GetInt64("order_id")
  573. admin_user_id, _ := c.GetInt64("admin_user_id")
  574. adminUser := c.GetAdminUserInfo()
  575. order, _ := service.GetHisOrderByID(order_id)
  576. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  577. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  578. orderInfos = append(orderInfos, orderInfos_two...)
  579. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  580. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  581. var dia_config []*models.HisXtDiagnoseConfig
  582. var name string
  583. var bedCostTotal float64 = 0 //床位总费
  584. var bedCostSelfTotal float64 = 0 //床位自费
  585. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  586. var bedSelfTotal float64 = 0 //床位部分项目自费
  587. var bedInscpTotal float64 = 0 //床位部分项目自费
  588. var operationCostTotal float64 = 0 //手术费
  589. var operationCostSelfTotal float64 = 0 //手术费
  590. var operationCostPartSelfTotal float64 = 0 //手术费
  591. var operationSelfTotal float64 = 0 //床位部分项目自费
  592. var operationInscpTotal float64 = 0 //床位部分项目自费
  593. var otherCostTotal float64 = 0 //其他费用
  594. var otherCostSelfTotal float64 = 0 //其他费用
  595. var otherCostPartSelfTotal float64 = 0 //其他费用
  596. var otherSelfTotal float64 = 0 //床位部分项目自费
  597. var otherInscpTotal float64 = 0 //床位部分项目自费
  598. var materialCostTotal float64 = 0 //材料费
  599. var materialCostSelfTotal float64 = 0 //材料费
  600. var materialCostPartSelfTotal float64 = 0 //材料费
  601. var materialSelfTotal float64 = 0 //床位部分项目自费
  602. var materialInscpTotal float64 = 0 //床位部分项目自费
  603. var westernMedicineCostTotal float64 = 0 //西药费
  604. var westernMedicineCostSelfTotal float64 = 0 //西药费
  605. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  606. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  607. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  608. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  609. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  610. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  611. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  612. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  613. var checkCostTotal float64 = 0 //检查费
  614. var checkCostSelfTotal float64 = 0 //检查费
  615. var checkCostPartSelfTotal float64 = 0 //检查费
  616. var checkSelfTotal float64 = 0 //床位部分项目自费
  617. var checkInscpTotal float64 = 0 //床位部分项目自费
  618. var laboratoryCostTotal float64 = 0 //化验费
  619. var laboratoryCostSelfTotal float64 = 0 //化验费
  620. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  621. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  622. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  623. var treatCostTotal float64 = 0 //治疗费用
  624. var treatCostSelfTotal float64 = 0 //治疗费用
  625. var treatCostPartSelfTotal float64 = 0 //治疗费用
  626. var treatSelfTotal float64 = 0 //床位部分项目自费
  627. var treatInscpTotal float64 = 0 //床位部分项目自费
  628. decimal.DivisionPrecision = 2
  629. for _, item := range orderInfos {
  630. if item.MedChrgitmType == "01" { //床位费
  631. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  632. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  633. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  634. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  635. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  636. }
  637. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  638. if item.MedChrgitmType == "03" { //检查费
  639. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  640. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  641. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  642. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  643. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  644. }
  645. } else {
  646. if item.MedChrgitmType == "03" { //检查费
  647. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  648. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  649. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  650. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  651. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  652. }
  653. }
  654. if item.MedChrgitmType == "04" { //化验费
  655. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  656. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  657. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  658. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  659. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  660. }
  661. if item.MedChrgitmType == "05" { //治疗费
  662. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  663. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  664. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  665. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  666. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  667. }
  668. if item.MedChrgitmType == "06" { //手术费
  669. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  670. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  671. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  672. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  673. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  674. }
  675. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  676. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  677. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  678. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  679. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  680. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  681. }
  682. if item.MedChrgitmType == "09" { //西药费
  683. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  684. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  685. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  686. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  687. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  688. }
  689. if item.MedChrgitmType == "11" { //中成费
  690. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  691. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  692. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  693. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  694. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  695. }
  696. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  697. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  698. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  699. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  700. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  701. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  702. }
  703. }
  704. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  705. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  706. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  707. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  708. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  709. var doctor_name string
  710. if roles.ID == 0 {
  711. doctor_name = "管理员"
  712. } else {
  713. doctor_name = roles.UserName
  714. }
  715. yiliao_leibie := ""
  716. switch order.MedType {
  717. case "11":
  718. yiliao_leibie = "普通门诊"
  719. break
  720. case "12":
  721. yiliao_leibie = "门诊挂号"
  722. break
  723. case "13":
  724. yiliao_leibie = "急诊"
  725. break
  726. case "14":
  727. yiliao_leibie = "门诊特殊病"
  728. break
  729. case "15":
  730. yiliao_leibie = "门诊统筹"
  731. break
  732. case "16":
  733. yiliao_leibie = "门诊慢性病"
  734. break
  735. case "21":
  736. yiliao_leibie = "普通住院"
  737. break
  738. }
  739. c.ServeSuccessJSON(map[string]interface{}{
  740. "diagnosis": name,
  741. "order_infos": orderInfos,
  742. "number": order.MdtrtId,
  743. "date": order.SettleAccountsDate,
  744. "charge_admin": charge_admin,
  745. "printor_admin": printor_admin,
  746. "info": order,
  747. "order": order,
  748. "bedCostTotal": bedCostTotal,
  749. "bedCostSelfTotal": bedCostSelfTotal,
  750. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  751. "bedSelfTotal": bedSelfTotal,
  752. "bedInscpTotal": bedInscpTotal,
  753. "operationCostTotal": operationCostTotal,
  754. "operationCostSelfTotal": operationCostSelfTotal,
  755. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  756. "operationSelfTotal": operationSelfTotal,
  757. "operationInscpTotal": operationInscpTotal,
  758. "otherCostTotal": otherCostTotal,
  759. "otherCostSelfTotal": otherCostSelfTotal,
  760. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  761. "otherSelfTotal": otherSelfTotal,
  762. "otherInscpTotal": otherInscpTotal,
  763. "materialCostTotal": materialCostTotal,
  764. "materialCostSelfTotal": materialCostSelfTotal,
  765. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  766. "materialSelfTotal": materialSelfTotal,
  767. "materialInscpTotal": materialInscpTotal,
  768. "westernMedicineCostTotal": westernMedicineCostTotal,
  769. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  770. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  771. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  772. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  773. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  774. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  775. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  776. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  777. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  778. "checkCostTotal": checkCostTotal,
  779. "checkCostSelfTotal": checkCostSelfTotal,
  780. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  781. "checkSelfTotal": checkSelfTotal,
  782. "checkInscpTotal": checkInscpTotal,
  783. "laboratoryCostTotal": laboratoryCostTotal,
  784. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  785. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  786. "laboratorySelfTotal": laboratorySelfTotal,
  787. "laboratoryInscpTotal": laboratoryInscpTotal,
  788. "treatCostTotal": treatCostTotal,
  789. "treatCostSelfTotal": treatCostSelfTotal,
  790. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  791. "treatSelfTotal": treatSelfTotal,
  792. "treatInscpTotal": treatInscpTotal,
  793. "doctor_info": doctor_info,
  794. "doctor_name": doctor_name,
  795. "health_card_no": order.PsnNo,
  796. "yiliao_leibie": yiliao_leibie,
  797. "patient": patient,
  798. "org_name": miConfig.OrgName,
  799. "org_code": miConfig.Code,
  800. "order_number": order.Number,
  801. "his_hospital": his_hospital,
  802. "dia_config": dia_config,
  803. })
  804. }
  805. type CustomFundPay struct {
  806. FundPayType string `json:"fund_pay_type"`
  807. FundPayamt float64 `json:"fund_payamt"`
  808. InscpScpAmt float64 `json:"inscp_scp_amt"`
  809. }
  810. func (c *PublicApiController) GetBaiLinExportData() {
  811. data := service.GetBaiLinOrderData()
  812. fmt.Println(len(data))
  813. var new_data []*models.NewCustomHisOrder
  814. for _, item := range data {
  815. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  816. new_data = append(new_data, item)
  817. }
  818. }
  819. fmt.Println(len(new_data))
  820. c.ServeSuccessJSON(map[string]interface{}{
  821. "list": new_data,
  822. })
  823. }
  824. func (c *HisApiController) GetHisUnChargePatientList() {
  825. record_date := c.GetString("record_date")
  826. sch_type, _ := c.GetInt64("sch_type")
  827. timeLayout := "2006-01-02"
  828. loc, _ := time.LoadLocation("Local")
  829. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  830. if err != nil {
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  832. return
  833. }
  834. recordDateTime := theTime.Unix()
  835. adminInfo := c.GetAdminUserInfo()
  836. var tempPatients []*service.NewTempPatients
  837. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  838. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  839. var patients []*service.NewTempPatients
  840. var patients_two []*service.NewTempPatients
  841. for _, item := range tempPatients {
  842. //过滤掉没挂号的和没开处方的
  843. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  844. patients = append(patients, item)
  845. }
  846. //过滤掉没挂号的
  847. if len(item.HisPatient) > 0 {
  848. patients_two = append(patients_two, item)
  849. }
  850. }
  851. c.ServeSuccessJSON(map[string]interface{}{
  852. "list": patients,
  853. "list_two": patients_two,
  854. })
  855. }
  856. func (c *HisApiController) GetPrivateExpensesOrder() {
  857. //id, _ := c.GetInt64("id")
  858. //record_time := c.GetString("record_time")
  859. order_id, _ := c.GetInt64("order_id")
  860. admin_user_id, _ := c.GetInt64("admin_user_id")
  861. //timeLayout := "2006-01-02"
  862. //loc, _ := time.LoadLocation("Local")
  863. //
  864. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  865. //if err != nil {
  866. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  867. // return
  868. //}
  869. //recordDateTime := theTime.Unix()
  870. adminUser := c.GetAdminUserInfo()
  871. order, _ := service.GetHisOrderByID(order_id)
  872. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  873. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  874. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  875. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  876. //var config []*models.HisXtDiagnoseConfig
  877. var name string
  878. if order.PType == 1 {
  879. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  880. for _, item := range diagnosis_ids {
  881. id, _ := strconv.ParseInt(item, 10, 64)
  882. diagnosisConfig, _ := service.FindDiagnoseById(id)
  883. if len(name) == 0 {
  884. name = diagnosisConfig.ClassName
  885. } else {
  886. name = name + "," + diagnosisConfig.ClassName
  887. }
  888. }
  889. } else {
  890. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  891. for _, item := range diagnosis_ids {
  892. id, _ := strconv.ParseInt(item, 10, 64)
  893. diagnosisConfig, _ := service.FindDiagnoseById(id)
  894. if len(name) == 0 {
  895. name = diagnosisConfig.ClassName
  896. } else {
  897. name = name + "," + diagnosisConfig.ClassName
  898. }
  899. }
  900. }
  901. var bedCostTotal float64 = 0 //床位总费
  902. var bedCostSelfTotal float64 = 0 //床位自费
  903. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  904. var bedSelfTotal float64 = 0 //床位部分项目自费
  905. var bedInscpTotal float64 = 0 //床位部分项目自费
  906. var operationCostTotal float64 = 0 //手术费
  907. var operationCostSelfTotal float64 = 0 //手术费
  908. var operationCostPartSelfTotal float64 = 0 //手术费
  909. var operationSelfTotal float64 = 0 //床位部分项目自费
  910. var operationInscpTotal float64 = 0 //床位部分项目自费
  911. var otherCostTotal float64 = 0 //其他费用
  912. //var otherCostSelfTotal float64 = 0 //其他费用
  913. var otherCostPartSelfTotal float64 = 0 //其他费用
  914. //var otherSelfTotal float64 = 0 //床位部分项目自费
  915. //var otherInscpTotal float64 = 0 //床位部分项目自费
  916. var materialCostTotal float64 = 0 //材料费
  917. var materialCostSelfTotal float64 = 0 //材料费
  918. var materialCostPartSelfTotal float64 = 0 //材料费
  919. var materialSelfTotal float64 = 0 //床位部分项目自费
  920. var materialInscpTotal float64 = 0 //床位部分项目自费
  921. var westernMedicineCostTotal float64 = 0 //西药费
  922. var westernMedicineCostSelfTotal float64 = 0 //西药费
  923. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  924. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  925. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  926. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  927. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  928. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  929. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  930. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  931. var checkCostTotal float64 = 0 //检查费
  932. var checkCostSelfTotal float64 = 0 //检查费
  933. var checkCostPartSelfTotal float64 = 0 //检查费
  934. var checkSelfTotal float64 = 0 //床位部分项目自费
  935. var checkInscpTotal float64 = 0 //床位部分项目自费
  936. var laboratoryCostTotal float64 = 0 //化验费
  937. var laboratoryCostSelfTotal float64 = 0 //化验费
  938. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  939. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  940. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  941. var treatCostTotal float64 = 0 //治疗费用
  942. var treatCostSelfTotal float64 = 0 //治疗费用
  943. var treatCostPartSelfTotal float64 = 0 //治疗费用
  944. var treatSelfTotal float64 = 0 //床位部分项目自费
  945. var treatInscpTotal float64 = 0 //床位部分项目自费
  946. var zhenChaCostTotal float64 = 0 //其他费用
  947. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  948. decimal.DivisionPrecision = 2
  949. for _, item := range orderInfos {
  950. //item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  951. if c.GetAdminUserInfo().CurrentOrgId != 10726 {
  952. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  953. item.MedChrgitmType = "09"
  954. }
  955. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  956. if item.HisPrescriptionProject.Type == 2 {
  957. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  958. fmt.Println("CostClassify")
  959. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  960. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  961. case 0:
  962. item.MedChrgitmType = "0"
  963. break
  964. case 1:
  965. item.MedChrgitmType = "14"
  966. break
  967. case 2:
  968. item.MedChrgitmType = "05"
  969. break
  970. case 3:
  971. item.MedChrgitmType = "03"
  972. break
  973. case 4:
  974. item.MedChrgitmType = "03"
  975. break
  976. case 5:
  977. item.MedChrgitmType = "08"
  978. break
  979. case 6:
  980. item.MedChrgitmType = "14"
  981. break
  982. case 7:
  983. item.MedChrgitmType = "14"
  984. break
  985. case 8:
  986. item.MedChrgitmType = "03"
  987. break
  988. case 9:
  989. item.MedChrgitmType = "14"
  990. break
  991. case 10:
  992. item.MedChrgitmType = "14"
  993. break
  994. case 11:
  995. item.MedChrgitmType = "06"
  996. break
  997. case 12:
  998. item.MedChrgitmType = "12"
  999. break
  1000. case 13:
  1001. item.MedChrgitmType = "01"
  1002. break
  1003. case 14:
  1004. item.MedChrgitmType = "04"
  1005. break
  1006. case 15:
  1007. item.MedChrgitmType = "14"
  1008. break
  1009. }
  1010. } else {
  1011. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  1012. case 1:
  1013. item.MedChrgitmType = "14"
  1014. break
  1015. case 2:
  1016. item.MedChrgitmType = "05"
  1017. break
  1018. case 3:
  1019. item.MedChrgitmType = "04"
  1020. break
  1021. case 4:
  1022. item.MedChrgitmType = "14"
  1023. break
  1024. case 5:
  1025. item.MedChrgitmType = "08"
  1026. break
  1027. case 6:
  1028. item.MedChrgitmType = "14"
  1029. break
  1030. case 7:
  1031. item.MedChrgitmType = "14"
  1032. break
  1033. case 8:
  1034. item.MedChrgitmType = "03"
  1035. break
  1036. case 9:
  1037. item.MedChrgitmType = "14"
  1038. break
  1039. default:
  1040. item.MedChrgitmType = "14"
  1041. break
  1042. }
  1043. }
  1044. } else if item.HisPrescriptionProject.Type == 3 {
  1045. item.MedChrgitmType = "08"
  1046. }
  1047. }
  1048. }
  1049. }
  1050. if order.IsMedicineInsurance != 1 {
  1051. order.PsnCashPay = order.MedfeeSumamt
  1052. }
  1053. for _, item := range orderInfos {
  1054. if item.MedChrgitmType == "01" { //床位费
  1055. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1056. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1057. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1058. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1059. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1060. }
  1061. if item.MedChrgitmType == "02" { //诊察费
  1062. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1063. //zhenChaCostSelfTotal = zhenChaCostTotal
  1064. }
  1065. if item.MedChrgitmType == "03" { //检查费
  1066. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1067. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1068. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1069. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1070. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1071. }
  1072. if item.MedChrgitmType == "02" { //检查费
  1073. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1074. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1075. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1076. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1077. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1078. }
  1079. if item.MedChrgitmType == "04" { //化验费
  1080. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1081. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1082. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1083. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1084. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1085. }
  1086. if item.MedChrgitmType == "05" { //治疗费
  1087. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1088. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1089. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1090. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1091. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1092. }
  1093. if item.MedChrgitmType == "06" { //手术费
  1094. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1095. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1096. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1097. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1098. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1099. }
  1100. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1101. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1102. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1103. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1104. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1105. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1106. }
  1107. if item.MedChrgitmType == "09" { //西药费
  1108. fmt.Println("FulamtOwnpayAmt")
  1109. fmt.Println(item.FulamtOwnpayAmt)
  1110. fmt.Println("FulamtOwnpayAmt")
  1111. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1112. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1113. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1114. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1115. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1116. }
  1117. if item.MedChrgitmType == "11" { //中成费
  1118. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1119. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1120. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1121. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1122. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1123. }
  1124. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1125. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1126. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1127. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1128. }
  1129. }
  1130. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1131. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1132. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1133. var dia_config []*models.HisXtDiagnoseConfig
  1134. var diagnosis_ids []string
  1135. if his.ID > 0 {
  1136. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1137. } else {
  1138. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1139. }
  1140. for _, item := range diagnosis_ids {
  1141. id, _ := strconv.ParseInt(item, 10, 64)
  1142. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1143. dia_config = append(dia_config, diagnosisConfig)
  1144. }
  1145. var rf []CustomFundPay
  1146. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1147. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1148. c.ServeSuccessJSON(map[string]interface{}{
  1149. "patient": patient,
  1150. "order_infos": orderInfos,
  1151. "diagnosis": name,
  1152. "bedCostTotal": bedCostTotal,
  1153. "bedCostSelfTotal": bedCostSelfTotal,
  1154. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1155. "bedSelfTotal": bedSelfTotal,
  1156. "bedInscpTotal": bedInscpTotal,
  1157. "operationCostTotal": operationCostTotal,
  1158. "operationCostSelfTotal": operationCostSelfTotal,
  1159. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1160. "operationInscpTotal": operationInscpTotal,
  1161. "operationSelfTotal": operationSelfTotal,
  1162. "otherCostTotal": otherCostTotal,
  1163. //"otherCostSelfTotal": otherCostSelfTotal,
  1164. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1165. "materialCostTotal": materialCostTotal,
  1166. "materialCostSelfTotal": materialCostSelfTotal,
  1167. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1168. "materialSelfTotal": materialSelfTotal,
  1169. "materialInscpTotal": materialInscpTotal,
  1170. "westernMedicineCostTotal": westernMedicineCostTotal,
  1171. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  1172. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1173. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  1174. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  1175. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1176. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  1177. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1178. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  1179. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  1180. "checkCostTotal": checkCostTotal,
  1181. "checkCostSelfTotal": checkCostSelfTotal,
  1182. "checkSelfTotal": checkSelfTotal,
  1183. "checkInscpTotal": checkInscpTotal,
  1184. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1185. "zhenChaCostTotal": zhenChaCostTotal,
  1186. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1187. "laboratoryCostTotal": laboratoryCostTotal,
  1188. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  1189. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1190. "laboratorySelfTotal": laboratorySelfTotal,
  1191. "laboratoryInscpTotal": laboratoryInscpTotal,
  1192. "treatCostTotal": treatCostTotal,
  1193. "treatCostSelfTotal": treatCostSelfTotal,
  1194. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1195. "treatSelfTotal": treatSelfTotal,
  1196. "treatInscpTotal": treatInscpTotal,
  1197. "charge_admin": charge_admin,
  1198. "printor_admin": printor_admin,
  1199. "org_name": org.OrgName,
  1200. "org_code": miConfig.Code,
  1201. "name": patient.Name,
  1202. "number": order.MdtrtId,
  1203. "date": order.SettleAccountsDate,
  1204. "info": order,
  1205. "new_order": order,
  1206. "his_hospital": his_hospital,
  1207. "his": his,
  1208. "funds": rf,
  1209. "dia_config": dia_config,
  1210. })
  1211. }
  1212. func (c *HisApiController) RefudDetail() {
  1213. order_id, _ := c.GetInt64("order_id")
  1214. order, _ := service.GetHisOrderByID(order_id)
  1215. adminUser := c.GetAdminUserInfo()
  1216. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1217. c.ServeSuccessJSON(map[string]interface{}{
  1218. "msg": "撤销成功",
  1219. })
  1220. }
  1221. func (c *HisApiController) Sscard() {
  1222. //r := CardInit()
  1223. //if r == 0 {
  1224. // GetBaseInfo()
  1225. //}
  1226. //c.ServeSuccessJSON(map[string]interface{}{
  1227. // "list": "11",
  1228. //})
  1229. }
  1230. func GetBaseInfo() error {
  1231. //handle := syscall.MustLoadDLL("SSCard.dll")
  1232. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1233. //
  1234. //str := make([]byte, 256)
  1235. //str1 := make([]byte, 256)
  1236. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1237. //if ferr != nil {
  1238. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1239. // return ferr
  1240. //}
  1241. //
  1242. //fmt.Println(string(str))
  1243. //
  1244. //fmt.Println(r)
  1245. return nil
  1246. }
  1247. func CardInit() int {
  1248. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1249. //add := DllTestDef.MustFindProc("Init")
  1250. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1251. //if err != nil {
  1252. // fmt.Println("SSCard的运算结果为:", ret)
  1253. //}
  1254. //result := int(ret)
  1255. return 0
  1256. }
  1257. func IntPtr(n int) uintptr {
  1258. return uintptr(n)
  1259. }
  1260. func StrPtr(s string) uintptr {
  1261. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1262. }
  1263. func (c *HisApiController) GetHisPatientList() {
  1264. record_date := c.GetString("record_date")
  1265. sch_type, _ := c.GetInt64("sch_type")
  1266. patient_type, _ := c.GetInt64("patient_type")
  1267. fmt.Println("patient_type")
  1268. fmt.Println(patient_type)
  1269. timeLayout := "2006-01-02"
  1270. loc, _ := time.LoadLocation("Local")
  1271. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1272. if err != nil {
  1273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1274. return
  1275. }
  1276. recordDateTime := theTime.Unix()
  1277. adminInfo := c.GetAdminUserInfo()
  1278. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1279. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1280. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1281. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1282. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1283. fmt.Println(patients_three)
  1284. //获取当前用户的信息
  1285. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1286. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1287. //获取所有科室信息
  1288. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1289. //var aa []service.PatientThree
  1290. noElementsSlice := make([]service.PatientThree, 0)
  1291. c.ServeSuccessJSON(map[string]interface{}{
  1292. "list": patients_three,
  1293. "list_two": patients_four,
  1294. "list_three": noElementsSlice,
  1295. "info": adminUserInfo,
  1296. "doctors": doctors,
  1297. "department": department,
  1298. })
  1299. } else {
  1300. //获取当前用户的信息
  1301. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1302. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1303. //获取所有科室信息
  1304. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1305. //var aa []service.PatientThree
  1306. noElementsSlice := make([]service.PatientThree, 0)
  1307. c.ServeSuccessJSON(map[string]interface{}{
  1308. "list": patients,
  1309. "list_two": patients_two,
  1310. "list_three": noElementsSlice,
  1311. "info": adminUserInfo,
  1312. "doctors": doctors,
  1313. "department": department,
  1314. })
  1315. }
  1316. }
  1317. type CustomTemplate struct {
  1318. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1319. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1320. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1321. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1322. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1323. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1324. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1325. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1326. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1327. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1328. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1329. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1330. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1331. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1332. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1333. }
  1334. func (c *HisApiController) GetHisPatientInfo() {
  1335. patient_id, _ := c.GetInt64("patient_id")
  1336. his_patient_id, _ := c.GetInt64("his_patient_id")
  1337. record_date := c.GetString("record_date")
  1338. number := c.GetString("number")
  1339. //start_time := c.GetString("start_time")
  1340. //end_time := c.GetString("end_time")
  1341. p_type, _ := c.GetInt64("p_type")
  1342. timeLayout := "2006-01-02"
  1343. loc, _ := time.LoadLocation("Local")
  1344. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1345. if err != nil {
  1346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1347. return
  1348. }
  1349. recordDateTime := theTime.Unix()
  1350. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1351. //if err != nil {
  1352. //
  1353. //}
  1354. //startRecordDateTime := startTime.Unix()
  1355. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1356. //if err != nil {
  1357. //
  1358. //}
  1359. //endRecordDateTime := endTime.Unix()
  1360. admin := c.GetAdminUserInfo()
  1361. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1362. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1363. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1364. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1365. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1366. var prescriptions []*models.HisPrescription
  1367. var last_prescriptions []*models.HisPrescription
  1368. var sch_prescriptions []CustomTemplate
  1369. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1370. if p_type == 1 { //住院
  1371. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1372. for _, item := range prescriptions {
  1373. for _, subItem := range item.HisDoctorAdviceInfo {
  1374. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1375. if info.RetailPrice > 0 {
  1376. subItem.Drug.MinPrice = info.RetailPrice
  1377. }
  1378. }
  1379. }
  1380. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1381. } else { //门诊
  1382. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1383. for _, item := range prescriptions {
  1384. for _, subItem := range item.HisDoctorAdviceInfo {
  1385. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1386. if info.RetailPrice > 0 {
  1387. subItem.Drug.MinPrice = info.RetailPrice
  1388. }
  1389. }
  1390. }
  1391. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1392. }
  1393. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1394. if sch.ID > 0 {
  1395. var week string
  1396. t := time.Now()
  1397. switch t.Weekday().String() {
  1398. case "Monday":
  1399. week = "周一"
  1400. break
  1401. case "Tuesday":
  1402. week = "周二"
  1403. break
  1404. case "Wednesday":
  1405. week = "周三"
  1406. break
  1407. case "Thursday":
  1408. week = "周四"
  1409. break
  1410. case "Friday":
  1411. week = "周五"
  1412. break
  1413. case "Saturday":
  1414. week = "周六"
  1415. break
  1416. case "Sunday":
  1417. week = "周日"
  1418. break
  1419. }
  1420. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1421. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1422. //根据推送频率组装新的数组
  1423. for _, item := range temp_sch_prescriptions {
  1424. var cus CustomTemplate
  1425. cus.ID = item.ID
  1426. cus.UserOrgId = item.UserOrgId
  1427. cus.PatientId = item.PatientId
  1428. cus.MedType = item.MedType
  1429. cus.RecordDate = item.RecordDate
  1430. cus.Type = item.Type
  1431. cus.PType = item.PType
  1432. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1433. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1434. if subItem.FrequencyType == 1 { //每次必推
  1435. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1436. }
  1437. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1438. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1439. }
  1440. if subItem.FrequencyType == 2 { //按照天数频率
  1441. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1442. now := p.Unix()
  1443. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1444. dayStr2 := "-" + dayStr
  1445. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1446. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1447. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1448. if len(advices) == 0 {
  1449. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1450. }
  1451. }
  1452. }
  1453. }
  1454. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1455. if subItem.Type == 2 {
  1456. if subItem.XtHisProject.MedicalStatus != 1 {
  1457. if subItem.FrequencyType == 1 {
  1458. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1459. }
  1460. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1461. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1462. }
  1463. if subItem.FrequencyType == 2 {
  1464. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1465. now := p.Unix()
  1466. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1467. dayStr2 := "-" + dayStr
  1468. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1469. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1470. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1471. if len(projects) == 0 {
  1472. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1473. }
  1474. }
  1475. }
  1476. } else if subItem.Type == 3 {
  1477. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1478. if subItem.FrequencyType == 1 {
  1479. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1480. }
  1481. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1482. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1483. }
  1484. if subItem.FrequencyType == 2 {
  1485. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1486. now := p.Unix()
  1487. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1488. dayStr2 := "-" + dayStr
  1489. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1490. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1491. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1492. if len(projects) == 0 {
  1493. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1494. }
  1495. }
  1496. }
  1497. }
  1498. }
  1499. sch_prescriptions = append(sch_prescriptions, cus)
  1500. }
  1501. for _, item := range sch_prescriptions {
  1502. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1503. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1504. }
  1505. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1506. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1507. }
  1508. }
  1509. }
  1510. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1511. if config.ID > 0 && config.IsOpen == 1 {
  1512. for _, item := range sch_prescriptions {
  1513. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1514. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1515. if info.RetailPrice > 0 {
  1516. subItem.Drug.MinPrice = info.RetailPrice
  1517. if admin.CurrentOrgId != 10598 {
  1518. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1519. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1520. }
  1521. }
  1522. }
  1523. }
  1524. }
  1525. if config.ID > 0 && config.IsOpen == 1 {
  1526. for _, item := range sch_prescriptions {
  1527. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1528. if subItem.Type == 3 {
  1529. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1530. if info.Price > 0 {
  1531. subItem.GoodInfo.PackingPrice = info.Price
  1532. if admin.CurrentOrgId != 10598 {
  1533. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1534. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1535. }
  1536. }
  1537. }
  1538. }
  1539. }
  1540. }
  1541. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1542. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1543. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1544. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1545. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1546. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1547. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1548. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1549. //获取所有科室信息
  1550. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1551. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1552. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1553. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1554. fmt.Println(prescriptions)
  1555. fmt.Println(sch_prescriptions)
  1556. fmt.Println(last_prescriptions)
  1557. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1558. if len(sch_prescriptions) > 0 {
  1559. var index = 0
  1560. for subindex, item := range sch_prescriptions {
  1561. if item.Type == 2 {
  1562. index = subindex
  1563. }
  1564. }
  1565. fmt.Println(index)
  1566. fmt.Println(len(sch_prescriptions))
  1567. if index >= 0 && index < len(sch_prescriptions) {
  1568. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1569. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1570. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1571. if one.ID > 0 {
  1572. var hpt models.HisPrescriptionProjectTemplate
  1573. hpt.Type = 3
  1574. hpt.ID = 0
  1575. hpt.PatientId = sch_prescriptions[index].PatientId
  1576. hpt.Status = 1
  1577. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1578. hpt.Mtime = time.Now().Unix()
  1579. hpt.Ctime = time.Now().Unix()
  1580. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1581. hpt.Count = "1"
  1582. hpt.Price = one.RetailPrice
  1583. hpt.ProjectId = one.ID
  1584. hpt.FeedetlSn = ""
  1585. hpt.PrescriptionId = sch_prescriptions[index].ID
  1586. hpt.Unit = one.PackingUnit
  1587. hpt.Day = "1"
  1588. hpt.SingleDose = "1"
  1589. hpt.GoodInfo = one
  1590. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1591. }
  1592. if two.ID > 0 {
  1593. var hpt models.HisPrescriptionProjectTemplate
  1594. hpt.Type = 3
  1595. hpt.ID = 0
  1596. hpt.PatientId = sch_prescriptions[index].PatientId
  1597. hpt.Status = 1
  1598. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1599. hpt.Mtime = time.Now().Unix()
  1600. hpt.Ctime = time.Now().Unix()
  1601. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1602. hpt.Count = "1"
  1603. hpt.Price = two.RetailPrice
  1604. hpt.ProjectId = two.ID
  1605. hpt.FeedetlSn = ""
  1606. hpt.PrescriptionId = sch_prescriptions[index].ID
  1607. hpt.Unit = two.PackingUnit
  1608. hpt.Day = "1"
  1609. hpt.SingleDose = "1"
  1610. hpt.GoodInfo = two
  1611. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1612. }
  1613. //if three.ID > 0 {
  1614. // var hpt models.HisPrescriptionProjectTemplate
  1615. // hpt.Type = 3
  1616. // hpt.ID = 0
  1617. // hpt.PatientId = sch_prescriptions[index].PatientId
  1618. // hpt.Status = 1
  1619. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1620. // hpt.Mtime = time.Now().Unix()
  1621. // hpt.Ctime = time.Now().Unix()
  1622. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1623. // hpt.Count = "1"
  1624. // hpt.Price = three.RetailPrice
  1625. // hpt.ProjectId = three.ID
  1626. // hpt.FeedetlSn = ""
  1627. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1628. // hpt.Unit = three.PackingUnit
  1629. // hpt.Day = "1"
  1630. // hpt.SingleDose = "1"
  1631. // hpt.GoodInfo = three
  1632. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1633. //}
  1634. fmt.Println(sch_prescriptions)
  1635. }
  1636. } else {
  1637. if len(last_prescriptions) > 0 {
  1638. var index = 0
  1639. for subindex, item := range last_prescriptions {
  1640. if item.Type == 2 {
  1641. index = subindex
  1642. }
  1643. }
  1644. if index >= 0 && index < len(last_prescriptions) {
  1645. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1646. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1647. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1648. if one.ID > 0 {
  1649. var hpt models.HisPrescriptionProject
  1650. hpt.Type = 3
  1651. hpt.ID = 0
  1652. hpt.PatientId = last_prescriptions[index].PatientId
  1653. hpt.Status = 1
  1654. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1655. hpt.Mtime = time.Now().Unix()
  1656. hpt.Ctime = time.Now().Unix()
  1657. hpt.RecordDate = last_prescriptions[index].RecordDate
  1658. hpt.Count = "1"
  1659. hpt.Price = one.RetailPrice
  1660. hpt.ProjectId = one.ID
  1661. hpt.FeedetlSn = ""
  1662. hpt.PrescriptionId = last_prescriptions[index].ID
  1663. hpt.Unit = one.PackingUnit
  1664. hpt.Day = "1"
  1665. hpt.SingleDose = "1"
  1666. hpt.GoodInfo = one
  1667. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1668. }
  1669. if two.ID > 0 {
  1670. var hpt models.HisPrescriptionProject
  1671. hpt.Type = 3
  1672. hpt.ID = 0
  1673. hpt.PatientId = last_prescriptions[index].PatientId
  1674. hpt.Status = 1
  1675. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1676. hpt.Mtime = time.Now().Unix()
  1677. hpt.Ctime = time.Now().Unix()
  1678. hpt.RecordDate = last_prescriptions[index].RecordDate
  1679. hpt.Count = "1"
  1680. hpt.Price = two.RetailPrice
  1681. hpt.ProjectId = two.ID
  1682. hpt.FeedetlSn = ""
  1683. hpt.PrescriptionId = last_prescriptions[index].ID
  1684. hpt.Unit = two.PackingUnit
  1685. hpt.Day = "1"
  1686. hpt.SingleDose = "1"
  1687. hpt.GoodInfo = two
  1688. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1689. }
  1690. //if three.ID > 0 {
  1691. // var hpt models.HisPrescriptionProject
  1692. // hpt.Type = 3
  1693. // hpt.ID = 0
  1694. // hpt.PatientId = last_prescriptions[index].PatientId
  1695. // hpt.Status = 1
  1696. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1697. // hpt.Mtime = time.Now().Unix()
  1698. // hpt.Ctime = time.Now().Unix()
  1699. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1700. // hpt.Count = "1"
  1701. // hpt.Price = three.RetailPrice
  1702. // hpt.ProjectId = three.ID
  1703. // hpt.FeedetlSn = ""
  1704. // hpt.PrescriptionId = last_prescriptions[index].ID
  1705. // hpt.Unit = three.PackingUnit
  1706. // hpt.Day = "1"
  1707. // hpt.SingleDose = "1"
  1708. // hpt.GoodInfo = three
  1709. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1710. //}
  1711. }
  1712. }
  1713. }
  1714. }
  1715. c.ServeSuccessJSON(map[string]interface{}{
  1716. "his_info": his_patient_info,
  1717. "xt_info": xt_patient_info,
  1718. "prescription": prescriptions,
  1719. "case_history": case_history,
  1720. "info": patientPrescriptionInfo,
  1721. //"month_prescriptions": monthPrescriptions,
  1722. "order": order,
  1723. "doctors": doctors,
  1724. "department": department,
  1725. "sch_prescriptions": sch_prescriptions,
  1726. "last_prescriptions": last_prescriptions,
  1727. "schedule": sch,
  1728. "count": count,
  1729. "drugStockConfig": drugStockConfig,
  1730. "last_info": lastPatientPrescriptionInfo,
  1731. "befor": beforThrity,
  1732. "LastCaseHistory": LastCaseHistory,
  1733. "prescriptionInfo": prescriptionInfo,
  1734. })
  1735. return
  1736. }
  1737. func (c *HisApiController) GetHisPrescriptionConfig() {
  1738. adminInfo := c.GetAdminUserInfo()
  1739. //获取医嘱模版
  1740. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1741. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1742. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1743. //获取所有基础药
  1744. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1745. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1746. if config.ID > 0 && config.IsOpen == 1 {
  1747. for _, item := range drugs {
  1748. var index = 0
  1749. for _, subItem := range item.OtherDrugWarehouseInfo {
  1750. if index == 0 {
  1751. index = index + 1
  1752. if subItem.RetailPrice > 0 {
  1753. item.MinPrice = subItem.RetailPrice
  1754. }
  1755. }
  1756. }
  1757. }
  1758. }
  1759. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1760. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1761. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1762. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1763. //获取所有科室信息
  1764. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1765. //获取诊断信息
  1766. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1767. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1768. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1769. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1770. //获取是否开启保存耗材出库的开关
  1771. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1772. c.ServeSuccessJSON(map[string]interface{}{
  1773. "drugs": drugs,
  1774. "advices_template": advices,
  1775. "drugways": drugways,
  1776. "efs": efs,
  1777. "doctors": doctors,
  1778. "department": department,
  1779. "sick": sick,
  1780. "additions": additions,
  1781. "diagnose": diagnose,
  1782. "manufacturers": manufacturers,
  1783. "goodOutOpen": goodOutOpen,
  1784. "patientDiagnose": patientDiagnose,
  1785. })
  1786. }
  1787. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1788. //获取所有基础药
  1789. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1790. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1791. if config.ID > 0 && config.IsOpen == 1 {
  1792. for _, item := range drugs {
  1793. var index = 0
  1794. for _, subItem := range item.OtherDrugWarehouseInfo {
  1795. if index == 0 {
  1796. index = index + 1
  1797. if subItem.RetailPrice > 0 {
  1798. item.MinPrice = subItem.RetailPrice
  1799. }
  1800. }
  1801. }
  1802. }
  1803. }
  1804. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1805. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1806. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1807. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1808. //获取所有科室信息
  1809. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1810. //获取诊断信息
  1811. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1812. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1813. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1814. //获取是否开启保存耗材出库的开关
  1815. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1816. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1817. c.ServeSuccessJSON(map[string]interface{}{
  1818. "drugs": drugs,
  1819. "advices_template": advices,
  1820. "drugways": drugways,
  1821. "efs": efs,
  1822. "doctors": doctors,
  1823. "department": department,
  1824. "sick": sick,
  1825. "additions": additions,
  1826. "diagnose": diagnose,
  1827. "manufacturers": manufacturers,
  1828. "goodOutOpen": goodOutOpen,
  1829. "patientDiagnose": patientDiagnose,
  1830. })
  1831. }
  1832. }
  1833. func (c *HisApiController) CreateHisPrescription() {
  1834. record_date := c.GetString("record_date")
  1835. patient_id, _ := c.GetInt64("patient_id")
  1836. reg_type, _ := c.GetInt64("reg_type")
  1837. diagnose := c.GetString("diagnose")
  1838. sick_type, _ := c.GetInt64("sick_type")
  1839. sick_history := c.GetString("sick_history")
  1840. doctor_id, _ := c.GetInt64("doctor", 0)
  1841. department, _ := c.GetInt64("department", 0)
  1842. his_patient_id, _ := c.GetInt64("his_patient_id")
  1843. p_type, _ := c.GetInt64("p_type")
  1844. patient_diagnose := c.GetString("patient_diagnose")
  1845. dataBody := make(map[string]interface{}, 0)
  1846. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1847. if err != nil {
  1848. utils.ErrorLog(err.Error())
  1849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1850. return
  1851. }
  1852. //edit, src := GetCompareData(dataBody)
  1853. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1854. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1855. //fmt.Println(drugResult)
  1856. //fmt.Println(goodResult)
  1857. timeLayout := "2006-01-02"
  1858. loc, _ := time.LoadLocation("Local")
  1859. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1860. if err != nil {
  1861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1862. return
  1863. }
  1864. adminInfo := c.GetAdminUserInfo()
  1865. recordDateTime := theTime.Unix()
  1866. //查询默认出库仓库库存
  1867. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1868. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1869. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1870. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1871. if len(lists) == 1 {
  1872. his_patient_id = lists[0].ID
  1873. }
  1874. }
  1875. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1876. //自动出库的开关开启
  1877. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1878. //自动出库
  1879. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1880. //耗材保存处方出库
  1881. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1882. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1883. //已发药和已收费限制逻辑
  1884. isMidicine := false
  1885. isCharge := false
  1886. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1887. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1888. if len(prescriptions) > 0 {
  1889. for _, item := range prescriptions {
  1890. items := item.(map[string]interface{})
  1891. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1892. utils.ErrorLog("id")
  1893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1894. return
  1895. }
  1896. id := int64(items["id"].(float64))
  1897. if id > 0 {
  1898. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1899. if err != nil {
  1900. if new_prescription.OrderStatus == 4 {
  1901. isCharge = true
  1902. }
  1903. }
  1904. }
  1905. }
  1906. }
  1907. }
  1908. if isMidicine == true {
  1909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1910. return
  1911. }
  1912. if isCharge == true {
  1913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1914. return
  1915. }
  1916. // 开始主事务
  1917. db := service.XTWriteDB()
  1918. tx := db.Begin()
  1919. // 在函数结束时处理事务回滚
  1920. defer func() {
  1921. if r := recover(); r != nil {
  1922. tx.Rollback()
  1923. }
  1924. }()
  1925. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1926. //药品发药出库
  1927. if pharmacyConfig.IsOpen == 1 {
  1928. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1929. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1930. if len(prescriptions) > 0 {
  1931. for _, item := range prescriptions {
  1932. items := item.(map[string]interface{})
  1933. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1934. advices := items["advices"].([]interface{})
  1935. if len(advices) > 0 {
  1936. for _, advice := range advices {
  1937. var drug_id int64
  1938. var prescribing_number float64
  1939. var prescribingNumberUnit string
  1940. var adviceId int64
  1941. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1942. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1943. }
  1944. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1945. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1946. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1947. }
  1948. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1949. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1950. }
  1951. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1952. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1953. }
  1954. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1955. if drug.ID == 0 {
  1956. tx.Rollback()
  1957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1958. return
  1959. }
  1960. //查询药品的所有库存
  1961. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1962. var total_count int64
  1963. for _, it := range list {
  1964. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1965. }
  1966. totals := strconv.FormatInt(total_count, 10)
  1967. //查询该药品是否存在开药记录
  1968. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1969. //新增处方盘点库存是否充足
  1970. if advicelist.ID == 0 {
  1971. all_count, _ := strconv.ParseFloat(totals, 64)
  1972. if prescribingNumberUnit == drug.MinUnit {
  1973. if drug.IsUse != 1 {
  1974. if drug.IsProject == 0 || drug.IsProject == 2 {
  1975. if all_count == 0 {
  1976. tx.Rollback()
  1977. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1978. return
  1979. }
  1980. if prescribing_number > all_count {
  1981. tx.Rollback()
  1982. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1983. return
  1984. }
  1985. }
  1986. }
  1987. }
  1988. if prescribingNumberUnit == drug.MaxUnit {
  1989. num := prescribing_number * float64(drug.MinNumber)
  1990. if drug.IsUse != 1 {
  1991. if drug.IsProject == 0 || drug.IsProject == 2 {
  1992. if all_count == 0 {
  1993. tx.Rollback()
  1994. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1995. return
  1996. }
  1997. if num > all_count {
  1998. tx.Rollback()
  1999. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2000. return
  2001. }
  2002. }
  2003. }
  2004. }
  2005. }
  2006. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2007. //不使用保存处方出库
  2008. if drugOutConfig.IsOpen != 1 {
  2009. //修改处方
  2010. for _, advice := range advices {
  2011. var drug_id int64
  2012. var prescribing_number float64
  2013. var prescribingNumberUnit string
  2014. var prescribingNumber string
  2015. var adviceId int64
  2016. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2017. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2018. }
  2019. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2020. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2021. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2022. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2023. }
  2024. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2025. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2026. }
  2027. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2028. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2029. }
  2030. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2031. if drug.ID == 0 {
  2032. tx.Rollback()
  2033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2034. return
  2035. }
  2036. //查询药品的所有库存
  2037. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2038. var total_count int64
  2039. for _, it := range list {
  2040. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2041. }
  2042. totals := strconv.FormatInt(total_count, 10)
  2043. //查询该药品是否存在开药记录
  2044. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2045. //新增处方
  2046. if advicelist.ID == 0 {
  2047. all_count, _ := strconv.ParseFloat(totals, 64)
  2048. if prescribingNumberUnit == drug.MinUnit {
  2049. if drug.IsUse != 1 {
  2050. if drug.IsProject == 0 || drug.IsProject == 2 {
  2051. if all_count == 0 {
  2052. tx.Rollback()
  2053. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2054. return
  2055. }
  2056. if prescribing_number > all_count {
  2057. tx.Rollback()
  2058. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2059. return
  2060. }
  2061. }
  2062. }
  2063. } else {
  2064. if prescribingNumberUnit == drug.MaxUnit {
  2065. num := prescribing_number * float64(drug.MinNumber)
  2066. if drug.IsUse != 1 {
  2067. if drug.IsProject == 0 || drug.IsProject == 2 {
  2068. if all_count == 0 {
  2069. tx.Rollback()
  2070. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2071. return
  2072. }
  2073. if num > all_count {
  2074. tx.Rollback()
  2075. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2076. return
  2077. }
  2078. }
  2079. }
  2080. }
  2081. }
  2082. }
  2083. //修改处方
  2084. if advicelist.ID > 0 {
  2085. var device_number int64
  2086. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2087. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2088. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2089. device_number = prescribingNumberInt * drug.MinNumber
  2090. }
  2091. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2092. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2093. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2094. device_number = prescribingNumberInt
  2095. }
  2096. var number_count int64
  2097. if prescribingNumberUnit == drug.MaxUnit {
  2098. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2099. number_count = prescribingNumberInt * drug.MinNumber
  2100. }
  2101. if prescribingNumberUnit == drug.MinUnit {
  2102. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2103. number_count = prescribingNumberInt
  2104. }
  2105. //如果修改的数量大于之前修改的数量
  2106. if (number_count - device_number) > 0 {
  2107. //如果修改的差数量 大于库存数量
  2108. if drug.IsUse != 1 {
  2109. if (number_count - device_number) > total_count {
  2110. tx.Rollback()
  2111. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2112. return
  2113. }
  2114. }
  2115. }
  2116. }
  2117. }
  2118. }
  2119. }
  2120. }
  2121. }
  2122. }
  2123. }
  2124. }
  2125. }
  2126. //已发药和已收费限制逻辑
  2127. //执行出库的逻辑
  2128. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2129. //校验库存总量
  2130. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2131. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2132. if len(prescriptions) > 0 {
  2133. for _, item := range prescriptions {
  2134. items := item.(map[string]interface{})
  2135. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2136. advices := items["advices"].([]interface{})
  2137. if len(advices) > 0 {
  2138. for _, advice := range advices {
  2139. var drug_id int64
  2140. var prescribing_number float64
  2141. var prescribingNumberUnit string
  2142. var adviceId int64
  2143. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2144. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2145. }
  2146. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2147. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2148. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2149. }
  2150. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2151. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2152. }
  2153. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2154. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2155. }
  2156. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2157. if drug.ID == 0 {
  2158. tx.Rollback()
  2159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2160. return
  2161. }
  2162. //查询药品的所有库存
  2163. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2164. var total_count int64
  2165. for _, it := range list {
  2166. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2167. }
  2168. totals := strconv.FormatInt(total_count, 10)
  2169. //查询该药品是否存在开药记录
  2170. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2171. //查询最新批次库存
  2172. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2173. var batch_number_count int64
  2174. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2175. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2176. //新增处方
  2177. if advicelist.ID == 0 {
  2178. all_count, _ := strconv.ParseFloat(totals, 64)
  2179. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2180. if prescribingNumberUnit == drug.MinUnit {
  2181. if drug.IsUse != 1 {
  2182. if drug.IsProject == 0 || drug.IsProject == 2 {
  2183. if all_count == 0 {
  2184. tx.Rollback()
  2185. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2186. return
  2187. }
  2188. if prescribing_number > all_count {
  2189. tx.Rollback()
  2190. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2191. return
  2192. }
  2193. }
  2194. if adminInfo.CurrentOrgId == 10215 {
  2195. if prescribing_number > batch_number_all_count {
  2196. tx.Rollback()
  2197. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2198. return
  2199. }
  2200. }
  2201. }
  2202. }
  2203. if prescribingNumberUnit == drug.MaxUnit {
  2204. num := prescribing_number * float64(drug.MinNumber)
  2205. if drug.IsUse != 1 {
  2206. if drug.IsProject == 0 || drug.IsProject == 2 {
  2207. if all_count == 0 {
  2208. tx.Rollback()
  2209. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2210. return
  2211. }
  2212. if num > all_count {
  2213. tx.Rollback()
  2214. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2215. return
  2216. }
  2217. }
  2218. if adminInfo.CurrentOrgId == 10215 {
  2219. if num > batch_number_all_count {
  2220. tx.Rollback()
  2221. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2222. return
  2223. }
  2224. }
  2225. }
  2226. }
  2227. }
  2228. //不是保存处方出库
  2229. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2230. if drugOutConfig.IsOpen != 1 {
  2231. //修改处方
  2232. for _, advice := range advices {
  2233. var drug_id int64
  2234. var prescribing_number float64
  2235. var prescribingNumberUnit string
  2236. var prescribingNumber string
  2237. var adviceId int64
  2238. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2239. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2240. }
  2241. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2242. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2243. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2244. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2245. }
  2246. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2247. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2248. }
  2249. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2250. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2251. }
  2252. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2253. if drug.ID == 0 {
  2254. tx.Rollback()
  2255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2256. return
  2257. }
  2258. //查询药品的所有库存
  2259. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2260. var total_count int64
  2261. for _, it := range list {
  2262. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2263. }
  2264. totals := strconv.FormatInt(total_count, 10)
  2265. //查询该药品是否存在开药记录
  2266. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2267. //新增处方
  2268. if advicelist.ID == 0 {
  2269. //查询最新批次库存
  2270. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2271. var batch_number_count int64
  2272. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2273. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2274. all_count, _ := strconv.ParseFloat(totals, 64)
  2275. if all_count == 0 {
  2276. tx.Rollback()
  2277. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2278. return
  2279. }
  2280. if prescribingNumberUnit == drug.MinUnit {
  2281. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2282. if drug.IsUse != 1 {
  2283. if drug.IsProject == 0 || drug.IsProject == 2 {
  2284. if all_count == 0 {
  2285. tx.Rollback()
  2286. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2287. return
  2288. }
  2289. if prescribing_number > all_count {
  2290. tx.Rollback()
  2291. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2292. return
  2293. }
  2294. }
  2295. if adminInfo.CurrentOrgId == 10215 {
  2296. if prescribing_number > batch_number_all_count {
  2297. tx.Rollback()
  2298. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2299. return
  2300. }
  2301. }
  2302. }
  2303. } else {
  2304. if prescribingNumberUnit == drug.MaxUnit {
  2305. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2306. num := prescribing_number * float64(drug.MinNumber)
  2307. if drug.IsUse != 1 {
  2308. if drug.IsProject == 0 || drug.IsProject == 2 {
  2309. if all_count == 0 {
  2310. tx.Rollback()
  2311. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2312. return
  2313. }
  2314. if num > all_count {
  2315. tx.Rollback()
  2316. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2317. return
  2318. }
  2319. }
  2320. if adminInfo.CurrentOrgId == 10215 {
  2321. if prescribing_number > batch_number_all_count {
  2322. tx.Rollback()
  2323. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2324. return
  2325. }
  2326. }
  2327. }
  2328. }
  2329. }
  2330. }
  2331. //修改处方
  2332. if advicelist.ID > 0 {
  2333. //查询最新批次库存
  2334. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2335. var batch_number_count int64
  2336. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2337. var device_number int64
  2338. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2339. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2340. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2341. device_number = prescribingNumberInt * drug.MinNumber
  2342. }
  2343. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2344. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2345. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2346. device_number = prescribingNumberInt
  2347. //回退库存
  2348. }
  2349. var number_count int64
  2350. if prescribingNumberUnit == drug.MaxUnit {
  2351. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2352. number_count = prescribingNumberInt * drug.MinNumber
  2353. //回退库存
  2354. }
  2355. if prescribingNumberUnit == drug.MinUnit {
  2356. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2357. number_count = prescribingNumberInt
  2358. //回退库存
  2359. }
  2360. //如果修改的数量大于之前修改的数量
  2361. if (number_count - device_number) > 0 {
  2362. //如果修改的差数量 大于库存数量
  2363. if drug.IsUse != 1 {
  2364. if drug.IsProject == 0 || drug.IsProject == 2 {
  2365. if total_count == 0 {
  2366. tx.Rollback()
  2367. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2368. return
  2369. }
  2370. if (number_count - device_number) > total_count {
  2371. tx.Rollback()
  2372. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2373. return
  2374. }
  2375. if (number_count - device_number) > batch_number_count {
  2376. tx.Rollback()
  2377. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2378. return
  2379. }
  2380. }
  2381. if adminInfo.CurrentOrgId == 10215 {
  2382. // 查询该药品最后一次出库记录
  2383. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2384. var out_count int64
  2385. var in_count int64
  2386. var stock_max_number int64
  2387. var stock_min_number int64
  2388. for _, it := range outInfo {
  2389. if it.CountUnit == drug.MaxUnit {
  2390. it.Count = it.Count * drug.MinNumber
  2391. }
  2392. out_count += it.Count
  2393. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2394. stock_max_number = warehouseInfoList.StockMaxNumber
  2395. stock_min_number = warehouseInfoList.StockMinNumber
  2396. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2397. }
  2398. if out_count > 0 {
  2399. if (number_count - device_number) > in_count {
  2400. tx.Rollback()
  2401. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2402. return
  2403. }
  2404. }
  2405. // 未出库
  2406. if out_count == 0 {
  2407. var sum_in_count int64
  2408. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2409. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2410. //如果修改的数量大于有库存的第一个批次
  2411. if number_count > sum_in_count {
  2412. tx.Rollback()
  2413. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2414. return
  2415. }
  2416. }
  2417. }
  2418. }
  2419. }
  2420. //药品发药
  2421. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2422. //不使用药品发药的功能
  2423. //if pharmacyConfig.IsOpen != 1 {
  2424. // if device_number != number_count {
  2425. //
  2426. // //查询该药品的出库记录
  2427. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2428. // if len(outListExport) > 0 {
  2429. // //
  2430. // for _, item := range outListExport {
  2431. // //回退库存
  2432. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2433. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2434. // }
  2435. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2436. // var stock_max_number int64
  2437. // var stock_min_number int64
  2438. //
  2439. // if number_count >= drug.MinNumber {
  2440. //
  2441. // stock_max_number = device_number / drug.MinNumber
  2442. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2443. //
  2444. // stock_min_number = device_number % drug.MinNumber
  2445. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2446. //
  2447. // } else {
  2448. //
  2449. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2450. //
  2451. // }
  2452. // }
  2453. //
  2454. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2455. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2456. // }
  2457. // }
  2458. // }
  2459. //
  2460. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2461. // var sum_count int64
  2462. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2463. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2464. // for _, its := range stockInfo {
  2465. // if its.MaxUnit == drug.MaxUnit {
  2466. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2467. // }
  2468. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2469. // }
  2470. // //更新字典里面的库存
  2471. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2472. //
  2473. // //剩余库存
  2474. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2475. //
  2476. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2477. // //减少出库数量
  2478. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2479. //
  2480. // }
  2481. //}
  2482. }
  2483. }
  2484. }
  2485. //保存处方开药
  2486. if drugOutConfig.IsOpen == 1 {
  2487. //修改处方
  2488. for _, advice := range advices {
  2489. var drug_id int64
  2490. var prescribing_number float64
  2491. var prescribingNumberUnit string
  2492. var prescribingNumber string
  2493. var adviceId int64
  2494. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2495. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2496. }
  2497. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2498. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2499. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2500. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2501. }
  2502. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2503. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2504. }
  2505. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2506. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2507. }
  2508. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2509. if drug.ID == 0 {
  2510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2511. return
  2512. }
  2513. //查询药品的所有库存
  2514. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2515. var total_count int64
  2516. for _, it := range list {
  2517. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2518. }
  2519. totals := strconv.FormatInt(total_count, 10)
  2520. //查询该药品是否存在开药记录
  2521. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2522. //新增处方
  2523. if advicelist.ID == 0 {
  2524. //查询最新批次库存
  2525. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2526. var batch_number_count int64
  2527. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2528. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2529. all_count, _ := strconv.ParseFloat(totals, 64)
  2530. if prescribingNumberUnit == drug.MinUnit {
  2531. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2532. if drug.IsUse != 1 {
  2533. if drug.IsProject == 0 || drug.IsProject == 2 {
  2534. if all_count == 0 {
  2535. tx.Rollback()
  2536. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2537. return
  2538. }
  2539. if prescribing_number > all_count {
  2540. tx.Rollback()
  2541. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2542. return
  2543. }
  2544. }
  2545. if adminInfo.CurrentOrgId == 10215 {
  2546. if prescribing_number > batch_number_all_count {
  2547. tx.Rollback()
  2548. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2549. return
  2550. }
  2551. }
  2552. }
  2553. } else {
  2554. if prescribingNumberUnit == drug.MaxUnit {
  2555. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2556. num := prescribing_number * float64(drug.MinNumber)
  2557. if drug.IsUse != 1 {
  2558. if drug.IsProject == 0 || drug.IsProject == 2 {
  2559. if all_count == 0 {
  2560. tx.Rollback()
  2561. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2562. return
  2563. }
  2564. if num > all_count {
  2565. tx.Rollback()
  2566. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2567. return
  2568. }
  2569. }
  2570. if adminInfo.CurrentOrgId == 10215 {
  2571. if prescribing_number > batch_number_all_count {
  2572. tx.Rollback()
  2573. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2574. return
  2575. }
  2576. }
  2577. }
  2578. }
  2579. }
  2580. }
  2581. //修改处方
  2582. if advicelist.ID > 0 {
  2583. //查询最新批次库存
  2584. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2585. var batch_number_count int64
  2586. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2587. var device_number int64
  2588. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2589. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2590. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2591. device_number = prescribingNumberInt * drug.MinNumber
  2592. }
  2593. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2594. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2595. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2596. device_number = prescribingNumberInt
  2597. }
  2598. var number_count int64
  2599. if prescribingNumberUnit == drug.MaxUnit {
  2600. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2601. number_count = prescribingNumberInt * drug.MinNumber
  2602. }
  2603. if prescribingNumberUnit == drug.MinUnit {
  2604. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2605. number_count = prescribingNumberInt
  2606. }
  2607. //如果修改的数量大于之前修改的数量
  2608. if (number_count - device_number) > 0 {
  2609. //如果修改的差数量 大于库存数量
  2610. if drug.IsUse != 1 {
  2611. if drug.IsProject == 0 || drug.IsProject == 2 {
  2612. if total_count == 0 {
  2613. tx.Rollback()
  2614. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2615. return
  2616. }
  2617. if (number_count - device_number) > total_count {
  2618. tx.Rollback()
  2619. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2620. return
  2621. }
  2622. }
  2623. if adminInfo.CurrentOrgId == 10215 {
  2624. if (number_count - device_number) > batch_number_count {
  2625. tx.Rollback()
  2626. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2627. return
  2628. }
  2629. }
  2630. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2631. //查询历史出库数据总批次
  2632. // 查询该药品最后一次出库记录
  2633. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2634. var out_count int64
  2635. var in_count int64
  2636. var stock_max_number int64
  2637. var stock_min_number int64
  2638. for _, it := range outInfo {
  2639. if it.CountUnit == drug.MaxUnit {
  2640. it.Count = it.Count * drug.MinNumber
  2641. }
  2642. out_count += it.Count
  2643. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2644. stock_max_number = warehouseInfoList.StockMaxNumber
  2645. stock_min_number = warehouseInfoList.StockMinNumber
  2646. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2647. }
  2648. if out_count > 0 {
  2649. if (number_count - device_number) > in_count {
  2650. tx.Rollback()
  2651. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2652. return
  2653. }
  2654. }
  2655. // 未出库
  2656. if out_count == 0 {
  2657. var sum_in_count int64
  2658. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2659. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2660. if sum_in_count == 0 {
  2661. tx.Rollback()
  2662. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2663. return
  2664. }
  2665. //如果修改的数量大于有库存的第一个批次
  2666. if number_count > sum_in_count {
  2667. tx.Rollback()
  2668. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2669. return
  2670. }
  2671. }
  2672. }
  2673. }
  2674. }
  2675. }
  2676. }
  2677. }
  2678. }
  2679. }
  2680. }
  2681. }
  2682. }
  2683. }
  2684. }
  2685. //校验耗材库存
  2686. if goodOutConfig.IsOpen == 1 {
  2687. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2688. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2689. if len(prescriptions) > 0 {
  2690. for _, item := range prescriptions {
  2691. items := item.(map[string]interface{})
  2692. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2693. projects := items["project"].([]interface{})
  2694. if len(projects) > 0 {
  2695. for _, project := range projects {
  2696. var project_id int64
  2697. var project_type int64
  2698. var totals float64
  2699. var project_name string
  2700. var parsetotal int64
  2701. var id int64
  2702. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2703. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2704. }
  2705. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2706. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2707. }
  2708. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2709. total, _ := project.(map[string]interface{})["total"].(string)
  2710. totals, _ = strconv.ParseFloat(total, 64)
  2711. }
  2712. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2713. project_name = project.(map[string]interface{})["project_name"].(string)
  2714. }
  2715. if project_type == 3 {
  2716. //查找该耗材的出库记录
  2717. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2718. if len(goodWarehouseInfo) == 0 {
  2719. //查询耗材库存
  2720. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2721. var stock_count int64
  2722. for _, it := range list {
  2723. stock_count += it.StockCount
  2724. }
  2725. stock_counts := strconv.FormatInt(stock_count, 10)
  2726. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2727. if stock_total_count == 0 {
  2728. tx.Rollback()
  2729. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2730. return
  2731. }
  2732. if totals > stock_total_count {
  2733. tx.Rollback()
  2734. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2735. return
  2736. }
  2737. }
  2738. if len(goodWarehouseInfo) > 0 {
  2739. //查询该患者耗材的历史数据
  2740. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2741. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2742. //数量发生改变
  2743. if parsetotal != count {
  2744. //如果现在的数量大于历史数量,就要看库存是否足够
  2745. if parsetotal > count {
  2746. //查询耗材所有库存
  2747. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2748. var stock_count int64
  2749. for _, it := range list {
  2750. stock_count += it.StockCount
  2751. }
  2752. //库存不足
  2753. if stock_count == 0 {
  2754. tx.Rollback()
  2755. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2756. return
  2757. }
  2758. if (parsetotal - count) > stock_count {
  2759. tx.Rollback()
  2760. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2761. return
  2762. }
  2763. }
  2764. }
  2765. }
  2766. }
  2767. }
  2768. }
  2769. }
  2770. }
  2771. }
  2772. }
  2773. }
  2774. //不使用耗材保存处方出库
  2775. if goodOutConfig.IsOpen != 1 {
  2776. if stockConfig.IsOpen == 1 {
  2777. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2778. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2779. if len(prescriptions) > 0 {
  2780. for _, item := range prescriptions {
  2781. items := item.(map[string]interface{})
  2782. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2783. projects := items["project"].([]interface{})
  2784. if len(projects) > 0 {
  2785. for _, project := range projects {
  2786. var project_id int64
  2787. var project_type int64
  2788. var totals float64
  2789. var project_name string
  2790. var parsetotal int64
  2791. var id int64
  2792. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2793. id = int64(project.(map[string]interface{})["id"].(float64))
  2794. }
  2795. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2796. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2797. }
  2798. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2799. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2800. }
  2801. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2802. total, _ := project.(map[string]interface{})["total"].(string)
  2803. totals, _ = strconv.ParseFloat(total, 64)
  2804. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2805. }
  2806. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2807. project_name = project.(map[string]interface{})["project_name"].(string)
  2808. }
  2809. if project_type == 3 {
  2810. //查找该耗材的出库记录
  2811. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2812. //没有出库记录
  2813. if len(goodWarehouseInfo) == 0 {
  2814. //查询耗材库存
  2815. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2816. var stock_count int64
  2817. for _, it := range list {
  2818. stock_count += it.StockCount
  2819. }
  2820. stock_counts := strconv.FormatInt(stock_count, 10)
  2821. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2822. if stock_total_count == 0 {
  2823. tx.Rollback()
  2824. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2825. return
  2826. }
  2827. if totals > stock_total_count {
  2828. tx.Rollback()
  2829. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2830. return
  2831. }
  2832. //查找今日该患者已经出库的所有耗材
  2833. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2834. for _, item := range goodList {
  2835. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2836. var flush_count int64
  2837. for _, it := range goodListSix {
  2838. flush_count += it.StockCount
  2839. }
  2840. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2841. creater := adminInfo.AdminUser.Id
  2842. if errs != nil {
  2843. goodErrcode := models.XtGoodErrcode{
  2844. UserOrgId: item.OrgId,
  2845. Errcode: "手动出库更新剩余出库失败",
  2846. GoodId: item.GoodId,
  2847. Status: 1,
  2848. Ctime: time.Now().Unix(),
  2849. Mtime: 0,
  2850. Count: 0,
  2851. StockCount: 0,
  2852. Creater: creater,
  2853. BatchNumberId: 0,
  2854. WarehouseOutId: 0,
  2855. }
  2856. service.CreateGoodErrcode(goodErrcode)
  2857. }
  2858. }
  2859. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2860. }
  2861. //有出库记录
  2862. if len(goodWarehouseInfo) > 0 {
  2863. //查询该患者耗材的历史数据
  2864. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2865. fmt.Println("ordProject-----------------------", ordProject.ProjectId)
  2866. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2867. //数量发生改变
  2868. if parsetotal != count {
  2869. //查找今日该患者已经出库的所有耗材
  2870. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2871. for _, item := range goodList {
  2872. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2873. var flush_count int64
  2874. for _, it := range goodListSix {
  2875. flush_count += it.StockCount
  2876. }
  2877. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2878. //减少出库数量
  2879. creater := adminInfo.AdminUser.Id
  2880. if errs != nil {
  2881. goodErrcode := models.XtGoodErrcode{
  2882. UserOrgId: item.OrgId,
  2883. Errcode: "手动出库更新剩余出库失败",
  2884. GoodId: item.GoodId,
  2885. Status: 1,
  2886. Ctime: time.Now().Unix(),
  2887. Mtime: 0,
  2888. Count: 0,
  2889. StockCount: 0,
  2890. Creater: creater,
  2891. BatchNumberId: 0,
  2892. WarehouseOutId: 0,
  2893. }
  2894. service.CreateGoodErrcode(goodErrcode)
  2895. }
  2896. //查询默认仓库
  2897. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2898. var total_count int64
  2899. for _, it := range stockList {
  2900. total_count += it.StockCount
  2901. }
  2902. //基础库插入数据
  2903. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2904. }
  2905. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2906. }
  2907. }
  2908. }
  2909. }
  2910. }
  2911. }
  2912. }
  2913. }
  2914. }
  2915. }
  2916. }
  2917. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2918. var hpInfo models.HisPrescriptionInfo
  2919. if info.ID == 0 {
  2920. var randNum int
  2921. randNum = rand.Intn(10000) + 1000
  2922. timestamp := time.Now().Unix()
  2923. tempTime := time.Unix(timestamp, 0)
  2924. timeFormat := tempTime.Format("20060102150405")
  2925. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2926. hpInfo = models.HisPrescriptionInfo{
  2927. HisPatientId: his_patient_id,
  2928. UserOrgId: adminInfo.CurrentOrgId,
  2929. RecordDate: theTime.Unix(),
  2930. PatientId: patient_id,
  2931. Status: 1,
  2932. Ctime: time.Now().Unix(),
  2933. Mtime: time.Now().Unix(),
  2934. Creator: adminInfo.AdminUser.Id,
  2935. Modifier: adminInfo.AdminUser.Id,
  2936. Diagnosis: diagnose,
  2937. SickHistory: sick_history,
  2938. Departments: department,
  2939. RegisterType: reg_type,
  2940. PrescriptionNumber: p_number,
  2941. PrescriptionStatus: 1,
  2942. Doctor: role.UserName,
  2943. DoctorId: doctor_id,
  2944. SickType: sick_type,
  2945. PType: p_type,
  2946. PatientDiagnosis: patient_diagnose,
  2947. }
  2948. service.SavePatientPrescriptionInfo(hpInfo)
  2949. //创建步骤表
  2950. finish := models.XtDialysisFinish{
  2951. IsFinish: 1,
  2952. UserOrgId: adminInfo.CurrentOrgId,
  2953. Status: 1,
  2954. Ctime: time.Now().Unix(),
  2955. Mtime: 0,
  2956. Module: 4,
  2957. RecordDate: theTime.Unix(),
  2958. Sourse: 1,
  2959. PatientId: patient_id,
  2960. }
  2961. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2962. if dialysisFinish.ID == 0 {
  2963. service.CreateDialysisFinish(finish)
  2964. }
  2965. redis := service.RedisClient()
  2966. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2967. redis.Set(key, "", time.Second)
  2968. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2969. redis.Set(keyOne, "", time.Second)
  2970. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2971. redis.Set(keySeven, "", time.Second)
  2972. defer redis.Close()
  2973. } else {
  2974. hpInfo = models.HisPrescriptionInfo{
  2975. ID: info.ID,
  2976. UserOrgId: adminInfo.CurrentOrgId,
  2977. RecordDate: info.RecordDate,
  2978. PatientId: info.PatientId,
  2979. Status: 1,
  2980. Ctime: info.Ctime,
  2981. Mtime: time.Now().Unix(),
  2982. Creator: info.Creator,
  2983. Modifier: adminInfo.AdminUser.Id,
  2984. Diagnosis: diagnose,
  2985. SickHistory: sick_history,
  2986. Departments: department,
  2987. RegisterType: reg_type,
  2988. PrescriptionNumber: info.PrescriptionNumber,
  2989. Doctor: role.UserName,
  2990. PrescriptionStatus: info.PrescriptionStatus,
  2991. DoctorId: doctor_id,
  2992. SickType: sick_type,
  2993. PType: info.PType,
  2994. HisPatientId: info.HisPatientId,
  2995. PatientDiagnosis: patient_diagnose,
  2996. }
  2997. service.SavePatientPrescriptionInfo(hpInfo)
  2998. //创建步骤表
  2999. finish := models.XtDialysisFinish{
  3000. IsFinish: 1,
  3001. UserOrgId: adminInfo.CurrentOrgId,
  3002. Status: 1,
  3003. Ctime: time.Now().Unix(),
  3004. Mtime: 0,
  3005. Module: 4,
  3006. RecordDate: info.RecordDate,
  3007. Sourse: 1,
  3008. PatientId: info.PatientId,
  3009. }
  3010. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  3011. if dialysisFinish.ID == 0 {
  3012. service.CreateDialysisFinish(finish)
  3013. }
  3014. redis := service.RedisClient()
  3015. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3016. redis.Set(key, "", time.Second)
  3017. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3018. redis.Set(keyOne, "", time.Second)
  3019. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3020. redis.Set(keySeven, "", time.Second)
  3021. defer redis.Close()
  3022. }
  3023. //定义切片
  3024. var adviceList []models.HisDoctorAdviceInfo
  3025. var projectList []models.HisPrescriptionProject
  3026. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10644 || adminInfo.CurrentOrgId == 10635 || adminInfo.CurrentOrgId == 10598 || adminInfo.CurrentOrgId == 10028 || adminInfo.CurrentOrgId == 10721 || adminInfo.CurrentOrgId == 10726 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10571 || adminInfo.CurrentOrgId == 10724 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10653 || adminInfo.CurrentOrgId == 10567 {
  3027. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3028. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3029. var tempPrescription *models.HisPrescription
  3030. if len(prescriptions) > 0 {
  3031. for _, item := range prescriptions {
  3032. // 开始外部循环的事务
  3033. tx := db.Begin()
  3034. // 在函数结束时处理事务回滚
  3035. defer func() {
  3036. if r := recover(); r != nil {
  3037. tx.Rollback()
  3038. }
  3039. }()
  3040. items := item.(map[string]interface{})
  3041. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3042. utils.ErrorLog("id")
  3043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3044. return
  3045. }
  3046. id := int64(items["id"].(float64))
  3047. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3048. tempPrescription = &new_prescription
  3049. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3050. utils.ErrorLog("type")
  3051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3052. return
  3053. }
  3054. types := int64(items["type"].(float64))
  3055. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3056. utils.ErrorLog("med_type")
  3057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3058. return
  3059. }
  3060. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3061. if med_type == "0" {
  3062. med_type = "14"
  3063. }
  3064. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3065. // utils.ErrorLog("diagnoses")
  3066. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3067. // return
  3068. //}
  3069. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3070. diagnoses, _ := items["diagnoses"].(string)
  3071. //if order_status == 0 {
  3072. // order_status = 1
  3073. //}
  3074. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3075. utils.ErrorLog("pre_time")
  3076. }
  3077. preTime, _ := items["pre_time"].(string)
  3078. fmt.Println("preTime", preTime)
  3079. timeLayout := "2006-01-02"
  3080. loc, _ := time.LoadLocation("Local")
  3081. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3082. //result := strings.Split(preTime, " ")
  3083. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3084. if err != nil {
  3085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3086. return
  3087. }
  3088. pTime := theTime2.Unix()
  3089. ctime := time.Now().Unix()
  3090. if tempPrescription.ID == 0 {
  3091. prescription := &models.HisPrescription{
  3092. ID: 0,
  3093. PatientId: patient_id,
  3094. UserOrgId: adminInfo.CurrentOrgId,
  3095. RecordDate: recordDateTime,
  3096. Ctime: ctime,
  3097. Mtime: ctime,
  3098. Type: types,
  3099. Modifier: adminInfo.AdminUser.Id,
  3100. Creator: adminInfo.AdminUser.Id,
  3101. Status: 1,
  3102. Doctor: role.UserName,
  3103. HisPatientId: his_patient_id,
  3104. OrderStatus: 1,
  3105. BatchNumber: "",
  3106. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3107. PreTime: pTime,
  3108. PType: p_type,
  3109. MedType: med_type,
  3110. Diagnose: diagnoses,
  3111. }
  3112. tempPrescription = prescription
  3113. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3114. redis := service.RedisClient()
  3115. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3116. redis.Set(key, "", time.Second)
  3117. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3118. redis.Set(keyOne, "", time.Second)
  3119. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3120. redis.Set(keySeven, "", time.Second)
  3121. defer redis.Close()
  3122. } else {
  3123. tempPrescription.ID = id
  3124. tempPrescription.Type = types
  3125. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3126. tempPrescription.Mtime = time.Now().Unix()
  3127. tempPrescription.Doctor = role.UserName
  3128. //tempPrescription.OrderStatus = order_status
  3129. tempPrescription.PreTime = pTime
  3130. tempPrescription.MedType = med_type
  3131. tempPrescription.Diagnose = diagnoses
  3132. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3133. redis := service.RedisClient()
  3134. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3135. redis.Set(key, "", time.Second)
  3136. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3137. redis.Set(keyOne, "", time.Second)
  3138. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3139. redis.Set(keySeven, "", time.Second)
  3140. defer redis.Close()
  3141. }
  3142. //service.SaveHisPrescription(prescription)
  3143. //更改患者挂号状态
  3144. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3145. fmt.Println("更改失败", err2)
  3146. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3147. advices := items["advices"].([]interface{})
  3148. groupNo := int64(0)
  3149. if len(advices) > 0 {
  3150. for _, advice := range advices {
  3151. tx := db.Begin()
  3152. // 在函数结束时处理事务回滚
  3153. defer func() {
  3154. if r := recover(); r != nil {
  3155. tx.Rollback()
  3156. }
  3157. }()
  3158. var s models.HisDoctorAdviceInfo
  3159. s.PrescriptionId = tempPrescription.ID
  3160. s.AdviceType = 2
  3161. s.AdviceDoctor = doctor_id
  3162. s.StopState = 2
  3163. s.ExecutionState = 2
  3164. s.AdviceDate = theTime3.Unix()
  3165. s.Status = 1
  3166. s.UserOrgId = adminInfo.CurrentOrgId
  3167. s.RecordDate = theTime3.Unix()
  3168. s.StartTime = tempPrescription.PreTime
  3169. s.Groupno = groupNo
  3170. s.PatientId = patient_id
  3171. s.HisPatientId = his_patient_id
  3172. s.StartTime = pTime
  3173. s.IsSettle = 2
  3174. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3175. if errcode > 0 {
  3176. c.ServeFailJSONWithSGJErrorCode(errcode)
  3177. return
  3178. }
  3179. s.StartTime = pTime
  3180. var total_count int64 //处方总库存
  3181. //查询改药品信息
  3182. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3183. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3184. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3185. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3186. total_count += prescribingNumberSeven * medical.MinNumber
  3187. }
  3188. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3189. total_count += prescribingNumberSeven
  3190. }
  3191. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3192. total_count += prescribingNumberSeven
  3193. }
  3194. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3195. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3196. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3197. if s.Price != lastWarehouse.RetailPrice {
  3198. s.Price = lastWarehouse.RetailPrice
  3199. }
  3200. if s.Price == 0 {
  3201. if lastWarehouse.ID == 0 {
  3202. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3203. s.Price = lastWarehouseTwo.RetailPrice
  3204. }
  3205. }
  3206. }
  3207. //查询保存处方出库开关是否打开
  3208. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3209. if s.PatientId != 30038 {
  3210. if drugOutConfig.IsOpen == 1 {
  3211. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3212. // 查询该药品最后一次出库记录
  3213. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3214. var is_user_total int64
  3215. var no_user_total int64
  3216. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3217. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3218. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3219. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3220. }
  3221. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3222. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3223. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3224. no_user_total += prescribingNumberSevenTy
  3225. }
  3226. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3227. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3228. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3229. no_user_total += prescribingNumberSevenTy
  3230. }
  3231. if len(druginfo) > 0 {
  3232. for _, it := range druginfo {
  3233. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3234. it.Count = it.Count * drug.MinNumber
  3235. is_user_total += it.Count
  3236. }
  3237. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3238. is_user_total += it.Count
  3239. }
  3240. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3241. is_user_total += it.Count
  3242. }
  3243. }
  3244. }
  3245. //库存不足
  3246. if s.UserOrgId != 10206 {
  3247. if s.ID == 0 {
  3248. //查询改药品是否已经停用
  3249. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3250. if base.ID > 0 {
  3251. tx.Rollback()
  3252. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3253. return
  3254. }
  3255. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3256. if drugMedical.SumCount == 0 {
  3257. tx.Rollback()
  3258. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3259. return
  3260. }
  3261. //针对康德
  3262. if s.UserOrgId == 10402 || s.UserOrgId == 10164 {
  3263. //获取该药品的总入库数量
  3264. drugWarehouseinfo, _ := service.GetAllDrugInfoList(s.DrugId, s.UserOrgId)
  3265. //获取该药品总共开了多少支医嘱
  3266. hisDocInfoList, _ := service.GetHisDocInfoList(s.DrugId, s.UserOrgId)
  3267. var in_count int64
  3268. var in_prescription_number_total int64
  3269. if len(drugWarehouseinfo) > 0 {
  3270. for _, item := range drugWarehouseinfo {
  3271. if item.MaxUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3272. in_count += item.WarehousingCount * drugMedical.MinNumber
  3273. }
  3274. if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3275. in_count += item.WarehousingCount
  3276. }
  3277. if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3278. in_count += item.WarehousingCount
  3279. }
  3280. }
  3281. }
  3282. if len(hisDocInfoList) > 0 {
  3283. for _, item := range hisDocInfoList {
  3284. if item.PrescribingNumberUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3285. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3286. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3287. in_prescription_number_total += prescribingNumberSevenTy * drug.MinNumber
  3288. }
  3289. if item.PrescribingNumberUnit == drugMedical.MinUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3290. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3291. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3292. in_prescription_number_total += prescribingNumberSevenTy
  3293. }
  3294. if item.PrescribingNumberUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3295. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3296. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3297. in_prescription_number_total += prescribingNumberSevenTy
  3298. }
  3299. }
  3300. }
  3301. //
  3302. //fmt.Println("no_user_total------------------------------", no_user_total)
  3303. //fmt.Println("in_prescription_number_total---------------------------", in_prescription_number_total)
  3304. //fmt.Println("in_count----------------------------------", in_count)
  3305. //如果已经开过的医嘱 加上未开的医嘱数量 大于 入库总数量则提示库存不足
  3306. if no_user_total+in_prescription_number_total > in_count {
  3307. tx.Rollback()
  3308. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3309. return
  3310. }
  3311. }
  3312. //查询该药品所有入库数量
  3313. }
  3314. if s.ID > 0 {
  3315. //查询改药品是否已经停用
  3316. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3317. if base.ID > 0 {
  3318. tx.Rollback()
  3319. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3320. return
  3321. }
  3322. }
  3323. }
  3324. //fmt.Println("药品名称----------------------", drug.DrugName)
  3325. //fmt.Println("药品名称----------------------", drug.IsUse)
  3326. //fmt.Println("is_user_total-------------------------", is_user_total)
  3327. //fmt.Println("no_user_total-------------------------", no_user_total)
  3328. //fmt.Println("drug.IsUse---------------", drug.IsUse)
  3329. //fmt.Println("00000000000000000000", s.UserOrgId)
  3330. if is_user_total != no_user_total {
  3331. //出库
  3332. //针对御享天源
  3333. if drug.IsUse == 1 && s.UserOrgId == 10635 {
  3334. creater := adminInfo.AdminUser.Id
  3335. newadviceInfo := &models.HisDoctorAdviceInfo{
  3336. ID: s.ID,
  3337. UserOrgId: s.UserOrgId,
  3338. PatientId: s.PatientId,
  3339. HisPatientId: s.HisPatientId,
  3340. AdviceType: s.AdviceType,
  3341. AdviceDate: s.AdviceDate,
  3342. StartTime: s.StartTime,
  3343. AdviceName: s.AdviceName,
  3344. AdviceDesc: s.AdviceDesc,
  3345. ReminderDate: s.ReminderDate,
  3346. SingleDose: s.SingleDose,
  3347. SingleDoseUnit: s.SingleDoseUnit,
  3348. PrescribingNumber: s.PrescribingNumber,
  3349. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3350. DeliveryWay: s.DeliveryWay,
  3351. ExecutionFrequency: s.ExecutionFrequency,
  3352. AdviceDoctor: s.AdviceDoctor,
  3353. Status: s.Status,
  3354. CreatedTime: s.CreatedTime,
  3355. UpdatedTime: s.UpdatedTime,
  3356. AdviceAffirm: s.AdviceAffirm,
  3357. Remark: s.Remark,
  3358. StopTime: s.StopTime,
  3359. StopReason: s.StopReason,
  3360. StopDoctor: s.StopDoctor,
  3361. StopState: s.StopState,
  3362. ParentId: s.ParentId,
  3363. ExecutionTime: s.ExecutionTime,
  3364. ExecutionStaff: s.ExecutionStaff,
  3365. ExecutionState: s.ExecutionState,
  3366. Checker: s.Checker,
  3367. RecordDate: s.RecordDate,
  3368. DialysisOrderId: s.DialysisOrderId,
  3369. CheckTime: s.CheckTime,
  3370. CheckState: s.CheckState,
  3371. DrugSpec: s.DrugSpec,
  3372. DrugSpecUnit: s.DrugSpecUnit,
  3373. Groupno: s.Groupno,
  3374. RemindType: s.RemindType,
  3375. FrequencyType: s.FrequencyType,
  3376. DayCount: s.DayCount,
  3377. WeekDay: s.WeekDay,
  3378. TemplateId: s.TemplateId,
  3379. Modifier: s.Modifier,
  3380. DrugId: s.DrugId,
  3381. Price: s.Price,
  3382. PrescriptionId: s.PrescriptionId,
  3383. MedListCodg: s.MedListCodg,
  3384. FeedetlSn: s.FeedetlSn,
  3385. Day: s.DayCount,
  3386. ChildDoctorAdvice: nil,
  3387. Drug: models.Drug{},
  3388. Diagnosis: s.Diagnosis,
  3389. Way: s.Way,
  3390. HospApprFlag: s.HospApprFlag,
  3391. LmtUsedFlag: s.LmtUsedFlag,
  3392. HisOrderInfo: models.HisOrderInfo{},
  3393. IsMedicine: s.IsMedicine,
  3394. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3395. Child: nil,
  3396. IsSettle: s.IsSettle,
  3397. IsMobile: s.IsMobile,
  3398. IsSelfDrug: s.IsSelfDrug,
  3399. DrugWayCount: s.DrugWayCount,
  3400. }
  3401. var history_count int64
  3402. var local_count int64
  3403. //查找已经开过的医嘱信息
  3404. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3405. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3406. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3407. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3408. local_count += prescribingNumberSevenTy * drug.MinNumber
  3409. }
  3410. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3411. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3412. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3413. local_count += prescribingNumberSevenTy
  3414. }
  3415. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3416. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3417. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3418. local_count += prescribingNumberSevenTy
  3419. }
  3420. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3421. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3422. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3423. history_count += prescribingNumberSevenTy * drug.MinNumber
  3424. }
  3425. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3426. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3427. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3428. history_count += prescribingNumberSevenTy
  3429. }
  3430. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3431. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3432. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3433. history_count += prescribingNumberSevenTy
  3434. }
  3435. fmt.Println("local_count---------------", local_count)
  3436. fmt.Println("history_count---------------", history_count)
  3437. //如果当前出库数量大于历史出库数量则需要出库
  3438. if local_count > history_count {
  3439. //按最小单位出库
  3440. var cha_count = local_count - history_count
  3441. newadviceInfo.PrescribingNumber = float64(cha_count)
  3442. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3443. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3444. }
  3445. //如果当前出库数量小于历史出库数量则需要退库
  3446. if local_count < history_count {
  3447. var cha_count = history_count - local_count
  3448. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3449. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3450. }
  3451. if local_count == history_count {
  3452. if is_user_total == 0 {
  3453. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3454. }
  3455. }
  3456. }
  3457. if drug.IsUse == 2 {
  3458. creater := adminInfo.AdminUser.Id
  3459. newadviceInfo := &models.HisDoctorAdviceInfo{
  3460. ID: s.ID,
  3461. UserOrgId: s.UserOrgId,
  3462. PatientId: s.PatientId,
  3463. HisPatientId: s.HisPatientId,
  3464. AdviceType: s.AdviceType,
  3465. AdviceDate: s.AdviceDate,
  3466. StartTime: s.StartTime,
  3467. AdviceName: s.AdviceName,
  3468. AdviceDesc: s.AdviceDesc,
  3469. ReminderDate: s.ReminderDate,
  3470. SingleDose: s.SingleDose,
  3471. SingleDoseUnit: s.SingleDoseUnit,
  3472. PrescribingNumber: s.PrescribingNumber,
  3473. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3474. DeliveryWay: s.DeliveryWay,
  3475. ExecutionFrequency: s.ExecutionFrequency,
  3476. AdviceDoctor: s.AdviceDoctor,
  3477. Status: s.Status,
  3478. CreatedTime: s.CreatedTime,
  3479. UpdatedTime: s.UpdatedTime,
  3480. AdviceAffirm: s.AdviceAffirm,
  3481. Remark: s.Remark,
  3482. StopTime: s.StopTime,
  3483. StopReason: s.StopReason,
  3484. StopDoctor: s.StopDoctor,
  3485. StopState: s.StopState,
  3486. ParentId: s.ParentId,
  3487. ExecutionTime: s.ExecutionTime,
  3488. ExecutionStaff: s.ExecutionStaff,
  3489. ExecutionState: s.ExecutionState,
  3490. Checker: s.Checker,
  3491. RecordDate: s.RecordDate,
  3492. DialysisOrderId: s.DialysisOrderId,
  3493. CheckTime: s.CheckTime,
  3494. CheckState: s.CheckState,
  3495. DrugSpec: s.DrugSpec,
  3496. DrugSpecUnit: s.DrugSpecUnit,
  3497. Groupno: s.Groupno,
  3498. RemindType: s.RemindType,
  3499. FrequencyType: s.FrequencyType,
  3500. DayCount: s.DayCount,
  3501. WeekDay: s.WeekDay,
  3502. TemplateId: s.TemplateId,
  3503. Modifier: s.Modifier,
  3504. DrugId: s.DrugId,
  3505. Price: s.Price,
  3506. PrescriptionId: s.PrescriptionId,
  3507. MedListCodg: s.MedListCodg,
  3508. FeedetlSn: s.FeedetlSn,
  3509. Day: s.DayCount,
  3510. ChildDoctorAdvice: nil,
  3511. Drug: models.Drug{},
  3512. Diagnosis: s.Diagnosis,
  3513. Way: s.Way,
  3514. HospApprFlag: s.HospApprFlag,
  3515. LmtUsedFlag: s.LmtUsedFlag,
  3516. HisOrderInfo: models.HisOrderInfo{},
  3517. IsMedicine: s.IsMedicine,
  3518. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3519. Child: nil,
  3520. IsSettle: s.IsSettle,
  3521. IsMobile: s.IsMobile,
  3522. IsSelfDrug: s.IsSelfDrug,
  3523. DrugWayCount: s.DrugWayCount,
  3524. }
  3525. var history_count int64
  3526. var local_count int64
  3527. //查找已经开过的医嘱信息
  3528. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3529. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3530. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3531. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3532. local_count += prescribingNumberSevenTy * drug.MinNumber
  3533. }
  3534. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3535. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3536. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3537. local_count += prescribingNumberSevenTy
  3538. }
  3539. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3540. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3541. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3542. local_count += prescribingNumberSevenTy
  3543. }
  3544. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3545. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3546. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3547. history_count += prescribingNumberSevenTy * drug.MinNumber
  3548. }
  3549. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3550. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3551. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3552. history_count += prescribingNumberSevenTy
  3553. }
  3554. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3555. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3556. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3557. history_count += prescribingNumberSevenTy
  3558. }
  3559. fmt.Println("local_count---------------", local_count)
  3560. fmt.Println("history_count---------------", history_count)
  3561. //如果当前出库数量大于历史出库数量则需要出库
  3562. if local_count > history_count {
  3563. //按最小单位出库
  3564. var cha_count = local_count - history_count
  3565. newadviceInfo.PrescribingNumber = float64(cha_count)
  3566. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3567. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3568. }
  3569. //如果当前出库数量小于历史出库数量则需要退库
  3570. if local_count < history_count {
  3571. var cha_count = history_count - local_count
  3572. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3573. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3574. }
  3575. if local_count == history_count {
  3576. if is_user_total == 0 {
  3577. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3578. }
  3579. }
  3580. }
  3581. //更新字典里面的库存
  3582. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3583. var sum_count int64
  3584. for _, its := range stockInfo {
  3585. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3586. if its.MaxUnit == baseDrug.MaxUnit {
  3587. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3588. }
  3589. sum_count += its.StockMaxNumber + its.StockMinNumber
  3590. }
  3591. //更新基础库存
  3592. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3593. //剩余库存
  3594. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3595. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3596. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3597. //创建医嘱
  3598. service.CreateHisDoctorAdviceOne(&s, tx)
  3599. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3600. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3601. if len(outInfoTwo) > 0 {
  3602. for _, item := range outInfoTwo {
  3603. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3604. }
  3605. }
  3606. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3607. if len(drugAutoDetail) > 0 {
  3608. for _, item := range drugAutoDetail {
  3609. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3610. }
  3611. }
  3612. }
  3613. }
  3614. }
  3615. //记录日志
  3616. byterequest, _ := json.Marshal(s)
  3617. adviceLog := models.XtDoctorAdviceLog{
  3618. UserOrgId: s.UserOrgId,
  3619. PatientId: s.PatientId,
  3620. AdminUserId: adminInfo.AdminUser.Id,
  3621. Module: 1,
  3622. ErrLog: string(byterequest),
  3623. Status: 1,
  3624. Ctime: time.Now().Unix(),
  3625. Mtime: 0,
  3626. Source: "电脑端新建his医嘱",
  3627. RecordDate: s.AdviceDate,
  3628. }
  3629. service.CreateDoctorAdviceLog(adviceLog)
  3630. //存储切片中
  3631. adviceList = append(adviceList, s)
  3632. redis := service.RedisClient()
  3633. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3634. redis.Set(key, "", time.Second)
  3635. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3636. redis.Set(keyOne, "", time.Second)
  3637. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3638. redis.Set(keySeven, "", time.Second)
  3639. var randNum int
  3640. randNum = rand.Intn(10000) + 1000
  3641. timestamp := time.Now().Unix()
  3642. tempTime := time.Unix(timestamp, 0)
  3643. timeFormat := tempTime.Format("20060102150405")
  3644. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3645. //赤峰
  3646. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3647. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3648. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3649. if info.RetailPrice > 0 {
  3650. if s.DeliveryWay == "口服" {
  3651. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3652. s.Price = drug.RetailPrice
  3653. }
  3654. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3655. s.Price = info.RetailPrice
  3656. }
  3657. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3658. s.Price = info.RetailPrice
  3659. }
  3660. }
  3661. }
  3662. }
  3663. service.CreateHisDoctorAdviceOne(&s, tx)
  3664. tx.Commit()
  3665. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3666. redis.Set(keySix, "", time.Second)
  3667. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3668. redis.Set(keyFive, "", time.Second)
  3669. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3670. redis.Set(keyEight, "", time.Second)
  3671. defer redis.Close()
  3672. }
  3673. }
  3674. }
  3675. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3676. projects := items["project"].([]interface{})
  3677. if len(projects) > 0 {
  3678. for _, project := range projects {
  3679. tx := db.Begin()
  3680. // 在函数结束时处理事务回滚
  3681. defer func() {
  3682. if r := recover(); r != nil {
  3683. tx.Rollback()
  3684. }
  3685. }()
  3686. var p models.HisPrescriptionProject
  3687. p.PrescriptionId = tempPrescription.ID
  3688. p.PatientId = patient_id
  3689. p.RecordDate = theTime3.Unix()
  3690. p.Doctor = doctor_id
  3691. p.UserOrgId = adminInfo.CurrentOrgId
  3692. p.HisPatientId = his_patient_id
  3693. p.Status = 1
  3694. p.StartTime = pTime
  3695. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3696. if errcode > 0 {
  3697. tx.Rollback()
  3698. c.ServeFailJSONWithSGJErrorCode(errcode)
  3699. return
  3700. }
  3701. if p.ID == 0 {
  3702. p.IsOut = 2
  3703. }
  3704. if p.ID > 0 {
  3705. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3706. p.IsOut = projectDetail.IsOut
  3707. }
  3708. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3709. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3710. if p.Type == 3 {
  3711. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3712. if p.Price != lastWarehouse.PackingPrice {
  3713. p.Price = lastWarehouse.PackingPrice
  3714. }
  3715. if p.Price == 0 {
  3716. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3717. p.Price = lastWarehouseTwo.PackingPrice
  3718. }
  3719. if p.Unit == "" {
  3720. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3721. p.Unit = goodInfoOne.PackingUnit
  3722. }
  3723. }
  3724. }
  3725. if adminInfo.CurrentOrgId != 10206 {
  3726. if p.Type == 3 {
  3727. if p.ID == 0 {
  3728. //查询该耗材是否停用
  3729. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3730. //表示该耗材已经停用,不能保存
  3731. if goodInfoSeven.ID == 0 {
  3732. tx.Rollback()
  3733. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3734. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3735. return
  3736. }
  3737. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3738. if goodInfoOne.SumCount == 0 {
  3739. tx.Rollback()
  3740. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3741. return
  3742. }
  3743. }
  3744. if p.ID > 0 {
  3745. //查询该耗材是否停用
  3746. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3747. //表示该耗材已经停用,不能保存
  3748. if goodInfoSeven.ID == 0 {
  3749. tx.Rollback()
  3750. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3751. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3752. return
  3753. }
  3754. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3755. if goodInfoOne.SumCount == 0 {
  3756. tx.Rollback()
  3757. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3758. return
  3759. }
  3760. }
  3761. }
  3762. }
  3763. //查询保存耗材出库开关是否打开
  3764. if p.PatientId != 30038 {
  3765. //用机构ID区分
  3766. if adminInfo.CurrentOrgId != 9671 {
  3767. if goodOutConfig.IsOpen == 1 {
  3768. //耗材出库
  3769. if p.Type == 3 {
  3770. //对比当前数据和历史出库数据
  3771. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3772. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3773. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3774. //针对康德
  3775. if p.UserOrgId == 10164 || p.UserOrgId == 10402 {
  3776. //查询耗材的总入库数量
  3777. warehouseInfo, _ := service.GetAllWarehouseInfo(p.ProjectId, adminInfo.CurrentOrgId)
  3778. //查询该耗材的总出库数量
  3779. prescriptionGood, _ := service.GetHisPrescriptionByGoodId(p.ProjectId, adminInfo.CurrentOrgId)
  3780. var all_good_count int64
  3781. var prescription_count int64
  3782. if len(warehouseInfo) > 0 {
  3783. for _, item := range warehouseInfo {
  3784. all_good_count += item.WarehousingCount
  3785. }
  3786. }
  3787. if len(prescriptionGood) > 0 {
  3788. for _, item := range prescriptionGood {
  3789. hisCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3790. prescription_count += hisCount
  3791. }
  3792. }
  3793. fmt.Println("prescription_count-------------------------", prescription_count)
  3794. fmt.Println("nowCount-------------------------", nowCount)
  3795. fmt.Println("all_good_count-------------------------", all_good_count)
  3796. if prescription_count+nowCount > all_good_count {
  3797. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3798. tx.Rollback()
  3799. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3800. return
  3801. }
  3802. }
  3803. //如果当前处方数量大于历史数据,则需要出库
  3804. if nowCount > historyCount {
  3805. var cha_count int64
  3806. cha_count = nowCount - historyCount
  3807. timeStr := time.Now().Format("2006-01-02")
  3808. timeArr := strings.Split(timeStr, "-")
  3809. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3810. total = total + 1
  3811. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3812. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3813. number = number + total
  3814. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3815. operation_time := time.Now().Unix()
  3816. creater := c.GetAdminUserInfo().AdminUser.Id
  3817. recordDateStr := time.Now().Format("2006-01-02")
  3818. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3819. nowtime := recordDate.Unix()
  3820. warehouseOut := models.WarehouseOut{
  3821. WarehouseOutOrderNumber: warehousing_out_order,
  3822. OperationTime: operation_time,
  3823. OrgId: adminInfo.CurrentOrgId,
  3824. Creater: creater,
  3825. Ctime: time.Now().Unix(),
  3826. Status: 1,
  3827. WarehouseOutTime: nowtime,
  3828. Type: 1,
  3829. StorehouseId: storeConfig.StorehouseOutInfo,
  3830. IsCheck: 1,
  3831. IsSys: 1,
  3832. }
  3833. //查询是否生成出库单
  3834. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3835. if out.ID == 0 {
  3836. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3837. }
  3838. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3839. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3840. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3841. dialyPrepareOne := models.DialysisBeforePrepare{
  3842. GoodTypeId: goodObj.GoodTypeId,
  3843. GoodId: p.ProjectId,
  3844. PatientId: p.PatientId,
  3845. RecordDate: p.RecordDate,
  3846. UserOrgId: adminInfo.CurrentOrgId,
  3847. Count: cha_count,
  3848. Ctime: time.Now().Unix(),
  3849. Creater: creater,
  3850. Status: 1,
  3851. StorehouseId: houseConfig.StorehouseOutInfo,
  3852. ProjectId: p.ID,
  3853. }
  3854. //出库
  3855. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3856. }
  3857. //如果当前处方数量小于历史数据,怎需要退库
  3858. if nowCount < historyCount {
  3859. var cha_count int64
  3860. cha_count = historyCount - nowCount
  3861. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3862. creater := c.GetAdminUserInfo().AdminUser.Id
  3863. newPrescriptionProject := &models.HisPrescriptionProject{
  3864. ID: p.ID,
  3865. ProjectId: p.ProjectId,
  3866. Price: p.Price,
  3867. UserOrgId: p.UserOrgId,
  3868. Status: 1,
  3869. Ctime: time.Now().Unix(),
  3870. Mtime: time.Now().Unix(),
  3871. PatientId: p.PatientId,
  3872. HisPatientId: p.HisPatientId,
  3873. RecordDate: p.RecordDate,
  3874. PrescriptionId: p.PrescriptionId,
  3875. Count: p.Count,
  3876. FeedetlSn: p.FeedetlSn,
  3877. MedListCodg: p.MedListCodg,
  3878. SingleDose: p.SingleDose,
  3879. DeliveryWay: p.DeliveryWay,
  3880. ExecutionFrequency: p.ExecutionFrequency,
  3881. Day: p.Day,
  3882. HisProject: models.HisProject{},
  3883. GoodInfo: models.GoodInfo{},
  3884. Remark: p.Remark,
  3885. Unit: p.Unit,
  3886. Type: p.Type,
  3887. Doctor: p.Doctor,
  3888. ExecutionTime: p.ExecutionTime,
  3889. ExecutionStaff: p.ExecutionStaff,
  3890. ExecutionState: p.ExecutionState,
  3891. CheckTime: p.CheckTime,
  3892. CheckState: p.CheckState,
  3893. Checker: p.Checker,
  3894. StartTime: p.StartTime,
  3895. TeamId: p.TeamId,
  3896. XtHisProjectTeam: models.XtHisProjectTeam{},
  3897. FrequencyType: p.FrequencyType,
  3898. DayCount: p.DayCount,
  3899. WeekDay: p.WeekDay,
  3900. IsCheckTeam: p.IsCheckTeam,
  3901. HisOrderInfo: models.HisOrderInfo{},
  3902. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3903. IsOut: p.IsOut,
  3904. YbSyncStatus: p.YbSyncStatus,
  3905. }
  3906. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3907. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3908. }
  3909. if nowCount == historyCount {
  3910. if historyCount == 0 {
  3911. recordDateStr := time.Now().Format("2006-01-02")
  3912. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3913. nowtime := recordDate.Unix()
  3914. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3915. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3916. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3917. creater := c.GetAdminUserInfo().AdminUser.Id
  3918. dialyPrepareOne := models.DialysisBeforePrepare{
  3919. GoodTypeId: goodObj.GoodTypeId,
  3920. GoodId: p.ProjectId,
  3921. PatientId: p.PatientId,
  3922. RecordDate: p.RecordDate,
  3923. UserOrgId: adminInfo.CurrentOrgId,
  3924. Count: nowCount,
  3925. Ctime: time.Now().Unix(),
  3926. Creater: creater,
  3927. Status: 1,
  3928. StorehouseId: houseConfig.StorehouseOutInfo,
  3929. ProjectId: p.ID,
  3930. }
  3931. //出库
  3932. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3933. }
  3934. }
  3935. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3936. //查询历史出库数据
  3937. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3938. var out_count_five int64
  3939. for _, item := range flowGood {
  3940. out_count_five += item.Count
  3941. }
  3942. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3943. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3944. if out_count_five != parseIntCount {
  3945. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3946. detail := models.AutomaticReduceDetail{
  3947. WarehouseOutId: 0,
  3948. WarehouseOutOrderNumber: "",
  3949. PatientId: p.PatientId,
  3950. Ctime: time.Now().Unix(),
  3951. Mtime: 0,
  3952. Status: 1,
  3953. RecordTime: p.RecordDate,
  3954. OrgId: p.UserOrgId,
  3955. GoodId: p.ProjectId,
  3956. GoodTypeId: 0,
  3957. Count: parseIntCount,
  3958. Type: 0,
  3959. ProjectId: lastHisProject.ID,
  3960. StorehouseId: 0,
  3961. }
  3962. service.CreateNewAutoDetail(detail, tx)
  3963. }
  3964. // //查询耗材最后一次出库记录
  3965. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3966. // //查询默认出库仓库库存
  3967. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3968. // if len(wareOut) > 0 {
  3969. //
  3970. // for _, it := range wareOut {
  3971. // //回退库存
  3972. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3973. //
  3974. // //删除出库记录
  3975. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3976. //
  3977. // }
  3978. // }
  3979. //
  3980. // timeStr := time.Now().Format("2006-01-02")
  3981. // timeArr := strings.Split(timeStr, "-")
  3982. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3983. //
  3984. // total = total + 1
  3985. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3986. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3987. // number = number + total
  3988. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3989. //
  3990. // operation_time := time.Now().Unix()
  3991. // creater := c.GetAdminUserInfo().AdminUser.Id
  3992. //
  3993. // recordDateStr := time.Now().Format("2006-01-02")
  3994. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3995. // nowtime := recordDate.Unix()
  3996. // warehouseOut := models.WarehouseOut{
  3997. // WarehouseOutOrderNumber: warehousing_out_order,
  3998. // OperationTime: operation_time,
  3999. // OrgId: adminInfo.CurrentOrgId,
  4000. // Creater: creater,
  4001. // Ctime: time.Now().Unix(),
  4002. // Status: 1,
  4003. // WarehouseOutTime: nowtime,
  4004. // Type: 1,
  4005. // StorehouseId: storeConfig.StorehouseOutInfo,
  4006. // IsCheck: 1,
  4007. // IsSys: 1,
  4008. // }
  4009. // //查询是否生成出库单
  4010. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4011. // if out.ID == 0 {
  4012. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4013. // }
  4014. //
  4015. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4016. //
  4017. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4018. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4019. //
  4020. // dialyPrepareOne := models.DialysisBeforePrepare{
  4021. // GoodTypeId: goodObj.GoodTypeId,
  4022. // GoodId: p.ProjectId,
  4023. // PatientId: p.PatientId,
  4024. // RecordDate: p.RecordDate,
  4025. // UserOrgId: adminInfo.CurrentOrgId,
  4026. // Count: parseIntCount,
  4027. // Ctime: time.Now().Unix(),
  4028. // Creater: creater,
  4029. // Status: 1,
  4030. // StorehouseId: houseConfig.StorehouseOutInfo,
  4031. // ProjectId: lastHisProject.ID,
  4032. // }
  4033. // //判断是否是零用耗材(非零用)
  4034. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4035. //
  4036. // //查询历史出库数据
  4037. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4038. // var out_count int64
  4039. // for _, item := range flowGood {
  4040. // out_count += item.Count
  4041. // }
  4042. // //如果历史数和当前数据不想等才进行退库出库
  4043. // if out_count != parseIntCount {
  4044. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4045. //
  4046. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4047. // detail := models.AutomaticReduceDetail{
  4048. // WarehouseOutId: 0,
  4049. // WarehouseOutOrderNumber: "",
  4050. // PatientId: p.PatientId,
  4051. // Ctime: time.Now().Unix(),
  4052. // Mtime: 0,
  4053. // Status: 1,
  4054. // RecordTime: p.RecordDate,
  4055. // OrgId: p.UserOrgId,
  4056. // GoodId: p.ProjectId,
  4057. // GoodTypeId: 0,
  4058. // Count: parseIntCount,
  4059. // Type: 0,
  4060. // ProjectId: lastHisProject.ID,
  4061. // StorehouseId: 0,
  4062. // }
  4063. //
  4064. // service.CreateNewAutoDetail(detail, tx)
  4065. //
  4066. // //查询剩余库存
  4067. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4068. // var sum_count int64
  4069. // for _, item := range goodList {
  4070. // sum_count += item.StockCount
  4071. // }
  4072. //
  4073. // //更新剩余库存
  4074. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4075. //
  4076. // //耗材
  4077. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4078. //
  4079. // }
  4080. // //判断是否是零用耗材(零用但是是出库耗材)
  4081. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4082. //
  4083. // //查询历史出库数据
  4084. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4085. // var out_count int64
  4086. // for _, item := range flowGood {
  4087. // out_count += item.Count
  4088. // }
  4089. // //如果历史数和当前数据不想等才进行退库出库
  4090. // if out_count != parseIntCount {
  4091. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4092. //
  4093. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4094. // detail := models.AutomaticReduceDetail{
  4095. // WarehouseOutId: 0,
  4096. // WarehouseOutOrderNumber: "",
  4097. // PatientId: p.PatientId,
  4098. // Ctime: time.Now().Unix(),
  4099. // Mtime: 0,
  4100. // Status: 1,
  4101. // RecordTime: p.RecordDate,
  4102. // OrgId: p.UserOrgId,
  4103. // GoodId: p.ProjectId,
  4104. // GoodTypeId: 0,
  4105. // Count: parseIntCount,
  4106. // Type: 0,
  4107. // ProjectId: p.ID,
  4108. // StorehouseId: 0,
  4109. // }
  4110. //
  4111. // service.CreateNewAutoDetail(detail, tx)
  4112. //
  4113. // //查询剩余库存
  4114. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4115. // var sum_count int64
  4116. // for _, item := range goodList {
  4117. // sum_count += item.StockCount
  4118. // }
  4119. //
  4120. // //更新剩余库存
  4121. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4122. //
  4123. // //耗材
  4124. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4125. // }
  4126. //
  4127. // }
  4128. //
  4129. // }
  4130. //
  4131. //}
  4132. //记录日志
  4133. byterequest, _ := json.Marshal(p)
  4134. adviceLog := models.XtDoctorAdviceLog{
  4135. UserOrgId: p.UserOrgId,
  4136. PatientId: p.PatientId,
  4137. AdminUserId: adminInfo.AdminUser.Id,
  4138. Module: 1,
  4139. ErrLog: string(byterequest),
  4140. Status: 1,
  4141. Ctime: time.Now().Unix(),
  4142. Mtime: 0,
  4143. Source: "电脑端新建his项目",
  4144. RecordDate: p.RecordDate,
  4145. }
  4146. service.CreateDoctorAdviceLog(adviceLog)
  4147. projectList = append(projectList, p)
  4148. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4149. //新增或者编辑项目,修改对应的标签数据
  4150. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4151. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4152. var label models.HisLabelPrintInfo
  4153. project, _ := service.GetProjectDetail(p.ProjectId)
  4154. if project.CostClassify == 3 { //类别为检验检查
  4155. if p.TeamId > 0 { //检验检查组套
  4156. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4157. if tempLabel.ID == 0 {
  4158. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4159. label.Number = tempPrescription.PrescriptionNumber
  4160. label.ProjectId = project.ID
  4161. label.Status = 1
  4162. label.IsPrint = 2
  4163. label.DoctorId = info.DoctorId
  4164. label.UserOrgId = p.UserOrgId
  4165. label.PatientId = patient_id
  4166. label.RecordDate = recordDateTime
  4167. label.Ctime = time.Now().Unix()
  4168. label.Mtime = time.Now().Unix()
  4169. label.ItemId = p.TeamId
  4170. label.FeedetlSn = p.FeedetlSn
  4171. label.PProjectId = p.ID
  4172. label.ProjectName = team.ProjectTeam
  4173. label.PatientName = patient.Name
  4174. service.CreateNewHisLabelRecord(&label, tx)
  4175. }
  4176. } else { //单条检验检查项目
  4177. label.Number = tempPrescription.PrescriptionNumber
  4178. label.ProjectId = project.ID
  4179. label.Status = 1
  4180. label.DoctorId = info.DoctorId
  4181. label.UserOrgId = p.UserOrgId
  4182. label.PatientId = patient_id
  4183. label.RecordDate = recordDateTime
  4184. label.IsPrint = 2
  4185. label.Ctime = time.Now().Unix()
  4186. label.Mtime = time.Now().Unix()
  4187. label.FeedetlSn = p.FeedetlSn
  4188. label.PProjectId = p.ID
  4189. label.ItemId = p.TeamId
  4190. label.ProjectName = project.ProjectName
  4191. label.PatientName = patient.Name
  4192. service.CreateNewHisLabelRecord(&label, tx)
  4193. }
  4194. }
  4195. }
  4196. }
  4197. }
  4198. }
  4199. }
  4200. if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  4201. //耗材出库
  4202. if p.Type == 3 {
  4203. //对比当前数据和历史出库数据
  4204. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  4205. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  4206. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4207. //如果当前处方数量大于历史数据,则需要出库
  4208. if nowCount > historyCount {
  4209. var cha_count int64
  4210. cha_count = nowCount - historyCount
  4211. timeStr := time.Now().Format("2006-01-02")
  4212. timeArr := strings.Split(timeStr, "-")
  4213. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4214. total = total + 1
  4215. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4216. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4217. number = number + total
  4218. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4219. operation_time := time.Now().Unix()
  4220. creater := c.GetAdminUserInfo().AdminUser.Id
  4221. recordDateStr := time.Now().Format("2006-01-02")
  4222. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4223. nowtime := recordDate.Unix()
  4224. warehouseOut := models.WarehouseOut{
  4225. WarehouseOutOrderNumber: warehousing_out_order,
  4226. OperationTime: operation_time,
  4227. OrgId: adminInfo.CurrentOrgId,
  4228. Creater: creater,
  4229. Ctime: time.Now().Unix(),
  4230. Status: 1,
  4231. WarehouseOutTime: nowtime,
  4232. Type: 1,
  4233. StorehouseId: storeConfig.StorehouseOutInfo,
  4234. IsCheck: 1,
  4235. IsSys: 1,
  4236. }
  4237. //查询是否生成出库单
  4238. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4239. if out.ID == 0 {
  4240. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4241. }
  4242. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4243. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4244. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4245. dialyPrepareOne := models.DialysisBeforePrepare{
  4246. GoodTypeId: goodObj.GoodTypeId,
  4247. GoodId: p.ProjectId,
  4248. PatientId: p.PatientId,
  4249. RecordDate: p.RecordDate,
  4250. UserOrgId: adminInfo.CurrentOrgId,
  4251. Count: cha_count,
  4252. Ctime: time.Now().Unix(),
  4253. Creater: creater,
  4254. Status: 1,
  4255. StorehouseId: houseConfig.StorehouseOutInfo,
  4256. ProjectId: p.ID,
  4257. }
  4258. //出库
  4259. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4260. }
  4261. //如果当前处方数量小于历史数据,怎需要退库
  4262. if nowCount < historyCount {
  4263. var cha_count int64
  4264. cha_count = historyCount - nowCount
  4265. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4266. creater := c.GetAdminUserInfo().AdminUser.Id
  4267. newPrescriptionProject := &models.HisPrescriptionProject{
  4268. ID: p.ID,
  4269. ProjectId: p.ProjectId,
  4270. Price: p.Price,
  4271. UserOrgId: p.UserOrgId,
  4272. Status: 1,
  4273. Ctime: time.Now().Unix(),
  4274. Mtime: time.Now().Unix(),
  4275. PatientId: p.PatientId,
  4276. HisPatientId: p.HisPatientId,
  4277. RecordDate: p.RecordDate,
  4278. PrescriptionId: p.PrescriptionId,
  4279. Count: p.Count,
  4280. FeedetlSn: p.FeedetlSn,
  4281. MedListCodg: p.MedListCodg,
  4282. SingleDose: p.SingleDose,
  4283. DeliveryWay: p.DeliveryWay,
  4284. ExecutionFrequency: p.ExecutionFrequency,
  4285. Day: p.Day,
  4286. HisProject: models.HisProject{},
  4287. GoodInfo: models.GoodInfo{},
  4288. Remark: p.Remark,
  4289. Unit: p.Unit,
  4290. Type: p.Type,
  4291. Doctor: p.Doctor,
  4292. ExecutionTime: p.ExecutionTime,
  4293. ExecutionStaff: p.ExecutionStaff,
  4294. ExecutionState: p.ExecutionState,
  4295. CheckTime: p.CheckTime,
  4296. CheckState: p.CheckState,
  4297. Checker: p.Checker,
  4298. StartTime: p.StartTime,
  4299. TeamId: p.TeamId,
  4300. XtHisProjectTeam: models.XtHisProjectTeam{},
  4301. FrequencyType: p.FrequencyType,
  4302. DayCount: p.DayCount,
  4303. WeekDay: p.WeekDay,
  4304. IsCheckTeam: p.IsCheckTeam,
  4305. HisOrderInfo: models.HisOrderInfo{},
  4306. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4307. IsOut: p.IsOut,
  4308. YbSyncStatus: p.YbSyncStatus,
  4309. }
  4310. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4311. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4312. }
  4313. if nowCount == historyCount {
  4314. if historyCount == 0 {
  4315. recordDateStr := time.Now().Format("2006-01-02")
  4316. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4317. nowtime := recordDate.Unix()
  4318. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4319. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4320. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4321. creater := c.GetAdminUserInfo().AdminUser.Id
  4322. dialyPrepareOne := models.DialysisBeforePrepare{
  4323. GoodTypeId: goodObj.GoodTypeId,
  4324. GoodId: p.ProjectId,
  4325. PatientId: p.PatientId,
  4326. RecordDate: p.RecordDate,
  4327. UserOrgId: adminInfo.CurrentOrgId,
  4328. Count: nowCount,
  4329. Ctime: time.Now().Unix(),
  4330. Creater: creater,
  4331. Status: 1,
  4332. StorehouseId: houseConfig.StorehouseOutInfo,
  4333. ProjectId: p.ID,
  4334. }
  4335. //出库
  4336. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4337. }
  4338. }
  4339. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4340. //查询历史出库数据
  4341. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4342. var out_count_five int64
  4343. for _, item := range flowGood {
  4344. out_count_five += item.Count
  4345. }
  4346. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4347. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4348. if out_count_five != parseIntCount {
  4349. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4350. detail := models.AutomaticReduceDetail{
  4351. WarehouseOutId: 0,
  4352. WarehouseOutOrderNumber: "",
  4353. PatientId: p.PatientId,
  4354. Ctime: time.Now().Unix(),
  4355. Mtime: 0,
  4356. Status: 1,
  4357. RecordTime: p.RecordDate,
  4358. OrgId: p.UserOrgId,
  4359. GoodId: p.ProjectId,
  4360. GoodTypeId: 0,
  4361. Count: parseIntCount,
  4362. Type: 0,
  4363. ProjectId: lastHisProject.ID,
  4364. StorehouseId: 0,
  4365. }
  4366. service.CreateNewAutoDetail(detail, tx)
  4367. }
  4368. // //查询耗材最后一次出库记录
  4369. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4370. // //查询默认出库仓库库存
  4371. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4372. // if len(wareOut) > 0 {
  4373. //
  4374. // for _, it := range wareOut {
  4375. // //回退库存
  4376. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4377. //
  4378. // //删除出库记录
  4379. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4380. //
  4381. // }
  4382. // }
  4383. //
  4384. // timeStr := time.Now().Format("2006-01-02")
  4385. // timeArr := strings.Split(timeStr, "-")
  4386. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4387. //
  4388. // total = total + 1
  4389. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4390. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4391. // number = number + total
  4392. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4393. //
  4394. // operation_time := time.Now().Unix()
  4395. // creater := c.GetAdminUserInfo().AdminUser.Id
  4396. //
  4397. // recordDateStr := time.Now().Format("2006-01-02")
  4398. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4399. // nowtime := recordDate.Unix()
  4400. // warehouseOut := models.WarehouseOut{
  4401. // WarehouseOutOrderNumber: warehousing_out_order,
  4402. // OperationTime: operation_time,
  4403. // OrgId: adminInfo.CurrentOrgId,
  4404. // Creater: creater,
  4405. // Ctime: time.Now().Unix(),
  4406. // Status: 1,
  4407. // WarehouseOutTime: nowtime,
  4408. // Type: 1,
  4409. // StorehouseId: storeConfig.StorehouseOutInfo,
  4410. // IsCheck: 1,
  4411. // IsSys: 1,
  4412. // }
  4413. // //查询是否生成出库单
  4414. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4415. // if out.ID == 0 {
  4416. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4417. // }
  4418. //
  4419. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4420. //
  4421. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4422. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4423. //
  4424. // dialyPrepareOne := models.DialysisBeforePrepare{
  4425. // GoodTypeId: goodObj.GoodTypeId,
  4426. // GoodId: p.ProjectId,
  4427. // PatientId: p.PatientId,
  4428. // RecordDate: p.RecordDate,
  4429. // UserOrgId: adminInfo.CurrentOrgId,
  4430. // Count: parseIntCount,
  4431. // Ctime: time.Now().Unix(),
  4432. // Creater: creater,
  4433. // Status: 1,
  4434. // StorehouseId: houseConfig.StorehouseOutInfo,
  4435. // ProjectId: lastHisProject.ID,
  4436. // }
  4437. // //判断是否是零用耗材(非零用)
  4438. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4439. //
  4440. // //查询历史出库数据
  4441. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4442. // var out_count int64
  4443. // for _, item := range flowGood {
  4444. // out_count += item.Count
  4445. // }
  4446. // //如果历史数和当前数据不想等才进行退库出库
  4447. // if out_count != parseIntCount {
  4448. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4449. //
  4450. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4451. // detail := models.AutomaticReduceDetail{
  4452. // WarehouseOutId: 0,
  4453. // WarehouseOutOrderNumber: "",
  4454. // PatientId: p.PatientId,
  4455. // Ctime: time.Now().Unix(),
  4456. // Mtime: 0,
  4457. // Status: 1,
  4458. // RecordTime: p.RecordDate,
  4459. // OrgId: p.UserOrgId,
  4460. // GoodId: p.ProjectId,
  4461. // GoodTypeId: 0,
  4462. // Count: parseIntCount,
  4463. // Type: 0,
  4464. // ProjectId: lastHisProject.ID,
  4465. // StorehouseId: 0,
  4466. // }
  4467. //
  4468. // service.CreateNewAutoDetail(detail, tx)
  4469. //
  4470. // //查询剩余库存
  4471. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4472. // var sum_count int64
  4473. // for _, item := range goodList {
  4474. // sum_count += item.StockCount
  4475. // }
  4476. //
  4477. // //更新剩余库存
  4478. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4479. //
  4480. // //耗材
  4481. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4482. //
  4483. // }
  4484. // //判断是否是零用耗材(零用但是是出库耗材)
  4485. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4486. //
  4487. // //查询历史出库数据
  4488. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4489. // var out_count int64
  4490. // for _, item := range flowGood {
  4491. // out_count += item.Count
  4492. // }
  4493. // //如果历史数和当前数据不想等才进行退库出库
  4494. // if out_count != parseIntCount {
  4495. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4496. //
  4497. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4498. // detail := models.AutomaticReduceDetail{
  4499. // WarehouseOutId: 0,
  4500. // WarehouseOutOrderNumber: "",
  4501. // PatientId: p.PatientId,
  4502. // Ctime: time.Now().Unix(),
  4503. // Mtime: 0,
  4504. // Status: 1,
  4505. // RecordTime: p.RecordDate,
  4506. // OrgId: p.UserOrgId,
  4507. // GoodId: p.ProjectId,
  4508. // GoodTypeId: 0,
  4509. // Count: parseIntCount,
  4510. // Type: 0,
  4511. // ProjectId: p.ID,
  4512. // StorehouseId: 0,
  4513. // }
  4514. //
  4515. // service.CreateNewAutoDetail(detail, tx)
  4516. //
  4517. // //查询剩余库存
  4518. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4519. // var sum_count int64
  4520. // for _, item := range goodList {
  4521. // sum_count += item.StockCount
  4522. // }
  4523. //
  4524. // //更新剩余库存
  4525. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4526. //
  4527. // //耗材
  4528. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4529. // }
  4530. //
  4531. // }
  4532. //
  4533. // }
  4534. //
  4535. //}
  4536. //记录日志
  4537. byterequest, _ := json.Marshal(p)
  4538. adviceLog := models.XtDoctorAdviceLog{
  4539. UserOrgId: p.UserOrgId,
  4540. PatientId: p.PatientId,
  4541. AdminUserId: adminInfo.AdminUser.Id,
  4542. Module: 1,
  4543. ErrLog: string(byterequest),
  4544. Status: 1,
  4545. Ctime: time.Now().Unix(),
  4546. Mtime: 0,
  4547. Source: "电脑端新建his项目",
  4548. RecordDate: p.RecordDate,
  4549. }
  4550. service.CreateDoctorAdviceLog(adviceLog)
  4551. projectList = append(projectList, p)
  4552. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4553. //新增或者编辑项目,修改对应的标签数据
  4554. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4555. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4556. var label models.HisLabelPrintInfo
  4557. project, _ := service.GetProjectDetail(p.ProjectId)
  4558. if project.CostClassify == 3 { //类别为检验检查
  4559. if p.TeamId > 0 { //检验检查组套
  4560. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4561. if tempLabel.ID == 0 {
  4562. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4563. label.Number = tempPrescription.PrescriptionNumber
  4564. label.ProjectId = project.ID
  4565. label.Status = 1
  4566. label.IsPrint = 2
  4567. label.DoctorId = info.DoctorId
  4568. label.UserOrgId = p.UserOrgId
  4569. label.PatientId = patient_id
  4570. label.RecordDate = recordDateTime
  4571. label.Ctime = time.Now().Unix()
  4572. label.Mtime = time.Now().Unix()
  4573. label.ItemId = p.TeamId
  4574. label.FeedetlSn = p.FeedetlSn
  4575. label.PProjectId = p.ID
  4576. label.ProjectName = team.ProjectTeam
  4577. label.PatientName = patient.Name
  4578. service.CreateNewHisLabelRecord(&label, tx)
  4579. }
  4580. } else { //单条检验检查项目
  4581. label.Number = tempPrescription.PrescriptionNumber
  4582. label.ProjectId = project.ID
  4583. label.Status = 1
  4584. label.DoctorId = info.DoctorId
  4585. label.UserOrgId = p.UserOrgId
  4586. label.PatientId = patient_id
  4587. label.RecordDate = recordDateTime
  4588. label.IsPrint = 2
  4589. label.Ctime = time.Now().Unix()
  4590. label.Mtime = time.Now().Unix()
  4591. label.FeedetlSn = p.FeedetlSn
  4592. label.PProjectId = p.ID
  4593. label.ItemId = p.TeamId
  4594. label.ProjectName = project.ProjectName
  4595. label.PatientName = patient.Name
  4596. service.CreateNewHisLabelRecord(&label, tx)
  4597. }
  4598. }
  4599. }
  4600. }
  4601. }
  4602. }
  4603. }
  4604. //插入检验数据
  4605. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4606. //新增或者编辑项目,修改对应的标签数据
  4607. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4608. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4609. var label models.HisLabelPrintInfo
  4610. project, _ := service.GetProjectDetail(p.ProjectId)
  4611. if project.CostClassify == 3 { //类别为检验检查
  4612. if p.TeamId > 0 { //检验检查组套
  4613. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4614. if tempLabel.ID == 0 {
  4615. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4616. label.Number = tempPrescription.PrescriptionNumber
  4617. label.ProjectId = project.ID
  4618. label.Status = 1
  4619. label.IsPrint = 2
  4620. label.DoctorId = info.DoctorId
  4621. label.UserOrgId = p.UserOrgId
  4622. label.PatientId = patient_id
  4623. label.RecordDate = recordDateTime
  4624. label.Ctime = time.Now().Unix()
  4625. label.Mtime = time.Now().Unix()
  4626. label.ItemId = p.TeamId
  4627. label.FeedetlSn = p.FeedetlSn
  4628. label.PProjectId = p.ID
  4629. label.ProjectName = team.ProjectTeam
  4630. label.PatientName = patient.Name
  4631. service.CreateHisLabelRecord(&label)
  4632. }
  4633. } else { //单条检验检查项目
  4634. label.Number = tempPrescription.PrescriptionNumber
  4635. label.ProjectId = project.ID
  4636. label.Status = 1
  4637. label.DoctorId = info.DoctorId
  4638. label.UserOrgId = p.UserOrgId
  4639. label.PatientId = patient_id
  4640. label.RecordDate = recordDateTime
  4641. label.IsPrint = 2
  4642. label.Ctime = time.Now().Unix()
  4643. label.Mtime = time.Now().Unix()
  4644. label.FeedetlSn = p.FeedetlSn
  4645. label.PProjectId = p.ID
  4646. label.ItemId = p.TeamId
  4647. label.ProjectName = project.ProjectName
  4648. label.PatientName = patient.Name
  4649. service.CreateHisLabelRecord(&label)
  4650. }
  4651. }
  4652. }
  4653. }
  4654. service.CreateNewHisProjectTwo(&p, tx)
  4655. var randNum int
  4656. randNum = rand.Intn(10000) + 1000
  4657. timestamp := time.Now().Unix()
  4658. tempTime := time.Unix(timestamp, 0)
  4659. timeFormat := tempTime.Format("20060102150405")
  4660. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4661. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4662. if goodBase.ID > 0 {
  4663. tx.Rollback()
  4664. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4665. return
  4666. }
  4667. service.CreateNewHisProjectTwo(&p, tx)
  4668. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4669. //查询剩余库存
  4670. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4671. var sum_count int64
  4672. for _, item := range goodList {
  4673. sum_count += item.StockCount
  4674. }
  4675. //更新剩余库存
  4676. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4677. //耗材
  4678. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4679. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4680. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4681. if len(outInfoTwo) > 0 {
  4682. for _, item := range outInfoTwo {
  4683. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4684. }
  4685. }
  4686. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4687. if len(drugAutoDetail) > 0 {
  4688. for _, item := range drugAutoDetail {
  4689. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4690. }
  4691. }
  4692. tx.Commit()
  4693. }
  4694. }
  4695. }
  4696. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4697. // addition := items["addition"].([]interface{})
  4698. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4699. // ctime := time.Now().Unix()
  4700. // mtime := ctime
  4701. // if len(addition) > 0 {
  4702. // for _, item := range addition {
  4703. // var s models.HisAdditionalCharge
  4704. // s.PrescriptionId = tempPrescription.ID
  4705. // s.Status = 1
  4706. // s.UserOrgId = adminInfo.CurrentOrgId
  4707. // s.RecordDate = recordDateTime
  4708. // s.CreatedTime = ctime
  4709. // s.UpdatedTime = mtime
  4710. // s.PatientId = patient_id
  4711. // s.HisPatientId = his_patient_id
  4712. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4713. // if errcode > 0 {
  4714. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4715. // return
  4716. // }
  4717. // service.CreateAdditionalCharge(&s)
  4718. // var randNum int
  4719. // randNum = rand.Intn(10000) + 1000
  4720. // timestamp := time.Now().Unix()
  4721. // tempTime := time.Unix(timestamp, 0)
  4722. // timeFormat := tempTime.Format("20060102150405")
  4723. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4724. // service.CreateAdditionalCharge(&s)
  4725. //
  4726. // }
  4727. // }
  4728. //}
  4729. }
  4730. }
  4731. }
  4732. tx.Commit()
  4733. if err == nil {
  4734. c.ServeSuccessJSON(map[string]interface{}{
  4735. "msg": "保存成功",
  4736. })
  4737. return
  4738. } else {
  4739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4740. return
  4741. }
  4742. } else {
  4743. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4744. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4745. var tempPrescription *models.HisPrescription
  4746. if len(prescriptions) > 0 {
  4747. for _, item := range prescriptions {
  4748. items := item.(map[string]interface{})
  4749. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4750. utils.ErrorLog("id")
  4751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4752. return
  4753. }
  4754. id := int64(items["id"].(float64))
  4755. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4756. tempPrescription = &new_prescription
  4757. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4758. utils.ErrorLog("type")
  4759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4760. return
  4761. }
  4762. types := int64(items["type"].(float64))
  4763. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4764. utils.ErrorLog("med_type")
  4765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4766. return
  4767. }
  4768. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4769. if med_type == "0" {
  4770. med_type = "14"
  4771. }
  4772. //if order_status == 0 {
  4773. // order_status = 1
  4774. //}
  4775. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4776. // utils.ErrorLog("diagnoses")
  4777. //}
  4778. diagnoses, _ := items["diagnoses"].(string)
  4779. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4780. utils.ErrorLog("pre_time")
  4781. }
  4782. preTime, _ := items["pre_time"].(string)
  4783. timeLayout := "2006-01-02"
  4784. loc, _ := time.LoadLocation("Local")
  4785. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4786. //result := strings.Split(preTime, " ")
  4787. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4788. if err != nil {
  4789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4790. return
  4791. }
  4792. pTime := theTime2.Unix()
  4793. ctime := time.Now().Unix()
  4794. if tempPrescription.ID == 0 {
  4795. prescription := &models.HisPrescription{
  4796. ID: 0,
  4797. PatientId: patient_id,
  4798. UserOrgId: adminInfo.CurrentOrgId,
  4799. RecordDate: recordDateTime,
  4800. Ctime: ctime,
  4801. Mtime: ctime,
  4802. Type: types,
  4803. Modifier: adminInfo.AdminUser.Id,
  4804. Creator: adminInfo.AdminUser.Id,
  4805. Status: 1,
  4806. Doctor: role.UserName,
  4807. HisPatientId: his_patient_id,
  4808. OrderStatus: 1,
  4809. BatchNumber: "",
  4810. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4811. PreTime: pTime,
  4812. PType: p_type,
  4813. MedType: med_type,
  4814. Diagnose: diagnoses,
  4815. }
  4816. tempPrescription = prescription
  4817. service.SaveHisPrescription(tempPrescription)
  4818. redis := service.RedisClient()
  4819. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4820. redis.Set(key, "", time.Second)
  4821. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4822. redis.Set(keyOne, "", time.Second)
  4823. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4824. redis.Set(keySeven, "", time.Second)
  4825. defer redis.Close()
  4826. } else {
  4827. tempPrescription.ID = id
  4828. tempPrescription.Type = types
  4829. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4830. tempPrescription.Mtime = time.Now().Unix()
  4831. tempPrescription.Doctor = role.UserName
  4832. //tempPrescription.OrderStatus = order_status
  4833. tempPrescription.PreTime = pTime
  4834. tempPrescription.MedType = med_type
  4835. tempPrescription.Diagnose = diagnoses
  4836. service.SaveHisPrescription(tempPrescription)
  4837. redis := service.RedisClient()
  4838. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4839. redis.Set(key, "", time.Second)
  4840. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4841. redis.Set(keyOne, "", time.Second)
  4842. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4843. redis.Set(keySeven, "", time.Second)
  4844. defer redis.Close()
  4845. }
  4846. //service.SaveHisPrescription(prescription)
  4847. //更改患者挂号状态
  4848. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4849. fmt.Println("更改失败", err2)
  4850. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4851. advices := items["advices"].([]interface{})
  4852. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4853. groupNo := int64(0)
  4854. if len(advices) > 0 {
  4855. for _, advice := range advices {
  4856. var s models.HisDoctorAdviceInfo
  4857. s.PrescriptionId = tempPrescription.ID
  4858. s.AdviceType = 2
  4859. s.AdviceDoctor = doctor_id
  4860. s.StopState = 2
  4861. s.ExecutionState = 2
  4862. s.AdviceDate = theTime3.Unix()
  4863. s.Status = 1
  4864. s.UserOrgId = adminInfo.CurrentOrgId
  4865. s.RecordDate = theTime3.Unix()
  4866. s.StartTime = tempPrescription.PreTime
  4867. s.Groupno = groupNo
  4868. s.PatientId = patient_id
  4869. s.HisPatientId = his_patient_id
  4870. s.StartTime = pTime
  4871. s.IsSettle = 2
  4872. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4873. if errcode > 0 {
  4874. c.ServeFailJSONWithSGJErrorCode(errcode)
  4875. return
  4876. }
  4877. s.StartTime = pTime
  4878. var total_count int64 //处方总库存
  4879. //查询改药品信息
  4880. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  4881. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  4882. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4883. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4884. total_count += prescribingNumberSeven * medical.MinNumber
  4885. }
  4886. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4887. total_count += prescribingNumberSeven
  4888. }
  4889. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4890. total_count += prescribingNumberSeven
  4891. }
  4892. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4893. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4894. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4895. if s.Price != lastWarehouse.RetailPrice {
  4896. s.Price = lastWarehouse.RetailPrice
  4897. }
  4898. if s.Price == 0 {
  4899. if lastWarehouse.ID == 0 {
  4900. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4901. s.Price = lastWarehouseTwo.RetailPrice
  4902. }
  4903. }
  4904. }
  4905. if adminInfo.CurrentOrgId != 10206 {
  4906. if s.ID == 0 {
  4907. //查询改药品是否已经停用
  4908. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4909. if base.ID > 0 {
  4910. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4911. return
  4912. }
  4913. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4914. if drugMedical.SumCount == 0 {
  4915. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4916. return
  4917. }
  4918. }
  4919. }
  4920. //赤峰
  4921. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4922. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4923. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4924. if info.RetailPrice > 0 {
  4925. if s.DeliveryWay == "口服" {
  4926. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4927. s.Price = drug.RetailPrice
  4928. }
  4929. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4930. s.Price = info.RetailPrice
  4931. }
  4932. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4933. s.Price = info.RetailPrice
  4934. }
  4935. }
  4936. }
  4937. }
  4938. service.CreateHisDoctorAdvice(&s)
  4939. //记录日志
  4940. byterequest, _ := json.Marshal(s)
  4941. adviceLog := models.XtDoctorAdviceLog{
  4942. UserOrgId: s.UserOrgId,
  4943. PatientId: s.PatientId,
  4944. AdminUserId: adminInfo.AdminUser.Id,
  4945. Module: 1,
  4946. ErrLog: string(byterequest),
  4947. Status: 1,
  4948. Ctime: time.Now().Unix(),
  4949. Mtime: 0,
  4950. Source: "电脑端新建his医嘱",
  4951. RecordDate: s.AdviceDate,
  4952. }
  4953. service.CreateDoctorAdviceLog(adviceLog)
  4954. //存储切片中
  4955. adviceList = append(adviceList, s)
  4956. redis := service.RedisClient()
  4957. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4958. redis.Set(key, "", time.Second)
  4959. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4960. redis.Set(keyOne, "", time.Second)
  4961. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4962. redis.Set(keySeven, "", time.Second)
  4963. var randNum int
  4964. randNum = rand.Intn(10000) + 1000
  4965. timestamp := time.Now().Unix()
  4966. tempTime := time.Unix(timestamp, 0)
  4967. timeFormat := tempTime.Format("20060102150405")
  4968. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4969. service.CreateHisDoctorAdvice(&s)
  4970. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4971. redis.Set(keySix, "", time.Second)
  4972. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4973. redis.Set(keyFive, "", time.Second)
  4974. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4975. redis.Set(keyEight, "", time.Second)
  4976. defer redis.Close()
  4977. }
  4978. }
  4979. }
  4980. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4981. projects := items["project"].([]interface{})
  4982. if len(projects) > 0 {
  4983. for _, project := range projects {
  4984. var p models.HisPrescriptionProject
  4985. p.PrescriptionId = tempPrescription.ID
  4986. p.PatientId = patient_id
  4987. p.RecordDate = theTime3.Unix()
  4988. p.Doctor = doctor_id
  4989. p.UserOrgId = adminInfo.CurrentOrgId
  4990. p.HisPatientId = his_patient_id
  4991. p.Status = 1
  4992. p.StartTime = pTime
  4993. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4994. if errcode > 0 {
  4995. c.ServeFailJSONWithSGJErrorCode(errcode)
  4996. return
  4997. }
  4998. if p.ID == 0 {
  4999. p.IsOut = 2
  5000. }
  5001. if p.ID > 0 {
  5002. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  5003. p.IsOut = projectDetail.IsOut
  5004. }
  5005. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5006. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5007. if p.Type == 3 {
  5008. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  5009. if p.Price != lastWarehouse.PackingPrice {
  5010. p.Price = lastWarehouse.PackingPrice
  5011. }
  5012. if p.Price == 0 {
  5013. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  5014. p.Price = lastWarehouseTwo.PackingPrice
  5015. }
  5016. if p.Unit == "" {
  5017. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5018. p.Unit = goodInfoOne.PackingUnit
  5019. }
  5020. }
  5021. }
  5022. if adminInfo.CurrentOrgId != 10206 {
  5023. if p.Type == 3 {
  5024. if p.ID == 0 {
  5025. //查询该耗材是否停用
  5026. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  5027. //表示该耗材已经停用,不能保存
  5028. if goodInfoSeven.ID == 0 {
  5029. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5030. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  5031. return
  5032. }
  5033. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5034. if goodInfoOne.SumCount == 0 {
  5035. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  5036. return
  5037. }
  5038. }
  5039. }
  5040. }
  5041. service.CreateHisProjectTwo(&p)
  5042. //记录日志
  5043. byterequest, _ := json.Marshal(p)
  5044. adviceLog := models.XtDoctorAdviceLog{
  5045. UserOrgId: p.UserOrgId,
  5046. PatientId: p.PatientId,
  5047. AdminUserId: adminInfo.AdminUser.Id,
  5048. Module: 1,
  5049. ErrLog: string(byterequest),
  5050. Status: 1,
  5051. Ctime: time.Now().Unix(),
  5052. Mtime: 0,
  5053. Source: "电脑端新建his项目",
  5054. RecordDate: p.RecordDate,
  5055. }
  5056. service.CreateDoctorAdviceLog(adviceLog)
  5057. projectList = append(projectList, p)
  5058. var randNum int
  5059. randNum = rand.Intn(10000) + 1000
  5060. timestamp := time.Now().Unix()
  5061. tempTime := time.Unix(timestamp, 0)
  5062. timeFormat := tempTime.Format("20060102150405")
  5063. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  5064. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  5065. //新增或者编辑项目,修改对应的标签数据
  5066. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  5067. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  5068. var label models.HisLabelPrintInfo
  5069. project, _ := service.GetProjectDetail(p.ProjectId)
  5070. if project.CostClassify == 3 { //类别为检验检查
  5071. if p.TeamId > 0 { //检验检查组套
  5072. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  5073. if tempLabel.ID == 0 {
  5074. team, _ := service.GetProjectTeamDetail(p.TeamId)
  5075. label.Number = tempPrescription.PrescriptionNumber
  5076. label.ProjectId = project.ID
  5077. label.Status = 1
  5078. label.IsPrint = 2
  5079. label.DoctorId = info.DoctorId
  5080. label.UserOrgId = p.UserOrgId
  5081. label.PatientId = patient_id
  5082. label.RecordDate = recordDateTime
  5083. label.Ctime = time.Now().Unix()
  5084. label.Mtime = time.Now().Unix()
  5085. label.ItemId = p.TeamId
  5086. label.FeedetlSn = p.FeedetlSn
  5087. label.PProjectId = p.ID
  5088. label.ProjectName = team.ProjectTeam
  5089. label.PatientName = patient.Name
  5090. service.CreateHisLabelRecord(&label)
  5091. }
  5092. } else { //单条检验检查项目
  5093. label.Number = tempPrescription.PrescriptionNumber
  5094. label.ProjectId = project.ID
  5095. label.Status = 1
  5096. label.DoctorId = info.DoctorId
  5097. label.UserOrgId = p.UserOrgId
  5098. label.PatientId = patient_id
  5099. label.RecordDate = recordDateTime
  5100. label.IsPrint = 2
  5101. label.Ctime = time.Now().Unix()
  5102. label.Mtime = time.Now().Unix()
  5103. label.FeedetlSn = p.FeedetlSn
  5104. label.PProjectId = p.ID
  5105. label.ItemId = p.TeamId
  5106. label.ProjectName = project.ProjectName
  5107. label.PatientName = patient.Name
  5108. service.CreateHisLabelRecord(&label)
  5109. }
  5110. }
  5111. }
  5112. }
  5113. service.SaveHisProjectTwo(&p)
  5114. }
  5115. }
  5116. }
  5117. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5118. // addition := items["addition"].([]interface{})
  5119. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5120. // ctime := time.Now().Unix()
  5121. // mtime := ctime
  5122. // if len(addition) > 0 {
  5123. // for _, item := range addition {
  5124. // var s models.HisAdditionalCharge
  5125. // s.PrescriptionId = tempPrescription.ID
  5126. // s.Status = 1
  5127. // s.UserOrgId = adminInfo.CurrentOrgId
  5128. // s.RecordDate = recordDateTime
  5129. // s.CreatedTime = ctime
  5130. // s.UpdatedTime = mtime
  5131. // s.PatientId = patient_id
  5132. // s.HisPatientId = his_patient_id
  5133. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5134. // if errcode > 0 {
  5135. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5136. // return
  5137. // }
  5138. // service.CreateAdditionalCharge(&s)
  5139. // var randNum int
  5140. // randNum = rand.Intn(10000) + 1000
  5141. // timestamp := time.Now().Unix()
  5142. // tempTime := time.Unix(timestamp, 0)
  5143. // timeFormat := tempTime.Format("20060102150405")
  5144. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  5145. // service.CreateAdditionalCharge(&s)
  5146. //
  5147. // }
  5148. // }
  5149. //}
  5150. }
  5151. }
  5152. //查询今日该患者开的药品处方
  5153. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5154. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  5155. //药品出库
  5156. if drugOutConfig.IsOpen == 1 {
  5157. for _, item := range hisdoctorlist {
  5158. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  5159. // 查询该药品最后一次出库记录
  5160. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  5161. if len(druginfo) > 0 {
  5162. //回退库存
  5163. for _, it := range druginfo {
  5164. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5165. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5166. }
  5167. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5168. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5169. }
  5170. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5171. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5172. }
  5173. }
  5174. }
  5175. //删除记录
  5176. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  5177. //查询最后一次数据
  5178. if drugOutConfig.IsOpen == 1 {
  5179. //出库
  5180. if drug.IsUse == 2 {
  5181. creater := adminInfo.AdminUser.Id
  5182. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  5183. }
  5184. //更新字典里面的库存
  5185. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5186. var sum_count int64
  5187. for _, its := range stockInfo {
  5188. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5189. if its.MaxUnit == baseDrug.MaxUnit {
  5190. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5191. }
  5192. sum_count += its.StockMaxNumber + its.StockMinNumber
  5193. }
  5194. //更新基础库存
  5195. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5196. //剩余库存
  5197. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  5198. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  5199. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  5200. }
  5201. }
  5202. }
  5203. //耗材保存处方出库
  5204. if goodOutConfig.IsOpen == 1 {
  5205. //查询今日耗材出库数量
  5206. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5207. for _, item := range hisgoodlist {
  5208. //查询历史出库数据
  5209. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5210. var out_count_five int64
  5211. for _, item := range flowGood {
  5212. out_count_five += item.Count
  5213. }
  5214. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  5215. if out_count_five != parseIntCount {
  5216. //查询耗材最后一次出库记录
  5217. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  5218. //查询默认出库仓库库存
  5219. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5220. if len(wareOut) > 0 {
  5221. for _, it := range wareOut {
  5222. //回退库存
  5223. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  5224. //删除出库记录
  5225. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  5226. }
  5227. }
  5228. timeStr := time.Now().Format("2006-01-02")
  5229. timeArr := strings.Split(timeStr, "-")
  5230. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  5231. total = total + 1
  5232. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5233. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5234. number = number + total
  5235. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5236. operation_time := time.Now().Unix()
  5237. creater := c.GetAdminUserInfo().AdminUser.Id
  5238. recordDateStr := time.Now().Format("2006-01-02")
  5239. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5240. nowtime := recordDate.Unix()
  5241. warehouseOut := models.WarehouseOut{
  5242. WarehouseOutOrderNumber: warehousing_out_order,
  5243. OperationTime: operation_time,
  5244. OrgId: adminInfo.CurrentOrgId,
  5245. Creater: creater,
  5246. Ctime: time.Now().Unix(),
  5247. Status: 1,
  5248. WarehouseOutTime: nowtime,
  5249. Type: 1,
  5250. StorehouseId: storeConfig.StorehouseOutInfo,
  5251. IsCheck: 1,
  5252. IsSys: 1,
  5253. }
  5254. //查询是否生成出库单
  5255. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5256. if out.ID == 0 {
  5257. service.AddSigleWarehouseOutOne(&warehouseOut)
  5258. }
  5259. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5260. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5261. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5262. dialyPrepareOne := models.DialysisBeforePrepare{
  5263. GoodTypeId: goodObj.GoodTypeId,
  5264. GoodId: item.ProjectId,
  5265. PatientId: item.PatientId,
  5266. RecordDate: item.RecordDate,
  5267. UserOrgId: adminInfo.CurrentOrgId,
  5268. Count: parseIntCount,
  5269. Ctime: time.Now().Unix(),
  5270. Creater: creater,
  5271. Status: 1,
  5272. StorehouseId: houseConfig.StorehouseOutInfo,
  5273. ProjectId: item.ID,
  5274. }
  5275. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5276. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5277. //查询历史出库数据
  5278. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5279. var out_count int64
  5280. for _, item := range flowGood {
  5281. out_count += item.Count
  5282. }
  5283. //如果历史数和当前数据不想等才进行退库出库
  5284. if out_count != parseIntCount {
  5285. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5286. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5287. detail := models.AutomaticReduceDetail{
  5288. WarehouseOutId: 0,
  5289. WarehouseOutOrderNumber: "",
  5290. PatientId: item.PatientId,
  5291. Ctime: time.Now().Unix(),
  5292. Mtime: 0,
  5293. Status: 1,
  5294. RecordTime: item.RecordDate,
  5295. OrgId: item.UserOrgId,
  5296. GoodId: item.ProjectId,
  5297. GoodTypeId: 0,
  5298. Count: parseIntCount,
  5299. Type: 0,
  5300. ProjectId: item.ID,
  5301. StorehouseId: 0,
  5302. }
  5303. service.CreateAutoDetail(detail)
  5304. //查询剩余库存
  5305. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5306. var sum_count int64
  5307. for _, item := range goodList {
  5308. sum_count += item.StockCount
  5309. }
  5310. //更新剩余库存
  5311. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5312. //耗材
  5313. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5314. }
  5315. }
  5316. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5317. //查询历史出库数据
  5318. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5319. var out_count int64
  5320. for _, item := range flowGood {
  5321. out_count += item.Count
  5322. }
  5323. //如果历史数和当前数据不想等才进行退库出库
  5324. if out_count != parseIntCount {
  5325. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5326. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5327. detail := models.AutomaticReduceDetail{
  5328. WarehouseOutId: 0,
  5329. WarehouseOutOrderNumber: "",
  5330. PatientId: item.PatientId,
  5331. Ctime: time.Now().Unix(),
  5332. Mtime: 0,
  5333. Status: 1,
  5334. RecordTime: item.RecordDate,
  5335. OrgId: item.UserOrgId,
  5336. GoodId: item.ProjectId,
  5337. GoodTypeId: 0,
  5338. Count: parseIntCount,
  5339. Type: 0,
  5340. ProjectId: item.ID,
  5341. StorehouseId: 0,
  5342. }
  5343. service.CreateAutoDetail(detail)
  5344. //查询剩余库存
  5345. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5346. var sum_count int64
  5347. for _, item := range goodList {
  5348. sum_count += item.StockCount
  5349. }
  5350. //更新剩余库存
  5351. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5352. //耗材
  5353. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5354. }
  5355. }
  5356. }
  5357. }
  5358. }
  5359. ////同步到自备药
  5360. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5361. if selfPrescriptionOpen.IsOpen == 1 {
  5362. timeStr := time.Now().Format("2006-01-02")
  5363. timeArr := strings.Split(timeStr, "-")
  5364. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5365. total = total + 1
  5366. operation_time := time.Now().Unix()
  5367. creater := adminInfo.AdminUser.Id
  5368. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5369. warehousing := models.XtSelfDrugWarehouse{
  5370. WarehousingOrder: warehousing_order,
  5371. OperationTime: operation_time,
  5372. OrgId: adminInfo.CurrentOrgId,
  5373. Creater: creater,
  5374. Ctime: time.Now().Unix(),
  5375. Status: 1,
  5376. WarehousingTime: recordDateTime,
  5377. Type: 0,
  5378. StorehouseId: 0,
  5379. IsCheck: 1,
  5380. PatientId: patient_id,
  5381. IsSys: 1,
  5382. }
  5383. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5384. if selfDrugWarehouse.ID == 0 {
  5385. service.AddSelfDrugWarehouse(&warehousing, tx)
  5386. }
  5387. if selfDrugWarehouse.ID > 0 {
  5388. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5389. }
  5390. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5391. fmt.Println(info)
  5392. for _, item := range hisdoctorlist {
  5393. //查询该病人的该药品是否已经入库
  5394. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5395. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5396. var in_count int64
  5397. if len(selfdruginfo) > 0 {
  5398. for _, item := range selfdruginfo {
  5399. var in_count_one int64
  5400. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5401. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5402. }
  5403. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5404. in_count_one = item.WarehousingCount
  5405. }
  5406. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5407. in_count_one = item.WarehousingCount
  5408. }
  5409. in_count += in_count_one
  5410. }
  5411. }
  5412. if selfBasedrug.IsSelfDrug == 1 {
  5413. var total_count int64
  5414. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5415. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5416. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5417. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5418. }
  5419. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5420. total_count += prescribingNumberSeven
  5421. }
  5422. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5423. total_count += prescribingNumberSeven
  5424. }
  5425. //入库
  5426. if total_count > in_count {
  5427. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5428. WarehousingOrder: warehousing_order,
  5429. WarehousingId: info.ID,
  5430. DrugId: item.DrugId,
  5431. Number: "",
  5432. ProductDate: 0,
  5433. ExpiryDate: 0,
  5434. WarehousingCount: total_count - in_count,
  5435. WarehouseingUnit: selfBasedrug.MinUnit,
  5436. Price: 0,
  5437. TotalPrice: 0,
  5438. Status: 1,
  5439. Ctime: time.Now().Unix(),
  5440. Remark: "",
  5441. OrgId: adminInfo.CurrentOrgId,
  5442. Type: 0,
  5443. Manufacturer: selfBasedrug.Manufacturer,
  5444. Dealer: selfBasedrug.Dealer,
  5445. StockMaxNumber: total_count - in_count,
  5446. RetailTotalPrice: 0,
  5447. BatchNumber: "",
  5448. MaxUnit: selfBasedrug.MinUnit,
  5449. MinUnit: selfBasedrug.MinUnit,
  5450. RetailPrice: 0,
  5451. StorehouseId: 0,
  5452. IsCheck: 1,
  5453. StockMinNumber: 0,
  5454. PatientId: patient_id,
  5455. IsSys: 1,
  5456. RecordDate: item.RecordDate,
  5457. AdviceId: item.ID,
  5458. }
  5459. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5460. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5461. Creator := adminInfo.AdminUser.Id
  5462. //查询默认仓库剩余多少库存
  5463. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5464. var sum_count int64
  5465. for _, it := range list {
  5466. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5467. if it.MaxUnit == baseDrug.MaxUnit {
  5468. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5469. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5470. }
  5471. sum_count += it.StockMaxNumber + it.StockMinNumber
  5472. }
  5473. flow := &models.XtSelfDrugFlow{
  5474. WarehousingId: info.ID,
  5475. DrugId: item.DrugId,
  5476. Number: "",
  5477. BatchNumber: "",
  5478. Count: total_count - in_count,
  5479. UserOrgId: adminInfo.CurrentOrgId,
  5480. PatientId: item.PatientId,
  5481. SystemTime: time.Now().Unix(),
  5482. ConsumableType: 1,
  5483. IsSys: 1,
  5484. WarehousingOrder: warehousing_order,
  5485. WarehouseOutId: 0,
  5486. WarehouseOutOrderNumber: "",
  5487. IsEdit: 0,
  5488. CancelStockId: 0,
  5489. CancelOrderNumber: "",
  5490. Manufacturer: selfBasedrug.Manufacturer,
  5491. Dealer: selfBasedrug.Dealer,
  5492. Creator: Creator,
  5493. UpdateCreator: Creator,
  5494. Status: 1,
  5495. Ctime: item.AdviceDate,
  5496. Mtime: 0,
  5497. Price: item.Price,
  5498. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5499. WarehouseOutDetailId: 0,
  5500. CancelOutDetailId: 0,
  5501. ExpireDate: 0,
  5502. ProductDate: 0,
  5503. MaxUnit: selfBasedrug.MinUnit,
  5504. MinUnit: selfBasedrug.MinUnit,
  5505. StorehouseId: 0,
  5506. OverCount: sum_count,
  5507. OperateTime: time.Now().Unix(),
  5508. AdviceId: item.ID,
  5509. }
  5510. service.CreateSelfDrugFlow(flow, tx)
  5511. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5512. var total_count int64 // 入库总数量
  5513. var over_count int64 //剩余库存
  5514. for _, it := range drugInfolist {
  5515. if it.MaxUnit == selfBasedrug.MaxUnit {
  5516. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5517. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5518. }
  5519. }
  5520. for _, it := range drugInfolist {
  5521. total_count += it.WarehousingCount
  5522. over_count += it.StockMaxNumber + it.StockMinNumber
  5523. }
  5524. //查询该仓库是否有默认数据
  5525. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5526. if selfDrugStock.ID == 0 {
  5527. drugStock := models.XtSelfDrugStockCount{
  5528. UserOrgId: item.UserOrgId,
  5529. PatientId: item.PatientId,
  5530. SumInCount: total_count,
  5531. SumOutCount: 0,
  5532. SumCancelCount: 0,
  5533. DrugId: item.DrugId,
  5534. Ctime: time.Now().Unix(),
  5535. Mtime: 0,
  5536. Status: 1,
  5537. FlushCount: over_count,
  5538. SumActOutCount: 0,
  5539. }
  5540. service.CreateSelfDrugStockSum(drugStock, tx)
  5541. }
  5542. if selfDrugStock.ID > 0 {
  5543. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5544. }
  5545. }
  5546. //查询这个单据的出库数量
  5547. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5548. var his_out_count int64
  5549. for _, item := range drugFlowList {
  5550. his_out_count += item.Count
  5551. }
  5552. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5553. if (total_count + his_out_count) <= in_count {
  5554. // 出库
  5555. if total_count < in_count {
  5556. var cha_count int64
  5557. cha_count = in_count - total_count
  5558. var stock_number int64 = 0
  5559. //查询库存是否充足
  5560. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5561. // 将该批次的剩余库存数量转换为拆零数量
  5562. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5563. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5564. }
  5565. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5566. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5567. }
  5568. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5569. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5570. }
  5571. if stock_number >= cha_count {
  5572. var maxNumber int64 = 0
  5573. var minNumber int64 = 0
  5574. maxNumber = cha_count / selfBasedrug.MinNumber
  5575. minNumber = cha_count % selfBasedrug.MinNumber
  5576. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5577. minNumber = maxNumber
  5578. }
  5579. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5580. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5582. return
  5583. }
  5584. }
  5585. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5586. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5587. }
  5588. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5589. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5590. }
  5591. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5592. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5593. }
  5594. if warehouse.StockMaxNumber < 0 {
  5595. warehouse.StockMaxNumber = 0
  5596. }
  5597. if warehouse.StockMinNumber < 0 {
  5598. warehouse.StockMinNumber = 0
  5599. }
  5600. warehouse.Mtime = time.Now().Unix()
  5601. if warehouse.StockMinNumber < minNumber {
  5602. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5603. if warehouse.MaxUnit != warehouse.MinUnit {
  5604. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5605. }
  5606. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5607. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5608. }
  5609. } else {
  5610. if minNumber > 0 {
  5611. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5612. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5613. }
  5614. }
  5615. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5616. if warehouse.StockMinNumber > 0 {
  5617. if warehouse.StockMinNumber-cha_count >= 0 {
  5618. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5619. }
  5620. }
  5621. }
  5622. }
  5623. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5624. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5625. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5626. }
  5627. }
  5628. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5629. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5631. return
  5632. }
  5633. }
  5634. if warehouse.StockMinNumber <= 0 {
  5635. warehouse.StockMinNumber = 0
  5636. }
  5637. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5638. //查询该药品剩余库存
  5639. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5640. var over_count int64
  5641. for _, its := range infolist {
  5642. if its.MaxUnit == selfBasedrug.MaxUnit {
  5643. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5644. }
  5645. over_count += its.StockMaxNumber + its.StockMinNumber
  5646. }
  5647. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5648. drugflow := models.XtSelfDrugFlow{
  5649. WarehouseOutId: 0,
  5650. WarehouseOutOrderNumber: warehousing_order,
  5651. WarehousingOrder: warehousing_order,
  5652. DrugId: item.DrugId,
  5653. Number: warehouse.Number,
  5654. ProductDate: warehouse.ProductDate,
  5655. ExpireDate: warehouse.ExpiryDate,
  5656. Count: cha_count,
  5657. Price: warehouse.RetailPrice,
  5658. Status: 1,
  5659. Ctime: item.AdviceDate,
  5660. Mtime: time.Now().Unix(),
  5661. UserOrgId: item.UserOrgId,
  5662. Manufacturer: warehouse.Manufacturer,
  5663. Dealer: warehouse.Dealer,
  5664. BatchNumber: warehouse.BatchNumber,
  5665. MaxUnit: selfBasedrug.MinUnit,
  5666. ConsumableType: 20,
  5667. IsEdit: 1,
  5668. Creator: 0,
  5669. IsSys: 3,
  5670. WarehouseOutDetailId: drugWareInfo.ID,
  5671. AdviceId: item.ID,
  5672. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5673. StorehouseId: 0,
  5674. AdminUserId: creater,
  5675. LastPrice: warehouse.Price,
  5676. StockCount: "",
  5677. WarehousingDetailId: 0,
  5678. OverCount: over_count,
  5679. RetailPrice: item.Price, //手动出库出库价格
  5680. WarehousingId: warehouse.ID,
  5681. SystemTime: item.AdviceDate,
  5682. PatientId: item.PatientId,
  5683. Remark: "保存处方入库数据差",
  5684. OperateTime: time.Now().Unix(),
  5685. }
  5686. if warehouse.RetailPrice == 0 {
  5687. drugflow.Price = item.Price
  5688. }
  5689. service.CreateSelfDrugFlowOne(drugflow, tx)
  5690. var out_count int64
  5691. out_count = in_count - total_count
  5692. //
  5693. //fmt.Println("in_count------------------", in_count)
  5694. //fmt.Println("total_count------------------", total_count)
  5695. //添加出库数量
  5696. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5697. //查询剩余库存
  5698. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5699. var sum_count int64
  5700. for _, its := range stockInfo {
  5701. if its.MaxUnit == selfBasedrug.MaxUnit {
  5702. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5703. }
  5704. sum_count += its.StockMaxNumber + its.StockMinNumber
  5705. }
  5706. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5707. } else {
  5708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5709. return
  5710. }
  5711. }
  5712. }
  5713. }
  5714. }
  5715. }
  5716. }
  5717. tx.Commit()
  5718. if err == nil {
  5719. c.ServeSuccessJSON(map[string]interface{}{
  5720. "msg": "保存成功",
  5721. })
  5722. return
  5723. } else {
  5724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5725. return
  5726. }
  5727. }
  5728. }
  5729. //func (c *HisApiController) EditHisPrescription() {
  5730. // record_date := c.GetString("record_date")
  5731. // patient_id, _ := c.GetInt64("patient_id")
  5732. // reg_type, _ := c.GetInt64("reg_type")
  5733. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5734. // diagnose := c.GetString("diagnose")
  5735. // sick_type, _ := c.GetInt64("sick_type")
  5736. // sick_history := c.GetString("sick_history")
  5737. // doctor_id, _ := c.GetInt64("doctor", 0)
  5738. // department, _ := c.GetInt64("department", 0)
  5739. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5740. // p_type, _ := c.GetInt64("p_type")
  5741. //
  5742. // dataBody := make(map[string]interface{}, 0)
  5743. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5744. // if err != nil {
  5745. // utils.ErrorLog(err.Error())
  5746. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5747. // return
  5748. // }
  5749. //
  5750. // timeLayout := "2006-01-02"
  5751. // loc, _ := time.LoadLocation("Local")
  5752. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5753. // if err != nil {
  5754. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5755. // return
  5756. // }
  5757. // adminInfo := c.GetAdminUserInfo()
  5758. // recordDateTime := theTime.Unix()
  5759. //
  5760. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5761. //
  5762. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5763. // var hpInfo models.HisPrescriptionInfo
  5764. // if info.ID == 0 {
  5765. // var randNum int
  5766. // randNum = rand.Intn(10000) + 1000
  5767. // timestamp := time.Now().Unix()
  5768. // tempTime := time.Unix(timestamp, 0)
  5769. // timeFormat := tempTime.Format("20060102150405")
  5770. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5771. //
  5772. // hpInfo = models.HisPrescriptionInfo{
  5773. // UserOrgId: adminInfo.CurrentOrgId,
  5774. // RecordDate: theTime.Unix(),
  5775. // PatientId: patient_id,
  5776. // Status: 1,
  5777. // Ctime: time.Now().Unix(),
  5778. // Mtime: time.Now().Unix(),
  5779. // Creator: adminInfo.AdminUser.Id,
  5780. // Modifier: adminInfo.AdminUser.Id,
  5781. // Diagnosis: diagnose,
  5782. // SickHistory: sick_history,
  5783. // Departments: department,
  5784. // RegisterType: reg_type,
  5785. // PrescriptionNumber: p_number,
  5786. // PrescriptionStatus: 1,
  5787. // Doctor: role.UserName,
  5788. // DoctorId: doctor_id,
  5789. // SickType: sick_type,
  5790. // PType: p_type,
  5791. // }
  5792. // service.SavePatientPrescriptionInfo(hpInfo)
  5793. //
  5794. // } else {
  5795. // hpInfo = models.HisPrescriptionInfo{
  5796. // ID: info.ID,
  5797. // UserOrgId: adminInfo.CurrentOrgId,
  5798. // RecordDate: info.RecordDate,
  5799. // PatientId: info.PatientId,
  5800. // Status: 1,
  5801. // Ctime: info.Ctime,
  5802. // Mtime: time.Now().Unix(),
  5803. // Creator: info.Creator,
  5804. // Modifier: adminInfo.AdminUser.Id,
  5805. // Diagnosis: diagnose,
  5806. // SickHistory: sick_history,
  5807. // Departments: department,
  5808. // RegisterType: reg_type,
  5809. // PrescriptionNumber: info.PrescriptionNumber,
  5810. // Doctor: role.UserName,
  5811. // PrescriptionStatus: info.PrescriptionStatus,
  5812. // DoctorId: doctor_id,
  5813. // SickType: sick_type,
  5814. // PType: info.PType,
  5815. // }
  5816. // service.SavePatientPrescriptionInfo(hpInfo)
  5817. // }
  5818. //
  5819. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5820. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5821. //
  5822. // if len(prescriptions) > 0 {
  5823. // for _, item := range prescriptions {
  5824. // items := item.(map[string]interface{})
  5825. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5826. // utils.ErrorLog("id")
  5827. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5828. // return
  5829. // }
  5830. // id := int64(items["id"].(float64))
  5831. //
  5832. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5833. // utils.ErrorLog("type")
  5834. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5835. // return
  5836. // }
  5837. // types := int64(items["type"].(float64))
  5838. //
  5839. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5840. // utils.ErrorLog("med_type")
  5841. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5842. // return
  5843. // }
  5844. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5845. //
  5846. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5847. //
  5848. // ctime := time.Now().Unix()
  5849. //
  5850. // prescription := &models.HisPrescription{
  5851. // ID: id,
  5852. // PatientId: patient_id,
  5853. // UserOrgId: adminInfo.CurrentOrgId,
  5854. // RecordDate: recordDateTime,
  5855. // Ctime: ctime,
  5856. // Mtime: ctime,
  5857. // Type: types,
  5858. // Modifier: adminInfo.AdminUser.Id,
  5859. // Creator: adminInfo.AdminUser.Id,
  5860. // Status: 1,
  5861. // Doctor: role.UserName,
  5862. // HisPatientId: his_patient_id,
  5863. // OrderStatus: 1,
  5864. // BatchNumber: "",
  5865. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5866. // PType: hpInfo.PType,
  5867. // MedType: med_type,
  5868. // }
  5869. //
  5870. // if historyPrescription.ID > 0 {
  5871. // prescription.PreTime = historyPrescription.PreTime
  5872. //
  5873. // }
  5874. //
  5875. // service.SaveHisPrescription(prescription)
  5876. //
  5877. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5878. // advices := items["advices"].([]interface{})
  5879. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5880. // groupNo := int64(0)
  5881. // ctime := time.Now().Unix()
  5882. // mtime := ctime
  5883. // if len(advices) > 0 {
  5884. // for _, advice := range advices {
  5885. // var s models.HisDoctorAdviceInfo
  5886. // s.PrescriptionId = prescription.ID
  5887. // s.AdviceType = 2
  5888. // s.AdviceDoctor = adminInfo.AdminUser.Id
  5889. // s.StopState = 2
  5890. // s.ExecutionState = 2
  5891. // s.AdviceDate = recordDateTime
  5892. // s.Status = 1
  5893. // s.UserOrgId = adminInfo.CurrentOrgId
  5894. // s.RecordDate = recordDateTime
  5895. // s.StartTime = prescription.PreTime
  5896. // s.Groupno = groupNo
  5897. // s.CreatedTime = ctime
  5898. // s.UpdatedTime = mtime
  5899. // s.PatientId = patient_id
  5900. // s.HisPatientId = his_patient_id
  5901. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5902. // if errcode > 0 {
  5903. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5904. // return
  5905. // }
  5906. //
  5907. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5908. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5909. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5910. // if s.Price == 0 {
  5911. // s.Price = lastWarehouse.RetailPrice
  5912. // }
  5913. // }
  5914. //
  5915. // service.CreateHisDoctorAdvice(&s)
  5916. // //记录日志
  5917. // byterequest, _ := json.Marshal(s)
  5918. // adviceLog := models.XtDoctorAdviceLog{
  5919. // UserOrgId: s.UserOrgId,
  5920. // PatientId: s.PatientId,
  5921. // AdminUserId: adminInfo.AdminUser.Id,
  5922. // Module: 1,
  5923. // ErrLog: string(byterequest),
  5924. // Status: 1,
  5925. // Ctime: time.Now().Unix(),
  5926. // Mtime: 0,
  5927. // Source: "电脑端his医嘱修改",
  5928. // RecordDate: s.AdviceDate,
  5929. // }
  5930. // service.CreateDoctorAdviceLog(adviceLog)
  5931. // redis := service.RedisClient()
  5932. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5933. // redis.Set(key, "", time.Second)
  5934. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5935. // fmt.Println("keyOne", keyOne)
  5936. // redis.Set(keyOne, "", time.Second)
  5937. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5938. // redis.Set(keySeven, "", time.Second)
  5939. // redis.Close()
  5940. //
  5941. // }
  5942. // }
  5943. // }
  5944. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5945. // projects := items["project"].([]interface{})
  5946. // if len(projects) > 0 {
  5947. // for _, project := range projects {
  5948. // var p models.HisPrescriptionProject
  5949. // p.PrescriptionId = prescription.ID
  5950. // p.Ctime = time.Now().Unix()
  5951. // p.Mtime = time.Now().Unix()
  5952. // p.PatientId = patient_id
  5953. // p.RecordDate = recordDateTime
  5954. // p.UserOrgId = adminInfo.CurrentOrgId
  5955. // p.HisPatientId = his_patient_id
  5956. // p.Status = 1
  5957. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5958. // if errcode > 0 {
  5959. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5960. // return
  5961. // }
  5962. // service.CreateHisProjectTwo(&p)
  5963. //
  5964. // //记录日志
  5965. // byterequest, _ := json.Marshal(p)
  5966. // adviceLog := models.XtDoctorAdviceLog{
  5967. // UserOrgId: p.UserOrgId,
  5968. // PatientId: p.PatientId,
  5969. // AdminUserId: adminInfo.AdminUser.Id,
  5970. // Module: 1,
  5971. // ErrLog: string(byterequest),
  5972. // Status: 1,
  5973. // Ctime: time.Now().Unix(),
  5974. // Mtime: 0,
  5975. // Source: "电脑端his项目修改",
  5976. // RecordDate: p.RecordDate,
  5977. // }
  5978. // service.CreateDoctorAdviceLog(adviceLog)
  5979. // }
  5980. // }
  5981. // }
  5982. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5983. // addition := items["addition"].([]interface{})
  5984. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5985. // ctime := time.Now().Unix()
  5986. // mtime := ctime
  5987. // if len(addition) > 0 {
  5988. // for _, item := range addition {
  5989. // var s models.HisAdditionalCharge
  5990. // s.PrescriptionId = prescription.ID
  5991. // s.Status = 1
  5992. // s.UserOrgId = adminInfo.CurrentOrgId
  5993. // s.RecordDate = recordDateTime
  5994. // s.CreatedTime = ctime
  5995. // s.UpdatedTime = mtime
  5996. // s.PatientId = patient_id
  5997. // s.HisPatientId = his_patient_id
  5998. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5999. // if errcode > 0 {
  6000. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6001. // return
  6002. // }
  6003. // service.CreateAdditionalCharge(&s)
  6004. // }
  6005. // }
  6006. // }
  6007. //
  6008. // }
  6009. // }
  6010. // }
  6011. // if err == nil {
  6012. // c.ServeSuccessJSON(map[string]interface{}{
  6013. // "msg": "保存成功",
  6014. // })
  6015. // return
  6016. //
  6017. // } else {
  6018. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6019. // return
  6020. // }
  6021. //}
  6022. func (c *HisApiController) DeletePrescription() {
  6023. prescription_id, _ := c.GetInt64("id")
  6024. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  6025. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  6026. ////同步到自备药
  6027. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6028. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6029. if selfPrescriptionOpen.IsOpen == 1 {
  6030. // 在函数结束时处理事务回滚
  6031. db := service.XTWriteDB()
  6032. tx := db.Begin()
  6033. defer func() {
  6034. if r := recover(); r != nil {
  6035. tx.Rollback()
  6036. } else {
  6037. tx.Commit()
  6038. }
  6039. }()
  6040. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  6041. for _, item := range advicesList {
  6042. timeStr := time.Now().Format("2006-01-02")
  6043. timeArr := strings.Split(timeStr, "-")
  6044. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6045. total = total + 1
  6046. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6047. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6048. number = number + total
  6049. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6050. operation_time := time.Now().Unix()
  6051. creater := c.GetAdminUserInfo().AdminUser.Id
  6052. //创建一个出库单
  6053. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6054. WarehouseOutOrderNumber: warehousing_out_order,
  6055. OperationTime: operation_time,
  6056. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6057. Creater: creater,
  6058. Ctime: time.Now().Unix(),
  6059. Status: 1,
  6060. WarehouseOutTime: item.AdviceDate,
  6061. Type: 0,
  6062. PatientId: item.PatientId,
  6063. IsCheck: 1,
  6064. }
  6065. //查询今日是否有出库数据
  6066. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  6067. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  6068. if lastWarehouseOut.ID == 0 {
  6069. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6070. }
  6071. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  6072. var total_count int64
  6073. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  6074. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6075. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6076. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6077. }
  6078. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6079. total_count += prescribingNumberSeven
  6080. }
  6081. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6082. total_count += prescribingNumberSeven
  6083. }
  6084. //出库
  6085. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6086. WarehouseOutOrderNumber: warehousing_out_order,
  6087. WarehouseOutId: lastWarehouseOut.ID,
  6088. DrugId: item.DrugId,
  6089. Count: total_count,
  6090. Price: 0,
  6091. TotalPrice: 0,
  6092. Status: 1,
  6093. Ctime: item.AdviceDate,
  6094. Mtime: item.AdviceDate,
  6095. Remark: "",
  6096. OrgId: item.UserOrgId,
  6097. Type: 0,
  6098. Manufacturer: selfBasedrug.Manufacturer,
  6099. Dealer: selfBasedrug.Dealer,
  6100. RetailPrice: 0,
  6101. RetailTotalPrice: 0,
  6102. CountUnit: selfBasedrug.MinUnit,
  6103. ExpiryDate: 0,
  6104. ProductDate: 0,
  6105. Number: "",
  6106. BatchNumber: "",
  6107. IsSys: 1,
  6108. WarehouseInfoId: 0,
  6109. AdminUserId: 0,
  6110. StockCount: "",
  6111. IsCheck: 1,
  6112. SysRecordTime: item.AdviceDate,
  6113. PatientId: item.PatientId,
  6114. ClassType: "",
  6115. AdviceId: item.ID,
  6116. }
  6117. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6118. }
  6119. fmt.Println("长度-------------------------------", warehousingOutInfo)
  6120. for _, it := range warehousingOutInfo {
  6121. //查询今日是否有出库数据
  6122. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  6123. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6124. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6125. //出库逻辑
  6126. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  6127. //查询剩余库存
  6128. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6129. var sum_count int64
  6130. for _, its := range stockInfo {
  6131. if its.MaxUnit == medical.MaxUnit {
  6132. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6133. }
  6134. sum_count += its.StockMaxNumber + its.StockMinNumber
  6135. }
  6136. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6137. }
  6138. }
  6139. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6140. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6141. //耗材保存处方出库
  6142. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6143. //已收费和已发药限制逻辑
  6144. isCharge := false
  6145. isMedicine := false
  6146. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6147. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6148. if new_prescription.IsMedicine == 1 {
  6149. isMedicine = true
  6150. }
  6151. for _, item := range new_prescriptions {
  6152. if item.OrderStatus == 4 {
  6153. isCharge = true
  6154. }
  6155. }
  6156. if p_err != nil {
  6157. if new_prescription.ID > 0 {
  6158. if new_prescription.OrderStatus == 2 {
  6159. isCharge = true
  6160. }
  6161. }
  6162. }
  6163. for _, item := range advices {
  6164. if item.IsMedicine == 1 {
  6165. isMedicine = true
  6166. }
  6167. }
  6168. if isCharge {
  6169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6170. return
  6171. }
  6172. if isMedicine {
  6173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6174. return
  6175. }
  6176. //已收费和已发药限制逻辑
  6177. if len(projects) > 0 {
  6178. for _, item := range projects {
  6179. service.DeletePrintInfo(item.ID) //删除打印信息
  6180. if goodOutConfig.IsOpen != 1 {
  6181. if stockConfig.IsOpen == 1 {
  6182. if item.Type == 3 && item.IsOut == 1 {
  6183. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6184. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6185. good.Total = good.Total + f_count
  6186. service.UpdateGoodInfo(&good)
  6187. operation_time := time.Now().Unix()
  6188. creater := c.GetAdminUserInfo().AdminUser.Id
  6189. //创建退库单
  6190. timeStr := time.Now().Format("2006-01-02")
  6191. timeArr := strings.Split(timeStr, "-")
  6192. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6193. total = total + 1
  6194. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6195. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6196. cancelStock := models.CancelStock{
  6197. OrderNumber: orderNumber,
  6198. OperaTime: operation_time,
  6199. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6200. Creater: creater,
  6201. Ctime: time.Now().Unix(),
  6202. Status: 1,
  6203. ReturnTime: item.RecordDate,
  6204. Type: 1,
  6205. StorehouseId: houseConfig.StorehouseOutInfo,
  6206. IsCheck: 1,
  6207. }
  6208. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6209. if msgerrkonde == gorm.ErrRecordNotFound {
  6210. service.AddSigleCancelStock(&cancelStock)
  6211. }
  6212. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6213. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6214. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6215. //查询该耗材是否出库
  6216. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6217. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6218. deaerler, _ := service.GetDealerById(info.Dealer)
  6219. var total_count int64
  6220. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6221. total_count += count
  6222. if info.ID > 0 {
  6223. if info.Count >= total_count {
  6224. //回退库存
  6225. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6226. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6227. var flush_count int64
  6228. for _, it := range goodList {
  6229. flush_count += it.StockCount
  6230. }
  6231. cancelStockInfo := models.CancelStockInfo{
  6232. GoodId: item.ProjectId,
  6233. CancelStockId: cancel.ID,
  6234. GoodTypeId: good.GoodTypeId,
  6235. Count: prescribingNumber,
  6236. Price: info.Price,
  6237. Total: 0,
  6238. ProductDate: info.ProductDate,
  6239. ExpiryDate: info.ExpiryDate,
  6240. Ctime: time.Now().Unix(),
  6241. Status: 1,
  6242. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6243. OrderNumber: cancel.OrderNumber,
  6244. Type: 0,
  6245. Dealer: deaerler.DealerName,
  6246. Manufacturer: manufacturer.ManufacturerName,
  6247. Number: info.Number,
  6248. RegisterAccount: "",
  6249. Remark: "",
  6250. WarehouseInfoId: info.WarehouseInfotId,
  6251. PatientId: info.PatientId,
  6252. RecordDate: info.SysRecordTime,
  6253. StorehouseId: houseConfig.StorehouseOutInfo,
  6254. IsCheck: 1,
  6255. }
  6256. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6257. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6258. flow := models.VmStockFlow{
  6259. WarehousingId: info.WarehouseInfotId,
  6260. GoodId: item.ProjectId,
  6261. Number: info.Number,
  6262. LicenseNumber: info.LicenseNumber,
  6263. Count: prescribingNumber,
  6264. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6265. PatientId: item.PatientId,
  6266. SystemTime: info.SysRecordTime,
  6267. ConsumableType: 7,
  6268. IsSys: 0,
  6269. WarehousingOrder: "",
  6270. WarehouseOutId: info.WarehouseOutId,
  6271. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6272. IsEdit: 0,
  6273. CancelStockId: cancel.ID,
  6274. CancelOrderNumber: cancel.OrderNumber,
  6275. Manufacturer: manufacturer.ID,
  6276. Dealer: 0,
  6277. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6278. UpdateCreator: 0,
  6279. Status: 1,
  6280. Ctime: time.Now().Unix(),
  6281. Mtime: 0,
  6282. Price: info.Price,
  6283. WarehousingDetailId: info.WarehouseInfotId,
  6284. WarehouseOutDetailId: info.ID,
  6285. CancelOutDetailId: cancelInfo.ID,
  6286. ProductDate: info.ProductDate,
  6287. ExpireDate: info.ExpiryDate,
  6288. StorehouseId: houseConfig.StorehouseOutInfo,
  6289. OverCount: flush_count,
  6290. OperateTime: time.Now().Unix(),
  6291. }
  6292. service.CreateStockFlowOne(flow)
  6293. //退库数量增加
  6294. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6295. //出库数量减少
  6296. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6297. }
  6298. if info.Count < total_count {
  6299. //回退库存
  6300. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6301. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6302. var flush_count int64
  6303. for _, it := range goodList {
  6304. flush_count += it.StockCount
  6305. }
  6306. cancelStockInfo := models.CancelStockInfo{
  6307. GoodId: item.ProjectId,
  6308. CancelStockId: cancel.ID,
  6309. GoodTypeId: good.GoodTypeId,
  6310. Count: info.Count,
  6311. Price: info.Price,
  6312. Total: 0,
  6313. ProductDate: info.ProductDate,
  6314. ExpiryDate: info.ExpiryDate,
  6315. Ctime: time.Now().Unix(),
  6316. Status: 1,
  6317. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6318. OrderNumber: cancel.OrderNumber,
  6319. Type: 0,
  6320. Dealer: deaerler.DealerName,
  6321. Manufacturer: manufacturer.ManufacturerName,
  6322. Number: info.Number,
  6323. RegisterAccount: "",
  6324. Remark: "",
  6325. WarehouseInfoId: info.WarehouseInfotId,
  6326. PatientId: info.PatientId,
  6327. RecordDate: info.SysRecordTime,
  6328. StorehouseId: houseConfig.StorehouseOutInfo,
  6329. IsCheck: 1,
  6330. }
  6331. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6332. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6333. flow := models.VmStockFlow{
  6334. WarehousingId: info.WarehouseInfotId,
  6335. GoodId: item.ProjectId,
  6336. Number: info.Number,
  6337. LicenseNumber: info.LicenseNumber,
  6338. Count: info.Count,
  6339. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6340. PatientId: item.PatientId,
  6341. SystemTime: info.SysRecordTime,
  6342. ConsumableType: 7,
  6343. IsSys: 0,
  6344. WarehousingOrder: "",
  6345. WarehouseOutId: info.WarehouseOutId,
  6346. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6347. IsEdit: 0,
  6348. CancelStockId: cancel.ID,
  6349. CancelOrderNumber: cancel.OrderNumber,
  6350. Manufacturer: manufacturer.ID,
  6351. Dealer: 0,
  6352. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6353. UpdateCreator: 0,
  6354. Status: 1,
  6355. Ctime: time.Now().Unix(),
  6356. Mtime: 0,
  6357. Price: info.Price,
  6358. WarehousingDetailId: info.WarehouseInfotId,
  6359. WarehouseOutDetailId: info.ID,
  6360. CancelOutDetailId: cancelInfo.ID,
  6361. ProductDate: info.ProductDate,
  6362. ExpireDate: info.ExpiryDate,
  6363. StorehouseId: houseConfig.StorehouseOutInfo,
  6364. OverCount: flush_count,
  6365. OperateTime: time.Now().Unix(),
  6366. }
  6367. service.CreateStockFlowOne(flow)
  6368. //退库数量增加
  6369. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6370. //出库数量减少
  6371. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6372. }
  6373. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6374. var flush_count int64
  6375. for _, it := range goodList {
  6376. flush_count += it.StockCount
  6377. }
  6378. //查询已出库数量
  6379. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6380. if prescribingNumber < dialysisInfo.Count {
  6381. //改变数量
  6382. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6383. }
  6384. if prescribingNumber >= dialysisInfo.Count {
  6385. //删除出库表
  6386. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6387. }
  6388. //更新库存
  6389. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6390. //更新基础库库存
  6391. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6392. }
  6393. }
  6394. }
  6395. }
  6396. //保存耗材出库
  6397. if goodOutConfig.IsOpen == 1 {
  6398. if item.Type == 3 {
  6399. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6400. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6401. good.Total = good.Total + f_count
  6402. service.UpdateGoodInfo(&good)
  6403. operation_time := time.Now().Unix()
  6404. creater := c.GetAdminUserInfo().AdminUser.Id
  6405. //创建退库单
  6406. timeStr := time.Now().Format("2006-01-02")
  6407. timeArr := strings.Split(timeStr, "-")
  6408. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6409. total = total + 1
  6410. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6411. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6412. cancelStock := models.CancelStock{
  6413. OrderNumber: orderNumber,
  6414. OperaTime: operation_time,
  6415. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6416. Creater: creater,
  6417. Ctime: time.Now().Unix(),
  6418. Status: 1,
  6419. ReturnTime: item.RecordDate,
  6420. Type: 1,
  6421. StorehouseId: houseConfig.StorehouseOutInfo,
  6422. IsCheck: 1,
  6423. }
  6424. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6425. if msgerrkonde == gorm.ErrRecordNotFound {
  6426. service.AddSigleCancelStock(&cancelStock)
  6427. }
  6428. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6429. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6430. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6431. //查询该耗材是否出库
  6432. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6433. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6434. deaerler, _ := service.GetDealerById(info.Dealer)
  6435. var total_count int64
  6436. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6437. total_count += count
  6438. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6439. var flush_count int64
  6440. for _, it := range goodList {
  6441. flush_count += it.StockCount
  6442. }
  6443. fmt.Println("历史出库数据", info.Count)
  6444. fmt.Println("出库数量", total_count)
  6445. if info.ID > 0 {
  6446. cancelStockInfo := models.CancelStockInfo{
  6447. GoodId: item.ProjectId,
  6448. CancelStockId: cancel.ID,
  6449. GoodTypeId: good.GoodTypeId,
  6450. Count: prescribingNumber,
  6451. Price: info.Price,
  6452. Total: 0,
  6453. ProductDate: info.ProductDate,
  6454. ExpiryDate: info.ExpiryDate,
  6455. Ctime: time.Now().Unix(),
  6456. Status: 1,
  6457. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6458. OrderNumber: cancel.OrderNumber,
  6459. Type: 0,
  6460. Dealer: deaerler.DealerName,
  6461. Manufacturer: manufacturer.ManufacturerName,
  6462. Number: info.Number,
  6463. RegisterAccount: "",
  6464. Remark: "",
  6465. WarehouseInfoId: info.WarehouseInfotId,
  6466. PatientId: info.PatientId,
  6467. RecordDate: info.SysRecordTime,
  6468. StorehouseId: houseConfig.StorehouseOutInfo,
  6469. IsCheck: 1,
  6470. }
  6471. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6472. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6473. //查询出库数量
  6474. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6475. //出库数据 大于 退库数量
  6476. if len(list) > 0 {
  6477. for _, it := range list {
  6478. //回退库存
  6479. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6480. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6481. var flush_count_one int64
  6482. for _, it := range goodList {
  6483. flush_count_one += it.StockCount
  6484. }
  6485. //查询该批次是否有退库数据
  6486. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6487. creater := c.GetAdminUserInfo().AdminUser.Id
  6488. flow := models.VmStockFlow{
  6489. WarehousingId: it.WarehouseInfotId,
  6490. GoodId: it.GoodId,
  6491. Number: it.Number,
  6492. LicenseNumber: it.LicenseNumber,
  6493. Count: it.Count,
  6494. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6495. PatientId: it.PatientId,
  6496. SystemTime: it.SysRecordTime,
  6497. ConsumableType: 7,
  6498. IsSys: 0,
  6499. WarehousingOrder: "",
  6500. WarehouseOutId: it.WarehouseOutId,
  6501. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6502. IsEdit: 0,
  6503. CancelStockId: cancel.ID,
  6504. CancelOrderNumber: cancel.OrderNumber,
  6505. Manufacturer: manufacturer.ID,
  6506. Dealer: 0,
  6507. Creator: creater,
  6508. UpdateCreator: 0,
  6509. Status: 1,
  6510. Ctime: time.Now().Unix(),
  6511. Mtime: 0,
  6512. Price: it.Price,
  6513. WarehousingDetailId: it.WarehouseInfotId,
  6514. WarehouseOutDetailId: it.ID,
  6515. CancelOutDetailId: cancelInfo.ID,
  6516. ProductDate: it.ProductDate,
  6517. ExpireDate: it.ExpiryDate,
  6518. StorehouseId: houseConfig.StorehouseOutInfo,
  6519. OverCount: flush_count_one,
  6520. OperateTime: time.Now().Unix(),
  6521. }
  6522. service.CreateStockFlowOne(flow)
  6523. //if flow.ID > 0 {
  6524. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6525. //}
  6526. }
  6527. }
  6528. //flow := models.VmStockFlow{
  6529. // WarehousingId: info.WarehouseInfotId,
  6530. // GoodId: item.ProjectId,
  6531. // Number: info.Number,
  6532. // LicenseNumber: info.LicenseNumber,
  6533. // Count: prescribingNumber,
  6534. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6535. // PatientId: item.PatientId,
  6536. // SystemTime: info.SysRecordTime,
  6537. // ConsumableType: 7,
  6538. // IsSys: 0,
  6539. // WarehousingOrder: "",
  6540. // WarehouseOutId: info.WarehouseOutId,
  6541. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6542. // IsEdit: 0,
  6543. // CancelStockId: cancel.ID,
  6544. // CancelOrderNumber: cancel.OrderNumber,
  6545. // Manufacturer: manufacturer.ID,
  6546. // Dealer: 0,
  6547. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6548. // UpdateCreator: 0,
  6549. // Status: 1,
  6550. // Ctime: time.Now().Unix(),
  6551. // Mtime: 0,
  6552. // Price: info.Price,
  6553. // WarehousingDetailId: info.WarehouseInfotId,
  6554. // WarehouseOutDetailId: info.ID,
  6555. // CancelOutDetailId: cancelInfo.ID,
  6556. // ProductDate: info.ProductDate,
  6557. // ExpireDate: info.ExpiryDate,
  6558. // StorehouseId: houseConfig.StorehouseOutInfo,
  6559. // OverCount: flush_count,
  6560. //}
  6561. //service.CreateStockFlowOne(flow)
  6562. //退库数量增加
  6563. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6564. //出库数量减少
  6565. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6566. //查询已出库数量
  6567. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6568. if prescribingNumber < dialysisInfo.Count {
  6569. //改变数量
  6570. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6571. }
  6572. if prescribingNumber >= dialysisInfo.Count {
  6573. //删除出库表
  6574. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6575. }
  6576. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6577. var flush_count_one int64
  6578. for _, it := range goodList {
  6579. flush_count_one += it.StockCount
  6580. }
  6581. //更新库存
  6582. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6583. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6584. //更新基础库库存
  6585. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6586. }
  6587. }
  6588. }
  6589. }
  6590. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6591. fmt.Println(err)
  6592. }
  6593. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6594. fmt.Println(err)
  6595. if len(advices) > 0 {
  6596. for _, item := range advices {
  6597. redis := service.RedisClient()
  6598. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6599. redis.Set(keyFive, "", time.Second)
  6600. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6601. redis.Set(keyOne, "", time.Second)
  6602. redis.Close()
  6603. }
  6604. }
  6605. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6606. if len(advices) > 0 {
  6607. for _, item := range advices {
  6608. creater := c.GetAdminUserInfo().AdminUser.Id
  6609. service.DrugAutoAddCancelInfo(item, creater)
  6610. }
  6611. }
  6612. } else {
  6613. if drugOutConfig.IsOpen == 1 {
  6614. if len(advices) > 0 {
  6615. for _, item := range advices {
  6616. creater := c.GetAdminUserInfo().AdminUser.Id
  6617. service.DrugAutoAddCancelInfo(item, creater)
  6618. }
  6619. }
  6620. } else {
  6621. if len(advices) > 0 {
  6622. for _, item := range advices {
  6623. creater := c.GetAdminUserInfo().AdminUser.Id
  6624. service.DrugAutoAddCancelInfo(item, creater)
  6625. }
  6626. }
  6627. }
  6628. }
  6629. c.ServeSuccessJSON(map[string]interface{}{
  6630. "msg": "删除成功",
  6631. })
  6632. return
  6633. }
  6634. func (c *HisApiController) DeleteDoctorAdvice() {
  6635. id, _ := c.GetInt64("id")
  6636. advice, _ := service.GetHisDoctorAdvicesById(id)
  6637. ////同步到自备药
  6638. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6639. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6640. if selfPrescriptionOpen.IsOpen == 1 {
  6641. db := service.XTWriteDB()
  6642. tx := db.Begin()
  6643. defer func() {
  6644. if r := recover(); r != nil {
  6645. tx.Rollback()
  6646. } else {
  6647. tx.Commit()
  6648. }
  6649. }()
  6650. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6651. var total_count int64
  6652. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6653. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6654. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6655. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6656. }
  6657. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6658. total_count += prescribingNumberSeven
  6659. }
  6660. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6661. total_count += prescribingNumberSeven
  6662. }
  6663. timeStr := time.Now().Format("2006-01-02")
  6664. timeArr := strings.Split(timeStr, "-")
  6665. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6666. total = total + 1
  6667. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6668. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6669. number = number + total
  6670. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6671. operation_time := time.Now().Unix()
  6672. creater := c.GetAdminUserInfo().AdminUser.Id
  6673. //创建一个出库单
  6674. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6675. WarehouseOutOrderNumber: warehousing_out_order,
  6676. OperationTime: operation_time,
  6677. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6678. Creater: creater,
  6679. Ctime: time.Now().Unix(),
  6680. Status: 1,
  6681. WarehouseOutTime: advice.AdviceDate,
  6682. Type: 0,
  6683. PatientId: advice.PatientId,
  6684. IsCheck: 1,
  6685. }
  6686. //查询今日是否有出库数据
  6687. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6688. if lastWarehouseOut.ID == 0 {
  6689. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6690. }
  6691. //出库
  6692. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6693. WarehouseOutId: lastWarehouseOut.ID,
  6694. WarehouseOutOrderNumber: warehousing_out_order,
  6695. DrugId: advice.DrugId,
  6696. Count: total_count,
  6697. Price: 0,
  6698. TotalPrice: 0,
  6699. Status: 1,
  6700. Ctime: advice.AdviceDate,
  6701. Mtime: advice.AdviceDate,
  6702. Remark: "",
  6703. OrgId: advice.UserOrgId,
  6704. Type: 0,
  6705. Manufacturer: selfBasedrug.Manufacturer,
  6706. Dealer: selfBasedrug.Dealer,
  6707. RetailPrice: 0,
  6708. RetailTotalPrice: 0,
  6709. CountUnit: advice.PrescribingNumberUnit,
  6710. ExpiryDate: 0,
  6711. ProductDate: 0,
  6712. Number: "",
  6713. BatchNumber: "",
  6714. IsSys: 0,
  6715. WarehouseInfoId: 0,
  6716. AdminUserId: 0,
  6717. StockCount: "",
  6718. IsCheck: 1,
  6719. SysRecordTime: advice.AdviceDate,
  6720. PatientId: advice.PatientId,
  6721. AdviceId: advice.ID,
  6722. ClassType: "",
  6723. }
  6724. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6725. for _, it := range warehousingOutInfo {
  6726. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6727. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6728. //出库逻辑
  6729. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6730. //查询剩余库存
  6731. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6732. var sum_count int64
  6733. for _, its := range stockInfo {
  6734. if its.MaxUnit == medical.MaxUnit {
  6735. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6736. }
  6737. sum_count += its.StockMaxNumber + its.StockMinNumber
  6738. }
  6739. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6740. }
  6741. }
  6742. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6743. //已收费和已发药的限制逻辑
  6744. isCharge := false
  6745. isMedicine := false
  6746. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6747. //获取今天该患者所有处方,判断是否发药或者收费
  6748. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6749. //for _, item := range new_prescriptions {
  6750. if new_prescription.IsMedicine == 1 {
  6751. isMedicine = true
  6752. }
  6753. //}
  6754. for _, item := range new_prescriptions {
  6755. if item.OrderStatus == 4 {
  6756. isCharge = true
  6757. }
  6758. }
  6759. if isMedicine {
  6760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6761. return
  6762. }
  6763. if isCharge {
  6764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6765. return
  6766. }
  6767. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6768. for _, item := range advices {
  6769. if item.IsMedicine == 1 {
  6770. isMedicine = true
  6771. }
  6772. }
  6773. if isMedicine {
  6774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6775. return
  6776. }
  6777. if new_prescription.ID > 0 {
  6778. if new_prescription.OrderStatus == 2 {
  6779. isCharge = true
  6780. }
  6781. }
  6782. if isCharge {
  6783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6784. return
  6785. }
  6786. //已收费和已发药的限制逻辑
  6787. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6788. redis := service.RedisClient()
  6789. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6790. redis.Set(keyFive, "", time.Second)
  6791. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6792. redis.Set(keyOne, "", time.Second)
  6793. defer redis.Close()
  6794. if err == nil {
  6795. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6796. //查询是否在处方中出库
  6797. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6798. if openConfig.IsOpen != 1 {
  6799. //判断该医嘱是否执行了
  6800. if advice.ExecutionState == 1 {
  6801. creater := c.GetAdminUserInfo().AdminUser.Id
  6802. service.DrugAutoAddCancelInfo(&advice, creater)
  6803. }
  6804. }
  6805. //开启保存处方扣减功能
  6806. if openConfig.IsOpen == 1 {
  6807. creater := c.GetAdminUserInfo().AdminUser.Id
  6808. service.DrugAutoAddCancelInfo(&advice, creater)
  6809. }
  6810. } else {
  6811. if drugOutConfig.IsOpen == 1 {
  6812. //查询是否在处方中出库
  6813. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6814. if openConfig.IsOpen != 1 {
  6815. //判断该医嘱是否执行了
  6816. if advice.ExecutionState == 1 {
  6817. creater := c.GetAdminUserInfo().AdminUser.Id
  6818. service.DrugAutoAddCancelInfo(&advice, creater)
  6819. }
  6820. }
  6821. //开启保存处方扣减功能
  6822. if openConfig.IsOpen == 1 {
  6823. creater := c.GetAdminUserInfo().AdminUser.Id
  6824. service.DrugAutoAddCancelInfo(&advice, creater)
  6825. }
  6826. } else {
  6827. //判断该医嘱是否执行了
  6828. if advice.ExecutionState == 1 {
  6829. creater := c.GetAdminUserInfo().AdminUser.Id
  6830. service.DrugAutoAddCancelInfo(&advice, creater)
  6831. }
  6832. }
  6833. }
  6834. c.ServeSuccessJSON(map[string]interface{}{
  6835. "msg": "删除成功",
  6836. })
  6837. return
  6838. } else {
  6839. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6840. return
  6841. }
  6842. }
  6843. func (c *HisApiController) DeleteProject() {
  6844. id, _ := c.GetInt64("id")
  6845. adminInfo := c.GetAdminUserInfo()
  6846. project, _ := service.GetHisProjectByID(id)
  6847. // var consumable models.DialysisBeforePrepare
  6848. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6849. //耗材保存处方出库
  6850. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6851. isCharge := false
  6852. isMedicine := false
  6853. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6854. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6855. for _, item := range new_prescriptions {
  6856. if item.IsMedicine == 1 {
  6857. isMedicine = true
  6858. }
  6859. }
  6860. for _, item := range new_prescriptions {
  6861. if item.OrderStatus == 4 {
  6862. isCharge = true
  6863. }
  6864. }
  6865. if isMedicine {
  6866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6867. return
  6868. }
  6869. if isCharge {
  6870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6871. return
  6872. }
  6873. if new_prescription.ID > 0 {
  6874. if new_prescription.OrderStatus == 2 {
  6875. isCharge = true
  6876. }
  6877. }
  6878. if isCharge {
  6879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6880. return
  6881. }
  6882. service.DeletePrintInfo(id)
  6883. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  6884. label.Status = 0
  6885. service.CreateHisLabelRecordTwo(&label)
  6886. fmt.Println(goodOutConfig.IsOpen)
  6887. if goodOutConfig.IsOpen != 1 {
  6888. if stockConfig.IsOpen == 1 {
  6889. if project.Type == 2 {
  6890. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6891. fmt.Println(err)
  6892. }
  6893. if project.Type == 3 && project.IsOut == 1 {
  6894. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6895. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6896. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6897. operation_time := time.Now().Unix()
  6898. creater := adminInfo.AdminUser.Id
  6899. //创建退库单
  6900. timeStr := time.Now().Format("2006-01-02")
  6901. timeArr := strings.Split(timeStr, "-")
  6902. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6903. total = total + 1
  6904. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6905. cancelStock := models.CancelStock{
  6906. OrderNumber: orderNumber,
  6907. OperaTime: operation_time,
  6908. OrgId: adminInfo.CurrentOrgId,
  6909. Creater: creater,
  6910. Ctime: time.Now().Unix(),
  6911. Status: 1,
  6912. ReturnTime: project.RecordDate,
  6913. Type: 1,
  6914. StorehouseId: houseConfig.StorehouseOutInfo,
  6915. IsCheck: 1,
  6916. }
  6917. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6918. if msgerrkonde == gorm.ErrRecordNotFound {
  6919. service.AddSigleCancelStock(&cancelStock)
  6920. }
  6921. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6922. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6923. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6924. //查询是否有出库
  6925. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6926. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6927. deaerler, _ := service.GetDealerById(info.Dealer)
  6928. if info.ID > 0 {
  6929. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6930. if info.Count >= prescribingNumber {
  6931. cancelStockInfo := models.CancelStockInfo{
  6932. GoodId: project.ProjectId,
  6933. CancelStockId: cancel.ID,
  6934. GoodTypeId: good.GoodTypeId,
  6935. Count: prescribingNumber,
  6936. Price: info.Price,
  6937. Total: 0,
  6938. ProductDate: info.ProductDate,
  6939. ExpiryDate: info.ExpiryDate,
  6940. Ctime: time.Now().Unix(),
  6941. Status: 1,
  6942. OrgId: adminInfo.CurrentOrgId,
  6943. OrderNumber: cancel.OrderNumber,
  6944. Type: 0,
  6945. Dealer: deaerler.DealerName,
  6946. Manufacturer: manufacturer.ManufacturerName,
  6947. Number: info.Number,
  6948. RegisterAccount: "",
  6949. Remark: "",
  6950. WarehouseInfoId: info.WarehouseInfotId,
  6951. PatientId: info.PatientId,
  6952. RecordDate: info.SysRecordTime,
  6953. StorehouseId: houseConfig.StorehouseOutInfo,
  6954. IsCheck: 1,
  6955. }
  6956. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6957. //回退库存
  6958. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6959. //退库数量增加
  6960. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6961. //出库数量减少
  6962. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6963. }
  6964. if info.Count < prescribingNumber {
  6965. cancelStockInfo := models.CancelStockInfo{
  6966. GoodId: project.ProjectId,
  6967. CancelStockId: cancel.ID,
  6968. GoodTypeId: good.GoodTypeId,
  6969. Count: info.Count,
  6970. Price: info.Price,
  6971. Total: 0,
  6972. ProductDate: info.ProductDate,
  6973. ExpiryDate: info.ExpiryDate,
  6974. Ctime: time.Now().Unix(),
  6975. Status: 1,
  6976. OrgId: adminInfo.CurrentOrgId,
  6977. OrderNumber: cancel.OrderNumber,
  6978. Type: 0,
  6979. Dealer: deaerler.DealerName,
  6980. Manufacturer: manufacturer.ManufacturerName,
  6981. Number: info.Number,
  6982. RegisterAccount: "",
  6983. Remark: "",
  6984. WarehouseInfoId: info.WarehouseInfotId,
  6985. PatientId: info.PatientId,
  6986. RecordDate: info.SysRecordTime,
  6987. StorehouseId: houseConfig.StorehouseOutInfo,
  6988. IsCheck: 1,
  6989. }
  6990. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6991. //回退库存
  6992. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6993. //退库数量增加
  6994. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6995. //出库数量减少
  6996. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6997. }
  6998. //查询剩余库存
  6999. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7000. var over_count int64
  7001. for _, it := range goodList {
  7002. over_count += it.StockCount
  7003. }
  7004. //出库数据 大于 退库数量
  7005. if info.Count >= prescribingNumber {
  7006. flow := models.VmStockFlow{
  7007. WarehousingId: info.WarehouseInfotId,
  7008. GoodId: project.ProjectId,
  7009. Number: info.Number,
  7010. LicenseNumber: info.LicenseNumber,
  7011. Count: prescribingNumber,
  7012. UserOrgId: adminInfo.CurrentOrgId,
  7013. PatientId: project.PatientId,
  7014. SystemTime: info.SysRecordTime,
  7015. ConsumableType: 7,
  7016. IsSys: 0,
  7017. WarehousingOrder: "",
  7018. WarehouseOutId: info.WarehouseOutId,
  7019. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7020. IsEdit: 0,
  7021. CancelStockId: cancel.ID,
  7022. CancelOrderNumber: cancel.OrderNumber,
  7023. Manufacturer: manufacturer.ID,
  7024. Dealer: 0,
  7025. Creator: adminInfo.AdminUser.Id,
  7026. UpdateCreator: 0,
  7027. Status: 1,
  7028. Ctime: time.Now().Unix(),
  7029. Mtime: 0,
  7030. Price: info.Price,
  7031. WarehousingDetailId: info.WarehouseInfotId,
  7032. WarehouseOutDetailId: info.ID,
  7033. CancelOutDetailId: cancelInfo.ID,
  7034. ProductDate: info.ProductDate,
  7035. ExpireDate: info.ExpiryDate,
  7036. StorehouseId: houseConfig.StorehouseOutInfo,
  7037. OverCount: over_count,
  7038. OperateTime: time.Now().Unix(),
  7039. }
  7040. service.CreateStockFlowOne(flow)
  7041. }
  7042. //出库数据小于退库数据
  7043. if info.Count < prescribingNumber {
  7044. flow := models.VmStockFlow{
  7045. WarehousingId: info.WarehouseInfotId,
  7046. GoodId: project.ProjectId,
  7047. Number: info.Number,
  7048. LicenseNumber: info.LicenseNumber,
  7049. Count: info.Count,
  7050. UserOrgId: adminInfo.CurrentOrgId,
  7051. PatientId: project.PatientId,
  7052. SystemTime: info.SysRecordTime,
  7053. ConsumableType: 7,
  7054. IsSys: 0,
  7055. WarehousingOrder: "",
  7056. WarehouseOutId: info.WarehouseOutId,
  7057. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7058. IsEdit: 0,
  7059. CancelStockId: cancel.ID,
  7060. CancelOrderNumber: cancel.OrderNumber,
  7061. Manufacturer: manufacturer.ID,
  7062. Dealer: 0,
  7063. Creator: adminInfo.AdminUser.Id,
  7064. UpdateCreator: 0,
  7065. Status: 1,
  7066. Ctime: time.Now().Unix(),
  7067. Mtime: 0,
  7068. Price: info.Price,
  7069. WarehousingDetailId: info.WarehouseInfotId,
  7070. WarehouseOutDetailId: info.ID,
  7071. CancelOutDetailId: cancelInfo.ID,
  7072. ProductDate: info.ProductDate,
  7073. ExpireDate: info.ExpiryDate,
  7074. StorehouseId: houseConfig.StorehouseOutInfo,
  7075. OverCount: over_count,
  7076. OperateTime: time.Now().Unix(),
  7077. }
  7078. service.CreateStockFlowOne(flow)
  7079. }
  7080. //查询已出库数量
  7081. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7082. if prescribingNumber < dialysisInfo.Count {
  7083. //改变数量
  7084. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7085. }
  7086. if prescribingNumber >= dialysisInfo.Count {
  7087. //删除出库表
  7088. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7089. }
  7090. //更新剩余库存
  7091. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7092. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7093. var total_count_one int64
  7094. for _, it := range stockList {
  7095. total_count_one += it.StockCount
  7096. }
  7097. //基础库插入数据
  7098. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7099. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7100. var flush_count int64
  7101. for _, it := range goodListOne {
  7102. flush_count += it.StockCount
  7103. }
  7104. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7105. if errs != nil {
  7106. goodErrcode := models.XtGoodErrcode{
  7107. UserOrgId: project.UserOrgId,
  7108. Errcode: "手动出库更新剩余出库失败",
  7109. GoodId: project.ProjectId,
  7110. Status: 1,
  7111. Ctime: time.Now().Unix(),
  7112. Mtime: 0,
  7113. Count: 0,
  7114. StockCount: 0,
  7115. Creater: creater,
  7116. BatchNumberId: 0,
  7117. WarehouseOutId: 0,
  7118. }
  7119. service.CreateGoodErrcode(goodErrcode)
  7120. }
  7121. }
  7122. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7123. fmt.Println(err)
  7124. } else {
  7125. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7126. fmt.Println(err)
  7127. }
  7128. } else {
  7129. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7130. fmt.Println(err)
  7131. }
  7132. }
  7133. //保存处方出库
  7134. if goodOutConfig.IsOpen == 1 {
  7135. if project.Type == 3 {
  7136. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7137. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7138. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7139. operation_time := time.Now().Unix()
  7140. creater := adminInfo.AdminUser.Id
  7141. //创建退库单
  7142. timeStr := time.Now().Format("2006-01-02")
  7143. timeArr := strings.Split(timeStr, "-")
  7144. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7145. total = total + 1
  7146. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7147. cancelStock := models.CancelStock{
  7148. OrderNumber: orderNumber,
  7149. OperaTime: operation_time,
  7150. OrgId: adminInfo.CurrentOrgId,
  7151. Creater: creater,
  7152. Ctime: time.Now().Unix(),
  7153. Status: 1,
  7154. ReturnTime: project.RecordDate,
  7155. Type: 1,
  7156. StorehouseId: houseConfig.StorehouseOutInfo,
  7157. IsCheck: 1,
  7158. }
  7159. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7160. if msgerrkonde == gorm.ErrRecordNotFound {
  7161. service.AddSigleCancelStock(&cancelStock)
  7162. }
  7163. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7164. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7165. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7166. //获取出库数据
  7167. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7168. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7169. deaerler, _ := service.GetDealerById(info.Dealer)
  7170. if info.ID > 0 {
  7171. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7172. if info.Count >= prescribingNumber {
  7173. cancelStockInfo := models.CancelStockInfo{
  7174. GoodId: project.ProjectId,
  7175. CancelStockId: cancel.ID,
  7176. GoodTypeId: good.GoodTypeId,
  7177. Count: prescribingNumber,
  7178. Price: info.Price,
  7179. Total: 0,
  7180. ProductDate: info.ProductDate,
  7181. ExpiryDate: info.ExpiryDate,
  7182. Ctime: time.Now().Unix(),
  7183. Status: 1,
  7184. OrgId: adminInfo.CurrentOrgId,
  7185. OrderNumber: cancel.OrderNumber,
  7186. Type: 0,
  7187. Dealer: deaerler.DealerName,
  7188. Manufacturer: manufacturer.ManufacturerName,
  7189. Number: info.Number,
  7190. RegisterAccount: "",
  7191. Remark: "",
  7192. WarehouseInfoId: info.WarehouseInfotId,
  7193. PatientId: info.PatientId,
  7194. RecordDate: info.SysRecordTime,
  7195. StorehouseId: houseConfig.StorehouseOutInfo,
  7196. IsCheck: 1,
  7197. }
  7198. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7199. //退库数量增加
  7200. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7201. //出库数量减少
  7202. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7203. }
  7204. if info.Count < prescribingNumber {
  7205. cancelStockInfo := models.CancelStockInfo{
  7206. GoodId: project.ProjectId,
  7207. CancelStockId: cancel.ID,
  7208. GoodTypeId: good.GoodTypeId,
  7209. Count: prescribingNumber,
  7210. Price: info.Price,
  7211. Total: 0,
  7212. ProductDate: info.ProductDate,
  7213. ExpiryDate: info.ExpiryDate,
  7214. Ctime: time.Now().Unix(),
  7215. Status: 1,
  7216. OrgId: adminInfo.CurrentOrgId,
  7217. OrderNumber: cancel.OrderNumber,
  7218. Type: 0,
  7219. Dealer: deaerler.DealerName,
  7220. Manufacturer: manufacturer.ManufacturerName,
  7221. Number: info.Number,
  7222. RegisterAccount: "",
  7223. Remark: "",
  7224. WarehouseInfoId: info.WarehouseInfotId,
  7225. PatientId: info.PatientId,
  7226. RecordDate: info.SysRecordTime,
  7227. StorehouseId: houseConfig.StorehouseOutInfo,
  7228. IsCheck: 1,
  7229. }
  7230. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7231. //回退库存
  7232. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7233. }
  7234. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7235. var over_count int64
  7236. for _, it := range goodList {
  7237. over_count += it.StockCount
  7238. }
  7239. //查询出库数量
  7240. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  7241. //出库数据 大于 退库数量
  7242. if len(list) > 0 {
  7243. for _, it := range list {
  7244. //回退库存
  7245. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  7246. //退库数量增加
  7247. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  7248. //出库数量减少
  7249. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  7250. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7251. var over_count_one int64
  7252. for _, it := range goodList {
  7253. over_count_one += it.StockCount
  7254. }
  7255. //查询该批次是否有退库数据
  7256. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  7257. flow := models.VmStockFlow{
  7258. WarehousingId: it.WarehouseInfotId,
  7259. GoodId: it.GoodId,
  7260. Number: it.Number,
  7261. LicenseNumber: it.LicenseNumber,
  7262. Count: it.Count,
  7263. UserOrgId: adminInfo.CurrentOrgId,
  7264. PatientId: it.PatientId,
  7265. SystemTime: it.SysRecordTime,
  7266. ConsumableType: 7,
  7267. IsSys: 0,
  7268. WarehousingOrder: "",
  7269. WarehouseOutId: it.WarehouseOutId,
  7270. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7271. IsEdit: 0,
  7272. CancelStockId: cancel.ID,
  7273. CancelOrderNumber: cancel.OrderNumber,
  7274. Manufacturer: manufacturer.ID,
  7275. Dealer: 0,
  7276. Creator: adminInfo.AdminUser.Id,
  7277. UpdateCreator: 0,
  7278. Status: 1,
  7279. Ctime: time.Now().Unix(),
  7280. Mtime: 0,
  7281. Price: it.Price,
  7282. WarehousingDetailId: it.WarehouseInfotId,
  7283. WarehouseOutDetailId: it.ID,
  7284. CancelOutDetailId: cancelInfo.ID,
  7285. ProductDate: it.ProductDate,
  7286. ExpireDate: it.ExpiryDate,
  7287. StorehouseId: houseConfig.StorehouseOutInfo,
  7288. OverCount: over_count_one,
  7289. OperateTime: time.Now().Unix(),
  7290. }
  7291. service.CreateStockFlowOne(flow)
  7292. }
  7293. }
  7294. //查询已出库数量
  7295. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7296. if prescribingNumber < dialysisInfo.Count {
  7297. //改变数量
  7298. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7299. }
  7300. if prescribingNumber >= dialysisInfo.Count {
  7301. //删除出库表
  7302. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7303. }
  7304. //更新剩余库存
  7305. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7306. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7307. var total_count_one int64
  7308. for _, it := range stockList {
  7309. total_count_one += it.StockCount
  7310. }
  7311. //基础库插入数据
  7312. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7313. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7314. var flush_count int64
  7315. for _, it := range goodListOne {
  7316. flush_count += it.StockCount
  7317. }
  7318. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7319. if errs != nil {
  7320. goodErrcode := models.XtGoodErrcode{
  7321. UserOrgId: project.UserOrgId,
  7322. Errcode: "手动出库更新剩余出库失败",
  7323. GoodId: project.ProjectId,
  7324. Status: 1,
  7325. Ctime: time.Now().Unix(),
  7326. Mtime: 0,
  7327. Count: 0,
  7328. StockCount: 0,
  7329. Creater: creater,
  7330. BatchNumberId: 0,
  7331. WarehouseOutId: 0,
  7332. }
  7333. service.CreateGoodErrcode(goodErrcode)
  7334. }
  7335. }
  7336. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7337. fmt.Println(err)
  7338. } else {
  7339. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7340. fmt.Println(err)
  7341. }
  7342. }
  7343. c.ServeSuccessJSON(map[string]interface{}{
  7344. "msg": "删除成功",
  7345. })
  7346. return
  7347. }
  7348. func (c *HisApiController) CreateHisAdditionalCharge() {
  7349. his_patient_id, _ := c.GetInt64("his_patient_id")
  7350. patient_id, _ := c.GetInt64("patient_id")
  7351. record_date := c.GetString("record_date")
  7352. timeLayout := "2006-01-02"
  7353. loc, _ := time.LoadLocation("Local")
  7354. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7355. if err != nil {
  7356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7357. return
  7358. }
  7359. adminInfo := c.GetAdminUserInfo()
  7360. recordDateTime := theTime.Unix()
  7361. dataBody := make(map[string]interface{}, 0)
  7362. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7363. if err != nil {
  7364. utils.ErrorLog(err.Error())
  7365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7366. return
  7367. }
  7368. var additions []*models.HisAdditionalCharge
  7369. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7370. additions, _ := dataBody["addition"].([]interface{})
  7371. if len(additions) > 0 {
  7372. for _, item := range additions {
  7373. items := item.(map[string]interface{})
  7374. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7375. utils.ErrorLog("item_id")
  7376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7377. return
  7378. }
  7379. item_id := int64(items["item_id"].(float64))
  7380. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7381. utils.ErrorLog("item_name")
  7382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7383. return
  7384. }
  7385. item_name := items["item_name"].(string)
  7386. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7387. utils.ErrorLog("price")
  7388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7389. return
  7390. }
  7391. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7392. ctime := time.Now().Unix()
  7393. additional := &models.HisAdditionalCharge{
  7394. PatientId: patient_id,
  7395. HisPatientId: his_patient_id,
  7396. UserOrgId: adminInfo.CurrentOrgId,
  7397. RecordDate: recordDateTime,
  7398. CreatedTime: ctime,
  7399. UpdatedTime: ctime,
  7400. Modifier: adminInfo.AdminUser.Id,
  7401. Creator: adminInfo.AdminUser.Id,
  7402. Price: price,
  7403. ItemName: item_name,
  7404. ItemId: item_id,
  7405. Status: 1,
  7406. }
  7407. additions = append(additions, additional)
  7408. }
  7409. }
  7410. }
  7411. for _, item := range additions {
  7412. service.CreateAddtionalCharge(item)
  7413. }
  7414. c.ServeSuccessJSON(map[string]interface{}{
  7415. "msg": "创建成功",
  7416. })
  7417. }
  7418. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7419. blood_fat := c.GetString("blood_fat")
  7420. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7421. blood_sugar := c.GetString("blood_sugar")
  7422. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7423. chief_conplaint := c.GetString("chief_conplaint")
  7424. dbp := c.GetString("dbp")
  7425. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7426. delivery_way, _ := c.GetInt64("delivery_way")
  7427. diagnostic := c.GetString("diagnostic")
  7428. family_history := c.GetString("family_history")
  7429. height := c.GetString("height")
  7430. history_of_present_illness := c.GetString("history_of_present_illness")
  7431. is_infect, _ := c.GetInt64("is_infect")
  7432. past_history := c.GetString("past_history")
  7433. patient_id, _ := c.GetInt64("patient_id")
  7434. his_patient_id, _ := c.GetInt64("his_patient_id")
  7435. personal_history := c.GetString("personal_history")
  7436. pulse := c.GetString("pulse")
  7437. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7438. sbp := c.GetString("sbp")
  7439. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7440. heightfloat, _ := strconv.ParseFloat(height, 64)
  7441. sicktype := c.GetString("sick_type")
  7442. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7443. symptom := c.GetString("symptom")
  7444. sick_date := c.GetString("sick_date")
  7445. temperatures := c.GetString("temperature")
  7446. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7447. record_date := c.GetString("record_date")
  7448. breathing := c.GetString("breathing")
  7449. doctor_advice := c.GetString("doctor_advice")
  7450. remark := c.GetString("remark")
  7451. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7452. sick, _ := c.GetInt64("sick")
  7453. diagnose, _ := c.GetInt64("diagnose")
  7454. //id, _ := c.GetInt64("id")
  7455. timeLayout := "2006-01-02"
  7456. loc, _ := time.LoadLocation("Local")
  7457. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7458. allergic_history := c.GetString("allergic_history")
  7459. if err != nil {
  7460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7461. return
  7462. }
  7463. recordDateTime := theTime.Unix()
  7464. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7465. if err != nil {
  7466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7467. return
  7468. }
  7469. sickTimes := sickTime.Unix()
  7470. ctime := time.Now().Unix()
  7471. primary_disease := c.GetString("primary_disease")
  7472. confirm_failure_date := c.GetString("confirm_failure_date")
  7473. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7474. drug_allergy_history := c.GetString("drug_allergy_history")
  7475. physical_examination := c.GetString("physical_examination")
  7476. special_inspection := c.GetString("special_inspection")
  7477. lab_apparatus := c.GetString("lab_apparatus")
  7478. caseHistory := models.HisPatientCaseHistory{
  7479. HisPatientId: his_patient_id,
  7480. PatientId: patient_id,
  7481. Temperature: temperature,
  7482. BloodSugar: bloodsugarfloat,
  7483. Pulse: pulsefloat,
  7484. Sbp: sbpfloat,
  7485. Dbp: dbpfloat,
  7486. Height: heightfloat,
  7487. BloodFat: bloodfatfloat,
  7488. SickType: sick_type,
  7489. Symptom: symptom,
  7490. SickDate: sickTimes,
  7491. IsInfect: is_infect,
  7492. HistoryOfPresentIllness: history_of_present_illness,
  7493. PastHistory: past_history,
  7494. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7495. ChiefConplaint: chief_conplaint,
  7496. PersonalHistory: personal_history,
  7497. FamilyHistory: family_history,
  7498. Diagnostic: diagnostic,
  7499. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7500. Status: 1,
  7501. Ctime: ctime,
  7502. Mtime: ctime,
  7503. RecordDate: recordDateTime,
  7504. DeliveryWay: delivery_way,
  7505. Breathing: breathingfloat,
  7506. DoctorAdvice: doctor_advice,
  7507. Remark: remark,
  7508. Sick: sick,
  7509. Diagnose: diagnose,
  7510. AllergicHistory: allergic_history,
  7511. PrimaryDisease: primary_disease,
  7512. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7513. DrugAllergyHistory: drug_allergy_history,
  7514. PhysicalExamination: physical_examination,
  7515. SpecialInspection: special_inspection,
  7516. LabApparatus: lab_apparatus,
  7517. }
  7518. //查询该患者是否有病历
  7519. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7520. if errcodes == gorm.ErrRecordNotFound {
  7521. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7522. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7523. if err != nil {
  7524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7525. return
  7526. }
  7527. c.ServeSuccessJSON(map[string]interface{}{
  7528. "caseHistory": caseHistory,
  7529. "historyInfo": historyInfo,
  7530. })
  7531. return
  7532. } else if errcodes == nil {
  7533. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7534. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7535. if err != nil {
  7536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7537. return
  7538. }
  7539. c.ServeSuccessJSON(map[string]interface{}{
  7540. "caseHistory": caseHistory,
  7541. "historyInfo": historyInfo,
  7542. })
  7543. }
  7544. //查询该患者是否有病历
  7545. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7546. //if errcode == gorm.ErrRecordNotFound {
  7547. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7548. // if err != nil {
  7549. // c.ServeSuccessJSON(map[string]interface{}{
  7550. // "msg": "保存成功",
  7551. // })
  7552. // }
  7553. //} else if errcode == nil {
  7554. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7555. // return
  7556. //}
  7557. }
  7558. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7559. patient_id, _ := c.GetInt64("patient_id", 0)
  7560. adminUser := c.GetAdminUserInfo()
  7561. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7562. c.ServeSuccessJSON(map[string]interface{}{
  7563. "list": caseHistorys,
  7564. })
  7565. }
  7566. func (c *HisApiController) GetHisPatientCaseHistory() {
  7567. record_date, _ := c.GetInt64("record_date", 0)
  7568. patient_id, _ := c.GetInt64("patient_id", 0)
  7569. admin := c.GetAdminUserInfo()
  7570. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7571. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7572. c.ServeSuccessJSON(map[string]interface{}{
  7573. "info": info,
  7574. "case_history": case_history,
  7575. })
  7576. }
  7577. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7578. template_name := c.GetString("template_name")
  7579. template_remark := c.GetString("template_remark")
  7580. doctor := c.GetAdminUserInfo().AdminUser.Id
  7581. diagnostic := c.GetString("diagnostic")
  7582. chief_conplaint := c.GetString("chief_conplain")
  7583. history_of_present_illness := c.GetString("history_of_present_illness")
  7584. past_history := c.GetString("past_history")
  7585. personal_history := c.GetString("personal_history")
  7586. family_history := c.GetString("family_history")
  7587. user_name := c.GetString("user_name")
  7588. doctor_advice := c.GetString("doctor_advice")
  7589. remark := c.GetString("remark")
  7590. //record_date := c.GetString("record_date")
  7591. //fmt.Println("record_date--------",record_date)
  7592. //timeLayout := "2006-01-02"
  7593. //loc, _ := time.LoadLocation("Local")
  7594. //
  7595. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7596. //if err != nil {
  7597. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7598. // return
  7599. //}
  7600. //recordDateTime := theTime.Unix()
  7601. ctime := time.Now().Unix()
  7602. template := models.HisCaseHistoryTemplate{
  7603. HistoryOfPresentIllness: history_of_present_illness,
  7604. PastHistory: past_history,
  7605. ChiefConplaint: chief_conplaint,
  7606. PersonalHistory: personal_history,
  7607. FamilyHistory: family_history,
  7608. Diagnostic: diagnostic,
  7609. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7610. Status: 1,
  7611. Ctime: ctime,
  7612. Mtime: ctime,
  7613. RecordDate: time.Now().Unix(),
  7614. TemplateName: template_name,
  7615. TemplateRemark: template_remark,
  7616. Creator: doctor,
  7617. Modifier: doctor,
  7618. UserName: user_name,
  7619. DoctorAdvice: doctor_advice,
  7620. Remark: remark,
  7621. }
  7622. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7623. if err == nil {
  7624. c.ServeSuccessJSON(map[string]interface{}{
  7625. "msg": "保存成功",
  7626. })
  7627. } else {
  7628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7629. return
  7630. }
  7631. }
  7632. func (c *HisApiController) GetCaseHistoryTemplate() {
  7633. timeLayout := "2006-01-02"
  7634. loc, _ := time.LoadLocation("Local")
  7635. keyword := c.GetString("keyword")
  7636. start_time := c.GetString("start_time")
  7637. end_time := c.GetString("end_time")
  7638. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7639. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7640. admin := c.GetAdminUserInfo()
  7641. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7642. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7643. c.ServeSuccessJSON(map[string]interface{}{
  7644. "template": template,
  7645. //"history": history,
  7646. })
  7647. }
  7648. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7649. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7650. utils.ErrorLog("drug_name")
  7651. return enums.ErrorCodeParamWrong
  7652. }
  7653. adviceName, _ := json["drug_name"].(string)
  7654. if len(adviceName) == 0 {
  7655. utils.ErrorLog("len(advice_name) == 0")
  7656. return enums.ErrorCodeParamWrong
  7657. }
  7658. advice.AdviceName = adviceName
  7659. adviceDesc, _ := json["advice_desc"].(string)
  7660. advice.AdviceDesc = adviceDesc
  7661. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7662. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7663. advice.DrugSpec = drugSpec
  7664. }
  7665. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7666. remark, _ := json["remark"].(string)
  7667. advice.Remark = remark
  7668. }
  7669. if json["id"] == nil {
  7670. advice.DrugId = 0
  7671. } else {
  7672. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7673. drug_id := int64(json["id"].(float64))
  7674. advice.DrugId = drug_id
  7675. }
  7676. }
  7677. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7678. advice_id := int64(json["advice_id"].(float64))
  7679. advice.ID = advice_id
  7680. if advice.ID > 0 {
  7681. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7682. if err == nil {
  7683. if hisAdvice.ID > 0 {
  7684. advice.ExecutionTime = hisAdvice.ExecutionTime
  7685. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7686. advice.ExecutionState = hisAdvice.ExecutionState
  7687. advice.CheckTime = hisAdvice.CheckTime
  7688. advice.Checker = hisAdvice.Checker
  7689. advice.CheckState = hisAdvice.CheckState
  7690. advice.StartTime = hisAdvice.StartTime
  7691. advice.FeedetlSn = hisAdvice.FeedetlSn
  7692. }
  7693. }
  7694. }
  7695. }
  7696. //
  7697. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7698. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7699. // advice.ExecutionTime = execution_time
  7700. //}
  7701. //
  7702. //
  7703. //
  7704. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7705. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7706. // advice.ExecutionStaff = execution_staff
  7707. //}
  7708. //
  7709. //
  7710. //
  7711. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7712. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7713. // advice.ExecutionState = execution_state
  7714. //}
  7715. //
  7716. //
  7717. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7718. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7719. // advice.CheckTime = check_time
  7720. //}
  7721. //
  7722. //
  7723. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7724. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7725. // advice.CheckState = check_state
  7726. //}
  7727. //
  7728. //
  7729. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7730. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7731. // advice.Checker = checker
  7732. //}
  7733. //
  7734. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7735. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7736. // advice.StartTime = start_time
  7737. //}
  7738. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7739. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7740. advice.IsSelfDrug = is_self_drug
  7741. }
  7742. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7743. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7744. drug_way_count, _ := json["drug_way_count"].(string)
  7745. advice.DrugWayCount = drug_way_count
  7746. }
  7747. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7748. drugSpecUnit, _ := json["min_unit"].(string)
  7749. advice.DrugSpecUnit = drugSpecUnit
  7750. }
  7751. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7752. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7753. advice.SingleDose = singleDose
  7754. }
  7755. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7756. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7757. advice.SingleDoseUnit = singleDoseUnit
  7758. }
  7759. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7760. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7761. advice.PrescribingNumber = prescribingNumber
  7762. }
  7763. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7764. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7765. advice.PrescribingNumberUnit = prescribingNumberUnit
  7766. }
  7767. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7768. deliveryWay, _ := json["delivery_way"].(string)
  7769. advice.DeliveryWay = deliveryWay
  7770. }
  7771. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7772. executionFrequency, _ := json["execution_frequency"].(string)
  7773. advice.ExecutionFrequency = executionFrequency
  7774. }
  7775. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7776. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7777. advice.Price = price
  7778. }
  7779. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7780. med_list_codg, _ := json["medical_insurance_number"].(string)
  7781. advice.MedListCodg = med_list_codg
  7782. }
  7783. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7784. day := int64(json["day"].(float64))
  7785. advice.Day = day
  7786. }
  7787. return 0
  7788. }
  7789. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7790. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7791. id := int64(json["id"].(float64))
  7792. project.ID = id
  7793. historyProject, _ := service.GetHisProjectByID(id)
  7794. project.FeedetlSn = historyProject.FeedetlSn
  7795. }
  7796. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7797. project_id := int64(json["project_id"].(float64))
  7798. project.ProjectId = project_id
  7799. }
  7800. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7801. // price := int64(json["price"].(float64))
  7802. // formatInt_price := strconv.FormatInt(price, 10)
  7803. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7804. // project.Price = float_price
  7805. // }
  7806. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7807. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7808. project.Price = price
  7809. }
  7810. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7811. total, _ := json["total"].(string)
  7812. project.Count = total
  7813. }
  7814. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7815. medical_code, _ := json["medical_code"].(string)
  7816. project.MedListCodg = medical_code
  7817. }
  7818. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7819. single_dose, _ := json["single_dose"].(string)
  7820. project.SingleDose = single_dose
  7821. }
  7822. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7823. delivery_way, _ := json["delivery_way"].(string)
  7824. project.DeliveryWay = delivery_way
  7825. }
  7826. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7827. execution_frequency, _ := json["execution_frequency"].(string)
  7828. project.ExecutionFrequency = execution_frequency
  7829. }
  7830. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7831. remark, _ := json["remark"].(string)
  7832. project.Remark = remark
  7833. }
  7834. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7835. day, _ := json["number_days"].(string)
  7836. project.Day = day
  7837. }
  7838. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7839. unit, _ := json["unit"].(string)
  7840. project.Unit = unit
  7841. }
  7842. return 0
  7843. }
  7844. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7845. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7846. id := int64(json["id"].(float64))
  7847. historyAddtions, _ := service.GetHisAdditionByID(id)
  7848. additionalCharge.ID = id
  7849. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  7850. }
  7851. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7852. item_id := int64(json["item_id"].(float64))
  7853. additionalCharge.ItemId = item_id
  7854. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7855. if config.ID > 0 {
  7856. if len(config.Code) > 0 {
  7857. additionalCharge.MedListCodg = config.Code
  7858. }
  7859. }
  7860. }
  7861. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7862. // price := int64(json["price"].(float64))
  7863. // formatInt_price := strconv.FormatInt(price, 10)
  7864. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7865. // additionalCharge.Price = float_price
  7866. // }
  7867. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7868. // price := int64(json["price"].(float64))
  7869. // formatInt_price := strconv.FormatInt(price, 10)
  7870. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7871. // additionalCharge.Price = float_price
  7872. //}
  7873. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7874. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7875. additionalCharge.Price = price
  7876. }
  7877. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7878. count, _ := json["count"].(string)
  7879. counts, _ := strconv.ParseInt(count, 10, 64)
  7880. additionalCharge.Count = counts
  7881. }
  7882. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7883. item_name, _ := json["item_name"].(string)
  7884. additionalCharge.ItemName = item_name
  7885. }
  7886. return 0
  7887. }
  7888. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7889. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7890. utils.ErrorLog("drug_name")
  7891. return enums.ErrorCodeParamWrong
  7892. }
  7893. adviceName, _ := json["drug_name"].(string)
  7894. if len(adviceName) == 0 {
  7895. utils.ErrorLog("len(advice_name) == 0")
  7896. return enums.ErrorCodeParamWrong
  7897. }
  7898. advice.AdviceName = adviceName
  7899. adviceDesc, _ := json["advice_desc"].(string)
  7900. advice.AdviceDesc = adviceDesc
  7901. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7902. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7903. advice.DrugSpec = drugSpec
  7904. }
  7905. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7906. remark, _ := json["remark"].(string)
  7907. advice.Remark = remark
  7908. }
  7909. if json["id"] == nil {
  7910. advice.DrugId = 0
  7911. } else {
  7912. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7913. drug_id := int64(json["id"].(float64))
  7914. advice.DrugId = drug_id
  7915. }
  7916. }
  7917. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7918. groupno := int64(json["groupno"].(float64))
  7919. advice.Groupno = groupno
  7920. }
  7921. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7922. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7923. advice.IsSelfDrug = is_self_drug
  7924. }
  7925. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7926. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7927. drug_way_count, _ := json["drug_way_count"].(string)
  7928. advice.DrugWayCount = drug_way_count
  7929. }
  7930. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7931. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7932. advice.HospApprFlag = hosp_appr_flag
  7933. }
  7934. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7935. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7936. advice.PrescribingNumber = prescribingNumber
  7937. }
  7938. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7939. // frequency_type := int64(json["frequency_type"].(float64))
  7940. // advice.FrequencyType = frequency_type
  7941. //}
  7942. //
  7943. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7944. // day_count := int64(json["day_count"].(float64))
  7945. // advice.DayCount = day_count
  7946. //}
  7947. //
  7948. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7949. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7950. // week_day, _ := json["week_day"].(string)
  7951. // advice.WeekDay = week_day
  7952. //}
  7953. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7954. drugSpecUnit, _ := json["min_unit"].(string)
  7955. advice.DrugSpecUnit = drugSpecUnit
  7956. }
  7957. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7958. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7959. advice.SingleDose = singleDose
  7960. }
  7961. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7962. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7963. advice.SingleDoseUnit = singleDoseUnit
  7964. }
  7965. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7966. deliveryWay, _ := json["delivery_way"].(string)
  7967. advice.DeliveryWay = deliveryWay
  7968. }
  7969. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7970. executionFrequency, _ := json["execution_frequency"].(string)
  7971. advice.ExecutionFrequency = executionFrequency
  7972. }
  7973. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7974. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7975. advice.Price = price
  7976. }
  7977. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7978. med_list_codg, _ := json["medical_insurance_number"].(string)
  7979. advice.MedListCodg = med_list_codg
  7980. }
  7981. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7982. day := int64(json["day"].(float64))
  7983. advice.Day = day
  7984. }
  7985. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7986. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7987. advice.PrescribingNumberUnit = prescribingNumberUnit
  7988. }
  7989. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7990. advice_id := int64(json["advice_id"].(float64))
  7991. advice.ID = advice_id
  7992. if advice.ID > 0 {
  7993. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7994. if err == nil {
  7995. if hisAdvice.ID > 0 {
  7996. advice.ExecutionTime = hisAdvice.ExecutionTime
  7997. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7998. advice.ExecutionState = hisAdvice.ExecutionState
  7999. advice.CheckTime = hisAdvice.CheckTime
  8000. advice.Checker = hisAdvice.Checker
  8001. advice.CheckState = hisAdvice.CheckState
  8002. advice.StartTime = hisAdvice.StartTime
  8003. advice.HospApprFlag = hisAdvice.HospApprFlag
  8004. advice.IsMedicine = hisAdvice.IsMedicine
  8005. if hisAdvice.UserOrgId == 10028 {
  8006. 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 {
  8007. advice.ExecutionTime = 0
  8008. advice.ExecutionStaff = 0
  8009. advice.ExecutionState = 2
  8010. advice.CheckTime = 0
  8011. advice.Checker = 0
  8012. advice.CheckState = 2
  8013. }
  8014. } else {
  8015. 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 {
  8016. advice.ExecutionTime = 0
  8017. advice.ExecutionStaff = 0
  8018. advice.ExecutionState = 2
  8019. advice.CheckTime = 0
  8020. advice.Checker = 0
  8021. advice.CheckState = 2
  8022. advice.UpdatedTime = time.Now().Unix()
  8023. }
  8024. }
  8025. //advice.Groupno = hisAdvice.Groupno
  8026. }
  8027. }
  8028. }
  8029. }
  8030. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8031. //
  8032. //if drugStockConfig.IsOpen == 1 {
  8033. //
  8034. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8035. // if advice.ID == 0 { //医嘱不存在
  8036. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8037. // drug.Total = drug.Total - advice.PrescribingNumber
  8038. // service.UpdateBaseDrugLib(&drug)
  8039. //
  8040. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8041. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8042. // drug.Total = drug.Total - num
  8043. // service.UpdateBaseDrugLib(&drug)
  8044. // }
  8045. //
  8046. // } else if advice.ID > 0 { //医嘱存在
  8047. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8048. // var num float64
  8049. //
  8050. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8051. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8052. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8053. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8054. // drug.Total = drug.Total + num
  8055. // service.UpdateBaseDrugLib(&drug)
  8056. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8057. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8058. // drug.Total = drug.Total - num
  8059. // service.UpdateBaseDrugLib(&drug)
  8060. // }
  8061. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8062. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8063. // if num2 > advice.PrescribingNumber {
  8064. // num = num2 - advice.PrescribingNumber
  8065. // drug.Total = drug.Total + num
  8066. // service.UpdateBaseDrugLib(&drug)
  8067. // } else if num2 < advice.PrescribingNumber {
  8068. // num = advice.PrescribingNumber - num2
  8069. // drug.Total = drug.Total - num
  8070. // service.UpdateBaseDrugLib(&drug)
  8071. // }
  8072. //
  8073. // }
  8074. //
  8075. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8076. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8077. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8078. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8079. // if num1 > num2 {
  8080. // num = num1 - num2
  8081. // drug.Total = drug.Total + num
  8082. // service.UpdateBaseDrugLib(&drug)
  8083. // } else if num1 < num2 {
  8084. // num = num2 - num1
  8085. // drug.Total = drug.Total - num
  8086. // service.UpdateBaseDrugLib(&drug)
  8087. // }
  8088. //
  8089. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8090. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8091. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8092. // if hisAdvice.PrescribingNumber > num2 {
  8093. // num = hisAdvice.PrescribingNumber - num2
  8094. // drug.Total = drug.Total + num
  8095. // service.UpdateBaseDrugLib(&drug)
  8096. // } else if num2 < advice.PrescribingNumber {
  8097. // num = num2 - hisAdvice.PrescribingNumber
  8098. // drug.Total = drug.Total - num
  8099. // service.UpdateBaseDrugLib(&drug)
  8100. // }
  8101. //
  8102. // }
  8103. // }
  8104. // }
  8105. //}
  8106. //
  8107. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8108. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8109. // advice.ExecutionTime = execution_time
  8110. //}
  8111. //
  8112. //
  8113. //
  8114. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8115. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8116. // advice.ExecutionStaff = execution_staff
  8117. //}
  8118. //
  8119. //
  8120. //
  8121. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8122. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8123. // advice.ExecutionState = execution_state
  8124. //}
  8125. //
  8126. //
  8127. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8128. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8129. // advice.CheckTime = check_time
  8130. //}
  8131. //
  8132. //
  8133. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8134. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8135. // advice.CheckState = check_state
  8136. //}
  8137. //
  8138. //
  8139. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8140. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8141. // advice.Checker = checker
  8142. //}
  8143. //
  8144. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8145. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8146. // advice.StartTime = start_time
  8147. //}
  8148. return 0
  8149. }
  8150. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8151. project.ExecutionStaff = 0
  8152. project.ExecutionState = 2
  8153. project.ExecutionTime = 0
  8154. project.Checker = 0
  8155. project.CheckState = 2
  8156. project.CheckTime = 0
  8157. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8158. id := int64(json["id"].(float64))
  8159. project.ID = id
  8160. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8161. project.ExecutionStaff = temp_project.ExecutionStaff
  8162. project.ExecutionState = temp_project.ExecutionState
  8163. project.ExecutionTime = temp_project.ExecutionTime
  8164. project.Checker = temp_project.Checker
  8165. project.CheckState = temp_project.CheckState
  8166. project.CheckTime = temp_project.CheckTime
  8167. project.TeamId = temp_project.TeamId
  8168. }
  8169. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8170. types := int64(json["type"].(float64))
  8171. project.Type = types
  8172. }
  8173. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8174. project_id := int64(json["project_id"].(float64))
  8175. project.ProjectId = project_id
  8176. }
  8177. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8178. team_id := int64(json["team_id"].(float64))
  8179. project.TeamId = team_id
  8180. }
  8181. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8182. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8183. project.Price = price
  8184. }
  8185. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8186. total, _ := json["total"].(string)
  8187. //totals, _ := strconv.ParseInt(total, 10, 64)
  8188. project.Count = total
  8189. }
  8190. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8191. medical_code, _ := json["medical_code"].(string)
  8192. project.MedListCodg = medical_code
  8193. }
  8194. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8195. single_dose, _ := json["single_dose"].(string)
  8196. project.SingleDose = single_dose
  8197. }
  8198. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8199. delivery_way, _ := json["delivery_way"].(string)
  8200. project.DeliveryWay = delivery_way
  8201. }
  8202. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8203. execution_frequency, _ := json["execution_frequency"].(string)
  8204. project.ExecutionFrequency = execution_frequency
  8205. }
  8206. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8207. remark, _ := json["remark"].(string)
  8208. project.Remark = remark
  8209. }
  8210. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8211. day, _ := json["number_days"].(string)
  8212. project.Day = day
  8213. }
  8214. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8215. unit, _ := json["unit"].(string)
  8216. project.Unit = unit
  8217. }
  8218. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8219. // frequency_type := int64(json["frequency_type"].(float64))
  8220. // project.FrequencyType = frequency_type
  8221. //}
  8222. //
  8223. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8224. // day_count := int64(json["day_count"].(float64))
  8225. // project.DayCount = day_count
  8226. //}
  8227. //
  8228. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8229. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8230. // week_day, _ := json["week_day"].(string)
  8231. // project.WeekDay = week_day
  8232. //}
  8233. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8234. //
  8235. //if project.ID == 0 {
  8236. // if stockConfig.IsOpen == 1 {
  8237. // if project.Type == 3 {
  8238. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8239. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8240. // good.Total = good.Total - f_count
  8241. // service.UpdateGoodInfo(&good)
  8242. // }
  8243. // }
  8244. //
  8245. //} else {
  8246. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8247. //
  8248. // if stockConfig.IsOpen == 1 {
  8249. // if project.Type == 3 {
  8250. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8251. // if project.Count < temp_project.Count {
  8252. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8253. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8254. //
  8255. // other_count := f_count_two - f_count_one
  8256. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8257. // good.Total = good.Total + other_count_two
  8258. // service.UpdateGoodInfo(&good)
  8259. // } else if project.Count > temp_project.Count {
  8260. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8261. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8262. //
  8263. // other_count := f_count_one - f_count_two
  8264. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8265. // good.Total = good.Total - other_count_two
  8266. // service.UpdateGoodInfo(&good)
  8267. // }
  8268. //
  8269. // }
  8270. // }
  8271. //
  8272. //}
  8273. return 0
  8274. }
  8275. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8276. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8277. utils.ErrorLog("drug_name")
  8278. return enums.ErrorCodeParamWrong
  8279. }
  8280. adviceName, _ := json["drug_name"].(string)
  8281. if len(adviceName) == 0 {
  8282. utils.ErrorLog("len(advice_name) == 0")
  8283. return enums.ErrorCodeParamWrong
  8284. }
  8285. advice.AdviceName = adviceName
  8286. adviceDesc, _ := json["advice_desc"].(string)
  8287. advice.AdviceDesc = adviceDesc
  8288. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8289. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8290. advice.DrugSpec = drugSpec
  8291. }
  8292. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8293. remark, _ := json["remark"].(string)
  8294. advice.Remark = remark
  8295. }
  8296. if json["id"] == nil {
  8297. advice.DrugId = 0
  8298. } else {
  8299. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8300. drug_id := int64(json["id"].(float64))
  8301. advice.DrugId = drug_id
  8302. }
  8303. }
  8304. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8305. groupno := int64(json["groupno"].(float64))
  8306. advice.Groupno = groupno
  8307. }
  8308. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8309. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8310. advice.IsSelfDrug = is_self_drug
  8311. }
  8312. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8313. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8314. drug_way_count, _ := json["drug_way_count"].(string)
  8315. advice.DrugWayCount = drug_way_count
  8316. }
  8317. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8318. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8319. advice.HospApprFlag = hosp_appr_flag
  8320. }
  8321. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8322. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8323. advice.PrescribingNumber = prescribingNumber
  8324. }
  8325. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8326. // frequency_type := int64(json["frequency_type"].(float64))
  8327. // advice.FrequencyType = frequency_type
  8328. //}
  8329. //
  8330. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8331. // day_count := int64(json["day_count"].(float64))
  8332. // advice.DayCount = day_count
  8333. //}
  8334. //
  8335. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8336. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8337. // week_day, _ := json["week_day"].(string)
  8338. // advice.WeekDay = week_day
  8339. //}
  8340. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8341. drugSpecUnit, _ := json["min_unit"].(string)
  8342. advice.DrugSpecUnit = drugSpecUnit
  8343. }
  8344. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8345. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8346. advice.SingleDose = singleDose
  8347. }
  8348. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8349. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8350. advice.SingleDoseUnit = singleDoseUnit
  8351. }
  8352. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8353. deliveryWay, _ := json["delivery_way"].(string)
  8354. advice.DeliveryWay = deliveryWay
  8355. }
  8356. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8357. executionFrequency, _ := json["execution_frequency"].(string)
  8358. advice.ExecutionFrequency = executionFrequency
  8359. }
  8360. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8361. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8362. advice.Price = price
  8363. }
  8364. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8365. med_list_codg, _ := json["medical_insurance_number"].(string)
  8366. advice.MedListCodg = med_list_codg
  8367. }
  8368. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8369. day := int64(json["day"].(float64))
  8370. advice.Day = day
  8371. }
  8372. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8373. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8374. advice.PrescribingNumberUnit = prescribingNumberUnit
  8375. }
  8376. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8377. advice_id := int64(json["advice_id"].(float64))
  8378. advice.ID = advice_id
  8379. if advice.ID > 0 {
  8380. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8381. if err == nil {
  8382. if hisAdvice.ID > 0 {
  8383. advice.ExecutionTime = hisAdvice.ExecutionTime
  8384. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8385. advice.ExecutionState = hisAdvice.ExecutionState
  8386. advice.CheckTime = hisAdvice.CheckTime
  8387. advice.Checker = hisAdvice.Checker
  8388. advice.DrugCode = hisAdvice.DrugCode
  8389. advice.CheckState = hisAdvice.CheckState
  8390. advice.StartTime = hisAdvice.StartTime
  8391. advice.HospApprFlag = hisAdvice.HospApprFlag
  8392. advice.IsMedicine = hisAdvice.IsMedicine
  8393. if hisAdvice.UserOrgId == 10028 {
  8394. 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 {
  8395. advice.ExecutionTime = 0
  8396. advice.ExecutionStaff = 0
  8397. advice.ExecutionState = 2
  8398. advice.CheckTime = 0
  8399. advice.Checker = 0
  8400. advice.CheckState = 2
  8401. }
  8402. } else {
  8403. 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 {
  8404. advice.ExecutionTime = 0
  8405. advice.ExecutionStaff = 0
  8406. advice.ExecutionState = 2
  8407. advice.CheckTime = 0
  8408. advice.Checker = 0
  8409. advice.CheckState = 2
  8410. //advice.UpdatedTime = time.Now().Unix()
  8411. advice.CreatedTime = hisAdvice.CreatedTime
  8412. advice.UpdatedTime = time.Now().Unix()
  8413. } else {
  8414. advice.CreatedTime = hisAdvice.CreatedTime
  8415. advice.UpdatedTime = hisAdvice.UpdatedTime
  8416. }
  8417. }
  8418. //advice.Groupno = hisAdvice.Groupno
  8419. } else {
  8420. advice.IsMedicine = 0
  8421. ctime := time.Now().Unix()
  8422. advice.CreatedTime = ctime
  8423. advice.UpdatedTime = ctime
  8424. }
  8425. }
  8426. } else {
  8427. advice.IsMedicine = 0
  8428. ctime := time.Now().Unix()
  8429. advice.CreatedTime = ctime
  8430. advice.UpdatedTime = ctime
  8431. }
  8432. }
  8433. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8434. //
  8435. //if drugStockConfig.IsOpen == 1 {
  8436. //
  8437. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8438. // if advice.ID == 0 { //医嘱不存在
  8439. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8440. // drug.Total = drug.Total - advice.PrescribingNumber
  8441. // service.UpdateBaseDrugLib(&drug)
  8442. //
  8443. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8444. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8445. // drug.Total = drug.Total - num
  8446. // service.UpdateBaseDrugLib(&drug)
  8447. // }
  8448. //
  8449. // } else if advice.ID > 0 { //医嘱存在
  8450. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8451. // var num float64
  8452. //
  8453. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8454. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8455. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8456. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8457. // drug.Total = drug.Total + num
  8458. // service.UpdateBaseDrugLib(&drug)
  8459. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8460. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8461. // drug.Total = drug.Total - num
  8462. // service.UpdateBaseDrugLib(&drug)
  8463. // }
  8464. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8465. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8466. // if num2 > advice.PrescribingNumber {
  8467. // num = num2 - advice.PrescribingNumber
  8468. // drug.Total = drug.Total + num
  8469. // service.UpdateBaseDrugLib(&drug)
  8470. // } else if num2 < advice.PrescribingNumber {
  8471. // num = advice.PrescribingNumber - num2
  8472. // drug.Total = drug.Total - num
  8473. // service.UpdateBaseDrugLib(&drug)
  8474. // }
  8475. //
  8476. // }
  8477. //
  8478. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8479. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8480. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8481. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8482. // if num1 > num2 {
  8483. // num = num1 - num2
  8484. // drug.Total = drug.Total + num
  8485. // service.UpdateBaseDrugLib(&drug)
  8486. // } else if num1 < num2 {
  8487. // num = num2 - num1
  8488. // drug.Total = drug.Total - num
  8489. // service.UpdateBaseDrugLib(&drug)
  8490. // }
  8491. //
  8492. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8493. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8494. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8495. // if hisAdvice.PrescribingNumber > num2 {
  8496. // num = hisAdvice.PrescribingNumber - num2
  8497. // drug.Total = drug.Total + num
  8498. // service.UpdateBaseDrugLib(&drug)
  8499. // } else if num2 < advice.PrescribingNumber {
  8500. // num = num2 - hisAdvice.PrescribingNumber
  8501. // drug.Total = drug.Total - num
  8502. // service.UpdateBaseDrugLib(&drug)
  8503. // }
  8504. //
  8505. // }
  8506. // }
  8507. // }
  8508. //}
  8509. //
  8510. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8511. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8512. // advice.ExecutionTime = execution_time
  8513. //}
  8514. //
  8515. //
  8516. //
  8517. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8518. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8519. // advice.ExecutionStaff = execution_staff
  8520. //}
  8521. //
  8522. //
  8523. //
  8524. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8525. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8526. // advice.ExecutionState = execution_state
  8527. //}
  8528. //
  8529. //
  8530. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8531. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8532. // advice.CheckTime = check_time
  8533. //}
  8534. //
  8535. //
  8536. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8537. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8538. // advice.CheckState = check_state
  8539. //}
  8540. //
  8541. //
  8542. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8543. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8544. // advice.Checker = checker
  8545. //}
  8546. //
  8547. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8548. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8549. // advice.StartTime = start_time
  8550. //}
  8551. return 0
  8552. }
  8553. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8554. project.ExecutionStaff = 0
  8555. project.ExecutionState = 2
  8556. project.ExecutionTime = 0
  8557. project.Checker = 0
  8558. project.CheckState = 2
  8559. project.CheckTime = 0
  8560. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8561. id := int64(json["id"].(float64))
  8562. project.ID = id
  8563. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8564. project.ExecutionStaff = temp_project.ExecutionStaff
  8565. project.ExecutionState = temp_project.ExecutionState
  8566. project.ExecutionTime = temp_project.ExecutionTime
  8567. project.Checker = temp_project.Checker
  8568. project.CheckState = temp_project.CheckState
  8569. project.CheckTime = temp_project.CheckTime
  8570. project.TeamId = temp_project.TeamId
  8571. }
  8572. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8573. types := int64(json["type"].(float64))
  8574. project.Type = types
  8575. }
  8576. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8577. project_id := int64(json["project_id"].(float64))
  8578. project.ProjectId = project_id
  8579. }
  8580. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8581. team_id := int64(json["team_id"].(float64))
  8582. project.TeamId = team_id
  8583. }
  8584. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8585. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8586. project.Price = price
  8587. }
  8588. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8589. total, _ := json["total"].(string)
  8590. //totals, _ := strconv.ParseInt(total, 10, 64)
  8591. project.Count = total
  8592. }
  8593. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8594. medical_code, _ := json["medical_code"].(string)
  8595. project.MedListCodg = medical_code
  8596. }
  8597. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8598. single_dose, _ := json["single_dose"].(string)
  8599. project.SingleDose = single_dose
  8600. }
  8601. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8602. delivery_way, _ := json["delivery_way"].(string)
  8603. project.DeliveryWay = delivery_way
  8604. }
  8605. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8606. execution_frequency, _ := json["execution_frequency"].(string)
  8607. project.ExecutionFrequency = execution_frequency
  8608. }
  8609. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8610. remark, _ := json["remark"].(string)
  8611. project.Remark = remark
  8612. }
  8613. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8614. day, _ := json["number_days"].(string)
  8615. project.Day = day
  8616. }
  8617. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8618. unit, _ := json["unit"].(string)
  8619. project.Unit = unit
  8620. }
  8621. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8622. // frequency_type := int64(json["frequency_type"].(float64))
  8623. // project.FrequencyType = frequency_type
  8624. //}
  8625. //
  8626. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8627. // day_count := int64(json["day_count"].(float64))
  8628. // project.DayCount = day_count
  8629. //}
  8630. //
  8631. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8632. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8633. // week_day, _ := json["week_day"].(string)
  8634. // project.WeekDay = week_day
  8635. //}
  8636. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8637. //
  8638. //if project.ID == 0 {
  8639. // if stockConfig.IsOpen == 1 {
  8640. // if project.Type == 3 {
  8641. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8642. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8643. // good.Total = good.Total - f_count
  8644. // service.UpdateGoodInfo(&good)
  8645. // }
  8646. // }
  8647. //
  8648. //} else {
  8649. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8650. //
  8651. // if stockConfig.IsOpen == 1 {
  8652. // if project.Type == 3 {
  8653. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8654. // if project.Count < temp_project.Count {
  8655. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8656. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8657. //
  8658. // other_count := f_count_two - f_count_one
  8659. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8660. // good.Total = good.Total + other_count_two
  8661. // service.UpdateGoodInfo(&good)
  8662. // } else if project.Count > temp_project.Count {
  8663. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8664. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8665. //
  8666. // other_count := f_count_one - f_count_two
  8667. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8668. // good.Total = good.Total - other_count_two
  8669. // service.UpdateGoodInfo(&good)
  8670. // }
  8671. //
  8672. // }
  8673. // }
  8674. //
  8675. //}
  8676. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8677. id := int64(json["id"].(float64))
  8678. if id > 0 {
  8679. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8680. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8681. fmt.Println("666666")
  8682. project.Mtime = time.Now().Unix()
  8683. project.Ctime = temp_project.Ctime
  8684. } else {
  8685. project.Mtime = temp_project.Mtime
  8686. project.Ctime = temp_project.Ctime
  8687. }
  8688. } else {
  8689. ctime := time.Now().Unix()
  8690. project.Mtime = ctime
  8691. project.Ctime = ctime
  8692. }
  8693. }
  8694. return 0
  8695. }
  8696. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8697. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8698. id := int64(json["id"].(float64))
  8699. additionalCharge.ID = id
  8700. }
  8701. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8702. item_id := int64(json["item_id"].(float64))
  8703. additionalCharge.ItemId = item_id
  8704. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8705. if config.ID > 0 {
  8706. if len(config.Code) > 0 {
  8707. additionalCharge.MedListCodg = config.Code
  8708. }
  8709. }
  8710. }
  8711. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8712. // price := int64(json["price"].(float64))
  8713. // formatInt_price := strconv.FormatInt(price, 10)
  8714. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8715. // additionalCharge.Price = float_price
  8716. // }
  8717. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8718. // price := int64(json["price"].(float64))
  8719. // formatInt_price := strconv.FormatInt(price, 10)
  8720. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8721. // additionalCharge.Price = float_price
  8722. //}
  8723. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8724. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8725. additionalCharge.Price = price
  8726. }
  8727. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8728. count, _ := json["count"].(string)
  8729. counts, _ := strconv.ParseInt(count, 10, 64)
  8730. additionalCharge.Count = counts
  8731. }
  8732. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8733. item_name, _ := json["item_name"].(string)
  8734. additionalCharge.ItemName = item_name
  8735. }
  8736. return 0
  8737. }
  8738. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8739. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8740. utils.ErrorLog("drug_name")
  8741. return enums.ErrorCodeParamWrong
  8742. }
  8743. adviceName, _ := json["drug_name"].(string)
  8744. if len(adviceName) == 0 {
  8745. utils.ErrorLog("len(advice_name) == 0")
  8746. return enums.ErrorCodeParamWrong
  8747. }
  8748. advice.AdviceName = adviceName
  8749. adviceDesc, _ := json["advice_desc"].(string)
  8750. advice.AdviceDesc = adviceDesc
  8751. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8752. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8753. advice.DrugSpec = drugSpec
  8754. }
  8755. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8756. remark, _ := json["remark"].(string)
  8757. advice.Remark = remark
  8758. }
  8759. if json["id"] == nil {
  8760. advice.DrugId = 0
  8761. } else {
  8762. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8763. drug_id := int64(json["id"].(float64))
  8764. advice.DrugId = drug_id
  8765. }
  8766. }
  8767. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8768. groupno := int64(json["groupno"].(float64))
  8769. advice.Groupno = groupno
  8770. }
  8771. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8772. drugSpecUnit, _ := json["min_unit"].(string)
  8773. advice.DrugSpecUnit = drugSpecUnit
  8774. }
  8775. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8776. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8777. advice.SingleDose = singleDose
  8778. }
  8779. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8780. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8781. advice.SingleDoseUnit = singleDoseUnit
  8782. }
  8783. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8784. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8785. advice.PrescribingNumber = prescribingNumber
  8786. }
  8787. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8788. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8789. advice.PrescribingNumberUnit = prescribingNumberUnit
  8790. }
  8791. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8792. deliveryWay, _ := json["delivery_way"].(string)
  8793. advice.DeliveryWay = deliveryWay
  8794. }
  8795. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8796. executionFrequency, _ := json["execution_frequency"].(string)
  8797. advice.ExecutionFrequency = executionFrequency
  8798. }
  8799. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8800. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8801. advice.Price = price
  8802. }
  8803. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8804. med_list_codg, _ := json["medical_insurance_number"].(string)
  8805. advice.MedListCodg = med_list_codg
  8806. }
  8807. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8808. day := int64(json["day"].(float64))
  8809. advice.Day = day
  8810. }
  8811. advice.FrequencyType = 1
  8812. return 0
  8813. }
  8814. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8815. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8816. types := int64(json["type"].(float64))
  8817. project.Type = types
  8818. }
  8819. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8820. project_id := int64(json["project_id"].(float64))
  8821. project.ProjectId = project_id
  8822. }
  8823. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8824. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8825. project.Price = price
  8826. }
  8827. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8828. total, _ := json["total"].(string)
  8829. //totals, _ := strconv.ParseInt(total, 10, 64)
  8830. project.Count = total
  8831. }
  8832. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8833. medical_code, _ := json["medical_code"].(string)
  8834. project.MedListCodg = medical_code
  8835. }
  8836. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8837. single_dose, _ := json["single_dose"].(string)
  8838. project.SingleDose = single_dose
  8839. }
  8840. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8841. delivery_way, _ := json["delivery_way"].(string)
  8842. project.DeliveryWay = delivery_way
  8843. }
  8844. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8845. execution_frequency, _ := json["execution_frequency"].(string)
  8846. project.ExecutionFrequency = execution_frequency
  8847. }
  8848. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8849. remark, _ := json["remark"].(string)
  8850. project.Remark = remark
  8851. }
  8852. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8853. day, _ := json["number_days"].(string)
  8854. project.Day = day
  8855. }
  8856. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8857. unit, _ := json["unit"].(string)
  8858. project.Unit = unit
  8859. }
  8860. project.FrequencyType = 1
  8861. return 0
  8862. }
  8863. func (c *HisApiController) GetHisOrderListTwo() {
  8864. start_time := c.GetString("start_time")
  8865. end_time := c.GetString("end_time")
  8866. timeLayout := "2006-01-02"
  8867. loc, _ := time.LoadLocation("Local")
  8868. var startTime int64
  8869. if len(start_time) > 0 {
  8870. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8871. if err != nil {
  8872. //fmt.Println(err)
  8873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8874. return
  8875. }
  8876. startTime = theTime.Unix()
  8877. }
  8878. var endTime int64
  8879. if len(end_time) > 0 {
  8880. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8881. if err != nil {
  8882. utils.ErrorLog(err.Error())
  8883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8884. return
  8885. }
  8886. endTime = theTime.Unix()
  8887. }
  8888. adminUser := c.GetAdminUserInfo()
  8889. org_id := adminUser.CurrentOrgId
  8890. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  8891. if err == nil {
  8892. c.ServeSuccessJSON(map[string]interface{}{
  8893. "order2": order,
  8894. })
  8895. } else {
  8896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8897. return
  8898. }
  8899. }
  8900. func (c *HisApiController) GetHisOrderList() {
  8901. page, _ := c.GetInt64("page", -1)
  8902. limit, _ := c.GetInt64("limit", -1)
  8903. start_time := c.GetString("start_time")
  8904. end_time := c.GetString("end_time")
  8905. types, _ := c.GetInt64("type", 0)
  8906. keywords := c.GetString("keywords")
  8907. p_type, _ := c.GetInt64("p_type", 0)
  8908. sort_type, _ := c.GetInt64("sort_type", 0)
  8909. charge_type, _ := c.GetInt64("charge_type", 0)
  8910. sch_type, _ := c.GetInt64("sch_type", 0)
  8911. zone_type, _ := c.GetInt64("zone_type", 0)
  8912. med_type, _ := c.GetInt64("med_type", 0)
  8913. timeLayout := "2006-01-02"
  8914. loc, _ := time.LoadLocation("Local")
  8915. var startTime int64
  8916. if len(start_time) > 0 {
  8917. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8918. if err != nil {
  8919. //fmt.Println(err)
  8920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8921. return
  8922. }
  8923. startTime = theTime.Unix()
  8924. }
  8925. var endTime int64
  8926. if len(end_time) > 0 {
  8927. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8928. if err != nil {
  8929. utils.ErrorLog(err.Error())
  8930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8931. return
  8932. }
  8933. endTime = theTime.Unix()
  8934. }
  8935. adminUser := c.GetAdminUserInfo()
  8936. org_id := adminUser.CurrentOrgId
  8937. 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)
  8938. for _, item := range order {
  8939. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8940. item.DoctorName = info.Doctor
  8941. item.DepartmentName = info.XtHisDepartment.Name
  8942. }
  8943. if err == nil {
  8944. c.ServeSuccessJSON(map[string]interface{}{
  8945. "order": order,
  8946. "total": total,
  8947. })
  8948. } else {
  8949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8950. return
  8951. }
  8952. }
  8953. func (c *HisApiController) GetHisOrder() {
  8954. patient_id, _ := c.GetInt64("patient_id", 0)
  8955. number := c.GetString("number")
  8956. adminInfo := c.GetAdminUserInfo()
  8957. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8958. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8959. if err == nil {
  8960. c.ServeSuccessJSON(map[string]interface{}{
  8961. "order": order,
  8962. "prescription": prescriptions,
  8963. })
  8964. } else {
  8965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8966. return
  8967. }
  8968. }
  8969. func (c *HisApiController) GetHisPrescriptionList() {
  8970. record_date := c.GetString("record_date")
  8971. keywords := c.GetString("keywords")
  8972. page, _ := c.GetInt64("page")
  8973. limit, _ := c.GetInt64("limit")
  8974. sch_type, _ := c.GetInt64("sch_type")
  8975. timeLayout := "2006-01-02"
  8976. loc, _ := time.LoadLocation("Local")
  8977. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8978. if err != nil {
  8979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8980. return
  8981. }
  8982. recordDateTime := theTime.Unix()
  8983. adminInfo := c.GetAdminUserInfo()
  8984. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8985. //adminInfo := c.GetAdminUserInfo()
  8986. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8987. //fmt.Println(prescriptionOrder)
  8988. if err == nil {
  8989. c.ServeSuccessJSON(map[string]interface{}{
  8990. "order": prescriptionOrder,
  8991. "total": total,
  8992. })
  8993. } else {
  8994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8995. return
  8996. }
  8997. }
  8998. func (c *HisApiController) GetHisPrescriptionInfo() {
  8999. id, _ := c.GetInt64("id")
  9000. adminInfo := c.GetAdminUserInfo()
  9001. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  9002. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  9003. if err == nil {
  9004. c.ServeSuccessJSON(map[string]interface{}{
  9005. "order": prescriptionOrder,
  9006. "prescription": prescription,
  9007. })
  9008. } else {
  9009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9010. return
  9011. }
  9012. }
  9013. func (c *HisApiController) GetMedicalInsuranceConfig() {
  9014. adminUser := c.GetAdminUserInfo()
  9015. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  9016. c.ServeSuccessJSON(map[string]interface{}{
  9017. "config": config,
  9018. })
  9019. }
  9020. type ResultTwo struct {
  9021. ErrMsg interface{} `json:"err_msg"`
  9022. InfRefmsgid string `json:"inf_refmsgid"`
  9023. Infcode int64 `json:"infcode"`
  9024. Output struct {
  9025. Baseinfo struct {
  9026. Age float64 `json:"age"`
  9027. Brdy string `json:"brdy"`
  9028. Certno string `json:"certno"`
  9029. Gend string `json:"gend"`
  9030. Naty string `json:"naty"`
  9031. PsnCertType string `json:"psn_cert_type"`
  9032. PsnName string `json:"psn_name"`
  9033. PsnNo string `json:"psn_no"`
  9034. } `json:"baseinfo"`
  9035. Idetinfo []interface{} `json:"idetinfo"`
  9036. Iinfo []struct {
  9037. Balc float64 `json:"balc"`
  9038. CvlservFlag string `json:"cvlserv_flag"`
  9039. EmpName string `json:"emp_name"`
  9040. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  9041. Insutype string `json:"insutype"`
  9042. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  9043. PausInsuDate interface{} `json:"paus_insu_date"`
  9044. PsnInsuDate string `json:"psn_insu_date"`
  9045. PsnInsuStas string `json:"psn_insu_stas"`
  9046. PsnType string `json:"psn_type"`
  9047. } `json:"insuinfo"`
  9048. } `json:"output"`
  9049. RefmsgTime string `json:"refmsg_time"`
  9050. RespondTime string `json:"respond_time"`
  9051. Signtype interface{} `json:"signtype"`
  9052. WarnInfo interface{} `json:"warn_info"`
  9053. }
  9054. type ResultThree struct {
  9055. Cainfo interface{} `json:"cainfo"`
  9056. ErrMsg interface{} `json:"err_msg"`
  9057. InfRefmsgid string `json:"inf_refmsgid"`
  9058. Infcode int64 `json:"infcode"`
  9059. Output struct {
  9060. Data struct {
  9061. IptOtpNo string `json:"ipt_otp_no"`
  9062. MdtrtID string `json:"mdtrt_id"`
  9063. PsnNo string `json:"psn_no"`
  9064. } `json:"data"`
  9065. } `json:"output"`
  9066. RefmsgTime string `json:"refmsg_time"`
  9067. RespondTime string `json:"respond_time"`
  9068. Signtype interface{} `json:"signtype"`
  9069. WarnMsg interface{} `json:"warn_msg"`
  9070. }
  9071. type ResultFour struct {
  9072. Cainfo string `json:"cainfo"`
  9073. ErrMsg string `json:"err_msg"`
  9074. InfRefmsgid string `json:"inf_refmsgid"`
  9075. Infcode int64 `json:"infcode"`
  9076. Output struct {
  9077. Result []struct {
  9078. BasMednFlag string `json:"bas_medn_flag"`
  9079. ChldMedcFlag string `json:"chld_medc_flag"`
  9080. ChrgitmLv string `json:"chrgitm_lv"`
  9081. Cnt float64 `json:"cnt"`
  9082. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  9083. DrtReimFlag string `json:"drt_reim_flag"`
  9084. FeedetlSn string `json:"feedetl_sn"`
  9085. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9086. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  9087. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9088. ListSpItemFlag string `json:"list_sp_item_flag"`
  9089. LmtUsedFlag string `json:"lmt_used_flag"`
  9090. MedChrgitmType string `json:"med_chrgitm_type"`
  9091. Memo string `json:"memo"`
  9092. OverlmtAmt float64 `json:"overlmt_amt"`
  9093. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9094. Pric float64 `json:"pric"`
  9095. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  9096. SelfpayProp float64 `json:"selfpay_prop"`
  9097. } `json:"result"`
  9098. } `json:"output"`
  9099. RefmsgTime string `json:"refmsg_time"`
  9100. RespondTime string `json:"respond_time"`
  9101. Signtype string `json:"signtype"`
  9102. WarnMsg string `json:"warn_msg"`
  9103. }
  9104. type ResultFive struct {
  9105. Insutype string `json:"insutype"`
  9106. }
  9107. type ResultSix struct {
  9108. Cainfo interface{} `json:"cainfo"`
  9109. ErrMsg interface{} `json:"err_msg"`
  9110. InfRefmsgid string `json:"inf_refmsgid"`
  9111. Infcode int64 `json:"infcode"`
  9112. Output struct {
  9113. } `json:"output"`
  9114. RefmsgTime string `json:"refmsg_time"`
  9115. RespondTime string `json:"respond_time"`
  9116. Signtype interface{} `json:"signtype"`
  9117. WarnMsg interface{} `json:"warn_msg"`
  9118. }
  9119. type ResultSeven struct {
  9120. Cainfo string `json:"cainfo"`
  9121. ErrMsg string `json:"err_msg"`
  9122. InfRefmsgid string `json:"inf_refmsgid"`
  9123. Infcode int64 `json:"infcode"`
  9124. Output struct {
  9125. Setldetail []interface{} `json:"setldetail"`
  9126. Setlinfo struct {
  9127. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9128. AcctPay float64 `json:"acct_pay"`
  9129. ActPayDedc float64 `json:"act_pay_dedc"`
  9130. Age float64 `json:"age"`
  9131. Balc float64 `json:"balc"`
  9132. Brdy string `json:"brdy"`
  9133. Certno string `json:"certno"`
  9134. ClrOptins string `json:"clr_optins"`
  9135. ClrType string `json:"clr_type"`
  9136. ClrWay string `json:"clr_way"`
  9137. CvlservFlag string `json:"cvlserv_flag"`
  9138. CvlservPay float64 `json:"cvlserv_pay"`
  9139. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9140. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9141. Gend string `json:"gend"`
  9142. HifesPay float64 `json:"hifes_pay"`
  9143. HifmiPay float64 `json:"hifmi_pay"`
  9144. HifobPay float64 `json:"hifob_pay"`
  9145. HifpPay float64 `json:"hifp_pay"`
  9146. HospPartAmt float64 `json:"hosp_part_amt"`
  9147. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9148. Insutype string `json:"insutype"`
  9149. MafPay float64 `json:"maf_pay"`
  9150. MdtrtCertType string `json:"mdtrt_cert_type"`
  9151. MdtrtID string `json:"mdtrt_id"`
  9152. MedType string `json:"med_type"`
  9153. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9154. MedinsSetlID string `json:"medins_setl_id"`
  9155. Naty string `json:"naty"`
  9156. OthPay float64 `json:"oth_pay"`
  9157. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9158. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9159. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9160. PsnCashPay float64 `json:"psn_cash_pay"`
  9161. PsnCertType string `json:"psn_cert_type"`
  9162. PsnName string `json:"psn_name"`
  9163. PsnNo string `json:"psn_no"`
  9164. PsnPartAmt float64 `json:"psn_part_amt"`
  9165. PsnType string `json:"psn_type"`
  9166. SetlID string `json:"setl_id"`
  9167. SetlTime string `json:"setl_time"`
  9168. } `json:"setlinfo"`
  9169. } `json:"output"`
  9170. RefmsgTime string `json:"refmsg_time"`
  9171. RespondTime string `json:"respond_time"`
  9172. Signtype interface{} `json:"signtype"`
  9173. WarnMsg interface{} `json:"warn_msg"`
  9174. }
  9175. type ResultEight struct {
  9176. Cainfo string `json:"cainfo"`
  9177. ErrMsg string `json:"err_msg"`
  9178. InfRefmsgid string `json:"inf_refmsgid"`
  9179. Infcode int64 `json:"infcode"`
  9180. Output struct {
  9181. Stmtinfo struct {
  9182. SetlOptins string `json:"setl_optins"`
  9183. StmtRslt string `json:"stmt_rslt"`
  9184. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  9185. } `json:"stmtinfo"`
  9186. } `json:"output"`
  9187. RefmsgTime string `json:"refmsg_time"`
  9188. RespondTime string `json:"respond_time"`
  9189. Signtype interface{} `json:"signtype"`
  9190. WarnMsg interface{} `json:"warn_msg"`
  9191. }
  9192. type ResultNine struct {
  9193. Cainfo string `json:"cainfo"`
  9194. ErrMsg string `json:"err_msg"`
  9195. InfRefmsgid string `json:"inf_refmsgid"`
  9196. Infcode int64 `json:"infcode"`
  9197. Output struct {
  9198. FileQuryNo string `json:"file_qury_no"`
  9199. } `json:"output"`
  9200. RefmsgTime string `json:"refmsg_time"`
  9201. RespondTime string `json:"respond_time"`
  9202. Signtype interface{} `json:"signtype"`
  9203. WarnMsg interface{} `json:"warn_msg"`
  9204. }
  9205. type ResultTen struct {
  9206. Cainfo string `json:"cainfo"`
  9207. ErrMsg string `json:"err_msg"`
  9208. InfRefmsgid string `json:"inf_refmsgid"`
  9209. Infcode int64 `json:"infcode"`
  9210. Output struct {
  9211. DldEndtime string `json:"dld_endtime"`
  9212. FileQuryNo string `json:"file_qury_no"`
  9213. Filename string `json:"filename"`
  9214. } `json:"output"`
  9215. RefmsgTime string `json:"refmsg_time"`
  9216. RespondTime string `json:"respond_time"`
  9217. Signtype interface{} `json:"signtype"`
  9218. WarnMsg interface{} `json:"warn_msg"`
  9219. }
  9220. type ResultEleven struct {
  9221. Cainfo string `json:"cainfo"`
  9222. ErrMsg string `json:"err_msg"`
  9223. InfRefmsgid string `json:"inf_refmsgid"`
  9224. Infcode int64 `json:"infcode"`
  9225. Output struct {
  9226. Setlinfo struct {
  9227. FixmedinsName string `json:"fixmedins_name"`
  9228. FixmedinsCode string `json:"fixmedins_code"`
  9229. PsnNo string `json:"psn_no"`
  9230. PsnName string `json:"psn_name"`
  9231. HifobPay float64 `json:"hifob_pay"`
  9232. Gend string `json:"gend"`
  9233. Brdy string `json:"brdy"`
  9234. PsnCertType string `json:"psn_cert_type"`
  9235. PsnType string `json:"psn_type"`
  9236. EmpName string `json:"emp_name"`
  9237. Certno string `json:"certno"`
  9238. Insutype string `json:"insutype"`
  9239. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9240. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9241. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9242. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9243. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9244. ActPayDedc float64 `json:"act_pay_dedc"`
  9245. HifpPay float64 `json:"hifp_pay"`
  9246. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9247. CvlservPay float64 `json:"cvlserv_pay"`
  9248. HifesPay float64 `json:"hifes_pay"`
  9249. HifmiPay float64 `json:"hifmi_pay"`
  9250. MafPay float64 `json:"maf_pay"`
  9251. OthPay float64 `json:"oth_pay"`
  9252. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9253. PsnPay float64 `json:"psn_pay"`
  9254. AcctPay float64 `json:"acct_pay"`
  9255. CashPayamt float64 `json:"cash_payamt"`
  9256. Balc float64 `json:"balc"`
  9257. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9258. MedinsSetlId string `json:"medins_setl_id"`
  9259. RefdSetlFlag string `json:"refd_setl_flag"`
  9260. SetlTime string `json:"setl_time"`
  9261. MedType string `json:"med_type"`
  9262. } `json:"setlinfo"`
  9263. } `json:"output"`
  9264. RefmsgTime string `json:"refmsg_time"`
  9265. RespondTime string `json:"respond_time"`
  9266. Signtype interface{} `json:"signtype"`
  9267. WarnMsg interface{} `json:"warn_msg"`
  9268. }
  9269. type Custom struct {
  9270. DetItemFeeSumamt string
  9271. Cut string
  9272. FeedetlSn string
  9273. Price string
  9274. MedListCodg string
  9275. Type int64
  9276. AdviceId int64
  9277. ProjectId int64
  9278. ItemId int64
  9279. CostType int64
  9280. }
  9281. // 获取个人信息----挂号-----上传就诊信息
  9282. func (c *HisApiController) GetRegisterInfo() {
  9283. id, _ := c.GetInt64("id")
  9284. record_time := c.GetString("record_time")
  9285. settlementValue, _ := c.GetInt64("settlement_value")
  9286. medical_insurance_card := c.GetString("medical_insurance_card")
  9287. name := c.GetString("name")
  9288. id_card_type, _ := c.GetInt64("id_card_type")
  9289. certificates, _ := c.GetInt64("certificates")
  9290. medical_care, _ := c.GetInt64("medical_care")
  9291. birthday := c.GetString("birthday")
  9292. age, _ := c.GetInt64("age")
  9293. id_card := c.GetString("id_card")
  9294. register_type, _ := c.GetInt64("register")
  9295. doctor, _ := c.GetInt64("doctor")
  9296. department, _ := c.GetInt64("department")
  9297. gender, _ := c.GetInt64("sex")
  9298. phone := c.GetString("phone")
  9299. registration_fee, _ := c.GetFloat("registration_fee")
  9300. medical_expenses, _ := c.GetFloat("medical_expenses")
  9301. social_type, _ := c.GetInt64("social_type")
  9302. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9303. diagnosis_ids := c.GetString("diagnosis")
  9304. sick_type, _ := c.GetInt64("sick_type")
  9305. reg_type := c.GetString("p_type")
  9306. timeLayout := "2006-01-02"
  9307. loc, _ := time.LoadLocation("Local")
  9308. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9309. birthUnix := birthdays.Unix()
  9310. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9311. if err != nil {
  9312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9313. return
  9314. }
  9315. recordDateTime := theTime.Unix()
  9316. adminInfo := c.GetAdminUserInfo()
  9317. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9318. if tempPatient.ID == 0 {
  9319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9320. return
  9321. }
  9322. var patient service.Patients
  9323. if id == 0 {
  9324. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9325. } else {
  9326. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9327. }
  9328. if patient.ID == 0 {
  9329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9330. return
  9331. }
  9332. if len(patient.IdCardNo) == 0 {
  9333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9334. return
  9335. }
  9336. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9337. if len(his) >= 1 {
  9338. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9339. if len(his) >= 1 && order.ID == 0 {
  9340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9341. return
  9342. }
  9343. }
  9344. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9345. fmt.Println(timeStr)
  9346. timeArr := strings.Split(timeStr, " ")
  9347. fmt.Println(timeArr)
  9348. timeArrTwo := strings.Split(timeArr[0], "-")
  9349. timeArrThree := strings.Split(timeArr[1], ":")
  9350. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9351. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9352. if len(lists) == 0 {
  9353. var hisPatient models.XtHisPatient
  9354. hisPatient = models.XtHisPatient{
  9355. Name: name,
  9356. Age: age,
  9357. Gender: gender,
  9358. Birthday: birthUnix,
  9359. Phone: phone,
  9360. MedicalTreatmentType: medical_care,
  9361. IdType: certificates,
  9362. IdCardNo: id_card,
  9363. BalanceAccountsType: settlementValue,
  9364. SocialType: social_type,
  9365. MedicalInsuranceNumber: medical_insurance_card,
  9366. RegisterType: register_type,
  9367. RegisterCost: registration_fee,
  9368. TreatmentCost: medical_expenses,
  9369. AdminUserId: adminInfo.AdminUser.Id,
  9370. UserOrgId: adminInfo.CurrentOrgId,
  9371. Status: 1,
  9372. RecordDate: recordDateTime,
  9373. IsReturn: 1,
  9374. PatientId: patient.ID,
  9375. Ctime: time.Now().Unix(),
  9376. Mtime: time.Now().Unix(),
  9377. Number: str,
  9378. IdCardType: id_card_type,
  9379. Departments: department,
  9380. Doctor: doctor,
  9381. PType: reg_type,
  9382. Diagnosis: diagnosis_ids,
  9383. SickType: sick_type,
  9384. }
  9385. service.CreateHisPatient(&hisPatient)
  9386. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9387. c.ServeSuccessJSON(map[string]interface{}{
  9388. "his_info": hisPatient,
  9389. })
  9390. } else {
  9391. //chrgBchno := rand.Intn(1000000) + 10000
  9392. var hisPatient models.XtHisPatient
  9393. hisPatient = models.XtHisPatient{
  9394. Name: name,
  9395. Age: age,
  9396. Gender: gender,
  9397. Birthday: birthUnix,
  9398. Phone: phone,
  9399. MedicalTreatmentType: medical_care,
  9400. IdType: certificates,
  9401. IdCardNo: id_card,
  9402. BalanceAccountsType: settlementValue,
  9403. SocialType: social_type,
  9404. MedicalInsuranceNumber: medical_insurance_card,
  9405. RegisterType: register_type,
  9406. RegisterCost: registration_fee,
  9407. TreatmentCost: medical_expenses,
  9408. AdminUserId: adminInfo.AdminUser.Id,
  9409. UserOrgId: adminInfo.CurrentOrgId,
  9410. Status: 1,
  9411. RecordDate: recordDateTime,
  9412. IsReturn: 1,
  9413. PatientId: patient.ID,
  9414. Ctime: time.Now().Unix(),
  9415. Mtime: time.Now().Unix(),
  9416. Number: str,
  9417. IdCardType: id_card_type,
  9418. Departments: department,
  9419. Doctor: doctor,
  9420. PType: reg_type,
  9421. Diagnosis: diagnosis_ids,
  9422. SickType: sick_type,
  9423. }
  9424. service.CreateHisPatient(&hisPatient)
  9425. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9426. c.ServeSuccessJSON(map[string]interface{}{
  9427. "his_info": hisPatient,
  9428. })
  9429. }
  9430. }
  9431. // 上传明细----结算
  9432. func (c *HisApiController) GetUploadInfo() {
  9433. id, _ := c.GetInt64("id")
  9434. record_time := c.GetString("record_time")
  9435. his_patient_id, _ := c.GetInt64("his_patient_id")
  9436. oth_desc := c.GetString("oth_desc")
  9437. pay_way, _ := c.GetInt64("pay_way")
  9438. pay_ways := c.GetString("pay_ways")
  9439. pay_price, _ := c.GetFloat("pay_price")
  9440. pay_card_no := c.GetString("pay_card_no")
  9441. discount_price, _ := c.GetFloat("discount_price")
  9442. preferential_price, _ := c.GetFloat("preferential_price")
  9443. reality_price, _ := c.GetFloat("reality_price")
  9444. found_price, _ := c.GetFloat("found_price")
  9445. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9446. private_price, _ := c.GetFloat("private_price")
  9447. timeLayout := "2006-01-02"
  9448. loc, _ := time.LoadLocation("Local")
  9449. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9450. fapiao_code := c.GetString("fapiao_code")
  9451. fapiao_number := c.GetString("fapiao_number")
  9452. diagnosis_id := c.GetString("diagnosis")
  9453. sick_type, _ := c.GetInt64("sick_type")
  9454. reg_type, _ := c.GetInt64("p_type")
  9455. order_id, _ := c.GetInt64("order_id")
  9456. cash_pay := c.GetString("cash_pay")
  9457. wechat_pay := c.GetString("wechat_pay")
  9458. ali_pay := c.GetString("ali_pay")
  9459. jifen_pay := c.GetString("jifen_pay")
  9460. card_desc := c.GetString("card_desc")
  9461. band_card_pay := c.GetString("band_card_pay")
  9462. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9463. tmp_decimal := c.GetString("tmp_decimal")
  9464. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9465. var decimal float64 //本次使用的押金
  9466. var errmsg error
  9467. tx := service.XTWriteDB().Begin() //开了事务
  9468. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9469. defer func() {
  9470. if errmsg != nil {
  9471. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9472. tx.Rollback()
  9473. } else {
  9474. tx.Commit()
  9475. }
  9476. }()
  9477. fmt.Println("dec_way", dec_way)
  9478. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9479. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9480. return
  9481. }
  9482. if len(tmp_decimal) > 0 {
  9483. if tmp_decimal[0] == 45 {
  9484. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9485. return
  9486. }
  9487. }
  9488. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9489. fmt.Println(errs)
  9490. decimal = tt
  9491. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9492. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9493. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9494. if err != nil {
  9495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9496. return
  9497. }
  9498. recordDateTime := theTime.Unix()
  9499. adminUser := c.GetAdminUserInfo()
  9500. var prescriptions []*models.HisPrescription
  9501. var prescriptionsOne []*models.HisPrescription
  9502. var start_time int64
  9503. var end_time int64
  9504. ids_str := c.GetString("ids")
  9505. ids_arr := strings.Split(ids_str, ",")
  9506. if tempOrder.ID == 0 {
  9507. if settle_accounts_type == 1 { //日结
  9508. fmt.Println(reg_type)
  9509. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9510. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9511. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9512. } else {
  9513. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9514. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9515. }
  9516. } else { //月结
  9517. start_time_str := c.GetString("start_time")
  9518. end_time_str := c.GetString("end_time")
  9519. timeLayout := "2006-01-02"
  9520. loc, _ := time.LoadLocation("Local")
  9521. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9522. if err != nil {
  9523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9524. return
  9525. }
  9526. recordStartTime := theStartTime.Unix()
  9527. start_time = recordStartTime
  9528. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9529. if err != nil {
  9530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9531. return
  9532. }
  9533. recordEndTime := theEndTime.Unix()
  9534. end_time = recordEndTime
  9535. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9536. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9537. }
  9538. var goods []*models.DialysisBeforePrepareGoods
  9539. var newGoods []*models.NewDialysisBeforePrepareGoods
  9540. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9541. var infos []*models.HisDoctorAdviceInfo
  9542. var infoList []*models.HisDoctorAdviceInfo
  9543. var hisAdvice []*models.HisDoctorAdviceInfo
  9544. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9545. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9546. //判断库存不足
  9547. //结算出库开关
  9548. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9549. if settConfig.IsOpen == 1 {
  9550. //判断库存的地方
  9551. for _, info := range prescriptions {
  9552. if info.Type == 1 {
  9553. infos = append(infos, info.HisDoctorAdviceInfo...)
  9554. }
  9555. if info.Type == 2 {
  9556. for _, sumItem := range info.HisPrescriptionProject {
  9557. if sumItem.Type == 3 {
  9558. var good models.DialysisBeforePrepareGoods
  9559. var newGood models.NewDialysisBeforePrepareGoods
  9560. good.GoodId = sumItem.GoodInfo.ID
  9561. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9562. count, _ := strconv.Atoi(sumItem.Count)
  9563. good.Count = int64(count)
  9564. good.StorehouseId = houseConfig.StorehouseOutInfo
  9565. good.ProjectId = sumItem.ID
  9566. goods = append(goods, &good)
  9567. newGood.GoodId = sumItem.GoodInfo.ID
  9568. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9569. count2, _ := strconv.Atoi(sumItem.Count)
  9570. newGood.Count = int64(count2)
  9571. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9572. newGood.ProjectId = sumItem.ID
  9573. newGoods = append(newGoods, &newGood)
  9574. }
  9575. }
  9576. }
  9577. }
  9578. for _, info := range prescriptionsOne {
  9579. if info.Type == 1 {
  9580. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9581. }
  9582. if info.Type == 2 {
  9583. for _, sumItem := range info.HisPrescriptionProject {
  9584. if sumItem.Type == 3 {
  9585. var newGood models.NewDialysisBeforePrepareGoods
  9586. newGood.GoodId = sumItem.GoodInfo.ID
  9587. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9588. count2, _ := strconv.Atoi(sumItem.Count)
  9589. newGood.Count = int64(count2)
  9590. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9591. newGood.ProjectId = sumItem.ID
  9592. newGoodOne = append(newGoodOne, &newGood)
  9593. }
  9594. }
  9595. }
  9596. }
  9597. //判断
  9598. for _, itemOne := range infos {
  9599. for _, itemTwo := range hisAdvice {
  9600. if itemOne.DrugId == itemTwo.DrugId {
  9601. itemTwo.Child = append(itemTwo.Child, itemOne)
  9602. }
  9603. }
  9604. }
  9605. for _, itemTwo := range hisAdvice {
  9606. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9607. var sum_out_count int64
  9608. for _, itemThree := range itemTwo.Child {
  9609. var prescribing_number int64
  9610. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9611. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9612. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9613. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9614. }
  9615. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9616. prescribing_number = parseIntPrescribingNumber
  9617. }
  9618. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9619. prescribing_number = parseIntPrescribingNumber
  9620. }
  9621. sum_out_count += prescribing_number
  9622. }
  9623. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9624. if sum_out_count > drugStockOut.FlushCount {
  9625. c.ServeSuccessJSON(map[string]interface{}{
  9626. "msg": "2",
  9627. "drug": medical,
  9628. })
  9629. return
  9630. }
  9631. }
  9632. for _, itemOne := range newGoods {
  9633. for _, item := range newGoodOne {
  9634. if itemOne.GoodId == item.GoodId {
  9635. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9636. }
  9637. }
  9638. }
  9639. for _, item := range newGoodOne {
  9640. var sum_out_count_one int64
  9641. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9642. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9643. sum_out_count_one += itemOne.Count
  9644. }
  9645. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9646. fmt.Println("sum_out_count_one", sum_out_count_one)
  9647. fmt.Println("list.FlushCount", list.FlushCount)
  9648. if sum_out_count_one > list.FlushCount {
  9649. c.ServeSuccessJSON(map[string]interface{}{
  9650. "msg": "3",
  9651. "good": good,
  9652. })
  9653. return
  9654. }
  9655. }
  9656. }
  9657. timestamp := time.Now().Unix()
  9658. tempTime := time.Unix(timestamp, 0)
  9659. timeFormat := tempTime.Format("20060102150405")
  9660. chrgBchno := rand.Intn(100000) + 10000
  9661. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9662. strconv.FormatInt(his.PatientId, 10)
  9663. var ids []int64
  9664. for _, item := range prescriptions {
  9665. ids = append(ids, item.ID)
  9666. }
  9667. var total float64
  9668. for _, item := range prescriptions {
  9669. fmt.Println(item)
  9670. if item.Type == 1 { //药品
  9671. for _, subItem := range item.HisDoctorAdviceInfo {
  9672. total = total + (subItem.Price * subItem.PrescribingNumber)
  9673. }
  9674. }
  9675. if item.Type == 2 { //项目
  9676. for _, subItem := range item.HisPrescriptionProject {
  9677. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9678. total = total + (subItem.Price * cnt)
  9679. }
  9680. }
  9681. for _, subItem := range item.HisAdditionalCharge {
  9682. total = total + (subItem.Price * float64(subItem.Count))
  9683. }
  9684. }
  9685. if reg_type == 1111 || reg_type == 1112 {
  9686. reg_type = 11
  9687. }
  9688. tm := time.Unix(time.Now().Unix(), 0)
  9689. allTotal := fmt.Sprintf("%.4f", total)
  9690. totals, _ := strconv.ParseFloat(allTotal, 64)
  9691. order := &models.HisOrder{
  9692. UserOrgId: adminUser.CurrentOrgId,
  9693. HisPatientId: his.ID,
  9694. PatientId: id,
  9695. SettleAccountsDate: recordDateTime,
  9696. Ctime: time.Now().Unix(),
  9697. Mtime: time.Now().Unix(),
  9698. Status: 1,
  9699. OrderStatus: 2,
  9700. MdtrtId: his.Number,
  9701. Number: chrg_bchno,
  9702. MedfeeSumamt: totals,
  9703. PayWay: pay_way,
  9704. PayWays: pay_ways,
  9705. PayPrice: pay_price,
  9706. MedType: strconv.Itoa(int(reg_type)),
  9707. PayCardNo: pay_card_no,
  9708. DiscountPrice: discount_price,
  9709. PreferentialPrice: preferential_price,
  9710. RealityPrice: reality_price,
  9711. FoundPrice: found_price,
  9712. MedicalInsurancePrice: medical_insurance_price,
  9713. PrivatePrice: private_price,
  9714. SettleEndTime: end_time,
  9715. SettleStartTime: start_time,
  9716. PsnPartAmt: totals,
  9717. PsnCashPay: totals,
  9718. SettleType: settle_accounts_type,
  9719. FaPiaoCode: fapiao_code,
  9720. FaPiaoNumber: fapiao_number,
  9721. Diagnosis: diagnosis_id,
  9722. PType: 2,
  9723. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9724. Decimal: decimal,
  9725. OthDesc: oth_desc,
  9726. CashPay: cash_pay,
  9727. WechatPay: wechat_pay,
  9728. AliPay: ali_pay,
  9729. JifenPay: jifen_pay,
  9730. BandCardPay: band_card_pay,
  9731. Creator: adminUser.AdminUser.Id,
  9732. CardDesc: card_desc,
  9733. }
  9734. err = service.CreateOrderTX(order, tx)
  9735. if err != nil {
  9736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9737. return
  9738. }
  9739. var customs []*Custom
  9740. for _, item := range prescriptions {
  9741. if item.Type == 1 { //药品a
  9742. for _, subItem := range item.HisDoctorAdviceInfo {
  9743. if subItem.Drug.IsUser != 1 {
  9744. cus := &Custom{
  9745. AdviceId: subItem.ID,
  9746. ProjectId: 0,
  9747. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9748. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9749. FeedetlSn: subItem.FeedetlSn,
  9750. Price: fmt.Sprintf("%.4f", subItem.Price),
  9751. MedListCodg: subItem.MedListCodg,
  9752. Type: 1,
  9753. CostType: 9,
  9754. }
  9755. customs = append(customs, cus)
  9756. }
  9757. }
  9758. }
  9759. if item.Type == 2 { //项目
  9760. for _, subItem := range item.HisPrescriptionProject {
  9761. if subItem.Type == 2 {
  9762. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9763. cus := &Custom{
  9764. AdviceId: 0,
  9765. ProjectId: subItem.ID,
  9766. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9767. Cut: fmt.Sprintf("%.4f", cnt),
  9768. FeedetlSn: subItem.FeedetlSn,
  9769. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9770. MedListCodg: subItem.MedListCodg,
  9771. Type: 2,
  9772. CostType: subItem.HisProject.CostClassify,
  9773. }
  9774. customs = append(customs, cus)
  9775. } else {
  9776. if subItem.GoodInfo.IsUser != 1 {
  9777. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9778. cus := &Custom{
  9779. AdviceId: 0,
  9780. ProjectId: subItem.ID,
  9781. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9782. Cut: fmt.Sprintf("%.4f", cnt),
  9783. FeedetlSn: subItem.FeedetlSn,
  9784. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9785. MedListCodg: subItem.MedListCodg,
  9786. Type: 2,
  9787. CostType: subItem.HisProject.CostClassify,
  9788. }
  9789. customs = append(customs, cus)
  9790. }
  9791. }
  9792. }
  9793. }
  9794. for _, item := range item.HisAdditionalCharge {
  9795. cus := &Custom{
  9796. ItemId: item.ID,
  9797. AdviceId: 0,
  9798. ProjectId: 0,
  9799. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9800. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9801. FeedetlSn: item.FeedetlSn,
  9802. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9803. MedListCodg: item.XtHisAddtionConfig.Code,
  9804. Type: 3,
  9805. CostType: 5,
  9806. }
  9807. customs = append(customs, cus)
  9808. }
  9809. }
  9810. for _, item := range customs {
  9811. var advice_id int64 = 0
  9812. var project_id int64 = 0
  9813. var item_id int64 = 0
  9814. var types int64 = 0
  9815. var med_chrgitm_type string
  9816. if item.Type == 1 {
  9817. advice_id = item.AdviceId
  9818. project_id = 0
  9819. item_id = 0
  9820. med_chrgitm_type = "09"
  9821. } else if item.Type == 2 {
  9822. med_chrgitm_type = "05"
  9823. if item.CostType == 3 {
  9824. med_chrgitm_type = "04"
  9825. }
  9826. if item.CostType == 8 {
  9827. med_chrgitm_type = "03"
  9828. }
  9829. advice_id = 0
  9830. item_id = 0
  9831. project_id = item.ProjectId
  9832. } else if item.Type == 3 {
  9833. advice_id = 0
  9834. item_id = item.ItemId
  9835. project_id = 0
  9836. med_chrgitm_type = "08"
  9837. }
  9838. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9839. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9840. pric, _ := strconv.ParseFloat(item.Price, 32)
  9841. info := &models.HisOrderInfo{
  9842. OrderNumber: order.Number,
  9843. UploadDate: time.Now().Unix(),
  9844. AdviceId: advice_id,
  9845. DetItemFeeSumamt: detItemFeeSumamt,
  9846. MedChrgitmType: med_chrgitm_type,
  9847. Cnt: cut,
  9848. Pric: pric,
  9849. PatientId: id,
  9850. Status: 1,
  9851. Mtime: time.Now().Unix(),
  9852. Ctime: time.Now().Unix(),
  9853. UserOrgId: adminUser.CurrentOrgId,
  9854. HisPatientId: his.ID,
  9855. OrderId: order.ID,
  9856. ProjectId: project_id,
  9857. Type: types,
  9858. ItemId: item_id,
  9859. }
  9860. service.CreateOrderInfoTX(info, tx)
  9861. }
  9862. his.Diagnosis = diagnosis_id
  9863. his.SickType = sick_type
  9864. his.RegisterType = reg_type
  9865. his.MedicalTreatmentType = reg_type
  9866. service.UpdataHisPateintTX(&his, tx)
  9867. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  9868. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  9869. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  9870. //判断是否使用了押金
  9871. if dec_way == "true" {
  9872. tmpstring := strconv.FormatInt(order.ID, 10)
  9873. //扣押金
  9874. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  9875. order.Decimal = decimal
  9876. service.UpDateOrderTwo(order, tx)
  9877. if errmsg != nil {
  9878. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  9879. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9880. return
  9881. }
  9882. }
  9883. if err == nil {
  9884. for _, info := range prescriptions {
  9885. if info.Type == 1 {
  9886. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  9887. }
  9888. if info.Type == 2 {
  9889. for _, sumItem := range info.HisPrescriptionProject {
  9890. if sumItem.Type == 3 {
  9891. var good models.DialysisBeforePrepareGoods
  9892. var newGood models.NewDialysisBeforePrepareGoods
  9893. var oldGood models.OldDialysisBeforePrepareGoods
  9894. good.GoodId = sumItem.GoodInfo.ID
  9895. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9896. count, _ := strconv.Atoi(sumItem.Count)
  9897. good.Count = int64(count)
  9898. good.StorehouseId = houseConfig.StorehouseOutInfo
  9899. good.ProjectId = sumItem.ID
  9900. good.PatientId = sumItem.PatientId
  9901. goods = append(goods, &good)
  9902. newGood.GoodId = sumItem.GoodInfo.ID
  9903. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9904. count2, _ := strconv.Atoi(sumItem.Count)
  9905. newGood.Count = int64(count2)
  9906. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9907. newGood.ProjectId = sumItem.ID
  9908. newGood.PatientId = sumItem.HisPatientId
  9909. newGoods = append(newGoods, &newGood)
  9910. oldGood.GoodId = sumItem.GoodInfo.ID
  9911. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9912. count3, _ := strconv.Atoi(sumItem.Count)
  9913. oldGood.Count = int64(count3)
  9914. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9915. oldGood.ProjectId = sumItem.ID
  9916. oldGood.RecordDate = sumItem.RecordDate
  9917. oldGood.PatientId = sumItem.HisPatientId
  9918. oldGoods = append(oldGoods, &oldGood)
  9919. }
  9920. }
  9921. }
  9922. }
  9923. if settConfig.IsOpen == 1 {
  9924. for _, item := range infoList {
  9925. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9926. if medical.IsUse == 2 {
  9927. //药品出库
  9928. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9929. //查询默认仓库
  9930. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9931. //查询默认仓库剩余多少库存
  9932. var sum_count int64
  9933. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9934. for _, its := range stockInfo {
  9935. if its.MaxUnit == medical.MaxUnit {
  9936. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9937. }
  9938. sum_count += its.StockMaxNumber + its.StockMinNumber
  9939. }
  9940. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9941. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9942. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9943. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9944. }
  9945. }
  9946. orgId := c.GetAdminUserInfo().CurrentOrgId
  9947. if len(oldGoods) > 0 {
  9948. timeStr := time.Now().Format("2006-01-02")
  9949. timeArr := strings.Split(timeStr, "-")
  9950. total, _ := service.FindAllWarehouseOut(orgId)
  9951. total = total + 1
  9952. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9953. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9954. number = number + total
  9955. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9956. operation_time := time.Now().Unix()
  9957. creater := c.GetAdminUserInfo().AdminUser.Id
  9958. //查询默认出库仓库库存
  9959. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9960. recordDateStr := time.Now().Format("2006-01-02")
  9961. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9962. nowtime := recordDate.Unix()
  9963. warehouseOut := models.WarehouseOut{
  9964. WarehouseOutOrderNumber: warehousing_out_order,
  9965. OperationTime: operation_time,
  9966. OrgId: orgId,
  9967. Creater: creater,
  9968. Ctime: time.Now().Unix(),
  9969. Status: 1,
  9970. WarehouseOutTime: nowtime,
  9971. Type: 1,
  9972. StorehouseId: storeConfig.StorehouseOutInfo,
  9973. IsCheck: 1,
  9974. OrderId: order.ID,
  9975. IsSys: 5,
  9976. }
  9977. //查询是否生成出库单
  9978. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9979. if out.ID == 0 {
  9980. service.AddSigleWarehouseOutOne(&warehouseOut)
  9981. }
  9982. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9983. for _, item := range oldGoods {
  9984. dialyPrepareOne := models.DialysisBeforePrepare{
  9985. GoodTypeId: item.GoodTypeId,
  9986. GoodId: item.GoodId,
  9987. PatientId: his.PatientId,
  9988. RecordDate: item.RecordDate,
  9989. UserOrgId: adminUser.CurrentOrgId,
  9990. Count: item.Count,
  9991. Ctime: time.Now().Unix(),
  9992. Creater: adminUser.AdminUser.Id,
  9993. CommdityCode: item.CommdityCode,
  9994. Status: 1,
  9995. StorehouseId: houseConfig.StorehouseOutInfo,
  9996. }
  9997. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9998. //非零用
  9999. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  10000. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10001. //查询剩余库存
  10002. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10003. var sum_count int64
  10004. for _, item := range goodList {
  10005. sum_count += item.StockCount
  10006. }
  10007. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10008. //耗材
  10009. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10010. }
  10011. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  10012. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10013. //查询剩余库存
  10014. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10015. var sum_count int64
  10016. for _, item := range goodList {
  10017. sum_count += item.StockCount
  10018. }
  10019. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10020. //耗材
  10021. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10022. }
  10023. }
  10024. }
  10025. }
  10026. c.ServeSuccessJSON(map[string]interface{}{
  10027. "msg": "结算成功",
  10028. })
  10029. }
  10030. }
  10031. }
  10032. // 退款
  10033. func (c *HisApiController) Refund() {
  10034. order_id, _ := c.GetInt64("order_id")
  10035. order, _ := service.GetHisOrderByID(order_id)
  10036. adminUser := c.GetAdminUserInfo()
  10037. orgid := c.GetAdminUserInfo().CurrentOrgId
  10038. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  10039. if err != nil {
  10040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10041. return
  10042. }
  10043. tmp := strconv.FormatInt(order.ID, 10)
  10044. //当押金不为零时产生退费记录
  10045. if order.Decimal != 0 {
  10046. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  10047. if err != nil {
  10048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10049. return
  10050. }
  10051. }
  10052. fapiao, _ := service.GetFaPiaoHisOrderByID(order_id)
  10053. if fapiao.ID > 0 {
  10054. c.ServeSuccessJSON(map[string]interface{}{
  10055. "failed_code": -10,
  10056. "msg": "该结算已经开具发票无法退费,请先红冲发票",
  10057. })
  10058. return
  10059. }
  10060. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  10061. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  10062. var goods []*models.DialysisBeforePrepareGoods
  10063. var newGoods []*models.NewDialysisBeforePrepareGoods
  10064. var infos []*models.HisDoctorAdviceInfo
  10065. for _, info := range orders {
  10066. if info.AdviceId > 0 && info.ProjectId == 0 {
  10067. infos = append(infos, &info.HisDoctorAdviceInfo)
  10068. }
  10069. if info.ProjectId > 0 && info.AdviceId == 0 {
  10070. if info.HisPrescriptionProject.Type == 3 {
  10071. var good models.DialysisBeforePrepareGoods
  10072. var newGood models.NewDialysisBeforePrepareGoods
  10073. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10074. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10075. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10076. good.Count = int64(count)
  10077. good.StorehouseId = houseConfig.StorehouseOutInfo
  10078. good.ProjectId = info.HisPrescriptionProject.ID
  10079. good.PatientId = info.PatientId
  10080. good.OrderId = order_id
  10081. goods = append(goods, &good)
  10082. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10083. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10084. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10085. newGood.Count = int64(count2)
  10086. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10087. newGood.ProjectId = info.HisPrescriptionProject.ID
  10088. newGood.RecordDate = order.SettleAccountsDate
  10089. newGood.UserOrgId = order.UserOrgId
  10090. newGood.PatientId = info.PatientId
  10091. newGood.OrderId = order_id
  10092. newGoods = append(newGoods, &newGood)
  10093. }
  10094. }
  10095. }
  10096. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  10097. if settConfig.IsOpen == 1 {
  10098. for _, item := range infos {
  10099. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10100. }
  10101. for _, item := range newGoods {
  10102. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10103. }
  10104. }
  10105. c.ServeSuccessJSON(map[string]interface{}{
  10106. "msg": "退费成功",
  10107. })
  10108. }
  10109. func (c *HisApiController) RefundNumber() {
  10110. his_patient_id, _ := c.GetInt64("id")
  10111. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10112. info.Status = 0
  10113. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  10114. if count > 0 {
  10115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  10116. return
  10117. }
  10118. err := service.SaveHisPatient(info)
  10119. if err == nil {
  10120. c.ServeSuccessJSON(map[string]interface{}{
  10121. "msg": "退号成功",
  10122. })
  10123. } else {
  10124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10125. return
  10126. }
  10127. }
  10128. func (this *HisApiController) AdditionalCharge() {
  10129. dataBody := make(map[string]interface{}, 0)
  10130. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10131. fmt.Println(err)
  10132. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  10133. patient_id := int64(dataBody["patient_id"].(float64))
  10134. medicineData, _ := dataBody["medicineData"].([]interface{})
  10135. adminUserInfo := this.GetAdminUserInfo()
  10136. orgId := adminUserInfo.CurrentOrgId
  10137. admin_user_id := adminUserInfo.AdminUser.Id
  10138. timeStr := time.Now().Format("2006-01-02")
  10139. timeLayout := "2006-01-02 15:04:05"
  10140. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10141. timenow := timeStringToTime.Unix()
  10142. var additionalCharges []*models.HisAdditionalCharge
  10143. for _, item := range medicineData {
  10144. var randNum int
  10145. randNum = rand.Intn(10000) + 1000
  10146. timestamp := time.Now().Unix()
  10147. tempTime := time.Unix(timestamp, 0)
  10148. timeFormat := tempTime.Format("20060102150405")
  10149. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  10150. items := item.(map[string]interface{})
  10151. money := items["price"].(string)
  10152. item_id_str := items["item_id"].(string)
  10153. name := items["name"].(string)
  10154. id_str := items["id"].(string)
  10155. moneys, _ := strconv.ParseInt(money, 10, 64)
  10156. monStr := strconv.FormatInt(moneys, 10)
  10157. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  10158. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  10159. id, _ := strconv.ParseInt(id_str, 10, 64)
  10160. additionalCharge := &models.HisAdditionalCharge{
  10161. ID: id,
  10162. HisPatientId: his_patient_id,
  10163. UserOrgId: orgId,
  10164. PatientId: patient_id,
  10165. RecordDate: timenow,
  10166. Price: monneyStr,
  10167. Status: 1,
  10168. ItemName: name,
  10169. ItemId: item_id,
  10170. AdminUserId: admin_user_id,
  10171. CreatedTime: time.Now().Unix(),
  10172. OrderStatus: 0,
  10173. PrescriptionNumber: "",
  10174. BatchNumber: "",
  10175. FeedetlSn: p_number,
  10176. }
  10177. service.CreateAdditionalCharge(additionalCharge)
  10178. additionalCharges = append(additionalCharges, additionalCharge)
  10179. }
  10180. this.ServeSuccessJSON(map[string]interface{}{
  10181. "msg": "添加成功",
  10182. "additional_charges": additionalCharges,
  10183. })
  10184. }
  10185. func (this *HisApiController) DeleteAddition() {
  10186. id, _ := this.GetInt64("id")
  10187. //TODO 需要判断是否已经结算
  10188. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  10189. if err == nil {
  10190. this.ServeSuccessJSON(map[string]interface{}{
  10191. "msg": "删除成功",
  10192. })
  10193. return
  10194. } else {
  10195. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10196. return
  10197. }
  10198. }
  10199. func (this *HisApiController) GetAdminUsers() {
  10200. adminUser := this.GetAdminUserInfo()
  10201. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  10202. this.ServeSuccessJSON(map[string]interface{}{
  10203. "doctors": doctors,
  10204. })
  10205. }
  10206. func (this *HisApiController) GetLastOrNextHisPrescription() {
  10207. change_type, _ := this.GetInt64("type", 0)
  10208. record_date := this.GetString("record_time")
  10209. patient_id, _ := this.GetInt64("patient_id", 0)
  10210. p_type, _ := this.GetInt64("p_type", 0)
  10211. timeLayout := "2006-01-02"
  10212. loc, _ := time.LoadLocation("Local")
  10213. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  10214. record_time := theAdviceRecordTime.Unix()
  10215. adminUserInfo := this.GetAdminUserInfo()
  10216. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  10217. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10218. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10219. if config.ID > 0 && config.IsOpen == 1 {
  10220. for _, subitems := range prescriptions {
  10221. for _, item := range subitems.VMHisPrescription {
  10222. for _, subItem := range item.HisDoctorAdviceInfo {
  10223. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10224. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10225. if info.RetailPrice > 0 {
  10226. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10227. subItem.Drug.RetailPrice = drug.RetailPrice
  10228. }
  10229. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10230. subItem.Drug.MinPrice = info.RetailPrice
  10231. subItem.Drug.RetailPrice = info.RetailPrice
  10232. }
  10233. }
  10234. }
  10235. }
  10236. }
  10237. }
  10238. if config.ID > 0 && config.IsOpen == 1 {
  10239. for _, subitems := range prescriptions {
  10240. for _, item := range subitems.VMHisPrescription {
  10241. for _, subItem := range item.HisPrescriptionProject {
  10242. if subItem.Type == 3 {
  10243. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10244. if info.Price > 0 {
  10245. subItem.GoodInfo.PackingPrice = info.Price
  10246. }
  10247. }
  10248. }
  10249. }
  10250. }
  10251. }
  10252. }
  10253. if err == nil {
  10254. if len(prescriptions) == 0 {
  10255. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  10256. return
  10257. } else {
  10258. this.ServeSuccessJSON(map[string]interface{}{
  10259. "prescriptions": prescriptions,
  10260. })
  10261. return
  10262. }
  10263. } else {
  10264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10265. return
  10266. }
  10267. }
  10268. func RemoveRepeatedPurviewElementByHP(arr []service.VMOtherHisPrescriptionInfo) (newArr []service.VMOtherHisPrescriptionInfo) {
  10269. newArr = make([]service.VMOtherHisPrescriptionInfo, 0)
  10270. for i := 0; i < len(arr); i++ {
  10271. repeat := false
  10272. for j := i + 1; j < len(arr); j++ {
  10273. if arr[i].PatientId == arr[j].PatientId && arr[i].RecordDate == arr[j].RecordDate {
  10274. repeat = true
  10275. break
  10276. }
  10277. }
  10278. if !repeat {
  10279. newArr = append(newArr, arr[i])
  10280. }
  10281. }
  10282. return
  10283. }
  10284. func (this *HisApiController) GetCallHisPrescription() {
  10285. patient_id, _ := this.GetInt64("patient_id", 0)
  10286. timeLayout := "2006-01-02"
  10287. loc, _ := time.LoadLocation("Local")
  10288. start_time := this.GetString("start_time")
  10289. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10290. end_time := this.GetString("end_time")
  10291. p_type, _ := this.GetInt64("p_type")
  10292. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10293. adminUserInfo := this.GetAdminUserInfo()
  10294. new_prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  10295. prescriptions := RemoveRepeatedPurviewElementByHP(new_prescriptions)
  10296. //if
  10297. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  10298. //
  10299. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  10300. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10301. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10302. if config.ID > 0 && config.IsOpen == 1 {
  10303. for _, subitems := range prescriptions {
  10304. for _, item := range subitems.VMHisPrescription {
  10305. for _, subItem := range item.HisDoctorAdviceInfo {
  10306. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10307. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10308. if info.RetailPrice > 0 {
  10309. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10310. subItem.Drug.RetailPrice = drug.RetailPrice
  10311. }
  10312. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10313. subItem.Drug.MinPrice = info.RetailPrice
  10314. subItem.Drug.RetailPrice = info.RetailPrice
  10315. }
  10316. }
  10317. }
  10318. }
  10319. }
  10320. }
  10321. if config.ID > 0 && config.IsOpen == 1 {
  10322. for _, subitems := range prescriptions {
  10323. for _, item := range subitems.VMHisPrescription {
  10324. for _, subItem := range item.HisPrescriptionProject {
  10325. if subItem.Type == 3 {
  10326. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10327. if info.Price > 0 {
  10328. subItem.GoodInfo.PackingPrice = info.Price
  10329. }
  10330. }
  10331. }
  10332. }
  10333. }
  10334. }
  10335. }
  10336. if err == nil {
  10337. this.ServeSuccessJSON(map[string]interface{}{
  10338. "prescriptions": prescriptions,
  10339. })
  10340. return
  10341. } else {
  10342. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10343. return
  10344. }
  10345. }
  10346. func (this *HisApiController) GetHisDayPrescription() {
  10347. timeLayout := "2006-01-02"
  10348. loc, _ := time.LoadLocation("Local")
  10349. start_time := this.GetString("start_time")
  10350. patient_id, _ := this.GetInt64("patient_id", 0)
  10351. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10352. end_time := this.GetString("end_time")
  10353. p_type, _ := this.GetInt64("p_type")
  10354. order_status, _ := this.GetInt64("type")
  10355. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10356. adminUserInfo := this.GetAdminUserInfo()
  10357. var dayHisPrescription []*models.HisPrescription
  10358. var err error
  10359. if order_status == 1 || order_status == 0 {
  10360. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10361. } else if order_status == 2 {
  10362. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10363. }
  10364. var settle_total float64
  10365. for _, item := range dayHisPrescription {
  10366. if len(item.HisPrescriptionProject) > 0 {
  10367. for _, subItem := range item.HisPrescriptionProject {
  10368. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10369. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10370. settle_total = settle_total + total
  10371. }
  10372. }
  10373. if len(item.HisDoctorAdviceInfo) > 0 {
  10374. for _, subItem := range item.HisDoctorAdviceInfo {
  10375. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10376. settle_total = settle_total + total
  10377. }
  10378. }
  10379. }
  10380. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10381. if err == nil {
  10382. this.ServeSuccessJSON(map[string]interface{}{
  10383. "day_prescription": dayHisPrescription,
  10384. "settle_total": settle_total,
  10385. })
  10386. return
  10387. } else {
  10388. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10389. return
  10390. }
  10391. }
  10392. func (c *HisApiController) GetHisChargePatientList() {
  10393. record_date := c.GetString("record_date")
  10394. order_status, _ := c.GetInt64("type")
  10395. sch_type, _ := c.GetInt64("sch_type")
  10396. timeLayout := "2006-01-02"
  10397. loc, _ := time.LoadLocation("Local")
  10398. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10399. if err != nil {
  10400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10401. return
  10402. }
  10403. recordDateTime := theTime.Unix()
  10404. adminInfo := c.GetAdminUserInfo()
  10405. var tempPatients []*service.NewTempPatients
  10406. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10407. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10408. if order_status != 2 {
  10409. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10410. } else {
  10411. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10412. }
  10413. } else {
  10414. if order_status != 2 {
  10415. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10416. } else {
  10417. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10418. }
  10419. }
  10420. var patients []*service.NewTempPatients
  10421. var patients_two []*service.NewTempPatients
  10422. for _, item := range tempPatients {
  10423. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10424. //过滤掉没挂号的和没开处方的
  10425. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10426. patients = append(patients, item)
  10427. }
  10428. //过滤掉没挂号的
  10429. if len(item.HisPatient) > 0 {
  10430. patients_two = append(patients_two, item)
  10431. }
  10432. } else {
  10433. if len(item.HisPrescription) > 0 {
  10434. patients = append(patients, item)
  10435. }
  10436. }
  10437. }
  10438. c.ServeSuccessJSON(map[string]interface{}{
  10439. "list": patients,
  10440. "list_two": patients_two,
  10441. })
  10442. }
  10443. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10444. record_date := c.GetString("record_date")
  10445. timeLayout := "2006-01-02"
  10446. loc, _ := time.LoadLocation("Local")
  10447. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10448. if err != nil {
  10449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10450. return
  10451. }
  10452. recordDateTime := theTime.Unix()
  10453. adminUser := c.GetAdminUserInfo()
  10454. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10455. var patients []*service.Patients
  10456. for _, item := range tempPatients {
  10457. if item.HisPatient.ID == 0 {
  10458. patients = append(patients, item)
  10459. }
  10460. }
  10461. c.ServeSuccessJSON(map[string]interface{}{
  10462. "list": patients,
  10463. //"list_two": patients_two,
  10464. })
  10465. }
  10466. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10467. newArr = make([]*service.Patients, 0)
  10468. for i := 0; i < len(patient); i++ {
  10469. repeat := false
  10470. for j := i + 1; j < len(patient); j++ {
  10471. if patient[i].ID == patient[j].ID {
  10472. repeat = true
  10473. break
  10474. }
  10475. }
  10476. if !repeat {
  10477. newArr = append(newArr, patient[i])
  10478. }
  10479. }
  10480. return
  10481. }
  10482. func (c *HisApiController) GetHisChargePatientInfo() {
  10483. patient_id, _ := c.GetInt64("patient_id")
  10484. his_patient_id, _ := c.GetInt64("his_patient_id")
  10485. record_date := c.GetString("record_date")
  10486. //start_time := c.GetString("start_time")
  10487. //end_time := c.GetString("end_time")
  10488. order_status, _ := c.GetInt64("type", 0)
  10489. p_type, _ := c.GetInt64("p_type", 0)
  10490. order_id, _ := c.GetInt64("order_id", 0)
  10491. timeLayout := "2006-01-02"
  10492. loc, _ := time.LoadLocation("Local")
  10493. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10494. if err != nil {
  10495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10496. return
  10497. }
  10498. recordDateTime := theTime.Unix()
  10499. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10500. //if err != nil {
  10501. //
  10502. //}
  10503. //startRecordDateTime := startTime.Unix()
  10504. //
  10505. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10506. //if err != nil {
  10507. //
  10508. //}
  10509. //endRecordDateTime := endTime.Unix()
  10510. admin := c.GetAdminUserInfo()
  10511. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10512. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10513. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10514. var prescriptions []*models.HisPrescription
  10515. //var unChargeMonthPrescriptions []*models.HisPrescription
  10516. order, _ := service.GetHisOrderByID(order_id)
  10517. if order_status == 1 || order_status == 0 {
  10518. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10519. } else if order_status == 2 {
  10520. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10521. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10522. }
  10523. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10524. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10525. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10526. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10527. //获取所有科室信息
  10528. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10529. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10530. c.ServeSuccessJSON(map[string]interface{}{
  10531. "his_info": his_patient_info,
  10532. "last_his_patient_info": last_his_patient_info,
  10533. "xt_info": xt_patient_info,
  10534. "prescription": prescriptions,
  10535. "case_history": case_history,
  10536. "info": patientPrescriptionInfo,
  10537. "last_info": lastPatientPrescriptionInfo,
  10538. "order": order,
  10539. "doctors": doctors,
  10540. "department": department,
  10541. "sch": sch,
  10542. })
  10543. return
  10544. }
  10545. func (c *HisApiController) GetAllOrderDetail() {
  10546. order_id, _ := c.GetInt64("id", 0)
  10547. order, _ := service.GetHisOrderByID(order_id)
  10548. if order.ID == 0 {
  10549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10550. return
  10551. }
  10552. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10553. org_id := c.GetAdminUserInfo().CurrentOrgId
  10554. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10555. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10556. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10557. c.ServeSuccessJSON(map[string]interface{}{
  10558. "order": order,
  10559. "order_info": order_info,
  10560. "patient": patient,
  10561. "admin_info": adminInfo,
  10562. "hospital_record": record,
  10563. })
  10564. return
  10565. }
  10566. func (c *HisApiController) GetAllOrderDetailCollect() {
  10567. order_id, _ := c.GetInt64("id", 0)
  10568. order, _ := service.GetHisOrderByID(order_id)
  10569. if order.ID == 0 {
  10570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10571. return
  10572. }
  10573. org_id := c.GetAdminUserInfo().CurrentOrgId
  10574. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10575. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10576. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10577. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10578. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10579. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10580. var bedCostTotal float64 = 0 //床位总费
  10581. //var bedCostSelfTotal float64 = 0 //床位自费
  10582. var operationCostTotal float64 = 0 //手术费
  10583. //var operationCostSelfTotal float64 = 0 //手术费
  10584. var otherCostTotal float64 = 0 //其他费用
  10585. //var otherCostSelfTotal float64 = 0 //其他费用
  10586. var materialCostTotal float64 = 0 //材料费
  10587. //var materialCostSelfTotal float64 = 0 //材料费
  10588. var westernMedicineCostTotal float64 = 0 //西药费
  10589. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10590. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10591. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10592. var checkCostTotal float64 = 0 //检查费
  10593. //var checkCostSelfTotal float64 = 0 //检查费
  10594. var laboratoryCostTotal float64 = 0 //化验费
  10595. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10596. var treatCostTotal float64 = 0 //治疗费用
  10597. //var treatCostSelfTotal float64 = 0 //治疗费用
  10598. var zhenChaCostTotal float64 = 0 //其他费用
  10599. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10600. decimal.DivisionPrecision = 2
  10601. var BalanceAccountsType int64
  10602. if his.ID > 0 {
  10603. BalanceAccountsType = his.BalanceAccountsType
  10604. } else {
  10605. BalanceAccountsType = record.BalanceAccountsType
  10606. }
  10607. if BalanceAccountsType != 2 {
  10608. for _, item := range order_info {
  10609. if org_id == 10215 {
  10610. if item.MedChrgitmType == "01" { //床位费
  10611. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10612. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10613. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10614. }
  10615. if item.MedChrgitmType == "02" { //诊察费
  10616. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10617. //zhenChaCostSelfTotal = zhenChaCostTotal
  10618. }
  10619. if item.MedChrgitmType == "03" { //检查费
  10620. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10621. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10622. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10623. }
  10624. //if item.MedChrgitmType == "02" { //检查费
  10625. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10626. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10627. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10628. //}
  10629. if item.MedChrgitmType == "04" { //化验费
  10630. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10631. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10632. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10633. }
  10634. if item.MedChrgitmType == "05" { //治疗费
  10635. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10636. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10637. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10638. }
  10639. if item.MedChrgitmType == "06" { //手术费
  10640. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10641. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10642. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10643. }
  10644. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10645. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10646. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10647. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10648. }
  10649. if item.MedChrgitmType == "09" { //西药费
  10650. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10651. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10652. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10653. }
  10654. if item.MedChrgitmType == "11" { //中成费
  10655. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10656. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10657. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10658. }
  10659. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10660. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10661. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10662. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10663. }
  10664. } else if org_id == 10188 || org_id == 10217 {
  10665. if item.MedChrgitmType == "01" { //床位费
  10666. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10667. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10668. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10669. }
  10670. if item.MedChrgitmType == "02" { //诊察费
  10671. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10672. //zhenChaCostSelfTotal = zhenChaCostTotal
  10673. }
  10674. if item.MedChrgitmType == "03" { //检查费
  10675. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10676. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10677. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10678. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10679. }
  10680. //if item.MedChrgitmType == "02" { //检查费
  10681. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10682. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10683. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10684. //}
  10685. if item.MedChrgitmType == "04" { //化验费
  10686. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10687. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10688. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10689. }
  10690. if item.MedChrgitmType == "05" { //治疗费
  10691. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10692. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10693. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10694. }
  10695. if item.MedChrgitmType == "06" { //手术费
  10696. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10697. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10698. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10699. }
  10700. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10701. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10702. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10703. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10704. }
  10705. if item.MedChrgitmType == "09" { //西药费
  10706. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10707. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10708. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10709. }
  10710. if item.MedChrgitmType == "11" { //中成费
  10711. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10712. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10713. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10714. }
  10715. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10716. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10717. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10718. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10719. }
  10720. } else {
  10721. if item.MedChrgitmType == "01" { //床位费
  10722. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10723. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10724. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10725. }
  10726. //if item.MedChrgitmType == "02" { //诊察费
  10727. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10728. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10729. //}
  10730. if item.MedChrgitmType == "03" { //检查费
  10731. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10732. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10733. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10734. }
  10735. //if item.MedChrgitmType == "02" { //检查费
  10736. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10737. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10738. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10739. //}
  10740. if item.MedChrgitmType == "04" { //化验费
  10741. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10742. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10743. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10744. }
  10745. if item.MedChrgitmType == "05" { //治疗费
  10746. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10747. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10748. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10749. }
  10750. if item.MedChrgitmType == "06" { //手术费
  10751. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10752. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10753. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10754. }
  10755. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10756. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10757. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10758. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10759. }
  10760. if item.MedChrgitmType == "09" { //西药费
  10761. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10762. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10763. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10764. }
  10765. if item.MedChrgitmType == "11" { //中成费
  10766. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10767. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10768. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10769. }
  10770. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10771. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10772. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10773. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10774. }
  10775. }
  10776. }
  10777. c.ServeSuccessJSON(map[string]interface{}{
  10778. "order": order,
  10779. "order_info": order_info,
  10780. "patient": patient,
  10781. "admin_info": adminInfo,
  10782. "his_hospital": record,
  10783. "bedCostTotal": bedCostTotal,
  10784. "operationCostTotal": operationCostTotal,
  10785. "otherCostTotal": otherCostTotal,
  10786. "materialCostTotal": materialCostTotal,
  10787. "westernMedicineCostTotal": westernMedicineCostTotal,
  10788. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10789. "checkCostTotal": checkCostTotal,
  10790. "zhenChaCostTotal": zhenChaCostTotal,
  10791. "laboratoryCostTotal": laboratoryCostTotal,
  10792. "treatCostTotal": treatCostTotal,
  10793. })
  10794. } else {
  10795. for _, item := range order_info {
  10796. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10797. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10798. item.MedChrgitmType = "09"
  10799. }
  10800. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10801. if item.HisPrescriptionProject.Type == 2 {
  10802. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10803. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10804. case 0:
  10805. item.MedChrgitmType = "0"
  10806. break
  10807. case 1:
  10808. item.MedChrgitmType = "14"
  10809. break
  10810. case 2:
  10811. item.MedChrgitmType = "05"
  10812. break
  10813. case 3:
  10814. item.MedChrgitmType = "03"
  10815. break
  10816. case 4:
  10817. item.MedChrgitmType = "03"
  10818. break
  10819. case 5:
  10820. item.MedChrgitmType = "08"
  10821. break
  10822. case 6:
  10823. item.MedChrgitmType = "14"
  10824. break
  10825. case 7:
  10826. item.MedChrgitmType = "14"
  10827. break
  10828. case 8:
  10829. item.MedChrgitmType = "03"
  10830. break
  10831. case 9:
  10832. item.MedChrgitmType = "14"
  10833. break
  10834. case 10:
  10835. item.MedChrgitmType = "14"
  10836. break
  10837. case 11:
  10838. item.MedChrgitmType = "06"
  10839. break
  10840. case 12:
  10841. item.MedChrgitmType = "12"
  10842. break
  10843. case 13:
  10844. item.MedChrgitmType = "01"
  10845. break
  10846. case 14:
  10847. item.MedChrgitmType = "04"
  10848. break
  10849. case 15:
  10850. item.MedChrgitmType = "14"
  10851. break
  10852. }
  10853. } else {
  10854. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10855. case 1:
  10856. item.MedChrgitmType = "14"
  10857. break
  10858. case 2:
  10859. item.MedChrgitmType = "05"
  10860. break
  10861. case 3:
  10862. item.MedChrgitmType = "04"
  10863. break
  10864. case 4:
  10865. item.MedChrgitmType = "14"
  10866. break
  10867. case 5:
  10868. item.MedChrgitmType = "08"
  10869. break
  10870. case 6:
  10871. item.MedChrgitmType = "14"
  10872. break
  10873. case 7:
  10874. item.MedChrgitmType = "14"
  10875. break
  10876. case 8:
  10877. item.MedChrgitmType = "03"
  10878. break
  10879. case 9:
  10880. item.MedChrgitmType = "14"
  10881. break
  10882. }
  10883. }
  10884. } else if item.HisPrescriptionProject.Type == 3 {
  10885. item.MedChrgitmType = "08"
  10886. }
  10887. }
  10888. }
  10889. for _, item := range order_info {
  10890. if org_id == 10215 {
  10891. if item.MedChrgitmType == "01" { //床位费
  10892. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10893. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10894. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10895. }
  10896. if item.MedChrgitmType == "02" { //诊察费
  10897. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10898. //zhenChaCostSelfTotal = zhenChaCostTotal
  10899. }
  10900. if item.MedChrgitmType == "03" { //检查费
  10901. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10902. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10903. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10904. }
  10905. //if item.MedChrgitmType == "02" { //检查费
  10906. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10907. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10908. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10909. //}
  10910. if item.MedChrgitmType == "04" { //化验费
  10911. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10912. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10913. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10914. }
  10915. if item.MedChrgitmType == "05" { //治疗费
  10916. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10917. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10918. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10919. }
  10920. if item.MedChrgitmType == "06" { //手术费
  10921. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10922. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10923. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10924. }
  10925. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10926. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10927. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10928. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10929. }
  10930. if item.MedChrgitmType == "09" { //西药费
  10931. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10932. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10933. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10934. }
  10935. if item.MedChrgitmType == "11" { //中成费
  10936. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10937. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10938. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10939. }
  10940. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10941. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10942. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10943. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10944. }
  10945. } else {
  10946. if item.MedChrgitmType == "01" { //床位费
  10947. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10948. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10949. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10950. }
  10951. //if item.MedChrgitmType == "02" { //诊察费
  10952. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10953. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10954. //}
  10955. if item.MedChrgitmType == "03" { //检查费
  10956. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10957. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10958. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10959. }
  10960. //if item.MedChrgitmType == "02" { //检查费
  10961. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10962. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10963. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10964. //}
  10965. if item.MedChrgitmType == "04" { //化验费
  10966. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10967. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10968. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10969. }
  10970. if item.MedChrgitmType == "05" { //治疗费
  10971. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10972. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10973. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10974. }
  10975. if item.MedChrgitmType == "06" { //手术费
  10976. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10977. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10978. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10979. }
  10980. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10981. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10982. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10983. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10984. }
  10985. if item.MedChrgitmType == "09" { //西药费
  10986. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10987. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10988. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10989. }
  10990. if item.MedChrgitmType == "11" { //中成费
  10991. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10992. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10993. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10994. }
  10995. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10996. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10997. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10998. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10999. }
  11000. }
  11001. }
  11002. c.ServeSuccessJSON(map[string]interface{}{
  11003. "order": order,
  11004. "order_info": order_info,
  11005. "patient": patient,
  11006. "admin_info": adminInfo,
  11007. "his_hospital": record,
  11008. "bedCostTotal": bedCostTotal,
  11009. "operationCostTotal": operationCostTotal,
  11010. "otherCostTotal": otherCostTotal,
  11011. "materialCostTotal": materialCostTotal,
  11012. "westernMedicineCostTotal": westernMedicineCostTotal,
  11013. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11014. "checkCostTotal": checkCostTotal,
  11015. "zhenChaCostTotal": zhenChaCostTotal,
  11016. "laboratoryCostTotal": laboratoryCostTotal,
  11017. "treatCostTotal": treatCostTotal,
  11018. })
  11019. }
  11020. }
  11021. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  11022. page, _ := c.GetInt64("page")
  11023. limit, _ := c.GetInt64("limit")
  11024. keywords := c.GetString("keywords")
  11025. start_time := c.GetString("start_time")
  11026. end_time := c.GetString("end_time")
  11027. //clr_type := c.GetString("clr_type")
  11028. insutype := c.GetString("insutype")
  11029. timeLayout := "2006-01-02"
  11030. loc, _ := time.LoadLocation("Local")
  11031. var theStartTIme int64
  11032. if len(start_time) > 0 {
  11033. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11034. theStartTIme = theTime.Unix()
  11035. }
  11036. var theEndtTIme int64
  11037. if len(end_time) > 0 {
  11038. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11039. theEndtTIme = theTime.Unix()
  11040. }
  11041. if page <= 0 {
  11042. page = 1
  11043. }
  11044. if limit <= 0 {
  11045. limit = 10
  11046. }
  11047. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  11048. c.ServeSuccessJSON(map[string]interface{}{
  11049. "total": total,
  11050. "list": list,
  11051. })
  11052. return
  11053. }
  11054. func (c *HisApiController) GetPutOnRecordList() {
  11055. page, _ := c.GetInt64("page")
  11056. limit, _ := c.GetInt64("limit")
  11057. keywords := c.GetString("keywords")
  11058. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  11059. if page <= 0 {
  11060. page = 1
  11061. }
  11062. if limit <= 0 {
  11063. limit = 10
  11064. }
  11065. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  11066. c.ServeSuccessJSON(map[string]interface{}{
  11067. "total": total,
  11068. "list": list,
  11069. })
  11070. return
  11071. }
  11072. func (c *HisApiController) GetCompareData() {
  11073. start_time := c.GetString("start_time")
  11074. end_time := c.GetString("end_time")
  11075. insutype := c.GetString("insutype")
  11076. clr_type := c.GetString("clr_type")
  11077. timeLayout := "2006-01-02"
  11078. loc, _ := time.LoadLocation("Local")
  11079. var theStartTIme int64
  11080. if len(start_time) > 0 {
  11081. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11082. if err != nil {
  11083. theStartTIme = 0
  11084. }
  11085. theStartTIme = theTime.Unix()
  11086. }
  11087. var theEndtTIme int64
  11088. if len(end_time) > 0 {
  11089. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11090. if err != nil {
  11091. theEndtTIme = 0
  11092. }
  11093. theEndtTIme = theTime.Unix()
  11094. }
  11095. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  11096. fmt.Println(err)
  11097. if err == nil {
  11098. c.ServeSuccessJSON(map[string]interface{}{
  11099. "list": formData,
  11100. })
  11101. } else {
  11102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  11103. return
  11104. }
  11105. }
  11106. func (c *HisApiController) GetFaPiaoData() {
  11107. order_id, _ := c.GetInt64("order_id")
  11108. patient_id, _ := c.GetInt64("patient_id")
  11109. //number := c.GetString("number")
  11110. adminUser := c.GetAdminUserInfo()
  11111. order, _ := service.GetHisOrderByID(order_id)
  11112. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11113. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11114. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11115. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11116. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  11117. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  11118. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11119. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11120. var bedCostTotal float64 = 0 //床位总费
  11121. var bedCostSelfTotal float64 = 0 //床位自费
  11122. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11123. var operationCostTotal float64 = 0 //手术费
  11124. var operationCostSelfTotal float64 = 0 //手术费
  11125. var operationCostPartSelfTotal float64 = 0 //手术费
  11126. var otherCostTotal float64 = 0 //其他费用
  11127. var otherCostSelfTotal float64 = 0 //其他费用
  11128. var otherCostPartSelfTotal float64 = 0 //其他费用
  11129. var materialCostTotal float64 = 0 //材料费
  11130. var materialCostSelfTotal float64 = 0 //材料费
  11131. var materialCostPartSelfTotal float64 = 0 //材料费
  11132. var westernMedicineCostTotal float64 = 0 //西药费
  11133. var westernMedicineCostSelfTotal float64 = 0 //西药费
  11134. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11135. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11136. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11137. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11138. var checkCostTotal float64 = 0 //检查费
  11139. var checkCostSelfTotal float64 = 0 //检查费
  11140. var checkCostPartSelfTotal float64 = 0 //检查费
  11141. var hiliCostTotal float64 = 0 //护理费
  11142. var hiliCostSelfTotal float64 = 0 //护理费
  11143. var hiliCostPartSelfTotal float64 = 0 //护理费
  11144. var laboratoryCostTotal float64 = 0 //化验费
  11145. var laboratoryCostSelfTotal float64 = 0 //化验费
  11146. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11147. var treatCostTotal float64 = 0 //治疗费用
  11148. var treatCostSelfTotal float64 = 0 //治疗费用
  11149. var treatCostPartSelfTotal float64 = 0 //治疗费用
  11150. var zhenChaCostTotal float64 = 0 //其他费用
  11151. var zhenChaCostSelfTotal float64 = 0 //其他费用
  11152. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11153. decimal.DivisionPrecision = 2
  11154. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11155. var balanceAccountsType int64
  11156. if his.ID > 0 {
  11157. balanceAccountsType = his.BalanceAccountsType
  11158. } else {
  11159. balanceAccountsType = his_hospital_record.BalanceAccountsType
  11160. }
  11161. if balanceAccountsType == 2 {
  11162. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11163. for _, item := range orderInfos_two {
  11164. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11165. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11166. item.MedChrgitmType = "09"
  11167. }
  11168. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11169. if item.HisPrescriptionProject.Type == 2 {
  11170. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11171. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11172. case 0:
  11173. item.MedChrgitmType = "0"
  11174. break
  11175. case 1:
  11176. item.MedChrgitmType = "14"
  11177. break
  11178. case 2:
  11179. item.MedChrgitmType = "05"
  11180. break
  11181. case 3:
  11182. item.MedChrgitmType = "03"
  11183. break
  11184. case 4:
  11185. item.MedChrgitmType = "03"
  11186. break
  11187. case 5:
  11188. item.MedChrgitmType = "08"
  11189. break
  11190. case 6:
  11191. item.MedChrgitmType = "14"
  11192. break
  11193. case 7:
  11194. item.MedChrgitmType = "14"
  11195. break
  11196. case 8:
  11197. item.MedChrgitmType = "03"
  11198. break
  11199. case 9:
  11200. item.MedChrgitmType = "14"
  11201. break
  11202. case 10:
  11203. item.MedChrgitmType = "14"
  11204. break
  11205. case 11:
  11206. item.MedChrgitmType = "06"
  11207. break
  11208. case 12:
  11209. item.MedChrgitmType = "12"
  11210. break
  11211. case 13:
  11212. item.MedChrgitmType = "01"
  11213. break
  11214. case 14:
  11215. item.MedChrgitmType = "04"
  11216. break
  11217. case 15:
  11218. item.MedChrgitmType = "02"
  11219. break
  11220. }
  11221. } else {
  11222. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11223. case 1:
  11224. item.MedChrgitmType = "14"
  11225. break
  11226. case 2:
  11227. item.MedChrgitmType = "05"
  11228. break
  11229. case 3:
  11230. item.MedChrgitmType = "04"
  11231. break
  11232. case 4:
  11233. item.MedChrgitmType = "03"
  11234. break
  11235. case 5:
  11236. item.MedChrgitmType = "08"
  11237. break
  11238. case 6:
  11239. item.MedChrgitmType = "14"
  11240. break
  11241. case 7:
  11242. item.MedChrgitmType = "14"
  11243. break
  11244. case 8:
  11245. item.MedChrgitmType = "03"
  11246. break
  11247. case 9:
  11248. item.MedChrgitmType = "14"
  11249. break
  11250. }
  11251. }
  11252. } else if item.HisPrescriptionProject.Type == 3 {
  11253. item.MedChrgitmType = "08"
  11254. }
  11255. }
  11256. }
  11257. for _, item := range orderInfos_two {
  11258. fmt.Println(item.MedChrgitmType)
  11259. if item.MedChrgitmType == "07" { //床位费
  11260. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11261. hiliCostSelfTotal = hiliCostTotal
  11262. }
  11263. if item.MedChrgitmType == "01" { //床位费
  11264. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11265. bedCostSelfTotal = bedCostTotal
  11266. }
  11267. if item.MedChrgitmType == "02" { //诊察费
  11268. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11269. zhenChaCostSelfTotal = zhenChaCostTotal
  11270. }
  11271. if item.MedChrgitmType == "03" { //检查费
  11272. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11273. checkCostSelfTotal = checkCostTotal
  11274. }
  11275. if item.MedChrgitmType == "04" { //化验费
  11276. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11277. laboratoryCostSelfTotal = laboratoryCostTotal
  11278. }
  11279. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11280. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11281. treatCostSelfTotal = treatCostTotal
  11282. }
  11283. if item.MedChrgitmType == "06" { //手术费
  11284. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11285. operationCostSelfTotal = treatCostTotal
  11286. }
  11287. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  11288. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11289. materialCostSelfTotal = materialCostTotal
  11290. }
  11291. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11292. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11293. westernMedicineCostSelfTotal = westernMedicineCostTotal
  11294. }
  11295. if item.MedChrgitmType == "11" { //中成费
  11296. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11297. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11298. }
  11299. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11300. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11301. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11302. otherCostSelfTotal = otherCostTotal
  11303. }
  11304. } else {
  11305. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11306. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11307. otherCostSelfTotal = otherCostTotal
  11308. }
  11309. }
  11310. }
  11311. } else {
  11312. for _, item := range orderInfos {
  11313. if item.MedChrgitmType == "01" { //床位费
  11314. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11315. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11316. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11317. }
  11318. if item.MedChrgitmType == "02" { //诊察费
  11319. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11320. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11321. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11322. }
  11323. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11324. if item.MedChrgitmType == "03" { //检查费
  11325. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11326. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11327. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11328. }
  11329. } else {
  11330. if item.MedChrgitmType == "03" { //检查费
  11331. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11332. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11333. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11334. }
  11335. }
  11336. if item.MedChrgitmType == "04" { //化验费
  11337. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11338. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11339. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11340. }
  11341. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11342. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11343. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11344. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11345. }
  11346. if item.MedChrgitmType == "06" { //手术费
  11347. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11348. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11349. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11350. }
  11351. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11352. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11353. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11354. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11355. }
  11356. if item.MedChrgitmType == "07" { //护理
  11357. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11358. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11359. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11360. }
  11361. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11362. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11363. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11364. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11365. }
  11366. if item.MedChrgitmType == "11" { //中成费
  11367. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11368. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11369. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11370. }
  11371. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11372. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11373. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11374. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11375. }
  11376. }
  11377. }
  11378. timeLayout := "2006-01-02"
  11379. loc, _ := time.LoadLocation("Local")
  11380. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11381. if err != nil {
  11382. }
  11383. startRecordDateTime := startTime.Unix()
  11384. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11385. if err != nil {
  11386. }
  11387. endRecordDateTime := endTime.Unix()
  11388. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11389. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11390. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11391. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11392. c.ServeSuccessJSON(map[string]interface{}{
  11393. "charge_admin_name": charge_admin.UserName,
  11394. "order_number": order.Number, //业务流水号
  11395. "id_card_no": his.IdCardNo, //社会保障号
  11396. "patient": patient,
  11397. "department_name": department.Name, //科室
  11398. "number": his.Number, //门诊号
  11399. "date": order.SettleAccountsDate, //结算日期
  11400. "name": order.PsnName, //姓名
  11401. "gender": patient.Gender, //性别
  11402. "psn_cash_money": order.PsnCashPay, //个人支付
  11403. "pay_way": "门诊", //结算方式
  11404. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11405. "admin_user_name": admin.UserName, //收款员
  11406. "order": order,
  11407. "order_info": orderInfos_two,
  11408. "his": his,
  11409. "bedCostTotal": bedCostTotal,
  11410. "bedCostSelfTotal": bedCostSelfTotal,
  11411. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11412. "operationCostTotal": operationCostTotal,
  11413. "operationCostSelfTotal": operationCostSelfTotal,
  11414. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11415. "otherCostTotal": otherCostTotal,
  11416. "otherCostSelfTotal": otherCostSelfTotal,
  11417. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11418. "materialCostTotal": materialCostTotal,
  11419. "materialCostSelfTotal": materialCostSelfTotal,
  11420. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11421. "westernMedicineCostTotal": westernMedicineCostTotal,
  11422. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11423. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11424. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11425. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11426. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11427. "checkCostTotal": checkCostTotal,
  11428. "checkCostSelfTotal": checkCostSelfTotal,
  11429. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11430. "laboratoryCostTotal": laboratoryCostTotal,
  11431. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11432. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11433. "treatCostTotal": treatCostTotal,
  11434. "treatCostSelfTotal": treatCostSelfTotal,
  11435. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11436. "zhenChaCostTotal": zhenChaCostTotal,
  11437. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11438. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11439. "his_hospital_record": his_hospital_record,
  11440. "pre_pay_money": pre_pay_money,
  11441. "refund_sum": sum,
  11442. "doctor_info": doctor_info,
  11443. "hiliCostTotal": hiliCostTotal,
  11444. "hiliCostSelfTotal": hiliCostSelfTotal,
  11445. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11446. })
  11447. }
  11448. //func (c *HisApiController) GetFaPiaoDatas() {
  11449. // order_ids := c.GetString("order_ids")
  11450. // patient_id, _ := c.GetInt64("patient_id")
  11451. // adminUser := c.GetAdminUserInfo()
  11452. //
  11453. // orders := strings.Split(order_ids, ",")
  11454. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11455. //
  11456. // for _, item := range orders {
  11457. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11458. // order, _ := service.GetHisOrderByID(order_id)
  11459. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11460. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11461. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11462. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11463. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11464. //
  11465. // }
  11466. //
  11467. // var bedCostTotal float64 = 0 //床位总费
  11468. // var bedCostSelfTotal float64 = 0 //床位自费
  11469. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11470. //
  11471. // var operationCostTotal float64 = 0 //手术费
  11472. // var operationCostSelfTotal float64 = 0 //手术费
  11473. // var operationCostPartSelfTotal float64 = 0 //手术费
  11474. //
  11475. // var otherCostTotal float64 = 0 //其他费用
  11476. // var otherCostSelfTotal float64 = 0 //其他费用
  11477. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11478. //
  11479. // var materialCostTotal float64 = 0 //材料费
  11480. // var materialCostSelfTotal float64 = 0 //材料费
  11481. // var materialCostPartSelfTotal float64 = 0 //材料费
  11482. //
  11483. // var westernMedicineCostTotal float64 = 0 //西药费
  11484. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11485. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11486. //
  11487. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11488. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11489. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11490. //
  11491. // var checkCostTotal float64 = 0 //检查费
  11492. // var checkCostSelfTotal float64 = 0 //检查费
  11493. // var checkCostPartSelfTotal float64 = 0 //检查费
  11494. //
  11495. // var laboratoryCostTotal float64 = 0 //化验费
  11496. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11497. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11498. //
  11499. // var treatCostTotal float64 = 0 //治疗费用
  11500. // var treatCostSelfTotal float64 = 0 //治疗费用
  11501. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11502. //
  11503. // var zhenChaCostTotal float64 = 0 //其他费用
  11504. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11505. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11506. //
  11507. // decimal.DivisionPrecision = 2
  11508. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11509. //
  11510. // var balanceAccountsType int64
  11511. // if his.ID > 0 {
  11512. // balanceAccountsType = his.BalanceAccountsType
  11513. // } else {
  11514. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11515. // }
  11516. // if balanceAccountsType == 2 {
  11517. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11518. // for _, item := range orderInfos_two {
  11519. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11520. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11521. // item.MedChrgitmType = "09"
  11522. // }
  11523. //
  11524. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11525. // if item.HisPrescriptionProject.Type == 2 {
  11526. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11527. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11528. // case 0:
  11529. // item.MedChrgitmType = "0"
  11530. // break
  11531. // case 1:
  11532. // item.MedChrgitmType = "14"
  11533. // break
  11534. // case 2:
  11535. // item.MedChrgitmType = "05"
  11536. //
  11537. // break
  11538. // case 3:
  11539. // item.MedChrgitmType = "03"
  11540. //
  11541. // break
  11542. // case 4:
  11543. // item.MedChrgitmType = "03"
  11544. //
  11545. // break
  11546. // case 5:
  11547. // item.MedChrgitmType = "08"
  11548. //
  11549. // break
  11550. // case 6:
  11551. // item.MedChrgitmType = "14"
  11552. //
  11553. // break
  11554. // case 7:
  11555. // item.MedChrgitmType = "14"
  11556. //
  11557. // break
  11558. // case 8:
  11559. // item.MedChrgitmType = "03"
  11560. // break
  11561. // case 9:
  11562. // item.MedChrgitmType = "14"
  11563. // break
  11564. // case 10:
  11565. // item.MedChrgitmType = "14"
  11566. // break
  11567. // case 11:
  11568. // item.MedChrgitmType = "06"
  11569. // break
  11570. // case 12:
  11571. // item.MedChrgitmType = "12"
  11572. // break
  11573. // case 13:
  11574. // item.MedChrgitmType = "01"
  11575. // break
  11576. // case 14:
  11577. // item.MedChrgitmType = "04"
  11578. // break
  11579. // case 15:
  11580. // item.MedChrgitmType = "02"
  11581. // break
  11582. //
  11583. // }
  11584. //
  11585. // } else {
  11586. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11587. //
  11588. // case 1:
  11589. // item.MedChrgitmType = "14"
  11590. // break
  11591. // case 2:
  11592. // item.MedChrgitmType = "05"
  11593. //
  11594. // break
  11595. // case 3:
  11596. // item.MedChrgitmType = "03"
  11597. //
  11598. // break
  11599. // case 4:
  11600. // item.MedChrgitmType = "03"
  11601. //
  11602. // break
  11603. // case 5:
  11604. // item.MedChrgitmType = "08"
  11605. //
  11606. // break
  11607. // case 6:
  11608. // item.MedChrgitmType = "14"
  11609. //
  11610. // break
  11611. // case 7:
  11612. // item.MedChrgitmType = "14"
  11613. //
  11614. // break
  11615. // case 8:
  11616. // item.MedChrgitmType = "03"
  11617. // break
  11618. // case 9:
  11619. // item.MedChrgitmType = "14"
  11620. // break
  11621. //
  11622. // }
  11623. //
  11624. // }
  11625. //
  11626. // } else if item.HisPrescriptionProject.Type == 3 {
  11627. // item.MedChrgitmType = "08"
  11628. // }
  11629. // }
  11630. // }
  11631. //
  11632. // for _, item := range orderInfos_two {
  11633. // fmt.Println(item.MedChrgitmType)
  11634. // if item.MedChrgitmType == "01" { //床位费
  11635. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11636. // bedCostSelfTotal = bedCostTotal
  11637. // }
  11638. //
  11639. // if item.MedChrgitmType == "02" { //诊察费
  11640. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11641. // zhenChaCostSelfTotal = zhenChaCostTotal
  11642. // }
  11643. //
  11644. // if item.MedChrgitmType == "03" { //检查费
  11645. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11646. // checkCostSelfTotal = checkCostTotal
  11647. // }
  11648. //
  11649. // if item.MedChrgitmType == "04" { //化验费
  11650. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11651. // laboratoryCostSelfTotal = laboratoryCostTotal
  11652. // }
  11653. //
  11654. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11655. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11656. // treatCostSelfTotal = treatCostTotal
  11657. // }
  11658. //
  11659. // if item.MedChrgitmType == "06" { //手术费
  11660. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11661. // operationCostSelfTotal = treatCostTotal
  11662. // }
  11663. //
  11664. // if item.MedChrgitmType == "08" { //材料费
  11665. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11666. // materialCostSelfTotal = materialCostTotal
  11667. // }
  11668. //
  11669. // if item.MedChrgitmType == "09" { //西药费
  11670. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11671. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11672. // }
  11673. //
  11674. // if item.MedChrgitmType == "11" { //中成费
  11675. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11676. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11677. // }
  11678. //
  11679. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11680. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11681. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11682. // otherCostSelfTotal = otherCostTotal
  11683. // }
  11684. // } else {
  11685. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11686. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11687. // otherCostSelfTotal = otherCostTotal
  11688. // }
  11689. //
  11690. // }
  11691. //
  11692. // }
  11693. //
  11694. // } else {
  11695. // for _, item := range orderInfos {
  11696. // if item.MedChrgitmType == "01" { //床位费
  11697. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11698. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11699. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11700. // }
  11701. //
  11702. // if item.MedChrgitmType == "02" { //诊察费
  11703. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11704. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11705. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11706. // }
  11707. //
  11708. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11709. // if item.MedChrgitmType == "03" { //检查费
  11710. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11711. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11712. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11713. //
  11714. // }
  11715. // } else {
  11716. // if item.MedChrgitmType == "03" { //检查费
  11717. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11718. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11719. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11720. // }
  11721. //
  11722. // }
  11723. //
  11724. // if item.MedChrgitmType == "04" { //化验费
  11725. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11726. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11727. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11728. //
  11729. // }
  11730. //
  11731. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11732. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11733. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11734. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11735. //
  11736. // }
  11737. //
  11738. // if item.MedChrgitmType == "06" { //手术费
  11739. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11740. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11741. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11742. // }
  11743. //
  11744. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11745. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11746. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11747. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11748. // }
  11749. //
  11750. // if item.MedChrgitmType == "09" { //西药费
  11751. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11752. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11753. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11754. // }
  11755. //
  11756. // if item.MedChrgitmType == "11" { //中成费
  11757. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11758. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11759. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11760. // }
  11761. //
  11762. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11763. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11764. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11765. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11766. // }
  11767. //
  11768. // }
  11769. // }
  11770. // timeLayout := "2006-01-02"
  11771. // loc, _ := time.LoadLocation("Local")
  11772. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11773. // if err != nil {
  11774. // }
  11775. // startRecordDateTime := startTime.Unix()
  11776. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11777. // if err != nil {
  11778. // }
  11779. // endRecordDateTime := endTime.Unix()
  11780. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11781. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11782. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11783. //
  11784. // c.ServeSuccessJSON(map[string]interface{}{
  11785. // "order_number": order.Number, //业务流水号
  11786. // "id_card_no": his.IdCardNo, //社会保障号
  11787. // "department_name": department.Name, //科室
  11788. // "number": his.Number, //门诊号
  11789. // "date": order.SettleAccountsDate, //结算日期
  11790. // "name": order.PsnName, //姓名
  11791. // "gender": patient.Gender, //性别
  11792. // "psn_cash_money": order.PsnCashPay, //个人支付
  11793. // "pay_way": "门诊", //结算方式
  11794. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11795. // "admin_user_name": admin.UserName, //收款员
  11796. // "order": order,
  11797. // "order_info": orderInfos_two,
  11798. // "his": his,
  11799. // "bedCostTotal": bedCostTotal,
  11800. // "bedCostSelfTotal": bedCostSelfTotal,
  11801. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11802. // "operationCostTotal": operationCostTotal,
  11803. // "operationCostSelfTotal": operationCostSelfTotal,
  11804. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11805. // "otherCostTotal": otherCostTotal,
  11806. // "otherCostSelfTotal": otherCostSelfTotal,
  11807. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11808. // "materialCostTotal": materialCostTotal,
  11809. // "materialCostSelfTotal": materialCostSelfTotal,
  11810. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11811. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11812. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11813. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11814. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11815. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11816. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11817. // "checkCostTotal": checkCostTotal,
  11818. // "checkCostSelfTotal": checkCostSelfTotal,
  11819. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11820. // "laboratoryCostTotal": laboratoryCostTotal,
  11821. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11822. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11823. // "treatCostTotal": treatCostTotal,
  11824. // "treatCostSelfTotal": treatCostSelfTotal,
  11825. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11826. // "zhenChaCostTotal": zhenChaCostTotal,
  11827. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11828. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11829. // "his_hospital_record": his_hospital_record,
  11830. // "pre_pay_money": pre_pay_money,
  11831. // "refund_sum": sum,
  11832. // })
  11833. //
  11834. //}
  11835. func (this *HisApiController) GetIncomeStatisticsData() {
  11836. start_time := this.GetString("start_time")
  11837. end_time := this.GetString("end_time")
  11838. key_words := this.GetString("key_words")
  11839. limit, _ := this.GetInt64("limit")
  11840. page, _ := this.GetInt64("page")
  11841. if page <= 0 {
  11842. page = 1
  11843. }
  11844. if limit <= 0 {
  11845. limit = 10
  11846. }
  11847. statistics_type, _ := this.GetInt64("statistics_type")
  11848. admin := this.GetAdminUserInfo()
  11849. timeLayout := "2006-01-02"
  11850. loc, _ := time.LoadLocation("Local")
  11851. var theStartTIme int64
  11852. if len(start_time) > 0 {
  11853. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11854. if err != nil {
  11855. theStartTIme = 0
  11856. }
  11857. theStartTIme = theTime.Unix()
  11858. }
  11859. var theEndtTIme int64
  11860. if len(end_time) > 0 {
  11861. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11862. if err != nil {
  11863. theEndtTIme = 0
  11864. }
  11865. theEndtTIme = theTime.Unix()
  11866. }
  11867. if statistics_type == 1 {
  11868. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11869. this.ServeSuccessJSON(map[string]interface{}{
  11870. "list": list,
  11871. "total": total,
  11872. })
  11873. } else {
  11874. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11875. this.ServeSuccessJSON(map[string]interface{}{
  11876. "list": list,
  11877. "total": total,
  11878. })
  11879. }
  11880. }
  11881. func (c *HisApiController) PostProjectInformation() {
  11882. adminUser := c.GetAdminUserInfo()
  11883. orgId := adminUser.CurrentOrgId
  11884. dataBody := make(map[string]interface{}, 0)
  11885. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11886. if err != nil {
  11887. utils.ErrorLog(err.Error())
  11888. return
  11889. }
  11890. utils.ErrorLog("%v", dataBody)
  11891. var projectList []*models.HisProject
  11892. var total_goods []interface{}
  11893. tempProjects := dataBody["projects"].([]interface{})
  11894. total_goods = tempProjects
  11895. for index, projectMap := range tempProjects {
  11896. projectM := projectMap.(map[string]interface{})
  11897. var project models.HisProject
  11898. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  11899. utils.ErrorLog("project_name")
  11900. return
  11901. }
  11902. project_name, _ := projectM["project_name"].(string)
  11903. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  11904. err_log := models.ExportErrLog{
  11905. LogType: 6,
  11906. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11907. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  11908. Status: 1,
  11909. CreateTime: time.Now().Unix(),
  11910. UpdateTime: time.Now().Unix(),
  11911. ExportTime: time.Now().Unix(),
  11912. }
  11913. service.CreateExportErrLog(&err_log)
  11914. continue
  11915. }
  11916. project.ProjectName = project_name
  11917. prices := projectM["price"].(string)
  11918. price, _ := strconv.ParseFloat(prices, 64)
  11919. if price <= 0 { //名字为空则生成一条导入错误日志
  11920. err_log := models.ExportErrLog{
  11921. LogType: 6,
  11922. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11923. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  11924. Status: 1,
  11925. CreateTime: time.Now().Unix(),
  11926. UpdateTime: time.Now().Unix(),
  11927. ExportTime: time.Now().Unix(),
  11928. }
  11929. service.CreateExportErrLog(&err_log)
  11930. continue
  11931. }
  11932. project.Price = price
  11933. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  11934. utils.ErrorLog("unit_id")
  11935. return
  11936. }
  11937. unit := projectM["unit"].(string)
  11938. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  11939. err_log := models.ExportErrLog{
  11940. LogType: 6,
  11941. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11942. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11943. Status: 1,
  11944. CreateTime: time.Now().Unix(),
  11945. UpdateTime: time.Now().Unix(),
  11946. ExportTime: time.Now().Unix(),
  11947. }
  11948. service.CreateExportErrLog(&err_log)
  11949. continue
  11950. }
  11951. project.Unit = unit
  11952. cost_classify := projectM["cost_classify"].(string)
  11953. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11954. err_log := models.ExportErrLog{
  11955. LogType: 6,
  11956. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11957. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11958. Status: 1,
  11959. CreateTime: time.Now().Unix(),
  11960. UpdateTime: time.Now().Unix(),
  11961. ExportTime: time.Now().Unix(),
  11962. }
  11963. service.CreateExportErrLog(&err_log)
  11964. continue
  11965. }
  11966. var costClassify = "费用类别"
  11967. var cost_classify_id int64
  11968. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11969. if len(cost_classify) != 0 {
  11970. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11971. if errcode == gorm.ErrRecordNotFound {
  11972. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11973. dataconfig := models.DictDataconfig{
  11974. ParentId: costClassifyConfig.ID,
  11975. Module: "system",
  11976. OrgId: orgId,
  11977. Name: cost_classify,
  11978. FieldName: "",
  11979. Value: costConfig.Value + 1,
  11980. CreatedTime: "",
  11981. UpdatedTime: "",
  11982. CreateUserId: adminUser.AdminUser.Id,
  11983. Status: 1,
  11984. Remark: "",
  11985. DeleteIdSystem: 0,
  11986. Title: "",
  11987. Content: "",
  11988. Order: 0,
  11989. Code: "",
  11990. }
  11991. service.CreatedDicConfig(&dataconfig)
  11992. }
  11993. }
  11994. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11995. for _, it := range costClassList {
  11996. if cost_classify == it.Name {
  11997. cost_classify_id = int64(it.Value)
  11998. }
  11999. }
  12000. project.CostClassify = cost_classify_id
  12001. executive_section := projectM["executive_section"].(string)
  12002. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  12003. err_log := models.ExportErrLog{
  12004. LogType: 6,
  12005. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12006. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  12007. Status: 1,
  12008. CreateTime: time.Now().Unix(),
  12009. UpdateTime: time.Now().Unix(),
  12010. ExportTime: time.Now().Unix(),
  12011. }
  12012. service.CreateExportErrLog(&err_log)
  12013. continue
  12014. }
  12015. if len(executive_section) != 0 {
  12016. //查找科室是否有内容
  12017. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  12018. if errcodedepart == gorm.ErrRecordNotFound {
  12019. department := models.XtHisDepartment{
  12020. Name: executive_section,
  12021. Status: 1,
  12022. UserOrgId: adminUser.CurrentOrgId,
  12023. CreatedTime: time.Now().Unix(),
  12024. }
  12025. service.CreateDePartment(&department)
  12026. }
  12027. }
  12028. var executive_section_id int64
  12029. departMentList, _ := service.GetAllDepartMent(orgId)
  12030. for _, it := range departMentList {
  12031. if executive_section == it.Name {
  12032. executive_section_id = it.ID
  12033. }
  12034. }
  12035. project.ExecutiveSection = executive_section_id
  12036. medical_coverage := projectM["medical_coverage"].(string)
  12037. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  12038. err_log := models.ExportErrLog{
  12039. LogType: 6,
  12040. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12041. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12042. Status: 1,
  12043. CreateTime: time.Now().Unix(),
  12044. UpdateTime: time.Now().Unix(),
  12045. ExportTime: time.Now().Unix(),
  12046. }
  12047. service.CreateExportErrLog(&err_log)
  12048. continue
  12049. }
  12050. var medicalCoverage = "医保等级"
  12051. var medical_coverage_id int64
  12052. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  12053. if len(medical_coverage) != 0 {
  12054. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  12055. if errormedicalcoverage == gorm.ErrRecordNotFound {
  12056. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  12057. dataconfig := models.DictDataconfig{
  12058. ParentId: medicalCoverageConfig.ID,
  12059. Module: "system",
  12060. OrgId: orgId,
  12061. Name: medical_coverage,
  12062. FieldName: "",
  12063. Value: medicalCoverageConfig.Value + 1,
  12064. CreatedTime: "",
  12065. UpdatedTime: "",
  12066. CreateUserId: adminUser.AdminUser.Id,
  12067. Status: 1,
  12068. Remark: "",
  12069. DeleteIdSystem: 0,
  12070. Title: "",
  12071. Content: "",
  12072. Order: 0,
  12073. Code: "",
  12074. }
  12075. service.CreatedDicConfig(&dataconfig)
  12076. }
  12077. }
  12078. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  12079. for _, it := range medicalCoverageList {
  12080. if medical_coverage == it.Name {
  12081. medical_coverage_id = int64(it.Value)
  12082. }
  12083. }
  12084. project.MedicalCoverage = medical_coverage_id
  12085. pinyin := projectM["pinyin"].(string)
  12086. project.Pinyin = pinyin
  12087. wubi := projectM["wubi"].(string)
  12088. project.Wubi = wubi
  12089. statistical_classification := projectM["statistical_classification"].(string)
  12090. var statisticalClassification = "统计分类"
  12091. var statistical_classification_id int64
  12092. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  12093. if len(statistical_classification) != 0 {
  12094. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  12095. if classificationerrcodes == gorm.ErrRecordNotFound {
  12096. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  12097. dataconfig := models.DictDataconfig{
  12098. ParentId: classiFication.ID,
  12099. Module: "system",
  12100. OrgId: orgId,
  12101. Name: statistical_classification,
  12102. FieldName: "",
  12103. Value: classiFicationConfig.Value + 1,
  12104. CreatedTime: "",
  12105. UpdatedTime: "",
  12106. CreateUserId: adminUser.AdminUser.Id,
  12107. Status: 1,
  12108. Remark: "",
  12109. DeleteIdSystem: 0,
  12110. Title: "",
  12111. Content: "",
  12112. Order: 0,
  12113. Code: "",
  12114. }
  12115. service.CreatedDicConfig(&dataconfig)
  12116. }
  12117. }
  12118. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  12119. for _, it := range classiFicationList {
  12120. if statistical_classification == it.Name {
  12121. statistical_classification_id = int64(it.Value)
  12122. }
  12123. }
  12124. project.StatisticalClassification = statistical_classification_id
  12125. disease_directory := int64(projectM["disease_directory"].(float64))
  12126. project.DiseaseDirectory = disease_directory
  12127. is_record := int64(projectM["is_record"].(float64))
  12128. project.IsRecord = is_record
  12129. medical_code := projectM["medical_code"].(string)
  12130. project.MedicalCode = medical_code
  12131. tube_color := projectM["tube_color"].(string)
  12132. var tubeColor = "试管颜色"
  12133. var tube_color_id int64
  12134. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  12135. if len(tube_color) != 0 {
  12136. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  12137. if errcodetube == gorm.ErrRecordNotFound {
  12138. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  12139. dataconfig := models.DictDataconfig{
  12140. ParentId: tubeColorConfig.ID,
  12141. Module: "system",
  12142. OrgId: orgId,
  12143. Name: tube_color,
  12144. FieldName: "",
  12145. Value: tubeConfig.Value + 1,
  12146. CreatedTime: "",
  12147. UpdatedTime: "",
  12148. CreateUserId: adminUser.AdminUser.Id,
  12149. Status: 1,
  12150. Remark: "",
  12151. DeleteIdSystem: 0,
  12152. Title: "",
  12153. Content: "",
  12154. Order: 0,
  12155. Code: "",
  12156. }
  12157. service.CreatedDicConfig(&dataconfig)
  12158. }
  12159. }
  12160. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  12161. for _, it := range tubeColorList {
  12162. if tube_color == it.Name {
  12163. tube_color_id = int64(it.Value)
  12164. }
  12165. }
  12166. project.TubeColor = tube_color_id
  12167. single_dose := projectM["single_dose"].(string)
  12168. project.SingleDose = single_dose
  12169. execution_frequency := projectM["execution_frequency"].(string)
  12170. project.ExecutionFrequency = execution_frequency
  12171. delivery_way := projectM["delivery_way"].(string)
  12172. project.DeliveryWay = delivery_way
  12173. number_days := projectM["number_days"].(string)
  12174. project.NumberDays = number_days
  12175. total := projectM["total"].(string)
  12176. project.Total = total
  12177. medical_status := int64(projectM["medical_status"].(float64))
  12178. project.MedicalStatus = medical_status
  12179. category := int64(projectM["category"].(float64))
  12180. project.Category = category
  12181. specail_project := int64(projectM["specail_project"].(float64))
  12182. project.SpecailProject = specail_project
  12183. social_security_directory_code := projectM["social_security_directory_code"].(string)
  12184. project.SocialSecurityDirectoryCode = social_security_directory_code
  12185. remark := projectM["remark"].(string)
  12186. project.Remark = remark
  12187. record_date := projectM["record_date"].(string)
  12188. timeLayout := "2006-01-02"
  12189. loc, _ := time.LoadLocation("Local")
  12190. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12191. project.RecordDate = theTime.Unix()
  12192. projectList = append(projectList, &project)
  12193. }
  12194. export_time := time.Now().Unix()
  12195. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  12196. if len(projectList) > 0 {
  12197. for _, item := range projectList {
  12198. hans := item.ProjectName // 要转换的汉字字符串
  12199. // 创建一个拼音转换器
  12200. p := pinyin.NewArgs()
  12201. // 将汉字转为拼音
  12202. pinyinSlice := pinyin.Pinyin(hans, p)
  12203. // 输出拼音
  12204. fmt.Println("Pinyin:", pinyinSlice)
  12205. // 获取首字母
  12206. firstLetter := ""
  12207. for _, py := range pinyinSlice {
  12208. if len(py) > 0 {
  12209. firstLetter += string(py[0][0])
  12210. }
  12211. }
  12212. item.FirstLetter = firstLetter
  12213. project := models.HisProject{
  12214. ProjectName: item.ProjectName,
  12215. Price: item.Price,
  12216. Unit: item.Unit,
  12217. CostClassify: item.CostClassify,
  12218. ExecutiveSection: item.ExecutiveSection,
  12219. MedicalCoverage: item.MedicalCoverage,
  12220. UserOrgId: orgId,
  12221. Status: 1,
  12222. CreatedTime: time.Now().Unix(),
  12223. Pinyin: item.Pinyin,
  12224. Wubi: item.Wubi,
  12225. StatisticalClassification: item.StatisticalClassification,
  12226. DiseaseDirectory: item.DiseaseDirectory,
  12227. IsRecord: item.IsRecord,
  12228. MedicalCode: item.MedicalCode,
  12229. TubeColor: item.TubeColor,
  12230. SingleDose: item.SingleDose,
  12231. DeliveryWay: item.DeliveryWay,
  12232. NumberDays: item.NumberDays,
  12233. Total: item.Total,
  12234. Category: item.Category,
  12235. MedicalStatus: item.MedicalStatus,
  12236. SpecailProject: item.SpecailProject,
  12237. RecordDate: item.RecordDate,
  12238. Remark: item.Remark,
  12239. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  12240. ExecutionFrequency: item.ExecutionFrequency,
  12241. FirstLetter: item.FirstLetter,
  12242. }
  12243. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  12244. if errcodeproject == gorm.ErrRecordNotFound {
  12245. service.CreateProjectInfomation(&project)
  12246. } else if errcodeproject == nil {
  12247. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  12248. }
  12249. log := models.ExportLog{
  12250. LogType: 6,
  12251. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12252. TotalNum: int64(len(total_goods)),
  12253. FailNum: int64(len(errLogs)),
  12254. SuccessNum: int64(len(projectList)),
  12255. CreateTime: time.Now().Unix(),
  12256. UpdateTime: time.Now().Unix(),
  12257. ExportTime: export_time,
  12258. Status: 1,
  12259. }
  12260. service.CreateExportLog(&log)
  12261. c.ServeSuccessJSON(map[string]interface{}{
  12262. "msg": "导入成功",
  12263. "total_num": len(total_goods),
  12264. "success_num": len(projectList),
  12265. "fail_num": int64(len(errLogs)),
  12266. })
  12267. }
  12268. } else {
  12269. log := models.ExportLog{
  12270. LogType: 6,
  12271. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12272. TotalNum: int64(len(total_goods)),
  12273. FailNum: int64(len(errLogs)),
  12274. SuccessNum: int64(len(projectList)),
  12275. CreateTime: time.Now().Unix(),
  12276. UpdateTime: time.Now().Unix(),
  12277. ExportTime: export_time,
  12278. Status: 1,
  12279. }
  12280. service.CreateExportLog(&log)
  12281. c.ServeSuccessJSON(map[string]interface{}{
  12282. "msg": "导入成功",
  12283. "total_num": len(total_goods),
  12284. "success_num": len(projectList),
  12285. "fail_num": int64(len(errLogs)),
  12286. })
  12287. }
  12288. }
  12289. //func (this *HisApiController) EditProjectInformation(){
  12290. //
  12291. // id, _ := this.GetInt64("id")
  12292. // project_team := this.GetString("project_team")
  12293. // price := this.GetString("price")
  12294. // price_float, _ := strconv.ParseFloat(price, 64)
  12295. // pinyin := this.GetString("pinyin")
  12296. // wubi := this.GetString("wubi")
  12297. // tube_color, _ := this.GetInt64("tube_color")
  12298. // team_type, _ := this.GetInt64("team_type")
  12299. // remark := this.GetString("remark")
  12300. // ids := this.GetString("ids")
  12301. // item_id := this.GetString("item_id")
  12302. // projectTeam := models.XtHisProjectTeam{
  12303. // ProjectTeam: project_team,
  12304. // Price: price_float,
  12305. // Pinyin: pinyin,
  12306. // Wubi: wubi,
  12307. // TubeColor: tube_color,
  12308. // TeamType: team_type,
  12309. // Remark: remark,
  12310. // ProjectId: ids,
  12311. // ItemId: item_id,
  12312. // }
  12313. //
  12314. //
  12315. // dataBody := make(map[string]interface{}, 0)
  12316. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12317. // if err != nil {
  12318. // utils.ErrorLog(err.Error())
  12319. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12320. // return
  12321. // }
  12322. //
  12323. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12324. //
  12325. //
  12326. // if err != nil {
  12327. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12328. // return
  12329. // }
  12330. //
  12331. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12332. // infos, _ := dataBody["info"].([]interface{})
  12333. // if len(infos) > 0 {
  12334. // var ids []string
  12335. //
  12336. // for _, item := range infos {
  12337. // items := item.(map[string]interface{})
  12338. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12339. // utils.ErrorLog("id")
  12340. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12341. // return
  12342. // }
  12343. // id := int64(items["id"].(float64))
  12344. //
  12345. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12346. // utils.ErrorLog("type")
  12347. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12348. // return
  12349. // }
  12350. // types := int64(items["type"].(float64))
  12351. //
  12352. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12353. // utils.ErrorLog("number")
  12354. // }
  12355. //
  12356. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12357. //
  12358. // projectList := models.XtHisProjectList{
  12359. // Number: number,
  12360. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12361. // ProjectId: id,
  12362. // Status: 1,
  12363. // CreatedTime: time.Now().Unix(),
  12364. // UpdatedTime: time.Now().Unix(),
  12365. // TeamId: projectTeam.ID,
  12366. // Type: types,
  12367. // }
  12368. // list := projectList
  12369. //
  12370. // service.CreateProjectList(&list)
  12371. //
  12372. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12373. //
  12374. // }
  12375. // ids_str := strings.Join(ids, ",")
  12376. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12377. // service.SaveProjectTeam(&projectTeam)
  12378. // this.ServeSuccessJSON(map[string]interface{}{
  12379. // "projectTeam": projectTeam,
  12380. // })
  12381. // }
  12382. // }
  12383. //}
  12384. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12385. name := c.GetString("name")
  12386. mode_id, _ := c.GetInt64("mode", 0)
  12387. types, _ := c.GetInt64("type", 0)
  12388. patient_id, _ := c.GetInt64("patient_id", 0)
  12389. types = 1
  12390. adminInfo := c.GetAdminUserInfo()
  12391. template := &models.HisPrescriptionTemplate{
  12392. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12393. PatientId: patient_id,
  12394. Type: types,
  12395. Status: 1,
  12396. Ctime: time.Now().Unix(),
  12397. Mtime: time.Now().Unix(),
  12398. Name: name,
  12399. Mode: mode_id,
  12400. }
  12401. dataBody := make(map[string]interface{}, 0)
  12402. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12403. if err != nil {
  12404. utils.ErrorLog(err.Error())
  12405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12406. return
  12407. }
  12408. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12409. //如果已经存在记录则删除处方
  12410. if template_one.ID > 0 {
  12411. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12412. var ids []int64
  12413. var org_id int64
  12414. for _, item := range ps {
  12415. org_id = c.GetAdminUserInfo().CurrentOrgId
  12416. ids = append(ids, item.ID)
  12417. }
  12418. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12419. if err2 == nil {
  12420. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12421. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12422. if len(prescriptions) > 0 {
  12423. for _, item := range prescriptions {
  12424. items := item.(map[string]interface{})
  12425. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12426. utils.ErrorLog("type")
  12427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12428. return
  12429. }
  12430. types := int64(items["type"].(float64))
  12431. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12432. utils.ErrorLog("med_type")
  12433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12434. return
  12435. }
  12436. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12437. ctime := time.Now().Unix()
  12438. prescription := &models.HisPrescriptionInfoTemplate{
  12439. PatientId: patient_id,
  12440. UserOrgId: adminInfo.CurrentOrgId,
  12441. Ctime: ctime,
  12442. Mtime: ctime,
  12443. Type: types,
  12444. Modifier: adminInfo.AdminUser.Id,
  12445. Creator: adminInfo.AdminUser.Id,
  12446. Status: 1,
  12447. PTemplateId: template_one.ID,
  12448. MedType: med_type,
  12449. }
  12450. service.CreateHisPrescriptionInfoTemplate(prescription)
  12451. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12452. advices := items["advices"].([]interface{})
  12453. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12454. ctime := time.Now().Unix()
  12455. mtime := ctime
  12456. if len(advices) > 0 {
  12457. for _, advice := range advices {
  12458. var s models.HisPrescriptionAdviceTemplate
  12459. s.PrescriptionId = prescription.ID
  12460. s.AdviceType = 2
  12461. s.StopState = 2
  12462. s.ExecutionState = 2
  12463. s.Status = 1
  12464. s.UserOrgId = adminInfo.CurrentOrgId
  12465. s.CreatedTime = ctime
  12466. s.UpdatedTime = mtime
  12467. s.PatientId = patient_id
  12468. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12469. if errcode > 0 {
  12470. c.ServeFailJSONWithSGJErrorCode(errcode)
  12471. return
  12472. }
  12473. service.CreateHisPrescriptionAdviceTemplate(&s)
  12474. }
  12475. }
  12476. }
  12477. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12478. projects := items["project"].([]interface{})
  12479. if len(projects) > 0 {
  12480. for _, project := range projects {
  12481. var p models.HisPrescriptionProjectTemplate
  12482. p.PrescriptionId = prescription.ID
  12483. p.Ctime = time.Now().Unix()
  12484. p.Mtime = time.Now().Unix()
  12485. p.PatientId = patient_id
  12486. p.UserOrgId = adminInfo.CurrentOrgId
  12487. p.Status = 1
  12488. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12489. if errcode > 0 {
  12490. c.ServeFailJSONWithSGJErrorCode(errcode)
  12491. return
  12492. }
  12493. service.CreateHisPrescriptionProjectTemplate(&p)
  12494. }
  12495. }
  12496. }
  12497. }
  12498. c.ServeSuccessJSON(map[string]interface{}{
  12499. "msg": "创建成功",
  12500. })
  12501. }
  12502. }
  12503. } else {
  12504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12505. return
  12506. }
  12507. } else {
  12508. err3 := service.CreateHisPrescriptionTemplate(template)
  12509. if err3 == nil {
  12510. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12511. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12512. if len(prescriptions) > 0 {
  12513. for _, item := range prescriptions {
  12514. items := item.(map[string]interface{})
  12515. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12516. utils.ErrorLog("type")
  12517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12518. return
  12519. }
  12520. types := int64(items["type"].(float64))
  12521. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12522. utils.ErrorLog("med_type")
  12523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12524. return
  12525. }
  12526. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12527. ctime := time.Now().Unix()
  12528. prescription := &models.HisPrescriptionInfoTemplate{
  12529. PatientId: patient_id,
  12530. UserOrgId: adminInfo.CurrentOrgId,
  12531. Ctime: ctime,
  12532. Mtime: ctime,
  12533. Type: types,
  12534. Modifier: adminInfo.AdminUser.Id,
  12535. Creator: adminInfo.AdminUser.Id,
  12536. Status: 1,
  12537. PTemplateId: template.ID,
  12538. MedType: med_type,
  12539. }
  12540. service.CreateHisPrescriptionInfoTemplate(prescription)
  12541. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12542. advices := items["advices"].([]interface{})
  12543. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12544. ctime := time.Now().Unix()
  12545. mtime := ctime
  12546. if len(advices) > 0 {
  12547. for _, advice := range advices {
  12548. var s models.HisPrescriptionAdviceTemplate
  12549. s.PrescriptionId = prescription.ID
  12550. s.AdviceType = 2
  12551. s.StopState = 2
  12552. s.ExecutionState = 2
  12553. s.Status = 1
  12554. s.UserOrgId = adminInfo.CurrentOrgId
  12555. s.CreatedTime = ctime
  12556. s.UpdatedTime = mtime
  12557. s.PatientId = patient_id
  12558. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12559. if errcode > 0 {
  12560. c.ServeFailJSONWithSGJErrorCode(errcode)
  12561. return
  12562. }
  12563. service.CreateHisPrescriptionAdviceTemplate(&s)
  12564. }
  12565. }
  12566. }
  12567. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12568. projects := items["project"].([]interface{})
  12569. if len(projects) > 0 {
  12570. for _, project := range projects {
  12571. var p models.HisPrescriptionProjectTemplate
  12572. p.PrescriptionId = prescription.ID
  12573. p.Ctime = time.Now().Unix()
  12574. p.Mtime = time.Now().Unix()
  12575. p.PatientId = patient_id
  12576. p.UserOrgId = adminInfo.CurrentOrgId
  12577. p.Status = 1
  12578. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12579. if errcode > 0 {
  12580. c.ServeFailJSONWithSGJErrorCode(errcode)
  12581. return
  12582. }
  12583. service.CreateHisPrescriptionProjectTemplate(&p)
  12584. }
  12585. }
  12586. }
  12587. }
  12588. c.ServeSuccessJSON(map[string]interface{}{
  12589. "msg": "创建成功",
  12590. })
  12591. }
  12592. }
  12593. } else {
  12594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12595. return
  12596. }
  12597. }
  12598. }
  12599. func (c *HisApiController) PreSettle() {
  12600. id, _ := c.GetInt64("id")
  12601. record_time := c.GetString("record_time")
  12602. his_patient_id, _ := c.GetInt64("his_patient_id")
  12603. timeLayout := "2006-01-02"
  12604. loc, _ := time.LoadLocation("Local")
  12605. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12606. diagnosis_id := c.GetString("diagnosis")
  12607. sick_type, _ := c.GetInt64("sick_type")
  12608. reg_type, _ := c.GetInt64("p_type")
  12609. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12610. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12611. if err != nil {
  12612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12613. return
  12614. }
  12615. recordDateTime := theTime.Unix()
  12616. adminUser := c.GetAdminUserInfo()
  12617. var prescriptions []*models.HisPrescription
  12618. var start_time int64
  12619. var end_time int64
  12620. ids_str := c.GetString("ids")
  12621. ids_arr := strings.Split(ids_str, ",")
  12622. fmt.Println(reg_type)
  12623. if settle_accounts_type == 1 { //日结
  12624. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12625. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12626. } else {
  12627. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12628. }
  12629. fmt.Println(prescriptions)
  12630. } else { //月结
  12631. start_time_str := c.GetString("start_time")
  12632. end_time_str := c.GetString("end_time")
  12633. timeLayout := "2006-01-02"
  12634. loc, _ := time.LoadLocation("Local")
  12635. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12636. if err != nil {
  12637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12638. return
  12639. }
  12640. recordStartTime := theStartTime.Unix()
  12641. start_time = recordStartTime
  12642. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12643. if err != nil {
  12644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12645. return
  12646. }
  12647. recordEndTime := theEndTime.Unix()
  12648. end_time = recordEndTime
  12649. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12650. }
  12651. if reg_type == 1111 || reg_type == 1112 {
  12652. reg_type = 11
  12653. }
  12654. timestamp := time.Now().Unix()
  12655. tempTime := time.Unix(timestamp, 0)
  12656. timeFormat := tempTime.Format("20060102150405")
  12657. chrgBchno := rand.Intn(100000) + 10000
  12658. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12659. strconv.FormatInt(his.PatientId, 10)
  12660. var ids []int64
  12661. for _, item := range prescriptions {
  12662. ids = append(ids, item.ID)
  12663. }
  12664. fmt.Println(ids)
  12665. var total float64
  12666. for _, item := range prescriptions {
  12667. fmt.Println(item)
  12668. if item.Type == 1 { //药品
  12669. for _, subItem := range item.HisDoctorAdviceInfo {
  12670. total = total + (subItem.Price * subItem.PrescribingNumber)
  12671. }
  12672. }
  12673. if item.Type == 2 { //项目
  12674. for _, subItem := range item.HisPrescriptionProject {
  12675. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12676. total = total + (subItem.Price * cnt)
  12677. }
  12678. }
  12679. for _, subItem := range item.HisAdditionalCharge {
  12680. total = total + (subItem.Price * float64(subItem.Count))
  12681. }
  12682. }
  12683. allTotal := fmt.Sprintf("%.2f", total)
  12684. totals, _ := strconv.ParseFloat(allTotal, 64)
  12685. order := &models.HisOrder{
  12686. UserOrgId: adminUser.CurrentOrgId,
  12687. HisPatientId: his.ID,
  12688. PatientId: id,
  12689. SettleAccountsDate: recordDateTime,
  12690. Ctime: time.Now().Unix(),
  12691. Mtime: time.Now().Unix(),
  12692. Status: 1,
  12693. OrderStatus: 1,
  12694. MdtrtId: his.Number,
  12695. Number: chrg_bchno,
  12696. MedfeeSumamt: totals,
  12697. SettleEndTime: end_time,
  12698. SettleStartTime: start_time,
  12699. SettleType: settle_accounts_type,
  12700. PsnPartAmt: totals,
  12701. PsnCashPay: totals,
  12702. PType: 2,
  12703. IsPre: 1,
  12704. MedType: strconv.Itoa(int(reg_type)),
  12705. Diagnosis: diagnosis_id,
  12706. }
  12707. err = service.CreateOrder(order)
  12708. if err != nil {
  12709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12710. return
  12711. }
  12712. var customs []*Custom
  12713. for _, item := range prescriptions {
  12714. fmt.Println(item.Type)
  12715. if item.Type == 1 { //药品
  12716. for _, subItem := range item.HisDoctorAdviceInfo {
  12717. cus := &Custom{
  12718. AdviceId: subItem.ID,
  12719. ProjectId: 0,
  12720. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12721. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12722. FeedetlSn: subItem.FeedetlSn,
  12723. Price: fmt.Sprintf("%.2f", subItem.Price),
  12724. MedListCodg: subItem.MedListCodg,
  12725. Type: 1,
  12726. }
  12727. customs = append(customs, cus)
  12728. }
  12729. }
  12730. if item.Type == 2 { //项目
  12731. for _, subItem := range item.HisPrescriptionProject {
  12732. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12733. cus := &Custom{
  12734. AdviceId: 0,
  12735. ProjectId: subItem.ID,
  12736. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12737. Cut: fmt.Sprintf("%.2f", cnt),
  12738. FeedetlSn: subItem.FeedetlSn,
  12739. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12740. MedListCodg: subItem.MedListCodg,
  12741. Type: 2,
  12742. }
  12743. customs = append(customs, cus)
  12744. }
  12745. }
  12746. for _, item := range item.HisAdditionalCharge {
  12747. cus := &Custom{
  12748. ItemId: item.ID,
  12749. AdviceId: 0,
  12750. ProjectId: 0,
  12751. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12752. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12753. FeedetlSn: item.FeedetlSn,
  12754. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12755. MedListCodg: item.XtHisAddtionConfig.Code,
  12756. Type: 3,
  12757. }
  12758. customs = append(customs, cus)
  12759. }
  12760. }
  12761. fmt.Println(customs)
  12762. for _, item := range customs {
  12763. var advice_id int64 = 0
  12764. var project_id int64 = 0
  12765. var item_id int64 = 0
  12766. var types int64 = 0
  12767. if item.Type == 1 {
  12768. advice_id = item.AdviceId
  12769. project_id = 0
  12770. item_id = 0
  12771. } else if item.Type == 2 {
  12772. advice_id = 0
  12773. item_id = 0
  12774. project_id = item.ProjectId
  12775. } else if item.Type == 3 {
  12776. advice_id = 0
  12777. item_id = item.ItemId
  12778. project_id = 0
  12779. }
  12780. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12781. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12782. pric, _ := strconv.ParseFloat(item.Price, 32)
  12783. info := &models.HisOrderInfo{
  12784. OrderNumber: order.Number,
  12785. UploadDate: time.Now().Unix(),
  12786. AdviceId: advice_id,
  12787. DetItemFeeSumamt: detItemFeeSumamt,
  12788. Cnt: cut,
  12789. Pric: pric,
  12790. PatientId: id,
  12791. Status: 1,
  12792. Mtime: time.Now().Unix(),
  12793. Ctime: time.Now().Unix(),
  12794. UserOrgId: adminUser.CurrentOrgId,
  12795. HisPatientId: his.ID,
  12796. OrderId: order.ID,
  12797. ProjectId: project_id,
  12798. Type: types,
  12799. ItemId: item_id,
  12800. }
  12801. service.CreateOrderInfo(info)
  12802. }
  12803. his.SickType = sick_type
  12804. service.UpdataHisPateint(&his)
  12805. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12806. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12807. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12808. if err == nil {
  12809. c.ServeSuccessJSON(map[string]interface{}{
  12810. "msg": "结算成功",
  12811. })
  12812. }
  12813. }
  12814. type CustomOrderInfo struct {
  12815. Name string
  12816. Spec string
  12817. Unit string
  12818. Count float64
  12819. Price float64
  12820. Total float64
  12821. }
  12822. func (c *HisApiController) GetPrivateExpensesInfo() {
  12823. order_id, _ := c.GetInt64("id", 0)
  12824. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12825. order, _ := service.GetHisOrderByID(order_id)
  12826. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12827. if order.ID == 0 {
  12828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12829. return
  12830. }
  12831. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12832. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12833. org_id := c.GetAdminUserInfo().CurrentOrgId
  12834. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12835. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12836. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12837. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12838. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12839. //var orderInfos_four []*models.HisOrderInfoTwo
  12840. //for _, item := range orderInfos_three {
  12841. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  12842. // item.HisPrescriptionProject.IsCheckTeam = 1
  12843. // orderInfos_four = append(orderInfos_four, item)
  12844. //
  12845. // }
  12846. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  12847. // item.HisPrescriptionProject.IsCheckTeam = 2
  12848. // orderInfos_two = append(orderInfos_two, item)
  12849. // }
  12850. //}
  12851. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  12852. //var cus_slice []CustomOrderInfo
  12853. //for _, item := range new_order_info {
  12854. // var cus CustomOrderInfo
  12855. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  12856. // cus.Unit = ""
  12857. // cus.Spec = ""
  12858. // var total float64
  12859. // for _, subItem := range orderInfos_four {
  12860. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  12861. // total = total + subItem.DetItemFeeSumamt
  12862. // fmt.Println(subItem.DetItemFeeSumamt)
  12863. // }
  12864. // }
  12865. // cus.Count = 1
  12866. // cus.Total = total
  12867. // cus_slice = append(cus_slice, cus)
  12868. //}
  12869. orderInfos = append(orderInfos, orderInfos_two...)
  12870. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  12871. //orderInfos = append(orderInfos, orderInfos_three...)
  12872. //}/**/
  12873. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  12874. c.ServeSuccessJSON(map[string]interface{}{
  12875. "order": order,
  12876. "order_info": orderInfos,
  12877. "patient": patient,
  12878. "admin_info": adminInfo,
  12879. "his": his,
  12880. "current_admin": role,
  12881. "org_config": miConfig,
  12882. //"new_order_info": cus_slice,
  12883. })
  12884. }
  12885. func (this *HisApiController) ChangeMedType() {
  12886. med_type := this.GetString("med_type")
  12887. old_med_type := this.GetString("old_med_type")
  12888. ids := this.GetString("ids")
  12889. settle_type, _ := this.GetInt64("settle_type")
  12890. start_time := this.GetString("start_time")
  12891. end_time := this.GetString("end_time")
  12892. ids_arr := strings.Split(ids, ",")
  12893. if settle_type == 1 { //日结
  12894. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  12895. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  12896. prescription.MedType = med_type
  12897. err := service.SaveHisPrescriptionTwo(&prescription)
  12898. if err == nil {
  12899. this.ServeSuccessJSON(map[string]interface{}{
  12900. "msg": "修改成功",
  12901. })
  12902. } else {
  12903. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12904. return
  12905. }
  12906. } else if settle_type == 2 {
  12907. timeLayout := "2006-01-02"
  12908. loc, _ := time.LoadLocation("Local")
  12909. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12910. if err != nil {
  12911. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12912. return
  12913. }
  12914. recordStartTime := theStartTime.Unix()
  12915. start_time_timestamp := recordStartTime
  12916. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  12917. if err != nil {
  12918. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12919. return
  12920. }
  12921. recordEndTime := theEndTime.Unix()
  12922. end_time_timestamp := recordEndTime
  12923. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  12924. if updateErr == nil {
  12925. this.ServeSuccessJSON(map[string]interface{}{
  12926. "msg": "修改成功",
  12927. })
  12928. } else {
  12929. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12930. return
  12931. }
  12932. }
  12933. }
  12934. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  12935. patient_id, _ := c.GetInt64("patient_id")
  12936. his_patient_id, _ := c.GetInt64("his_patient_id")
  12937. record_date := c.GetString("record_date")
  12938. start_time := c.GetString("start_time")
  12939. end_time := c.GetString("end_time")
  12940. order_status, _ := c.GetInt64("type", 0)
  12941. p_type, _ := c.GetInt64("p_type", 0)
  12942. order_id, _ := c.GetInt64("order_id", 0)
  12943. timeLayout := "2006-01-02"
  12944. loc, _ := time.LoadLocation("Local")
  12945. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12946. if err != nil {
  12947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12948. return
  12949. }
  12950. recordDateTime := theTime.Unix()
  12951. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12952. if err != nil {
  12953. }
  12954. startRecordDateTime := startTime.Unix()
  12955. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12956. if err != nil {
  12957. }
  12958. endRecordDateTime := endTime.Unix()
  12959. admin := c.GetAdminUserInfo()
  12960. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12961. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12962. order, _ := service.GetHisOrderByID(order_id)
  12963. var monthPrescriptions []*models.HisPrescription
  12964. if order_status == 1 || order_status == 0 {
  12965. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12966. } else if order_status == 2 {
  12967. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12968. }
  12969. var settle_total float64
  12970. for _, item := range monthPrescriptions {
  12971. if len(item.HisPrescriptionProject) > 0 {
  12972. for _, subItem := range item.HisPrescriptionProject {
  12973. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12974. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12975. settle_total = settle_total + total
  12976. }
  12977. }
  12978. if len(item.HisDoctorAdviceInfo) > 0 {
  12979. for _, subItem := range item.HisDoctorAdviceInfo {
  12980. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12981. settle_total = settle_total + total
  12982. }
  12983. }
  12984. }
  12985. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12986. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12987. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12988. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12989. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12990. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12991. //获取所有科室信息
  12992. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12993. var dia string
  12994. for _, item := range month_p_info {
  12995. if len(dia) == 0 {
  12996. dia = item.Diagnosis
  12997. } else {
  12998. dia = dia + "," + item.Diagnosis
  12999. }
  13000. }
  13001. dia_arr := removeDuplicates(strings.Split(dia, ","))
  13002. dia_arr = removeEmptyStrings(dia_arr)
  13003. c.ServeSuccessJSON(map[string]interface{}{
  13004. "his_info": his_patient_info,
  13005. "xt_info": xt_patient_info,
  13006. "case_history": case_history,
  13007. "info": patientPrescriptionInfo,
  13008. "last_info": lastPatientPrescriptionInfo,
  13009. "month_prescriptions": monthPrescriptions,
  13010. "order": order,
  13011. "doctors": doctors,
  13012. "department": department,
  13013. "settle_total": settle_total,
  13014. "dia_arr": dia_arr,
  13015. })
  13016. return
  13017. }
  13018. func removeEmptyStrings(input []string) []string {
  13019. var output []string
  13020. for _, s := range input {
  13021. if s != "" {
  13022. output = append(output, s)
  13023. }
  13024. }
  13025. return output
  13026. }
  13027. func removeDuplicates(input []string) []string {
  13028. seen := make(map[string]bool)
  13029. output := []string{}
  13030. for _, s := range input {
  13031. if _, exists := seen[s]; !exists {
  13032. seen[s] = true
  13033. output = append(output, s)
  13034. }
  13035. }
  13036. return output
  13037. }
  13038. func (c *HisApiController) GetHisMonthPatientInfo() {
  13039. patient_id, _ := c.GetInt64("patient_id")
  13040. his_patient_id, _ := c.GetInt64("his_patient_id")
  13041. record_date := c.GetString("record_date")
  13042. number := c.GetString("number")
  13043. start_time := c.GetString("start_time")
  13044. end_time := c.GetString("end_time")
  13045. p_type, _ := c.GetInt64("p_type")
  13046. timeLayout := "2006-01-02"
  13047. loc, _ := time.LoadLocation("Local")
  13048. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  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. admin := c.GetAdminUserInfo()
  13063. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  13064. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13065. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  13066. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13067. var settle_total float64
  13068. for _, item := range monthPrescriptions {
  13069. if len(item.HisPrescriptionProject) > 0 {
  13070. for _, subItem := range item.HisPrescriptionProject {
  13071. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13072. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13073. settle_total = settle_total + total
  13074. }
  13075. }
  13076. if len(item.HisDoctorAdviceInfo) > 0 {
  13077. for _, subItem := range item.HisDoctorAdviceInfo {
  13078. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13079. settle_total = settle_total + total
  13080. }
  13081. }
  13082. }
  13083. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13084. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13085. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13086. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13087. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  13088. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13089. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  13090. //获取所有科室信息
  13091. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13092. c.ServeSuccessJSON(map[string]interface{}{
  13093. "his_info": his_patient_info,
  13094. "xt_info": xt_patient_info,
  13095. "case_history": case_history,
  13096. "info": patientPrescriptionInfo,
  13097. "month_prescriptions": monthPrescriptions,
  13098. "order": order,
  13099. "doctors": doctors,
  13100. "department": department,
  13101. "count": count,
  13102. "drugStockConfig": drugStockConfig,
  13103. "last_info": lastPatientPrescriptionInfo,
  13104. "settle_total": settle_total,
  13105. })
  13106. return
  13107. }
  13108. func (c *HisApiController) GetAllOrder() {
  13109. org_id := c.GetAdminUserInfo().CurrentOrgId
  13110. orders, _ := service.GetNewHisOrderList(org_id)
  13111. c.ServeSuccessJSON(map[string]interface{}{
  13112. "order": orders,
  13113. })
  13114. return
  13115. }
  13116. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  13117. newArr = make([]*models.HisOrderInfoTwo, 0)
  13118. for i := 0; i < len(arr); i++ {
  13119. repeat := false
  13120. for j := i + 1; j < len(arr); j++ {
  13121. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  13122. repeat = true
  13123. break
  13124. }
  13125. }
  13126. if !repeat {
  13127. newArr = append(newArr, arr[i])
  13128. }
  13129. }
  13130. return
  13131. }
  13132. // 修改处方退库操作 参数传修改之前的处方数据
  13133. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  13134. if advice.ExecutionState == 1 {
  13135. //查询该病人该药品是否有库存记录
  13136. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  13137. if errcode == gorm.ErrRecordNotFound {
  13138. } else {
  13139. //退库
  13140. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  13141. if advice.PrescribingNumberUnit == drug.MinUnit {
  13142. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13143. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13144. //退库
  13145. warehouseInfo := models.DrugWarehouseInfo{
  13146. StockMinNumber: prescribingNumber,
  13147. }
  13148. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  13149. operation_time := time.Now().Unix()
  13150. creater := advice.AdviceDoctor
  13151. ctime := time.Now().Unix()
  13152. timeStr := time.Now().Format("2006-01-02")
  13153. timeArr := strings.Split(timeStr, "-")
  13154. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13155. total = total + 1
  13156. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13157. cancelStock := models.DrugCancelStock{
  13158. OrderNumber: orderNumber,
  13159. OperaTime: operation_time,
  13160. OrgId: advice.UserOrgId,
  13161. Creater: creater,
  13162. Ctime: ctime,
  13163. Status: 1,
  13164. ReturnTime: advice.AdviceDate,
  13165. Dealer: info.Dealer,
  13166. Manufacturer: info.Manufacturer,
  13167. Type: 1,
  13168. }
  13169. service.AddSigleDrugCancelStock(&cancelStock)
  13170. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13171. dealer, _ := service.GetDealerById(info.Dealer)
  13172. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13173. cancelStockInfo := models.DrugCancelStockInfo{
  13174. OrderNumber: cancelInfo.OrderNumber,
  13175. CancelStockId: cancelInfo.ID,
  13176. DrugId: info.DrugId,
  13177. Count: info.Count,
  13178. Status: 1,
  13179. Ctime: ctime,
  13180. OrgId: advice.UserOrgId,
  13181. Type: 1,
  13182. Manufacturer: manufactureName.ManufacturerName,
  13183. Dealer: dealer.DealerName,
  13184. Total: 0,
  13185. RetailPrice: info.RetailPrice,
  13186. RetailTotalPrice: info.RetailTotalPrice,
  13187. Price: info.Price,
  13188. RegisterAccount: "",
  13189. Remark: info.Remark,
  13190. BatchNumber: info.BatchNumber,
  13191. MaxUnit: info.CountUnit,
  13192. ProductDate: info.ProductDate,
  13193. ExpiryDate: info.ExpiryDate,
  13194. BatchNumberId: info.WarehouseInfoId,
  13195. }
  13196. flow := models.DrugFlow{
  13197. WarehousingId: 0,
  13198. DrugId: info.DrugId,
  13199. Number: "",
  13200. BatchNumber: info.BatchNumber,
  13201. Count: info.Count,
  13202. UserOrgId: advice.UserOrgId,
  13203. PatientId: 0,
  13204. SystemTime: ctime,
  13205. ConsumableType: 4,
  13206. IsSys: 0,
  13207. WarehousingOrder: "",
  13208. WarehouseOutId: 0,
  13209. WarehouseOutOrderNumber: "",
  13210. IsEdit: 0,
  13211. CancelStockId: cancelStock.ID,
  13212. CancelOrderNumber: cancelStock.OrderNumber,
  13213. Manufacturer: info.Manufacturer,
  13214. Dealer: info.Dealer,
  13215. Creator: advice.UserOrgId,
  13216. UpdateCreator: 0,
  13217. Status: 1,
  13218. Ctime: time.Now().Unix(),
  13219. Mtime: 0,
  13220. Price: info.Price,
  13221. WarehousingDetailId: 0,
  13222. WarehouseOutDetailId: 0,
  13223. CancelOutDetailId: 0,
  13224. ExpireDate: info.ExpiryDate,
  13225. ProductDate: info.ProductDate,
  13226. MaxUnit: info.CountUnit,
  13227. MinUnit: "",
  13228. }
  13229. service.CreatedCancelStock(cancelStockInfo)
  13230. service.CreateDrugFlowOne(flow)
  13231. } else {
  13232. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13233. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13234. if advice.PrescribingNumberUnit == drug.MaxUnit {
  13235. warehouseInfo := models.DrugWarehouseInfo{
  13236. StockMinNumber: prescribingNumber,
  13237. }
  13238. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  13239. }
  13240. operation_time := time.Now().Unix()
  13241. creater := advice.AdviceDoctor
  13242. ctime := time.Now().Unix()
  13243. timeStr := time.Now().Format("2006-01-02")
  13244. timeArr := strings.Split(timeStr, "-")
  13245. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13246. total = total + 1
  13247. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13248. cancelStock := models.DrugCancelStock{
  13249. OrderNumber: orderNumber,
  13250. OperaTime: operation_time,
  13251. OrgId: advice.UserOrgId,
  13252. Creater: creater,
  13253. Ctime: ctime,
  13254. Status: 1,
  13255. ReturnTime: advice.AdviceDate,
  13256. Dealer: info.Dealer,
  13257. Manufacturer: info.Manufacturer,
  13258. Type: 1,
  13259. }
  13260. service.AddSigleDrugCancelStock(&cancelStock)
  13261. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13262. dealer, _ := service.GetDealerById(info.Dealer)
  13263. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13264. cancelStockInfo := models.DrugCancelStockInfo{
  13265. OrderNumber: cancelInfo.OrderNumber,
  13266. CancelStockId: cancelInfo.ID,
  13267. DrugId: info.DrugId,
  13268. Count: info.Count,
  13269. Status: 1,
  13270. Ctime: ctime,
  13271. OrgId: advice.UserOrgId,
  13272. Type: 1,
  13273. Manufacturer: manufactureName.ManufacturerName,
  13274. Dealer: dealer.DealerName,
  13275. Total: 0,
  13276. RetailPrice: info.RetailPrice,
  13277. RetailTotalPrice: info.RetailTotalPrice,
  13278. Price: info.Price,
  13279. RegisterAccount: "",
  13280. Remark: info.Remark,
  13281. BatchNumber: info.BatchNumber,
  13282. MaxUnit: info.CountUnit,
  13283. ProductDate: info.ProductDate,
  13284. ExpiryDate: info.ExpiryDate,
  13285. BatchNumberId: info.WarehouseInfoId,
  13286. }
  13287. flow := models.DrugFlow{
  13288. WarehousingId: 0,
  13289. DrugId: info.DrugId,
  13290. Number: "",
  13291. BatchNumber: info.BatchNumber,
  13292. Count: info.Count,
  13293. UserOrgId: advice.UserOrgId,
  13294. PatientId: 0,
  13295. SystemTime: ctime,
  13296. ConsumableType: 4,
  13297. IsSys: 0,
  13298. WarehousingOrder: "",
  13299. WarehouseOutId: 0,
  13300. WarehouseOutOrderNumber: "",
  13301. IsEdit: 0,
  13302. CancelStockId: cancelStock.ID,
  13303. CancelOrderNumber: cancelStock.OrderNumber,
  13304. Manufacturer: info.Manufacturer,
  13305. Dealer: info.Dealer,
  13306. Creator: advice.AdviceDoctor,
  13307. UpdateCreator: 0,
  13308. Status: 1,
  13309. Ctime: time.Now().Unix(),
  13310. Mtime: 0,
  13311. Price: info.Price,
  13312. WarehousingDetailId: 0,
  13313. WarehouseOutDetailId: 0,
  13314. CancelOutDetailId: 0,
  13315. ExpireDate: info.ExpiryDate,
  13316. ProductDate: info.ProductDate,
  13317. MaxUnit: info.CountUnit,
  13318. MinUnit: "",
  13319. }
  13320. service.CreatedCancelStock(cancelStockInfo)
  13321. service.CreateDrugFlowOne(flow)
  13322. }
  13323. }
  13324. }
  13325. return err
  13326. }
  13327. func (this *HisApiController) DeleteNCDS() {
  13328. id, _ := this.GetInt64("id", 0)
  13329. if id > 0 {
  13330. service.DeletePsnNCDSRecordById(id)
  13331. this.ServeSuccessJSON(map[string]interface{}{
  13332. "msg": "删除成功",
  13333. })
  13334. } else {
  13335. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13336. return
  13337. }
  13338. }
  13339. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13340. id, _ := c.GetInt64("id")
  13341. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13342. c.ServeSuccessJSON(map[string]interface{}{
  13343. "advice": advice,
  13344. })
  13345. return
  13346. }
  13347. func (c *HisApiController) GetHisMonthChargePatientList() {
  13348. record_date := c.GetString("record_date")
  13349. start_time := c.GetString("start_time")
  13350. end_time := c.GetString("end_time")
  13351. timeLayout := "2006-01-02"
  13352. loc, _ := time.LoadLocation("Local")
  13353. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13354. if err != nil {
  13355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13356. return
  13357. }
  13358. if err != nil {
  13359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13360. return
  13361. }
  13362. recordDateTime := theTime.Unix()
  13363. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13364. if err != nil {
  13365. }
  13366. startRecordDateTime := startTime.Unix()
  13367. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13368. if err != nil {
  13369. }
  13370. endRecordDateTime := endTime.Unix()
  13371. adminInfo := c.GetAdminUserInfo()
  13372. var tempMonthChargePatients []*service.MonthChargePatients
  13373. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13374. for _, item := range tempPatients {
  13375. //过滤没有处方的
  13376. if len(item.HisPrescription) == 0 {
  13377. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13378. }
  13379. }
  13380. c.ServeSuccessJSON(map[string]interface{}{
  13381. "list": tempMonthChargePatients,
  13382. })
  13383. }
  13384. // PrescriptionDifference 医嘱数量差值结构体
  13385. type PrescriptionDrugDifference struct {
  13386. DrugID int64 //基础库药品id
  13387. ID int64 //医嘱id
  13388. Difference float64 //差值
  13389. Unit string //单位
  13390. }
  13391. type PrescriptionGoodDifference struct {
  13392. GoodID int64 //基础库项目耗材id
  13393. ID int64 //医嘱id
  13394. Difference int64 //差值
  13395. Unit string //单位
  13396. Type int64 //类型
  13397. }
  13398. type EditCustomData struct {
  13399. adviceList []*models.HisDoctorAdviceInfo
  13400. projectList []*models.HisPrescriptionProject
  13401. }
  13402. type SrcCustomData struct {
  13403. adviceList []*models.HisDoctorAdviceInfo
  13404. projectList []*models.HisPrescriptionProject
  13405. }
  13406. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13407. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13408. differences := make([]*PrescriptionDrugDifference, 0)
  13409. // 创建一个 map 来存储第一个切片中的药品信息
  13410. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13411. for _, advice := range firstPrescription {
  13412. firstMap[advice.DrugId] = advice
  13413. }
  13414. // 遍历第二个切片中的药品信息,并比较数量差值
  13415. for _, advice := range secondPrescription {
  13416. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13417. diff := &PrescriptionDrugDifference{
  13418. DrugID: advice.DrugId,
  13419. ID: firstAdvice.ID,
  13420. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13421. Unit: firstAdvice.PrescribingNumberUnit,
  13422. }
  13423. differences = append(differences, diff)
  13424. }
  13425. }
  13426. return differences
  13427. }
  13428. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13429. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13430. differences := make([]*PrescriptionGoodDifference, 0)
  13431. // 创建一个 map 来存储第一个切片中的耗材信息
  13432. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13433. for _, good := range firstPrescription {
  13434. firstMap[good.ProjectId] = good
  13435. }
  13436. // 遍历第二个切片中的耗材信息,并比较数量差值
  13437. for _, good := range secondPrescription {
  13438. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13439. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13440. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13441. diff := &PrescriptionGoodDifference{
  13442. GoodID: good.ProjectId,
  13443. ID: firstGood.ID,
  13444. Difference: count - firstCount,
  13445. Unit: firstGood.Unit,
  13446. Type: firstGood.Type,
  13447. }
  13448. differences = append(differences, diff)
  13449. }
  13450. }
  13451. return differences
  13452. }
  13453. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13454. var adviceList []*models.HisDoctorAdviceInfo
  13455. var projectList []*models.HisPrescriptionProject
  13456. var advice_ids []int64
  13457. var project_ids []int64
  13458. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13459. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13460. //var tempPrescription *models.HisPrescriptionProjectscription
  13461. if len(prescriptions) > 0 {
  13462. for _, item := range prescriptions {
  13463. items := item.(map[string]interface{})
  13464. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13465. advices := items["advices"].([]interface{})
  13466. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13467. groupNo := int64(0)
  13468. ctime := time.Now().Unix()
  13469. mtime := ctime
  13470. if len(advices) > 0 {
  13471. for _, advice := range advices {
  13472. var s models.HisDoctorAdviceInfo
  13473. s.AdviceType = 2
  13474. s.StopState = 2
  13475. s.ExecutionState = 2
  13476. s.Status = 1
  13477. s.Groupno = groupNo
  13478. s.CreatedTime = ctime
  13479. s.UpdatedTime = mtime
  13480. s.IsSettle = 2
  13481. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13482. //存储切片中
  13483. if s.ID > 0 {
  13484. advice_ids = append(advice_ids, s.ID)
  13485. adviceList = append(adviceList, &s)
  13486. }
  13487. }
  13488. }
  13489. }
  13490. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13491. projects := items["project"].([]interface{})
  13492. if len(projects) > 0 {
  13493. for _, project := range projects {
  13494. var p models.HisPrescriptionProject
  13495. p.Ctime = time.Now().Unix()
  13496. p.Mtime = time.Now().Unix()
  13497. p.Status = 1
  13498. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13499. if p.ID > 0 {
  13500. project_ids = append(project_ids, p.ID)
  13501. projectList = append(projectList, &p)
  13502. }
  13503. }
  13504. }
  13505. }
  13506. }
  13507. }
  13508. }
  13509. editCustomData.projectList = projectList
  13510. editCustomData.adviceList = adviceList
  13511. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13512. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13513. srcCustomData.adviceList = list
  13514. srcCustomData.projectList = list2
  13515. return
  13516. }
  13517. func (c *HisApiController) GetAllGoodInforList() {
  13518. orgId := c.GetAdminUserInfo().CurrentOrgId
  13519. goodList, _ := service.GetAllGoodList(orgId)
  13520. c.ServeSuccessJSON(map[string]interface{}{
  13521. "goodList": goodList,
  13522. })
  13523. return
  13524. }
  13525. func (this *HisApiController) SaveGoodList() {
  13526. project_name := this.GetString("project_name")
  13527. sort, _ := this.GetInt64("sort")
  13528. orgId := this.GetAdminUserInfo().CurrentOrgId
  13529. dataBody := make(map[string]interface{}, 0)
  13530. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13531. if err != nil {
  13532. utils.ErrorLog(err.Error())
  13533. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13534. return
  13535. }
  13536. goodTeam := models.XtGoodTeam{
  13537. ProjectName: project_name,
  13538. Sort: sort,
  13539. UserOrgId: orgId,
  13540. Status: 1,
  13541. Ctime: time.Now().Unix(),
  13542. Mtime: time.Now().Unix(),
  13543. }
  13544. service.CreateGoodTeam(goodTeam)
  13545. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13546. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13547. infos, _ := dataBody["info"].([]interface{})
  13548. if len(infos) > 0 {
  13549. for _, item := range infos {
  13550. items := item.(map[string]interface{})
  13551. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13552. utils.ErrorLog("good_id")
  13553. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13554. return
  13555. }
  13556. good_id := int64(items["good_id"].(float64))
  13557. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13558. utils.ErrorLog("number")
  13559. }
  13560. number := int64(items["number"].(float64))
  13561. xtGoodTeamList := models.XtGoodTeamList{
  13562. GoodId: good_id,
  13563. Count: number,
  13564. TeamId: lastGoodTeam.ID,
  13565. UserOrgId: orgId,
  13566. Status: 1,
  13567. Ctime: time.Now().Unix(),
  13568. Mtime: time.Now().Unix(),
  13569. }
  13570. service.CreateGoodList(xtGoodTeamList)
  13571. }
  13572. this.ServeSuccessJSON(map[string]interface{}{
  13573. "lastGoodTeam": lastGoodTeam,
  13574. })
  13575. }
  13576. }
  13577. return
  13578. }
  13579. func (this *HisApiController) GetGoodList() {
  13580. orgId := this.GetAdminUserInfo().CurrentOrgId
  13581. limit, _ := this.GetInt64("limit")
  13582. page, _ := this.GetInt64("page")
  13583. keyword := this.GetString("keyword")
  13584. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13585. this.ServeSuccessJSON(map[string]interface{}{
  13586. "list": list,
  13587. "total": total,
  13588. })
  13589. }
  13590. func (this *HisApiController) GetGoodNameDetail() {
  13591. id, _ := this.GetInt64("id")
  13592. orgId := this.GetAdminUserInfo().CurrentOrgId
  13593. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13594. goodList, _ := service.GetAllGoodList(orgId)
  13595. this.ServeSuccessJSON(map[string]interface{}{
  13596. "goodNameDetail": goodNameDetail,
  13597. "goodList": goodList,
  13598. })
  13599. }
  13600. func (this *HisApiController) UpdateGoodList() {
  13601. project_name := this.GetString("project_name")
  13602. sort, _ := this.GetInt64("sort")
  13603. id, _ := this.GetInt64("id")
  13604. orgId := this.GetAdminUserInfo().CurrentOrgId
  13605. dataBody := make(map[string]interface{}, 0)
  13606. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13607. if err != nil {
  13608. utils.ErrorLog(err.Error())
  13609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13610. return
  13611. }
  13612. goodTeam := models.XtGoodTeam{
  13613. ProjectName: project_name,
  13614. Sort: sort,
  13615. UserOrgId: orgId,
  13616. Status: 1,
  13617. Ctime: time.Now().Unix(),
  13618. Mtime: time.Now().Unix(),
  13619. ID: id,
  13620. }
  13621. service.SaveGoodTeam(goodTeam)
  13622. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13623. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13624. infos, _ := dataBody["info"].([]interface{})
  13625. if len(infos) > 0 {
  13626. for _, item := range infos {
  13627. items := item.(map[string]interface{})
  13628. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13629. utils.ErrorLog("good_id")
  13630. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13631. return
  13632. }
  13633. good_id := int64(items["good_id"].(float64))
  13634. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13635. utils.ErrorLog("id")
  13636. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13637. return
  13638. }
  13639. id := int64(items["id"].(float64))
  13640. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13641. utils.ErrorLog("number")
  13642. }
  13643. number := int64(items["number"].(float64))
  13644. xtGoodTeamList := models.XtGoodTeamList{
  13645. ID: id,
  13646. GoodId: good_id,
  13647. Count: number,
  13648. TeamId: lastGoodTeam.ID,
  13649. UserOrgId: orgId,
  13650. Status: 1,
  13651. Ctime: time.Now().Unix(),
  13652. Mtime: time.Now().Unix(),
  13653. }
  13654. service.SaveGoodList(xtGoodTeamList)
  13655. }
  13656. this.ServeSuccessJSON(map[string]interface{}{
  13657. "lastGoodTeam": lastGoodTeam,
  13658. })
  13659. }
  13660. }
  13661. return
  13662. }
  13663. func (this *HisApiController) DeleteGoodTeam() {
  13664. id, _ := this.GetInt64("id")
  13665. team, _ := service.DeleteGoodTeam(id)
  13666. this.ServeSuccessJSON(map[string]interface{}{
  13667. "team": team,
  13668. })
  13669. }
  13670. func (this *HisApiController) DeleteGood() {
  13671. id, _ := this.GetInt64("id")
  13672. good, _ := service.DeleteGood(id)
  13673. this.ServeSuccessJSON(map[string]interface{}{
  13674. "good": good,
  13675. })
  13676. }