his_api_controller.go 588KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165
  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. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3149. groupNo := int64(0)
  3150. if len(advices) > 0 {
  3151. for _, advice := range advices {
  3152. tx := db.Begin()
  3153. // 在函数结束时处理事务回滚
  3154. defer func() {
  3155. if r := recover(); r != nil {
  3156. tx.Rollback()
  3157. }
  3158. }()
  3159. var s models.HisDoctorAdviceInfo
  3160. s.PrescriptionId = tempPrescription.ID
  3161. s.AdviceType = 2
  3162. s.AdviceDoctor = doctor_id
  3163. s.StopState = 2
  3164. s.ExecutionState = 2
  3165. s.AdviceDate = theTime3.Unix()
  3166. s.Status = 1
  3167. s.UserOrgId = adminInfo.CurrentOrgId
  3168. s.RecordDate = theTime3.Unix()
  3169. s.StartTime = tempPrescription.PreTime
  3170. s.Groupno = groupNo
  3171. s.PatientId = patient_id
  3172. s.HisPatientId = his_patient_id
  3173. s.StartTime = pTime
  3174. s.IsSettle = 2
  3175. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3176. if errcode > 0 {
  3177. c.ServeFailJSONWithSGJErrorCode(errcode)
  3178. return
  3179. }
  3180. s.StartTime = pTime
  3181. var total_count int64 //处方总库存
  3182. //查询改药品信息
  3183. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3184. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3185. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3186. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3187. total_count += prescribingNumberSeven * medical.MinNumber
  3188. }
  3189. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3190. total_count += prescribingNumberSeven
  3191. }
  3192. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3193. total_count += prescribingNumberSeven
  3194. }
  3195. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3196. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3197. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3198. if s.Price != lastWarehouse.RetailPrice {
  3199. s.Price = lastWarehouse.RetailPrice
  3200. }
  3201. if s.Price == 0 {
  3202. if lastWarehouse.ID == 0 {
  3203. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3204. s.Price = lastWarehouseTwo.RetailPrice
  3205. }
  3206. }
  3207. }
  3208. //查询保存处方出库开关是否打开
  3209. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3210. if s.PatientId != 30038 {
  3211. if drugOutConfig.IsOpen == 1 {
  3212. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3213. // 查询该药品最后一次出库记录
  3214. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3215. var is_user_total int64
  3216. var no_user_total int64
  3217. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3218. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3219. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3220. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3221. }
  3222. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3223. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3224. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3225. no_user_total += prescribingNumberSevenTy
  3226. }
  3227. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3228. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3229. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3230. no_user_total += prescribingNumberSevenTy
  3231. }
  3232. if len(druginfo) > 0 {
  3233. for _, it := range druginfo {
  3234. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3235. it.Count = it.Count * drug.MinNumber
  3236. is_user_total += it.Count
  3237. }
  3238. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3239. is_user_total += it.Count
  3240. }
  3241. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3242. is_user_total += it.Count
  3243. }
  3244. }
  3245. }
  3246. //fmt.Println("药品名称----------------------", drug.DrugName)
  3247. //fmt.Println("药品名称----------------------", drug.IsUse)
  3248. //fmt.Println("is_user_total-------------------------", is_user_total)
  3249. //fmt.Println("no_user_total-------------------------", no_user_total)
  3250. if is_user_total != no_user_total {
  3251. //出库
  3252. if drug.IsUse == 2 {
  3253. creater := adminInfo.AdminUser.Id
  3254. newadviceInfo := &models.HisDoctorAdviceInfo{
  3255. ID: s.ID,
  3256. UserOrgId: s.UserOrgId,
  3257. PatientId: s.PatientId,
  3258. HisPatientId: s.HisPatientId,
  3259. AdviceType: s.AdviceType,
  3260. AdviceDate: s.AdviceDate,
  3261. StartTime: s.StartTime,
  3262. AdviceName: s.AdviceName,
  3263. AdviceDesc: s.AdviceDesc,
  3264. ReminderDate: s.ReminderDate,
  3265. SingleDose: s.SingleDose,
  3266. SingleDoseUnit: s.SingleDoseUnit,
  3267. PrescribingNumber: s.PrescribingNumber,
  3268. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3269. DeliveryWay: s.DeliveryWay,
  3270. ExecutionFrequency: s.ExecutionFrequency,
  3271. AdviceDoctor: s.AdviceDoctor,
  3272. Status: s.Status,
  3273. CreatedTime: s.CreatedTime,
  3274. UpdatedTime: s.UpdatedTime,
  3275. AdviceAffirm: s.AdviceAffirm,
  3276. Remark: s.Remark,
  3277. StopTime: s.StopTime,
  3278. StopReason: s.StopReason,
  3279. StopDoctor: s.StopDoctor,
  3280. StopState: s.StopState,
  3281. ParentId: s.ParentId,
  3282. ExecutionTime: s.ExecutionTime,
  3283. ExecutionStaff: s.ExecutionStaff,
  3284. ExecutionState: s.ExecutionState,
  3285. Checker: s.Checker,
  3286. RecordDate: s.RecordDate,
  3287. DialysisOrderId: s.DialysisOrderId,
  3288. CheckTime: s.CheckTime,
  3289. CheckState: s.CheckState,
  3290. DrugSpec: s.DrugSpec,
  3291. DrugSpecUnit: s.DrugSpecUnit,
  3292. Groupno: s.Groupno,
  3293. RemindType: s.RemindType,
  3294. FrequencyType: s.FrequencyType,
  3295. DayCount: s.DayCount,
  3296. WeekDay: s.WeekDay,
  3297. TemplateId: s.TemplateId,
  3298. Modifier: s.Modifier,
  3299. DrugId: s.DrugId,
  3300. Price: s.Price,
  3301. PrescriptionId: s.PrescriptionId,
  3302. MedListCodg: s.MedListCodg,
  3303. FeedetlSn: s.FeedetlSn,
  3304. Day: s.DayCount,
  3305. ChildDoctorAdvice: nil,
  3306. Drug: models.Drug{},
  3307. Diagnosis: s.Diagnosis,
  3308. Way: s.Way,
  3309. HospApprFlag: s.HospApprFlag,
  3310. LmtUsedFlag: s.LmtUsedFlag,
  3311. HisOrderInfo: models.HisOrderInfo{},
  3312. IsMedicine: s.IsMedicine,
  3313. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3314. Child: nil,
  3315. IsSettle: s.IsSettle,
  3316. IsMobile: s.IsMobile,
  3317. IsSelfDrug: s.IsSelfDrug,
  3318. DrugWayCount: s.DrugWayCount,
  3319. }
  3320. var history_count int64
  3321. var local_count int64
  3322. //查找已经开过的医嘱信息
  3323. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3324. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3325. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3326. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3327. local_count += prescribingNumberSevenTy * drug.MinNumber
  3328. }
  3329. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3330. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3331. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3332. local_count += prescribingNumberSevenTy
  3333. }
  3334. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3335. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3336. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3337. local_count += prescribingNumberSevenTy
  3338. }
  3339. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3340. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3341. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3342. history_count += prescribingNumberSevenTy * drug.MinNumber
  3343. }
  3344. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3345. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3346. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3347. history_count += prescribingNumberSevenTy
  3348. }
  3349. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3350. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3351. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3352. history_count += prescribingNumberSevenTy
  3353. }
  3354. //如果当前出库数量大于历史出库数量则需要出库
  3355. if local_count > history_count {
  3356. //按最小单位出库
  3357. var cha_count = local_count - history_count
  3358. newadviceInfo.PrescribingNumber = float64(cha_count)
  3359. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3360. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3361. }
  3362. //如果当前出库数量小于历史出库数量则需要退库
  3363. if local_count < history_count {
  3364. var cha_count = history_count - local_count
  3365. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3366. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3367. }
  3368. if local_count == history_count {
  3369. if is_user_total == 0 {
  3370. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3371. }
  3372. }
  3373. }
  3374. //更新字典里面的库存
  3375. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3376. var sum_count int64
  3377. for _, its := range stockInfo {
  3378. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3379. if its.MaxUnit == baseDrug.MaxUnit {
  3380. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3381. }
  3382. sum_count += its.StockMaxNumber + its.StockMinNumber
  3383. }
  3384. //更新基础库存
  3385. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3386. //剩余库存
  3387. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3388. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3389. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3390. //创建医嘱
  3391. service.CreateHisDoctorAdviceOne(&s, tx)
  3392. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3393. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3394. if len(outInfoTwo) > 0 {
  3395. for _, item := range outInfoTwo {
  3396. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3397. }
  3398. }
  3399. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3400. if len(drugAutoDetail) > 0 {
  3401. for _, item := range drugAutoDetail {
  3402. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3403. }
  3404. }
  3405. }
  3406. }
  3407. }
  3408. //记录日志
  3409. byterequest, _ := json.Marshal(s)
  3410. adviceLog := models.XtDoctorAdviceLog{
  3411. UserOrgId: s.UserOrgId,
  3412. PatientId: s.PatientId,
  3413. AdminUserId: adminInfo.AdminUser.Id,
  3414. Module: 1,
  3415. ErrLog: string(byterequest),
  3416. Status: 1,
  3417. Ctime: time.Now().Unix(),
  3418. Mtime: 0,
  3419. Source: "电脑端新建his医嘱",
  3420. RecordDate: s.AdviceDate,
  3421. }
  3422. service.CreateDoctorAdviceLog(adviceLog)
  3423. //存储切片中
  3424. adviceList = append(adviceList, s)
  3425. redis := service.RedisClient()
  3426. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3427. redis.Set(key, "", time.Second)
  3428. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3429. redis.Set(keyOne, "", time.Second)
  3430. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3431. redis.Set(keySeven, "", time.Second)
  3432. var randNum int
  3433. randNum = rand.Intn(10000) + 1000
  3434. timestamp := time.Now().Unix()
  3435. tempTime := time.Unix(timestamp, 0)
  3436. timeFormat := tempTime.Format("20060102150405")
  3437. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3438. if s.UserOrgId != 10206 {
  3439. if s.ID == 0 {
  3440. //查询改药品是否已经停用
  3441. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3442. if base.ID > 0 {
  3443. tx.Rollback()
  3444. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3445. return
  3446. }
  3447. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3448. if drugMedical.SumCount == 0 {
  3449. tx.Rollback()
  3450. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3451. return
  3452. }
  3453. }
  3454. if s.ID > 0 {
  3455. //查询改药品是否已经停用
  3456. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3457. if base.ID > 0 {
  3458. tx.Rollback()
  3459. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3460. return
  3461. }
  3462. }
  3463. }
  3464. //赤峰
  3465. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3466. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3467. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3468. if info.RetailPrice > 0 {
  3469. if s.DeliveryWay == "口服" {
  3470. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3471. s.Price = drug.RetailPrice
  3472. }
  3473. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3474. s.Price = info.RetailPrice
  3475. }
  3476. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3477. s.Price = info.RetailPrice
  3478. }
  3479. }
  3480. }
  3481. }
  3482. service.CreateHisDoctorAdviceOne(&s, tx)
  3483. tx.Commit()
  3484. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3485. redis.Set(keySix, "", time.Second)
  3486. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3487. redis.Set(keyFive, "", time.Second)
  3488. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3489. redis.Set(keyEight, "", time.Second)
  3490. defer redis.Close()
  3491. }
  3492. }
  3493. }
  3494. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3495. projects := items["project"].([]interface{})
  3496. if len(projects) > 0 {
  3497. for _, project := range projects {
  3498. tx := db.Begin()
  3499. // 在函数结束时处理事务回滚
  3500. defer func() {
  3501. if r := recover(); r != nil {
  3502. tx.Rollback()
  3503. }
  3504. }()
  3505. var p models.HisPrescriptionProject
  3506. p.PrescriptionId = tempPrescription.ID
  3507. p.PatientId = patient_id
  3508. p.RecordDate = theTime3.Unix()
  3509. p.Doctor = doctor_id
  3510. p.UserOrgId = adminInfo.CurrentOrgId
  3511. p.HisPatientId = his_patient_id
  3512. p.Status = 1
  3513. p.StartTime = pTime
  3514. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3515. if errcode > 0 {
  3516. tx.Rollback()
  3517. c.ServeFailJSONWithSGJErrorCode(errcode)
  3518. return
  3519. }
  3520. if p.ID == 0 {
  3521. p.IsOut = 2
  3522. }
  3523. if p.ID > 0 {
  3524. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3525. p.IsOut = projectDetail.IsOut
  3526. }
  3527. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3528. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3529. if p.Type == 3 {
  3530. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3531. if p.Price != lastWarehouse.PackingPrice {
  3532. p.Price = lastWarehouse.PackingPrice
  3533. }
  3534. if p.Price == 0 {
  3535. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3536. p.Price = lastWarehouseTwo.PackingPrice
  3537. }
  3538. if p.Unit == "" {
  3539. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3540. p.Unit = goodInfoOne.PackingUnit
  3541. }
  3542. }
  3543. }
  3544. if adminInfo.CurrentOrgId != 10206 {
  3545. if p.Type == 3 {
  3546. if p.ID == 0 {
  3547. //查询该耗材是否停用
  3548. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3549. //表示该耗材已经停用,不能保存
  3550. if goodInfoSeven.ID == 0 {
  3551. tx.Rollback()
  3552. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3553. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3554. return
  3555. }
  3556. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3557. if goodInfoOne.SumCount == 0 {
  3558. tx.Rollback()
  3559. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3560. return
  3561. }
  3562. }
  3563. if p.ID > 0 {
  3564. //查询该耗材是否停用
  3565. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3566. //表示该耗材已经停用,不能保存
  3567. if goodInfoSeven.ID == 0 {
  3568. tx.Rollback()
  3569. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3570. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3571. return
  3572. }
  3573. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3574. if goodInfoOne.SumCount == 0 {
  3575. tx.Rollback()
  3576. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3577. return
  3578. }
  3579. }
  3580. }
  3581. }
  3582. //查询保存耗材出库开关是否打开
  3583. if p.PatientId != 30038 {
  3584. //用机构ID区分
  3585. if adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10164 {
  3586. if goodOutConfig.IsOpen == 1 {
  3587. //耗材出库
  3588. if p.Type == 3 {
  3589. //对比当前数据和历史出库数据
  3590. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3591. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3592. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3593. //如果当前处方数量大于历史数据,则需要出库
  3594. if nowCount > historyCount {
  3595. var cha_count int64
  3596. cha_count = nowCount - historyCount
  3597. timeStr := time.Now().Format("2006-01-02")
  3598. timeArr := strings.Split(timeStr, "-")
  3599. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3600. total = total + 1
  3601. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3602. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3603. number = number + total
  3604. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3605. operation_time := time.Now().Unix()
  3606. creater := c.GetAdminUserInfo().AdminUser.Id
  3607. recordDateStr := time.Now().Format("2006-01-02")
  3608. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3609. nowtime := recordDate.Unix()
  3610. warehouseOut := models.WarehouseOut{
  3611. WarehouseOutOrderNumber: warehousing_out_order,
  3612. OperationTime: operation_time,
  3613. OrgId: adminInfo.CurrentOrgId,
  3614. Creater: creater,
  3615. Ctime: time.Now().Unix(),
  3616. Status: 1,
  3617. WarehouseOutTime: nowtime,
  3618. Type: 1,
  3619. StorehouseId: storeConfig.StorehouseOutInfo,
  3620. IsCheck: 1,
  3621. IsSys: 1,
  3622. }
  3623. //查询是否生成出库单
  3624. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3625. if out.ID == 0 {
  3626. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3627. }
  3628. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3629. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3630. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3631. dialyPrepareOne := models.DialysisBeforePrepare{
  3632. GoodTypeId: goodObj.GoodTypeId,
  3633. GoodId: p.ProjectId,
  3634. PatientId: p.PatientId,
  3635. RecordDate: p.RecordDate,
  3636. UserOrgId: adminInfo.CurrentOrgId,
  3637. Count: cha_count,
  3638. Ctime: time.Now().Unix(),
  3639. Creater: creater,
  3640. Status: 1,
  3641. StorehouseId: houseConfig.StorehouseOutInfo,
  3642. ProjectId: p.ID,
  3643. }
  3644. //出库
  3645. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3646. }
  3647. //如果当前处方数量小于历史数据,怎需要退库
  3648. if nowCount < historyCount {
  3649. var cha_count int64
  3650. cha_count = historyCount - nowCount
  3651. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3652. creater := c.GetAdminUserInfo().AdminUser.Id
  3653. newPrescriptionProject := &models.HisPrescriptionProject{
  3654. ID: p.ID,
  3655. ProjectId: p.ProjectId,
  3656. Price: p.Price,
  3657. UserOrgId: p.UserOrgId,
  3658. Status: 1,
  3659. Ctime: time.Now().Unix(),
  3660. Mtime: time.Now().Unix(),
  3661. PatientId: p.PatientId,
  3662. HisPatientId: p.HisPatientId,
  3663. RecordDate: p.RecordDate,
  3664. PrescriptionId: p.PrescriptionId,
  3665. Count: p.Count,
  3666. FeedetlSn: p.FeedetlSn,
  3667. MedListCodg: p.MedListCodg,
  3668. SingleDose: p.SingleDose,
  3669. DeliveryWay: p.DeliveryWay,
  3670. ExecutionFrequency: p.ExecutionFrequency,
  3671. Day: p.Day,
  3672. HisProject: models.HisProject{},
  3673. GoodInfo: models.GoodInfo{},
  3674. Remark: p.Remark,
  3675. Unit: p.Unit,
  3676. Type: p.Type,
  3677. Doctor: p.Doctor,
  3678. ExecutionTime: p.ExecutionTime,
  3679. ExecutionStaff: p.ExecutionStaff,
  3680. ExecutionState: p.ExecutionState,
  3681. CheckTime: p.CheckTime,
  3682. CheckState: p.CheckState,
  3683. Checker: p.Checker,
  3684. StartTime: p.StartTime,
  3685. TeamId: p.TeamId,
  3686. XtHisProjectTeam: models.XtHisProjectTeam{},
  3687. FrequencyType: p.FrequencyType,
  3688. DayCount: p.DayCount,
  3689. WeekDay: p.WeekDay,
  3690. IsCheckTeam: p.IsCheckTeam,
  3691. HisOrderInfo: models.HisOrderInfo{},
  3692. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3693. IsOut: p.IsOut,
  3694. YbSyncStatus: p.YbSyncStatus,
  3695. }
  3696. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3697. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3698. }
  3699. if nowCount == historyCount {
  3700. if historyCount == 0 {
  3701. recordDateStr := time.Now().Format("2006-01-02")
  3702. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3703. nowtime := recordDate.Unix()
  3704. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3705. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3706. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3707. creater := c.GetAdminUserInfo().AdminUser.Id
  3708. dialyPrepareOne := models.DialysisBeforePrepare{
  3709. GoodTypeId: goodObj.GoodTypeId,
  3710. GoodId: p.ProjectId,
  3711. PatientId: p.PatientId,
  3712. RecordDate: p.RecordDate,
  3713. UserOrgId: adminInfo.CurrentOrgId,
  3714. Count: nowCount,
  3715. Ctime: time.Now().Unix(),
  3716. Creater: creater,
  3717. Status: 1,
  3718. StorehouseId: houseConfig.StorehouseOutInfo,
  3719. ProjectId: p.ID,
  3720. }
  3721. //出库
  3722. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3723. }
  3724. }
  3725. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3726. //查询历史出库数据
  3727. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3728. var out_count_five int64
  3729. for _, item := range flowGood {
  3730. out_count_five += item.Count
  3731. }
  3732. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3733. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3734. if out_count_five != parseIntCount {
  3735. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3736. detail := models.AutomaticReduceDetail{
  3737. WarehouseOutId: 0,
  3738. WarehouseOutOrderNumber: "",
  3739. PatientId: p.PatientId,
  3740. Ctime: time.Now().Unix(),
  3741. Mtime: 0,
  3742. Status: 1,
  3743. RecordTime: p.RecordDate,
  3744. OrgId: p.UserOrgId,
  3745. GoodId: p.ProjectId,
  3746. GoodTypeId: 0,
  3747. Count: parseIntCount,
  3748. Type: 0,
  3749. ProjectId: lastHisProject.ID,
  3750. StorehouseId: 0,
  3751. }
  3752. service.CreateNewAutoDetail(detail, tx)
  3753. }
  3754. // //查询耗材最后一次出库记录
  3755. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3756. // //查询默认出库仓库库存
  3757. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3758. // if len(wareOut) > 0 {
  3759. //
  3760. // for _, it := range wareOut {
  3761. // //回退库存
  3762. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3763. //
  3764. // //删除出库记录
  3765. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3766. //
  3767. // }
  3768. // }
  3769. //
  3770. // timeStr := time.Now().Format("2006-01-02")
  3771. // timeArr := strings.Split(timeStr, "-")
  3772. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3773. //
  3774. // total = total + 1
  3775. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3776. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3777. // number = number + total
  3778. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3779. //
  3780. // operation_time := time.Now().Unix()
  3781. // creater := c.GetAdminUserInfo().AdminUser.Id
  3782. //
  3783. // recordDateStr := time.Now().Format("2006-01-02")
  3784. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3785. // nowtime := recordDate.Unix()
  3786. // warehouseOut := models.WarehouseOut{
  3787. // WarehouseOutOrderNumber: warehousing_out_order,
  3788. // OperationTime: operation_time,
  3789. // OrgId: adminInfo.CurrentOrgId,
  3790. // Creater: creater,
  3791. // Ctime: time.Now().Unix(),
  3792. // Status: 1,
  3793. // WarehouseOutTime: nowtime,
  3794. // Type: 1,
  3795. // StorehouseId: storeConfig.StorehouseOutInfo,
  3796. // IsCheck: 1,
  3797. // IsSys: 1,
  3798. // }
  3799. // //查询是否生成出库单
  3800. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3801. // if out.ID == 0 {
  3802. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3803. // }
  3804. //
  3805. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3806. //
  3807. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3808. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3809. //
  3810. // dialyPrepareOne := models.DialysisBeforePrepare{
  3811. // GoodTypeId: goodObj.GoodTypeId,
  3812. // GoodId: p.ProjectId,
  3813. // PatientId: p.PatientId,
  3814. // RecordDate: p.RecordDate,
  3815. // UserOrgId: adminInfo.CurrentOrgId,
  3816. // Count: parseIntCount,
  3817. // Ctime: time.Now().Unix(),
  3818. // Creater: creater,
  3819. // Status: 1,
  3820. // StorehouseId: houseConfig.StorehouseOutInfo,
  3821. // ProjectId: lastHisProject.ID,
  3822. // }
  3823. // //判断是否是零用耗材(非零用)
  3824. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3825. //
  3826. // //查询历史出库数据
  3827. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3828. // var out_count int64
  3829. // for _, item := range flowGood {
  3830. // out_count += item.Count
  3831. // }
  3832. // //如果历史数和当前数据不想等才进行退库出库
  3833. // if out_count != parseIntCount {
  3834. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3835. //
  3836. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3837. // detail := models.AutomaticReduceDetail{
  3838. // WarehouseOutId: 0,
  3839. // WarehouseOutOrderNumber: "",
  3840. // PatientId: p.PatientId,
  3841. // Ctime: time.Now().Unix(),
  3842. // Mtime: 0,
  3843. // Status: 1,
  3844. // RecordTime: p.RecordDate,
  3845. // OrgId: p.UserOrgId,
  3846. // GoodId: p.ProjectId,
  3847. // GoodTypeId: 0,
  3848. // Count: parseIntCount,
  3849. // Type: 0,
  3850. // ProjectId: lastHisProject.ID,
  3851. // StorehouseId: 0,
  3852. // }
  3853. //
  3854. // service.CreateNewAutoDetail(detail, tx)
  3855. //
  3856. // //查询剩余库存
  3857. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3858. // var sum_count int64
  3859. // for _, item := range goodList {
  3860. // sum_count += item.StockCount
  3861. // }
  3862. //
  3863. // //更新剩余库存
  3864. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3865. //
  3866. // //耗材
  3867. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3868. //
  3869. // }
  3870. // //判断是否是零用耗材(零用但是是出库耗材)
  3871. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3872. //
  3873. // //查询历史出库数据
  3874. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3875. // var out_count int64
  3876. // for _, item := range flowGood {
  3877. // out_count += item.Count
  3878. // }
  3879. // //如果历史数和当前数据不想等才进行退库出库
  3880. // if out_count != parseIntCount {
  3881. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3882. //
  3883. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3884. // detail := models.AutomaticReduceDetail{
  3885. // WarehouseOutId: 0,
  3886. // WarehouseOutOrderNumber: "",
  3887. // PatientId: p.PatientId,
  3888. // Ctime: time.Now().Unix(),
  3889. // Mtime: 0,
  3890. // Status: 1,
  3891. // RecordTime: p.RecordDate,
  3892. // OrgId: p.UserOrgId,
  3893. // GoodId: p.ProjectId,
  3894. // GoodTypeId: 0,
  3895. // Count: parseIntCount,
  3896. // Type: 0,
  3897. // ProjectId: p.ID,
  3898. // StorehouseId: 0,
  3899. // }
  3900. //
  3901. // service.CreateNewAutoDetail(detail, tx)
  3902. //
  3903. // //查询剩余库存
  3904. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3905. // var sum_count int64
  3906. // for _, item := range goodList {
  3907. // sum_count += item.StockCount
  3908. // }
  3909. //
  3910. // //更新剩余库存
  3911. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3912. //
  3913. // //耗材
  3914. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3915. // }
  3916. //
  3917. // }
  3918. //
  3919. // }
  3920. //
  3921. //}
  3922. //记录日志
  3923. byterequest, _ := json.Marshal(p)
  3924. adviceLog := models.XtDoctorAdviceLog{
  3925. UserOrgId: p.UserOrgId,
  3926. PatientId: p.PatientId,
  3927. AdminUserId: adminInfo.AdminUser.Id,
  3928. Module: 1,
  3929. ErrLog: string(byterequest),
  3930. Status: 1,
  3931. Ctime: time.Now().Unix(),
  3932. Mtime: 0,
  3933. Source: "电脑端新建his项目",
  3934. RecordDate: p.RecordDate,
  3935. }
  3936. service.CreateDoctorAdviceLog(adviceLog)
  3937. projectList = append(projectList, p)
  3938. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3939. //新增或者编辑项目,修改对应的标签数据
  3940. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3941. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3942. var label models.HisLabelPrintInfo
  3943. project, _ := service.GetProjectDetail(p.ProjectId)
  3944. if project.CostClassify == 3 { //类别为检验检查
  3945. if p.TeamId > 0 { //检验检查组套
  3946. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3947. if tempLabel.ID == 0 {
  3948. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3949. label.Number = tempPrescription.PrescriptionNumber
  3950. label.ProjectId = project.ID
  3951. label.Status = 1
  3952. label.IsPrint = 2
  3953. label.DoctorId = info.DoctorId
  3954. label.UserOrgId = p.UserOrgId
  3955. label.PatientId = patient_id
  3956. label.RecordDate = recordDateTime
  3957. label.Ctime = time.Now().Unix()
  3958. label.Mtime = time.Now().Unix()
  3959. label.ItemId = p.TeamId
  3960. label.FeedetlSn = p.FeedetlSn
  3961. label.PProjectId = p.ID
  3962. label.ProjectName = team.ProjectTeam
  3963. label.PatientName = patient.Name
  3964. service.CreateNewHisLabelRecord(&label, tx)
  3965. }
  3966. } else { //单条检验检查项目
  3967. label.Number = tempPrescription.PrescriptionNumber
  3968. label.ProjectId = project.ID
  3969. label.Status = 1
  3970. label.DoctorId = info.DoctorId
  3971. label.UserOrgId = p.UserOrgId
  3972. label.PatientId = patient_id
  3973. label.RecordDate = recordDateTime
  3974. label.IsPrint = 2
  3975. label.Ctime = time.Now().Unix()
  3976. label.Mtime = time.Now().Unix()
  3977. label.FeedetlSn = p.FeedetlSn
  3978. label.PProjectId = p.ID
  3979. label.ItemId = p.TeamId
  3980. label.ProjectName = project.ProjectName
  3981. label.PatientName = patient.Name
  3982. service.CreateNewHisLabelRecord(&label, tx)
  3983. }
  3984. }
  3985. }
  3986. }
  3987. }
  3988. }
  3989. }
  3990. if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  3991. //耗材出库
  3992. if p.Type == 3 {
  3993. //对比当前数据和历史出库数据
  3994. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3995. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3996. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3997. //如果当前处方数量大于历史数据,则需要出库
  3998. if nowCount > historyCount {
  3999. var cha_count int64
  4000. cha_count = nowCount - historyCount
  4001. timeStr := time.Now().Format("2006-01-02")
  4002. timeArr := strings.Split(timeStr, "-")
  4003. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4004. total = total + 1
  4005. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4006. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4007. number = number + total
  4008. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4009. operation_time := time.Now().Unix()
  4010. creater := c.GetAdminUserInfo().AdminUser.Id
  4011. recordDateStr := time.Now().Format("2006-01-02")
  4012. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4013. nowtime := recordDate.Unix()
  4014. warehouseOut := models.WarehouseOut{
  4015. WarehouseOutOrderNumber: warehousing_out_order,
  4016. OperationTime: operation_time,
  4017. OrgId: adminInfo.CurrentOrgId,
  4018. Creater: creater,
  4019. Ctime: time.Now().Unix(),
  4020. Status: 1,
  4021. WarehouseOutTime: nowtime,
  4022. Type: 1,
  4023. StorehouseId: storeConfig.StorehouseOutInfo,
  4024. IsCheck: 1,
  4025. IsSys: 1,
  4026. }
  4027. //查询是否生成出库单
  4028. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4029. if out.ID == 0 {
  4030. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4031. }
  4032. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4033. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4034. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4035. dialyPrepareOne := models.DialysisBeforePrepare{
  4036. GoodTypeId: goodObj.GoodTypeId,
  4037. GoodId: p.ProjectId,
  4038. PatientId: p.PatientId,
  4039. RecordDate: p.RecordDate,
  4040. UserOrgId: adminInfo.CurrentOrgId,
  4041. Count: cha_count,
  4042. Ctime: time.Now().Unix(),
  4043. Creater: creater,
  4044. Status: 1,
  4045. StorehouseId: houseConfig.StorehouseOutInfo,
  4046. ProjectId: p.ID,
  4047. }
  4048. //出库
  4049. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4050. }
  4051. //如果当前处方数量小于历史数据,怎需要退库
  4052. if nowCount < historyCount {
  4053. var cha_count int64
  4054. cha_count = historyCount - nowCount
  4055. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4056. creater := c.GetAdminUserInfo().AdminUser.Id
  4057. newPrescriptionProject := &models.HisPrescriptionProject{
  4058. ID: p.ID,
  4059. ProjectId: p.ProjectId,
  4060. Price: p.Price,
  4061. UserOrgId: p.UserOrgId,
  4062. Status: 1,
  4063. Ctime: time.Now().Unix(),
  4064. Mtime: time.Now().Unix(),
  4065. PatientId: p.PatientId,
  4066. HisPatientId: p.HisPatientId,
  4067. RecordDate: p.RecordDate,
  4068. PrescriptionId: p.PrescriptionId,
  4069. Count: p.Count,
  4070. FeedetlSn: p.FeedetlSn,
  4071. MedListCodg: p.MedListCodg,
  4072. SingleDose: p.SingleDose,
  4073. DeliveryWay: p.DeliveryWay,
  4074. ExecutionFrequency: p.ExecutionFrequency,
  4075. Day: p.Day,
  4076. HisProject: models.HisProject{},
  4077. GoodInfo: models.GoodInfo{},
  4078. Remark: p.Remark,
  4079. Unit: p.Unit,
  4080. Type: p.Type,
  4081. Doctor: p.Doctor,
  4082. ExecutionTime: p.ExecutionTime,
  4083. ExecutionStaff: p.ExecutionStaff,
  4084. ExecutionState: p.ExecutionState,
  4085. CheckTime: p.CheckTime,
  4086. CheckState: p.CheckState,
  4087. Checker: p.Checker,
  4088. StartTime: p.StartTime,
  4089. TeamId: p.TeamId,
  4090. XtHisProjectTeam: models.XtHisProjectTeam{},
  4091. FrequencyType: p.FrequencyType,
  4092. DayCount: p.DayCount,
  4093. WeekDay: p.WeekDay,
  4094. IsCheckTeam: p.IsCheckTeam,
  4095. HisOrderInfo: models.HisOrderInfo{},
  4096. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4097. IsOut: p.IsOut,
  4098. YbSyncStatus: p.YbSyncStatus,
  4099. }
  4100. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4101. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4102. }
  4103. if nowCount == historyCount {
  4104. if historyCount == 0 {
  4105. recordDateStr := time.Now().Format("2006-01-02")
  4106. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4107. nowtime := recordDate.Unix()
  4108. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4109. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4110. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4111. creater := c.GetAdminUserInfo().AdminUser.Id
  4112. dialyPrepareOne := models.DialysisBeforePrepare{
  4113. GoodTypeId: goodObj.GoodTypeId,
  4114. GoodId: p.ProjectId,
  4115. PatientId: p.PatientId,
  4116. RecordDate: p.RecordDate,
  4117. UserOrgId: adminInfo.CurrentOrgId,
  4118. Count: nowCount,
  4119. Ctime: time.Now().Unix(),
  4120. Creater: creater,
  4121. Status: 1,
  4122. StorehouseId: houseConfig.StorehouseOutInfo,
  4123. ProjectId: p.ID,
  4124. }
  4125. //出库
  4126. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4127. }
  4128. }
  4129. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4130. //查询历史出库数据
  4131. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4132. var out_count_five int64
  4133. for _, item := range flowGood {
  4134. out_count_five += item.Count
  4135. }
  4136. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4137. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4138. if out_count_five != parseIntCount {
  4139. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4140. detail := models.AutomaticReduceDetail{
  4141. WarehouseOutId: 0,
  4142. WarehouseOutOrderNumber: "",
  4143. PatientId: p.PatientId,
  4144. Ctime: time.Now().Unix(),
  4145. Mtime: 0,
  4146. Status: 1,
  4147. RecordTime: p.RecordDate,
  4148. OrgId: p.UserOrgId,
  4149. GoodId: p.ProjectId,
  4150. GoodTypeId: 0,
  4151. Count: parseIntCount,
  4152. Type: 0,
  4153. ProjectId: lastHisProject.ID,
  4154. StorehouseId: 0,
  4155. }
  4156. service.CreateNewAutoDetail(detail, tx)
  4157. }
  4158. // //查询耗材最后一次出库记录
  4159. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4160. // //查询默认出库仓库库存
  4161. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4162. // if len(wareOut) > 0 {
  4163. //
  4164. // for _, it := range wareOut {
  4165. // //回退库存
  4166. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4167. //
  4168. // //删除出库记录
  4169. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4170. //
  4171. // }
  4172. // }
  4173. //
  4174. // timeStr := time.Now().Format("2006-01-02")
  4175. // timeArr := strings.Split(timeStr, "-")
  4176. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4177. //
  4178. // total = total + 1
  4179. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4180. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4181. // number = number + total
  4182. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4183. //
  4184. // operation_time := time.Now().Unix()
  4185. // creater := c.GetAdminUserInfo().AdminUser.Id
  4186. //
  4187. // recordDateStr := time.Now().Format("2006-01-02")
  4188. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4189. // nowtime := recordDate.Unix()
  4190. // warehouseOut := models.WarehouseOut{
  4191. // WarehouseOutOrderNumber: warehousing_out_order,
  4192. // OperationTime: operation_time,
  4193. // OrgId: adminInfo.CurrentOrgId,
  4194. // Creater: creater,
  4195. // Ctime: time.Now().Unix(),
  4196. // Status: 1,
  4197. // WarehouseOutTime: nowtime,
  4198. // Type: 1,
  4199. // StorehouseId: storeConfig.StorehouseOutInfo,
  4200. // IsCheck: 1,
  4201. // IsSys: 1,
  4202. // }
  4203. // //查询是否生成出库单
  4204. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4205. // if out.ID == 0 {
  4206. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4207. // }
  4208. //
  4209. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4210. //
  4211. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4212. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4213. //
  4214. // dialyPrepareOne := models.DialysisBeforePrepare{
  4215. // GoodTypeId: goodObj.GoodTypeId,
  4216. // GoodId: p.ProjectId,
  4217. // PatientId: p.PatientId,
  4218. // RecordDate: p.RecordDate,
  4219. // UserOrgId: adminInfo.CurrentOrgId,
  4220. // Count: parseIntCount,
  4221. // Ctime: time.Now().Unix(),
  4222. // Creater: creater,
  4223. // Status: 1,
  4224. // StorehouseId: houseConfig.StorehouseOutInfo,
  4225. // ProjectId: lastHisProject.ID,
  4226. // }
  4227. // //判断是否是零用耗材(非零用)
  4228. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4229. //
  4230. // //查询历史出库数据
  4231. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4232. // var out_count int64
  4233. // for _, item := range flowGood {
  4234. // out_count += item.Count
  4235. // }
  4236. // //如果历史数和当前数据不想等才进行退库出库
  4237. // if out_count != parseIntCount {
  4238. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4239. //
  4240. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4241. // detail := models.AutomaticReduceDetail{
  4242. // WarehouseOutId: 0,
  4243. // WarehouseOutOrderNumber: "",
  4244. // PatientId: p.PatientId,
  4245. // Ctime: time.Now().Unix(),
  4246. // Mtime: 0,
  4247. // Status: 1,
  4248. // RecordTime: p.RecordDate,
  4249. // OrgId: p.UserOrgId,
  4250. // GoodId: p.ProjectId,
  4251. // GoodTypeId: 0,
  4252. // Count: parseIntCount,
  4253. // Type: 0,
  4254. // ProjectId: lastHisProject.ID,
  4255. // StorehouseId: 0,
  4256. // }
  4257. //
  4258. // service.CreateNewAutoDetail(detail, tx)
  4259. //
  4260. // //查询剩余库存
  4261. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4262. // var sum_count int64
  4263. // for _, item := range goodList {
  4264. // sum_count += item.StockCount
  4265. // }
  4266. //
  4267. // //更新剩余库存
  4268. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4269. //
  4270. // //耗材
  4271. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4272. //
  4273. // }
  4274. // //判断是否是零用耗材(零用但是是出库耗材)
  4275. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4276. //
  4277. // //查询历史出库数据
  4278. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4279. // var out_count int64
  4280. // for _, item := range flowGood {
  4281. // out_count += item.Count
  4282. // }
  4283. // //如果历史数和当前数据不想等才进行退库出库
  4284. // if out_count != parseIntCount {
  4285. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4286. //
  4287. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4288. // detail := models.AutomaticReduceDetail{
  4289. // WarehouseOutId: 0,
  4290. // WarehouseOutOrderNumber: "",
  4291. // PatientId: p.PatientId,
  4292. // Ctime: time.Now().Unix(),
  4293. // Mtime: 0,
  4294. // Status: 1,
  4295. // RecordTime: p.RecordDate,
  4296. // OrgId: p.UserOrgId,
  4297. // GoodId: p.ProjectId,
  4298. // GoodTypeId: 0,
  4299. // Count: parseIntCount,
  4300. // Type: 0,
  4301. // ProjectId: p.ID,
  4302. // StorehouseId: 0,
  4303. // }
  4304. //
  4305. // service.CreateNewAutoDetail(detail, tx)
  4306. //
  4307. // //查询剩余库存
  4308. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4309. // var sum_count int64
  4310. // for _, item := range goodList {
  4311. // sum_count += item.StockCount
  4312. // }
  4313. //
  4314. // //更新剩余库存
  4315. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4316. //
  4317. // //耗材
  4318. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4319. // }
  4320. //
  4321. // }
  4322. //
  4323. // }
  4324. //
  4325. //}
  4326. //记录日志
  4327. byterequest, _ := json.Marshal(p)
  4328. adviceLog := models.XtDoctorAdviceLog{
  4329. UserOrgId: p.UserOrgId,
  4330. PatientId: p.PatientId,
  4331. AdminUserId: adminInfo.AdminUser.Id,
  4332. Module: 1,
  4333. ErrLog: string(byterequest),
  4334. Status: 1,
  4335. Ctime: time.Now().Unix(),
  4336. Mtime: 0,
  4337. Source: "电脑端新建his项目",
  4338. RecordDate: p.RecordDate,
  4339. }
  4340. service.CreateDoctorAdviceLog(adviceLog)
  4341. projectList = append(projectList, p)
  4342. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4343. //新增或者编辑项目,修改对应的标签数据
  4344. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4345. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4346. var label models.HisLabelPrintInfo
  4347. project, _ := service.GetProjectDetail(p.ProjectId)
  4348. if project.CostClassify == 3 { //类别为检验检查
  4349. if p.TeamId > 0 { //检验检查组套
  4350. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4351. if tempLabel.ID == 0 {
  4352. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4353. label.Number = tempPrescription.PrescriptionNumber
  4354. label.ProjectId = project.ID
  4355. label.Status = 1
  4356. label.IsPrint = 2
  4357. label.DoctorId = info.DoctorId
  4358. label.UserOrgId = p.UserOrgId
  4359. label.PatientId = patient_id
  4360. label.RecordDate = recordDateTime
  4361. label.Ctime = time.Now().Unix()
  4362. label.Mtime = time.Now().Unix()
  4363. label.ItemId = p.TeamId
  4364. label.FeedetlSn = p.FeedetlSn
  4365. label.PProjectId = p.ID
  4366. label.ProjectName = team.ProjectTeam
  4367. label.PatientName = patient.Name
  4368. service.CreateNewHisLabelRecord(&label, tx)
  4369. }
  4370. } else { //单条检验检查项目
  4371. label.Number = tempPrescription.PrescriptionNumber
  4372. label.ProjectId = project.ID
  4373. label.Status = 1
  4374. label.DoctorId = info.DoctorId
  4375. label.UserOrgId = p.UserOrgId
  4376. label.PatientId = patient_id
  4377. label.RecordDate = recordDateTime
  4378. label.IsPrint = 2
  4379. label.Ctime = time.Now().Unix()
  4380. label.Mtime = time.Now().Unix()
  4381. label.FeedetlSn = p.FeedetlSn
  4382. label.PProjectId = p.ID
  4383. label.ItemId = p.TeamId
  4384. label.ProjectName = project.ProjectName
  4385. label.PatientName = patient.Name
  4386. service.CreateNewHisLabelRecord(&label, tx)
  4387. }
  4388. }
  4389. }
  4390. }
  4391. }
  4392. }
  4393. }
  4394. //插入检验数据
  4395. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4396. //新增或者编辑项目,修改对应的标签数据
  4397. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4398. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4399. var label models.HisLabelPrintInfo
  4400. project, _ := service.GetProjectDetail(p.ProjectId)
  4401. if project.CostClassify == 3 { //类别为检验检查
  4402. if p.TeamId > 0 { //检验检查组套
  4403. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4404. if tempLabel.ID == 0 {
  4405. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4406. label.Number = tempPrescription.PrescriptionNumber
  4407. label.ProjectId = project.ID
  4408. label.Status = 1
  4409. label.IsPrint = 2
  4410. label.DoctorId = info.DoctorId
  4411. label.UserOrgId = p.UserOrgId
  4412. label.PatientId = patient_id
  4413. label.RecordDate = recordDateTime
  4414. label.Ctime = time.Now().Unix()
  4415. label.Mtime = time.Now().Unix()
  4416. label.ItemId = p.TeamId
  4417. label.FeedetlSn = p.FeedetlSn
  4418. label.PProjectId = p.ID
  4419. label.ProjectName = team.ProjectTeam
  4420. label.PatientName = patient.Name
  4421. service.CreateHisLabelRecord(&label)
  4422. }
  4423. } else { //单条检验检查项目
  4424. label.Number = tempPrescription.PrescriptionNumber
  4425. label.ProjectId = project.ID
  4426. label.Status = 1
  4427. label.DoctorId = info.DoctorId
  4428. label.UserOrgId = p.UserOrgId
  4429. label.PatientId = patient_id
  4430. label.RecordDate = recordDateTime
  4431. label.IsPrint = 2
  4432. label.Ctime = time.Now().Unix()
  4433. label.Mtime = time.Now().Unix()
  4434. label.FeedetlSn = p.FeedetlSn
  4435. label.PProjectId = p.ID
  4436. label.ItemId = p.TeamId
  4437. label.ProjectName = project.ProjectName
  4438. label.PatientName = patient.Name
  4439. service.CreateHisLabelRecord(&label)
  4440. }
  4441. }
  4442. }
  4443. }
  4444. service.CreateNewHisProjectTwo(&p, tx)
  4445. var randNum int
  4446. randNum = rand.Intn(10000) + 1000
  4447. timestamp := time.Now().Unix()
  4448. tempTime := time.Unix(timestamp, 0)
  4449. timeFormat := tempTime.Format("20060102150405")
  4450. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4451. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4452. if goodBase.ID > 0 {
  4453. tx.Rollback()
  4454. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4455. return
  4456. }
  4457. service.CreateNewHisProjectTwo(&p, tx)
  4458. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4459. //查询剩余库存
  4460. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4461. var sum_count int64
  4462. for _, item := range goodList {
  4463. sum_count += item.StockCount
  4464. }
  4465. //更新剩余库存
  4466. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4467. //耗材
  4468. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4469. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4470. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4471. if len(outInfoTwo) > 0 {
  4472. for _, item := range outInfoTwo {
  4473. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4474. }
  4475. }
  4476. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4477. if len(drugAutoDetail) > 0 {
  4478. for _, item := range drugAutoDetail {
  4479. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4480. }
  4481. }
  4482. tx.Commit()
  4483. }
  4484. }
  4485. }
  4486. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4487. // addition := items["addition"].([]interface{})
  4488. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4489. // ctime := time.Now().Unix()
  4490. // mtime := ctime
  4491. // if len(addition) > 0 {
  4492. // for _, item := range addition {
  4493. // var s models.HisAdditionalCharge
  4494. // s.PrescriptionId = tempPrescription.ID
  4495. // s.Status = 1
  4496. // s.UserOrgId = adminInfo.CurrentOrgId
  4497. // s.RecordDate = recordDateTime
  4498. // s.CreatedTime = ctime
  4499. // s.UpdatedTime = mtime
  4500. // s.PatientId = patient_id
  4501. // s.HisPatientId = his_patient_id
  4502. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4503. // if errcode > 0 {
  4504. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4505. // return
  4506. // }
  4507. // service.CreateAdditionalCharge(&s)
  4508. // var randNum int
  4509. // randNum = rand.Intn(10000) + 1000
  4510. // timestamp := time.Now().Unix()
  4511. // tempTime := time.Unix(timestamp, 0)
  4512. // timeFormat := tempTime.Format("20060102150405")
  4513. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4514. // service.CreateAdditionalCharge(&s)
  4515. //
  4516. // }
  4517. // }
  4518. //}
  4519. }
  4520. }
  4521. }
  4522. tx.Commit()
  4523. if err == nil {
  4524. c.ServeSuccessJSON(map[string]interface{}{
  4525. "msg": "保存成功",
  4526. })
  4527. return
  4528. } else {
  4529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4530. return
  4531. }
  4532. } else {
  4533. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4534. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4535. var tempPrescription *models.HisPrescription
  4536. if len(prescriptions) > 0 {
  4537. for _, item := range prescriptions {
  4538. items := item.(map[string]interface{})
  4539. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4540. utils.ErrorLog("id")
  4541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4542. return
  4543. }
  4544. id := int64(items["id"].(float64))
  4545. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4546. tempPrescription = &new_prescription
  4547. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4548. utils.ErrorLog("type")
  4549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4550. return
  4551. }
  4552. types := int64(items["type"].(float64))
  4553. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4554. utils.ErrorLog("med_type")
  4555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4556. return
  4557. }
  4558. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4559. if med_type == "0" {
  4560. med_type = "14"
  4561. }
  4562. //if order_status == 0 {
  4563. // order_status = 1
  4564. //}
  4565. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4566. // utils.ErrorLog("diagnoses")
  4567. //}
  4568. diagnoses, _ := items["diagnoses"].(string)
  4569. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4570. utils.ErrorLog("pre_time")
  4571. }
  4572. preTime, _ := items["pre_time"].(string)
  4573. timeLayout := "2006-01-02"
  4574. loc, _ := time.LoadLocation("Local")
  4575. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4576. //result := strings.Split(preTime, " ")
  4577. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4578. if err != nil {
  4579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4580. return
  4581. }
  4582. pTime := theTime2.Unix()
  4583. ctime := time.Now().Unix()
  4584. if tempPrescription.ID == 0 {
  4585. prescription := &models.HisPrescription{
  4586. ID: 0,
  4587. PatientId: patient_id,
  4588. UserOrgId: adminInfo.CurrentOrgId,
  4589. RecordDate: recordDateTime,
  4590. Ctime: ctime,
  4591. Mtime: ctime,
  4592. Type: types,
  4593. Modifier: adminInfo.AdminUser.Id,
  4594. Creator: adminInfo.AdminUser.Id,
  4595. Status: 1,
  4596. Doctor: role.UserName,
  4597. HisPatientId: his_patient_id,
  4598. OrderStatus: 1,
  4599. BatchNumber: "",
  4600. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4601. PreTime: pTime,
  4602. PType: p_type,
  4603. MedType: med_type,
  4604. Diagnose: diagnoses,
  4605. }
  4606. tempPrescription = prescription
  4607. service.SaveHisPrescription(tempPrescription)
  4608. redis := service.RedisClient()
  4609. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4610. redis.Set(key, "", time.Second)
  4611. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4612. redis.Set(keyOne, "", time.Second)
  4613. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4614. redis.Set(keySeven, "", time.Second)
  4615. defer redis.Close()
  4616. } else {
  4617. tempPrescription.ID = id
  4618. tempPrescription.Type = types
  4619. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4620. tempPrescription.Mtime = time.Now().Unix()
  4621. tempPrescription.Doctor = role.UserName
  4622. //tempPrescription.OrderStatus = order_status
  4623. tempPrescription.PreTime = pTime
  4624. tempPrescription.MedType = med_type
  4625. tempPrescription.Diagnose = diagnoses
  4626. service.SaveHisPrescription(tempPrescription)
  4627. redis := service.RedisClient()
  4628. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4629. redis.Set(key, "", time.Second)
  4630. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4631. redis.Set(keyOne, "", time.Second)
  4632. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4633. redis.Set(keySeven, "", time.Second)
  4634. defer redis.Close()
  4635. }
  4636. //service.SaveHisPrescription(prescription)
  4637. //更改患者挂号状态
  4638. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4639. fmt.Println("更改失败", err2)
  4640. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4641. advices := items["advices"].([]interface{})
  4642. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4643. groupNo := int64(0)
  4644. if len(advices) > 0 {
  4645. for _, advice := range advices {
  4646. var s models.HisDoctorAdviceInfo
  4647. s.PrescriptionId = tempPrescription.ID
  4648. s.AdviceType = 2
  4649. s.AdviceDoctor = doctor_id
  4650. s.StopState = 2
  4651. s.ExecutionState = 2
  4652. s.AdviceDate = theTime3.Unix()
  4653. s.Status = 1
  4654. s.UserOrgId = adminInfo.CurrentOrgId
  4655. s.RecordDate = theTime3.Unix()
  4656. s.StartTime = tempPrescription.PreTime
  4657. s.Groupno = groupNo
  4658. s.PatientId = patient_id
  4659. s.HisPatientId = his_patient_id
  4660. s.StartTime = pTime
  4661. s.IsSettle = 2
  4662. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4663. if errcode > 0 {
  4664. c.ServeFailJSONWithSGJErrorCode(errcode)
  4665. return
  4666. }
  4667. s.StartTime = pTime
  4668. var total_count int64 //处方总库存
  4669. //查询改药品信息
  4670. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  4671. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  4672. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4673. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4674. total_count += prescribingNumberSeven * medical.MinNumber
  4675. }
  4676. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4677. total_count += prescribingNumberSeven
  4678. }
  4679. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4680. total_count += prescribingNumberSeven
  4681. }
  4682. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4683. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4684. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4685. if s.Price != lastWarehouse.RetailPrice {
  4686. s.Price = lastWarehouse.RetailPrice
  4687. }
  4688. if s.Price == 0 {
  4689. if lastWarehouse.ID == 0 {
  4690. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4691. s.Price = lastWarehouseTwo.RetailPrice
  4692. }
  4693. }
  4694. }
  4695. if adminInfo.CurrentOrgId != 10206 {
  4696. if s.ID == 0 {
  4697. //查询改药品是否已经停用
  4698. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4699. if base.ID > 0 {
  4700. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4701. return
  4702. }
  4703. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4704. if drugMedical.SumCount == 0 {
  4705. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4706. return
  4707. }
  4708. }
  4709. }
  4710. //赤峰
  4711. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4712. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4713. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4714. if info.RetailPrice > 0 {
  4715. if s.DeliveryWay == "口服" {
  4716. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4717. s.Price = drug.RetailPrice
  4718. }
  4719. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4720. s.Price = info.RetailPrice
  4721. }
  4722. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4723. s.Price = info.RetailPrice
  4724. }
  4725. }
  4726. }
  4727. }
  4728. service.CreateHisDoctorAdvice(&s)
  4729. //记录日志
  4730. byterequest, _ := json.Marshal(s)
  4731. adviceLog := models.XtDoctorAdviceLog{
  4732. UserOrgId: s.UserOrgId,
  4733. PatientId: s.PatientId,
  4734. AdminUserId: adminInfo.AdminUser.Id,
  4735. Module: 1,
  4736. ErrLog: string(byterequest),
  4737. Status: 1,
  4738. Ctime: time.Now().Unix(),
  4739. Mtime: 0,
  4740. Source: "电脑端新建his医嘱",
  4741. RecordDate: s.AdviceDate,
  4742. }
  4743. service.CreateDoctorAdviceLog(adviceLog)
  4744. //存储切片中
  4745. adviceList = append(adviceList, s)
  4746. redis := service.RedisClient()
  4747. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4748. redis.Set(key, "", time.Second)
  4749. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4750. redis.Set(keyOne, "", time.Second)
  4751. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4752. redis.Set(keySeven, "", time.Second)
  4753. var randNum int
  4754. randNum = rand.Intn(10000) + 1000
  4755. timestamp := time.Now().Unix()
  4756. tempTime := time.Unix(timestamp, 0)
  4757. timeFormat := tempTime.Format("20060102150405")
  4758. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4759. service.CreateHisDoctorAdvice(&s)
  4760. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4761. redis.Set(keySix, "", time.Second)
  4762. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4763. redis.Set(keyFive, "", time.Second)
  4764. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4765. redis.Set(keyEight, "", time.Second)
  4766. defer redis.Close()
  4767. }
  4768. }
  4769. }
  4770. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4771. projects := items["project"].([]interface{})
  4772. if len(projects) > 0 {
  4773. for _, project := range projects {
  4774. var p models.HisPrescriptionProject
  4775. p.PrescriptionId = tempPrescription.ID
  4776. p.PatientId = patient_id
  4777. p.RecordDate = theTime3.Unix()
  4778. p.Doctor = doctor_id
  4779. p.UserOrgId = adminInfo.CurrentOrgId
  4780. p.HisPatientId = his_patient_id
  4781. p.Status = 1
  4782. p.StartTime = pTime
  4783. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4784. if errcode > 0 {
  4785. c.ServeFailJSONWithSGJErrorCode(errcode)
  4786. return
  4787. }
  4788. if p.ID == 0 {
  4789. p.IsOut = 2
  4790. }
  4791. if p.ID > 0 {
  4792. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4793. p.IsOut = projectDetail.IsOut
  4794. }
  4795. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4796. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4797. if p.Type == 3 {
  4798. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4799. if p.Price != lastWarehouse.PackingPrice {
  4800. p.Price = lastWarehouse.PackingPrice
  4801. }
  4802. if p.Price == 0 {
  4803. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4804. p.Price = lastWarehouseTwo.PackingPrice
  4805. }
  4806. if p.Unit == "" {
  4807. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4808. p.Unit = goodInfoOne.PackingUnit
  4809. }
  4810. }
  4811. }
  4812. if adminInfo.CurrentOrgId != 10206 {
  4813. if p.Type == 3 {
  4814. if p.ID == 0 {
  4815. //查询该耗材是否停用
  4816. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4817. //表示该耗材已经停用,不能保存
  4818. if goodInfoSeven.ID == 0 {
  4819. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4820. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4821. return
  4822. }
  4823. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4824. if goodInfoOne.SumCount == 0 {
  4825. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4826. return
  4827. }
  4828. }
  4829. }
  4830. }
  4831. service.CreateHisProjectTwo(&p)
  4832. //记录日志
  4833. byterequest, _ := json.Marshal(p)
  4834. adviceLog := models.XtDoctorAdviceLog{
  4835. UserOrgId: p.UserOrgId,
  4836. PatientId: p.PatientId,
  4837. AdminUserId: adminInfo.AdminUser.Id,
  4838. Module: 1,
  4839. ErrLog: string(byterequest),
  4840. Status: 1,
  4841. Ctime: time.Now().Unix(),
  4842. Mtime: 0,
  4843. Source: "电脑端新建his项目",
  4844. RecordDate: p.RecordDate,
  4845. }
  4846. service.CreateDoctorAdviceLog(adviceLog)
  4847. projectList = append(projectList, p)
  4848. var randNum int
  4849. randNum = rand.Intn(10000) + 1000
  4850. timestamp := time.Now().Unix()
  4851. tempTime := time.Unix(timestamp, 0)
  4852. timeFormat := tempTime.Format("20060102150405")
  4853. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4854. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4855. //新增或者编辑项目,修改对应的标签数据
  4856. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4857. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4858. var label models.HisLabelPrintInfo
  4859. project, _ := service.GetProjectDetail(p.ProjectId)
  4860. if project.CostClassify == 3 { //类别为检验检查
  4861. if p.TeamId > 0 { //检验检查组套
  4862. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4863. if tempLabel.ID == 0 {
  4864. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4865. label.Number = tempPrescription.PrescriptionNumber
  4866. label.ProjectId = project.ID
  4867. label.Status = 1
  4868. label.IsPrint = 2
  4869. label.DoctorId = info.DoctorId
  4870. label.UserOrgId = p.UserOrgId
  4871. label.PatientId = patient_id
  4872. label.RecordDate = recordDateTime
  4873. label.Ctime = time.Now().Unix()
  4874. label.Mtime = time.Now().Unix()
  4875. label.ItemId = p.TeamId
  4876. label.FeedetlSn = p.FeedetlSn
  4877. label.PProjectId = p.ID
  4878. label.ProjectName = team.ProjectTeam
  4879. label.PatientName = patient.Name
  4880. service.CreateHisLabelRecord(&label)
  4881. }
  4882. } else { //单条检验检查项目
  4883. label.Number = tempPrescription.PrescriptionNumber
  4884. label.ProjectId = project.ID
  4885. label.Status = 1
  4886. label.DoctorId = info.DoctorId
  4887. label.UserOrgId = p.UserOrgId
  4888. label.PatientId = patient_id
  4889. label.RecordDate = recordDateTime
  4890. label.IsPrint = 2
  4891. label.Ctime = time.Now().Unix()
  4892. label.Mtime = time.Now().Unix()
  4893. label.FeedetlSn = p.FeedetlSn
  4894. label.PProjectId = p.ID
  4895. label.ItemId = p.TeamId
  4896. label.ProjectName = project.ProjectName
  4897. label.PatientName = patient.Name
  4898. service.CreateHisLabelRecord(&label)
  4899. }
  4900. }
  4901. }
  4902. }
  4903. service.SaveHisProjectTwo(&p)
  4904. }
  4905. }
  4906. }
  4907. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4908. // addition := items["addition"].([]interface{})
  4909. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4910. // ctime := time.Now().Unix()
  4911. // mtime := ctime
  4912. // if len(addition) > 0 {
  4913. // for _, item := range addition {
  4914. // var s models.HisAdditionalCharge
  4915. // s.PrescriptionId = tempPrescription.ID
  4916. // s.Status = 1
  4917. // s.UserOrgId = adminInfo.CurrentOrgId
  4918. // s.RecordDate = recordDateTime
  4919. // s.CreatedTime = ctime
  4920. // s.UpdatedTime = mtime
  4921. // s.PatientId = patient_id
  4922. // s.HisPatientId = his_patient_id
  4923. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4924. // if errcode > 0 {
  4925. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4926. // return
  4927. // }
  4928. // service.CreateAdditionalCharge(&s)
  4929. // var randNum int
  4930. // randNum = rand.Intn(10000) + 1000
  4931. // timestamp := time.Now().Unix()
  4932. // tempTime := time.Unix(timestamp, 0)
  4933. // timeFormat := tempTime.Format("20060102150405")
  4934. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4935. // service.CreateAdditionalCharge(&s)
  4936. //
  4937. // }
  4938. // }
  4939. //}
  4940. }
  4941. }
  4942. //查询今日该患者开的药品处方
  4943. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4944. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4945. //药品出库
  4946. if drugOutConfig.IsOpen == 1 {
  4947. for _, item := range hisdoctorlist {
  4948. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4949. // 查询该药品最后一次出库记录
  4950. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4951. if len(druginfo) > 0 {
  4952. //回退库存
  4953. for _, it := range druginfo {
  4954. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4955. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4956. }
  4957. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4958. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4959. }
  4960. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4961. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4962. }
  4963. }
  4964. }
  4965. //删除记录
  4966. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4967. //查询最后一次数据
  4968. if drugOutConfig.IsOpen == 1 {
  4969. //出库
  4970. if drug.IsUse == 2 {
  4971. creater := adminInfo.AdminUser.Id
  4972. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4973. }
  4974. //更新字典里面的库存
  4975. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4976. var sum_count int64
  4977. for _, its := range stockInfo {
  4978. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4979. if its.MaxUnit == baseDrug.MaxUnit {
  4980. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4981. }
  4982. sum_count += its.StockMaxNumber + its.StockMinNumber
  4983. }
  4984. //更新基础库存
  4985. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4986. //剩余库存
  4987. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4988. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4989. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4990. }
  4991. }
  4992. }
  4993. //耗材保存处方出库
  4994. if goodOutConfig.IsOpen == 1 {
  4995. //查询今日耗材出库数量
  4996. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4997. for _, item := range hisgoodlist {
  4998. //查询历史出库数据
  4999. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5000. var out_count_five int64
  5001. for _, item := range flowGood {
  5002. out_count_five += item.Count
  5003. }
  5004. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  5005. if out_count_five != parseIntCount {
  5006. //查询耗材最后一次出库记录
  5007. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  5008. //查询默认出库仓库库存
  5009. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5010. if len(wareOut) > 0 {
  5011. for _, it := range wareOut {
  5012. //回退库存
  5013. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  5014. //删除出库记录
  5015. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  5016. }
  5017. }
  5018. timeStr := time.Now().Format("2006-01-02")
  5019. timeArr := strings.Split(timeStr, "-")
  5020. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  5021. total = total + 1
  5022. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5023. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5024. number = number + total
  5025. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5026. operation_time := time.Now().Unix()
  5027. creater := c.GetAdminUserInfo().AdminUser.Id
  5028. recordDateStr := time.Now().Format("2006-01-02")
  5029. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5030. nowtime := recordDate.Unix()
  5031. warehouseOut := models.WarehouseOut{
  5032. WarehouseOutOrderNumber: warehousing_out_order,
  5033. OperationTime: operation_time,
  5034. OrgId: adminInfo.CurrentOrgId,
  5035. Creater: creater,
  5036. Ctime: time.Now().Unix(),
  5037. Status: 1,
  5038. WarehouseOutTime: nowtime,
  5039. Type: 1,
  5040. StorehouseId: storeConfig.StorehouseOutInfo,
  5041. IsCheck: 1,
  5042. IsSys: 1,
  5043. }
  5044. //查询是否生成出库单
  5045. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5046. if out.ID == 0 {
  5047. service.AddSigleWarehouseOut(&warehouseOut)
  5048. }
  5049. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5050. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5051. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5052. dialyPrepareOne := models.DialysisBeforePrepare{
  5053. GoodTypeId: goodObj.GoodTypeId,
  5054. GoodId: item.ProjectId,
  5055. PatientId: item.PatientId,
  5056. RecordDate: item.RecordDate,
  5057. UserOrgId: adminInfo.CurrentOrgId,
  5058. Count: parseIntCount,
  5059. Ctime: time.Now().Unix(),
  5060. Creater: creater,
  5061. Status: 1,
  5062. StorehouseId: houseConfig.StorehouseOutInfo,
  5063. ProjectId: item.ID,
  5064. }
  5065. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5066. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5067. //查询历史出库数据
  5068. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5069. var out_count int64
  5070. for _, item := range flowGood {
  5071. out_count += item.Count
  5072. }
  5073. //如果历史数和当前数据不想等才进行退库出库
  5074. if out_count != parseIntCount {
  5075. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5076. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5077. detail := models.AutomaticReduceDetail{
  5078. WarehouseOutId: 0,
  5079. WarehouseOutOrderNumber: "",
  5080. PatientId: item.PatientId,
  5081. Ctime: time.Now().Unix(),
  5082. Mtime: 0,
  5083. Status: 1,
  5084. RecordTime: item.RecordDate,
  5085. OrgId: item.UserOrgId,
  5086. GoodId: item.ProjectId,
  5087. GoodTypeId: 0,
  5088. Count: parseIntCount,
  5089. Type: 0,
  5090. ProjectId: item.ID,
  5091. StorehouseId: 0,
  5092. }
  5093. service.CreateAutoDetail(detail)
  5094. //查询剩余库存
  5095. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5096. var sum_count int64
  5097. for _, item := range goodList {
  5098. sum_count += item.StockCount
  5099. }
  5100. //更新剩余库存
  5101. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5102. //耗材
  5103. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5104. }
  5105. }
  5106. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5107. //查询历史出库数据
  5108. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5109. var out_count int64
  5110. for _, item := range flowGood {
  5111. out_count += item.Count
  5112. }
  5113. //如果历史数和当前数据不想等才进行退库出库
  5114. if out_count != parseIntCount {
  5115. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5116. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5117. detail := models.AutomaticReduceDetail{
  5118. WarehouseOutId: 0,
  5119. WarehouseOutOrderNumber: "",
  5120. PatientId: item.PatientId,
  5121. Ctime: time.Now().Unix(),
  5122. Mtime: 0,
  5123. Status: 1,
  5124. RecordTime: item.RecordDate,
  5125. OrgId: item.UserOrgId,
  5126. GoodId: item.ProjectId,
  5127. GoodTypeId: 0,
  5128. Count: parseIntCount,
  5129. Type: 0,
  5130. ProjectId: item.ID,
  5131. StorehouseId: 0,
  5132. }
  5133. service.CreateAutoDetail(detail)
  5134. //查询剩余库存
  5135. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5136. var sum_count int64
  5137. for _, item := range goodList {
  5138. sum_count += item.StockCount
  5139. }
  5140. //更新剩余库存
  5141. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5142. //耗材
  5143. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5144. }
  5145. }
  5146. }
  5147. }
  5148. }
  5149. ////同步到自备药
  5150. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5151. if selfPrescriptionOpen.IsOpen == 1 {
  5152. timeStr := time.Now().Format("2006-01-02")
  5153. timeArr := strings.Split(timeStr, "-")
  5154. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5155. total = total + 1
  5156. operation_time := time.Now().Unix()
  5157. creater := adminInfo.AdminUser.Id
  5158. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5159. warehousing := models.XtSelfDrugWarehouse{
  5160. WarehousingOrder: warehousing_order,
  5161. OperationTime: operation_time,
  5162. OrgId: adminInfo.CurrentOrgId,
  5163. Creater: creater,
  5164. Ctime: time.Now().Unix(),
  5165. Status: 1,
  5166. WarehousingTime: recordDateTime,
  5167. Type: 0,
  5168. StorehouseId: 0,
  5169. IsCheck: 1,
  5170. PatientId: patient_id,
  5171. IsSys: 1,
  5172. }
  5173. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5174. if selfDrugWarehouse.ID == 0 {
  5175. service.AddSelfDrugWarehouse(&warehousing, tx)
  5176. }
  5177. if selfDrugWarehouse.ID > 0 {
  5178. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5179. }
  5180. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5181. fmt.Println(info)
  5182. for _, item := range hisdoctorlist {
  5183. //查询该病人的该药品是否已经入库
  5184. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5185. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5186. var in_count int64
  5187. if len(selfdruginfo) > 0 {
  5188. for _, item := range selfdruginfo {
  5189. var in_count_one int64
  5190. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5191. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5192. }
  5193. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5194. in_count_one = item.WarehousingCount
  5195. }
  5196. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5197. in_count_one = item.WarehousingCount
  5198. }
  5199. in_count += in_count_one
  5200. }
  5201. }
  5202. if selfBasedrug.IsSelfDrug == 1 {
  5203. var total_count int64
  5204. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5205. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5206. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5207. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5208. }
  5209. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5210. total_count += prescribingNumberSeven
  5211. }
  5212. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5213. total_count += prescribingNumberSeven
  5214. }
  5215. //入库
  5216. if total_count > in_count {
  5217. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5218. WarehousingOrder: warehousing_order,
  5219. WarehousingId: info.ID,
  5220. DrugId: item.DrugId,
  5221. Number: "",
  5222. ProductDate: 0,
  5223. ExpiryDate: 0,
  5224. WarehousingCount: total_count - in_count,
  5225. WarehouseingUnit: selfBasedrug.MinUnit,
  5226. Price: 0,
  5227. TotalPrice: 0,
  5228. Status: 1,
  5229. Ctime: time.Now().Unix(),
  5230. Remark: "",
  5231. OrgId: adminInfo.CurrentOrgId,
  5232. Type: 0,
  5233. Manufacturer: selfBasedrug.Manufacturer,
  5234. Dealer: selfBasedrug.Dealer,
  5235. StockMaxNumber: total_count - in_count,
  5236. RetailTotalPrice: 0,
  5237. BatchNumber: "",
  5238. MaxUnit: selfBasedrug.MinUnit,
  5239. MinUnit: selfBasedrug.MinUnit,
  5240. RetailPrice: 0,
  5241. StorehouseId: 0,
  5242. IsCheck: 1,
  5243. StockMinNumber: 0,
  5244. PatientId: patient_id,
  5245. IsSys: 1,
  5246. RecordDate: item.RecordDate,
  5247. AdviceId: item.ID,
  5248. }
  5249. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5250. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5251. Creator := adminInfo.AdminUser.Id
  5252. //查询默认仓库剩余多少库存
  5253. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5254. var sum_count int64
  5255. for _, it := range list {
  5256. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5257. if it.MaxUnit == baseDrug.MaxUnit {
  5258. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5259. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5260. }
  5261. sum_count += it.StockMaxNumber + it.StockMinNumber
  5262. }
  5263. flow := &models.XtSelfDrugFlow{
  5264. WarehousingId: info.ID,
  5265. DrugId: item.DrugId,
  5266. Number: "",
  5267. BatchNumber: "",
  5268. Count: total_count - in_count,
  5269. UserOrgId: adminInfo.CurrentOrgId,
  5270. PatientId: item.PatientId,
  5271. SystemTime: time.Now().Unix(),
  5272. ConsumableType: 1,
  5273. IsSys: 1,
  5274. WarehousingOrder: warehousing_order,
  5275. WarehouseOutId: 0,
  5276. WarehouseOutOrderNumber: "",
  5277. IsEdit: 0,
  5278. CancelStockId: 0,
  5279. CancelOrderNumber: "",
  5280. Manufacturer: selfBasedrug.Manufacturer,
  5281. Dealer: selfBasedrug.Dealer,
  5282. Creator: Creator,
  5283. UpdateCreator: Creator,
  5284. Status: 1,
  5285. Ctime: item.AdviceDate,
  5286. Mtime: 0,
  5287. Price: item.Price,
  5288. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5289. WarehouseOutDetailId: 0,
  5290. CancelOutDetailId: 0,
  5291. ExpireDate: 0,
  5292. ProductDate: 0,
  5293. MaxUnit: selfBasedrug.MinUnit,
  5294. MinUnit: selfBasedrug.MinUnit,
  5295. StorehouseId: 0,
  5296. OverCount: sum_count,
  5297. OperateTime: time.Now().Unix(),
  5298. AdviceId: item.ID,
  5299. }
  5300. service.CreateSelfDrugFlow(flow, tx)
  5301. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5302. var total_count int64 // 入库总数量
  5303. var over_count int64 //剩余库存
  5304. for _, it := range drugInfolist {
  5305. if it.MaxUnit == selfBasedrug.MaxUnit {
  5306. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5307. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5308. }
  5309. }
  5310. for _, it := range drugInfolist {
  5311. total_count += it.WarehousingCount
  5312. over_count += it.StockMaxNumber + it.StockMinNumber
  5313. }
  5314. //查询该仓库是否有默认数据
  5315. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5316. if selfDrugStock.ID == 0 {
  5317. drugStock := models.XtSelfDrugStockCount{
  5318. UserOrgId: item.UserOrgId,
  5319. PatientId: item.PatientId,
  5320. SumInCount: total_count,
  5321. SumOutCount: 0,
  5322. SumCancelCount: 0,
  5323. DrugId: item.DrugId,
  5324. Ctime: time.Now().Unix(),
  5325. Mtime: 0,
  5326. Status: 1,
  5327. FlushCount: over_count,
  5328. SumActOutCount: 0,
  5329. }
  5330. service.CreateSelfDrugStockSum(drugStock, tx)
  5331. }
  5332. if selfDrugStock.ID > 0 {
  5333. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5334. }
  5335. }
  5336. //查询这个单据的出库数量
  5337. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5338. var his_out_count int64
  5339. for _, item := range drugFlowList {
  5340. his_out_count += item.Count
  5341. }
  5342. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5343. if (total_count + his_out_count) <= in_count {
  5344. // 出库
  5345. if total_count < in_count {
  5346. var cha_count int64
  5347. cha_count = in_count - total_count
  5348. var stock_number int64 = 0
  5349. //查询库存是否充足
  5350. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5351. // 将该批次的剩余库存数量转换为拆零数量
  5352. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5353. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5354. }
  5355. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5356. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5357. }
  5358. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5359. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5360. }
  5361. if stock_number >= cha_count {
  5362. var maxNumber int64 = 0
  5363. var minNumber int64 = 0
  5364. maxNumber = cha_count / selfBasedrug.MinNumber
  5365. minNumber = cha_count % selfBasedrug.MinNumber
  5366. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5367. minNumber = maxNumber
  5368. }
  5369. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5370. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5372. return
  5373. }
  5374. }
  5375. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5376. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5377. }
  5378. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5379. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5380. }
  5381. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5382. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5383. }
  5384. if warehouse.StockMaxNumber < 0 {
  5385. warehouse.StockMaxNumber = 0
  5386. }
  5387. if warehouse.StockMinNumber < 0 {
  5388. warehouse.StockMinNumber = 0
  5389. }
  5390. warehouse.Mtime = time.Now().Unix()
  5391. if warehouse.StockMinNumber < minNumber {
  5392. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5393. if warehouse.MaxUnit != warehouse.MinUnit {
  5394. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5395. }
  5396. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5397. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5398. }
  5399. } else {
  5400. if minNumber > 0 {
  5401. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5402. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5403. }
  5404. }
  5405. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5406. if warehouse.StockMinNumber > 0 {
  5407. if warehouse.StockMinNumber-cha_count >= 0 {
  5408. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5409. }
  5410. }
  5411. }
  5412. }
  5413. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5414. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5415. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5416. }
  5417. }
  5418. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5419. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5421. return
  5422. }
  5423. }
  5424. if warehouse.StockMinNumber <= 0 {
  5425. warehouse.StockMinNumber = 0
  5426. }
  5427. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5428. //查询该药品剩余库存
  5429. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5430. var over_count int64
  5431. for _, its := range infolist {
  5432. if its.MaxUnit == selfBasedrug.MaxUnit {
  5433. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5434. }
  5435. over_count += its.StockMaxNumber + its.StockMinNumber
  5436. }
  5437. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5438. drugflow := models.XtSelfDrugFlow{
  5439. WarehouseOutId: 0,
  5440. WarehouseOutOrderNumber: warehousing_order,
  5441. WarehousingOrder: warehousing_order,
  5442. DrugId: item.DrugId,
  5443. Number: warehouse.Number,
  5444. ProductDate: warehouse.ProductDate,
  5445. ExpireDate: warehouse.ExpiryDate,
  5446. Count: cha_count,
  5447. Price: warehouse.RetailPrice,
  5448. Status: 1,
  5449. Ctime: item.AdviceDate,
  5450. Mtime: time.Now().Unix(),
  5451. UserOrgId: item.UserOrgId,
  5452. Manufacturer: warehouse.Manufacturer,
  5453. Dealer: warehouse.Dealer,
  5454. BatchNumber: warehouse.BatchNumber,
  5455. MaxUnit: selfBasedrug.MinUnit,
  5456. ConsumableType: 20,
  5457. IsEdit: 1,
  5458. Creator: 0,
  5459. IsSys: 3,
  5460. WarehouseOutDetailId: drugWareInfo.ID,
  5461. AdviceId: item.ID,
  5462. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5463. StorehouseId: 0,
  5464. AdminUserId: creater,
  5465. LastPrice: warehouse.Price,
  5466. StockCount: "",
  5467. WarehousingDetailId: 0,
  5468. OverCount: over_count,
  5469. RetailPrice: item.Price, //手动出库出库价格
  5470. WarehousingId: warehouse.ID,
  5471. SystemTime: item.AdviceDate,
  5472. PatientId: item.PatientId,
  5473. Remark: "保存处方入库数据差",
  5474. OperateTime: time.Now().Unix(),
  5475. }
  5476. if warehouse.RetailPrice == 0 {
  5477. drugflow.Price = item.Price
  5478. }
  5479. service.CreateSelfDrugFlowOne(drugflow, tx)
  5480. var out_count int64
  5481. out_count = in_count - total_count
  5482. //
  5483. //fmt.Println("in_count------------------", in_count)
  5484. //fmt.Println("total_count------------------", total_count)
  5485. //添加出库数量
  5486. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5487. //查询剩余库存
  5488. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5489. var sum_count int64
  5490. for _, its := range stockInfo {
  5491. if its.MaxUnit == selfBasedrug.MaxUnit {
  5492. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5493. }
  5494. sum_count += its.StockMaxNumber + its.StockMinNumber
  5495. }
  5496. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5497. } else {
  5498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5499. return
  5500. }
  5501. }
  5502. }
  5503. }
  5504. }
  5505. }
  5506. }
  5507. tx.Commit()
  5508. if err == nil {
  5509. c.ServeSuccessJSON(map[string]interface{}{
  5510. "msg": "保存成功",
  5511. })
  5512. return
  5513. } else {
  5514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5515. return
  5516. }
  5517. }
  5518. }
  5519. //func (c *HisApiController) EditHisPrescription() {
  5520. // record_date := c.GetString("record_date")
  5521. // patient_id, _ := c.GetInt64("patient_id")
  5522. // reg_type, _ := c.GetInt64("reg_type")
  5523. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5524. // diagnose := c.GetString("diagnose")
  5525. // sick_type, _ := c.GetInt64("sick_type")
  5526. // sick_history := c.GetString("sick_history")
  5527. // doctor_id, _ := c.GetInt64("doctor", 0)
  5528. // department, _ := c.GetInt64("department", 0)
  5529. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5530. // p_type, _ := c.GetInt64("p_type")
  5531. //
  5532. // dataBody := make(map[string]interface{}, 0)
  5533. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5534. // if err != nil {
  5535. // utils.ErrorLog(err.Error())
  5536. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5537. // return
  5538. // }
  5539. //
  5540. // timeLayout := "2006-01-02"
  5541. // loc, _ := time.LoadLocation("Local")
  5542. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5543. // if err != nil {
  5544. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5545. // return
  5546. // }
  5547. // adminInfo := c.GetAdminUserInfo()
  5548. // recordDateTime := theTime.Unix()
  5549. //
  5550. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5551. //
  5552. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5553. // var hpInfo models.HisPrescriptionInfo
  5554. // if info.ID == 0 {
  5555. // var randNum int
  5556. // randNum = rand.Intn(10000) + 1000
  5557. // timestamp := time.Now().Unix()
  5558. // tempTime := time.Unix(timestamp, 0)
  5559. // timeFormat := tempTime.Format("20060102150405")
  5560. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5561. //
  5562. // hpInfo = models.HisPrescriptionInfo{
  5563. // UserOrgId: adminInfo.CurrentOrgId,
  5564. // RecordDate: theTime.Unix(),
  5565. // PatientId: patient_id,
  5566. // Status: 1,
  5567. // Ctime: time.Now().Unix(),
  5568. // Mtime: time.Now().Unix(),
  5569. // Creator: adminInfo.AdminUser.Id,
  5570. // Modifier: adminInfo.AdminUser.Id,
  5571. // Diagnosis: diagnose,
  5572. // SickHistory: sick_history,
  5573. // Departments: department,
  5574. // RegisterType: reg_type,
  5575. // PrescriptionNumber: p_number,
  5576. // PrescriptionStatus: 1,
  5577. // Doctor: role.UserName,
  5578. // DoctorId: doctor_id,
  5579. // SickType: sick_type,
  5580. // PType: p_type,
  5581. // }
  5582. // service.SavePatientPrescriptionInfo(hpInfo)
  5583. //
  5584. // } else {
  5585. // hpInfo = models.HisPrescriptionInfo{
  5586. // ID: info.ID,
  5587. // UserOrgId: adminInfo.CurrentOrgId,
  5588. // RecordDate: info.RecordDate,
  5589. // PatientId: info.PatientId,
  5590. // Status: 1,
  5591. // Ctime: info.Ctime,
  5592. // Mtime: time.Now().Unix(),
  5593. // Creator: info.Creator,
  5594. // Modifier: adminInfo.AdminUser.Id,
  5595. // Diagnosis: diagnose,
  5596. // SickHistory: sick_history,
  5597. // Departments: department,
  5598. // RegisterType: reg_type,
  5599. // PrescriptionNumber: info.PrescriptionNumber,
  5600. // Doctor: role.UserName,
  5601. // PrescriptionStatus: info.PrescriptionStatus,
  5602. // DoctorId: doctor_id,
  5603. // SickType: sick_type,
  5604. // PType: info.PType,
  5605. // }
  5606. // service.SavePatientPrescriptionInfo(hpInfo)
  5607. // }
  5608. //
  5609. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5610. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5611. //
  5612. // if len(prescriptions) > 0 {
  5613. // for _, item := range prescriptions {
  5614. // items := item.(map[string]interface{})
  5615. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5616. // utils.ErrorLog("id")
  5617. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5618. // return
  5619. // }
  5620. // id := int64(items["id"].(float64))
  5621. //
  5622. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5623. // utils.ErrorLog("type")
  5624. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5625. // return
  5626. // }
  5627. // types := int64(items["type"].(float64))
  5628. //
  5629. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5630. // utils.ErrorLog("med_type")
  5631. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5632. // return
  5633. // }
  5634. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5635. //
  5636. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5637. //
  5638. // ctime := time.Now().Unix()
  5639. //
  5640. // prescription := &models.HisPrescription{
  5641. // ID: id,
  5642. // PatientId: patient_id,
  5643. // UserOrgId: adminInfo.CurrentOrgId,
  5644. // RecordDate: recordDateTime,
  5645. // Ctime: ctime,
  5646. // Mtime: ctime,
  5647. // Type: types,
  5648. // Modifier: adminInfo.AdminUser.Id,
  5649. // Creator: adminInfo.AdminUser.Id,
  5650. // Status: 1,
  5651. // Doctor: role.UserName,
  5652. // HisPatientId: his_patient_id,
  5653. // OrderStatus: 1,
  5654. // BatchNumber: "",
  5655. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5656. // PType: hpInfo.PType,
  5657. // MedType: med_type,
  5658. // }
  5659. //
  5660. // if historyPrescription.ID > 0 {
  5661. // prescription.PreTime = historyPrescription.PreTime
  5662. //
  5663. // }
  5664. //
  5665. // service.SaveHisPrescription(prescription)
  5666. //
  5667. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5668. // advices := items["advices"].([]interface{})
  5669. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5670. // groupNo := int64(0)
  5671. // ctime := time.Now().Unix()
  5672. // mtime := ctime
  5673. // if len(advices) > 0 {
  5674. // for _, advice := range advices {
  5675. // var s models.HisDoctorAdviceInfo
  5676. // s.PrescriptionId = prescription.ID
  5677. // s.AdviceType = 2
  5678. // s.AdviceDoctor = adminInfo.AdminUser.Id
  5679. // s.StopState = 2
  5680. // s.ExecutionState = 2
  5681. // s.AdviceDate = recordDateTime
  5682. // s.Status = 1
  5683. // s.UserOrgId = adminInfo.CurrentOrgId
  5684. // s.RecordDate = recordDateTime
  5685. // s.StartTime = prescription.PreTime
  5686. // s.Groupno = groupNo
  5687. // s.CreatedTime = ctime
  5688. // s.UpdatedTime = mtime
  5689. // s.PatientId = patient_id
  5690. // s.HisPatientId = his_patient_id
  5691. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5692. // if errcode > 0 {
  5693. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5694. // return
  5695. // }
  5696. //
  5697. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5698. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5699. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5700. // if s.Price == 0 {
  5701. // s.Price = lastWarehouse.RetailPrice
  5702. // }
  5703. // }
  5704. //
  5705. // service.CreateHisDoctorAdvice(&s)
  5706. // //记录日志
  5707. // byterequest, _ := json.Marshal(s)
  5708. // adviceLog := models.XtDoctorAdviceLog{
  5709. // UserOrgId: s.UserOrgId,
  5710. // PatientId: s.PatientId,
  5711. // AdminUserId: adminInfo.AdminUser.Id,
  5712. // Module: 1,
  5713. // ErrLog: string(byterequest),
  5714. // Status: 1,
  5715. // Ctime: time.Now().Unix(),
  5716. // Mtime: 0,
  5717. // Source: "电脑端his医嘱修改",
  5718. // RecordDate: s.AdviceDate,
  5719. // }
  5720. // service.CreateDoctorAdviceLog(adviceLog)
  5721. // redis := service.RedisClient()
  5722. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5723. // redis.Set(key, "", time.Second)
  5724. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5725. // fmt.Println("keyOne", keyOne)
  5726. // redis.Set(keyOne, "", time.Second)
  5727. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5728. // redis.Set(keySeven, "", time.Second)
  5729. // redis.Close()
  5730. //
  5731. // }
  5732. // }
  5733. // }
  5734. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5735. // projects := items["project"].([]interface{})
  5736. // if len(projects) > 0 {
  5737. // for _, project := range projects {
  5738. // var p models.HisPrescriptionProject
  5739. // p.PrescriptionId = prescription.ID
  5740. // p.Ctime = time.Now().Unix()
  5741. // p.Mtime = time.Now().Unix()
  5742. // p.PatientId = patient_id
  5743. // p.RecordDate = recordDateTime
  5744. // p.UserOrgId = adminInfo.CurrentOrgId
  5745. // p.HisPatientId = his_patient_id
  5746. // p.Status = 1
  5747. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5748. // if errcode > 0 {
  5749. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5750. // return
  5751. // }
  5752. // service.CreateHisProjectTwo(&p)
  5753. //
  5754. // //记录日志
  5755. // byterequest, _ := json.Marshal(p)
  5756. // adviceLog := models.XtDoctorAdviceLog{
  5757. // UserOrgId: p.UserOrgId,
  5758. // PatientId: p.PatientId,
  5759. // AdminUserId: adminInfo.AdminUser.Id,
  5760. // Module: 1,
  5761. // ErrLog: string(byterequest),
  5762. // Status: 1,
  5763. // Ctime: time.Now().Unix(),
  5764. // Mtime: 0,
  5765. // Source: "电脑端his项目修改",
  5766. // RecordDate: p.RecordDate,
  5767. // }
  5768. // service.CreateDoctorAdviceLog(adviceLog)
  5769. // }
  5770. // }
  5771. // }
  5772. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5773. // addition := items["addition"].([]interface{})
  5774. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5775. // ctime := time.Now().Unix()
  5776. // mtime := ctime
  5777. // if len(addition) > 0 {
  5778. // for _, item := range addition {
  5779. // var s models.HisAdditionalCharge
  5780. // s.PrescriptionId = prescription.ID
  5781. // s.Status = 1
  5782. // s.UserOrgId = adminInfo.CurrentOrgId
  5783. // s.RecordDate = recordDateTime
  5784. // s.CreatedTime = ctime
  5785. // s.UpdatedTime = mtime
  5786. // s.PatientId = patient_id
  5787. // s.HisPatientId = his_patient_id
  5788. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5789. // if errcode > 0 {
  5790. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5791. // return
  5792. // }
  5793. // service.CreateAdditionalCharge(&s)
  5794. // }
  5795. // }
  5796. // }
  5797. //
  5798. // }
  5799. // }
  5800. // }
  5801. // if err == nil {
  5802. // c.ServeSuccessJSON(map[string]interface{}{
  5803. // "msg": "保存成功",
  5804. // })
  5805. // return
  5806. //
  5807. // } else {
  5808. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5809. // return
  5810. // }
  5811. //}
  5812. func (c *HisApiController) DeletePrescription() {
  5813. prescription_id, _ := c.GetInt64("id")
  5814. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5815. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5816. ////同步到自备药
  5817. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5818. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5819. if selfPrescriptionOpen.IsOpen == 1 {
  5820. // 在函数结束时处理事务回滚
  5821. db := service.XTWriteDB()
  5822. tx := db.Begin()
  5823. defer func() {
  5824. if r := recover(); r != nil {
  5825. tx.Rollback()
  5826. } else {
  5827. tx.Commit()
  5828. }
  5829. }()
  5830. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5831. for _, item := range advicesList {
  5832. timeStr := time.Now().Format("2006-01-02")
  5833. timeArr := strings.Split(timeStr, "-")
  5834. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5835. total = total + 1
  5836. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5837. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5838. number = number + total
  5839. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5840. operation_time := time.Now().Unix()
  5841. creater := c.GetAdminUserInfo().AdminUser.Id
  5842. //创建一个出库单
  5843. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5844. WarehouseOutOrderNumber: warehousing_out_order,
  5845. OperationTime: operation_time,
  5846. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5847. Creater: creater,
  5848. Ctime: time.Now().Unix(),
  5849. Status: 1,
  5850. WarehouseOutTime: item.AdviceDate,
  5851. Type: 0,
  5852. PatientId: item.PatientId,
  5853. IsCheck: 1,
  5854. }
  5855. //查询今日是否有出库数据
  5856. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5857. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5858. if lastWarehouseOut.ID == 0 {
  5859. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5860. }
  5861. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5862. var total_count int64
  5863. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5864. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5865. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5866. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5867. }
  5868. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5869. total_count += prescribingNumberSeven
  5870. }
  5871. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5872. total_count += prescribingNumberSeven
  5873. }
  5874. //出库
  5875. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5876. WarehouseOutOrderNumber: warehousing_out_order,
  5877. WarehouseOutId: lastWarehouseOut.ID,
  5878. DrugId: item.DrugId,
  5879. Count: total_count,
  5880. Price: 0,
  5881. TotalPrice: 0,
  5882. Status: 1,
  5883. Ctime: item.AdviceDate,
  5884. Mtime: item.AdviceDate,
  5885. Remark: "",
  5886. OrgId: item.UserOrgId,
  5887. Type: 0,
  5888. Manufacturer: selfBasedrug.Manufacturer,
  5889. Dealer: selfBasedrug.Dealer,
  5890. RetailPrice: 0,
  5891. RetailTotalPrice: 0,
  5892. CountUnit: selfBasedrug.MinUnit,
  5893. ExpiryDate: 0,
  5894. ProductDate: 0,
  5895. Number: "",
  5896. BatchNumber: "",
  5897. IsSys: 1,
  5898. WarehouseInfoId: 0,
  5899. AdminUserId: 0,
  5900. StockCount: "",
  5901. IsCheck: 1,
  5902. SysRecordTime: item.AdviceDate,
  5903. PatientId: item.PatientId,
  5904. ClassType: "",
  5905. AdviceId: item.ID,
  5906. }
  5907. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5908. }
  5909. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5910. for _, it := range warehousingOutInfo {
  5911. //查询今日是否有出库数据
  5912. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5913. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5914. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5915. //出库逻辑
  5916. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5917. //查询剩余库存
  5918. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5919. var sum_count int64
  5920. for _, its := range stockInfo {
  5921. if its.MaxUnit == medical.MaxUnit {
  5922. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5923. }
  5924. sum_count += its.StockMaxNumber + its.StockMinNumber
  5925. }
  5926. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5927. }
  5928. }
  5929. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5930. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5931. //耗材保存处方出库
  5932. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5933. //已收费和已发药限制逻辑
  5934. isCharge := false
  5935. isMedicine := false
  5936. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5937. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5938. if new_prescription.IsMedicine == 1 {
  5939. isMedicine = true
  5940. }
  5941. for _, item := range new_prescriptions {
  5942. if item.OrderStatus == 4 {
  5943. isCharge = true
  5944. }
  5945. }
  5946. if p_err != nil {
  5947. if new_prescription.ID > 0 {
  5948. if new_prescription.OrderStatus == 2 {
  5949. isCharge = true
  5950. }
  5951. }
  5952. }
  5953. for _, item := range advices {
  5954. if item.IsMedicine == 1 {
  5955. isMedicine = true
  5956. }
  5957. }
  5958. if isCharge {
  5959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5960. return
  5961. }
  5962. if isMedicine {
  5963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5964. return
  5965. }
  5966. //已收费和已发药限制逻辑
  5967. if len(projects) > 0 {
  5968. for _, item := range projects {
  5969. service.DeletePrintInfo(item.ID) //删除打印信息
  5970. if goodOutConfig.IsOpen != 1 {
  5971. if stockConfig.IsOpen == 1 {
  5972. if item.Type == 3 && item.IsOut == 1 {
  5973. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5974. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5975. good.Total = good.Total + f_count
  5976. service.UpdateGoodInfo(&good)
  5977. operation_time := time.Now().Unix()
  5978. creater := c.GetAdminUserInfo().AdminUser.Id
  5979. //创建退库单
  5980. timeStr := time.Now().Format("2006-01-02")
  5981. timeArr := strings.Split(timeStr, "-")
  5982. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5983. total = total + 1
  5984. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5985. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5986. cancelStock := models.CancelStock{
  5987. OrderNumber: orderNumber,
  5988. OperaTime: operation_time,
  5989. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5990. Creater: creater,
  5991. Ctime: time.Now().Unix(),
  5992. Status: 1,
  5993. ReturnTime: item.RecordDate,
  5994. Type: 1,
  5995. StorehouseId: houseConfig.StorehouseOutInfo,
  5996. IsCheck: 1,
  5997. }
  5998. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5999. if msgerrkonde == gorm.ErrRecordNotFound {
  6000. service.AddSigleCancelStock(&cancelStock)
  6001. }
  6002. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6003. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6004. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6005. //查询该耗材是否出库
  6006. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6007. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6008. deaerler, _ := service.GetDealerById(info.Dealer)
  6009. var total_count int64
  6010. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6011. total_count += count
  6012. if info.ID > 0 {
  6013. if info.Count >= total_count {
  6014. //回退库存
  6015. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6016. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6017. var flush_count int64
  6018. for _, it := range goodList {
  6019. flush_count += it.StockCount
  6020. }
  6021. cancelStockInfo := models.CancelStockInfo{
  6022. GoodId: item.ProjectId,
  6023. CancelStockId: cancel.ID,
  6024. GoodTypeId: good.GoodTypeId,
  6025. Count: prescribingNumber,
  6026. Price: info.Price,
  6027. Total: 0,
  6028. ProductDate: info.ProductDate,
  6029. ExpiryDate: info.ExpiryDate,
  6030. Ctime: time.Now().Unix(),
  6031. Status: 1,
  6032. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6033. OrderNumber: cancel.OrderNumber,
  6034. Type: 0,
  6035. Dealer: deaerler.DealerName,
  6036. Manufacturer: manufacturer.ManufacturerName,
  6037. Number: info.Number,
  6038. RegisterAccount: "",
  6039. Remark: "",
  6040. WarehouseInfoId: info.WarehouseInfotId,
  6041. PatientId: info.PatientId,
  6042. RecordDate: info.SysRecordTime,
  6043. StorehouseId: houseConfig.StorehouseOutInfo,
  6044. IsCheck: 1,
  6045. }
  6046. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6047. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6048. flow := models.VmStockFlow{
  6049. WarehousingId: info.WarehouseInfotId,
  6050. GoodId: item.ProjectId,
  6051. Number: info.Number,
  6052. LicenseNumber: info.LicenseNumber,
  6053. Count: prescribingNumber,
  6054. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6055. PatientId: item.PatientId,
  6056. SystemTime: info.SysRecordTime,
  6057. ConsumableType: 7,
  6058. IsSys: 0,
  6059. WarehousingOrder: "",
  6060. WarehouseOutId: info.WarehouseOutId,
  6061. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6062. IsEdit: 0,
  6063. CancelStockId: cancel.ID,
  6064. CancelOrderNumber: cancel.OrderNumber,
  6065. Manufacturer: manufacturer.ID,
  6066. Dealer: 0,
  6067. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6068. UpdateCreator: 0,
  6069. Status: 1,
  6070. Ctime: time.Now().Unix(),
  6071. Mtime: 0,
  6072. Price: info.Price,
  6073. WarehousingDetailId: info.WarehouseInfotId,
  6074. WarehouseOutDetailId: info.ID,
  6075. CancelOutDetailId: cancelInfo.ID,
  6076. ProductDate: info.ProductDate,
  6077. ExpireDate: info.ExpiryDate,
  6078. StorehouseId: houseConfig.StorehouseOutInfo,
  6079. OverCount: flush_count,
  6080. OperateTime: time.Now().Unix(),
  6081. }
  6082. service.CreateStockFlowOne(flow)
  6083. //退库数量增加
  6084. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6085. //出库数量减少
  6086. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6087. }
  6088. if info.Count < total_count {
  6089. //回退库存
  6090. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6091. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6092. var flush_count int64
  6093. for _, it := range goodList {
  6094. flush_count += it.StockCount
  6095. }
  6096. cancelStockInfo := models.CancelStockInfo{
  6097. GoodId: item.ProjectId,
  6098. CancelStockId: cancel.ID,
  6099. GoodTypeId: good.GoodTypeId,
  6100. Count: info.Count,
  6101. Price: info.Price,
  6102. Total: 0,
  6103. ProductDate: info.ProductDate,
  6104. ExpiryDate: info.ExpiryDate,
  6105. Ctime: time.Now().Unix(),
  6106. Status: 1,
  6107. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6108. OrderNumber: cancel.OrderNumber,
  6109. Type: 0,
  6110. Dealer: deaerler.DealerName,
  6111. Manufacturer: manufacturer.ManufacturerName,
  6112. Number: info.Number,
  6113. RegisterAccount: "",
  6114. Remark: "",
  6115. WarehouseInfoId: info.WarehouseInfotId,
  6116. PatientId: info.PatientId,
  6117. RecordDate: info.SysRecordTime,
  6118. StorehouseId: houseConfig.StorehouseOutInfo,
  6119. IsCheck: 1,
  6120. }
  6121. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6122. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6123. flow := models.VmStockFlow{
  6124. WarehousingId: info.WarehouseInfotId,
  6125. GoodId: item.ProjectId,
  6126. Number: info.Number,
  6127. LicenseNumber: info.LicenseNumber,
  6128. Count: info.Count,
  6129. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6130. PatientId: item.PatientId,
  6131. SystemTime: info.SysRecordTime,
  6132. ConsumableType: 7,
  6133. IsSys: 0,
  6134. WarehousingOrder: "",
  6135. WarehouseOutId: info.WarehouseOutId,
  6136. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6137. IsEdit: 0,
  6138. CancelStockId: cancel.ID,
  6139. CancelOrderNumber: cancel.OrderNumber,
  6140. Manufacturer: manufacturer.ID,
  6141. Dealer: 0,
  6142. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6143. UpdateCreator: 0,
  6144. Status: 1,
  6145. Ctime: time.Now().Unix(),
  6146. Mtime: 0,
  6147. Price: info.Price,
  6148. WarehousingDetailId: info.WarehouseInfotId,
  6149. WarehouseOutDetailId: info.ID,
  6150. CancelOutDetailId: cancelInfo.ID,
  6151. ProductDate: info.ProductDate,
  6152. ExpireDate: info.ExpiryDate,
  6153. StorehouseId: houseConfig.StorehouseOutInfo,
  6154. OverCount: flush_count,
  6155. OperateTime: time.Now().Unix(),
  6156. }
  6157. service.CreateStockFlowOne(flow)
  6158. //退库数量增加
  6159. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6160. //出库数量减少
  6161. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6162. }
  6163. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6164. var flush_count int64
  6165. for _, it := range goodList {
  6166. flush_count += it.StockCount
  6167. }
  6168. //查询已出库数量
  6169. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6170. if prescribingNumber < dialysisInfo.Count {
  6171. //改变数量
  6172. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6173. }
  6174. if prescribingNumber >= dialysisInfo.Count {
  6175. //删除出库表
  6176. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6177. }
  6178. //更新库存
  6179. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6180. //更新基础库库存
  6181. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6182. }
  6183. }
  6184. }
  6185. }
  6186. //保存耗材出库
  6187. if goodOutConfig.IsOpen == 1 {
  6188. if item.Type == 3 {
  6189. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6190. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6191. good.Total = good.Total + f_count
  6192. service.UpdateGoodInfo(&good)
  6193. operation_time := time.Now().Unix()
  6194. creater := c.GetAdminUserInfo().AdminUser.Id
  6195. //创建退库单
  6196. timeStr := time.Now().Format("2006-01-02")
  6197. timeArr := strings.Split(timeStr, "-")
  6198. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6199. total = total + 1
  6200. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6201. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6202. cancelStock := models.CancelStock{
  6203. OrderNumber: orderNumber,
  6204. OperaTime: operation_time,
  6205. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6206. Creater: creater,
  6207. Ctime: time.Now().Unix(),
  6208. Status: 1,
  6209. ReturnTime: item.RecordDate,
  6210. Type: 1,
  6211. StorehouseId: houseConfig.StorehouseOutInfo,
  6212. IsCheck: 1,
  6213. }
  6214. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6215. if msgerrkonde == gorm.ErrRecordNotFound {
  6216. service.AddSigleCancelStock(&cancelStock)
  6217. }
  6218. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6219. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6220. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6221. //查询该耗材是否出库
  6222. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6223. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6224. deaerler, _ := service.GetDealerById(info.Dealer)
  6225. var total_count int64
  6226. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6227. total_count += count
  6228. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6229. var flush_count int64
  6230. for _, it := range goodList {
  6231. flush_count += it.StockCount
  6232. }
  6233. fmt.Println("历史出库数据", info.Count)
  6234. fmt.Println("出库数量", total_count)
  6235. if info.ID > 0 {
  6236. cancelStockInfo := models.CancelStockInfo{
  6237. GoodId: item.ProjectId,
  6238. CancelStockId: cancel.ID,
  6239. GoodTypeId: good.GoodTypeId,
  6240. Count: prescribingNumber,
  6241. Price: info.Price,
  6242. Total: 0,
  6243. ProductDate: info.ProductDate,
  6244. ExpiryDate: info.ExpiryDate,
  6245. Ctime: time.Now().Unix(),
  6246. Status: 1,
  6247. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6248. OrderNumber: cancel.OrderNumber,
  6249. Type: 0,
  6250. Dealer: deaerler.DealerName,
  6251. Manufacturer: manufacturer.ManufacturerName,
  6252. Number: info.Number,
  6253. RegisterAccount: "",
  6254. Remark: "",
  6255. WarehouseInfoId: info.WarehouseInfotId,
  6256. PatientId: info.PatientId,
  6257. RecordDate: info.SysRecordTime,
  6258. StorehouseId: houseConfig.StorehouseOutInfo,
  6259. IsCheck: 1,
  6260. }
  6261. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6262. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6263. //查询出库数量
  6264. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6265. //出库数据 大于 退库数量
  6266. if len(list) > 0 {
  6267. for _, it := range list {
  6268. //回退库存
  6269. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6270. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6271. var flush_count_one int64
  6272. for _, it := range goodList {
  6273. flush_count_one += it.StockCount
  6274. }
  6275. //查询该批次是否有退库数据
  6276. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6277. creater := c.GetAdminUserInfo().AdminUser.Id
  6278. flow := models.VmStockFlow{
  6279. WarehousingId: it.WarehouseInfotId,
  6280. GoodId: it.GoodId,
  6281. Number: it.Number,
  6282. LicenseNumber: it.LicenseNumber,
  6283. Count: it.Count,
  6284. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6285. PatientId: it.PatientId,
  6286. SystemTime: it.SysRecordTime,
  6287. ConsumableType: 7,
  6288. IsSys: 0,
  6289. WarehousingOrder: "",
  6290. WarehouseOutId: it.WarehouseOutId,
  6291. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6292. IsEdit: 0,
  6293. CancelStockId: cancel.ID,
  6294. CancelOrderNumber: cancel.OrderNumber,
  6295. Manufacturer: manufacturer.ID,
  6296. Dealer: 0,
  6297. Creator: creater,
  6298. UpdateCreator: 0,
  6299. Status: 1,
  6300. Ctime: time.Now().Unix(),
  6301. Mtime: 0,
  6302. Price: it.Price,
  6303. WarehousingDetailId: it.WarehouseInfotId,
  6304. WarehouseOutDetailId: it.ID,
  6305. CancelOutDetailId: cancelInfo.ID,
  6306. ProductDate: it.ProductDate,
  6307. ExpireDate: it.ExpiryDate,
  6308. StorehouseId: houseConfig.StorehouseOutInfo,
  6309. OverCount: flush_count_one,
  6310. OperateTime: time.Now().Unix(),
  6311. }
  6312. service.CreateStockFlowOne(flow)
  6313. //if flow.ID > 0 {
  6314. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6315. //}
  6316. }
  6317. }
  6318. //flow := models.VmStockFlow{
  6319. // WarehousingId: info.WarehouseInfotId,
  6320. // GoodId: item.ProjectId,
  6321. // Number: info.Number,
  6322. // LicenseNumber: info.LicenseNumber,
  6323. // Count: prescribingNumber,
  6324. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6325. // PatientId: item.PatientId,
  6326. // SystemTime: info.SysRecordTime,
  6327. // ConsumableType: 7,
  6328. // IsSys: 0,
  6329. // WarehousingOrder: "",
  6330. // WarehouseOutId: info.WarehouseOutId,
  6331. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6332. // IsEdit: 0,
  6333. // CancelStockId: cancel.ID,
  6334. // CancelOrderNumber: cancel.OrderNumber,
  6335. // Manufacturer: manufacturer.ID,
  6336. // Dealer: 0,
  6337. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6338. // UpdateCreator: 0,
  6339. // Status: 1,
  6340. // Ctime: time.Now().Unix(),
  6341. // Mtime: 0,
  6342. // Price: info.Price,
  6343. // WarehousingDetailId: info.WarehouseInfotId,
  6344. // WarehouseOutDetailId: info.ID,
  6345. // CancelOutDetailId: cancelInfo.ID,
  6346. // ProductDate: info.ProductDate,
  6347. // ExpireDate: info.ExpiryDate,
  6348. // StorehouseId: houseConfig.StorehouseOutInfo,
  6349. // OverCount: flush_count,
  6350. //}
  6351. //service.CreateStockFlowOne(flow)
  6352. //退库数量增加
  6353. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6354. //出库数量减少
  6355. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6356. //查询已出库数量
  6357. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6358. if prescribingNumber < dialysisInfo.Count {
  6359. //改变数量
  6360. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6361. }
  6362. if prescribingNumber >= dialysisInfo.Count {
  6363. //删除出库表
  6364. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6365. }
  6366. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6367. var flush_count_one int64
  6368. for _, it := range goodList {
  6369. flush_count_one += it.StockCount
  6370. }
  6371. //更新库存
  6372. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6373. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6374. //更新基础库库存
  6375. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6376. }
  6377. }
  6378. }
  6379. }
  6380. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6381. fmt.Println(err)
  6382. }
  6383. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6384. fmt.Println(err)
  6385. if len(advices) > 0 {
  6386. for _, item := range advices {
  6387. redis := service.RedisClient()
  6388. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6389. redis.Set(keyFive, "", time.Second)
  6390. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6391. redis.Set(keyOne, "", time.Second)
  6392. redis.Close()
  6393. }
  6394. }
  6395. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6396. if len(advices) > 0 {
  6397. for _, item := range advices {
  6398. creater := c.GetAdminUserInfo().AdminUser.Id
  6399. service.DrugAutoAddCancelInfo(item, creater)
  6400. }
  6401. }
  6402. } else {
  6403. if drugOutConfig.IsOpen == 1 {
  6404. if len(advices) > 0 {
  6405. for _, item := range advices {
  6406. creater := c.GetAdminUserInfo().AdminUser.Id
  6407. service.DrugAutoAddCancelInfo(item, creater)
  6408. }
  6409. }
  6410. } else {
  6411. if len(advices) > 0 {
  6412. for _, item := range advices {
  6413. creater := c.GetAdminUserInfo().AdminUser.Id
  6414. service.DrugAutoAddCancelInfo(item, creater)
  6415. }
  6416. }
  6417. }
  6418. }
  6419. c.ServeSuccessJSON(map[string]interface{}{
  6420. "msg": "删除成功",
  6421. })
  6422. return
  6423. }
  6424. func (c *HisApiController) DeleteDoctorAdvice() {
  6425. id, _ := c.GetInt64("id")
  6426. advice, _ := service.GetHisDoctorAdvicesById(id)
  6427. ////同步到自备药
  6428. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6429. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6430. if selfPrescriptionOpen.IsOpen == 1 {
  6431. db := service.XTWriteDB()
  6432. tx := db.Begin()
  6433. defer func() {
  6434. if r := recover(); r != nil {
  6435. tx.Rollback()
  6436. } else {
  6437. tx.Commit()
  6438. }
  6439. }()
  6440. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6441. var total_count int64
  6442. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6443. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6444. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6445. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6446. }
  6447. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6448. total_count += prescribingNumberSeven
  6449. }
  6450. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6451. total_count += prescribingNumberSeven
  6452. }
  6453. timeStr := time.Now().Format("2006-01-02")
  6454. timeArr := strings.Split(timeStr, "-")
  6455. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6456. total = total + 1
  6457. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6458. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6459. number = number + total
  6460. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6461. operation_time := time.Now().Unix()
  6462. creater := c.GetAdminUserInfo().AdminUser.Id
  6463. //创建一个出库单
  6464. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6465. WarehouseOutOrderNumber: warehousing_out_order,
  6466. OperationTime: operation_time,
  6467. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6468. Creater: creater,
  6469. Ctime: time.Now().Unix(),
  6470. Status: 1,
  6471. WarehouseOutTime: advice.AdviceDate,
  6472. Type: 0,
  6473. PatientId: advice.PatientId,
  6474. IsCheck: 1,
  6475. }
  6476. //查询今日是否有出库数据
  6477. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6478. if lastWarehouseOut.ID == 0 {
  6479. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6480. }
  6481. //出库
  6482. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6483. WarehouseOutId: lastWarehouseOut.ID,
  6484. WarehouseOutOrderNumber: warehousing_out_order,
  6485. DrugId: advice.DrugId,
  6486. Count: total_count,
  6487. Price: 0,
  6488. TotalPrice: 0,
  6489. Status: 1,
  6490. Ctime: advice.AdviceDate,
  6491. Mtime: advice.AdviceDate,
  6492. Remark: "",
  6493. OrgId: advice.UserOrgId,
  6494. Type: 0,
  6495. Manufacturer: selfBasedrug.Manufacturer,
  6496. Dealer: selfBasedrug.Dealer,
  6497. RetailPrice: 0,
  6498. RetailTotalPrice: 0,
  6499. CountUnit: advice.PrescribingNumberUnit,
  6500. ExpiryDate: 0,
  6501. ProductDate: 0,
  6502. Number: "",
  6503. BatchNumber: "",
  6504. IsSys: 0,
  6505. WarehouseInfoId: 0,
  6506. AdminUserId: 0,
  6507. StockCount: "",
  6508. IsCheck: 1,
  6509. SysRecordTime: advice.AdviceDate,
  6510. PatientId: advice.PatientId,
  6511. AdviceId: advice.ID,
  6512. ClassType: "",
  6513. }
  6514. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6515. for _, it := range warehousingOutInfo {
  6516. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6517. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6518. //出库逻辑
  6519. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6520. //查询剩余库存
  6521. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6522. var sum_count int64
  6523. for _, its := range stockInfo {
  6524. if its.MaxUnit == medical.MaxUnit {
  6525. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6526. }
  6527. sum_count += its.StockMaxNumber + its.StockMinNumber
  6528. }
  6529. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6530. }
  6531. }
  6532. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6533. //已收费和已发药的限制逻辑
  6534. isCharge := false
  6535. isMedicine := false
  6536. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6537. //获取今天该患者所有处方,判断是否发药或者收费
  6538. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6539. //for _, item := range new_prescriptions {
  6540. if new_prescription.IsMedicine == 1 {
  6541. isMedicine = true
  6542. }
  6543. //}
  6544. for _, item := range new_prescriptions {
  6545. if item.OrderStatus == 4 {
  6546. isCharge = true
  6547. }
  6548. }
  6549. if isMedicine {
  6550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6551. return
  6552. }
  6553. if isCharge {
  6554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6555. return
  6556. }
  6557. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6558. for _, item := range advices {
  6559. if item.IsMedicine == 1 {
  6560. isMedicine = true
  6561. }
  6562. }
  6563. if isMedicine {
  6564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6565. return
  6566. }
  6567. if new_prescription.ID > 0 {
  6568. if new_prescription.OrderStatus == 2 {
  6569. isCharge = true
  6570. }
  6571. }
  6572. if isCharge {
  6573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6574. return
  6575. }
  6576. //已收费和已发药的限制逻辑
  6577. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6578. redis := service.RedisClient()
  6579. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6580. redis.Set(keyFive, "", time.Second)
  6581. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6582. redis.Set(keyOne, "", time.Second)
  6583. defer redis.Close()
  6584. if err == nil {
  6585. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6586. //查询是否在处方中出库
  6587. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6588. if openConfig.IsOpen != 1 {
  6589. //判断该医嘱是否执行了
  6590. if advice.ExecutionState == 1 {
  6591. creater := c.GetAdminUserInfo().AdminUser.Id
  6592. service.DrugAutoAddCancelInfo(&advice, creater)
  6593. }
  6594. }
  6595. //开启保存处方扣减功能
  6596. if openConfig.IsOpen == 1 {
  6597. creater := c.GetAdminUserInfo().AdminUser.Id
  6598. service.DrugAutoAddCancelInfo(&advice, creater)
  6599. }
  6600. } else {
  6601. if drugOutConfig.IsOpen == 1 {
  6602. //查询是否在处方中出库
  6603. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6604. if openConfig.IsOpen != 1 {
  6605. //判断该医嘱是否执行了
  6606. if advice.ExecutionState == 1 {
  6607. creater := c.GetAdminUserInfo().AdminUser.Id
  6608. service.DrugAutoAddCancelInfo(&advice, creater)
  6609. }
  6610. }
  6611. //开启保存处方扣减功能
  6612. if openConfig.IsOpen == 1 {
  6613. creater := c.GetAdminUserInfo().AdminUser.Id
  6614. service.DrugAutoAddCancelInfo(&advice, creater)
  6615. }
  6616. } else {
  6617. //判断该医嘱是否执行了
  6618. if advice.ExecutionState == 1 {
  6619. creater := c.GetAdminUserInfo().AdminUser.Id
  6620. service.DrugAutoAddCancelInfo(&advice, creater)
  6621. }
  6622. }
  6623. }
  6624. c.ServeSuccessJSON(map[string]interface{}{
  6625. "msg": "删除成功",
  6626. })
  6627. return
  6628. } else {
  6629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6630. return
  6631. }
  6632. }
  6633. func (c *HisApiController) DeleteProject() {
  6634. id, _ := c.GetInt64("id")
  6635. adminInfo := c.GetAdminUserInfo()
  6636. project, _ := service.GetHisProjectByID(id)
  6637. // var consumable models.DialysisBeforePrepare
  6638. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6639. //耗材保存处方出库
  6640. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6641. isCharge := false
  6642. isMedicine := false
  6643. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6644. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6645. for _, item := range new_prescriptions {
  6646. if item.IsMedicine == 1 {
  6647. isMedicine = true
  6648. }
  6649. }
  6650. for _, item := range new_prescriptions {
  6651. if item.OrderStatus == 4 {
  6652. isCharge = true
  6653. }
  6654. }
  6655. if isMedicine {
  6656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6657. return
  6658. }
  6659. if isCharge {
  6660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6661. return
  6662. }
  6663. if new_prescription.ID > 0 {
  6664. if new_prescription.OrderStatus == 2 {
  6665. isCharge = true
  6666. }
  6667. }
  6668. if isCharge {
  6669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6670. return
  6671. }
  6672. service.DeletePrintInfo(id)
  6673. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  6674. label.Status = 0
  6675. service.CreateHisLabelRecordTwo(&label)
  6676. fmt.Println(goodOutConfig.IsOpen)
  6677. if goodOutConfig.IsOpen != 1 {
  6678. if stockConfig.IsOpen == 1 {
  6679. if project.Type == 2 {
  6680. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6681. fmt.Println(err)
  6682. }
  6683. if project.Type == 3 && project.IsOut == 1 {
  6684. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6685. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6686. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6687. operation_time := time.Now().Unix()
  6688. creater := adminInfo.AdminUser.Id
  6689. //创建退库单
  6690. timeStr := time.Now().Format("2006-01-02")
  6691. timeArr := strings.Split(timeStr, "-")
  6692. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6693. total = total + 1
  6694. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6695. cancelStock := models.CancelStock{
  6696. OrderNumber: orderNumber,
  6697. OperaTime: operation_time,
  6698. OrgId: adminInfo.CurrentOrgId,
  6699. Creater: creater,
  6700. Ctime: time.Now().Unix(),
  6701. Status: 1,
  6702. ReturnTime: project.RecordDate,
  6703. Type: 1,
  6704. StorehouseId: houseConfig.StorehouseOutInfo,
  6705. IsCheck: 1,
  6706. }
  6707. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6708. if msgerrkonde == gorm.ErrRecordNotFound {
  6709. service.AddSigleCancelStock(&cancelStock)
  6710. }
  6711. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6712. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6713. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6714. //查询是否有出库
  6715. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6716. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6717. deaerler, _ := service.GetDealerById(info.Dealer)
  6718. if info.ID > 0 {
  6719. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6720. if info.Count >= prescribingNumber {
  6721. cancelStockInfo := models.CancelStockInfo{
  6722. GoodId: project.ProjectId,
  6723. CancelStockId: cancel.ID,
  6724. GoodTypeId: good.GoodTypeId,
  6725. Count: prescribingNumber,
  6726. Price: info.Price,
  6727. Total: 0,
  6728. ProductDate: info.ProductDate,
  6729. ExpiryDate: info.ExpiryDate,
  6730. Ctime: time.Now().Unix(),
  6731. Status: 1,
  6732. OrgId: adminInfo.CurrentOrgId,
  6733. OrderNumber: cancel.OrderNumber,
  6734. Type: 0,
  6735. Dealer: deaerler.DealerName,
  6736. Manufacturer: manufacturer.ManufacturerName,
  6737. Number: info.Number,
  6738. RegisterAccount: "",
  6739. Remark: "",
  6740. WarehouseInfoId: info.WarehouseInfotId,
  6741. PatientId: info.PatientId,
  6742. RecordDate: info.SysRecordTime,
  6743. StorehouseId: houseConfig.StorehouseOutInfo,
  6744. IsCheck: 1,
  6745. }
  6746. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6747. //回退库存
  6748. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6749. //退库数量增加
  6750. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6751. //出库数量减少
  6752. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6753. }
  6754. if info.Count < prescribingNumber {
  6755. cancelStockInfo := models.CancelStockInfo{
  6756. GoodId: project.ProjectId,
  6757. CancelStockId: cancel.ID,
  6758. GoodTypeId: good.GoodTypeId,
  6759. Count: info.Count,
  6760. Price: info.Price,
  6761. Total: 0,
  6762. ProductDate: info.ProductDate,
  6763. ExpiryDate: info.ExpiryDate,
  6764. Ctime: time.Now().Unix(),
  6765. Status: 1,
  6766. OrgId: adminInfo.CurrentOrgId,
  6767. OrderNumber: cancel.OrderNumber,
  6768. Type: 0,
  6769. Dealer: deaerler.DealerName,
  6770. Manufacturer: manufacturer.ManufacturerName,
  6771. Number: info.Number,
  6772. RegisterAccount: "",
  6773. Remark: "",
  6774. WarehouseInfoId: info.WarehouseInfotId,
  6775. PatientId: info.PatientId,
  6776. RecordDate: info.SysRecordTime,
  6777. StorehouseId: houseConfig.StorehouseOutInfo,
  6778. IsCheck: 1,
  6779. }
  6780. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6781. //回退库存
  6782. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6783. //退库数量增加
  6784. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6785. //出库数量减少
  6786. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6787. }
  6788. //查询剩余库存
  6789. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6790. var over_count int64
  6791. for _, it := range goodList {
  6792. over_count += it.StockCount
  6793. }
  6794. //出库数据 大于 退库数量
  6795. if info.Count >= prescribingNumber {
  6796. flow := models.VmStockFlow{
  6797. WarehousingId: info.WarehouseInfotId,
  6798. GoodId: project.ProjectId,
  6799. Number: info.Number,
  6800. LicenseNumber: info.LicenseNumber,
  6801. Count: prescribingNumber,
  6802. UserOrgId: adminInfo.CurrentOrgId,
  6803. PatientId: project.PatientId,
  6804. SystemTime: info.SysRecordTime,
  6805. ConsumableType: 7,
  6806. IsSys: 0,
  6807. WarehousingOrder: "",
  6808. WarehouseOutId: info.WarehouseOutId,
  6809. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6810. IsEdit: 0,
  6811. CancelStockId: cancel.ID,
  6812. CancelOrderNumber: cancel.OrderNumber,
  6813. Manufacturer: manufacturer.ID,
  6814. Dealer: 0,
  6815. Creator: adminInfo.AdminUser.Id,
  6816. UpdateCreator: 0,
  6817. Status: 1,
  6818. Ctime: time.Now().Unix(),
  6819. Mtime: 0,
  6820. Price: info.Price,
  6821. WarehousingDetailId: info.WarehouseInfotId,
  6822. WarehouseOutDetailId: info.ID,
  6823. CancelOutDetailId: cancelInfo.ID,
  6824. ProductDate: info.ProductDate,
  6825. ExpireDate: info.ExpiryDate,
  6826. StorehouseId: houseConfig.StorehouseOutInfo,
  6827. OverCount: over_count,
  6828. OperateTime: time.Now().Unix(),
  6829. }
  6830. service.CreateStockFlowOne(flow)
  6831. }
  6832. //出库数据小于退库数据
  6833. if info.Count < prescribingNumber {
  6834. flow := models.VmStockFlow{
  6835. WarehousingId: info.WarehouseInfotId,
  6836. GoodId: project.ProjectId,
  6837. Number: info.Number,
  6838. LicenseNumber: info.LicenseNumber,
  6839. Count: info.Count,
  6840. UserOrgId: adminInfo.CurrentOrgId,
  6841. PatientId: project.PatientId,
  6842. SystemTime: info.SysRecordTime,
  6843. ConsumableType: 7,
  6844. IsSys: 0,
  6845. WarehousingOrder: "",
  6846. WarehouseOutId: info.WarehouseOutId,
  6847. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6848. IsEdit: 0,
  6849. CancelStockId: cancel.ID,
  6850. CancelOrderNumber: cancel.OrderNumber,
  6851. Manufacturer: manufacturer.ID,
  6852. Dealer: 0,
  6853. Creator: adminInfo.AdminUser.Id,
  6854. UpdateCreator: 0,
  6855. Status: 1,
  6856. Ctime: time.Now().Unix(),
  6857. Mtime: 0,
  6858. Price: info.Price,
  6859. WarehousingDetailId: info.WarehouseInfotId,
  6860. WarehouseOutDetailId: info.ID,
  6861. CancelOutDetailId: cancelInfo.ID,
  6862. ProductDate: info.ProductDate,
  6863. ExpireDate: info.ExpiryDate,
  6864. StorehouseId: houseConfig.StorehouseOutInfo,
  6865. OverCount: over_count,
  6866. OperateTime: time.Now().Unix(),
  6867. }
  6868. service.CreateStockFlowOne(flow)
  6869. }
  6870. //查询已出库数量
  6871. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6872. if prescribingNumber < dialysisInfo.Count {
  6873. //改变数量
  6874. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6875. }
  6876. if prescribingNumber >= dialysisInfo.Count {
  6877. //删除出库表
  6878. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6879. }
  6880. //更新剩余库存
  6881. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6882. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6883. var total_count_one int64
  6884. for _, it := range stockList {
  6885. total_count_one += it.StockCount
  6886. }
  6887. //基础库插入数据
  6888. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6889. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6890. var flush_count int64
  6891. for _, it := range goodListOne {
  6892. flush_count += it.StockCount
  6893. }
  6894. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6895. if errs != nil {
  6896. goodErrcode := models.XtGoodErrcode{
  6897. UserOrgId: project.UserOrgId,
  6898. Errcode: "手动出库更新剩余出库失败",
  6899. GoodId: project.ProjectId,
  6900. Status: 1,
  6901. Ctime: time.Now().Unix(),
  6902. Mtime: 0,
  6903. Count: 0,
  6904. StockCount: 0,
  6905. Creater: creater,
  6906. BatchNumberId: 0,
  6907. WarehouseOutId: 0,
  6908. }
  6909. service.CreateGoodErrcode(goodErrcode)
  6910. }
  6911. }
  6912. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6913. fmt.Println(err)
  6914. } else {
  6915. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6916. fmt.Println(err)
  6917. }
  6918. } else {
  6919. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6920. fmt.Println(err)
  6921. }
  6922. }
  6923. //保存处方出库
  6924. if goodOutConfig.IsOpen == 1 {
  6925. if project.Type == 3 {
  6926. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6927. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6928. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6929. operation_time := time.Now().Unix()
  6930. creater := adminInfo.AdminUser.Id
  6931. //创建退库单
  6932. timeStr := time.Now().Format("2006-01-02")
  6933. timeArr := strings.Split(timeStr, "-")
  6934. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6935. total = total + 1
  6936. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6937. cancelStock := models.CancelStock{
  6938. OrderNumber: orderNumber,
  6939. OperaTime: operation_time,
  6940. OrgId: adminInfo.CurrentOrgId,
  6941. Creater: creater,
  6942. Ctime: time.Now().Unix(),
  6943. Status: 1,
  6944. ReturnTime: project.RecordDate,
  6945. Type: 1,
  6946. StorehouseId: houseConfig.StorehouseOutInfo,
  6947. IsCheck: 1,
  6948. }
  6949. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6950. if msgerrkonde == gorm.ErrRecordNotFound {
  6951. service.AddSigleCancelStock(&cancelStock)
  6952. }
  6953. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6954. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6955. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6956. //获取出库数据
  6957. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6958. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6959. deaerler, _ := service.GetDealerById(info.Dealer)
  6960. if info.ID > 0 {
  6961. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6962. if info.Count >= prescribingNumber {
  6963. cancelStockInfo := models.CancelStockInfo{
  6964. GoodId: project.ProjectId,
  6965. CancelStockId: cancel.ID,
  6966. GoodTypeId: good.GoodTypeId,
  6967. Count: prescribingNumber,
  6968. Price: info.Price,
  6969. Total: 0,
  6970. ProductDate: info.ProductDate,
  6971. ExpiryDate: info.ExpiryDate,
  6972. Ctime: time.Now().Unix(),
  6973. Status: 1,
  6974. OrgId: adminInfo.CurrentOrgId,
  6975. OrderNumber: cancel.OrderNumber,
  6976. Type: 0,
  6977. Dealer: deaerler.DealerName,
  6978. Manufacturer: manufacturer.ManufacturerName,
  6979. Number: info.Number,
  6980. RegisterAccount: "",
  6981. Remark: "",
  6982. WarehouseInfoId: info.WarehouseInfotId,
  6983. PatientId: info.PatientId,
  6984. RecordDate: info.SysRecordTime,
  6985. StorehouseId: houseConfig.StorehouseOutInfo,
  6986. IsCheck: 1,
  6987. }
  6988. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6989. //退库数量增加
  6990. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6991. //出库数量减少
  6992. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6993. }
  6994. if info.Count < prescribingNumber {
  6995. cancelStockInfo := models.CancelStockInfo{
  6996. GoodId: project.ProjectId,
  6997. CancelStockId: cancel.ID,
  6998. GoodTypeId: good.GoodTypeId,
  6999. Count: prescribingNumber,
  7000. Price: info.Price,
  7001. Total: 0,
  7002. ProductDate: info.ProductDate,
  7003. ExpiryDate: info.ExpiryDate,
  7004. Ctime: time.Now().Unix(),
  7005. Status: 1,
  7006. OrgId: adminInfo.CurrentOrgId,
  7007. OrderNumber: cancel.OrderNumber,
  7008. Type: 0,
  7009. Dealer: deaerler.DealerName,
  7010. Manufacturer: manufacturer.ManufacturerName,
  7011. Number: info.Number,
  7012. RegisterAccount: "",
  7013. Remark: "",
  7014. WarehouseInfoId: info.WarehouseInfotId,
  7015. PatientId: info.PatientId,
  7016. RecordDate: info.SysRecordTime,
  7017. StorehouseId: houseConfig.StorehouseOutInfo,
  7018. IsCheck: 1,
  7019. }
  7020. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7021. //回退库存
  7022. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7023. }
  7024. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7025. var over_count int64
  7026. for _, it := range goodList {
  7027. over_count += it.StockCount
  7028. }
  7029. //查询出库数量
  7030. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  7031. //出库数据 大于 退库数量
  7032. if len(list) > 0 {
  7033. for _, it := range list {
  7034. //回退库存
  7035. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  7036. //退库数量增加
  7037. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  7038. //出库数量减少
  7039. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  7040. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7041. var over_count_one int64
  7042. for _, it := range goodList {
  7043. over_count_one += it.StockCount
  7044. }
  7045. //查询该批次是否有退库数据
  7046. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  7047. flow := models.VmStockFlow{
  7048. WarehousingId: it.WarehouseInfotId,
  7049. GoodId: it.GoodId,
  7050. Number: it.Number,
  7051. LicenseNumber: it.LicenseNumber,
  7052. Count: it.Count,
  7053. UserOrgId: adminInfo.CurrentOrgId,
  7054. PatientId: it.PatientId,
  7055. SystemTime: it.SysRecordTime,
  7056. ConsumableType: 7,
  7057. IsSys: 0,
  7058. WarehousingOrder: "",
  7059. WarehouseOutId: it.WarehouseOutId,
  7060. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7061. IsEdit: 0,
  7062. CancelStockId: cancel.ID,
  7063. CancelOrderNumber: cancel.OrderNumber,
  7064. Manufacturer: manufacturer.ID,
  7065. Dealer: 0,
  7066. Creator: adminInfo.AdminUser.Id,
  7067. UpdateCreator: 0,
  7068. Status: 1,
  7069. Ctime: time.Now().Unix(),
  7070. Mtime: 0,
  7071. Price: it.Price,
  7072. WarehousingDetailId: it.WarehouseInfotId,
  7073. WarehouseOutDetailId: it.ID,
  7074. CancelOutDetailId: cancelInfo.ID,
  7075. ProductDate: it.ProductDate,
  7076. ExpireDate: it.ExpiryDate,
  7077. StorehouseId: houseConfig.StorehouseOutInfo,
  7078. OverCount: over_count_one,
  7079. OperateTime: time.Now().Unix(),
  7080. }
  7081. service.CreateStockFlowOne(flow)
  7082. }
  7083. }
  7084. //查询已出库数量
  7085. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7086. if prescribingNumber < dialysisInfo.Count {
  7087. //改变数量
  7088. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7089. }
  7090. if prescribingNumber >= dialysisInfo.Count {
  7091. //删除出库表
  7092. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7093. }
  7094. //更新剩余库存
  7095. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7096. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7097. var total_count_one int64
  7098. for _, it := range stockList {
  7099. total_count_one += it.StockCount
  7100. }
  7101. //基础库插入数据
  7102. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7103. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7104. var flush_count int64
  7105. for _, it := range goodListOne {
  7106. flush_count += it.StockCount
  7107. }
  7108. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7109. if errs != nil {
  7110. goodErrcode := models.XtGoodErrcode{
  7111. UserOrgId: project.UserOrgId,
  7112. Errcode: "手动出库更新剩余出库失败",
  7113. GoodId: project.ProjectId,
  7114. Status: 1,
  7115. Ctime: time.Now().Unix(),
  7116. Mtime: 0,
  7117. Count: 0,
  7118. StockCount: 0,
  7119. Creater: creater,
  7120. BatchNumberId: 0,
  7121. WarehouseOutId: 0,
  7122. }
  7123. service.CreateGoodErrcode(goodErrcode)
  7124. }
  7125. }
  7126. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7127. fmt.Println(err)
  7128. } else {
  7129. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7130. fmt.Println(err)
  7131. }
  7132. }
  7133. c.ServeSuccessJSON(map[string]interface{}{
  7134. "msg": "删除成功",
  7135. })
  7136. return
  7137. }
  7138. func (c *HisApiController) CreateHisAdditionalCharge() {
  7139. his_patient_id, _ := c.GetInt64("his_patient_id")
  7140. patient_id, _ := c.GetInt64("patient_id")
  7141. record_date := c.GetString("record_date")
  7142. timeLayout := "2006-01-02"
  7143. loc, _ := time.LoadLocation("Local")
  7144. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7145. if err != nil {
  7146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7147. return
  7148. }
  7149. adminInfo := c.GetAdminUserInfo()
  7150. recordDateTime := theTime.Unix()
  7151. dataBody := make(map[string]interface{}, 0)
  7152. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7153. if err != nil {
  7154. utils.ErrorLog(err.Error())
  7155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7156. return
  7157. }
  7158. var additions []*models.HisAdditionalCharge
  7159. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7160. additions, _ := dataBody["addition"].([]interface{})
  7161. if len(additions) > 0 {
  7162. for _, item := range additions {
  7163. items := item.(map[string]interface{})
  7164. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7165. utils.ErrorLog("item_id")
  7166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7167. return
  7168. }
  7169. item_id := int64(items["item_id"].(float64))
  7170. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7171. utils.ErrorLog("item_name")
  7172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7173. return
  7174. }
  7175. item_name := items["item_name"].(string)
  7176. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7177. utils.ErrorLog("price")
  7178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7179. return
  7180. }
  7181. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7182. ctime := time.Now().Unix()
  7183. additional := &models.HisAdditionalCharge{
  7184. PatientId: patient_id,
  7185. HisPatientId: his_patient_id,
  7186. UserOrgId: adminInfo.CurrentOrgId,
  7187. RecordDate: recordDateTime,
  7188. CreatedTime: ctime,
  7189. UpdatedTime: ctime,
  7190. Modifier: adminInfo.AdminUser.Id,
  7191. Creator: adminInfo.AdminUser.Id,
  7192. Price: price,
  7193. ItemName: item_name,
  7194. ItemId: item_id,
  7195. Status: 1,
  7196. }
  7197. additions = append(additions, additional)
  7198. }
  7199. }
  7200. }
  7201. for _, item := range additions {
  7202. service.CreateAddtionalCharge(item)
  7203. }
  7204. c.ServeSuccessJSON(map[string]interface{}{
  7205. "msg": "创建成功",
  7206. })
  7207. }
  7208. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7209. blood_fat := c.GetString("blood_fat")
  7210. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7211. blood_sugar := c.GetString("blood_sugar")
  7212. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7213. chief_conplaint := c.GetString("chief_conplaint")
  7214. dbp := c.GetString("dbp")
  7215. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7216. delivery_way, _ := c.GetInt64("delivery_way")
  7217. diagnostic := c.GetString("diagnostic")
  7218. family_history := c.GetString("family_history")
  7219. height := c.GetString("height")
  7220. history_of_present_illness := c.GetString("history_of_present_illness")
  7221. is_infect, _ := c.GetInt64("is_infect")
  7222. past_history := c.GetString("past_history")
  7223. patient_id, _ := c.GetInt64("patient_id")
  7224. his_patient_id, _ := c.GetInt64("his_patient_id")
  7225. personal_history := c.GetString("personal_history")
  7226. pulse := c.GetString("pulse")
  7227. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7228. sbp := c.GetString("sbp")
  7229. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7230. heightfloat, _ := strconv.ParseFloat(height, 64)
  7231. sicktype := c.GetString("sick_type")
  7232. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7233. symptom := c.GetString("symptom")
  7234. sick_date := c.GetString("sick_date")
  7235. temperatures := c.GetString("temperature")
  7236. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7237. record_date := c.GetString("record_date")
  7238. breathing := c.GetString("breathing")
  7239. doctor_advice := c.GetString("doctor_advice")
  7240. remark := c.GetString("remark")
  7241. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7242. sick, _ := c.GetInt64("sick")
  7243. diagnose, _ := c.GetInt64("diagnose")
  7244. //id, _ := c.GetInt64("id")
  7245. timeLayout := "2006-01-02"
  7246. loc, _ := time.LoadLocation("Local")
  7247. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7248. allergic_history := c.GetString("allergic_history")
  7249. if err != nil {
  7250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7251. return
  7252. }
  7253. recordDateTime := theTime.Unix()
  7254. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7255. if err != nil {
  7256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7257. return
  7258. }
  7259. sickTimes := sickTime.Unix()
  7260. ctime := time.Now().Unix()
  7261. primary_disease := c.GetString("primary_disease")
  7262. confirm_failure_date := c.GetString("confirm_failure_date")
  7263. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7264. drug_allergy_history := c.GetString("drug_allergy_history")
  7265. physical_examination := c.GetString("physical_examination")
  7266. special_inspection := c.GetString("special_inspection")
  7267. lab_apparatus := c.GetString("lab_apparatus")
  7268. caseHistory := models.HisPatientCaseHistory{
  7269. HisPatientId: his_patient_id,
  7270. PatientId: patient_id,
  7271. Temperature: temperature,
  7272. BloodSugar: bloodsugarfloat,
  7273. Pulse: pulsefloat,
  7274. Sbp: sbpfloat,
  7275. Dbp: dbpfloat,
  7276. Height: heightfloat,
  7277. BloodFat: bloodfatfloat,
  7278. SickType: sick_type,
  7279. Symptom: symptom,
  7280. SickDate: sickTimes,
  7281. IsInfect: is_infect,
  7282. HistoryOfPresentIllness: history_of_present_illness,
  7283. PastHistory: past_history,
  7284. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7285. ChiefConplaint: chief_conplaint,
  7286. PersonalHistory: personal_history,
  7287. FamilyHistory: family_history,
  7288. Diagnostic: diagnostic,
  7289. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7290. Status: 1,
  7291. Ctime: ctime,
  7292. Mtime: ctime,
  7293. RecordDate: recordDateTime,
  7294. DeliveryWay: delivery_way,
  7295. Breathing: breathingfloat,
  7296. DoctorAdvice: doctor_advice,
  7297. Remark: remark,
  7298. Sick: sick,
  7299. Diagnose: diagnose,
  7300. AllergicHistory: allergic_history,
  7301. PrimaryDisease: primary_disease,
  7302. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7303. DrugAllergyHistory: drug_allergy_history,
  7304. PhysicalExamination: physical_examination,
  7305. SpecialInspection: special_inspection,
  7306. LabApparatus: lab_apparatus,
  7307. }
  7308. //查询该患者是否有病历
  7309. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7310. if errcodes == gorm.ErrRecordNotFound {
  7311. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7312. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7313. if err != nil {
  7314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7315. return
  7316. }
  7317. c.ServeSuccessJSON(map[string]interface{}{
  7318. "caseHistory": caseHistory,
  7319. "historyInfo": historyInfo,
  7320. })
  7321. return
  7322. } else if errcodes == nil {
  7323. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7324. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7325. if err != nil {
  7326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7327. return
  7328. }
  7329. c.ServeSuccessJSON(map[string]interface{}{
  7330. "caseHistory": caseHistory,
  7331. "historyInfo": historyInfo,
  7332. })
  7333. }
  7334. //查询该患者是否有病历
  7335. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7336. //if errcode == gorm.ErrRecordNotFound {
  7337. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7338. // if err != nil {
  7339. // c.ServeSuccessJSON(map[string]interface{}{
  7340. // "msg": "保存成功",
  7341. // })
  7342. // }
  7343. //} else if errcode == nil {
  7344. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7345. // return
  7346. //}
  7347. }
  7348. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7349. patient_id, _ := c.GetInt64("patient_id", 0)
  7350. adminUser := c.GetAdminUserInfo()
  7351. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7352. c.ServeSuccessJSON(map[string]interface{}{
  7353. "list": caseHistorys,
  7354. })
  7355. }
  7356. func (c *HisApiController) GetHisPatientCaseHistory() {
  7357. record_date, _ := c.GetInt64("record_date", 0)
  7358. patient_id, _ := c.GetInt64("patient_id", 0)
  7359. admin := c.GetAdminUserInfo()
  7360. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7361. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7362. c.ServeSuccessJSON(map[string]interface{}{
  7363. "info": info,
  7364. "case_history": case_history,
  7365. })
  7366. }
  7367. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7368. template_name := c.GetString("template_name")
  7369. template_remark := c.GetString("template_remark")
  7370. doctor := c.GetAdminUserInfo().AdminUser.Id
  7371. diagnostic := c.GetString("diagnostic")
  7372. chief_conplaint := c.GetString("chief_conplain")
  7373. history_of_present_illness := c.GetString("history_of_present_illness")
  7374. past_history := c.GetString("past_history")
  7375. personal_history := c.GetString("personal_history")
  7376. family_history := c.GetString("family_history")
  7377. user_name := c.GetString("user_name")
  7378. doctor_advice := c.GetString("doctor_advice")
  7379. remark := c.GetString("remark")
  7380. //record_date := c.GetString("record_date")
  7381. //fmt.Println("record_date--------",record_date)
  7382. //timeLayout := "2006-01-02"
  7383. //loc, _ := time.LoadLocation("Local")
  7384. //
  7385. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7386. //if err != nil {
  7387. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7388. // return
  7389. //}
  7390. //recordDateTime := theTime.Unix()
  7391. ctime := time.Now().Unix()
  7392. template := models.HisCaseHistoryTemplate{
  7393. HistoryOfPresentIllness: history_of_present_illness,
  7394. PastHistory: past_history,
  7395. ChiefConplaint: chief_conplaint,
  7396. PersonalHistory: personal_history,
  7397. FamilyHistory: family_history,
  7398. Diagnostic: diagnostic,
  7399. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7400. Status: 1,
  7401. Ctime: ctime,
  7402. Mtime: ctime,
  7403. RecordDate: time.Now().Unix(),
  7404. TemplateName: template_name,
  7405. TemplateRemark: template_remark,
  7406. Creator: doctor,
  7407. Modifier: doctor,
  7408. UserName: user_name,
  7409. DoctorAdvice: doctor_advice,
  7410. Remark: remark,
  7411. }
  7412. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7413. if err == nil {
  7414. c.ServeSuccessJSON(map[string]interface{}{
  7415. "msg": "保存成功",
  7416. })
  7417. } else {
  7418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7419. return
  7420. }
  7421. }
  7422. func (c *HisApiController) GetCaseHistoryTemplate() {
  7423. timeLayout := "2006-01-02"
  7424. loc, _ := time.LoadLocation("Local")
  7425. keyword := c.GetString("keyword")
  7426. start_time := c.GetString("start_time")
  7427. end_time := c.GetString("end_time")
  7428. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7429. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7430. admin := c.GetAdminUserInfo()
  7431. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7432. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7433. c.ServeSuccessJSON(map[string]interface{}{
  7434. "template": template,
  7435. //"history": history,
  7436. })
  7437. }
  7438. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7439. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7440. utils.ErrorLog("drug_name")
  7441. return enums.ErrorCodeParamWrong
  7442. }
  7443. adviceName, _ := json["drug_name"].(string)
  7444. if len(adviceName) == 0 {
  7445. utils.ErrorLog("len(advice_name) == 0")
  7446. return enums.ErrorCodeParamWrong
  7447. }
  7448. advice.AdviceName = adviceName
  7449. adviceDesc, _ := json["advice_desc"].(string)
  7450. advice.AdviceDesc = adviceDesc
  7451. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7452. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7453. advice.DrugSpec = drugSpec
  7454. }
  7455. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7456. remark, _ := json["remark"].(string)
  7457. advice.Remark = remark
  7458. }
  7459. if json["id"] == nil {
  7460. advice.DrugId = 0
  7461. } else {
  7462. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7463. drug_id := int64(json["id"].(float64))
  7464. advice.DrugId = drug_id
  7465. }
  7466. }
  7467. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7468. advice_id := int64(json["advice_id"].(float64))
  7469. advice.ID = advice_id
  7470. if advice.ID > 0 {
  7471. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7472. if err == nil {
  7473. if hisAdvice.ID > 0 {
  7474. advice.ExecutionTime = hisAdvice.ExecutionTime
  7475. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7476. advice.ExecutionState = hisAdvice.ExecutionState
  7477. advice.CheckTime = hisAdvice.CheckTime
  7478. advice.Checker = hisAdvice.Checker
  7479. advice.CheckState = hisAdvice.CheckState
  7480. advice.StartTime = hisAdvice.StartTime
  7481. advice.FeedetlSn = hisAdvice.FeedetlSn
  7482. }
  7483. }
  7484. }
  7485. }
  7486. //
  7487. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7488. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7489. // advice.ExecutionTime = execution_time
  7490. //}
  7491. //
  7492. //
  7493. //
  7494. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7495. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7496. // advice.ExecutionStaff = execution_staff
  7497. //}
  7498. //
  7499. //
  7500. //
  7501. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7502. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7503. // advice.ExecutionState = execution_state
  7504. //}
  7505. //
  7506. //
  7507. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7508. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7509. // advice.CheckTime = check_time
  7510. //}
  7511. //
  7512. //
  7513. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7514. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7515. // advice.CheckState = check_state
  7516. //}
  7517. //
  7518. //
  7519. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7520. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7521. // advice.Checker = checker
  7522. //}
  7523. //
  7524. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7525. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7526. // advice.StartTime = start_time
  7527. //}
  7528. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7529. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7530. advice.IsSelfDrug = is_self_drug
  7531. }
  7532. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7533. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7534. drug_way_count, _ := json["drug_way_count"].(string)
  7535. advice.DrugWayCount = drug_way_count
  7536. }
  7537. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7538. drugSpecUnit, _ := json["min_unit"].(string)
  7539. advice.DrugSpecUnit = drugSpecUnit
  7540. }
  7541. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7542. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7543. advice.SingleDose = singleDose
  7544. }
  7545. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7546. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7547. advice.SingleDoseUnit = singleDoseUnit
  7548. }
  7549. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7550. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7551. advice.PrescribingNumber = prescribingNumber
  7552. }
  7553. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7554. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7555. advice.PrescribingNumberUnit = prescribingNumberUnit
  7556. }
  7557. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7558. deliveryWay, _ := json["delivery_way"].(string)
  7559. advice.DeliveryWay = deliveryWay
  7560. }
  7561. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7562. executionFrequency, _ := json["execution_frequency"].(string)
  7563. advice.ExecutionFrequency = executionFrequency
  7564. }
  7565. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7566. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7567. advice.Price = price
  7568. }
  7569. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7570. med_list_codg, _ := json["medical_insurance_number"].(string)
  7571. advice.MedListCodg = med_list_codg
  7572. }
  7573. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7574. day := int64(json["day"].(float64))
  7575. advice.Day = day
  7576. }
  7577. return 0
  7578. }
  7579. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7580. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7581. id := int64(json["id"].(float64))
  7582. project.ID = id
  7583. historyProject, _ := service.GetHisProjectByID(id)
  7584. project.FeedetlSn = historyProject.FeedetlSn
  7585. }
  7586. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7587. project_id := int64(json["project_id"].(float64))
  7588. project.ProjectId = project_id
  7589. }
  7590. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7591. // price := int64(json["price"].(float64))
  7592. // formatInt_price := strconv.FormatInt(price, 10)
  7593. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7594. // project.Price = float_price
  7595. // }
  7596. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7597. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7598. project.Price = price
  7599. }
  7600. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7601. total, _ := json["total"].(string)
  7602. project.Count = total
  7603. }
  7604. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7605. medical_code, _ := json["medical_code"].(string)
  7606. project.MedListCodg = medical_code
  7607. }
  7608. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7609. single_dose, _ := json["single_dose"].(string)
  7610. project.SingleDose = single_dose
  7611. }
  7612. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7613. delivery_way, _ := json["delivery_way"].(string)
  7614. project.DeliveryWay = delivery_way
  7615. }
  7616. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7617. execution_frequency, _ := json["execution_frequency"].(string)
  7618. project.ExecutionFrequency = execution_frequency
  7619. }
  7620. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7621. remark, _ := json["remark"].(string)
  7622. project.Remark = remark
  7623. }
  7624. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7625. day, _ := json["number_days"].(string)
  7626. project.Day = day
  7627. }
  7628. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7629. unit, _ := json["unit"].(string)
  7630. project.Unit = unit
  7631. }
  7632. return 0
  7633. }
  7634. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7635. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7636. id := int64(json["id"].(float64))
  7637. historyAddtions, _ := service.GetHisAdditionByID(id)
  7638. additionalCharge.ID = id
  7639. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  7640. }
  7641. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7642. item_id := int64(json["item_id"].(float64))
  7643. additionalCharge.ItemId = item_id
  7644. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7645. if config.ID > 0 {
  7646. if len(config.Code) > 0 {
  7647. additionalCharge.MedListCodg = config.Code
  7648. }
  7649. }
  7650. }
  7651. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7652. // price := int64(json["price"].(float64))
  7653. // formatInt_price := strconv.FormatInt(price, 10)
  7654. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7655. // additionalCharge.Price = float_price
  7656. // }
  7657. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7658. // price := int64(json["price"].(float64))
  7659. // formatInt_price := strconv.FormatInt(price, 10)
  7660. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7661. // additionalCharge.Price = float_price
  7662. //}
  7663. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7664. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7665. additionalCharge.Price = price
  7666. }
  7667. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7668. count, _ := json["count"].(string)
  7669. counts, _ := strconv.ParseInt(count, 10, 64)
  7670. additionalCharge.Count = counts
  7671. }
  7672. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7673. item_name, _ := json["item_name"].(string)
  7674. additionalCharge.ItemName = item_name
  7675. }
  7676. return 0
  7677. }
  7678. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7679. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7680. utils.ErrorLog("drug_name")
  7681. return enums.ErrorCodeParamWrong
  7682. }
  7683. adviceName, _ := json["drug_name"].(string)
  7684. if len(adviceName) == 0 {
  7685. utils.ErrorLog("len(advice_name) == 0")
  7686. return enums.ErrorCodeParamWrong
  7687. }
  7688. advice.AdviceName = adviceName
  7689. adviceDesc, _ := json["advice_desc"].(string)
  7690. advice.AdviceDesc = adviceDesc
  7691. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7692. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7693. advice.DrugSpec = drugSpec
  7694. }
  7695. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7696. remark, _ := json["remark"].(string)
  7697. advice.Remark = remark
  7698. }
  7699. if json["id"] == nil {
  7700. advice.DrugId = 0
  7701. } else {
  7702. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7703. drug_id := int64(json["id"].(float64))
  7704. advice.DrugId = drug_id
  7705. }
  7706. }
  7707. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7708. groupno := int64(json["groupno"].(float64))
  7709. advice.Groupno = groupno
  7710. }
  7711. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7712. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7713. advice.IsSelfDrug = is_self_drug
  7714. }
  7715. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7716. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7717. drug_way_count, _ := json["drug_way_count"].(string)
  7718. advice.DrugWayCount = drug_way_count
  7719. }
  7720. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7721. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7722. advice.HospApprFlag = hosp_appr_flag
  7723. }
  7724. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7725. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7726. advice.PrescribingNumber = prescribingNumber
  7727. }
  7728. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7729. // frequency_type := int64(json["frequency_type"].(float64))
  7730. // advice.FrequencyType = frequency_type
  7731. //}
  7732. //
  7733. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7734. // day_count := int64(json["day_count"].(float64))
  7735. // advice.DayCount = day_count
  7736. //}
  7737. //
  7738. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7739. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7740. // week_day, _ := json["week_day"].(string)
  7741. // advice.WeekDay = week_day
  7742. //}
  7743. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7744. drugSpecUnit, _ := json["min_unit"].(string)
  7745. advice.DrugSpecUnit = drugSpecUnit
  7746. }
  7747. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7748. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7749. advice.SingleDose = singleDose
  7750. }
  7751. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7752. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7753. advice.SingleDoseUnit = singleDoseUnit
  7754. }
  7755. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7756. deliveryWay, _ := json["delivery_way"].(string)
  7757. advice.DeliveryWay = deliveryWay
  7758. }
  7759. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7760. executionFrequency, _ := json["execution_frequency"].(string)
  7761. advice.ExecutionFrequency = executionFrequency
  7762. }
  7763. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7764. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7765. advice.Price = price
  7766. }
  7767. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7768. med_list_codg, _ := json["medical_insurance_number"].(string)
  7769. advice.MedListCodg = med_list_codg
  7770. }
  7771. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7772. day := int64(json["day"].(float64))
  7773. advice.Day = day
  7774. }
  7775. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7776. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7777. advice.PrescribingNumberUnit = prescribingNumberUnit
  7778. }
  7779. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7780. advice_id := int64(json["advice_id"].(float64))
  7781. advice.ID = advice_id
  7782. if advice.ID > 0 {
  7783. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7784. if err == nil {
  7785. if hisAdvice.ID > 0 {
  7786. advice.ExecutionTime = hisAdvice.ExecutionTime
  7787. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7788. advice.ExecutionState = hisAdvice.ExecutionState
  7789. advice.CheckTime = hisAdvice.CheckTime
  7790. advice.Checker = hisAdvice.Checker
  7791. advice.CheckState = hisAdvice.CheckState
  7792. advice.StartTime = hisAdvice.StartTime
  7793. advice.HospApprFlag = hisAdvice.HospApprFlag
  7794. advice.IsMedicine = hisAdvice.IsMedicine
  7795. if hisAdvice.UserOrgId == 10028 {
  7796. 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 {
  7797. advice.ExecutionTime = 0
  7798. advice.ExecutionStaff = 0
  7799. advice.ExecutionState = 2
  7800. advice.CheckTime = 0
  7801. advice.Checker = 0
  7802. advice.CheckState = 2
  7803. }
  7804. } else {
  7805. 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 {
  7806. advice.ExecutionTime = 0
  7807. advice.ExecutionStaff = 0
  7808. advice.ExecutionState = 2
  7809. advice.CheckTime = 0
  7810. advice.Checker = 0
  7811. advice.CheckState = 2
  7812. advice.UpdatedTime = time.Now().Unix()
  7813. }
  7814. }
  7815. //advice.Groupno = hisAdvice.Groupno
  7816. }
  7817. }
  7818. }
  7819. }
  7820. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7821. //
  7822. //if drugStockConfig.IsOpen == 1 {
  7823. //
  7824. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7825. // if advice.ID == 0 { //医嘱不存在
  7826. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7827. // drug.Total = drug.Total - advice.PrescribingNumber
  7828. // service.UpdateBaseDrugLib(&drug)
  7829. //
  7830. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7831. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7832. // drug.Total = drug.Total - num
  7833. // service.UpdateBaseDrugLib(&drug)
  7834. // }
  7835. //
  7836. // } else if advice.ID > 0 { //医嘱存在
  7837. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7838. // var num float64
  7839. //
  7840. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7841. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7842. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7843. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7844. // drug.Total = drug.Total + num
  7845. // service.UpdateBaseDrugLib(&drug)
  7846. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7847. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7848. // drug.Total = drug.Total - num
  7849. // service.UpdateBaseDrugLib(&drug)
  7850. // }
  7851. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7852. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7853. // if num2 > advice.PrescribingNumber {
  7854. // num = num2 - advice.PrescribingNumber
  7855. // drug.Total = drug.Total + num
  7856. // service.UpdateBaseDrugLib(&drug)
  7857. // } else if num2 < advice.PrescribingNumber {
  7858. // num = advice.PrescribingNumber - num2
  7859. // drug.Total = drug.Total - num
  7860. // service.UpdateBaseDrugLib(&drug)
  7861. // }
  7862. //
  7863. // }
  7864. //
  7865. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7866. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7867. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7868. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7869. // if num1 > num2 {
  7870. // num = num1 - num2
  7871. // drug.Total = drug.Total + num
  7872. // service.UpdateBaseDrugLib(&drug)
  7873. // } else if num1 < num2 {
  7874. // num = num2 - num1
  7875. // drug.Total = drug.Total - num
  7876. // service.UpdateBaseDrugLib(&drug)
  7877. // }
  7878. //
  7879. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7880. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7881. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7882. // if hisAdvice.PrescribingNumber > num2 {
  7883. // num = hisAdvice.PrescribingNumber - num2
  7884. // drug.Total = drug.Total + num
  7885. // service.UpdateBaseDrugLib(&drug)
  7886. // } else if num2 < advice.PrescribingNumber {
  7887. // num = num2 - hisAdvice.PrescribingNumber
  7888. // drug.Total = drug.Total - num
  7889. // service.UpdateBaseDrugLib(&drug)
  7890. // }
  7891. //
  7892. // }
  7893. // }
  7894. // }
  7895. //}
  7896. //
  7897. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7898. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7899. // advice.ExecutionTime = execution_time
  7900. //}
  7901. //
  7902. //
  7903. //
  7904. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7905. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7906. // advice.ExecutionStaff = execution_staff
  7907. //}
  7908. //
  7909. //
  7910. //
  7911. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7912. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7913. // advice.ExecutionState = execution_state
  7914. //}
  7915. //
  7916. //
  7917. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7918. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7919. // advice.CheckTime = check_time
  7920. //}
  7921. //
  7922. //
  7923. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7924. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7925. // advice.CheckState = check_state
  7926. //}
  7927. //
  7928. //
  7929. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7930. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7931. // advice.Checker = checker
  7932. //}
  7933. //
  7934. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7935. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7936. // advice.StartTime = start_time
  7937. //}
  7938. return 0
  7939. }
  7940. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7941. project.ExecutionStaff = 0
  7942. project.ExecutionState = 2
  7943. project.ExecutionTime = 0
  7944. project.Checker = 0
  7945. project.CheckState = 2
  7946. project.CheckTime = 0
  7947. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7948. id := int64(json["id"].(float64))
  7949. project.ID = id
  7950. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7951. project.ExecutionStaff = temp_project.ExecutionStaff
  7952. project.ExecutionState = temp_project.ExecutionState
  7953. project.ExecutionTime = temp_project.ExecutionTime
  7954. project.Checker = temp_project.Checker
  7955. project.CheckState = temp_project.CheckState
  7956. project.CheckTime = temp_project.CheckTime
  7957. project.TeamId = temp_project.TeamId
  7958. }
  7959. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7960. types := int64(json["type"].(float64))
  7961. project.Type = types
  7962. }
  7963. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7964. project_id := int64(json["project_id"].(float64))
  7965. project.ProjectId = project_id
  7966. }
  7967. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7968. team_id := int64(json["team_id"].(float64))
  7969. project.TeamId = team_id
  7970. }
  7971. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7972. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7973. project.Price = price
  7974. }
  7975. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7976. total, _ := json["total"].(string)
  7977. //totals, _ := strconv.ParseInt(total, 10, 64)
  7978. project.Count = total
  7979. }
  7980. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7981. medical_code, _ := json["medical_code"].(string)
  7982. project.MedListCodg = medical_code
  7983. }
  7984. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7985. single_dose, _ := json["single_dose"].(string)
  7986. project.SingleDose = single_dose
  7987. }
  7988. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7989. delivery_way, _ := json["delivery_way"].(string)
  7990. project.DeliveryWay = delivery_way
  7991. }
  7992. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7993. execution_frequency, _ := json["execution_frequency"].(string)
  7994. project.ExecutionFrequency = execution_frequency
  7995. }
  7996. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7997. remark, _ := json["remark"].(string)
  7998. project.Remark = remark
  7999. }
  8000. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8001. day, _ := json["number_days"].(string)
  8002. project.Day = day
  8003. }
  8004. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8005. unit, _ := json["unit"].(string)
  8006. project.Unit = unit
  8007. }
  8008. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8009. // frequency_type := int64(json["frequency_type"].(float64))
  8010. // project.FrequencyType = frequency_type
  8011. //}
  8012. //
  8013. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8014. // day_count := int64(json["day_count"].(float64))
  8015. // project.DayCount = day_count
  8016. //}
  8017. //
  8018. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8019. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8020. // week_day, _ := json["week_day"].(string)
  8021. // project.WeekDay = week_day
  8022. //}
  8023. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8024. //
  8025. //if project.ID == 0 {
  8026. // if stockConfig.IsOpen == 1 {
  8027. // if project.Type == 3 {
  8028. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8029. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8030. // good.Total = good.Total - f_count
  8031. // service.UpdateGoodInfo(&good)
  8032. // }
  8033. // }
  8034. //
  8035. //} else {
  8036. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8037. //
  8038. // if stockConfig.IsOpen == 1 {
  8039. // if project.Type == 3 {
  8040. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8041. // if project.Count < temp_project.Count {
  8042. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8043. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8044. //
  8045. // other_count := f_count_two - f_count_one
  8046. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8047. // good.Total = good.Total + other_count_two
  8048. // service.UpdateGoodInfo(&good)
  8049. // } else if project.Count > temp_project.Count {
  8050. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8051. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8052. //
  8053. // other_count := f_count_one - f_count_two
  8054. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8055. // good.Total = good.Total - other_count_two
  8056. // service.UpdateGoodInfo(&good)
  8057. // }
  8058. //
  8059. // }
  8060. // }
  8061. //
  8062. //}
  8063. return 0
  8064. }
  8065. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8066. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8067. utils.ErrorLog("drug_name")
  8068. return enums.ErrorCodeParamWrong
  8069. }
  8070. adviceName, _ := json["drug_name"].(string)
  8071. if len(adviceName) == 0 {
  8072. utils.ErrorLog("len(advice_name) == 0")
  8073. return enums.ErrorCodeParamWrong
  8074. }
  8075. advice.AdviceName = adviceName
  8076. adviceDesc, _ := json["advice_desc"].(string)
  8077. advice.AdviceDesc = adviceDesc
  8078. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8079. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8080. advice.DrugSpec = drugSpec
  8081. }
  8082. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8083. remark, _ := json["remark"].(string)
  8084. advice.Remark = remark
  8085. }
  8086. if json["id"] == nil {
  8087. advice.DrugId = 0
  8088. } else {
  8089. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8090. drug_id := int64(json["id"].(float64))
  8091. advice.DrugId = drug_id
  8092. }
  8093. }
  8094. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8095. groupno := int64(json["groupno"].(float64))
  8096. advice.Groupno = groupno
  8097. }
  8098. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8099. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8100. advice.IsSelfDrug = is_self_drug
  8101. }
  8102. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8103. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8104. drug_way_count, _ := json["drug_way_count"].(string)
  8105. advice.DrugWayCount = drug_way_count
  8106. }
  8107. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8108. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8109. advice.HospApprFlag = hosp_appr_flag
  8110. }
  8111. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8112. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8113. advice.PrescribingNumber = prescribingNumber
  8114. }
  8115. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8116. // frequency_type := int64(json["frequency_type"].(float64))
  8117. // advice.FrequencyType = frequency_type
  8118. //}
  8119. //
  8120. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8121. // day_count := int64(json["day_count"].(float64))
  8122. // advice.DayCount = day_count
  8123. //}
  8124. //
  8125. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8126. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8127. // week_day, _ := json["week_day"].(string)
  8128. // advice.WeekDay = week_day
  8129. //}
  8130. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8131. drugSpecUnit, _ := json["min_unit"].(string)
  8132. advice.DrugSpecUnit = drugSpecUnit
  8133. }
  8134. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8135. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8136. advice.SingleDose = singleDose
  8137. }
  8138. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8139. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8140. advice.SingleDoseUnit = singleDoseUnit
  8141. }
  8142. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8143. deliveryWay, _ := json["delivery_way"].(string)
  8144. advice.DeliveryWay = deliveryWay
  8145. }
  8146. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8147. executionFrequency, _ := json["execution_frequency"].(string)
  8148. advice.ExecutionFrequency = executionFrequency
  8149. }
  8150. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8151. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8152. advice.Price = price
  8153. }
  8154. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8155. med_list_codg, _ := json["medical_insurance_number"].(string)
  8156. advice.MedListCodg = med_list_codg
  8157. }
  8158. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8159. day := int64(json["day"].(float64))
  8160. advice.Day = day
  8161. }
  8162. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8163. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8164. advice.PrescribingNumberUnit = prescribingNumberUnit
  8165. }
  8166. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8167. advice_id := int64(json["advice_id"].(float64))
  8168. advice.ID = advice_id
  8169. if advice.ID > 0 {
  8170. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8171. if err == nil {
  8172. if hisAdvice.ID > 0 {
  8173. advice.ExecutionTime = hisAdvice.ExecutionTime
  8174. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8175. advice.ExecutionState = hisAdvice.ExecutionState
  8176. advice.CheckTime = hisAdvice.CheckTime
  8177. advice.Checker = hisAdvice.Checker
  8178. advice.DrugCode = hisAdvice.DrugCode
  8179. advice.CheckState = hisAdvice.CheckState
  8180. advice.StartTime = hisAdvice.StartTime
  8181. advice.HospApprFlag = hisAdvice.HospApprFlag
  8182. advice.IsMedicine = hisAdvice.IsMedicine
  8183. if hisAdvice.UserOrgId == 10028 {
  8184. 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 {
  8185. advice.ExecutionTime = 0
  8186. advice.ExecutionStaff = 0
  8187. advice.ExecutionState = 2
  8188. advice.CheckTime = 0
  8189. advice.Checker = 0
  8190. advice.CheckState = 2
  8191. }
  8192. } else {
  8193. 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 {
  8194. advice.ExecutionTime = 0
  8195. advice.ExecutionStaff = 0
  8196. advice.ExecutionState = 2
  8197. advice.CheckTime = 0
  8198. advice.Checker = 0
  8199. advice.CheckState = 2
  8200. //advice.UpdatedTime = time.Now().Unix()
  8201. advice.CreatedTime = hisAdvice.CreatedTime
  8202. advice.UpdatedTime = time.Now().Unix()
  8203. } else {
  8204. advice.CreatedTime = hisAdvice.CreatedTime
  8205. advice.UpdatedTime = hisAdvice.UpdatedTime
  8206. }
  8207. }
  8208. //advice.Groupno = hisAdvice.Groupno
  8209. } else {
  8210. advice.IsMedicine = 0
  8211. ctime := time.Now().Unix()
  8212. advice.CreatedTime = ctime
  8213. advice.UpdatedTime = ctime
  8214. }
  8215. }
  8216. } else {
  8217. advice.IsMedicine = 0
  8218. ctime := time.Now().Unix()
  8219. advice.CreatedTime = ctime
  8220. advice.UpdatedTime = ctime
  8221. }
  8222. }
  8223. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8224. //
  8225. //if drugStockConfig.IsOpen == 1 {
  8226. //
  8227. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8228. // if advice.ID == 0 { //医嘱不存在
  8229. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8230. // drug.Total = drug.Total - advice.PrescribingNumber
  8231. // service.UpdateBaseDrugLib(&drug)
  8232. //
  8233. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8234. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8235. // drug.Total = drug.Total - num
  8236. // service.UpdateBaseDrugLib(&drug)
  8237. // }
  8238. //
  8239. // } else if advice.ID > 0 { //医嘱存在
  8240. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8241. // var num float64
  8242. //
  8243. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8244. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8245. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8246. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8247. // drug.Total = drug.Total + num
  8248. // service.UpdateBaseDrugLib(&drug)
  8249. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8250. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8251. // drug.Total = drug.Total - num
  8252. // service.UpdateBaseDrugLib(&drug)
  8253. // }
  8254. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8255. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8256. // if num2 > advice.PrescribingNumber {
  8257. // num = num2 - advice.PrescribingNumber
  8258. // drug.Total = drug.Total + num
  8259. // service.UpdateBaseDrugLib(&drug)
  8260. // } else if num2 < advice.PrescribingNumber {
  8261. // num = advice.PrescribingNumber - num2
  8262. // drug.Total = drug.Total - num
  8263. // service.UpdateBaseDrugLib(&drug)
  8264. // }
  8265. //
  8266. // }
  8267. //
  8268. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8269. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8270. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8271. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8272. // if num1 > num2 {
  8273. // num = num1 - num2
  8274. // drug.Total = drug.Total + num
  8275. // service.UpdateBaseDrugLib(&drug)
  8276. // } else if num1 < num2 {
  8277. // num = num2 - num1
  8278. // drug.Total = drug.Total - num
  8279. // service.UpdateBaseDrugLib(&drug)
  8280. // }
  8281. //
  8282. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8283. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8284. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8285. // if hisAdvice.PrescribingNumber > num2 {
  8286. // num = hisAdvice.PrescribingNumber - num2
  8287. // drug.Total = drug.Total + num
  8288. // service.UpdateBaseDrugLib(&drug)
  8289. // } else if num2 < advice.PrescribingNumber {
  8290. // num = num2 - hisAdvice.PrescribingNumber
  8291. // drug.Total = drug.Total - num
  8292. // service.UpdateBaseDrugLib(&drug)
  8293. // }
  8294. //
  8295. // }
  8296. // }
  8297. // }
  8298. //}
  8299. //
  8300. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8301. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8302. // advice.ExecutionTime = execution_time
  8303. //}
  8304. //
  8305. //
  8306. //
  8307. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8308. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8309. // advice.ExecutionStaff = execution_staff
  8310. //}
  8311. //
  8312. //
  8313. //
  8314. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8315. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8316. // advice.ExecutionState = execution_state
  8317. //}
  8318. //
  8319. //
  8320. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8321. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8322. // advice.CheckTime = check_time
  8323. //}
  8324. //
  8325. //
  8326. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8327. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8328. // advice.CheckState = check_state
  8329. //}
  8330. //
  8331. //
  8332. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8333. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8334. // advice.Checker = checker
  8335. //}
  8336. //
  8337. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8338. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8339. // advice.StartTime = start_time
  8340. //}
  8341. return 0
  8342. }
  8343. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8344. project.ExecutionStaff = 0
  8345. project.ExecutionState = 2
  8346. project.ExecutionTime = 0
  8347. project.Checker = 0
  8348. project.CheckState = 2
  8349. project.CheckTime = 0
  8350. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8351. id := int64(json["id"].(float64))
  8352. project.ID = id
  8353. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8354. project.ExecutionStaff = temp_project.ExecutionStaff
  8355. project.ExecutionState = temp_project.ExecutionState
  8356. project.ExecutionTime = temp_project.ExecutionTime
  8357. project.Checker = temp_project.Checker
  8358. project.CheckState = temp_project.CheckState
  8359. project.CheckTime = temp_project.CheckTime
  8360. project.TeamId = temp_project.TeamId
  8361. }
  8362. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8363. types := int64(json["type"].(float64))
  8364. project.Type = types
  8365. }
  8366. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8367. project_id := int64(json["project_id"].(float64))
  8368. project.ProjectId = project_id
  8369. }
  8370. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8371. team_id := int64(json["team_id"].(float64))
  8372. project.TeamId = team_id
  8373. }
  8374. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8375. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8376. project.Price = price
  8377. }
  8378. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8379. total, _ := json["total"].(string)
  8380. //totals, _ := strconv.ParseInt(total, 10, 64)
  8381. project.Count = total
  8382. }
  8383. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8384. medical_code, _ := json["medical_code"].(string)
  8385. project.MedListCodg = medical_code
  8386. }
  8387. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8388. single_dose, _ := json["single_dose"].(string)
  8389. project.SingleDose = single_dose
  8390. }
  8391. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8392. delivery_way, _ := json["delivery_way"].(string)
  8393. project.DeliveryWay = delivery_way
  8394. }
  8395. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8396. execution_frequency, _ := json["execution_frequency"].(string)
  8397. project.ExecutionFrequency = execution_frequency
  8398. }
  8399. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8400. remark, _ := json["remark"].(string)
  8401. project.Remark = remark
  8402. }
  8403. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8404. day, _ := json["number_days"].(string)
  8405. project.Day = day
  8406. }
  8407. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8408. unit, _ := json["unit"].(string)
  8409. project.Unit = unit
  8410. }
  8411. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8412. // frequency_type := int64(json["frequency_type"].(float64))
  8413. // project.FrequencyType = frequency_type
  8414. //}
  8415. //
  8416. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8417. // day_count := int64(json["day_count"].(float64))
  8418. // project.DayCount = day_count
  8419. //}
  8420. //
  8421. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8422. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8423. // week_day, _ := json["week_day"].(string)
  8424. // project.WeekDay = week_day
  8425. //}
  8426. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8427. //
  8428. //if project.ID == 0 {
  8429. // if stockConfig.IsOpen == 1 {
  8430. // if project.Type == 3 {
  8431. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8432. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8433. // good.Total = good.Total - f_count
  8434. // service.UpdateGoodInfo(&good)
  8435. // }
  8436. // }
  8437. //
  8438. //} else {
  8439. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8440. //
  8441. // if stockConfig.IsOpen == 1 {
  8442. // if project.Type == 3 {
  8443. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8444. // if project.Count < temp_project.Count {
  8445. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8446. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8447. //
  8448. // other_count := f_count_two - f_count_one
  8449. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8450. // good.Total = good.Total + other_count_two
  8451. // service.UpdateGoodInfo(&good)
  8452. // } else if project.Count > temp_project.Count {
  8453. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8454. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8455. //
  8456. // other_count := f_count_one - f_count_two
  8457. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8458. // good.Total = good.Total - other_count_two
  8459. // service.UpdateGoodInfo(&good)
  8460. // }
  8461. //
  8462. // }
  8463. // }
  8464. //
  8465. //}
  8466. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8467. id := int64(json["id"].(float64))
  8468. if id > 0 {
  8469. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8470. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8471. fmt.Println("666666")
  8472. project.Mtime = time.Now().Unix()
  8473. project.Ctime = temp_project.Ctime
  8474. } else {
  8475. project.Mtime = temp_project.Mtime
  8476. project.Ctime = temp_project.Ctime
  8477. }
  8478. } else {
  8479. ctime := time.Now().Unix()
  8480. project.Mtime = ctime
  8481. project.Ctime = ctime
  8482. }
  8483. }
  8484. return 0
  8485. }
  8486. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8487. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8488. id := int64(json["id"].(float64))
  8489. additionalCharge.ID = id
  8490. }
  8491. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8492. item_id := int64(json["item_id"].(float64))
  8493. additionalCharge.ItemId = item_id
  8494. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8495. if config.ID > 0 {
  8496. if len(config.Code) > 0 {
  8497. additionalCharge.MedListCodg = config.Code
  8498. }
  8499. }
  8500. }
  8501. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8502. // price := int64(json["price"].(float64))
  8503. // formatInt_price := strconv.FormatInt(price, 10)
  8504. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8505. // additionalCharge.Price = float_price
  8506. // }
  8507. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8508. // price := int64(json["price"].(float64))
  8509. // formatInt_price := strconv.FormatInt(price, 10)
  8510. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8511. // additionalCharge.Price = float_price
  8512. //}
  8513. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8514. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8515. additionalCharge.Price = price
  8516. }
  8517. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8518. count, _ := json["count"].(string)
  8519. counts, _ := strconv.ParseInt(count, 10, 64)
  8520. additionalCharge.Count = counts
  8521. }
  8522. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8523. item_name, _ := json["item_name"].(string)
  8524. additionalCharge.ItemName = item_name
  8525. }
  8526. return 0
  8527. }
  8528. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8529. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8530. utils.ErrorLog("drug_name")
  8531. return enums.ErrorCodeParamWrong
  8532. }
  8533. adviceName, _ := json["drug_name"].(string)
  8534. if len(adviceName) == 0 {
  8535. utils.ErrorLog("len(advice_name) == 0")
  8536. return enums.ErrorCodeParamWrong
  8537. }
  8538. advice.AdviceName = adviceName
  8539. adviceDesc, _ := json["advice_desc"].(string)
  8540. advice.AdviceDesc = adviceDesc
  8541. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8542. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8543. advice.DrugSpec = drugSpec
  8544. }
  8545. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8546. remark, _ := json["remark"].(string)
  8547. advice.Remark = remark
  8548. }
  8549. if json["id"] == nil {
  8550. advice.DrugId = 0
  8551. } else {
  8552. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8553. drug_id := int64(json["id"].(float64))
  8554. advice.DrugId = drug_id
  8555. }
  8556. }
  8557. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8558. groupno := int64(json["groupno"].(float64))
  8559. advice.Groupno = groupno
  8560. }
  8561. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8562. drugSpecUnit, _ := json["min_unit"].(string)
  8563. advice.DrugSpecUnit = drugSpecUnit
  8564. }
  8565. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8566. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8567. advice.SingleDose = singleDose
  8568. }
  8569. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8570. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8571. advice.SingleDoseUnit = singleDoseUnit
  8572. }
  8573. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8574. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8575. advice.PrescribingNumber = prescribingNumber
  8576. }
  8577. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8578. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8579. advice.PrescribingNumberUnit = prescribingNumberUnit
  8580. }
  8581. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8582. deliveryWay, _ := json["delivery_way"].(string)
  8583. advice.DeliveryWay = deliveryWay
  8584. }
  8585. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8586. executionFrequency, _ := json["execution_frequency"].(string)
  8587. advice.ExecutionFrequency = executionFrequency
  8588. }
  8589. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8590. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8591. advice.Price = price
  8592. }
  8593. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8594. med_list_codg, _ := json["medical_insurance_number"].(string)
  8595. advice.MedListCodg = med_list_codg
  8596. }
  8597. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8598. day := int64(json["day"].(float64))
  8599. advice.Day = day
  8600. }
  8601. advice.FrequencyType = 1
  8602. return 0
  8603. }
  8604. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8605. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8606. types := int64(json["type"].(float64))
  8607. project.Type = types
  8608. }
  8609. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8610. project_id := int64(json["project_id"].(float64))
  8611. project.ProjectId = project_id
  8612. }
  8613. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8614. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8615. project.Price = price
  8616. }
  8617. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8618. total, _ := json["total"].(string)
  8619. //totals, _ := strconv.ParseInt(total, 10, 64)
  8620. project.Count = total
  8621. }
  8622. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8623. medical_code, _ := json["medical_code"].(string)
  8624. project.MedListCodg = medical_code
  8625. }
  8626. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8627. single_dose, _ := json["single_dose"].(string)
  8628. project.SingleDose = single_dose
  8629. }
  8630. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8631. delivery_way, _ := json["delivery_way"].(string)
  8632. project.DeliveryWay = delivery_way
  8633. }
  8634. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8635. execution_frequency, _ := json["execution_frequency"].(string)
  8636. project.ExecutionFrequency = execution_frequency
  8637. }
  8638. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8639. remark, _ := json["remark"].(string)
  8640. project.Remark = remark
  8641. }
  8642. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8643. day, _ := json["number_days"].(string)
  8644. project.Day = day
  8645. }
  8646. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8647. unit, _ := json["unit"].(string)
  8648. project.Unit = unit
  8649. }
  8650. project.FrequencyType = 1
  8651. return 0
  8652. }
  8653. func (c *HisApiController) GetHisOrderListTwo() {
  8654. start_time := c.GetString("start_time")
  8655. end_time := c.GetString("end_time")
  8656. timeLayout := "2006-01-02"
  8657. loc, _ := time.LoadLocation("Local")
  8658. var startTime int64
  8659. if len(start_time) > 0 {
  8660. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8661. if err != nil {
  8662. //fmt.Println(err)
  8663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8664. return
  8665. }
  8666. startTime = theTime.Unix()
  8667. }
  8668. var endTime int64
  8669. if len(end_time) > 0 {
  8670. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8671. if err != nil {
  8672. utils.ErrorLog(err.Error())
  8673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8674. return
  8675. }
  8676. endTime = theTime.Unix()
  8677. }
  8678. adminUser := c.GetAdminUserInfo()
  8679. org_id := adminUser.CurrentOrgId
  8680. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  8681. if err == nil {
  8682. c.ServeSuccessJSON(map[string]interface{}{
  8683. "order2": order,
  8684. })
  8685. } else {
  8686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8687. return
  8688. }
  8689. }
  8690. func (c *HisApiController) GetHisOrderList() {
  8691. page, _ := c.GetInt64("page", -1)
  8692. limit, _ := c.GetInt64("limit", -1)
  8693. start_time := c.GetString("start_time")
  8694. end_time := c.GetString("end_time")
  8695. types, _ := c.GetInt64("type", 0)
  8696. keywords := c.GetString("keywords")
  8697. p_type, _ := c.GetInt64("p_type", 0)
  8698. sort_type, _ := c.GetInt64("sort_type", 0)
  8699. charge_type, _ := c.GetInt64("charge_type", 0)
  8700. sch_type, _ := c.GetInt64("sch_type", 0)
  8701. zone_type, _ := c.GetInt64("zone_type", 0)
  8702. med_type, _ := c.GetInt64("med_type", 0)
  8703. timeLayout := "2006-01-02"
  8704. loc, _ := time.LoadLocation("Local")
  8705. var startTime int64
  8706. if len(start_time) > 0 {
  8707. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8708. if err != nil {
  8709. //fmt.Println(err)
  8710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8711. return
  8712. }
  8713. startTime = theTime.Unix()
  8714. }
  8715. var endTime int64
  8716. if len(end_time) > 0 {
  8717. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8718. if err != nil {
  8719. utils.ErrorLog(err.Error())
  8720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8721. return
  8722. }
  8723. endTime = theTime.Unix()
  8724. }
  8725. adminUser := c.GetAdminUserInfo()
  8726. org_id := adminUser.CurrentOrgId
  8727. 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)
  8728. for _, item := range order {
  8729. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8730. item.DoctorName = info.Doctor
  8731. item.DepartmentName = info.XtHisDepartment.Name
  8732. }
  8733. if err == nil {
  8734. c.ServeSuccessJSON(map[string]interface{}{
  8735. "order": order,
  8736. "total": total,
  8737. })
  8738. } else {
  8739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8740. return
  8741. }
  8742. }
  8743. func (c *HisApiController) GetHisOrder() {
  8744. patient_id, _ := c.GetInt64("patient_id", 0)
  8745. number := c.GetString("number")
  8746. adminInfo := c.GetAdminUserInfo()
  8747. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8748. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8749. if err == nil {
  8750. c.ServeSuccessJSON(map[string]interface{}{
  8751. "order": order,
  8752. "prescription": prescriptions,
  8753. })
  8754. } else {
  8755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8756. return
  8757. }
  8758. }
  8759. func (c *HisApiController) GetHisPrescriptionList() {
  8760. record_date := c.GetString("record_date")
  8761. keywords := c.GetString("keywords")
  8762. page, _ := c.GetInt64("page")
  8763. limit, _ := c.GetInt64("limit")
  8764. sch_type, _ := c.GetInt64("sch_type")
  8765. timeLayout := "2006-01-02"
  8766. loc, _ := time.LoadLocation("Local")
  8767. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8768. if err != nil {
  8769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8770. return
  8771. }
  8772. recordDateTime := theTime.Unix()
  8773. adminInfo := c.GetAdminUserInfo()
  8774. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8775. //adminInfo := c.GetAdminUserInfo()
  8776. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8777. //fmt.Println(prescriptionOrder)
  8778. if err == nil {
  8779. c.ServeSuccessJSON(map[string]interface{}{
  8780. "order": prescriptionOrder,
  8781. "total": total,
  8782. })
  8783. } else {
  8784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8785. return
  8786. }
  8787. }
  8788. func (c *HisApiController) GetHisPrescriptionInfo() {
  8789. id, _ := c.GetInt64("id")
  8790. adminInfo := c.GetAdminUserInfo()
  8791. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8792. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8793. if err == nil {
  8794. c.ServeSuccessJSON(map[string]interface{}{
  8795. "order": prescriptionOrder,
  8796. "prescription": prescription,
  8797. })
  8798. } else {
  8799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8800. return
  8801. }
  8802. }
  8803. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8804. adminUser := c.GetAdminUserInfo()
  8805. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8806. c.ServeSuccessJSON(map[string]interface{}{
  8807. "config": config,
  8808. })
  8809. }
  8810. type ResultTwo struct {
  8811. ErrMsg interface{} `json:"err_msg"`
  8812. InfRefmsgid string `json:"inf_refmsgid"`
  8813. Infcode int64 `json:"infcode"`
  8814. Output struct {
  8815. Baseinfo struct {
  8816. Age float64 `json:"age"`
  8817. Brdy string `json:"brdy"`
  8818. Certno string `json:"certno"`
  8819. Gend string `json:"gend"`
  8820. Naty string `json:"naty"`
  8821. PsnCertType string `json:"psn_cert_type"`
  8822. PsnName string `json:"psn_name"`
  8823. PsnNo string `json:"psn_no"`
  8824. } `json:"baseinfo"`
  8825. Idetinfo []interface{} `json:"idetinfo"`
  8826. Iinfo []struct {
  8827. Balc float64 `json:"balc"`
  8828. CvlservFlag string `json:"cvlserv_flag"`
  8829. EmpName string `json:"emp_name"`
  8830. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8831. Insutype string `json:"insutype"`
  8832. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8833. PausInsuDate interface{} `json:"paus_insu_date"`
  8834. PsnInsuDate string `json:"psn_insu_date"`
  8835. PsnInsuStas string `json:"psn_insu_stas"`
  8836. PsnType string `json:"psn_type"`
  8837. } `json:"insuinfo"`
  8838. } `json:"output"`
  8839. RefmsgTime string `json:"refmsg_time"`
  8840. RespondTime string `json:"respond_time"`
  8841. Signtype interface{} `json:"signtype"`
  8842. WarnInfo interface{} `json:"warn_info"`
  8843. }
  8844. type ResultThree struct {
  8845. Cainfo interface{} `json:"cainfo"`
  8846. ErrMsg interface{} `json:"err_msg"`
  8847. InfRefmsgid string `json:"inf_refmsgid"`
  8848. Infcode int64 `json:"infcode"`
  8849. Output struct {
  8850. Data struct {
  8851. IptOtpNo string `json:"ipt_otp_no"`
  8852. MdtrtID string `json:"mdtrt_id"`
  8853. PsnNo string `json:"psn_no"`
  8854. } `json:"data"`
  8855. } `json:"output"`
  8856. RefmsgTime string `json:"refmsg_time"`
  8857. RespondTime string `json:"respond_time"`
  8858. Signtype interface{} `json:"signtype"`
  8859. WarnMsg interface{} `json:"warn_msg"`
  8860. }
  8861. type ResultFour struct {
  8862. Cainfo string `json:"cainfo"`
  8863. ErrMsg string `json:"err_msg"`
  8864. InfRefmsgid string `json:"inf_refmsgid"`
  8865. Infcode int64 `json:"infcode"`
  8866. Output struct {
  8867. Result []struct {
  8868. BasMednFlag string `json:"bas_medn_flag"`
  8869. ChldMedcFlag string `json:"chld_medc_flag"`
  8870. ChrgitmLv string `json:"chrgitm_lv"`
  8871. Cnt float64 `json:"cnt"`
  8872. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8873. DrtReimFlag string `json:"drt_reim_flag"`
  8874. FeedetlSn string `json:"feedetl_sn"`
  8875. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8876. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8877. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8878. ListSpItemFlag string `json:"list_sp_item_flag"`
  8879. LmtUsedFlag string `json:"lmt_used_flag"`
  8880. MedChrgitmType string `json:"med_chrgitm_type"`
  8881. Memo string `json:"memo"`
  8882. OverlmtAmt float64 `json:"overlmt_amt"`
  8883. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8884. Pric float64 `json:"pric"`
  8885. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8886. SelfpayProp float64 `json:"selfpay_prop"`
  8887. } `json:"result"`
  8888. } `json:"output"`
  8889. RefmsgTime string `json:"refmsg_time"`
  8890. RespondTime string `json:"respond_time"`
  8891. Signtype string `json:"signtype"`
  8892. WarnMsg string `json:"warn_msg"`
  8893. }
  8894. type ResultFive struct {
  8895. Insutype string `json:"insutype"`
  8896. }
  8897. type ResultSix struct {
  8898. Cainfo interface{} `json:"cainfo"`
  8899. ErrMsg interface{} `json:"err_msg"`
  8900. InfRefmsgid string `json:"inf_refmsgid"`
  8901. Infcode int64 `json:"infcode"`
  8902. Output struct {
  8903. } `json:"output"`
  8904. RefmsgTime string `json:"refmsg_time"`
  8905. RespondTime string `json:"respond_time"`
  8906. Signtype interface{} `json:"signtype"`
  8907. WarnMsg interface{} `json:"warn_msg"`
  8908. }
  8909. type ResultSeven struct {
  8910. Cainfo string `json:"cainfo"`
  8911. ErrMsg string `json:"err_msg"`
  8912. InfRefmsgid string `json:"inf_refmsgid"`
  8913. Infcode int64 `json:"infcode"`
  8914. Output struct {
  8915. Setldetail []interface{} `json:"setldetail"`
  8916. Setlinfo struct {
  8917. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8918. AcctPay float64 `json:"acct_pay"`
  8919. ActPayDedc float64 `json:"act_pay_dedc"`
  8920. Age float64 `json:"age"`
  8921. Balc float64 `json:"balc"`
  8922. Brdy string `json:"brdy"`
  8923. Certno string `json:"certno"`
  8924. ClrOptins string `json:"clr_optins"`
  8925. ClrType string `json:"clr_type"`
  8926. ClrWay string `json:"clr_way"`
  8927. CvlservFlag string `json:"cvlserv_flag"`
  8928. CvlservPay float64 `json:"cvlserv_pay"`
  8929. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8930. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8931. Gend string `json:"gend"`
  8932. HifesPay float64 `json:"hifes_pay"`
  8933. HifmiPay float64 `json:"hifmi_pay"`
  8934. HifobPay float64 `json:"hifob_pay"`
  8935. HifpPay float64 `json:"hifp_pay"`
  8936. HospPartAmt float64 `json:"hosp_part_amt"`
  8937. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8938. Insutype string `json:"insutype"`
  8939. MafPay float64 `json:"maf_pay"`
  8940. MdtrtCertType string `json:"mdtrt_cert_type"`
  8941. MdtrtID string `json:"mdtrt_id"`
  8942. MedType string `json:"med_type"`
  8943. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8944. MedinsSetlID string `json:"medins_setl_id"`
  8945. Naty string `json:"naty"`
  8946. OthPay float64 `json:"oth_pay"`
  8947. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8948. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8949. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8950. PsnCashPay float64 `json:"psn_cash_pay"`
  8951. PsnCertType string `json:"psn_cert_type"`
  8952. PsnName string `json:"psn_name"`
  8953. PsnNo string `json:"psn_no"`
  8954. PsnPartAmt float64 `json:"psn_part_amt"`
  8955. PsnType string `json:"psn_type"`
  8956. SetlID string `json:"setl_id"`
  8957. SetlTime string `json:"setl_time"`
  8958. } `json:"setlinfo"`
  8959. } `json:"output"`
  8960. RefmsgTime string `json:"refmsg_time"`
  8961. RespondTime string `json:"respond_time"`
  8962. Signtype interface{} `json:"signtype"`
  8963. WarnMsg interface{} `json:"warn_msg"`
  8964. }
  8965. type ResultEight struct {
  8966. Cainfo string `json:"cainfo"`
  8967. ErrMsg string `json:"err_msg"`
  8968. InfRefmsgid string `json:"inf_refmsgid"`
  8969. Infcode int64 `json:"infcode"`
  8970. Output struct {
  8971. Stmtinfo struct {
  8972. SetlOptins string `json:"setl_optins"`
  8973. StmtRslt string `json:"stmt_rslt"`
  8974. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8975. } `json:"stmtinfo"`
  8976. } `json:"output"`
  8977. RefmsgTime string `json:"refmsg_time"`
  8978. RespondTime string `json:"respond_time"`
  8979. Signtype interface{} `json:"signtype"`
  8980. WarnMsg interface{} `json:"warn_msg"`
  8981. }
  8982. type ResultNine struct {
  8983. Cainfo string `json:"cainfo"`
  8984. ErrMsg string `json:"err_msg"`
  8985. InfRefmsgid string `json:"inf_refmsgid"`
  8986. Infcode int64 `json:"infcode"`
  8987. Output struct {
  8988. FileQuryNo string `json:"file_qury_no"`
  8989. } `json:"output"`
  8990. RefmsgTime string `json:"refmsg_time"`
  8991. RespondTime string `json:"respond_time"`
  8992. Signtype interface{} `json:"signtype"`
  8993. WarnMsg interface{} `json:"warn_msg"`
  8994. }
  8995. type ResultTen struct {
  8996. Cainfo string `json:"cainfo"`
  8997. ErrMsg string `json:"err_msg"`
  8998. InfRefmsgid string `json:"inf_refmsgid"`
  8999. Infcode int64 `json:"infcode"`
  9000. Output struct {
  9001. DldEndtime string `json:"dld_endtime"`
  9002. FileQuryNo string `json:"file_qury_no"`
  9003. Filename string `json:"filename"`
  9004. } `json:"output"`
  9005. RefmsgTime string `json:"refmsg_time"`
  9006. RespondTime string `json:"respond_time"`
  9007. Signtype interface{} `json:"signtype"`
  9008. WarnMsg interface{} `json:"warn_msg"`
  9009. }
  9010. type ResultEleven struct {
  9011. Cainfo string `json:"cainfo"`
  9012. ErrMsg string `json:"err_msg"`
  9013. InfRefmsgid string `json:"inf_refmsgid"`
  9014. Infcode int64 `json:"infcode"`
  9015. Output struct {
  9016. Setlinfo struct {
  9017. FixmedinsName string `json:"fixmedins_name"`
  9018. FixmedinsCode string `json:"fixmedins_code"`
  9019. PsnNo string `json:"psn_no"`
  9020. PsnName string `json:"psn_name"`
  9021. HifobPay float64 `json:"hifob_pay"`
  9022. Gend string `json:"gend"`
  9023. Brdy string `json:"brdy"`
  9024. PsnCertType string `json:"psn_cert_type"`
  9025. PsnType string `json:"psn_type"`
  9026. EmpName string `json:"emp_name"`
  9027. Certno string `json:"certno"`
  9028. Insutype string `json:"insutype"`
  9029. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9030. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9031. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9032. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9033. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9034. ActPayDedc float64 `json:"act_pay_dedc"`
  9035. HifpPay float64 `json:"hifp_pay"`
  9036. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9037. CvlservPay float64 `json:"cvlserv_pay"`
  9038. HifesPay float64 `json:"hifes_pay"`
  9039. HifmiPay float64 `json:"hifmi_pay"`
  9040. MafPay float64 `json:"maf_pay"`
  9041. OthPay float64 `json:"oth_pay"`
  9042. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9043. PsnPay float64 `json:"psn_pay"`
  9044. AcctPay float64 `json:"acct_pay"`
  9045. CashPayamt float64 `json:"cash_payamt"`
  9046. Balc float64 `json:"balc"`
  9047. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9048. MedinsSetlId string `json:"medins_setl_id"`
  9049. RefdSetlFlag string `json:"refd_setl_flag"`
  9050. SetlTime string `json:"setl_time"`
  9051. MedType string `json:"med_type"`
  9052. } `json:"setlinfo"`
  9053. } `json:"output"`
  9054. RefmsgTime string `json:"refmsg_time"`
  9055. RespondTime string `json:"respond_time"`
  9056. Signtype interface{} `json:"signtype"`
  9057. WarnMsg interface{} `json:"warn_msg"`
  9058. }
  9059. type Custom struct {
  9060. DetItemFeeSumamt string
  9061. Cut string
  9062. FeedetlSn string
  9063. Price string
  9064. MedListCodg string
  9065. Type int64
  9066. AdviceId int64
  9067. ProjectId int64
  9068. ItemId int64
  9069. CostType int64
  9070. }
  9071. // 获取个人信息----挂号-----上传就诊信息
  9072. func (c *HisApiController) GetRegisterInfo() {
  9073. id, _ := c.GetInt64("id")
  9074. record_time := c.GetString("record_time")
  9075. settlementValue, _ := c.GetInt64("settlement_value")
  9076. medical_insurance_card := c.GetString("medical_insurance_card")
  9077. name := c.GetString("name")
  9078. id_card_type, _ := c.GetInt64("id_card_type")
  9079. certificates, _ := c.GetInt64("certificates")
  9080. medical_care, _ := c.GetInt64("medical_care")
  9081. birthday := c.GetString("birthday")
  9082. age, _ := c.GetInt64("age")
  9083. id_card := c.GetString("id_card")
  9084. register_type, _ := c.GetInt64("register")
  9085. doctor, _ := c.GetInt64("doctor")
  9086. department, _ := c.GetInt64("department")
  9087. gender, _ := c.GetInt64("sex")
  9088. phone := c.GetString("phone")
  9089. registration_fee, _ := c.GetFloat("registration_fee")
  9090. medical_expenses, _ := c.GetFloat("medical_expenses")
  9091. social_type, _ := c.GetInt64("social_type")
  9092. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9093. diagnosis_ids := c.GetString("diagnosis")
  9094. sick_type, _ := c.GetInt64("sick_type")
  9095. reg_type := c.GetString("p_type")
  9096. timeLayout := "2006-01-02"
  9097. loc, _ := time.LoadLocation("Local")
  9098. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9099. birthUnix := birthdays.Unix()
  9100. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9101. if err != nil {
  9102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9103. return
  9104. }
  9105. recordDateTime := theTime.Unix()
  9106. adminInfo := c.GetAdminUserInfo()
  9107. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9108. if tempPatient.ID == 0 {
  9109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9110. return
  9111. }
  9112. var patient service.Patients
  9113. if id == 0 {
  9114. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9115. } else {
  9116. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9117. }
  9118. if patient.ID == 0 {
  9119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9120. return
  9121. }
  9122. if len(patient.IdCardNo) == 0 {
  9123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9124. return
  9125. }
  9126. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9127. if len(his) >= 1 {
  9128. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9129. if len(his) >= 1 && order.ID == 0 {
  9130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9131. return
  9132. }
  9133. }
  9134. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9135. fmt.Println(timeStr)
  9136. timeArr := strings.Split(timeStr, " ")
  9137. fmt.Println(timeArr)
  9138. timeArrTwo := strings.Split(timeArr[0], "-")
  9139. timeArrThree := strings.Split(timeArr[1], ":")
  9140. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9141. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9142. if len(lists) == 0 {
  9143. var hisPatient models.XtHisPatient
  9144. hisPatient = models.XtHisPatient{
  9145. Name: name,
  9146. Age: age,
  9147. Gender: gender,
  9148. Birthday: birthUnix,
  9149. Phone: phone,
  9150. MedicalTreatmentType: medical_care,
  9151. IdType: certificates,
  9152. IdCardNo: id_card,
  9153. BalanceAccountsType: settlementValue,
  9154. SocialType: social_type,
  9155. MedicalInsuranceNumber: medical_insurance_card,
  9156. RegisterType: register_type,
  9157. RegisterCost: registration_fee,
  9158. TreatmentCost: medical_expenses,
  9159. AdminUserId: adminInfo.AdminUser.Id,
  9160. UserOrgId: adminInfo.CurrentOrgId,
  9161. Status: 1,
  9162. RecordDate: recordDateTime,
  9163. IsReturn: 1,
  9164. PatientId: patient.ID,
  9165. Ctime: time.Now().Unix(),
  9166. Mtime: time.Now().Unix(),
  9167. Number: str,
  9168. IdCardType: id_card_type,
  9169. Departments: department,
  9170. Doctor: doctor,
  9171. PType: reg_type,
  9172. Diagnosis: diagnosis_ids,
  9173. SickType: sick_type,
  9174. }
  9175. service.CreateHisPatient(&hisPatient)
  9176. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9177. c.ServeSuccessJSON(map[string]interface{}{
  9178. "his_info": hisPatient,
  9179. })
  9180. } else {
  9181. //chrgBchno := rand.Intn(1000000) + 10000
  9182. var hisPatient models.XtHisPatient
  9183. hisPatient = models.XtHisPatient{
  9184. Name: name,
  9185. Age: age,
  9186. Gender: gender,
  9187. Birthday: birthUnix,
  9188. Phone: phone,
  9189. MedicalTreatmentType: medical_care,
  9190. IdType: certificates,
  9191. IdCardNo: id_card,
  9192. BalanceAccountsType: settlementValue,
  9193. SocialType: social_type,
  9194. MedicalInsuranceNumber: medical_insurance_card,
  9195. RegisterType: register_type,
  9196. RegisterCost: registration_fee,
  9197. TreatmentCost: medical_expenses,
  9198. AdminUserId: adminInfo.AdminUser.Id,
  9199. UserOrgId: adminInfo.CurrentOrgId,
  9200. Status: 1,
  9201. RecordDate: recordDateTime,
  9202. IsReturn: 1,
  9203. PatientId: patient.ID,
  9204. Ctime: time.Now().Unix(),
  9205. Mtime: time.Now().Unix(),
  9206. Number: str,
  9207. IdCardType: id_card_type,
  9208. Departments: department,
  9209. Doctor: doctor,
  9210. PType: reg_type,
  9211. Diagnosis: diagnosis_ids,
  9212. SickType: sick_type,
  9213. }
  9214. service.CreateHisPatient(&hisPatient)
  9215. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9216. c.ServeSuccessJSON(map[string]interface{}{
  9217. "his_info": hisPatient,
  9218. })
  9219. }
  9220. }
  9221. // 上传明细----结算
  9222. func (c *HisApiController) GetUploadInfo() {
  9223. id, _ := c.GetInt64("id")
  9224. record_time := c.GetString("record_time")
  9225. his_patient_id, _ := c.GetInt64("his_patient_id")
  9226. oth_desc := c.GetString("oth_desc")
  9227. pay_way, _ := c.GetInt64("pay_way")
  9228. pay_ways := c.GetString("pay_ways")
  9229. pay_price, _ := c.GetFloat("pay_price")
  9230. pay_card_no := c.GetString("pay_card_no")
  9231. discount_price, _ := c.GetFloat("discount_price")
  9232. preferential_price, _ := c.GetFloat("preferential_price")
  9233. reality_price, _ := c.GetFloat("reality_price")
  9234. found_price, _ := c.GetFloat("found_price")
  9235. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9236. private_price, _ := c.GetFloat("private_price")
  9237. timeLayout := "2006-01-02"
  9238. loc, _ := time.LoadLocation("Local")
  9239. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9240. fapiao_code := c.GetString("fapiao_code")
  9241. fapiao_number := c.GetString("fapiao_number")
  9242. diagnosis_id := c.GetString("diagnosis")
  9243. sick_type, _ := c.GetInt64("sick_type")
  9244. reg_type, _ := c.GetInt64("p_type")
  9245. order_id, _ := c.GetInt64("order_id")
  9246. cash_pay := c.GetString("cash_pay")
  9247. wechat_pay := c.GetString("wechat_pay")
  9248. ali_pay := c.GetString("ali_pay")
  9249. jifen_pay := c.GetString("jifen_pay")
  9250. card_desc := c.GetString("card_desc")
  9251. band_card_pay := c.GetString("band_card_pay")
  9252. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9253. tmp_decimal := c.GetString("tmp_decimal")
  9254. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9255. var decimal float64 //本次使用的押金
  9256. var errmsg error
  9257. tx := service.XTWriteDB().Begin() //开了事务
  9258. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9259. defer func() {
  9260. if errmsg != nil {
  9261. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9262. tx.Rollback()
  9263. } else {
  9264. tx.Commit()
  9265. }
  9266. }()
  9267. fmt.Println("dec_way", dec_way)
  9268. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9269. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9270. return
  9271. }
  9272. if len(tmp_decimal) > 0 {
  9273. if tmp_decimal[0] == 45 {
  9274. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9275. return
  9276. }
  9277. }
  9278. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9279. fmt.Println(errs)
  9280. decimal = tt
  9281. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9282. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9283. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9284. if err != nil {
  9285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9286. return
  9287. }
  9288. recordDateTime := theTime.Unix()
  9289. adminUser := c.GetAdminUserInfo()
  9290. var prescriptions []*models.HisPrescription
  9291. var prescriptionsOne []*models.HisPrescription
  9292. var start_time int64
  9293. var end_time int64
  9294. ids_str := c.GetString("ids")
  9295. ids_arr := strings.Split(ids_str, ",")
  9296. if tempOrder.ID == 0 {
  9297. if settle_accounts_type == 1 { //日结
  9298. fmt.Println(reg_type)
  9299. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9300. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9301. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9302. } else {
  9303. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9304. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9305. }
  9306. } else { //月结
  9307. start_time_str := c.GetString("start_time")
  9308. end_time_str := c.GetString("end_time")
  9309. timeLayout := "2006-01-02"
  9310. loc, _ := time.LoadLocation("Local")
  9311. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9312. if err != nil {
  9313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9314. return
  9315. }
  9316. recordStartTime := theStartTime.Unix()
  9317. start_time = recordStartTime
  9318. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9319. if err != nil {
  9320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9321. return
  9322. }
  9323. recordEndTime := theEndTime.Unix()
  9324. end_time = recordEndTime
  9325. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9326. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9327. }
  9328. var goods []*models.DialysisBeforePrepareGoods
  9329. var newGoods []*models.NewDialysisBeforePrepareGoods
  9330. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9331. var infos []*models.HisDoctorAdviceInfo
  9332. var infoList []*models.HisDoctorAdviceInfo
  9333. var hisAdvice []*models.HisDoctorAdviceInfo
  9334. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9335. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9336. //判断库存不足
  9337. //结算出库开关
  9338. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9339. if settConfig.IsOpen == 1 {
  9340. //判断库存的地方
  9341. for _, info := range prescriptions {
  9342. if info.Type == 1 {
  9343. infos = append(infos, info.HisDoctorAdviceInfo...)
  9344. }
  9345. if info.Type == 2 {
  9346. for _, sumItem := range info.HisPrescriptionProject {
  9347. if sumItem.Type == 3 {
  9348. var good models.DialysisBeforePrepareGoods
  9349. var newGood models.NewDialysisBeforePrepareGoods
  9350. good.GoodId = sumItem.GoodInfo.ID
  9351. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9352. count, _ := strconv.Atoi(sumItem.Count)
  9353. good.Count = int64(count)
  9354. good.StorehouseId = houseConfig.StorehouseOutInfo
  9355. good.ProjectId = sumItem.ID
  9356. goods = append(goods, &good)
  9357. newGood.GoodId = sumItem.GoodInfo.ID
  9358. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9359. count2, _ := strconv.Atoi(sumItem.Count)
  9360. newGood.Count = int64(count2)
  9361. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9362. newGood.ProjectId = sumItem.ID
  9363. newGoods = append(newGoods, &newGood)
  9364. }
  9365. }
  9366. }
  9367. }
  9368. for _, info := range prescriptionsOne {
  9369. if info.Type == 1 {
  9370. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9371. }
  9372. if info.Type == 2 {
  9373. for _, sumItem := range info.HisPrescriptionProject {
  9374. if sumItem.Type == 3 {
  9375. var newGood models.NewDialysisBeforePrepareGoods
  9376. newGood.GoodId = sumItem.GoodInfo.ID
  9377. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9378. count2, _ := strconv.Atoi(sumItem.Count)
  9379. newGood.Count = int64(count2)
  9380. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9381. newGood.ProjectId = sumItem.ID
  9382. newGoodOne = append(newGoodOne, &newGood)
  9383. }
  9384. }
  9385. }
  9386. }
  9387. //判断
  9388. for _, itemOne := range infos {
  9389. for _, itemTwo := range hisAdvice {
  9390. if itemOne.DrugId == itemTwo.DrugId {
  9391. itemTwo.Child = append(itemTwo.Child, itemOne)
  9392. }
  9393. }
  9394. }
  9395. for _, itemTwo := range hisAdvice {
  9396. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9397. var sum_out_count int64
  9398. for _, itemThree := range itemTwo.Child {
  9399. var prescribing_number int64
  9400. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9401. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9402. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9403. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9404. }
  9405. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9406. prescribing_number = parseIntPrescribingNumber
  9407. }
  9408. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9409. prescribing_number = parseIntPrescribingNumber
  9410. }
  9411. sum_out_count += prescribing_number
  9412. }
  9413. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9414. if sum_out_count > drugStockOut.FlushCount {
  9415. c.ServeSuccessJSON(map[string]interface{}{
  9416. "msg": "2",
  9417. "drug": medical,
  9418. })
  9419. return
  9420. }
  9421. }
  9422. for _, itemOne := range newGoods {
  9423. for _, item := range newGoodOne {
  9424. if itemOne.GoodId == item.GoodId {
  9425. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9426. }
  9427. }
  9428. }
  9429. for _, item := range newGoodOne {
  9430. var sum_out_count_one int64
  9431. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9432. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9433. sum_out_count_one += itemOne.Count
  9434. }
  9435. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9436. fmt.Println("sum_out_count_one", sum_out_count_one)
  9437. fmt.Println("list.FlushCount", list.FlushCount)
  9438. if sum_out_count_one > list.FlushCount {
  9439. c.ServeSuccessJSON(map[string]interface{}{
  9440. "msg": "3",
  9441. "good": good,
  9442. })
  9443. return
  9444. }
  9445. }
  9446. }
  9447. timestamp := time.Now().Unix()
  9448. tempTime := time.Unix(timestamp, 0)
  9449. timeFormat := tempTime.Format("20060102150405")
  9450. chrgBchno := rand.Intn(100000) + 10000
  9451. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9452. strconv.FormatInt(his.PatientId, 10)
  9453. var ids []int64
  9454. for _, item := range prescriptions {
  9455. ids = append(ids, item.ID)
  9456. }
  9457. var total float64
  9458. for _, item := range prescriptions {
  9459. fmt.Println(item)
  9460. if item.Type == 1 { //药品
  9461. for _, subItem := range item.HisDoctorAdviceInfo {
  9462. total = total + (subItem.Price * subItem.PrescribingNumber)
  9463. }
  9464. }
  9465. if item.Type == 2 { //项目
  9466. for _, subItem := range item.HisPrescriptionProject {
  9467. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9468. total = total + (subItem.Price * cnt)
  9469. }
  9470. }
  9471. for _, subItem := range item.HisAdditionalCharge {
  9472. total = total + (subItem.Price * float64(subItem.Count))
  9473. }
  9474. }
  9475. if reg_type == 1111 || reg_type == 1112 {
  9476. reg_type = 11
  9477. }
  9478. tm := time.Unix(time.Now().Unix(), 0)
  9479. allTotal := fmt.Sprintf("%.4f", total)
  9480. totals, _ := strconv.ParseFloat(allTotal, 64)
  9481. order := &models.HisOrder{
  9482. UserOrgId: adminUser.CurrentOrgId,
  9483. HisPatientId: his.ID,
  9484. PatientId: id,
  9485. SettleAccountsDate: recordDateTime,
  9486. Ctime: time.Now().Unix(),
  9487. Mtime: time.Now().Unix(),
  9488. Status: 1,
  9489. OrderStatus: 2,
  9490. MdtrtId: his.Number,
  9491. Number: chrg_bchno,
  9492. MedfeeSumamt: totals,
  9493. PayWay: pay_way,
  9494. PayWays: pay_ways,
  9495. PayPrice: pay_price,
  9496. MedType: strconv.Itoa(int(reg_type)),
  9497. PayCardNo: pay_card_no,
  9498. DiscountPrice: discount_price,
  9499. PreferentialPrice: preferential_price,
  9500. RealityPrice: reality_price,
  9501. FoundPrice: found_price,
  9502. MedicalInsurancePrice: medical_insurance_price,
  9503. PrivatePrice: private_price,
  9504. SettleEndTime: end_time,
  9505. SettleStartTime: start_time,
  9506. PsnPartAmt: totals,
  9507. PsnCashPay: totals,
  9508. SettleType: settle_accounts_type,
  9509. FaPiaoCode: fapiao_code,
  9510. FaPiaoNumber: fapiao_number,
  9511. Diagnosis: diagnosis_id,
  9512. PType: 2,
  9513. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9514. Decimal: decimal,
  9515. OthDesc: oth_desc,
  9516. CashPay: cash_pay,
  9517. WechatPay: wechat_pay,
  9518. AliPay: ali_pay,
  9519. JifenPay: jifen_pay,
  9520. BandCardPay: band_card_pay,
  9521. Creator: adminUser.AdminUser.Id,
  9522. CardDesc: card_desc,
  9523. }
  9524. err = service.CreateOrderTX(order, tx)
  9525. if err != nil {
  9526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9527. return
  9528. }
  9529. var customs []*Custom
  9530. for _, item := range prescriptions {
  9531. if item.Type == 1 { //药品a
  9532. for _, subItem := range item.HisDoctorAdviceInfo {
  9533. cus := &Custom{
  9534. AdviceId: subItem.ID,
  9535. ProjectId: 0,
  9536. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9537. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9538. FeedetlSn: subItem.FeedetlSn,
  9539. Price: fmt.Sprintf("%.4f", subItem.Price),
  9540. MedListCodg: subItem.MedListCodg,
  9541. Type: 1,
  9542. CostType: 9,
  9543. }
  9544. customs = append(customs, cus)
  9545. }
  9546. }
  9547. if item.Type == 2 { //项目
  9548. for _, subItem := range item.HisPrescriptionProject {
  9549. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9550. cus := &Custom{
  9551. AdviceId: 0,
  9552. ProjectId: subItem.ID,
  9553. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9554. Cut: fmt.Sprintf("%.4f", cnt),
  9555. FeedetlSn: subItem.FeedetlSn,
  9556. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9557. MedListCodg: subItem.MedListCodg,
  9558. Type: 2,
  9559. CostType: subItem.HisProject.CostClassify,
  9560. }
  9561. customs = append(customs, cus)
  9562. }
  9563. }
  9564. for _, item := range item.HisAdditionalCharge {
  9565. cus := &Custom{
  9566. ItemId: item.ID,
  9567. AdviceId: 0,
  9568. ProjectId: 0,
  9569. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9570. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9571. FeedetlSn: item.FeedetlSn,
  9572. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9573. MedListCodg: item.XtHisAddtionConfig.Code,
  9574. Type: 3,
  9575. CostType: 5,
  9576. }
  9577. customs = append(customs, cus)
  9578. }
  9579. }
  9580. for _, item := range customs {
  9581. var advice_id int64 = 0
  9582. var project_id int64 = 0
  9583. var item_id int64 = 0
  9584. var types int64 = 0
  9585. var med_chrgitm_type string
  9586. if item.Type == 1 {
  9587. advice_id = item.AdviceId
  9588. project_id = 0
  9589. item_id = 0
  9590. med_chrgitm_type = "09"
  9591. } else if item.Type == 2 {
  9592. med_chrgitm_type = "05"
  9593. if item.CostType == 3 {
  9594. med_chrgitm_type = "04"
  9595. }
  9596. if item.CostType == 8 {
  9597. med_chrgitm_type = "03"
  9598. }
  9599. advice_id = 0
  9600. item_id = 0
  9601. project_id = item.ProjectId
  9602. } else if item.Type == 3 {
  9603. advice_id = 0
  9604. item_id = item.ItemId
  9605. project_id = 0
  9606. med_chrgitm_type = "08"
  9607. }
  9608. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9609. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9610. pric, _ := strconv.ParseFloat(item.Price, 32)
  9611. info := &models.HisOrderInfo{
  9612. OrderNumber: order.Number,
  9613. UploadDate: time.Now().Unix(),
  9614. AdviceId: advice_id,
  9615. DetItemFeeSumamt: detItemFeeSumamt,
  9616. MedChrgitmType: med_chrgitm_type,
  9617. Cnt: cut,
  9618. Pric: pric,
  9619. PatientId: id,
  9620. Status: 1,
  9621. Mtime: time.Now().Unix(),
  9622. Ctime: time.Now().Unix(),
  9623. UserOrgId: adminUser.CurrentOrgId,
  9624. HisPatientId: his.ID,
  9625. OrderId: order.ID,
  9626. ProjectId: project_id,
  9627. Type: types,
  9628. ItemId: item_id,
  9629. }
  9630. service.CreateOrderInfoTX(info, tx)
  9631. }
  9632. his.Diagnosis = diagnosis_id
  9633. his.SickType = sick_type
  9634. his.RegisterType = reg_type
  9635. his.MedicalTreatmentType = reg_type
  9636. service.UpdataHisPateintTX(&his, tx)
  9637. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  9638. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  9639. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  9640. //判断是否使用了押金
  9641. if dec_way == "true" {
  9642. tmpstring := strconv.FormatInt(order.ID, 10)
  9643. //扣押金
  9644. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  9645. order.Decimal = decimal
  9646. service.UpDateOrderTwo(order, tx)
  9647. if errmsg != nil {
  9648. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  9649. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9650. return
  9651. }
  9652. }
  9653. if err == nil {
  9654. for _, info := range prescriptions {
  9655. if info.Type == 1 {
  9656. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  9657. }
  9658. if info.Type == 2 {
  9659. for _, sumItem := range info.HisPrescriptionProject {
  9660. if sumItem.Type == 3 {
  9661. var good models.DialysisBeforePrepareGoods
  9662. var newGood models.NewDialysisBeforePrepareGoods
  9663. var oldGood models.OldDialysisBeforePrepareGoods
  9664. good.GoodId = sumItem.GoodInfo.ID
  9665. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9666. count, _ := strconv.Atoi(sumItem.Count)
  9667. good.Count = int64(count)
  9668. good.StorehouseId = houseConfig.StorehouseOutInfo
  9669. good.ProjectId = sumItem.ID
  9670. good.PatientId = sumItem.PatientId
  9671. goods = append(goods, &good)
  9672. newGood.GoodId = sumItem.GoodInfo.ID
  9673. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9674. count2, _ := strconv.Atoi(sumItem.Count)
  9675. newGood.Count = int64(count2)
  9676. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9677. newGood.ProjectId = sumItem.ID
  9678. newGood.PatientId = sumItem.HisPatientId
  9679. newGoods = append(newGoods, &newGood)
  9680. oldGood.GoodId = sumItem.GoodInfo.ID
  9681. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9682. count3, _ := strconv.Atoi(sumItem.Count)
  9683. oldGood.Count = int64(count3)
  9684. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9685. oldGood.ProjectId = sumItem.ID
  9686. oldGood.RecordDate = sumItem.RecordDate
  9687. oldGood.PatientId = sumItem.HisPatientId
  9688. oldGoods = append(oldGoods, &oldGood)
  9689. }
  9690. }
  9691. }
  9692. }
  9693. if settConfig.IsOpen == 1 {
  9694. for _, item := range infoList {
  9695. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9696. if medical.IsUse == 2 {
  9697. //药品出库
  9698. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9699. //查询默认仓库
  9700. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9701. //查询默认仓库剩余多少库存
  9702. var sum_count int64
  9703. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9704. for _, its := range stockInfo {
  9705. if its.MaxUnit == medical.MaxUnit {
  9706. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9707. }
  9708. sum_count += its.StockMaxNumber + its.StockMinNumber
  9709. }
  9710. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9711. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9712. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9713. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9714. }
  9715. }
  9716. orgId := c.GetAdminUserInfo().CurrentOrgId
  9717. if len(oldGoods) > 0 {
  9718. timeStr := time.Now().Format("2006-01-02")
  9719. timeArr := strings.Split(timeStr, "-")
  9720. total, _ := service.FindAllWarehouseOut(orgId)
  9721. total = total + 1
  9722. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9723. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9724. number = number + total
  9725. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9726. operation_time := time.Now().Unix()
  9727. creater := c.GetAdminUserInfo().AdminUser.Id
  9728. //查询默认出库仓库库存
  9729. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9730. recordDateStr := time.Now().Format("2006-01-02")
  9731. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9732. nowtime := recordDate.Unix()
  9733. warehouseOut := models.WarehouseOut{
  9734. WarehouseOutOrderNumber: warehousing_out_order,
  9735. OperationTime: operation_time,
  9736. OrgId: orgId,
  9737. Creater: creater,
  9738. Ctime: time.Now().Unix(),
  9739. Status: 1,
  9740. WarehouseOutTime: nowtime,
  9741. Type: 1,
  9742. StorehouseId: storeConfig.StorehouseOutInfo,
  9743. IsCheck: 1,
  9744. OrderId: order.ID,
  9745. IsSys: 5,
  9746. }
  9747. //查询是否生成出库单
  9748. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9749. if out.ID == 0 {
  9750. service.AddSigleWarehouseOut(&warehouseOut)
  9751. }
  9752. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9753. for _, item := range oldGoods {
  9754. dialyPrepareOne := models.DialysisBeforePrepare{
  9755. GoodTypeId: item.GoodTypeId,
  9756. GoodId: item.GoodId,
  9757. PatientId: his.PatientId,
  9758. RecordDate: item.RecordDate,
  9759. UserOrgId: adminUser.CurrentOrgId,
  9760. Count: item.Count,
  9761. Ctime: time.Now().Unix(),
  9762. Creater: adminUser.AdminUser.Id,
  9763. CommdityCode: item.CommdityCode,
  9764. Status: 1,
  9765. StorehouseId: houseConfig.StorehouseOutInfo,
  9766. }
  9767. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9768. //非零用
  9769. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9770. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9771. //查询剩余库存
  9772. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9773. var sum_count int64
  9774. for _, item := range goodList {
  9775. sum_count += item.StockCount
  9776. }
  9777. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9778. //耗材
  9779. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9780. }
  9781. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9782. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9783. //查询剩余库存
  9784. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9785. var sum_count int64
  9786. for _, item := range goodList {
  9787. sum_count += item.StockCount
  9788. }
  9789. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9790. //耗材
  9791. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9792. }
  9793. }
  9794. }
  9795. }
  9796. c.ServeSuccessJSON(map[string]interface{}{
  9797. "msg": "结算成功",
  9798. })
  9799. }
  9800. }
  9801. }
  9802. // 退款
  9803. func (c *HisApiController) Refund() {
  9804. order_id, _ := c.GetInt64("order_id")
  9805. order, _ := service.GetHisOrderByID(order_id)
  9806. adminUser := c.GetAdminUserInfo()
  9807. orgid := c.GetAdminUserInfo().CurrentOrgId
  9808. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9809. if err != nil {
  9810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9811. return
  9812. }
  9813. tmp := strconv.FormatInt(order.ID, 10)
  9814. //当押金不为零时产生退费记录
  9815. if order.Decimal != 0 {
  9816. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9817. if err != nil {
  9818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9819. return
  9820. }
  9821. }
  9822. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9823. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9824. var goods []*models.DialysisBeforePrepareGoods
  9825. var newGoods []*models.NewDialysisBeforePrepareGoods
  9826. var infos []*models.HisDoctorAdviceInfo
  9827. for _, info := range orders {
  9828. if info.AdviceId > 0 && info.ProjectId == 0 {
  9829. infos = append(infos, &info.HisDoctorAdviceInfo)
  9830. }
  9831. if info.ProjectId > 0 && info.AdviceId == 0 {
  9832. if info.HisPrescriptionProject.Type == 3 {
  9833. var good models.DialysisBeforePrepareGoods
  9834. var newGood models.NewDialysisBeforePrepareGoods
  9835. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9836. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9837. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9838. good.Count = int64(count)
  9839. good.StorehouseId = houseConfig.StorehouseOutInfo
  9840. good.ProjectId = info.HisPrescriptionProject.ID
  9841. good.PatientId = info.PatientId
  9842. good.OrderId = order_id
  9843. goods = append(goods, &good)
  9844. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9845. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9846. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9847. newGood.Count = int64(count2)
  9848. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9849. newGood.ProjectId = info.HisPrescriptionProject.ID
  9850. newGood.RecordDate = order.SettleAccountsDate
  9851. newGood.UserOrgId = order.UserOrgId
  9852. newGood.PatientId = info.PatientId
  9853. newGood.OrderId = order_id
  9854. newGoods = append(newGoods, &newGood)
  9855. }
  9856. }
  9857. }
  9858. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9859. if settConfig.IsOpen == 1 {
  9860. for _, item := range infos {
  9861. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9862. }
  9863. for _, item := range newGoods {
  9864. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9865. }
  9866. }
  9867. c.ServeSuccessJSON(map[string]interface{}{
  9868. "msg": "退费成功",
  9869. })
  9870. }
  9871. func (c *HisApiController) RefundNumber() {
  9872. his_patient_id, _ := c.GetInt64("id")
  9873. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9874. info.Status = 0
  9875. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9876. if count > 0 {
  9877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9878. return
  9879. }
  9880. err := service.SaveHisPatient(info)
  9881. if err == nil {
  9882. c.ServeSuccessJSON(map[string]interface{}{
  9883. "msg": "退号成功",
  9884. })
  9885. } else {
  9886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9887. return
  9888. }
  9889. }
  9890. func (this *HisApiController) AdditionalCharge() {
  9891. dataBody := make(map[string]interface{}, 0)
  9892. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9893. fmt.Println(err)
  9894. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9895. patient_id := int64(dataBody["patient_id"].(float64))
  9896. medicineData, _ := dataBody["medicineData"].([]interface{})
  9897. adminUserInfo := this.GetAdminUserInfo()
  9898. orgId := adminUserInfo.CurrentOrgId
  9899. admin_user_id := adminUserInfo.AdminUser.Id
  9900. timeStr := time.Now().Format("2006-01-02")
  9901. timeLayout := "2006-01-02 15:04:05"
  9902. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9903. timenow := timeStringToTime.Unix()
  9904. var additionalCharges []*models.HisAdditionalCharge
  9905. for _, item := range medicineData {
  9906. var randNum int
  9907. randNum = rand.Intn(10000) + 1000
  9908. timestamp := time.Now().Unix()
  9909. tempTime := time.Unix(timestamp, 0)
  9910. timeFormat := tempTime.Format("20060102150405")
  9911. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9912. items := item.(map[string]interface{})
  9913. money := items["price"].(string)
  9914. item_id_str := items["item_id"].(string)
  9915. name := items["name"].(string)
  9916. id_str := items["id"].(string)
  9917. moneys, _ := strconv.ParseInt(money, 10, 64)
  9918. monStr := strconv.FormatInt(moneys, 10)
  9919. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9920. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9921. id, _ := strconv.ParseInt(id_str, 10, 64)
  9922. additionalCharge := &models.HisAdditionalCharge{
  9923. ID: id,
  9924. HisPatientId: his_patient_id,
  9925. UserOrgId: orgId,
  9926. PatientId: patient_id,
  9927. RecordDate: timenow,
  9928. Price: monneyStr,
  9929. Status: 1,
  9930. ItemName: name,
  9931. ItemId: item_id,
  9932. AdminUserId: admin_user_id,
  9933. CreatedTime: time.Now().Unix(),
  9934. OrderStatus: 0,
  9935. PrescriptionNumber: "",
  9936. BatchNumber: "",
  9937. FeedetlSn: p_number,
  9938. }
  9939. service.CreateAdditionalCharge(additionalCharge)
  9940. additionalCharges = append(additionalCharges, additionalCharge)
  9941. }
  9942. this.ServeSuccessJSON(map[string]interface{}{
  9943. "msg": "添加成功",
  9944. "additional_charges": additionalCharges,
  9945. })
  9946. }
  9947. func (this *HisApiController) DeleteAddition() {
  9948. id, _ := this.GetInt64("id")
  9949. //TODO 需要判断是否已经结算
  9950. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9951. if err == nil {
  9952. this.ServeSuccessJSON(map[string]interface{}{
  9953. "msg": "删除成功",
  9954. })
  9955. return
  9956. } else {
  9957. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9958. return
  9959. }
  9960. }
  9961. func (this *HisApiController) GetAdminUsers() {
  9962. adminUser := this.GetAdminUserInfo()
  9963. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9964. this.ServeSuccessJSON(map[string]interface{}{
  9965. "doctors": doctors,
  9966. })
  9967. }
  9968. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9969. change_type, _ := this.GetInt64("type", 0)
  9970. record_date := this.GetString("record_time")
  9971. patient_id, _ := this.GetInt64("patient_id", 0)
  9972. p_type, _ := this.GetInt64("p_type", 0)
  9973. timeLayout := "2006-01-02"
  9974. loc, _ := time.LoadLocation("Local")
  9975. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9976. record_time := theAdviceRecordTime.Unix()
  9977. adminUserInfo := this.GetAdminUserInfo()
  9978. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9979. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9980. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9981. if config.ID > 0 && config.IsOpen == 1 {
  9982. for _, subitems := range prescriptions {
  9983. for _, item := range subitems.VMHisPrescription {
  9984. for _, subItem := range item.HisDoctorAdviceInfo {
  9985. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9986. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9987. if info.RetailPrice > 0 {
  9988. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9989. subItem.Drug.RetailPrice = drug.RetailPrice
  9990. }
  9991. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9992. subItem.Drug.MinPrice = info.RetailPrice
  9993. subItem.Drug.RetailPrice = info.RetailPrice
  9994. }
  9995. }
  9996. }
  9997. }
  9998. }
  9999. }
  10000. if config.ID > 0 && config.IsOpen == 1 {
  10001. for _, subitems := range prescriptions {
  10002. for _, item := range subitems.VMHisPrescription {
  10003. for _, subItem := range item.HisPrescriptionProject {
  10004. if subItem.Type == 3 {
  10005. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10006. if info.Price > 0 {
  10007. subItem.GoodInfo.PackingPrice = info.Price
  10008. }
  10009. }
  10010. }
  10011. }
  10012. }
  10013. }
  10014. }
  10015. if err == nil {
  10016. if len(prescriptions) == 0 {
  10017. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  10018. return
  10019. } else {
  10020. this.ServeSuccessJSON(map[string]interface{}{
  10021. "prescriptions": prescriptions,
  10022. })
  10023. return
  10024. }
  10025. } else {
  10026. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10027. return
  10028. }
  10029. }
  10030. func (this *HisApiController) GetCallHisPrescription() {
  10031. patient_id, _ := this.GetInt64("patient_id", 0)
  10032. timeLayout := "2006-01-02"
  10033. loc, _ := time.LoadLocation("Local")
  10034. start_time := this.GetString("start_time")
  10035. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10036. end_time := this.GetString("end_time")
  10037. p_type, _ := this.GetInt64("p_type")
  10038. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10039. adminUserInfo := this.GetAdminUserInfo()
  10040. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  10041. //if
  10042. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  10043. //
  10044. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  10045. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10046. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10047. if config.ID > 0 && config.IsOpen == 1 {
  10048. for _, subitems := range prescriptions {
  10049. for _, item := range subitems.VMHisPrescription {
  10050. for _, subItem := range item.HisDoctorAdviceInfo {
  10051. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10052. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10053. if info.RetailPrice > 0 {
  10054. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10055. subItem.Drug.RetailPrice = drug.RetailPrice
  10056. }
  10057. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10058. subItem.Drug.MinPrice = info.RetailPrice
  10059. subItem.Drug.RetailPrice = info.RetailPrice
  10060. }
  10061. }
  10062. }
  10063. }
  10064. }
  10065. }
  10066. if config.ID > 0 && config.IsOpen == 1 {
  10067. for _, subitems := range prescriptions {
  10068. for _, item := range subitems.VMHisPrescription {
  10069. for _, subItem := range item.HisPrescriptionProject {
  10070. if subItem.Type == 3 {
  10071. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10072. if info.Price > 0 {
  10073. subItem.GoodInfo.PackingPrice = info.Price
  10074. }
  10075. }
  10076. }
  10077. }
  10078. }
  10079. }
  10080. }
  10081. if err == nil {
  10082. this.ServeSuccessJSON(map[string]interface{}{
  10083. "prescriptions": prescriptions,
  10084. })
  10085. return
  10086. } else {
  10087. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10088. return
  10089. }
  10090. }
  10091. func (this *HisApiController) GetHisDayPrescription() {
  10092. timeLayout := "2006-01-02"
  10093. loc, _ := time.LoadLocation("Local")
  10094. start_time := this.GetString("start_time")
  10095. patient_id, _ := this.GetInt64("patient_id", 0)
  10096. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10097. end_time := this.GetString("end_time")
  10098. p_type, _ := this.GetInt64("p_type")
  10099. order_status, _ := this.GetInt64("type")
  10100. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10101. adminUserInfo := this.GetAdminUserInfo()
  10102. var dayHisPrescription []*models.HisPrescription
  10103. var err error
  10104. if order_status == 1 || order_status == 0 {
  10105. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10106. } else if order_status == 2 {
  10107. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10108. }
  10109. var settle_total float64
  10110. for _, item := range dayHisPrescription {
  10111. if len(item.HisPrescriptionProject) > 0 {
  10112. for _, subItem := range item.HisPrescriptionProject {
  10113. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10114. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10115. settle_total = settle_total + total
  10116. }
  10117. }
  10118. if len(item.HisDoctorAdviceInfo) > 0 {
  10119. for _, subItem := range item.HisDoctorAdviceInfo {
  10120. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10121. settle_total = settle_total + total
  10122. }
  10123. }
  10124. }
  10125. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10126. if err == nil {
  10127. this.ServeSuccessJSON(map[string]interface{}{
  10128. "day_prescription": dayHisPrescription,
  10129. "settle_total": settle_total,
  10130. })
  10131. return
  10132. } else {
  10133. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10134. return
  10135. }
  10136. }
  10137. func (c *HisApiController) GetHisChargePatientList() {
  10138. record_date := c.GetString("record_date")
  10139. order_status, _ := c.GetInt64("type")
  10140. sch_type, _ := c.GetInt64("sch_type")
  10141. timeLayout := "2006-01-02"
  10142. loc, _ := time.LoadLocation("Local")
  10143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10144. if err != nil {
  10145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10146. return
  10147. }
  10148. recordDateTime := theTime.Unix()
  10149. adminInfo := c.GetAdminUserInfo()
  10150. var tempPatients []*service.NewTempPatients
  10151. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10152. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10153. if order_status != 2 {
  10154. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10155. } else {
  10156. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10157. }
  10158. } else {
  10159. if order_status != 2 {
  10160. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10161. } else {
  10162. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10163. }
  10164. }
  10165. var patients []*service.NewTempPatients
  10166. var patients_two []*service.NewTempPatients
  10167. for _, item := range tempPatients {
  10168. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10169. //过滤掉没挂号的和没开处方的
  10170. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10171. patients = append(patients, item)
  10172. }
  10173. //过滤掉没挂号的
  10174. if len(item.HisPatient) > 0 {
  10175. patients_two = append(patients_two, item)
  10176. }
  10177. } else {
  10178. if len(item.HisPrescription) > 0 {
  10179. patients = append(patients, item)
  10180. }
  10181. }
  10182. }
  10183. c.ServeSuccessJSON(map[string]interface{}{
  10184. "list": patients,
  10185. "list_two": patients_two,
  10186. })
  10187. }
  10188. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10189. record_date := c.GetString("record_date")
  10190. timeLayout := "2006-01-02"
  10191. loc, _ := time.LoadLocation("Local")
  10192. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10193. if err != nil {
  10194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10195. return
  10196. }
  10197. recordDateTime := theTime.Unix()
  10198. adminUser := c.GetAdminUserInfo()
  10199. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10200. var patients []*service.Patients
  10201. for _, item := range tempPatients {
  10202. if item.HisPatient.ID == 0 {
  10203. patients = append(patients, item)
  10204. }
  10205. }
  10206. c.ServeSuccessJSON(map[string]interface{}{
  10207. "list": patients,
  10208. //"list_two": patients_two,
  10209. })
  10210. }
  10211. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10212. newArr = make([]*service.Patients, 0)
  10213. for i := 0; i < len(patient); i++ {
  10214. repeat := false
  10215. for j := i + 1; j < len(patient); j++ {
  10216. if patient[i].ID == patient[j].ID {
  10217. repeat = true
  10218. break
  10219. }
  10220. }
  10221. if !repeat {
  10222. newArr = append(newArr, patient[i])
  10223. }
  10224. }
  10225. return
  10226. }
  10227. func (c *HisApiController) GetHisChargePatientInfo() {
  10228. patient_id, _ := c.GetInt64("patient_id")
  10229. his_patient_id, _ := c.GetInt64("his_patient_id")
  10230. record_date := c.GetString("record_date")
  10231. //start_time := c.GetString("start_time")
  10232. //end_time := c.GetString("end_time")
  10233. order_status, _ := c.GetInt64("type", 0)
  10234. p_type, _ := c.GetInt64("p_type", 0)
  10235. order_id, _ := c.GetInt64("order_id", 0)
  10236. timeLayout := "2006-01-02"
  10237. loc, _ := time.LoadLocation("Local")
  10238. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10239. if err != nil {
  10240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10241. return
  10242. }
  10243. recordDateTime := theTime.Unix()
  10244. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10245. //if err != nil {
  10246. //
  10247. //}
  10248. //startRecordDateTime := startTime.Unix()
  10249. //
  10250. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10251. //if err != nil {
  10252. //
  10253. //}
  10254. //endRecordDateTime := endTime.Unix()
  10255. admin := c.GetAdminUserInfo()
  10256. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10257. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10258. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10259. var prescriptions []*models.HisPrescription
  10260. //var unChargeMonthPrescriptions []*models.HisPrescription
  10261. order, _ := service.GetHisOrderByID(order_id)
  10262. if order_status == 1 || order_status == 0 {
  10263. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10264. } else if order_status == 2 {
  10265. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10266. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10267. }
  10268. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10269. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10270. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10271. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10272. //获取所有科室信息
  10273. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10274. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10275. c.ServeSuccessJSON(map[string]interface{}{
  10276. "his_info": his_patient_info,
  10277. "last_his_patient_info": last_his_patient_info,
  10278. "xt_info": xt_patient_info,
  10279. "prescription": prescriptions,
  10280. "case_history": case_history,
  10281. "info": patientPrescriptionInfo,
  10282. "last_info": lastPatientPrescriptionInfo,
  10283. "order": order,
  10284. "doctors": doctors,
  10285. "department": department,
  10286. "sch": sch,
  10287. })
  10288. return
  10289. }
  10290. func (c *HisApiController) GetAllOrderDetail() {
  10291. order_id, _ := c.GetInt64("id", 0)
  10292. order, _ := service.GetHisOrderByID(order_id)
  10293. if order.ID == 0 {
  10294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10295. return
  10296. }
  10297. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10298. org_id := c.GetAdminUserInfo().CurrentOrgId
  10299. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10300. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10301. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10302. c.ServeSuccessJSON(map[string]interface{}{
  10303. "order": order,
  10304. "order_info": order_info,
  10305. "patient": patient,
  10306. "admin_info": adminInfo,
  10307. "hospital_record": record,
  10308. })
  10309. return
  10310. }
  10311. func (c *HisApiController) GetAllOrderDetailCollect() {
  10312. order_id, _ := c.GetInt64("id", 0)
  10313. order, _ := service.GetHisOrderByID(order_id)
  10314. if order.ID == 0 {
  10315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10316. return
  10317. }
  10318. org_id := c.GetAdminUserInfo().CurrentOrgId
  10319. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10320. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10321. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10322. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10323. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10324. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10325. var bedCostTotal float64 = 0 //床位总费
  10326. //var bedCostSelfTotal float64 = 0 //床位自费
  10327. var operationCostTotal float64 = 0 //手术费
  10328. //var operationCostSelfTotal float64 = 0 //手术费
  10329. var otherCostTotal float64 = 0 //其他费用
  10330. //var otherCostSelfTotal float64 = 0 //其他费用
  10331. var materialCostTotal float64 = 0 //材料费
  10332. //var materialCostSelfTotal float64 = 0 //材料费
  10333. var westernMedicineCostTotal float64 = 0 //西药费
  10334. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10335. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10336. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10337. var checkCostTotal float64 = 0 //检查费
  10338. //var checkCostSelfTotal float64 = 0 //检查费
  10339. var laboratoryCostTotal float64 = 0 //化验费
  10340. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10341. var treatCostTotal float64 = 0 //治疗费用
  10342. //var treatCostSelfTotal float64 = 0 //治疗费用
  10343. var zhenChaCostTotal float64 = 0 //其他费用
  10344. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10345. decimal.DivisionPrecision = 2
  10346. var BalanceAccountsType int64
  10347. if his.ID > 0 {
  10348. BalanceAccountsType = his.BalanceAccountsType
  10349. } else {
  10350. BalanceAccountsType = record.BalanceAccountsType
  10351. }
  10352. if BalanceAccountsType != 2 {
  10353. for _, item := range order_info {
  10354. if org_id == 10215 {
  10355. if item.MedChrgitmType == "01" { //床位费
  10356. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10357. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10358. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10359. }
  10360. if item.MedChrgitmType == "02" { //诊察费
  10361. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10362. //zhenChaCostSelfTotal = zhenChaCostTotal
  10363. }
  10364. if item.MedChrgitmType == "03" { //检查费
  10365. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10366. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10367. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10368. }
  10369. //if item.MedChrgitmType == "02" { //检查费
  10370. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10371. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10372. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10373. //}
  10374. if item.MedChrgitmType == "04" { //化验费
  10375. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10376. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10377. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10378. }
  10379. if item.MedChrgitmType == "05" { //治疗费
  10380. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10381. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10382. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10383. }
  10384. if item.MedChrgitmType == "06" { //手术费
  10385. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10386. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10387. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10388. }
  10389. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10390. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10391. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10392. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10393. }
  10394. if item.MedChrgitmType == "09" { //西药费
  10395. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10396. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10397. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10398. }
  10399. if item.MedChrgitmType == "11" { //中成费
  10400. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10401. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10402. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10403. }
  10404. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10405. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10406. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10407. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10408. }
  10409. } else if org_id == 10188 || org_id == 10217 {
  10410. if item.MedChrgitmType == "01" { //床位费
  10411. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10412. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10413. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10414. }
  10415. if item.MedChrgitmType == "02" { //诊察费
  10416. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10417. //zhenChaCostSelfTotal = zhenChaCostTotal
  10418. }
  10419. if item.MedChrgitmType == "03" { //检查费
  10420. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10421. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10422. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10423. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10424. }
  10425. //if item.MedChrgitmType == "02" { //检查费
  10426. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10427. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10428. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10429. //}
  10430. if item.MedChrgitmType == "04" { //化验费
  10431. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10432. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10433. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10434. }
  10435. if item.MedChrgitmType == "05" { //治疗费
  10436. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10437. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10438. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10439. }
  10440. if item.MedChrgitmType == "06" { //手术费
  10441. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10442. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10443. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10444. }
  10445. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10446. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10447. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10448. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10449. }
  10450. if item.MedChrgitmType == "09" { //西药费
  10451. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10452. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10453. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10454. }
  10455. if item.MedChrgitmType == "11" { //中成费
  10456. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10457. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10458. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10459. }
  10460. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10461. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10462. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10463. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10464. }
  10465. } else {
  10466. if item.MedChrgitmType == "01" { //床位费
  10467. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10468. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10469. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10470. }
  10471. //if item.MedChrgitmType == "02" { //诊察费
  10472. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10473. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10474. //}
  10475. if item.MedChrgitmType == "03" { //检查费
  10476. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10477. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10478. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10479. }
  10480. //if item.MedChrgitmType == "02" { //检查费
  10481. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10482. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10483. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10484. //}
  10485. if item.MedChrgitmType == "04" { //化验费
  10486. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10487. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10488. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10489. }
  10490. if item.MedChrgitmType == "05" { //治疗费
  10491. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10492. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10493. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10494. }
  10495. if item.MedChrgitmType == "06" { //手术费
  10496. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10497. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10498. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10499. }
  10500. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10501. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10502. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10503. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10504. }
  10505. if item.MedChrgitmType == "09" { //西药费
  10506. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10507. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10508. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10509. }
  10510. if item.MedChrgitmType == "11" { //中成费
  10511. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10512. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10513. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10514. }
  10515. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10516. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10517. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10518. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10519. }
  10520. }
  10521. }
  10522. c.ServeSuccessJSON(map[string]interface{}{
  10523. "order": order,
  10524. "order_info": order_info,
  10525. "patient": patient,
  10526. "admin_info": adminInfo,
  10527. "his_hospital": record,
  10528. "bedCostTotal": bedCostTotal,
  10529. "operationCostTotal": operationCostTotal,
  10530. "otherCostTotal": otherCostTotal,
  10531. "materialCostTotal": materialCostTotal,
  10532. "westernMedicineCostTotal": westernMedicineCostTotal,
  10533. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10534. "checkCostTotal": checkCostTotal,
  10535. "zhenChaCostTotal": zhenChaCostTotal,
  10536. "laboratoryCostTotal": laboratoryCostTotal,
  10537. "treatCostTotal": treatCostTotal,
  10538. })
  10539. } else {
  10540. for _, item := range order_info {
  10541. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10542. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10543. item.MedChrgitmType = "09"
  10544. }
  10545. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10546. if item.HisPrescriptionProject.Type == 2 {
  10547. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10548. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10549. case 0:
  10550. item.MedChrgitmType = "0"
  10551. break
  10552. case 1:
  10553. item.MedChrgitmType = "14"
  10554. break
  10555. case 2:
  10556. item.MedChrgitmType = "05"
  10557. break
  10558. case 3:
  10559. item.MedChrgitmType = "03"
  10560. break
  10561. case 4:
  10562. item.MedChrgitmType = "03"
  10563. break
  10564. case 5:
  10565. item.MedChrgitmType = "08"
  10566. break
  10567. case 6:
  10568. item.MedChrgitmType = "14"
  10569. break
  10570. case 7:
  10571. item.MedChrgitmType = "14"
  10572. break
  10573. case 8:
  10574. item.MedChrgitmType = "03"
  10575. break
  10576. case 9:
  10577. item.MedChrgitmType = "14"
  10578. break
  10579. case 10:
  10580. item.MedChrgitmType = "14"
  10581. break
  10582. case 11:
  10583. item.MedChrgitmType = "06"
  10584. break
  10585. case 12:
  10586. item.MedChrgitmType = "12"
  10587. break
  10588. case 13:
  10589. item.MedChrgitmType = "01"
  10590. break
  10591. case 14:
  10592. item.MedChrgitmType = "04"
  10593. break
  10594. case 15:
  10595. item.MedChrgitmType = "14"
  10596. break
  10597. }
  10598. } else {
  10599. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10600. case 1:
  10601. item.MedChrgitmType = "14"
  10602. break
  10603. case 2:
  10604. item.MedChrgitmType = "05"
  10605. break
  10606. case 3:
  10607. item.MedChrgitmType = "04"
  10608. break
  10609. case 4:
  10610. item.MedChrgitmType = "14"
  10611. break
  10612. case 5:
  10613. item.MedChrgitmType = "08"
  10614. break
  10615. case 6:
  10616. item.MedChrgitmType = "14"
  10617. break
  10618. case 7:
  10619. item.MedChrgitmType = "14"
  10620. break
  10621. case 8:
  10622. item.MedChrgitmType = "03"
  10623. break
  10624. case 9:
  10625. item.MedChrgitmType = "14"
  10626. break
  10627. }
  10628. }
  10629. } else if item.HisPrescriptionProject.Type == 3 {
  10630. item.MedChrgitmType = "08"
  10631. }
  10632. }
  10633. }
  10634. for _, item := range order_info {
  10635. if org_id == 10215 {
  10636. if item.MedChrgitmType == "01" { //床位费
  10637. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10638. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10639. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10640. }
  10641. if item.MedChrgitmType == "02" { //诊察费
  10642. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10643. //zhenChaCostSelfTotal = zhenChaCostTotal
  10644. }
  10645. if item.MedChrgitmType == "03" { //检查费
  10646. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10647. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10648. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10649. }
  10650. //if item.MedChrgitmType == "02" { //检查费
  10651. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10652. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10653. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10654. //}
  10655. if item.MedChrgitmType == "04" { //化验费
  10656. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10657. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10658. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10659. }
  10660. if item.MedChrgitmType == "05" { //治疗费
  10661. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10662. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10663. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10664. }
  10665. if item.MedChrgitmType == "06" { //手术费
  10666. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10667. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10668. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10669. }
  10670. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10671. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10672. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10673. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10674. }
  10675. if item.MedChrgitmType == "09" { //西药费
  10676. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10677. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10678. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10679. }
  10680. if item.MedChrgitmType == "11" { //中成费
  10681. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10682. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10683. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10684. }
  10685. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10686. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10687. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10688. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10689. }
  10690. } else {
  10691. if item.MedChrgitmType == "01" { //床位费
  10692. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10693. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10694. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10695. }
  10696. //if item.MedChrgitmType == "02" { //诊察费
  10697. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10698. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10699. //}
  10700. if item.MedChrgitmType == "03" { //检查费
  10701. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10702. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10703. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10704. }
  10705. //if item.MedChrgitmType == "02" { //检查费
  10706. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10707. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10708. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10709. //}
  10710. if item.MedChrgitmType == "04" { //化验费
  10711. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10712. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10713. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10714. }
  10715. if item.MedChrgitmType == "05" { //治疗费
  10716. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10717. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10718. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10719. }
  10720. if item.MedChrgitmType == "06" { //手术费
  10721. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10722. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10723. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10724. }
  10725. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10726. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10727. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10728. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10729. }
  10730. if item.MedChrgitmType == "09" { //西药费
  10731. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10732. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10733. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10734. }
  10735. if item.MedChrgitmType == "11" { //中成费
  10736. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10737. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10738. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10739. }
  10740. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10741. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10742. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10743. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10744. }
  10745. }
  10746. }
  10747. c.ServeSuccessJSON(map[string]interface{}{
  10748. "order": order,
  10749. "order_info": order_info,
  10750. "patient": patient,
  10751. "admin_info": adminInfo,
  10752. "his_hospital": record,
  10753. "bedCostTotal": bedCostTotal,
  10754. "operationCostTotal": operationCostTotal,
  10755. "otherCostTotal": otherCostTotal,
  10756. "materialCostTotal": materialCostTotal,
  10757. "westernMedicineCostTotal": westernMedicineCostTotal,
  10758. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10759. "checkCostTotal": checkCostTotal,
  10760. "zhenChaCostTotal": zhenChaCostTotal,
  10761. "laboratoryCostTotal": laboratoryCostTotal,
  10762. "treatCostTotal": treatCostTotal,
  10763. })
  10764. }
  10765. }
  10766. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10767. page, _ := c.GetInt64("page")
  10768. limit, _ := c.GetInt64("limit")
  10769. keywords := c.GetString("keywords")
  10770. start_time := c.GetString("start_time")
  10771. end_time := c.GetString("end_time")
  10772. //clr_type := c.GetString("clr_type")
  10773. insutype := c.GetString("insutype")
  10774. timeLayout := "2006-01-02"
  10775. loc, _ := time.LoadLocation("Local")
  10776. var theStartTIme int64
  10777. if len(start_time) > 0 {
  10778. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10779. theStartTIme = theTime.Unix()
  10780. }
  10781. var theEndtTIme int64
  10782. if len(end_time) > 0 {
  10783. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10784. theEndtTIme = theTime.Unix()
  10785. }
  10786. if page <= 0 {
  10787. page = 1
  10788. }
  10789. if limit <= 0 {
  10790. limit = 10
  10791. }
  10792. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10793. c.ServeSuccessJSON(map[string]interface{}{
  10794. "total": total,
  10795. "list": list,
  10796. })
  10797. return
  10798. }
  10799. func (c *HisApiController) GetPutOnRecordList() {
  10800. page, _ := c.GetInt64("page")
  10801. limit, _ := c.GetInt64("limit")
  10802. keywords := c.GetString("keywords")
  10803. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10804. if page <= 0 {
  10805. page = 1
  10806. }
  10807. if limit <= 0 {
  10808. limit = 10
  10809. }
  10810. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10811. c.ServeSuccessJSON(map[string]interface{}{
  10812. "total": total,
  10813. "list": list,
  10814. })
  10815. return
  10816. }
  10817. func (c *HisApiController) GetCompareData() {
  10818. start_time := c.GetString("start_time")
  10819. end_time := c.GetString("end_time")
  10820. insutype := c.GetString("insutype")
  10821. clr_type := c.GetString("clr_type")
  10822. timeLayout := "2006-01-02"
  10823. loc, _ := time.LoadLocation("Local")
  10824. var theStartTIme int64
  10825. if len(start_time) > 0 {
  10826. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10827. if err != nil {
  10828. theStartTIme = 0
  10829. }
  10830. theStartTIme = theTime.Unix()
  10831. }
  10832. var theEndtTIme int64
  10833. if len(end_time) > 0 {
  10834. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10835. if err != nil {
  10836. theEndtTIme = 0
  10837. }
  10838. theEndtTIme = theTime.Unix()
  10839. }
  10840. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10841. fmt.Println(err)
  10842. if err == nil {
  10843. c.ServeSuccessJSON(map[string]interface{}{
  10844. "list": formData,
  10845. })
  10846. } else {
  10847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10848. return
  10849. }
  10850. }
  10851. func (c *HisApiController) GetFaPiaoData() {
  10852. order_id, _ := c.GetInt64("order_id")
  10853. patient_id, _ := c.GetInt64("patient_id")
  10854. //number := c.GetString("number")
  10855. adminUser := c.GetAdminUserInfo()
  10856. order, _ := service.GetHisOrderByID(order_id)
  10857. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10858. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10859. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10860. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10861. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10862. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10863. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10864. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10865. var bedCostTotal float64 = 0 //床位总费
  10866. var bedCostSelfTotal float64 = 0 //床位自费
  10867. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10868. var operationCostTotal float64 = 0 //手术费
  10869. var operationCostSelfTotal float64 = 0 //手术费
  10870. var operationCostPartSelfTotal float64 = 0 //手术费
  10871. var otherCostTotal float64 = 0 //其他费用
  10872. var otherCostSelfTotal float64 = 0 //其他费用
  10873. var otherCostPartSelfTotal float64 = 0 //其他费用
  10874. var materialCostTotal float64 = 0 //材料费
  10875. var materialCostSelfTotal float64 = 0 //材料费
  10876. var materialCostPartSelfTotal float64 = 0 //材料费
  10877. var westernMedicineCostTotal float64 = 0 //西药费
  10878. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10879. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10880. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10881. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10882. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10883. var checkCostTotal float64 = 0 //检查费
  10884. var checkCostSelfTotal float64 = 0 //检查费
  10885. var checkCostPartSelfTotal float64 = 0 //检查费
  10886. var hiliCostTotal float64 = 0 //护理费
  10887. var hiliCostSelfTotal float64 = 0 //护理费
  10888. var hiliCostPartSelfTotal float64 = 0 //护理费
  10889. var laboratoryCostTotal float64 = 0 //化验费
  10890. var laboratoryCostSelfTotal float64 = 0 //化验费
  10891. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10892. var treatCostTotal float64 = 0 //治疗费用
  10893. var treatCostSelfTotal float64 = 0 //治疗费用
  10894. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10895. var zhenChaCostTotal float64 = 0 //其他费用
  10896. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10897. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10898. decimal.DivisionPrecision = 2
  10899. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10900. var balanceAccountsType int64
  10901. if his.ID > 0 {
  10902. balanceAccountsType = his.BalanceAccountsType
  10903. } else {
  10904. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10905. }
  10906. if balanceAccountsType == 2 {
  10907. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10908. for _, item := range orderInfos_two {
  10909. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10910. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10911. item.MedChrgitmType = "09"
  10912. }
  10913. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10914. if item.HisPrescriptionProject.Type == 2 {
  10915. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10916. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10917. case 0:
  10918. item.MedChrgitmType = "0"
  10919. break
  10920. case 1:
  10921. item.MedChrgitmType = "14"
  10922. break
  10923. case 2:
  10924. item.MedChrgitmType = "05"
  10925. break
  10926. case 3:
  10927. item.MedChrgitmType = "03"
  10928. break
  10929. case 4:
  10930. item.MedChrgitmType = "03"
  10931. break
  10932. case 5:
  10933. item.MedChrgitmType = "08"
  10934. break
  10935. case 6:
  10936. item.MedChrgitmType = "14"
  10937. break
  10938. case 7:
  10939. item.MedChrgitmType = "14"
  10940. break
  10941. case 8:
  10942. item.MedChrgitmType = "03"
  10943. break
  10944. case 9:
  10945. item.MedChrgitmType = "14"
  10946. break
  10947. case 10:
  10948. item.MedChrgitmType = "14"
  10949. break
  10950. case 11:
  10951. item.MedChrgitmType = "06"
  10952. break
  10953. case 12:
  10954. item.MedChrgitmType = "12"
  10955. break
  10956. case 13:
  10957. item.MedChrgitmType = "01"
  10958. break
  10959. case 14:
  10960. item.MedChrgitmType = "04"
  10961. break
  10962. case 15:
  10963. item.MedChrgitmType = "02"
  10964. break
  10965. }
  10966. } else {
  10967. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10968. case 1:
  10969. item.MedChrgitmType = "14"
  10970. break
  10971. case 2:
  10972. item.MedChrgitmType = "05"
  10973. break
  10974. case 3:
  10975. item.MedChrgitmType = "04"
  10976. break
  10977. case 4:
  10978. item.MedChrgitmType = "03"
  10979. break
  10980. case 5:
  10981. item.MedChrgitmType = "08"
  10982. break
  10983. case 6:
  10984. item.MedChrgitmType = "14"
  10985. break
  10986. case 7:
  10987. item.MedChrgitmType = "14"
  10988. break
  10989. case 8:
  10990. item.MedChrgitmType = "03"
  10991. break
  10992. case 9:
  10993. item.MedChrgitmType = "14"
  10994. break
  10995. }
  10996. }
  10997. } else if item.HisPrescriptionProject.Type == 3 {
  10998. item.MedChrgitmType = "08"
  10999. }
  11000. }
  11001. }
  11002. for _, item := range orderInfos_two {
  11003. fmt.Println(item.MedChrgitmType)
  11004. if item.MedChrgitmType == "07" { //床位费
  11005. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11006. hiliCostSelfTotal = hiliCostTotal
  11007. }
  11008. if item.MedChrgitmType == "01" { //床位费
  11009. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11010. bedCostSelfTotal = bedCostTotal
  11011. }
  11012. if item.MedChrgitmType == "02" { //诊察费
  11013. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11014. zhenChaCostSelfTotal = zhenChaCostTotal
  11015. }
  11016. if item.MedChrgitmType == "03" { //检查费
  11017. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11018. checkCostSelfTotal = checkCostTotal
  11019. }
  11020. if item.MedChrgitmType == "04" { //化验费
  11021. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11022. laboratoryCostSelfTotal = laboratoryCostTotal
  11023. }
  11024. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11025. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11026. treatCostSelfTotal = treatCostTotal
  11027. }
  11028. if item.MedChrgitmType == "06" { //手术费
  11029. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11030. operationCostSelfTotal = treatCostTotal
  11031. }
  11032. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  11033. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11034. materialCostSelfTotal = materialCostTotal
  11035. }
  11036. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11037. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11038. westernMedicineCostSelfTotal = westernMedicineCostTotal
  11039. }
  11040. if item.MedChrgitmType == "11" { //中成费
  11041. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11042. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11043. }
  11044. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11045. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11046. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11047. otherCostSelfTotal = otherCostTotal
  11048. }
  11049. } else {
  11050. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11051. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11052. otherCostSelfTotal = otherCostTotal
  11053. }
  11054. }
  11055. }
  11056. } else {
  11057. for _, item := range orderInfos {
  11058. if item.MedChrgitmType == "01" { //床位费
  11059. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11060. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11061. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11062. }
  11063. if item.MedChrgitmType == "02" { //诊察费
  11064. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11065. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11066. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11067. }
  11068. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11069. if item.MedChrgitmType == "03" { //检查费
  11070. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11071. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11072. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11073. }
  11074. } else {
  11075. if item.MedChrgitmType == "03" { //检查费
  11076. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11077. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11078. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11079. }
  11080. }
  11081. if item.MedChrgitmType == "04" { //化验费
  11082. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11083. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11084. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11085. }
  11086. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11087. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11088. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11089. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11090. }
  11091. if item.MedChrgitmType == "06" { //手术费
  11092. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11093. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11094. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11095. }
  11096. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11097. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11098. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11099. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11100. }
  11101. if item.MedChrgitmType == "07" { //护理
  11102. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11103. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11104. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11105. }
  11106. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11107. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11108. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11109. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11110. }
  11111. if item.MedChrgitmType == "11" { //中成费
  11112. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11113. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11114. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11115. }
  11116. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11117. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11118. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11119. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11120. }
  11121. }
  11122. }
  11123. timeLayout := "2006-01-02"
  11124. loc, _ := time.LoadLocation("Local")
  11125. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11126. if err != nil {
  11127. }
  11128. startRecordDateTime := startTime.Unix()
  11129. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11130. if err != nil {
  11131. }
  11132. endRecordDateTime := endTime.Unix()
  11133. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11134. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11135. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11136. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11137. c.ServeSuccessJSON(map[string]interface{}{
  11138. "charge_admin_name": charge_admin.UserName,
  11139. "order_number": order.Number, //业务流水号
  11140. "id_card_no": his.IdCardNo, //社会保障号
  11141. "patient": patient,
  11142. "department_name": department.Name, //科室
  11143. "number": his.Number, //门诊号
  11144. "date": order.SettleAccountsDate, //结算日期
  11145. "name": order.PsnName, //姓名
  11146. "gender": patient.Gender, //性别
  11147. "psn_cash_money": order.PsnCashPay, //个人支付
  11148. "pay_way": "门诊", //结算方式
  11149. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11150. "admin_user_name": admin.UserName, //收款员
  11151. "order": order,
  11152. "order_info": orderInfos_two,
  11153. "his": his,
  11154. "bedCostTotal": bedCostTotal,
  11155. "bedCostSelfTotal": bedCostSelfTotal,
  11156. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11157. "operationCostTotal": operationCostTotal,
  11158. "operationCostSelfTotal": operationCostSelfTotal,
  11159. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11160. "otherCostTotal": otherCostTotal,
  11161. "otherCostSelfTotal": otherCostSelfTotal,
  11162. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11163. "materialCostTotal": materialCostTotal,
  11164. "materialCostSelfTotal": materialCostSelfTotal,
  11165. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11166. "westernMedicineCostTotal": westernMedicineCostTotal,
  11167. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11168. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11169. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11170. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11171. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11172. "checkCostTotal": checkCostTotal,
  11173. "checkCostSelfTotal": checkCostSelfTotal,
  11174. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11175. "laboratoryCostTotal": laboratoryCostTotal,
  11176. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11177. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11178. "treatCostTotal": treatCostTotal,
  11179. "treatCostSelfTotal": treatCostSelfTotal,
  11180. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11181. "zhenChaCostTotal": zhenChaCostTotal,
  11182. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11183. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11184. "his_hospital_record": his_hospital_record,
  11185. "pre_pay_money": pre_pay_money,
  11186. "refund_sum": sum,
  11187. "doctor_info": doctor_info,
  11188. "hiliCostTotal": hiliCostTotal,
  11189. "hiliCostSelfTotal": hiliCostSelfTotal,
  11190. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11191. })
  11192. }
  11193. //func (c *HisApiController) GetFaPiaoDatas() {
  11194. // order_ids := c.GetString("order_ids")
  11195. // patient_id, _ := c.GetInt64("patient_id")
  11196. // adminUser := c.GetAdminUserInfo()
  11197. //
  11198. // orders := strings.Split(order_ids, ",")
  11199. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11200. //
  11201. // for _, item := range orders {
  11202. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11203. // order, _ := service.GetHisOrderByID(order_id)
  11204. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11205. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11206. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11207. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11208. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11209. //
  11210. // }
  11211. //
  11212. // var bedCostTotal float64 = 0 //床位总费
  11213. // var bedCostSelfTotal float64 = 0 //床位自费
  11214. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11215. //
  11216. // var operationCostTotal float64 = 0 //手术费
  11217. // var operationCostSelfTotal float64 = 0 //手术费
  11218. // var operationCostPartSelfTotal float64 = 0 //手术费
  11219. //
  11220. // var otherCostTotal float64 = 0 //其他费用
  11221. // var otherCostSelfTotal float64 = 0 //其他费用
  11222. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11223. //
  11224. // var materialCostTotal float64 = 0 //材料费
  11225. // var materialCostSelfTotal float64 = 0 //材料费
  11226. // var materialCostPartSelfTotal float64 = 0 //材料费
  11227. //
  11228. // var westernMedicineCostTotal float64 = 0 //西药费
  11229. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11230. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11231. //
  11232. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11233. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11234. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11235. //
  11236. // var checkCostTotal float64 = 0 //检查费
  11237. // var checkCostSelfTotal float64 = 0 //检查费
  11238. // var checkCostPartSelfTotal float64 = 0 //检查费
  11239. //
  11240. // var laboratoryCostTotal float64 = 0 //化验费
  11241. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11242. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11243. //
  11244. // var treatCostTotal float64 = 0 //治疗费用
  11245. // var treatCostSelfTotal float64 = 0 //治疗费用
  11246. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11247. //
  11248. // var zhenChaCostTotal float64 = 0 //其他费用
  11249. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11250. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11251. //
  11252. // decimal.DivisionPrecision = 2
  11253. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11254. //
  11255. // var balanceAccountsType int64
  11256. // if his.ID > 0 {
  11257. // balanceAccountsType = his.BalanceAccountsType
  11258. // } else {
  11259. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11260. // }
  11261. // if balanceAccountsType == 2 {
  11262. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11263. // for _, item := range orderInfos_two {
  11264. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11265. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11266. // item.MedChrgitmType = "09"
  11267. // }
  11268. //
  11269. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11270. // if item.HisPrescriptionProject.Type == 2 {
  11271. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11272. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11273. // case 0:
  11274. // item.MedChrgitmType = "0"
  11275. // break
  11276. // case 1:
  11277. // item.MedChrgitmType = "14"
  11278. // break
  11279. // case 2:
  11280. // item.MedChrgitmType = "05"
  11281. //
  11282. // break
  11283. // case 3:
  11284. // item.MedChrgitmType = "03"
  11285. //
  11286. // break
  11287. // case 4:
  11288. // item.MedChrgitmType = "03"
  11289. //
  11290. // break
  11291. // case 5:
  11292. // item.MedChrgitmType = "08"
  11293. //
  11294. // break
  11295. // case 6:
  11296. // item.MedChrgitmType = "14"
  11297. //
  11298. // break
  11299. // case 7:
  11300. // item.MedChrgitmType = "14"
  11301. //
  11302. // break
  11303. // case 8:
  11304. // item.MedChrgitmType = "03"
  11305. // break
  11306. // case 9:
  11307. // item.MedChrgitmType = "14"
  11308. // break
  11309. // case 10:
  11310. // item.MedChrgitmType = "14"
  11311. // break
  11312. // case 11:
  11313. // item.MedChrgitmType = "06"
  11314. // break
  11315. // case 12:
  11316. // item.MedChrgitmType = "12"
  11317. // break
  11318. // case 13:
  11319. // item.MedChrgitmType = "01"
  11320. // break
  11321. // case 14:
  11322. // item.MedChrgitmType = "04"
  11323. // break
  11324. // case 15:
  11325. // item.MedChrgitmType = "02"
  11326. // break
  11327. //
  11328. // }
  11329. //
  11330. // } else {
  11331. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11332. //
  11333. // case 1:
  11334. // item.MedChrgitmType = "14"
  11335. // break
  11336. // case 2:
  11337. // item.MedChrgitmType = "05"
  11338. //
  11339. // break
  11340. // case 3:
  11341. // item.MedChrgitmType = "03"
  11342. //
  11343. // break
  11344. // case 4:
  11345. // item.MedChrgitmType = "03"
  11346. //
  11347. // break
  11348. // case 5:
  11349. // item.MedChrgitmType = "08"
  11350. //
  11351. // break
  11352. // case 6:
  11353. // item.MedChrgitmType = "14"
  11354. //
  11355. // break
  11356. // case 7:
  11357. // item.MedChrgitmType = "14"
  11358. //
  11359. // break
  11360. // case 8:
  11361. // item.MedChrgitmType = "03"
  11362. // break
  11363. // case 9:
  11364. // item.MedChrgitmType = "14"
  11365. // break
  11366. //
  11367. // }
  11368. //
  11369. // }
  11370. //
  11371. // } else if item.HisPrescriptionProject.Type == 3 {
  11372. // item.MedChrgitmType = "08"
  11373. // }
  11374. // }
  11375. // }
  11376. //
  11377. // for _, item := range orderInfos_two {
  11378. // fmt.Println(item.MedChrgitmType)
  11379. // if item.MedChrgitmType == "01" { //床位费
  11380. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11381. // bedCostSelfTotal = bedCostTotal
  11382. // }
  11383. //
  11384. // if item.MedChrgitmType == "02" { //诊察费
  11385. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11386. // zhenChaCostSelfTotal = zhenChaCostTotal
  11387. // }
  11388. //
  11389. // if item.MedChrgitmType == "03" { //检查费
  11390. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11391. // checkCostSelfTotal = checkCostTotal
  11392. // }
  11393. //
  11394. // if item.MedChrgitmType == "04" { //化验费
  11395. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11396. // laboratoryCostSelfTotal = laboratoryCostTotal
  11397. // }
  11398. //
  11399. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11400. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11401. // treatCostSelfTotal = treatCostTotal
  11402. // }
  11403. //
  11404. // if item.MedChrgitmType == "06" { //手术费
  11405. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11406. // operationCostSelfTotal = treatCostTotal
  11407. // }
  11408. //
  11409. // if item.MedChrgitmType == "08" { //材料费
  11410. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11411. // materialCostSelfTotal = materialCostTotal
  11412. // }
  11413. //
  11414. // if item.MedChrgitmType == "09" { //西药费
  11415. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11416. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11417. // }
  11418. //
  11419. // if item.MedChrgitmType == "11" { //中成费
  11420. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11421. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11422. // }
  11423. //
  11424. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11425. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11426. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11427. // otherCostSelfTotal = otherCostTotal
  11428. // }
  11429. // } else {
  11430. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11431. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11432. // otherCostSelfTotal = otherCostTotal
  11433. // }
  11434. //
  11435. // }
  11436. //
  11437. // }
  11438. //
  11439. // } else {
  11440. // for _, item := range orderInfos {
  11441. // if item.MedChrgitmType == "01" { //床位费
  11442. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11443. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11444. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11445. // }
  11446. //
  11447. // if item.MedChrgitmType == "02" { //诊察费
  11448. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11449. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11450. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11451. // }
  11452. //
  11453. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11454. // if item.MedChrgitmType == "03" { //检查费
  11455. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11456. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11457. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11458. //
  11459. // }
  11460. // } else {
  11461. // if item.MedChrgitmType == "03" { //检查费
  11462. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11463. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11464. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11465. // }
  11466. //
  11467. // }
  11468. //
  11469. // if item.MedChrgitmType == "04" { //化验费
  11470. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11471. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11472. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11473. //
  11474. // }
  11475. //
  11476. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11477. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11478. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11479. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11480. //
  11481. // }
  11482. //
  11483. // if item.MedChrgitmType == "06" { //手术费
  11484. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11485. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11486. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11487. // }
  11488. //
  11489. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11490. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11491. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11492. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11493. // }
  11494. //
  11495. // if item.MedChrgitmType == "09" { //西药费
  11496. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11497. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11498. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11499. // }
  11500. //
  11501. // if item.MedChrgitmType == "11" { //中成费
  11502. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11503. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11504. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11505. // }
  11506. //
  11507. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11508. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11509. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11510. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11511. // }
  11512. //
  11513. // }
  11514. // }
  11515. // timeLayout := "2006-01-02"
  11516. // loc, _ := time.LoadLocation("Local")
  11517. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11518. // if err != nil {
  11519. // }
  11520. // startRecordDateTime := startTime.Unix()
  11521. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11522. // if err != nil {
  11523. // }
  11524. // endRecordDateTime := endTime.Unix()
  11525. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11526. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11527. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11528. //
  11529. // c.ServeSuccessJSON(map[string]interface{}{
  11530. // "order_number": order.Number, //业务流水号
  11531. // "id_card_no": his.IdCardNo, //社会保障号
  11532. // "department_name": department.Name, //科室
  11533. // "number": his.Number, //门诊号
  11534. // "date": order.SettleAccountsDate, //结算日期
  11535. // "name": order.PsnName, //姓名
  11536. // "gender": patient.Gender, //性别
  11537. // "psn_cash_money": order.PsnCashPay, //个人支付
  11538. // "pay_way": "门诊", //结算方式
  11539. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11540. // "admin_user_name": admin.UserName, //收款员
  11541. // "order": order,
  11542. // "order_info": orderInfos_two,
  11543. // "his": his,
  11544. // "bedCostTotal": bedCostTotal,
  11545. // "bedCostSelfTotal": bedCostSelfTotal,
  11546. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11547. // "operationCostTotal": operationCostTotal,
  11548. // "operationCostSelfTotal": operationCostSelfTotal,
  11549. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11550. // "otherCostTotal": otherCostTotal,
  11551. // "otherCostSelfTotal": otherCostSelfTotal,
  11552. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11553. // "materialCostTotal": materialCostTotal,
  11554. // "materialCostSelfTotal": materialCostSelfTotal,
  11555. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11556. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11557. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11558. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11559. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11560. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11561. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11562. // "checkCostTotal": checkCostTotal,
  11563. // "checkCostSelfTotal": checkCostSelfTotal,
  11564. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11565. // "laboratoryCostTotal": laboratoryCostTotal,
  11566. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11567. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11568. // "treatCostTotal": treatCostTotal,
  11569. // "treatCostSelfTotal": treatCostSelfTotal,
  11570. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11571. // "zhenChaCostTotal": zhenChaCostTotal,
  11572. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11573. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11574. // "his_hospital_record": his_hospital_record,
  11575. // "pre_pay_money": pre_pay_money,
  11576. // "refund_sum": sum,
  11577. // })
  11578. //
  11579. //}
  11580. func (this *HisApiController) GetIncomeStatisticsData() {
  11581. start_time := this.GetString("start_time")
  11582. end_time := this.GetString("end_time")
  11583. key_words := this.GetString("key_words")
  11584. limit, _ := this.GetInt64("limit")
  11585. page, _ := this.GetInt64("page")
  11586. if page <= 0 {
  11587. page = 1
  11588. }
  11589. if limit <= 0 {
  11590. limit = 10
  11591. }
  11592. statistics_type, _ := this.GetInt64("statistics_type")
  11593. admin := this.GetAdminUserInfo()
  11594. timeLayout := "2006-01-02"
  11595. loc, _ := time.LoadLocation("Local")
  11596. var theStartTIme int64
  11597. if len(start_time) > 0 {
  11598. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11599. if err != nil {
  11600. theStartTIme = 0
  11601. }
  11602. theStartTIme = theTime.Unix()
  11603. }
  11604. var theEndtTIme int64
  11605. if len(end_time) > 0 {
  11606. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11607. if err != nil {
  11608. theEndtTIme = 0
  11609. }
  11610. theEndtTIme = theTime.Unix()
  11611. }
  11612. if statistics_type == 1 {
  11613. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11614. this.ServeSuccessJSON(map[string]interface{}{
  11615. "list": list,
  11616. "total": total,
  11617. })
  11618. } else {
  11619. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11620. this.ServeSuccessJSON(map[string]interface{}{
  11621. "list": list,
  11622. "total": total,
  11623. })
  11624. }
  11625. }
  11626. func (c *HisApiController) PostProjectInformation() {
  11627. adminUser := c.GetAdminUserInfo()
  11628. orgId := adminUser.CurrentOrgId
  11629. dataBody := make(map[string]interface{}, 0)
  11630. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11631. if err != nil {
  11632. utils.ErrorLog(err.Error())
  11633. return
  11634. }
  11635. utils.ErrorLog("%v", dataBody)
  11636. var projectList []*models.HisProject
  11637. var total_goods []interface{}
  11638. tempProjects := dataBody["projects"].([]interface{})
  11639. total_goods = tempProjects
  11640. for index, projectMap := range tempProjects {
  11641. projectM := projectMap.(map[string]interface{})
  11642. var project models.HisProject
  11643. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  11644. utils.ErrorLog("project_name")
  11645. return
  11646. }
  11647. project_name, _ := projectM["project_name"].(string)
  11648. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  11649. err_log := models.ExportErrLog{
  11650. LogType: 6,
  11651. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11652. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  11653. Status: 1,
  11654. CreateTime: time.Now().Unix(),
  11655. UpdateTime: time.Now().Unix(),
  11656. ExportTime: time.Now().Unix(),
  11657. }
  11658. service.CreateExportErrLog(&err_log)
  11659. continue
  11660. }
  11661. project.ProjectName = project_name
  11662. prices := projectM["price"].(string)
  11663. price, _ := strconv.ParseFloat(prices, 64)
  11664. if price <= 0 { //名字为空则生成一条导入错误日志
  11665. err_log := models.ExportErrLog{
  11666. LogType: 6,
  11667. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11668. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  11669. Status: 1,
  11670. CreateTime: time.Now().Unix(),
  11671. UpdateTime: time.Now().Unix(),
  11672. ExportTime: time.Now().Unix(),
  11673. }
  11674. service.CreateExportErrLog(&err_log)
  11675. continue
  11676. }
  11677. project.Price = price
  11678. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  11679. utils.ErrorLog("unit_id")
  11680. return
  11681. }
  11682. unit := projectM["unit"].(string)
  11683. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  11684. err_log := models.ExportErrLog{
  11685. LogType: 6,
  11686. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11687. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11688. Status: 1,
  11689. CreateTime: time.Now().Unix(),
  11690. UpdateTime: time.Now().Unix(),
  11691. ExportTime: time.Now().Unix(),
  11692. }
  11693. service.CreateExportErrLog(&err_log)
  11694. continue
  11695. }
  11696. project.Unit = unit
  11697. cost_classify := projectM["cost_classify"].(string)
  11698. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11699. err_log := models.ExportErrLog{
  11700. LogType: 6,
  11701. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11702. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11703. Status: 1,
  11704. CreateTime: time.Now().Unix(),
  11705. UpdateTime: time.Now().Unix(),
  11706. ExportTime: time.Now().Unix(),
  11707. }
  11708. service.CreateExportErrLog(&err_log)
  11709. continue
  11710. }
  11711. var costClassify = "费用类别"
  11712. var cost_classify_id int64
  11713. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11714. if len(cost_classify) != 0 {
  11715. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11716. if errcode == gorm.ErrRecordNotFound {
  11717. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11718. dataconfig := models.DictDataconfig{
  11719. ParentId: costClassifyConfig.ID,
  11720. Module: "system",
  11721. OrgId: orgId,
  11722. Name: cost_classify,
  11723. FieldName: "",
  11724. Value: costConfig.Value + 1,
  11725. CreatedTime: "",
  11726. UpdatedTime: "",
  11727. CreateUserId: adminUser.AdminUser.Id,
  11728. Status: 1,
  11729. Remark: "",
  11730. DeleteIdSystem: 0,
  11731. Title: "",
  11732. Content: "",
  11733. Order: 0,
  11734. Code: "",
  11735. }
  11736. service.CreatedDicConfig(&dataconfig)
  11737. }
  11738. }
  11739. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11740. for _, it := range costClassList {
  11741. if cost_classify == it.Name {
  11742. cost_classify_id = int64(it.Value)
  11743. }
  11744. }
  11745. project.CostClassify = cost_classify_id
  11746. executive_section := projectM["executive_section"].(string)
  11747. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11748. err_log := models.ExportErrLog{
  11749. LogType: 6,
  11750. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11751. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11752. Status: 1,
  11753. CreateTime: time.Now().Unix(),
  11754. UpdateTime: time.Now().Unix(),
  11755. ExportTime: time.Now().Unix(),
  11756. }
  11757. service.CreateExportErrLog(&err_log)
  11758. continue
  11759. }
  11760. if len(executive_section) != 0 {
  11761. //查找科室是否有内容
  11762. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11763. if errcodedepart == gorm.ErrRecordNotFound {
  11764. department := models.XtHisDepartment{
  11765. Name: executive_section,
  11766. Status: 1,
  11767. UserOrgId: adminUser.CurrentOrgId,
  11768. CreatedTime: time.Now().Unix(),
  11769. }
  11770. service.CreateDePartment(&department)
  11771. }
  11772. }
  11773. var executive_section_id int64
  11774. departMentList, _ := service.GetAllDepartMent(orgId)
  11775. for _, it := range departMentList {
  11776. if executive_section == it.Name {
  11777. executive_section_id = it.ID
  11778. }
  11779. }
  11780. project.ExecutiveSection = executive_section_id
  11781. medical_coverage := projectM["medical_coverage"].(string)
  11782. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11783. err_log := models.ExportErrLog{
  11784. LogType: 6,
  11785. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11786. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11787. Status: 1,
  11788. CreateTime: time.Now().Unix(),
  11789. UpdateTime: time.Now().Unix(),
  11790. ExportTime: time.Now().Unix(),
  11791. }
  11792. service.CreateExportErrLog(&err_log)
  11793. continue
  11794. }
  11795. var medicalCoverage = "医保等级"
  11796. var medical_coverage_id int64
  11797. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11798. if len(medical_coverage) != 0 {
  11799. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11800. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11801. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11802. dataconfig := models.DictDataconfig{
  11803. ParentId: medicalCoverageConfig.ID,
  11804. Module: "system",
  11805. OrgId: orgId,
  11806. Name: medical_coverage,
  11807. FieldName: "",
  11808. Value: medicalCoverageConfig.Value + 1,
  11809. CreatedTime: "",
  11810. UpdatedTime: "",
  11811. CreateUserId: adminUser.AdminUser.Id,
  11812. Status: 1,
  11813. Remark: "",
  11814. DeleteIdSystem: 0,
  11815. Title: "",
  11816. Content: "",
  11817. Order: 0,
  11818. Code: "",
  11819. }
  11820. service.CreatedDicConfig(&dataconfig)
  11821. }
  11822. }
  11823. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11824. for _, it := range medicalCoverageList {
  11825. if medical_coverage == it.Name {
  11826. medical_coverage_id = int64(it.Value)
  11827. }
  11828. }
  11829. project.MedicalCoverage = medical_coverage_id
  11830. pinyin := projectM["pinyin"].(string)
  11831. project.Pinyin = pinyin
  11832. wubi := projectM["wubi"].(string)
  11833. project.Wubi = wubi
  11834. statistical_classification := projectM["statistical_classification"].(string)
  11835. var statisticalClassification = "统计分类"
  11836. var statistical_classification_id int64
  11837. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11838. if len(statistical_classification) != 0 {
  11839. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11840. if classificationerrcodes == gorm.ErrRecordNotFound {
  11841. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11842. dataconfig := models.DictDataconfig{
  11843. ParentId: classiFication.ID,
  11844. Module: "system",
  11845. OrgId: orgId,
  11846. Name: statistical_classification,
  11847. FieldName: "",
  11848. Value: classiFicationConfig.Value + 1,
  11849. CreatedTime: "",
  11850. UpdatedTime: "",
  11851. CreateUserId: adminUser.AdminUser.Id,
  11852. Status: 1,
  11853. Remark: "",
  11854. DeleteIdSystem: 0,
  11855. Title: "",
  11856. Content: "",
  11857. Order: 0,
  11858. Code: "",
  11859. }
  11860. service.CreatedDicConfig(&dataconfig)
  11861. }
  11862. }
  11863. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11864. for _, it := range classiFicationList {
  11865. if statistical_classification == it.Name {
  11866. statistical_classification_id = int64(it.Value)
  11867. }
  11868. }
  11869. project.StatisticalClassification = statistical_classification_id
  11870. disease_directory := int64(projectM["disease_directory"].(float64))
  11871. project.DiseaseDirectory = disease_directory
  11872. is_record := int64(projectM["is_record"].(float64))
  11873. project.IsRecord = is_record
  11874. medical_code := projectM["medical_code"].(string)
  11875. project.MedicalCode = medical_code
  11876. tube_color := projectM["tube_color"].(string)
  11877. var tubeColor = "试管颜色"
  11878. var tube_color_id int64
  11879. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11880. if len(tube_color) != 0 {
  11881. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11882. if errcodetube == gorm.ErrRecordNotFound {
  11883. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11884. dataconfig := models.DictDataconfig{
  11885. ParentId: tubeColorConfig.ID,
  11886. Module: "system",
  11887. OrgId: orgId,
  11888. Name: tube_color,
  11889. FieldName: "",
  11890. Value: tubeConfig.Value + 1,
  11891. CreatedTime: "",
  11892. UpdatedTime: "",
  11893. CreateUserId: adminUser.AdminUser.Id,
  11894. Status: 1,
  11895. Remark: "",
  11896. DeleteIdSystem: 0,
  11897. Title: "",
  11898. Content: "",
  11899. Order: 0,
  11900. Code: "",
  11901. }
  11902. service.CreatedDicConfig(&dataconfig)
  11903. }
  11904. }
  11905. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11906. for _, it := range tubeColorList {
  11907. if tube_color == it.Name {
  11908. tube_color_id = int64(it.Value)
  11909. }
  11910. }
  11911. project.TubeColor = tube_color_id
  11912. single_dose := projectM["single_dose"].(string)
  11913. project.SingleDose = single_dose
  11914. execution_frequency := projectM["execution_frequency"].(string)
  11915. project.ExecutionFrequency = execution_frequency
  11916. delivery_way := projectM["delivery_way"].(string)
  11917. project.DeliveryWay = delivery_way
  11918. number_days := projectM["number_days"].(string)
  11919. project.NumberDays = number_days
  11920. total := projectM["total"].(string)
  11921. project.Total = total
  11922. medical_status := int64(projectM["medical_status"].(float64))
  11923. project.MedicalStatus = medical_status
  11924. category := int64(projectM["category"].(float64))
  11925. project.Category = category
  11926. specail_project := int64(projectM["specail_project"].(float64))
  11927. project.SpecailProject = specail_project
  11928. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11929. project.SocialSecurityDirectoryCode = social_security_directory_code
  11930. remark := projectM["remark"].(string)
  11931. project.Remark = remark
  11932. record_date := projectM["record_date"].(string)
  11933. timeLayout := "2006-01-02"
  11934. loc, _ := time.LoadLocation("Local")
  11935. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11936. project.RecordDate = theTime.Unix()
  11937. projectList = append(projectList, &project)
  11938. }
  11939. export_time := time.Now().Unix()
  11940. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11941. if len(projectList) > 0 {
  11942. for _, item := range projectList {
  11943. hans := item.ProjectName // 要转换的汉字字符串
  11944. // 创建一个拼音转换器
  11945. p := pinyin.NewArgs()
  11946. // 将汉字转为拼音
  11947. pinyinSlice := pinyin.Pinyin(hans, p)
  11948. // 输出拼音
  11949. fmt.Println("Pinyin:", pinyinSlice)
  11950. // 获取首字母
  11951. firstLetter := ""
  11952. for _, py := range pinyinSlice {
  11953. if len(py) > 0 {
  11954. firstLetter += string(py[0][0])
  11955. }
  11956. }
  11957. item.FirstLetter = firstLetter
  11958. project := models.HisProject{
  11959. ProjectName: item.ProjectName,
  11960. Price: item.Price,
  11961. Unit: item.Unit,
  11962. CostClassify: item.CostClassify,
  11963. ExecutiveSection: item.ExecutiveSection,
  11964. MedicalCoverage: item.MedicalCoverage,
  11965. UserOrgId: orgId,
  11966. Status: 1,
  11967. CreatedTime: time.Now().Unix(),
  11968. Pinyin: item.Pinyin,
  11969. Wubi: item.Wubi,
  11970. StatisticalClassification: item.StatisticalClassification,
  11971. DiseaseDirectory: item.DiseaseDirectory,
  11972. IsRecord: item.IsRecord,
  11973. MedicalCode: item.MedicalCode,
  11974. TubeColor: item.TubeColor,
  11975. SingleDose: item.SingleDose,
  11976. DeliveryWay: item.DeliveryWay,
  11977. NumberDays: item.NumberDays,
  11978. Total: item.Total,
  11979. Category: item.Category,
  11980. MedicalStatus: item.MedicalStatus,
  11981. SpecailProject: item.SpecailProject,
  11982. RecordDate: item.RecordDate,
  11983. Remark: item.Remark,
  11984. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11985. ExecutionFrequency: item.ExecutionFrequency,
  11986. FirstLetter: item.FirstLetter,
  11987. }
  11988. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11989. if errcodeproject == gorm.ErrRecordNotFound {
  11990. service.CreateProjectInfomation(&project)
  11991. } else if errcodeproject == nil {
  11992. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11993. }
  11994. log := models.ExportLog{
  11995. LogType: 6,
  11996. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11997. TotalNum: int64(len(total_goods)),
  11998. FailNum: int64(len(errLogs)),
  11999. SuccessNum: int64(len(projectList)),
  12000. CreateTime: time.Now().Unix(),
  12001. UpdateTime: time.Now().Unix(),
  12002. ExportTime: export_time,
  12003. Status: 1,
  12004. }
  12005. service.CreateExportLog(&log)
  12006. c.ServeSuccessJSON(map[string]interface{}{
  12007. "msg": "导入成功",
  12008. "total_num": len(total_goods),
  12009. "success_num": len(projectList),
  12010. "fail_num": int64(len(errLogs)),
  12011. })
  12012. }
  12013. } else {
  12014. log := models.ExportLog{
  12015. LogType: 6,
  12016. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12017. TotalNum: int64(len(total_goods)),
  12018. FailNum: int64(len(errLogs)),
  12019. SuccessNum: int64(len(projectList)),
  12020. CreateTime: time.Now().Unix(),
  12021. UpdateTime: time.Now().Unix(),
  12022. ExportTime: export_time,
  12023. Status: 1,
  12024. }
  12025. service.CreateExportLog(&log)
  12026. c.ServeSuccessJSON(map[string]interface{}{
  12027. "msg": "导入成功",
  12028. "total_num": len(total_goods),
  12029. "success_num": len(projectList),
  12030. "fail_num": int64(len(errLogs)),
  12031. })
  12032. }
  12033. }
  12034. //func (this *HisApiController) EditProjectInformation(){
  12035. //
  12036. // id, _ := this.GetInt64("id")
  12037. // project_team := this.GetString("project_team")
  12038. // price := this.GetString("price")
  12039. // price_float, _ := strconv.ParseFloat(price, 64)
  12040. // pinyin := this.GetString("pinyin")
  12041. // wubi := this.GetString("wubi")
  12042. // tube_color, _ := this.GetInt64("tube_color")
  12043. // team_type, _ := this.GetInt64("team_type")
  12044. // remark := this.GetString("remark")
  12045. // ids := this.GetString("ids")
  12046. // item_id := this.GetString("item_id")
  12047. // projectTeam := models.XtHisProjectTeam{
  12048. // ProjectTeam: project_team,
  12049. // Price: price_float,
  12050. // Pinyin: pinyin,
  12051. // Wubi: wubi,
  12052. // TubeColor: tube_color,
  12053. // TeamType: team_type,
  12054. // Remark: remark,
  12055. // ProjectId: ids,
  12056. // ItemId: item_id,
  12057. // }
  12058. //
  12059. //
  12060. // dataBody := make(map[string]interface{}, 0)
  12061. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12062. // if err != nil {
  12063. // utils.ErrorLog(err.Error())
  12064. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12065. // return
  12066. // }
  12067. //
  12068. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12069. //
  12070. //
  12071. // if err != nil {
  12072. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12073. // return
  12074. // }
  12075. //
  12076. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12077. // infos, _ := dataBody["info"].([]interface{})
  12078. // if len(infos) > 0 {
  12079. // var ids []string
  12080. //
  12081. // for _, item := range infos {
  12082. // items := item.(map[string]interface{})
  12083. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12084. // utils.ErrorLog("id")
  12085. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12086. // return
  12087. // }
  12088. // id := int64(items["id"].(float64))
  12089. //
  12090. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12091. // utils.ErrorLog("type")
  12092. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12093. // return
  12094. // }
  12095. // types := int64(items["type"].(float64))
  12096. //
  12097. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12098. // utils.ErrorLog("number")
  12099. // }
  12100. //
  12101. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12102. //
  12103. // projectList := models.XtHisProjectList{
  12104. // Number: number,
  12105. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12106. // ProjectId: id,
  12107. // Status: 1,
  12108. // CreatedTime: time.Now().Unix(),
  12109. // UpdatedTime: time.Now().Unix(),
  12110. // TeamId: projectTeam.ID,
  12111. // Type: types,
  12112. // }
  12113. // list := projectList
  12114. //
  12115. // service.CreateProjectList(&list)
  12116. //
  12117. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12118. //
  12119. // }
  12120. // ids_str := strings.Join(ids, ",")
  12121. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12122. // service.SaveProjectTeam(&projectTeam)
  12123. // this.ServeSuccessJSON(map[string]interface{}{
  12124. // "projectTeam": projectTeam,
  12125. // })
  12126. // }
  12127. // }
  12128. //}
  12129. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12130. name := c.GetString("name")
  12131. mode_id, _ := c.GetInt64("mode", 0)
  12132. types, _ := c.GetInt64("type", 0)
  12133. patient_id, _ := c.GetInt64("patient_id", 0)
  12134. types = 1
  12135. adminInfo := c.GetAdminUserInfo()
  12136. template := &models.HisPrescriptionTemplate{
  12137. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12138. PatientId: patient_id,
  12139. Type: types,
  12140. Status: 1,
  12141. Ctime: time.Now().Unix(),
  12142. Mtime: time.Now().Unix(),
  12143. Name: name,
  12144. Mode: mode_id,
  12145. }
  12146. dataBody := make(map[string]interface{}, 0)
  12147. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12148. if err != nil {
  12149. utils.ErrorLog(err.Error())
  12150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12151. return
  12152. }
  12153. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12154. //如果已经存在记录则删除处方
  12155. if template_one.ID > 0 {
  12156. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12157. var ids []int64
  12158. var org_id int64
  12159. for _, item := range ps {
  12160. org_id = c.GetAdminUserInfo().CurrentOrgId
  12161. ids = append(ids, item.ID)
  12162. }
  12163. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12164. if err2 == nil {
  12165. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12166. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12167. if len(prescriptions) > 0 {
  12168. for _, item := range prescriptions {
  12169. items := item.(map[string]interface{})
  12170. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12171. utils.ErrorLog("type")
  12172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12173. return
  12174. }
  12175. types := int64(items["type"].(float64))
  12176. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12177. utils.ErrorLog("med_type")
  12178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12179. return
  12180. }
  12181. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12182. ctime := time.Now().Unix()
  12183. prescription := &models.HisPrescriptionInfoTemplate{
  12184. PatientId: patient_id,
  12185. UserOrgId: adminInfo.CurrentOrgId,
  12186. Ctime: ctime,
  12187. Mtime: ctime,
  12188. Type: types,
  12189. Modifier: adminInfo.AdminUser.Id,
  12190. Creator: adminInfo.AdminUser.Id,
  12191. Status: 1,
  12192. PTemplateId: template_one.ID,
  12193. MedType: med_type,
  12194. }
  12195. service.CreateHisPrescriptionInfoTemplate(prescription)
  12196. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12197. advices := items["advices"].([]interface{})
  12198. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12199. ctime := time.Now().Unix()
  12200. mtime := ctime
  12201. if len(advices) > 0 {
  12202. for _, advice := range advices {
  12203. var s models.HisPrescriptionAdviceTemplate
  12204. s.PrescriptionId = prescription.ID
  12205. s.AdviceType = 2
  12206. s.StopState = 2
  12207. s.ExecutionState = 2
  12208. s.Status = 1
  12209. s.UserOrgId = adminInfo.CurrentOrgId
  12210. s.CreatedTime = ctime
  12211. s.UpdatedTime = mtime
  12212. s.PatientId = patient_id
  12213. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12214. if errcode > 0 {
  12215. c.ServeFailJSONWithSGJErrorCode(errcode)
  12216. return
  12217. }
  12218. service.CreateHisPrescriptionAdviceTemplate(&s)
  12219. }
  12220. }
  12221. }
  12222. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12223. projects := items["project"].([]interface{})
  12224. if len(projects) > 0 {
  12225. for _, project := range projects {
  12226. var p models.HisPrescriptionProjectTemplate
  12227. p.PrescriptionId = prescription.ID
  12228. p.Ctime = time.Now().Unix()
  12229. p.Mtime = time.Now().Unix()
  12230. p.PatientId = patient_id
  12231. p.UserOrgId = adminInfo.CurrentOrgId
  12232. p.Status = 1
  12233. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12234. if errcode > 0 {
  12235. c.ServeFailJSONWithSGJErrorCode(errcode)
  12236. return
  12237. }
  12238. service.CreateHisPrescriptionProjectTemplate(&p)
  12239. }
  12240. }
  12241. }
  12242. }
  12243. c.ServeSuccessJSON(map[string]interface{}{
  12244. "msg": "创建成功",
  12245. })
  12246. }
  12247. }
  12248. } else {
  12249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12250. return
  12251. }
  12252. } else {
  12253. err3 := service.CreateHisPrescriptionTemplate(template)
  12254. if err3 == nil {
  12255. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12256. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12257. if len(prescriptions) > 0 {
  12258. for _, item := range prescriptions {
  12259. items := item.(map[string]interface{})
  12260. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12261. utils.ErrorLog("type")
  12262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12263. return
  12264. }
  12265. types := int64(items["type"].(float64))
  12266. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12267. utils.ErrorLog("med_type")
  12268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12269. return
  12270. }
  12271. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12272. ctime := time.Now().Unix()
  12273. prescription := &models.HisPrescriptionInfoTemplate{
  12274. PatientId: patient_id,
  12275. UserOrgId: adminInfo.CurrentOrgId,
  12276. Ctime: ctime,
  12277. Mtime: ctime,
  12278. Type: types,
  12279. Modifier: adminInfo.AdminUser.Id,
  12280. Creator: adminInfo.AdminUser.Id,
  12281. Status: 1,
  12282. PTemplateId: template.ID,
  12283. MedType: med_type,
  12284. }
  12285. service.CreateHisPrescriptionInfoTemplate(prescription)
  12286. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12287. advices := items["advices"].([]interface{})
  12288. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12289. ctime := time.Now().Unix()
  12290. mtime := ctime
  12291. if len(advices) > 0 {
  12292. for _, advice := range advices {
  12293. var s models.HisPrescriptionAdviceTemplate
  12294. s.PrescriptionId = prescription.ID
  12295. s.AdviceType = 2
  12296. s.StopState = 2
  12297. s.ExecutionState = 2
  12298. s.Status = 1
  12299. s.UserOrgId = adminInfo.CurrentOrgId
  12300. s.CreatedTime = ctime
  12301. s.UpdatedTime = mtime
  12302. s.PatientId = patient_id
  12303. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12304. if errcode > 0 {
  12305. c.ServeFailJSONWithSGJErrorCode(errcode)
  12306. return
  12307. }
  12308. service.CreateHisPrescriptionAdviceTemplate(&s)
  12309. }
  12310. }
  12311. }
  12312. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12313. projects := items["project"].([]interface{})
  12314. if len(projects) > 0 {
  12315. for _, project := range projects {
  12316. var p models.HisPrescriptionProjectTemplate
  12317. p.PrescriptionId = prescription.ID
  12318. p.Ctime = time.Now().Unix()
  12319. p.Mtime = time.Now().Unix()
  12320. p.PatientId = patient_id
  12321. p.UserOrgId = adminInfo.CurrentOrgId
  12322. p.Status = 1
  12323. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12324. if errcode > 0 {
  12325. c.ServeFailJSONWithSGJErrorCode(errcode)
  12326. return
  12327. }
  12328. service.CreateHisPrescriptionProjectTemplate(&p)
  12329. }
  12330. }
  12331. }
  12332. }
  12333. c.ServeSuccessJSON(map[string]interface{}{
  12334. "msg": "创建成功",
  12335. })
  12336. }
  12337. }
  12338. } else {
  12339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12340. return
  12341. }
  12342. }
  12343. }
  12344. func (c *HisApiController) PreSettle() {
  12345. id, _ := c.GetInt64("id")
  12346. record_time := c.GetString("record_time")
  12347. his_patient_id, _ := c.GetInt64("his_patient_id")
  12348. timeLayout := "2006-01-02"
  12349. loc, _ := time.LoadLocation("Local")
  12350. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12351. diagnosis_id := c.GetString("diagnosis")
  12352. sick_type, _ := c.GetInt64("sick_type")
  12353. reg_type, _ := c.GetInt64("p_type")
  12354. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12355. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12356. if err != nil {
  12357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12358. return
  12359. }
  12360. recordDateTime := theTime.Unix()
  12361. adminUser := c.GetAdminUserInfo()
  12362. var prescriptions []*models.HisPrescription
  12363. var start_time int64
  12364. var end_time int64
  12365. ids_str := c.GetString("ids")
  12366. ids_arr := strings.Split(ids_str, ",")
  12367. fmt.Println(reg_type)
  12368. if settle_accounts_type == 1 { //日结
  12369. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12370. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12371. } else {
  12372. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12373. }
  12374. fmt.Println(prescriptions)
  12375. } else { //月结
  12376. start_time_str := c.GetString("start_time")
  12377. end_time_str := c.GetString("end_time")
  12378. timeLayout := "2006-01-02"
  12379. loc, _ := time.LoadLocation("Local")
  12380. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12381. if err != nil {
  12382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12383. return
  12384. }
  12385. recordStartTime := theStartTime.Unix()
  12386. start_time = recordStartTime
  12387. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12388. if err != nil {
  12389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12390. return
  12391. }
  12392. recordEndTime := theEndTime.Unix()
  12393. end_time = recordEndTime
  12394. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12395. }
  12396. if reg_type == 1111 || reg_type == 1112 {
  12397. reg_type = 11
  12398. }
  12399. timestamp := time.Now().Unix()
  12400. tempTime := time.Unix(timestamp, 0)
  12401. timeFormat := tempTime.Format("20060102150405")
  12402. chrgBchno := rand.Intn(100000) + 10000
  12403. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12404. strconv.FormatInt(his.PatientId, 10)
  12405. var ids []int64
  12406. for _, item := range prescriptions {
  12407. ids = append(ids, item.ID)
  12408. }
  12409. fmt.Println(ids)
  12410. var total float64
  12411. for _, item := range prescriptions {
  12412. fmt.Println(item)
  12413. if item.Type == 1 { //药品
  12414. for _, subItem := range item.HisDoctorAdviceInfo {
  12415. total = total + (subItem.Price * subItem.PrescribingNumber)
  12416. }
  12417. }
  12418. if item.Type == 2 { //项目
  12419. for _, subItem := range item.HisPrescriptionProject {
  12420. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12421. total = total + (subItem.Price * cnt)
  12422. }
  12423. }
  12424. for _, subItem := range item.HisAdditionalCharge {
  12425. total = total + (subItem.Price * float64(subItem.Count))
  12426. }
  12427. }
  12428. allTotal := fmt.Sprintf("%.2f", total)
  12429. totals, _ := strconv.ParseFloat(allTotal, 64)
  12430. order := &models.HisOrder{
  12431. UserOrgId: adminUser.CurrentOrgId,
  12432. HisPatientId: his.ID,
  12433. PatientId: id,
  12434. SettleAccountsDate: recordDateTime,
  12435. Ctime: time.Now().Unix(),
  12436. Mtime: time.Now().Unix(),
  12437. Status: 1,
  12438. OrderStatus: 1,
  12439. MdtrtId: his.Number,
  12440. Number: chrg_bchno,
  12441. MedfeeSumamt: totals,
  12442. SettleEndTime: end_time,
  12443. SettleStartTime: start_time,
  12444. SettleType: settle_accounts_type,
  12445. PsnPartAmt: totals,
  12446. PsnCashPay: totals,
  12447. PType: 2,
  12448. IsPre: 1,
  12449. MedType: strconv.Itoa(int(reg_type)),
  12450. Diagnosis: diagnosis_id,
  12451. }
  12452. err = service.CreateOrder(order)
  12453. if err != nil {
  12454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12455. return
  12456. }
  12457. var customs []*Custom
  12458. for _, item := range prescriptions {
  12459. fmt.Println(item.Type)
  12460. if item.Type == 1 { //药品
  12461. for _, subItem := range item.HisDoctorAdviceInfo {
  12462. cus := &Custom{
  12463. AdviceId: subItem.ID,
  12464. ProjectId: 0,
  12465. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12466. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12467. FeedetlSn: subItem.FeedetlSn,
  12468. Price: fmt.Sprintf("%.2f", subItem.Price),
  12469. MedListCodg: subItem.MedListCodg,
  12470. Type: 1,
  12471. }
  12472. customs = append(customs, cus)
  12473. }
  12474. }
  12475. if item.Type == 2 { //项目
  12476. for _, subItem := range item.HisPrescriptionProject {
  12477. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12478. cus := &Custom{
  12479. AdviceId: 0,
  12480. ProjectId: subItem.ID,
  12481. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12482. Cut: fmt.Sprintf("%.2f", cnt),
  12483. FeedetlSn: subItem.FeedetlSn,
  12484. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12485. MedListCodg: subItem.MedListCodg,
  12486. Type: 2,
  12487. }
  12488. customs = append(customs, cus)
  12489. }
  12490. }
  12491. for _, item := range item.HisAdditionalCharge {
  12492. cus := &Custom{
  12493. ItemId: item.ID,
  12494. AdviceId: 0,
  12495. ProjectId: 0,
  12496. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12497. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12498. FeedetlSn: item.FeedetlSn,
  12499. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12500. MedListCodg: item.XtHisAddtionConfig.Code,
  12501. Type: 3,
  12502. }
  12503. customs = append(customs, cus)
  12504. }
  12505. }
  12506. fmt.Println(customs)
  12507. for _, item := range customs {
  12508. var advice_id int64 = 0
  12509. var project_id int64 = 0
  12510. var item_id int64 = 0
  12511. var types int64 = 0
  12512. if item.Type == 1 {
  12513. advice_id = item.AdviceId
  12514. project_id = 0
  12515. item_id = 0
  12516. } else if item.Type == 2 {
  12517. advice_id = 0
  12518. item_id = 0
  12519. project_id = item.ProjectId
  12520. } else if item.Type == 3 {
  12521. advice_id = 0
  12522. item_id = item.ItemId
  12523. project_id = 0
  12524. }
  12525. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12526. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12527. pric, _ := strconv.ParseFloat(item.Price, 32)
  12528. info := &models.HisOrderInfo{
  12529. OrderNumber: order.Number,
  12530. UploadDate: time.Now().Unix(),
  12531. AdviceId: advice_id,
  12532. DetItemFeeSumamt: detItemFeeSumamt,
  12533. Cnt: cut,
  12534. Pric: pric,
  12535. PatientId: id,
  12536. Status: 1,
  12537. Mtime: time.Now().Unix(),
  12538. Ctime: time.Now().Unix(),
  12539. UserOrgId: adminUser.CurrentOrgId,
  12540. HisPatientId: his.ID,
  12541. OrderId: order.ID,
  12542. ProjectId: project_id,
  12543. Type: types,
  12544. ItemId: item_id,
  12545. }
  12546. service.CreateOrderInfo(info)
  12547. }
  12548. his.SickType = sick_type
  12549. service.UpdataHisPateint(&his)
  12550. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12551. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12552. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12553. if err == nil {
  12554. c.ServeSuccessJSON(map[string]interface{}{
  12555. "msg": "结算成功",
  12556. })
  12557. }
  12558. }
  12559. type CustomOrderInfo struct {
  12560. Name string
  12561. Spec string
  12562. Unit string
  12563. Count float64
  12564. Price float64
  12565. Total float64
  12566. }
  12567. func (c *HisApiController) GetPrivateExpensesInfo() {
  12568. order_id, _ := c.GetInt64("id", 0)
  12569. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12570. order, _ := service.GetHisOrderByID(order_id)
  12571. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12572. if order.ID == 0 {
  12573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12574. return
  12575. }
  12576. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12577. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12578. org_id := c.GetAdminUserInfo().CurrentOrgId
  12579. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12580. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12581. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12582. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12583. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12584. //var orderInfos_four []*models.HisOrderInfoTwo
  12585. //for _, item := range orderInfos_three {
  12586. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  12587. // item.HisPrescriptionProject.IsCheckTeam = 1
  12588. // orderInfos_four = append(orderInfos_four, item)
  12589. //
  12590. // }
  12591. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  12592. // item.HisPrescriptionProject.IsCheckTeam = 2
  12593. // orderInfos_two = append(orderInfos_two, item)
  12594. // }
  12595. //}
  12596. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  12597. //var cus_slice []CustomOrderInfo
  12598. //for _, item := range new_order_info {
  12599. // var cus CustomOrderInfo
  12600. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  12601. // cus.Unit = ""
  12602. // cus.Spec = ""
  12603. // var total float64
  12604. // for _, subItem := range orderInfos_four {
  12605. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  12606. // total = total + subItem.DetItemFeeSumamt
  12607. // fmt.Println(subItem.DetItemFeeSumamt)
  12608. // }
  12609. // }
  12610. // cus.Count = 1
  12611. // cus.Total = total
  12612. // cus_slice = append(cus_slice, cus)
  12613. //}
  12614. orderInfos = append(orderInfos, orderInfos_two...)
  12615. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  12616. //orderInfos = append(orderInfos, orderInfos_three...)
  12617. //}/**/
  12618. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  12619. c.ServeSuccessJSON(map[string]interface{}{
  12620. "order": order,
  12621. "order_info": orderInfos,
  12622. "patient": patient,
  12623. "admin_info": adminInfo,
  12624. "his": his,
  12625. "current_admin": role,
  12626. "org_config": miConfig,
  12627. //"new_order_info": cus_slice,
  12628. })
  12629. }
  12630. func (this *HisApiController) ChangeMedType() {
  12631. med_type := this.GetString("med_type")
  12632. old_med_type := this.GetString("old_med_type")
  12633. ids := this.GetString("ids")
  12634. settle_type, _ := this.GetInt64("settle_type")
  12635. start_time := this.GetString("start_time")
  12636. end_time := this.GetString("end_time")
  12637. ids_arr := strings.Split(ids, ",")
  12638. if settle_type == 1 { //日结
  12639. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  12640. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  12641. prescription.MedType = med_type
  12642. err := service.SaveHisPrescriptionTwo(&prescription)
  12643. if err == nil {
  12644. this.ServeSuccessJSON(map[string]interface{}{
  12645. "msg": "修改成功",
  12646. })
  12647. } else {
  12648. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12649. return
  12650. }
  12651. } else if settle_type == 2 {
  12652. timeLayout := "2006-01-02"
  12653. loc, _ := time.LoadLocation("Local")
  12654. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12655. if err != nil {
  12656. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12657. return
  12658. }
  12659. recordStartTime := theStartTime.Unix()
  12660. start_time_timestamp := recordStartTime
  12661. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  12662. if err != nil {
  12663. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12664. return
  12665. }
  12666. recordEndTime := theEndTime.Unix()
  12667. end_time_timestamp := recordEndTime
  12668. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  12669. if updateErr == nil {
  12670. this.ServeSuccessJSON(map[string]interface{}{
  12671. "msg": "修改成功",
  12672. })
  12673. } else {
  12674. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12675. return
  12676. }
  12677. }
  12678. }
  12679. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  12680. patient_id, _ := c.GetInt64("patient_id")
  12681. his_patient_id, _ := c.GetInt64("his_patient_id")
  12682. record_date := c.GetString("record_date")
  12683. start_time := c.GetString("start_time")
  12684. end_time := c.GetString("end_time")
  12685. order_status, _ := c.GetInt64("type", 0)
  12686. p_type, _ := c.GetInt64("p_type", 0)
  12687. order_id, _ := c.GetInt64("order_id", 0)
  12688. timeLayout := "2006-01-02"
  12689. loc, _ := time.LoadLocation("Local")
  12690. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12691. if err != nil {
  12692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12693. return
  12694. }
  12695. recordDateTime := theTime.Unix()
  12696. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12697. if err != nil {
  12698. }
  12699. startRecordDateTime := startTime.Unix()
  12700. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12701. if err != nil {
  12702. }
  12703. endRecordDateTime := endTime.Unix()
  12704. admin := c.GetAdminUserInfo()
  12705. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12706. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12707. order, _ := service.GetHisOrderByID(order_id)
  12708. var monthPrescriptions []*models.HisPrescription
  12709. if order_status == 1 || order_status == 0 {
  12710. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12711. } else if order_status == 2 {
  12712. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12713. }
  12714. var settle_total float64
  12715. for _, item := range monthPrescriptions {
  12716. if len(item.HisPrescriptionProject) > 0 {
  12717. for _, subItem := range item.HisPrescriptionProject {
  12718. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12719. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12720. settle_total = settle_total + total
  12721. }
  12722. }
  12723. if len(item.HisDoctorAdviceInfo) > 0 {
  12724. for _, subItem := range item.HisDoctorAdviceInfo {
  12725. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12726. settle_total = settle_total + total
  12727. }
  12728. }
  12729. }
  12730. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12731. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12732. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12733. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12734. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12735. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12736. //获取所有科室信息
  12737. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12738. var dia string
  12739. for _, item := range month_p_info {
  12740. if len(dia) == 0 {
  12741. dia = item.Diagnosis
  12742. } else {
  12743. dia = dia + "," + item.Diagnosis
  12744. }
  12745. }
  12746. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12747. dia_arr = removeEmptyStrings(dia_arr)
  12748. c.ServeSuccessJSON(map[string]interface{}{
  12749. "his_info": his_patient_info,
  12750. "xt_info": xt_patient_info,
  12751. "case_history": case_history,
  12752. "info": patientPrescriptionInfo,
  12753. "last_info": lastPatientPrescriptionInfo,
  12754. "month_prescriptions": monthPrescriptions,
  12755. "order": order,
  12756. "doctors": doctors,
  12757. "department": department,
  12758. "settle_total": settle_total,
  12759. "dia_arr": dia_arr,
  12760. })
  12761. return
  12762. }
  12763. func removeEmptyStrings(input []string) []string {
  12764. var output []string
  12765. for _, s := range input {
  12766. if s != "" {
  12767. output = append(output, s)
  12768. }
  12769. }
  12770. return output
  12771. }
  12772. func removeDuplicates(input []string) []string {
  12773. seen := make(map[string]bool)
  12774. output := []string{}
  12775. for _, s := range input {
  12776. if _, exists := seen[s]; !exists {
  12777. seen[s] = true
  12778. output = append(output, s)
  12779. }
  12780. }
  12781. return output
  12782. }
  12783. func (c *HisApiController) GetHisMonthPatientInfo() {
  12784. patient_id, _ := c.GetInt64("patient_id")
  12785. his_patient_id, _ := c.GetInt64("his_patient_id")
  12786. record_date := c.GetString("record_date")
  12787. number := c.GetString("number")
  12788. start_time := c.GetString("start_time")
  12789. end_time := c.GetString("end_time")
  12790. p_type, _ := c.GetInt64("p_type")
  12791. timeLayout := "2006-01-02"
  12792. loc, _ := time.LoadLocation("Local")
  12793. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12794. if err != nil {
  12795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12796. return
  12797. }
  12798. recordDateTime := theTime.Unix()
  12799. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12800. if err != nil {
  12801. }
  12802. startRecordDateTime := startTime.Unix()
  12803. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12804. if err != nil {
  12805. }
  12806. endRecordDateTime := endTime.Unix()
  12807. admin := c.GetAdminUserInfo()
  12808. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12809. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12810. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12811. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12812. var settle_total float64
  12813. for _, item := range monthPrescriptions {
  12814. if len(item.HisPrescriptionProject) > 0 {
  12815. for _, subItem := range item.HisPrescriptionProject {
  12816. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12817. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12818. settle_total = settle_total + total
  12819. }
  12820. }
  12821. if len(item.HisDoctorAdviceInfo) > 0 {
  12822. for _, subItem := range item.HisDoctorAdviceInfo {
  12823. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12824. settle_total = settle_total + total
  12825. }
  12826. }
  12827. }
  12828. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12829. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12830. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12831. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12832. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12833. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12834. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12835. //获取所有科室信息
  12836. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12837. c.ServeSuccessJSON(map[string]interface{}{
  12838. "his_info": his_patient_info,
  12839. "xt_info": xt_patient_info,
  12840. "case_history": case_history,
  12841. "info": patientPrescriptionInfo,
  12842. "month_prescriptions": monthPrescriptions,
  12843. "order": order,
  12844. "doctors": doctors,
  12845. "department": department,
  12846. "count": count,
  12847. "drugStockConfig": drugStockConfig,
  12848. "last_info": lastPatientPrescriptionInfo,
  12849. "settle_total": settle_total,
  12850. })
  12851. return
  12852. }
  12853. func (c *HisApiController) GetAllOrder() {
  12854. org_id := c.GetAdminUserInfo().CurrentOrgId
  12855. orders, _ := service.GetNewHisOrderList(org_id)
  12856. c.ServeSuccessJSON(map[string]interface{}{
  12857. "order": orders,
  12858. })
  12859. return
  12860. }
  12861. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12862. newArr = make([]*models.HisOrderInfoTwo, 0)
  12863. for i := 0; i < len(arr); i++ {
  12864. repeat := false
  12865. for j := i + 1; j < len(arr); j++ {
  12866. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12867. repeat = true
  12868. break
  12869. }
  12870. }
  12871. if !repeat {
  12872. newArr = append(newArr, arr[i])
  12873. }
  12874. }
  12875. return
  12876. }
  12877. // 修改处方退库操作 参数传修改之前的处方数据
  12878. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12879. if advice.ExecutionState == 1 {
  12880. //查询该病人该药品是否有库存记录
  12881. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12882. if errcode == gorm.ErrRecordNotFound {
  12883. } else {
  12884. //退库
  12885. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12886. if advice.PrescribingNumberUnit == drug.MinUnit {
  12887. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12888. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12889. //退库
  12890. warehouseInfo := models.DrugWarehouseInfo{
  12891. StockMinNumber: prescribingNumber,
  12892. }
  12893. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12894. operation_time := time.Now().Unix()
  12895. creater := advice.AdviceDoctor
  12896. ctime := time.Now().Unix()
  12897. timeStr := time.Now().Format("2006-01-02")
  12898. timeArr := strings.Split(timeStr, "-")
  12899. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12900. total = total + 1
  12901. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12902. cancelStock := models.DrugCancelStock{
  12903. OrderNumber: orderNumber,
  12904. OperaTime: operation_time,
  12905. OrgId: advice.UserOrgId,
  12906. Creater: creater,
  12907. Ctime: ctime,
  12908. Status: 1,
  12909. ReturnTime: advice.AdviceDate,
  12910. Dealer: info.Dealer,
  12911. Manufacturer: info.Manufacturer,
  12912. Type: 1,
  12913. }
  12914. service.AddSigleDrugCancelStock(&cancelStock)
  12915. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12916. dealer, _ := service.GetDealerById(info.Dealer)
  12917. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12918. cancelStockInfo := models.DrugCancelStockInfo{
  12919. OrderNumber: cancelInfo.OrderNumber,
  12920. CancelStockId: cancelInfo.ID,
  12921. DrugId: info.DrugId,
  12922. Count: info.Count,
  12923. Status: 1,
  12924. Ctime: ctime,
  12925. OrgId: advice.UserOrgId,
  12926. Type: 1,
  12927. Manufacturer: manufactureName.ManufacturerName,
  12928. Dealer: dealer.DealerName,
  12929. Total: 0,
  12930. RetailPrice: info.RetailPrice,
  12931. RetailTotalPrice: info.RetailTotalPrice,
  12932. Price: info.Price,
  12933. RegisterAccount: "",
  12934. Remark: info.Remark,
  12935. BatchNumber: info.BatchNumber,
  12936. MaxUnit: info.CountUnit,
  12937. ProductDate: info.ProductDate,
  12938. ExpiryDate: info.ExpiryDate,
  12939. BatchNumberId: info.WarehouseInfoId,
  12940. }
  12941. flow := models.DrugFlow{
  12942. WarehousingId: 0,
  12943. DrugId: info.DrugId,
  12944. Number: "",
  12945. BatchNumber: info.BatchNumber,
  12946. Count: info.Count,
  12947. UserOrgId: advice.UserOrgId,
  12948. PatientId: 0,
  12949. SystemTime: ctime,
  12950. ConsumableType: 4,
  12951. IsSys: 0,
  12952. WarehousingOrder: "",
  12953. WarehouseOutId: 0,
  12954. WarehouseOutOrderNumber: "",
  12955. IsEdit: 0,
  12956. CancelStockId: cancelStock.ID,
  12957. CancelOrderNumber: cancelStock.OrderNumber,
  12958. Manufacturer: info.Manufacturer,
  12959. Dealer: info.Dealer,
  12960. Creator: advice.UserOrgId,
  12961. UpdateCreator: 0,
  12962. Status: 1,
  12963. Ctime: time.Now().Unix(),
  12964. Mtime: 0,
  12965. Price: info.Price,
  12966. WarehousingDetailId: 0,
  12967. WarehouseOutDetailId: 0,
  12968. CancelOutDetailId: 0,
  12969. ExpireDate: info.ExpiryDate,
  12970. ProductDate: info.ProductDate,
  12971. MaxUnit: info.CountUnit,
  12972. MinUnit: "",
  12973. }
  12974. service.CreatedCancelStock(cancelStockInfo)
  12975. service.CreateDrugFlowOne(flow)
  12976. } else {
  12977. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12978. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12979. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12980. warehouseInfo := models.DrugWarehouseInfo{
  12981. StockMinNumber: prescribingNumber,
  12982. }
  12983. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12984. }
  12985. operation_time := time.Now().Unix()
  12986. creater := advice.AdviceDoctor
  12987. ctime := time.Now().Unix()
  12988. timeStr := time.Now().Format("2006-01-02")
  12989. timeArr := strings.Split(timeStr, "-")
  12990. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12991. total = total + 1
  12992. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12993. cancelStock := models.DrugCancelStock{
  12994. OrderNumber: orderNumber,
  12995. OperaTime: operation_time,
  12996. OrgId: advice.UserOrgId,
  12997. Creater: creater,
  12998. Ctime: ctime,
  12999. Status: 1,
  13000. ReturnTime: advice.AdviceDate,
  13001. Dealer: info.Dealer,
  13002. Manufacturer: info.Manufacturer,
  13003. Type: 1,
  13004. }
  13005. service.AddSigleDrugCancelStock(&cancelStock)
  13006. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13007. dealer, _ := service.GetDealerById(info.Dealer)
  13008. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13009. cancelStockInfo := models.DrugCancelStockInfo{
  13010. OrderNumber: cancelInfo.OrderNumber,
  13011. CancelStockId: cancelInfo.ID,
  13012. DrugId: info.DrugId,
  13013. Count: info.Count,
  13014. Status: 1,
  13015. Ctime: ctime,
  13016. OrgId: advice.UserOrgId,
  13017. Type: 1,
  13018. Manufacturer: manufactureName.ManufacturerName,
  13019. Dealer: dealer.DealerName,
  13020. Total: 0,
  13021. RetailPrice: info.RetailPrice,
  13022. RetailTotalPrice: info.RetailTotalPrice,
  13023. Price: info.Price,
  13024. RegisterAccount: "",
  13025. Remark: info.Remark,
  13026. BatchNumber: info.BatchNumber,
  13027. MaxUnit: info.CountUnit,
  13028. ProductDate: info.ProductDate,
  13029. ExpiryDate: info.ExpiryDate,
  13030. BatchNumberId: info.WarehouseInfoId,
  13031. }
  13032. flow := models.DrugFlow{
  13033. WarehousingId: 0,
  13034. DrugId: info.DrugId,
  13035. Number: "",
  13036. BatchNumber: info.BatchNumber,
  13037. Count: info.Count,
  13038. UserOrgId: advice.UserOrgId,
  13039. PatientId: 0,
  13040. SystemTime: ctime,
  13041. ConsumableType: 4,
  13042. IsSys: 0,
  13043. WarehousingOrder: "",
  13044. WarehouseOutId: 0,
  13045. WarehouseOutOrderNumber: "",
  13046. IsEdit: 0,
  13047. CancelStockId: cancelStock.ID,
  13048. CancelOrderNumber: cancelStock.OrderNumber,
  13049. Manufacturer: info.Manufacturer,
  13050. Dealer: info.Dealer,
  13051. Creator: advice.AdviceDoctor,
  13052. UpdateCreator: 0,
  13053. Status: 1,
  13054. Ctime: time.Now().Unix(),
  13055. Mtime: 0,
  13056. Price: info.Price,
  13057. WarehousingDetailId: 0,
  13058. WarehouseOutDetailId: 0,
  13059. CancelOutDetailId: 0,
  13060. ExpireDate: info.ExpiryDate,
  13061. ProductDate: info.ProductDate,
  13062. MaxUnit: info.CountUnit,
  13063. MinUnit: "",
  13064. }
  13065. service.CreatedCancelStock(cancelStockInfo)
  13066. service.CreateDrugFlowOne(flow)
  13067. }
  13068. }
  13069. }
  13070. return err
  13071. }
  13072. func (this *HisApiController) DeleteNCDS() {
  13073. id, _ := this.GetInt64("id", 0)
  13074. if id > 0 {
  13075. service.DeletePsnNCDSRecordById(id)
  13076. this.ServeSuccessJSON(map[string]interface{}{
  13077. "msg": "删除成功",
  13078. })
  13079. } else {
  13080. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13081. return
  13082. }
  13083. }
  13084. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13085. id, _ := c.GetInt64("id")
  13086. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13087. c.ServeSuccessJSON(map[string]interface{}{
  13088. "advice": advice,
  13089. })
  13090. return
  13091. }
  13092. func (c *HisApiController) GetHisMonthChargePatientList() {
  13093. record_date := c.GetString("record_date")
  13094. start_time := c.GetString("start_time")
  13095. end_time := c.GetString("end_time")
  13096. timeLayout := "2006-01-02"
  13097. loc, _ := time.LoadLocation("Local")
  13098. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13099. if err != nil {
  13100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13101. return
  13102. }
  13103. if err != nil {
  13104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13105. return
  13106. }
  13107. recordDateTime := theTime.Unix()
  13108. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13109. if err != nil {
  13110. }
  13111. startRecordDateTime := startTime.Unix()
  13112. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13113. if err != nil {
  13114. }
  13115. endRecordDateTime := endTime.Unix()
  13116. adminInfo := c.GetAdminUserInfo()
  13117. var tempMonthChargePatients []*service.MonthChargePatients
  13118. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13119. for _, item := range tempPatients {
  13120. //过滤没有处方的
  13121. if len(item.HisPrescription) == 0 {
  13122. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13123. }
  13124. }
  13125. c.ServeSuccessJSON(map[string]interface{}{
  13126. "list": tempMonthChargePatients,
  13127. })
  13128. }
  13129. // PrescriptionDifference 医嘱数量差值结构体
  13130. type PrescriptionDrugDifference struct {
  13131. DrugID int64 //基础库药品id
  13132. ID int64 //医嘱id
  13133. Difference float64 //差值
  13134. Unit string //单位
  13135. }
  13136. type PrescriptionGoodDifference struct {
  13137. GoodID int64 //基础库项目耗材id
  13138. ID int64 //医嘱id
  13139. Difference int64 //差值
  13140. Unit string //单位
  13141. Type int64 //类型
  13142. }
  13143. type EditCustomData struct {
  13144. adviceList []*models.HisDoctorAdviceInfo
  13145. projectList []*models.HisPrescriptionProject
  13146. }
  13147. type SrcCustomData struct {
  13148. adviceList []*models.HisDoctorAdviceInfo
  13149. projectList []*models.HisPrescriptionProject
  13150. }
  13151. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13152. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13153. differences := make([]*PrescriptionDrugDifference, 0)
  13154. // 创建一个 map 来存储第一个切片中的药品信息
  13155. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13156. for _, advice := range firstPrescription {
  13157. firstMap[advice.DrugId] = advice
  13158. }
  13159. // 遍历第二个切片中的药品信息,并比较数量差值
  13160. for _, advice := range secondPrescription {
  13161. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13162. diff := &PrescriptionDrugDifference{
  13163. DrugID: advice.DrugId,
  13164. ID: firstAdvice.ID,
  13165. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13166. Unit: firstAdvice.PrescribingNumberUnit,
  13167. }
  13168. differences = append(differences, diff)
  13169. }
  13170. }
  13171. return differences
  13172. }
  13173. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13174. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13175. differences := make([]*PrescriptionGoodDifference, 0)
  13176. // 创建一个 map 来存储第一个切片中的耗材信息
  13177. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13178. for _, good := range firstPrescription {
  13179. firstMap[good.ProjectId] = good
  13180. }
  13181. // 遍历第二个切片中的耗材信息,并比较数量差值
  13182. for _, good := range secondPrescription {
  13183. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13184. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13185. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13186. diff := &PrescriptionGoodDifference{
  13187. GoodID: good.ProjectId,
  13188. ID: firstGood.ID,
  13189. Difference: count - firstCount,
  13190. Unit: firstGood.Unit,
  13191. Type: firstGood.Type,
  13192. }
  13193. differences = append(differences, diff)
  13194. }
  13195. }
  13196. return differences
  13197. }
  13198. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13199. var adviceList []*models.HisDoctorAdviceInfo
  13200. var projectList []*models.HisPrescriptionProject
  13201. var advice_ids []int64
  13202. var project_ids []int64
  13203. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13204. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13205. //var tempPrescription *models.HisPrescriptionProjectscription
  13206. if len(prescriptions) > 0 {
  13207. for _, item := range prescriptions {
  13208. items := item.(map[string]interface{})
  13209. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13210. advices := items["advices"].([]interface{})
  13211. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13212. groupNo := int64(0)
  13213. ctime := time.Now().Unix()
  13214. mtime := ctime
  13215. if len(advices) > 0 {
  13216. for _, advice := range advices {
  13217. var s models.HisDoctorAdviceInfo
  13218. s.AdviceType = 2
  13219. s.StopState = 2
  13220. s.ExecutionState = 2
  13221. s.Status = 1
  13222. s.Groupno = groupNo
  13223. s.CreatedTime = ctime
  13224. s.UpdatedTime = mtime
  13225. s.IsSettle = 2
  13226. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13227. //存储切片中
  13228. if s.ID > 0 {
  13229. advice_ids = append(advice_ids, s.ID)
  13230. adviceList = append(adviceList, &s)
  13231. }
  13232. }
  13233. }
  13234. }
  13235. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13236. projects := items["project"].([]interface{})
  13237. if len(projects) > 0 {
  13238. for _, project := range projects {
  13239. var p models.HisPrescriptionProject
  13240. p.Ctime = time.Now().Unix()
  13241. p.Mtime = time.Now().Unix()
  13242. p.Status = 1
  13243. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13244. if p.ID > 0 {
  13245. project_ids = append(project_ids, p.ID)
  13246. projectList = append(projectList, &p)
  13247. }
  13248. }
  13249. }
  13250. }
  13251. }
  13252. }
  13253. }
  13254. editCustomData.projectList = projectList
  13255. editCustomData.adviceList = adviceList
  13256. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13257. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13258. srcCustomData.adviceList = list
  13259. srcCustomData.projectList = list2
  13260. return
  13261. }
  13262. func (c *HisApiController) GetAllGoodInforList() {
  13263. orgId := c.GetAdminUserInfo().CurrentOrgId
  13264. goodList, _ := service.GetAllGoodList(orgId)
  13265. c.ServeSuccessJSON(map[string]interface{}{
  13266. "goodList": goodList,
  13267. })
  13268. return
  13269. }
  13270. func (this *HisApiController) SaveGoodList() {
  13271. project_name := this.GetString("project_name")
  13272. sort, _ := this.GetInt64("sort")
  13273. orgId := this.GetAdminUserInfo().CurrentOrgId
  13274. dataBody := make(map[string]interface{}, 0)
  13275. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13276. if err != nil {
  13277. utils.ErrorLog(err.Error())
  13278. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13279. return
  13280. }
  13281. goodTeam := models.XtGoodTeam{
  13282. ProjectName: project_name,
  13283. Sort: sort,
  13284. UserOrgId: orgId,
  13285. Status: 1,
  13286. Ctime: time.Now().Unix(),
  13287. Mtime: time.Now().Unix(),
  13288. }
  13289. service.CreateGoodTeam(goodTeam)
  13290. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13291. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13292. infos, _ := dataBody["info"].([]interface{})
  13293. if len(infos) > 0 {
  13294. for _, item := range infos {
  13295. items := item.(map[string]interface{})
  13296. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13297. utils.ErrorLog("good_id")
  13298. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13299. return
  13300. }
  13301. good_id := int64(items["good_id"].(float64))
  13302. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13303. utils.ErrorLog("number")
  13304. }
  13305. number := int64(items["number"].(float64))
  13306. xtGoodTeamList := models.XtGoodTeamList{
  13307. GoodId: good_id,
  13308. Count: number,
  13309. TeamId: lastGoodTeam.ID,
  13310. UserOrgId: orgId,
  13311. Status: 1,
  13312. Ctime: time.Now().Unix(),
  13313. Mtime: time.Now().Unix(),
  13314. }
  13315. service.CreateGoodList(xtGoodTeamList)
  13316. }
  13317. this.ServeSuccessJSON(map[string]interface{}{
  13318. "lastGoodTeam": lastGoodTeam,
  13319. })
  13320. }
  13321. }
  13322. return
  13323. }
  13324. func (this *HisApiController) GetGoodList() {
  13325. orgId := this.GetAdminUserInfo().CurrentOrgId
  13326. limit, _ := this.GetInt64("limit")
  13327. page, _ := this.GetInt64("page")
  13328. keyword := this.GetString("keyword")
  13329. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13330. this.ServeSuccessJSON(map[string]interface{}{
  13331. "list": list,
  13332. "total": total,
  13333. })
  13334. }
  13335. func (this *HisApiController) GetGoodNameDetail() {
  13336. id, _ := this.GetInt64("id")
  13337. orgId := this.GetAdminUserInfo().CurrentOrgId
  13338. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13339. goodList, _ := service.GetAllGoodList(orgId)
  13340. this.ServeSuccessJSON(map[string]interface{}{
  13341. "goodNameDetail": goodNameDetail,
  13342. "goodList": goodList,
  13343. })
  13344. }
  13345. func (this *HisApiController) UpdateGoodList() {
  13346. project_name := this.GetString("project_name")
  13347. sort, _ := this.GetInt64("sort")
  13348. id, _ := this.GetInt64("id")
  13349. orgId := this.GetAdminUserInfo().CurrentOrgId
  13350. dataBody := make(map[string]interface{}, 0)
  13351. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13352. if err != nil {
  13353. utils.ErrorLog(err.Error())
  13354. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13355. return
  13356. }
  13357. goodTeam := models.XtGoodTeam{
  13358. ProjectName: project_name,
  13359. Sort: sort,
  13360. UserOrgId: orgId,
  13361. Status: 1,
  13362. Ctime: time.Now().Unix(),
  13363. Mtime: time.Now().Unix(),
  13364. ID: id,
  13365. }
  13366. service.SaveGoodTeam(goodTeam)
  13367. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13368. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13369. infos, _ := dataBody["info"].([]interface{})
  13370. if len(infos) > 0 {
  13371. for _, item := range infos {
  13372. items := item.(map[string]interface{})
  13373. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13374. utils.ErrorLog("good_id")
  13375. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13376. return
  13377. }
  13378. good_id := int64(items["good_id"].(float64))
  13379. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13380. utils.ErrorLog("id")
  13381. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13382. return
  13383. }
  13384. id := int64(items["id"].(float64))
  13385. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13386. utils.ErrorLog("number")
  13387. }
  13388. number := int64(items["number"].(float64))
  13389. xtGoodTeamList := models.XtGoodTeamList{
  13390. ID: id,
  13391. GoodId: good_id,
  13392. Count: number,
  13393. TeamId: lastGoodTeam.ID,
  13394. UserOrgId: orgId,
  13395. Status: 1,
  13396. Ctime: time.Now().Unix(),
  13397. Mtime: time.Now().Unix(),
  13398. }
  13399. service.SaveGoodList(xtGoodTeamList)
  13400. }
  13401. this.ServeSuccessJSON(map[string]interface{}{
  13402. "lastGoodTeam": lastGoodTeam,
  13403. })
  13404. }
  13405. }
  13406. return
  13407. }
  13408. func (this *HisApiController) DeleteGoodTeam() {
  13409. id, _ := this.GetInt64("id")
  13410. team, _ := service.DeleteGoodTeam(id)
  13411. this.ServeSuccessJSON(map[string]interface{}{
  13412. "team": team,
  13413. })
  13414. }
  13415. func (this *HisApiController) DeleteGood() {
  13416. id, _ := this.GetInt64("id")
  13417. good, _ := service.DeleteGood(id)
  13418. this.ServeSuccessJSON(map[string]interface{}{
  13419. "good": good,
  13420. })
  13421. }