his_api_controller.go 585KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  91. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  92. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  93. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  94. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  95. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  96. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  97. }
  98. func (c *HisApiController) CheckHisPatient() {
  99. record_date := c.GetString("record_date")
  100. patient_id, _ := c.GetInt64("patient_id")
  101. timeLayout := "2006-01-02"
  102. loc, _ := time.LoadLocation("Local")
  103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  104. if err != nil {
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. recordDateTime := theTime.Unix()
  109. adminInfo := c.GetAdminUserInfo()
  110. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  111. if len(patients) > 1 {
  112. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  113. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "status": 1,
  116. "msg": "关联",
  117. "ps": ps,
  118. "his_patient_id": patients[len(patients)-1].ID,
  119. "patient_id": patients[len(patients)-1].PatientId,
  120. })
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. }
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. return
  133. }
  134. }
  135. func (c *HisApiController) AssociationHisPrescription() {
  136. record_date := c.GetString("record_date")
  137. his_patient_id, _ := c.GetInt64("his_patient_id")
  138. patient_id, _ := c.GetInt64("patient_id")
  139. p_ids := c.GetString("p_ids")
  140. p_ids_arr := strings.Split(p_ids, ",")
  141. timeLayout := "2006-01-02"
  142. loc, _ := time.LoadLocation("Local")
  143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  144. if err != nil {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. recordDateTime := theTime.Unix()
  149. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  150. if his_patient_id == 0 || his_patient.ID == 0 {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  155. if err == nil {
  156. c.ServeSuccessJSON(map[string]interface{}{
  157. "msg": "关联处方成功",
  158. })
  159. return
  160. } else {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  162. return
  163. }
  164. }
  165. //func (c *HisApiController) AssociationHisPrescription() {
  166. // record_date, _ := c.GetInt64("record_date")
  167. // his_patient_id, _ := c.GetInt64("his_patient_id")
  168. // patient_id, _ := c.GetInt64("patient_id")
  169. // p_ids := c.GetString("p_ids")
  170. // p_ids_arr := strings.Split(p_ids, ",")
  171. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  172. // if his_patient_id == 0 || his_patient.ID == 0 {
  173. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. // return
  175. // }
  176. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  177. // if err == nil {
  178. // c.ServeSuccessJSON(map[string]interface{}{
  179. // "msg": "关联处方成功",
  180. // })
  181. // return
  182. // } else {
  183. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  184. // return
  185. // }
  186. //}
  187. func (c *HisApiController) GetFaPiaoNumber() {
  188. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  189. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  190. fmt.Println(count)
  191. var zero string
  192. number := count + 1
  193. //if number >= 1000 {
  194. // zero = "0000" + strconv.FormatInt(number, 10)
  195. //} else if number >= 10000 {
  196. // zero = "000" + strconv.FormatInt(number, 10)
  197. //} else if number >= 100000 {
  198. // zero = "00" + strconv.FormatInt(number, 10)
  199. //} else if number >= 1000000 {
  200. // zero = "0" + strconv.FormatInt(number, 10)
  201. //} else {
  202. zero = "0" + strconv.FormatInt(number, 10)
  203. //}
  204. c.ServeSuccessJSON(map[string]interface{}{
  205. "fapiao_number": zero,
  206. })
  207. return
  208. }
  209. func (c *HisApiController) ChangeOrderDesc() {
  210. id, _ := c.GetInt64("id")
  211. desc := c.GetString("desc")
  212. change_type := c.GetString("change_type")
  213. order, _ := service.GetHisOrderByID(id)
  214. if order.ID == 0 {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  216. return
  217. }
  218. switch change_type {
  219. case "oth_desc":
  220. order.OthDesc = desc
  221. break
  222. case "cash_pay":
  223. order.CashPay = desc
  224. break
  225. case "jifen_pay":
  226. order.JifenPay = desc
  227. break
  228. case "card_desc":
  229. order.CardDesc = desc
  230. break
  231. case "band_card_pay":
  232. order.BandCardPay = desc
  233. break
  234. case "ali_pay":
  235. order.AliPay = desc
  236. break
  237. case "wechat_pay":
  238. order.WechatPay = desc
  239. break
  240. case "fa_piao_number":
  241. order.FaPiaoNumber = desc
  242. break
  243. case "fa_piao_code":
  244. order.FaPiaoCode = desc
  245. break
  246. }
  247. err := service.SaveHisOrder(&order)
  248. if err == nil {
  249. c.ServeSuccessJSON(map[string]interface{}{
  250. "msg": "修改成功",
  251. })
  252. return
  253. } else {
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  255. return
  256. }
  257. }
  258. func (c *HisApiController) GetMonthHisPatient() {
  259. record_date := c.GetString("record_date")
  260. //order_status, _ := c.GetInt64("type")
  261. timeLayout := "2006-01-02"
  262. loc, _ := time.LoadLocation("Local")
  263. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  264. if err != nil {
  265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  266. return
  267. }
  268. recordDateTime := theTime.Unix()
  269. adminInfo := c.GetAdminUserInfo()
  270. var tempPatients []service.NewTempPatients
  271. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  272. // 获取当前时间
  273. now := time.Now()
  274. // 获取本月的第一天
  275. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  276. // 获取下个月的第一天
  277. nextMonth := firstDay.AddDate(0, 1, 0)
  278. // 获取本月的最后一天
  279. lastDay := nextMonth.Add(-time.Nanosecond)
  280. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  281. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  282. var patients []service.NewTempPatients
  283. var patients_two []service.NewTempPatients
  284. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  285. for _, item := range tempPatients {
  286. //过滤掉没挂号的和没开处方的
  287. if len(item.HisPrescription) > 0 {
  288. patients = append(patients, item)
  289. patients_two = append(patients_two, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. //}
  294. }
  295. } else {
  296. for _, item := range tempPatients {
  297. //过滤掉没挂号的和没开处方的
  298. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  299. patients = append(patients, item)
  300. }
  301. ////过滤掉没挂号的
  302. //if len(item.HisPatient) > 0 {
  303. // patients_two = append(patients_two, item)
  304. //}
  305. }
  306. }
  307. c.ServeSuccessJSON(map[string]interface{}{
  308. "list": patients,
  309. "list_two": patients_two,
  310. "chargePatients": chargePatients,
  311. })
  312. }
  313. func (c *HisApiController) GetBatchSettleAccounts() {
  314. order_ids := c.GetString("order_ids")
  315. admin_user_id, _ := c.GetInt64("admin_user_id")
  316. adminUser := c.GetAdminUserInfo()
  317. orders := strings.Split(order_ids, ",")
  318. var newOrders []models.Orders
  319. for _, item := range orders {
  320. order, _ := service.GetHisOrderByIDTenOne(item)
  321. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  322. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  323. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  324. orderInfos = append(orderInfos, orderInfos_two...)
  325. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  326. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  327. var diagnosis_ids []string
  328. if his.ID > 0 {
  329. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  330. } else {
  331. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  332. }
  333. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  334. var dia_config []*models.HisXtDiagnoseConfig
  335. var name string
  336. for _, item := range diagnosis_ids {
  337. id, _ := strconv.ParseInt(item, 10, 64)
  338. diagnosisConfig, _ := service.FindDiagnoseById(id)
  339. dia_config = append(dia_config, diagnosisConfig)
  340. if len(name) == 0 {
  341. name = diagnosisConfig.ClassName
  342. } else {
  343. name = name + "," + diagnosisConfig.ClassName
  344. }
  345. }
  346. var bedCostTotal float64 = 0 //床位总费
  347. var bedCostSelfTotal float64 = 0 //床位自费
  348. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  349. var bedSelfTotal float64 = 0 //床位部分项目自费
  350. var bedInscpTotal float64 = 0 //床位部分项目自费
  351. var operationCostTotal float64 = 0 //手术费
  352. var operationCostSelfTotal float64 = 0 //手术费
  353. var operationCostPartSelfTotal float64 = 0 //手术费
  354. var operationSelfTotal float64 = 0 //床位部分项目自费
  355. var operationInscpTotal float64 = 0 //床位部分项目自费
  356. var otherCostTotal float64 = 0 //其他费用
  357. var otherCostSelfTotal float64 = 0 //其他费用
  358. var otherCostPartSelfTotal float64 = 0 //其他费用
  359. var otherSelfTotal float64 = 0 //床位部分项目自费
  360. var otherInscpTotal float64 = 0 //床位部分项目自费
  361. var materialCostTotal float64 = 0 //材料费
  362. var materialCostSelfTotal float64 = 0 //材料费
  363. var materialCostPartSelfTotal float64 = 0 //材料费
  364. var materialSelfTotal float64 = 0 //床位部分项目自费
  365. var materialInscpTotal float64 = 0 //床位部分项目自费
  366. var westernMedicineCostTotal float64 = 0 //西药费
  367. var westernMedicineCostSelfTotal float64 = 0 //西药费
  368. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  369. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  370. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  371. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  372. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  373. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  374. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  375. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  376. var checkCostTotal float64 = 0 //检查费
  377. var checkCostSelfTotal float64 = 0 //检查费
  378. var checkCostPartSelfTotal float64 = 0 //检查费
  379. var checkSelfTotal float64 = 0 //床位部分项目自费
  380. var checkInscpTotal float64 = 0 //床位部分项目自费
  381. var laboratoryCostTotal float64 = 0 //化验费
  382. var laboratoryCostSelfTotal float64 = 0 //化验费
  383. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  384. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  385. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  386. var treatCostTotal float64 = 0 //治疗费用
  387. var treatCostSelfTotal float64 = 0 //治疗费用
  388. var treatCostPartSelfTotal float64 = 0 //治疗费用
  389. var treatSelfTotal float64 = 0 //床位部分项目自费
  390. var treatInscpTotal float64 = 0 //床位部分项目自费
  391. decimal.DivisionPrecision = 2
  392. for _, item := range orderInfos {
  393. if item.MedChrgitmType == "01" { //床位费
  394. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  395. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  396. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  397. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  398. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  399. }
  400. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  401. if item.MedChrgitmType == "03" { //检查费
  402. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  403. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  404. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  405. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  406. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  407. }
  408. } else {
  409. if item.MedChrgitmType == "03" { //检查费
  410. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  411. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  412. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  413. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  414. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  415. }
  416. }
  417. if item.MedChrgitmType == "04" { //化验费
  418. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  419. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  420. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  421. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  422. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  423. }
  424. if item.MedChrgitmType == "05" { //治疗费
  425. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  426. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  427. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  428. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  429. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  430. }
  431. if item.MedChrgitmType == "06" { //手术费
  432. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  433. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  434. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  435. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  436. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  437. }
  438. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  439. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  440. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  441. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  442. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  443. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  444. }
  445. if item.MedChrgitmType == "09" { //西药费
  446. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  447. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  448. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  449. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  450. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  451. }
  452. if item.MedChrgitmType == "11" { //中成费
  453. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  454. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  455. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  456. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  457. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  458. }
  459. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  460. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  461. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  462. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  463. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  464. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  465. }
  466. }
  467. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  468. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  469. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  470. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  471. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  472. var doctor_name string
  473. if roles.ID == 0 {
  474. doctor_name = "管理员"
  475. } else {
  476. doctor_name = roles.UserName
  477. }
  478. yiliao_leibie := ""
  479. switch order.MedType {
  480. case "11":
  481. yiliao_leibie = "普通门诊"
  482. break
  483. case "12":
  484. yiliao_leibie = "门诊挂号"
  485. break
  486. case "13":
  487. yiliao_leibie = "急诊"
  488. break
  489. case "14":
  490. yiliao_leibie = "门诊特殊病"
  491. break
  492. case "15":
  493. yiliao_leibie = "门诊统筹"
  494. break
  495. case "16":
  496. yiliao_leibie = "门诊慢性病"
  497. break
  498. case "21":
  499. yiliao_leibie = "普通住院"
  500. break
  501. }
  502. var newOrder models.Orders
  503. newOrder.Diagnosis = name
  504. newOrder.OrderInfos = orderInfos
  505. newOrder.Number = order.MdtrtId
  506. newOrder.Date = order.SettleAccountsDate
  507. newOrder.ChargeAdmin = charge_admin
  508. newOrder.PrintorAdmin = printor_admin
  509. newOrder.Order = order
  510. newOrder.BedCostTotal = bedCostTotal
  511. newOrder.BedCostSelfTotal = bedCostSelfTotal
  512. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  513. newOrder.BedSelfTotal = bedSelfTotal
  514. newOrder.BedInscpTotal = bedInscpTotal
  515. newOrder.OperationCostTotal = operationCostTotal
  516. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  517. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  518. newOrder.OperationSelfTotal = operationSelfTotal
  519. newOrder.OperationInscpTotal = operationInscpTotal
  520. newOrder.OtherCostTotal = otherCostTotal
  521. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  522. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  523. newOrder.OtherSelfTotal = otherSelfTotal
  524. newOrder.OtherInscpTotal = otherInscpTotal
  525. newOrder.MaterialCostTotal = materialCostTotal
  526. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  527. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  528. newOrder.MaterialSelfTotal = materialSelfTotal
  529. newOrder.MaterialInscpTotal = materialInscpTotal
  530. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  531. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  532. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  533. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  534. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  535. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  536. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  537. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  538. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  539. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  540. newOrder.CheckCostTotal = checkCostTotal
  541. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  542. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  543. newOrder.CheckSelfTotal = checkSelfTotal
  544. newOrder.CheckInscpTotal = checkInscpTotal
  545. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  546. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  547. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  548. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  549. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  550. newOrder.TreatCostTotal = treatCostTotal
  551. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  552. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  553. newOrder.TreatSelfTotal = treatSelfTotal
  554. newOrder.TreatInscpTotal = treatInscpTotal
  555. newOrder.DoctorInfo = doctor_info
  556. newOrder.DoctorName = doctor_name
  557. newOrder.HealthCardNo = order.PsnNo
  558. newOrder.YiliaoLeibie = yiliao_leibie
  559. newOrder.Patient = patient
  560. newOrder.OrgName = miConfig.OrgName
  561. newOrder.OrgCode = miConfig.Code
  562. newOrder.OrderNumber = order.Number
  563. newOrder.HisPatient = his
  564. newOrder.DiaConfig = dia_config
  565. newOrders = append(newOrders, newOrder)
  566. }
  567. c.ServeSuccessJSON(map[string]interface{}{
  568. "orders": newOrders,
  569. })
  570. }
  571. func (c *HisApiController) GetTestOrder() {
  572. order_id, _ := c.GetInt64("order_id")
  573. admin_user_id, _ := c.GetInt64("admin_user_id")
  574. adminUser := c.GetAdminUserInfo()
  575. order, _ := service.GetHisOrderByID(order_id)
  576. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  577. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  578. orderInfos = append(orderInfos, orderInfos_two...)
  579. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  580. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  581. var dia_config []*models.HisXtDiagnoseConfig
  582. var name string
  583. var bedCostTotal float64 = 0 //床位总费
  584. var bedCostSelfTotal float64 = 0 //床位自费
  585. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  586. var bedSelfTotal float64 = 0 //床位部分项目自费
  587. var bedInscpTotal float64 = 0 //床位部分项目自费
  588. var operationCostTotal float64 = 0 //手术费
  589. var operationCostSelfTotal float64 = 0 //手术费
  590. var operationCostPartSelfTotal float64 = 0 //手术费
  591. var operationSelfTotal float64 = 0 //床位部分项目自费
  592. var operationInscpTotal float64 = 0 //床位部分项目自费
  593. var otherCostTotal float64 = 0 //其他费用
  594. var otherCostSelfTotal float64 = 0 //其他费用
  595. var otherCostPartSelfTotal float64 = 0 //其他费用
  596. var otherSelfTotal float64 = 0 //床位部分项目自费
  597. var otherInscpTotal float64 = 0 //床位部分项目自费
  598. var materialCostTotal float64 = 0 //材料费
  599. var materialCostSelfTotal float64 = 0 //材料费
  600. var materialCostPartSelfTotal float64 = 0 //材料费
  601. var materialSelfTotal float64 = 0 //床位部分项目自费
  602. var materialInscpTotal float64 = 0 //床位部分项目自费
  603. var westernMedicineCostTotal float64 = 0 //西药费
  604. var westernMedicineCostSelfTotal float64 = 0 //西药费
  605. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  606. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  607. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  608. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  609. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  610. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  611. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  612. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  613. var checkCostTotal float64 = 0 //检查费
  614. var checkCostSelfTotal float64 = 0 //检查费
  615. var checkCostPartSelfTotal float64 = 0 //检查费
  616. var checkSelfTotal float64 = 0 //床位部分项目自费
  617. var checkInscpTotal float64 = 0 //床位部分项目自费
  618. var laboratoryCostTotal float64 = 0 //化验费
  619. var laboratoryCostSelfTotal float64 = 0 //化验费
  620. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  621. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  622. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  623. var treatCostTotal float64 = 0 //治疗费用
  624. var treatCostSelfTotal float64 = 0 //治疗费用
  625. var treatCostPartSelfTotal float64 = 0 //治疗费用
  626. var treatSelfTotal float64 = 0 //床位部分项目自费
  627. var treatInscpTotal float64 = 0 //床位部分项目自费
  628. decimal.DivisionPrecision = 2
  629. for _, item := range orderInfos {
  630. if item.MedChrgitmType == "01" { //床位费
  631. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  632. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  633. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  634. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  635. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  636. }
  637. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  638. if item.MedChrgitmType == "03" { //检查费
  639. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  640. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  641. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  642. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  643. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  644. }
  645. } else {
  646. if item.MedChrgitmType == "03" { //检查费
  647. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  648. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  649. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  650. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  651. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  652. }
  653. }
  654. if item.MedChrgitmType == "04" { //化验费
  655. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  656. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  657. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  658. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  659. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  660. }
  661. if item.MedChrgitmType == "05" { //治疗费
  662. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  663. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  664. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  665. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  666. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  667. }
  668. if item.MedChrgitmType == "06" { //手术费
  669. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  670. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  671. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  672. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  673. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  674. }
  675. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  676. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  677. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  678. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  679. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  680. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  681. }
  682. if item.MedChrgitmType == "09" { //西药费
  683. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  684. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  685. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  686. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  687. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  688. }
  689. if item.MedChrgitmType == "11" { //中成费
  690. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  691. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  692. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  693. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  694. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  695. }
  696. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  697. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  698. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  699. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  700. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  701. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  702. }
  703. }
  704. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  705. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  706. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  707. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  708. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  709. var doctor_name string
  710. if roles.ID == 0 {
  711. doctor_name = "管理员"
  712. } else {
  713. doctor_name = roles.UserName
  714. }
  715. yiliao_leibie := ""
  716. switch order.MedType {
  717. case "11":
  718. yiliao_leibie = "普通门诊"
  719. break
  720. case "12":
  721. yiliao_leibie = "门诊挂号"
  722. break
  723. case "13":
  724. yiliao_leibie = "急诊"
  725. break
  726. case "14":
  727. yiliao_leibie = "门诊特殊病"
  728. break
  729. case "15":
  730. yiliao_leibie = "门诊统筹"
  731. break
  732. case "16":
  733. yiliao_leibie = "门诊慢性病"
  734. break
  735. case "21":
  736. yiliao_leibie = "普通住院"
  737. break
  738. }
  739. c.ServeSuccessJSON(map[string]interface{}{
  740. "diagnosis": name,
  741. "order_infos": orderInfos,
  742. "number": order.MdtrtId,
  743. "date": order.SettleAccountsDate,
  744. "charge_admin": charge_admin,
  745. "printor_admin": printor_admin,
  746. "info": order,
  747. "order": order,
  748. "bedCostTotal": bedCostTotal,
  749. "bedCostSelfTotal": bedCostSelfTotal,
  750. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  751. "bedSelfTotal": bedSelfTotal,
  752. "bedInscpTotal": bedInscpTotal,
  753. "operationCostTotal": operationCostTotal,
  754. "operationCostSelfTotal": operationCostSelfTotal,
  755. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  756. "operationSelfTotal": operationSelfTotal,
  757. "operationInscpTotal": operationInscpTotal,
  758. "otherCostTotal": otherCostTotal,
  759. "otherCostSelfTotal": otherCostSelfTotal,
  760. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  761. "otherSelfTotal": otherSelfTotal,
  762. "otherInscpTotal": otherInscpTotal,
  763. "materialCostTotal": materialCostTotal,
  764. "materialCostSelfTotal": materialCostSelfTotal,
  765. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  766. "materialSelfTotal": materialSelfTotal,
  767. "materialInscpTotal": materialInscpTotal,
  768. "westernMedicineCostTotal": westernMedicineCostTotal,
  769. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  770. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  771. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  772. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  773. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  774. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  775. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  776. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  777. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  778. "checkCostTotal": checkCostTotal,
  779. "checkCostSelfTotal": checkCostSelfTotal,
  780. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  781. "checkSelfTotal": checkSelfTotal,
  782. "checkInscpTotal": checkInscpTotal,
  783. "laboratoryCostTotal": laboratoryCostTotal,
  784. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  785. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  786. "laboratorySelfTotal": laboratorySelfTotal,
  787. "laboratoryInscpTotal": laboratoryInscpTotal,
  788. "treatCostTotal": treatCostTotal,
  789. "treatCostSelfTotal": treatCostSelfTotal,
  790. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  791. "treatSelfTotal": treatSelfTotal,
  792. "treatInscpTotal": treatInscpTotal,
  793. "doctor_info": doctor_info,
  794. "doctor_name": doctor_name,
  795. "health_card_no": order.PsnNo,
  796. "yiliao_leibie": yiliao_leibie,
  797. "patient": patient,
  798. "org_name": miConfig.OrgName,
  799. "org_code": miConfig.Code,
  800. "order_number": order.Number,
  801. "his_hospital": his_hospital,
  802. "dia_config": dia_config,
  803. })
  804. }
  805. type CustomFundPay struct {
  806. FundPayType string `json:"fund_pay_type"`
  807. FundPayamt float64 `json:"fund_payamt"`
  808. InscpScpAmt float64 `json:"inscp_scp_amt"`
  809. }
  810. func (c *PublicApiController) GetBaiLinExportData() {
  811. data := service.GetBaiLinOrderData()
  812. fmt.Println(len(data))
  813. var new_data []*models.NewCustomHisOrder
  814. for _, item := range data {
  815. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  816. new_data = append(new_data, item)
  817. }
  818. }
  819. fmt.Println(len(new_data))
  820. c.ServeSuccessJSON(map[string]interface{}{
  821. "list": new_data,
  822. })
  823. }
  824. func (c *HisApiController) GetHisUnChargePatientList() {
  825. record_date := c.GetString("record_date")
  826. sch_type, _ := c.GetInt64("sch_type")
  827. timeLayout := "2006-01-02"
  828. loc, _ := time.LoadLocation("Local")
  829. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  830. if err != nil {
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  832. return
  833. }
  834. recordDateTime := theTime.Unix()
  835. adminInfo := c.GetAdminUserInfo()
  836. var tempPatients []*service.NewTempPatients
  837. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  838. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  839. var patients []*service.NewTempPatients
  840. var patients_two []*service.NewTempPatients
  841. for _, item := range tempPatients {
  842. //过滤掉没挂号的和没开处方的
  843. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  844. patients = append(patients, item)
  845. }
  846. //过滤掉没挂号的
  847. if len(item.HisPatient) > 0 {
  848. patients_two = append(patients_two, item)
  849. }
  850. }
  851. c.ServeSuccessJSON(map[string]interface{}{
  852. "list": patients,
  853. "list_two": patients_two,
  854. })
  855. }
  856. func (c *HisApiController) GetPrivateExpensesOrder() {
  857. //id, _ := c.GetInt64("id")
  858. //record_time := c.GetString("record_time")
  859. order_id, _ := c.GetInt64("order_id")
  860. admin_user_id, _ := c.GetInt64("admin_user_id")
  861. //timeLayout := "2006-01-02"
  862. //loc, _ := time.LoadLocation("Local")
  863. //
  864. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  865. //if err != nil {
  866. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  867. // return
  868. //}
  869. //recordDateTime := theTime.Unix()
  870. adminUser := c.GetAdminUserInfo()
  871. order, _ := service.GetHisOrderByID(order_id)
  872. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  873. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  874. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  875. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  876. //var config []*models.HisXtDiagnoseConfig
  877. var name string
  878. if order.PType == 1 {
  879. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  880. for _, item := range diagnosis_ids {
  881. id, _ := strconv.ParseInt(item, 10, 64)
  882. diagnosisConfig, _ := service.FindDiagnoseById(id)
  883. if len(name) == 0 {
  884. name = diagnosisConfig.ClassName
  885. } else {
  886. name = name + "," + diagnosisConfig.ClassName
  887. }
  888. }
  889. } else {
  890. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  891. for _, item := range diagnosis_ids {
  892. id, _ := strconv.ParseInt(item, 10, 64)
  893. diagnosisConfig, _ := service.FindDiagnoseById(id)
  894. if len(name) == 0 {
  895. name = diagnosisConfig.ClassName
  896. } else {
  897. name = name + "," + diagnosisConfig.ClassName
  898. }
  899. }
  900. }
  901. var bedCostTotal float64 = 0 //床位总费
  902. //var bedCostSelfTotal float64 = 0 //床位自费
  903. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  904. var operationCostTotal float64 = 0 //手术费
  905. //var operationCostSelfTotal float64 = 0 //手术费
  906. var operationCostPartSelfTotal float64 = 0 //手术费
  907. var otherCostTotal float64 = 0 //其他费用
  908. //var otherCostSelfTotal float64 = 0 //其他费用
  909. var otherCostPartSelfTotal float64 = 0 //其他费用
  910. var materialCostTotal float64 = 0 //材料费
  911. //var materialCostSelfTotal float64 = 0 //材料费
  912. var materialCostPartSelfTotal float64 = 0 //材料费
  913. var westernMedicineCostTotal float64 = 0 //西药费
  914. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  915. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  916. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  917. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  918. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  919. var checkCostTotal float64 = 0 //检查费
  920. //var checkCostSelfTotal float64 = 0 //检查费
  921. var checkCostPartSelfTotal float64 = 0 //检查费
  922. var laboratoryCostTotal float64 = 0 //化验费
  923. //var laboratoryCostSelfTotal float64 = 0 //化验费
  924. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  925. var treatCostTotal float64 = 0 //治疗费用
  926. //var treatCostSelfTotal float64 = 0 //治疗费用
  927. var treatCostPartSelfTotal float64 = 0 //治疗费用
  928. var zhenChaCostTotal float64 = 0 //其他费用
  929. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  930. decimal.DivisionPrecision = 2
  931. for _, item := range orderInfos {
  932. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  933. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  934. item.MedChrgitmType = "09"
  935. }
  936. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  937. if item.HisPrescriptionProject.Type == 2 {
  938. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  939. fmt.Println("CostClassify")
  940. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  941. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  942. case 0:
  943. item.MedChrgitmType = "0"
  944. break
  945. case 1:
  946. item.MedChrgitmType = "14"
  947. break
  948. case 2:
  949. item.MedChrgitmType = "05"
  950. break
  951. case 3:
  952. item.MedChrgitmType = "03"
  953. break
  954. case 4:
  955. item.MedChrgitmType = "03"
  956. break
  957. case 5:
  958. item.MedChrgitmType = "08"
  959. break
  960. case 6:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 7:
  964. item.MedChrgitmType = "14"
  965. break
  966. case 8:
  967. item.MedChrgitmType = "03"
  968. break
  969. case 9:
  970. item.MedChrgitmType = "14"
  971. break
  972. case 10:
  973. item.MedChrgitmType = "14"
  974. break
  975. case 11:
  976. item.MedChrgitmType = "06"
  977. break
  978. case 12:
  979. item.MedChrgitmType = "12"
  980. break
  981. case 13:
  982. item.MedChrgitmType = "01"
  983. break
  984. case 14:
  985. item.MedChrgitmType = "04"
  986. break
  987. case 15:
  988. item.MedChrgitmType = "14"
  989. break
  990. }
  991. } else {
  992. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  993. case 1:
  994. item.MedChrgitmType = "14"
  995. break
  996. case 2:
  997. item.MedChrgitmType = "05"
  998. break
  999. case 3:
  1000. item.MedChrgitmType = "04"
  1001. break
  1002. case 4:
  1003. item.MedChrgitmType = "14"
  1004. break
  1005. case 5:
  1006. item.MedChrgitmType = "08"
  1007. break
  1008. case 6:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. case 7:
  1012. item.MedChrgitmType = "14"
  1013. break
  1014. case 8:
  1015. item.MedChrgitmType = "03"
  1016. break
  1017. case 9:
  1018. item.MedChrgitmType = "14"
  1019. break
  1020. default:
  1021. item.MedChrgitmType = "14"
  1022. break
  1023. }
  1024. }
  1025. } else if item.HisPrescriptionProject.Type == 3 {
  1026. item.MedChrgitmType = "08"
  1027. }
  1028. }
  1029. }
  1030. if order.IsMedicineInsurance != 1 {
  1031. order.PsnCashPay = order.MedfeeSumamt
  1032. }
  1033. for _, item := range orderInfos {
  1034. if item.MedChrgitmType == "01" { //床位费
  1035. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1036. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1037. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1038. }
  1039. if item.MedChrgitmType == "02" { //诊察费
  1040. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1041. //zhenChaCostSelfTotal = zhenChaCostTotal
  1042. }
  1043. if item.MedChrgitmType == "03" { //检查费
  1044. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1045. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1046. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1047. }
  1048. if item.MedChrgitmType == "02" { //检查费
  1049. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1050. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1051. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1052. }
  1053. if item.MedChrgitmType == "04" { //化验费
  1054. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1055. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1056. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1057. }
  1058. if item.MedChrgitmType == "05" { //治疗费
  1059. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1060. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1061. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1062. }
  1063. if item.MedChrgitmType == "06" { //手术费
  1064. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1065. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1066. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1067. }
  1068. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1069. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1070. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1071. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1072. }
  1073. if item.MedChrgitmType == "09" { //西药费
  1074. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1075. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1076. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1077. }
  1078. if item.MedChrgitmType == "11" { //中成费
  1079. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1080. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1081. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1082. }
  1083. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1084. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1085. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1086. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1087. }
  1088. }
  1089. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1090. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1091. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1092. var dia_config []*models.HisXtDiagnoseConfig
  1093. var diagnosis_ids []string
  1094. if his.ID > 0 {
  1095. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1096. } else {
  1097. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1098. }
  1099. for _, item := range diagnosis_ids {
  1100. id, _ := strconv.ParseInt(item, 10, 64)
  1101. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1102. dia_config = append(dia_config, diagnosisConfig)
  1103. }
  1104. var rf []CustomFundPay
  1105. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1106. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1107. c.ServeSuccessJSON(map[string]interface{}{
  1108. "patient": patient,
  1109. "order_infos": orderInfos,
  1110. "diagnosis": name,
  1111. "bedCostTotal": bedCostTotal,
  1112. "bedCostSelfTotal": bedCostTotal,
  1113. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1114. "operationCostTotal": operationCostTotal,
  1115. "operationCostSelfTotal": operationCostTotal,
  1116. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1117. "otherCostTotal": otherCostTotal,
  1118. "otherCostSelfTotal": otherCostTotal,
  1119. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1120. "materialCostTotal": materialCostTotal,
  1121. "materialCostSelfTotal": materialCostTotal,
  1122. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1123. "westernMedicineCostTotal": westernMedicineCostTotal,
  1124. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1125. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1126. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1127. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1128. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1129. "checkCostTotal": checkCostTotal,
  1130. "checkCostSelfTotal": checkCostTotal,
  1131. "zhenChaCostTotal": zhenChaCostTotal,
  1132. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1133. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1134. "laboratoryCostTotal": laboratoryCostTotal,
  1135. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1136. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1137. "treatCostTotal": treatCostTotal,
  1138. "treatCostSelfTotal": treatCostTotal,
  1139. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1140. "charge_admin": charge_admin,
  1141. "printor_admin": printor_admin,
  1142. "org_name": org.OrgName,
  1143. "org_code": miConfig.Code,
  1144. "name": patient.Name,
  1145. "number": order.MdtrtId,
  1146. "date": order.SettleAccountsDate,
  1147. "info": order,
  1148. "new_order": order,
  1149. "his_hospital": his_hospital,
  1150. "his": his,
  1151. "funds": rf,
  1152. "dia_config": dia_config,
  1153. })
  1154. }
  1155. func (c *HisApiController) RefudDetail() {
  1156. order_id, _ := c.GetInt64("order_id")
  1157. order, _ := service.GetHisOrderByID(order_id)
  1158. adminUser := c.GetAdminUserInfo()
  1159. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1160. c.ServeSuccessJSON(map[string]interface{}{
  1161. "msg": "撤销成功",
  1162. })
  1163. }
  1164. func (c *HisApiController) Sscard() {
  1165. //r := CardInit()
  1166. //if r == 0 {
  1167. // GetBaseInfo()
  1168. //}
  1169. //c.ServeSuccessJSON(map[string]interface{}{
  1170. // "list": "11",
  1171. //})
  1172. }
  1173. func GetBaseInfo() error {
  1174. //handle := syscall.MustLoadDLL("SSCard.dll")
  1175. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1176. //
  1177. //str := make([]byte, 256)
  1178. //str1 := make([]byte, 256)
  1179. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1180. //if ferr != nil {
  1181. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1182. // return ferr
  1183. //}
  1184. //
  1185. //fmt.Println(string(str))
  1186. //
  1187. //fmt.Println(r)
  1188. return nil
  1189. }
  1190. func CardInit() int {
  1191. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1192. //add := DllTestDef.MustFindProc("Init")
  1193. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1194. //if err != nil {
  1195. // fmt.Println("SSCard的运算结果为:", ret)
  1196. //}
  1197. //result := int(ret)
  1198. return 0
  1199. }
  1200. func IntPtr(n int) uintptr {
  1201. return uintptr(n)
  1202. }
  1203. func StrPtr(s string) uintptr {
  1204. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1205. }
  1206. func (c *HisApiController) GetHisPatientList() {
  1207. record_date := c.GetString("record_date")
  1208. sch_type, _ := c.GetInt64("sch_type")
  1209. patient_type, _ := c.GetInt64("patient_type")
  1210. fmt.Println("patient_type")
  1211. fmt.Println(patient_type)
  1212. timeLayout := "2006-01-02"
  1213. loc, _ := time.LoadLocation("Local")
  1214. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1215. if err != nil {
  1216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1217. return
  1218. }
  1219. recordDateTime := theTime.Unix()
  1220. adminInfo := c.GetAdminUserInfo()
  1221. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1222. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1223. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1224. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1225. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1226. fmt.Println(patients_three)
  1227. //获取当前用户的信息
  1228. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1229. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1230. //获取所有科室信息
  1231. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1232. //var aa []service.PatientThree
  1233. noElementsSlice := make([]service.PatientThree, 0)
  1234. c.ServeSuccessJSON(map[string]interface{}{
  1235. "list": patients_three,
  1236. "list_two": patients_four,
  1237. "list_three": noElementsSlice,
  1238. "info": adminUserInfo,
  1239. "doctors": doctors,
  1240. "department": department,
  1241. })
  1242. } else {
  1243. //获取当前用户的信息
  1244. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1245. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1246. //获取所有科室信息
  1247. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1248. //var aa []service.PatientThree
  1249. noElementsSlice := make([]service.PatientThree, 0)
  1250. c.ServeSuccessJSON(map[string]interface{}{
  1251. "list": patients,
  1252. "list_two": patients_two,
  1253. "list_three": noElementsSlice,
  1254. "info": adminUserInfo,
  1255. "doctors": doctors,
  1256. "department": department,
  1257. })
  1258. }
  1259. }
  1260. type CustomTemplate struct {
  1261. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1262. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1263. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1264. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1265. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1266. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1267. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1268. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1269. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1270. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1271. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1272. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1273. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1274. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1275. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1276. }
  1277. func (c *HisApiController) GetHisPatientInfo() {
  1278. patient_id, _ := c.GetInt64("patient_id")
  1279. his_patient_id, _ := c.GetInt64("his_patient_id")
  1280. record_date := c.GetString("record_date")
  1281. number := c.GetString("number")
  1282. //start_time := c.GetString("start_time")
  1283. //end_time := c.GetString("end_time")
  1284. p_type, _ := c.GetInt64("p_type")
  1285. timeLayout := "2006-01-02"
  1286. loc, _ := time.LoadLocation("Local")
  1287. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1288. if err != nil {
  1289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1290. return
  1291. }
  1292. recordDateTime := theTime.Unix()
  1293. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1294. //if err != nil {
  1295. //
  1296. //}
  1297. //startRecordDateTime := startTime.Unix()
  1298. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1299. //if err != nil {
  1300. //
  1301. //}
  1302. //endRecordDateTime := endTime.Unix()
  1303. admin := c.GetAdminUserInfo()
  1304. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1305. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1306. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1307. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1308. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1309. var prescriptions []*models.HisPrescription
  1310. var last_prescriptions []*models.HisPrescription
  1311. var sch_prescriptions []CustomTemplate
  1312. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1313. if p_type == 1 { //住院
  1314. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1315. for _, item := range prescriptions {
  1316. for _, subItem := range item.HisDoctorAdviceInfo {
  1317. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1318. if info.RetailPrice > 0 {
  1319. subItem.Drug.MinPrice = info.RetailPrice
  1320. }
  1321. }
  1322. }
  1323. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1324. } else { //门诊
  1325. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1326. for _, item := range prescriptions {
  1327. for _, subItem := range item.HisDoctorAdviceInfo {
  1328. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1329. if info.RetailPrice > 0 {
  1330. subItem.Drug.MinPrice = info.RetailPrice
  1331. }
  1332. }
  1333. }
  1334. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1335. }
  1336. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1337. if sch.ID > 0 {
  1338. var week string
  1339. t := time.Now()
  1340. switch t.Weekday().String() {
  1341. case "Monday":
  1342. week = "周一"
  1343. break
  1344. case "Tuesday":
  1345. week = "周二"
  1346. break
  1347. case "Wednesday":
  1348. week = "周三"
  1349. break
  1350. case "Thursday":
  1351. week = "周四"
  1352. break
  1353. case "Friday":
  1354. week = "周五"
  1355. break
  1356. case "Saturday":
  1357. week = "周六"
  1358. break
  1359. case "Sunday":
  1360. week = "周日"
  1361. break
  1362. }
  1363. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1364. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1365. //根据推送频率组装新的数组
  1366. for _, item := range temp_sch_prescriptions {
  1367. var cus CustomTemplate
  1368. cus.ID = item.ID
  1369. cus.UserOrgId = item.UserOrgId
  1370. cus.PatientId = item.PatientId
  1371. cus.MedType = item.MedType
  1372. cus.RecordDate = item.RecordDate
  1373. cus.Type = item.Type
  1374. cus.PType = item.PType
  1375. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1376. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1377. if subItem.FrequencyType == 1 { //每次必推
  1378. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1379. }
  1380. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1381. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1382. }
  1383. if subItem.FrequencyType == 2 { //按照天数频率
  1384. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1385. now := p.Unix()
  1386. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1387. dayStr2 := "-" + dayStr
  1388. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1389. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1390. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1391. if len(advices) == 0 {
  1392. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1393. }
  1394. }
  1395. }
  1396. }
  1397. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1398. if subItem.Type == 2 {
  1399. if subItem.XtHisProject.MedicalStatus != 1 {
  1400. if subItem.FrequencyType == 1 {
  1401. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1402. }
  1403. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1404. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1405. }
  1406. if subItem.FrequencyType == 2 {
  1407. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1408. now := p.Unix()
  1409. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1410. dayStr2 := "-" + dayStr
  1411. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1412. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1413. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1414. if len(projects) == 0 {
  1415. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1416. }
  1417. }
  1418. }
  1419. } else if subItem.Type == 3 {
  1420. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1421. if subItem.FrequencyType == 1 {
  1422. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1423. }
  1424. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1425. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1426. }
  1427. if subItem.FrequencyType == 2 {
  1428. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1429. now := p.Unix()
  1430. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1431. dayStr2 := "-" + dayStr
  1432. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1433. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1434. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1435. if len(projects) == 0 {
  1436. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1437. }
  1438. }
  1439. }
  1440. }
  1441. }
  1442. sch_prescriptions = append(sch_prescriptions, cus)
  1443. }
  1444. for _, item := range sch_prescriptions {
  1445. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1446. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1447. }
  1448. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1449. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1450. }
  1451. }
  1452. }
  1453. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1454. if config.ID > 0 && config.IsOpen == 1 {
  1455. for _, item := range sch_prescriptions {
  1456. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1457. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1458. if info.RetailPrice > 0 {
  1459. subItem.Drug.MinPrice = info.RetailPrice
  1460. if admin.CurrentOrgId != 10598 {
  1461. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1462. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1463. }
  1464. }
  1465. }
  1466. }
  1467. }
  1468. if config.ID > 0 && config.IsOpen == 1 {
  1469. for _, item := range sch_prescriptions {
  1470. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1471. if subItem.Type == 3 {
  1472. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1473. if info.Price > 0 {
  1474. subItem.GoodInfo.PackingPrice = info.Price
  1475. if admin.CurrentOrgId != 10598 {
  1476. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1477. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1478. }
  1479. }
  1480. }
  1481. }
  1482. }
  1483. }
  1484. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1485. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1486. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1487. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1488. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1489. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1490. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1491. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1492. //获取所有科室信息
  1493. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1494. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1495. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1496. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1497. fmt.Println(prescriptions)
  1498. fmt.Println(sch_prescriptions)
  1499. fmt.Println(last_prescriptions)
  1500. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1501. if len(sch_prescriptions) > 0 {
  1502. var index = 0
  1503. for subindex, item := range sch_prescriptions {
  1504. if item.Type == 2 {
  1505. index = subindex
  1506. }
  1507. }
  1508. fmt.Println(index)
  1509. fmt.Println(len(sch_prescriptions))
  1510. if index >= 0 && index < len(sch_prescriptions) {
  1511. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1512. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1513. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1514. if one.ID > 0 {
  1515. var hpt models.HisPrescriptionProjectTemplate
  1516. hpt.Type = 3
  1517. hpt.ID = 0
  1518. hpt.PatientId = sch_prescriptions[index].PatientId
  1519. hpt.Status = 1
  1520. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1521. hpt.Mtime = time.Now().Unix()
  1522. hpt.Ctime = time.Now().Unix()
  1523. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1524. hpt.Count = "1"
  1525. hpt.Price = one.RetailPrice
  1526. hpt.ProjectId = one.ID
  1527. hpt.FeedetlSn = ""
  1528. hpt.PrescriptionId = sch_prescriptions[index].ID
  1529. hpt.Unit = one.PackingUnit
  1530. hpt.Day = "1"
  1531. hpt.SingleDose = "1"
  1532. hpt.GoodInfo = one
  1533. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1534. }
  1535. if two.ID > 0 {
  1536. var hpt models.HisPrescriptionProjectTemplate
  1537. hpt.Type = 3
  1538. hpt.ID = 0
  1539. hpt.PatientId = sch_prescriptions[index].PatientId
  1540. hpt.Status = 1
  1541. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1542. hpt.Mtime = time.Now().Unix()
  1543. hpt.Ctime = time.Now().Unix()
  1544. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1545. hpt.Count = "1"
  1546. hpt.Price = two.RetailPrice
  1547. hpt.ProjectId = two.ID
  1548. hpt.FeedetlSn = ""
  1549. hpt.PrescriptionId = sch_prescriptions[index].ID
  1550. hpt.Unit = two.PackingUnit
  1551. hpt.Day = "1"
  1552. hpt.SingleDose = "1"
  1553. hpt.GoodInfo = two
  1554. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1555. }
  1556. //if three.ID > 0 {
  1557. // var hpt models.HisPrescriptionProjectTemplate
  1558. // hpt.Type = 3
  1559. // hpt.ID = 0
  1560. // hpt.PatientId = sch_prescriptions[index].PatientId
  1561. // hpt.Status = 1
  1562. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1563. // hpt.Mtime = time.Now().Unix()
  1564. // hpt.Ctime = time.Now().Unix()
  1565. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1566. // hpt.Count = "1"
  1567. // hpt.Price = three.RetailPrice
  1568. // hpt.ProjectId = three.ID
  1569. // hpt.FeedetlSn = ""
  1570. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1571. // hpt.Unit = three.PackingUnit
  1572. // hpt.Day = "1"
  1573. // hpt.SingleDose = "1"
  1574. // hpt.GoodInfo = three
  1575. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1576. //}
  1577. fmt.Println(sch_prescriptions)
  1578. }
  1579. } else {
  1580. if len(last_prescriptions) > 0 {
  1581. var index = 0
  1582. for subindex, item := range last_prescriptions {
  1583. if item.Type == 2 {
  1584. index = subindex
  1585. }
  1586. }
  1587. if index >= 0 && index < len(last_prescriptions) {
  1588. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1589. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1590. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1591. if one.ID > 0 {
  1592. var hpt models.HisPrescriptionProject
  1593. hpt.Type = 3
  1594. hpt.ID = 0
  1595. hpt.PatientId = last_prescriptions[index].PatientId
  1596. hpt.Status = 1
  1597. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1598. hpt.Mtime = time.Now().Unix()
  1599. hpt.Ctime = time.Now().Unix()
  1600. hpt.RecordDate = last_prescriptions[index].RecordDate
  1601. hpt.Count = "1"
  1602. hpt.Price = one.RetailPrice
  1603. hpt.ProjectId = one.ID
  1604. hpt.FeedetlSn = ""
  1605. hpt.PrescriptionId = last_prescriptions[index].ID
  1606. hpt.Unit = one.PackingUnit
  1607. hpt.Day = "1"
  1608. hpt.SingleDose = "1"
  1609. hpt.GoodInfo = one
  1610. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1611. }
  1612. if two.ID > 0 {
  1613. var hpt models.HisPrescriptionProject
  1614. hpt.Type = 3
  1615. hpt.ID = 0
  1616. hpt.PatientId = last_prescriptions[index].PatientId
  1617. hpt.Status = 1
  1618. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1619. hpt.Mtime = time.Now().Unix()
  1620. hpt.Ctime = time.Now().Unix()
  1621. hpt.RecordDate = last_prescriptions[index].RecordDate
  1622. hpt.Count = "1"
  1623. hpt.Price = two.RetailPrice
  1624. hpt.ProjectId = two.ID
  1625. hpt.FeedetlSn = ""
  1626. hpt.PrescriptionId = last_prescriptions[index].ID
  1627. hpt.Unit = two.PackingUnit
  1628. hpt.Day = "1"
  1629. hpt.SingleDose = "1"
  1630. hpt.GoodInfo = two
  1631. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1632. }
  1633. //if three.ID > 0 {
  1634. // var hpt models.HisPrescriptionProject
  1635. // hpt.Type = 3
  1636. // hpt.ID = 0
  1637. // hpt.PatientId = last_prescriptions[index].PatientId
  1638. // hpt.Status = 1
  1639. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1640. // hpt.Mtime = time.Now().Unix()
  1641. // hpt.Ctime = time.Now().Unix()
  1642. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1643. // hpt.Count = "1"
  1644. // hpt.Price = three.RetailPrice
  1645. // hpt.ProjectId = three.ID
  1646. // hpt.FeedetlSn = ""
  1647. // hpt.PrescriptionId = last_prescriptions[index].ID
  1648. // hpt.Unit = three.PackingUnit
  1649. // hpt.Day = "1"
  1650. // hpt.SingleDose = "1"
  1651. // hpt.GoodInfo = three
  1652. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1653. //}
  1654. }
  1655. }
  1656. }
  1657. }
  1658. c.ServeSuccessJSON(map[string]interface{}{
  1659. "his_info": his_patient_info,
  1660. "xt_info": xt_patient_info,
  1661. "prescription": prescriptions,
  1662. "case_history": case_history,
  1663. "info": patientPrescriptionInfo,
  1664. //"month_prescriptions": monthPrescriptions,
  1665. "order": order,
  1666. "doctors": doctors,
  1667. "department": department,
  1668. "sch_prescriptions": sch_prescriptions,
  1669. "last_prescriptions": last_prescriptions,
  1670. "schedule": sch,
  1671. "count": count,
  1672. "drugStockConfig": drugStockConfig,
  1673. "last_info": lastPatientPrescriptionInfo,
  1674. "befor": beforThrity,
  1675. "LastCaseHistory": LastCaseHistory,
  1676. "prescriptionInfo": prescriptionInfo,
  1677. })
  1678. return
  1679. }
  1680. func (c *HisApiController) GetHisPrescriptionConfig() {
  1681. adminInfo := c.GetAdminUserInfo()
  1682. //获取医嘱模版
  1683. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1684. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1685. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1686. //获取所有基础药
  1687. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1688. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1689. if config.ID > 0 && config.IsOpen == 1 {
  1690. for _, item := range drugs {
  1691. var index = 0
  1692. for _, subItem := range item.OtherDrugWarehouseInfo {
  1693. if index == 0 {
  1694. index = index + 1
  1695. if subItem.RetailPrice > 0 {
  1696. item.MinPrice = subItem.RetailPrice
  1697. }
  1698. }
  1699. }
  1700. }
  1701. }
  1702. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1703. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1704. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1705. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1706. //获取所有科室信息
  1707. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1708. //获取诊断信息
  1709. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1710. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1711. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1712. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1713. //获取是否开启保存耗材出库的开关
  1714. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1715. c.ServeSuccessJSON(map[string]interface{}{
  1716. "drugs": drugs,
  1717. "advices_template": advices,
  1718. "drugways": drugways,
  1719. "efs": efs,
  1720. "doctors": doctors,
  1721. "department": department,
  1722. "sick": sick,
  1723. "additions": additions,
  1724. "diagnose": diagnose,
  1725. "manufacturers": manufacturers,
  1726. "goodOutOpen": goodOutOpen,
  1727. "patientDiagnose": patientDiagnose,
  1728. })
  1729. }
  1730. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1731. //获取所有基础药
  1732. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1733. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1734. if config.ID > 0 && config.IsOpen == 1 {
  1735. for _, item := range drugs {
  1736. var index = 0
  1737. for _, subItem := range item.OtherDrugWarehouseInfo {
  1738. if index == 0 {
  1739. index = index + 1
  1740. if subItem.RetailPrice > 0 {
  1741. item.MinPrice = subItem.RetailPrice
  1742. }
  1743. }
  1744. }
  1745. }
  1746. }
  1747. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1748. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1749. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1750. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1751. //获取所有科室信息
  1752. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1753. //获取诊断信息
  1754. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1755. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1756. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1757. //获取是否开启保存耗材出库的开关
  1758. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1759. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1760. c.ServeSuccessJSON(map[string]interface{}{
  1761. "drugs": drugs,
  1762. "advices_template": advices,
  1763. "drugways": drugways,
  1764. "efs": efs,
  1765. "doctors": doctors,
  1766. "department": department,
  1767. "sick": sick,
  1768. "additions": additions,
  1769. "diagnose": diagnose,
  1770. "manufacturers": manufacturers,
  1771. "goodOutOpen": goodOutOpen,
  1772. "patientDiagnose": patientDiagnose,
  1773. })
  1774. }
  1775. }
  1776. func (c *HisApiController) CreateHisPrescription() {
  1777. record_date := c.GetString("record_date")
  1778. patient_id, _ := c.GetInt64("patient_id")
  1779. reg_type, _ := c.GetInt64("reg_type")
  1780. diagnose := c.GetString("diagnose")
  1781. sick_type, _ := c.GetInt64("sick_type")
  1782. sick_history := c.GetString("sick_history")
  1783. doctor_id, _ := c.GetInt64("doctor", 0)
  1784. department, _ := c.GetInt64("department", 0)
  1785. his_patient_id, _ := c.GetInt64("his_patient_id")
  1786. p_type, _ := c.GetInt64("p_type")
  1787. patient_diagnose := c.GetString("patient_diagnose")
  1788. dataBody := make(map[string]interface{}, 0)
  1789. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1790. if err != nil {
  1791. utils.ErrorLog(err.Error())
  1792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1793. return
  1794. }
  1795. //edit, src := GetCompareData(dataBody)
  1796. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1797. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1798. //fmt.Println(drugResult)
  1799. //fmt.Println(goodResult)
  1800. timeLayout := "2006-01-02"
  1801. loc, _ := time.LoadLocation("Local")
  1802. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1803. if err != nil {
  1804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1805. return
  1806. }
  1807. adminInfo := c.GetAdminUserInfo()
  1808. recordDateTime := theTime.Unix()
  1809. //查询默认出库仓库库存
  1810. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1811. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1812. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1813. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1814. if len(lists) == 1 {
  1815. his_patient_id = lists[0].ID
  1816. }
  1817. }
  1818. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1819. //自动出库的开关开启
  1820. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1821. //自动出库
  1822. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1823. //耗材保存处方出库
  1824. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1825. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1826. //已发药和已收费限制逻辑
  1827. isMidicine := false
  1828. isCharge := false
  1829. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1830. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1831. if len(prescriptions) > 0 {
  1832. for _, item := range prescriptions {
  1833. items := item.(map[string]interface{})
  1834. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1835. utils.ErrorLog("id")
  1836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1837. return
  1838. }
  1839. id := int64(items["id"].(float64))
  1840. if id > 0 {
  1841. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1842. if err != nil {
  1843. if new_prescription.OrderStatus == 4 {
  1844. isCharge = true
  1845. }
  1846. }
  1847. }
  1848. }
  1849. }
  1850. }
  1851. if isMidicine == true {
  1852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1853. return
  1854. }
  1855. if isCharge == true {
  1856. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1857. return
  1858. }
  1859. // 开始主事务
  1860. db := service.XTWriteDB()
  1861. tx := db.Begin()
  1862. // 在函数结束时处理事务回滚
  1863. defer func() {
  1864. if r := recover(); r != nil {
  1865. tx.Rollback()
  1866. }
  1867. }()
  1868. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1869. //药品发药出库
  1870. if pharmacyConfig.IsOpen == 1 {
  1871. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1872. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1873. if len(prescriptions) > 0 {
  1874. for _, item := range prescriptions {
  1875. items := item.(map[string]interface{})
  1876. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1877. advices := items["advices"].([]interface{})
  1878. if len(advices) > 0 {
  1879. for _, advice := range advices {
  1880. var drug_id int64
  1881. var prescribing_number float64
  1882. var prescribingNumberUnit string
  1883. var adviceId int64
  1884. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1885. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1886. }
  1887. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1888. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1889. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1890. }
  1891. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1892. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1893. }
  1894. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1895. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1896. }
  1897. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1898. if drug.ID == 0 {
  1899. tx.Rollback()
  1900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1901. return
  1902. }
  1903. //查询药品的所有库存
  1904. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1905. var total_count int64
  1906. for _, it := range list {
  1907. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1908. }
  1909. totals := strconv.FormatInt(total_count, 10)
  1910. //查询该药品是否存在开药记录
  1911. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1912. //新增处方盘点库存是否充足
  1913. if advicelist.ID == 0 {
  1914. all_count, _ := strconv.ParseFloat(totals, 64)
  1915. if prescribingNumberUnit == drug.MinUnit {
  1916. if drug.IsUse != 1 {
  1917. if drug.IsProject == 0 || drug.IsProject == 2 {
  1918. if all_count == 0 {
  1919. tx.Rollback()
  1920. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1921. return
  1922. }
  1923. if prescribing_number > all_count {
  1924. tx.Rollback()
  1925. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1926. return
  1927. }
  1928. }
  1929. }
  1930. }
  1931. if prescribingNumberUnit == drug.MaxUnit {
  1932. num := prescribing_number * float64(drug.MinNumber)
  1933. if drug.IsUse != 1 {
  1934. if drug.IsProject == 0 || drug.IsProject == 2 {
  1935. if all_count == 0 {
  1936. tx.Rollback()
  1937. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1938. return
  1939. }
  1940. if num > all_count {
  1941. tx.Rollback()
  1942. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1943. return
  1944. }
  1945. }
  1946. }
  1947. }
  1948. }
  1949. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1950. //不使用保存处方出库
  1951. if drugOutConfig.IsOpen != 1 {
  1952. //修改处方
  1953. for _, advice := range advices {
  1954. var drug_id int64
  1955. var prescribing_number float64
  1956. var prescribingNumberUnit string
  1957. var prescribingNumber string
  1958. var adviceId int64
  1959. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1960. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1961. }
  1962. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1963. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1964. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1965. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1966. }
  1967. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1968. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1969. }
  1970. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1971. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1972. }
  1973. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1974. if drug.ID == 0 {
  1975. tx.Rollback()
  1976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1977. return
  1978. }
  1979. //查询药品的所有库存
  1980. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1981. var total_count int64
  1982. for _, it := range list {
  1983. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1984. }
  1985. totals := strconv.FormatInt(total_count, 10)
  1986. //查询该药品是否存在开药记录
  1987. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1988. //新增处方
  1989. if advicelist.ID == 0 {
  1990. all_count, _ := strconv.ParseFloat(totals, 64)
  1991. if prescribingNumberUnit == drug.MinUnit {
  1992. if drug.IsUse != 1 {
  1993. if drug.IsProject == 0 || drug.IsProject == 2 {
  1994. if all_count == 0 {
  1995. tx.Rollback()
  1996. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1997. return
  1998. }
  1999. if prescribing_number > all_count {
  2000. tx.Rollback()
  2001. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2002. return
  2003. }
  2004. }
  2005. }
  2006. } else {
  2007. if prescribingNumberUnit == drug.MaxUnit {
  2008. num := prescribing_number * float64(drug.MinNumber)
  2009. if drug.IsUse != 1 {
  2010. if drug.IsProject == 0 || drug.IsProject == 2 {
  2011. if all_count == 0 {
  2012. tx.Rollback()
  2013. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2014. return
  2015. }
  2016. if num > all_count {
  2017. tx.Rollback()
  2018. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2019. return
  2020. }
  2021. }
  2022. }
  2023. }
  2024. }
  2025. }
  2026. //修改处方
  2027. if advicelist.ID > 0 {
  2028. var device_number int64
  2029. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2030. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2031. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2032. device_number = prescribingNumberInt * drug.MinNumber
  2033. }
  2034. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2035. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2036. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2037. device_number = prescribingNumberInt
  2038. }
  2039. var number_count int64
  2040. if prescribingNumberUnit == drug.MaxUnit {
  2041. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2042. number_count = prescribingNumberInt * drug.MinNumber
  2043. }
  2044. if prescribingNumberUnit == drug.MinUnit {
  2045. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2046. number_count = prescribingNumberInt
  2047. }
  2048. //如果修改的数量大于之前修改的数量
  2049. if (number_count - device_number) > 0 {
  2050. //如果修改的差数量 大于库存数量
  2051. if drug.IsUse != 1 {
  2052. if (number_count - device_number) > total_count {
  2053. tx.Rollback()
  2054. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2055. return
  2056. }
  2057. }
  2058. }
  2059. }
  2060. }
  2061. }
  2062. }
  2063. }
  2064. }
  2065. }
  2066. }
  2067. }
  2068. }
  2069. //已发药和已收费限制逻辑
  2070. //执行出库的逻辑
  2071. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2072. //校验库存总量
  2073. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2074. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2075. if len(prescriptions) > 0 {
  2076. for _, item := range prescriptions {
  2077. items := item.(map[string]interface{})
  2078. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2079. advices := items["advices"].([]interface{})
  2080. if len(advices) > 0 {
  2081. for _, advice := range advices {
  2082. var drug_id int64
  2083. var prescribing_number float64
  2084. var prescribingNumberUnit string
  2085. var adviceId int64
  2086. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2087. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2088. }
  2089. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2090. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2091. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2092. }
  2093. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2094. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2095. }
  2096. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2097. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2098. }
  2099. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2100. if drug.ID == 0 {
  2101. tx.Rollback()
  2102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2103. return
  2104. }
  2105. //查询药品的所有库存
  2106. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2107. var total_count int64
  2108. for _, it := range list {
  2109. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2110. }
  2111. totals := strconv.FormatInt(total_count, 10)
  2112. //查询该药品是否存在开药记录
  2113. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2114. //查询最新批次库存
  2115. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2116. var batch_number_count int64
  2117. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2118. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2119. //新增处方
  2120. if advicelist.ID == 0 {
  2121. all_count, _ := strconv.ParseFloat(totals, 64)
  2122. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2123. if prescribingNumberUnit == drug.MinUnit {
  2124. if drug.IsUse != 1 {
  2125. if drug.IsProject == 0 || drug.IsProject == 2 {
  2126. if all_count == 0 {
  2127. tx.Rollback()
  2128. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2129. return
  2130. }
  2131. if prescribing_number > all_count {
  2132. tx.Rollback()
  2133. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2134. return
  2135. }
  2136. }
  2137. if adminInfo.CurrentOrgId == 10215 {
  2138. if prescribing_number > batch_number_all_count {
  2139. tx.Rollback()
  2140. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2141. return
  2142. }
  2143. }
  2144. }
  2145. }
  2146. if prescribingNumberUnit == drug.MaxUnit {
  2147. num := prescribing_number * float64(drug.MinNumber)
  2148. if drug.IsUse != 1 {
  2149. if drug.IsProject == 0 || drug.IsProject == 2 {
  2150. if all_count == 0 {
  2151. tx.Rollback()
  2152. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2153. return
  2154. }
  2155. if num > all_count {
  2156. tx.Rollback()
  2157. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2158. return
  2159. }
  2160. }
  2161. if adminInfo.CurrentOrgId == 10215 {
  2162. if num > batch_number_all_count {
  2163. tx.Rollback()
  2164. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2165. return
  2166. }
  2167. }
  2168. }
  2169. }
  2170. }
  2171. //不是保存处方出库
  2172. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2173. if drugOutConfig.IsOpen != 1 {
  2174. //修改处方
  2175. for _, advice := range advices {
  2176. var drug_id int64
  2177. var prescribing_number float64
  2178. var prescribingNumberUnit string
  2179. var prescribingNumber string
  2180. var adviceId int64
  2181. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2182. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2183. }
  2184. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2185. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2186. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2187. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2188. }
  2189. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2190. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2191. }
  2192. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2193. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2194. }
  2195. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2196. if drug.ID == 0 {
  2197. tx.Rollback()
  2198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2199. return
  2200. }
  2201. //查询药品的所有库存
  2202. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2203. var total_count int64
  2204. for _, it := range list {
  2205. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2206. }
  2207. totals := strconv.FormatInt(total_count, 10)
  2208. //查询该药品是否存在开药记录
  2209. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2210. //新增处方
  2211. if advicelist.ID == 0 {
  2212. //查询最新批次库存
  2213. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2214. var batch_number_count int64
  2215. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2216. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2217. all_count, _ := strconv.ParseFloat(totals, 64)
  2218. if all_count == 0 {
  2219. tx.Rollback()
  2220. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2221. return
  2222. }
  2223. if prescribingNumberUnit == drug.MinUnit {
  2224. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2225. if drug.IsUse != 1 {
  2226. if drug.IsProject == 0 || drug.IsProject == 2 {
  2227. if all_count == 0 {
  2228. tx.Rollback()
  2229. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2230. return
  2231. }
  2232. if prescribing_number > all_count {
  2233. tx.Rollback()
  2234. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2235. return
  2236. }
  2237. }
  2238. if adminInfo.CurrentOrgId == 10215 {
  2239. if prescribing_number > batch_number_all_count {
  2240. tx.Rollback()
  2241. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2242. return
  2243. }
  2244. }
  2245. }
  2246. } else {
  2247. if prescribingNumberUnit == drug.MaxUnit {
  2248. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2249. num := prescribing_number * float64(drug.MinNumber)
  2250. if drug.IsUse != 1 {
  2251. if drug.IsProject == 0 || drug.IsProject == 2 {
  2252. if all_count == 0 {
  2253. tx.Rollback()
  2254. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2255. return
  2256. }
  2257. if num > all_count {
  2258. tx.Rollback()
  2259. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2260. return
  2261. }
  2262. }
  2263. if adminInfo.CurrentOrgId == 10215 {
  2264. if prescribing_number > batch_number_all_count {
  2265. tx.Rollback()
  2266. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2267. return
  2268. }
  2269. }
  2270. }
  2271. }
  2272. }
  2273. }
  2274. //修改处方
  2275. if advicelist.ID > 0 {
  2276. //查询最新批次库存
  2277. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2278. var batch_number_count int64
  2279. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2280. var device_number int64
  2281. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2282. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2283. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2284. device_number = prescribingNumberInt * drug.MinNumber
  2285. }
  2286. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2287. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2288. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2289. device_number = prescribingNumberInt
  2290. //回退库存
  2291. }
  2292. var number_count int64
  2293. if prescribingNumberUnit == drug.MaxUnit {
  2294. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2295. number_count = prescribingNumberInt * drug.MinNumber
  2296. //回退库存
  2297. }
  2298. if prescribingNumberUnit == drug.MinUnit {
  2299. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2300. number_count = prescribingNumberInt
  2301. //回退库存
  2302. }
  2303. //如果修改的数量大于之前修改的数量
  2304. if (number_count - device_number) > 0 {
  2305. //如果修改的差数量 大于库存数量
  2306. if drug.IsUse != 1 {
  2307. if drug.IsProject == 0 || drug.IsProject == 2 {
  2308. if total_count == 0 {
  2309. tx.Rollback()
  2310. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2311. return
  2312. }
  2313. if (number_count - device_number) > total_count {
  2314. tx.Rollback()
  2315. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2316. return
  2317. }
  2318. if (number_count - device_number) > batch_number_count {
  2319. tx.Rollback()
  2320. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2321. return
  2322. }
  2323. }
  2324. if adminInfo.CurrentOrgId == 10215 {
  2325. // 查询该药品最后一次出库记录
  2326. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2327. var out_count int64
  2328. var in_count int64
  2329. var stock_max_number int64
  2330. var stock_min_number int64
  2331. for _, it := range outInfo {
  2332. if it.CountUnit == drug.MaxUnit {
  2333. it.Count = it.Count * drug.MinNumber
  2334. }
  2335. out_count += it.Count
  2336. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2337. stock_max_number = warehouseInfoList.StockMaxNumber
  2338. stock_min_number = warehouseInfoList.StockMinNumber
  2339. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2340. }
  2341. if out_count > 0 {
  2342. if (number_count - device_number) > in_count {
  2343. tx.Rollback()
  2344. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2345. return
  2346. }
  2347. }
  2348. // 未出库
  2349. if out_count == 0 {
  2350. var sum_in_count int64
  2351. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2352. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2353. //如果修改的数量大于有库存的第一个批次
  2354. if number_count > sum_in_count {
  2355. tx.Rollback()
  2356. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2357. return
  2358. }
  2359. }
  2360. }
  2361. }
  2362. }
  2363. //药品发药
  2364. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2365. //不使用药品发药的功能
  2366. //if pharmacyConfig.IsOpen != 1 {
  2367. // if device_number != number_count {
  2368. //
  2369. // //查询该药品的出库记录
  2370. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2371. // if len(outListExport) > 0 {
  2372. // //
  2373. // for _, item := range outListExport {
  2374. // //回退库存
  2375. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2376. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2377. // }
  2378. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2379. // var stock_max_number int64
  2380. // var stock_min_number int64
  2381. //
  2382. // if number_count >= drug.MinNumber {
  2383. //
  2384. // stock_max_number = device_number / drug.MinNumber
  2385. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2386. //
  2387. // stock_min_number = device_number % drug.MinNumber
  2388. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2389. //
  2390. // } else {
  2391. //
  2392. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2393. //
  2394. // }
  2395. // }
  2396. //
  2397. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2398. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2399. // }
  2400. // }
  2401. // }
  2402. //
  2403. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2404. // var sum_count int64
  2405. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2406. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2407. // for _, its := range stockInfo {
  2408. // if its.MaxUnit == drug.MaxUnit {
  2409. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2410. // }
  2411. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2412. // }
  2413. // //更新字典里面的库存
  2414. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2415. //
  2416. // //剩余库存
  2417. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2418. //
  2419. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2420. // //减少出库数量
  2421. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2422. //
  2423. // }
  2424. //}
  2425. }
  2426. }
  2427. }
  2428. //保存处方开药
  2429. if drugOutConfig.IsOpen == 1 {
  2430. //修改处方
  2431. for _, advice := range advices {
  2432. var drug_id int64
  2433. var prescribing_number float64
  2434. var prescribingNumberUnit string
  2435. var prescribingNumber string
  2436. var adviceId int64
  2437. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2438. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2439. }
  2440. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2441. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2442. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2443. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2444. }
  2445. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2446. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2447. }
  2448. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2449. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2450. }
  2451. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2452. if drug.ID == 0 {
  2453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2454. return
  2455. }
  2456. //查询药品的所有库存
  2457. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2458. var total_count int64
  2459. for _, it := range list {
  2460. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2461. }
  2462. totals := strconv.FormatInt(total_count, 10)
  2463. //查询该药品是否存在开药记录
  2464. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2465. //新增处方
  2466. if advicelist.ID == 0 {
  2467. //查询最新批次库存
  2468. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2469. var batch_number_count int64
  2470. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2471. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2472. all_count, _ := strconv.ParseFloat(totals, 64)
  2473. if prescribingNumberUnit == drug.MinUnit {
  2474. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2475. if drug.IsUse != 1 {
  2476. if drug.IsProject == 0 || drug.IsProject == 2 {
  2477. if all_count == 0 {
  2478. tx.Rollback()
  2479. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2480. return
  2481. }
  2482. if prescribing_number > all_count {
  2483. tx.Rollback()
  2484. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2485. return
  2486. }
  2487. }
  2488. if adminInfo.CurrentOrgId == 10215 {
  2489. if prescribing_number > batch_number_all_count {
  2490. tx.Rollback()
  2491. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2492. return
  2493. }
  2494. }
  2495. }
  2496. } else {
  2497. if prescribingNumberUnit == drug.MaxUnit {
  2498. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2499. num := prescribing_number * float64(drug.MinNumber)
  2500. if drug.IsUse != 1 {
  2501. if drug.IsProject == 0 || drug.IsProject == 2 {
  2502. if all_count == 0 {
  2503. tx.Rollback()
  2504. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2505. return
  2506. }
  2507. if num > all_count {
  2508. tx.Rollback()
  2509. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2510. return
  2511. }
  2512. }
  2513. if adminInfo.CurrentOrgId == 10215 {
  2514. if prescribing_number > batch_number_all_count {
  2515. tx.Rollback()
  2516. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2517. return
  2518. }
  2519. }
  2520. }
  2521. }
  2522. }
  2523. }
  2524. //修改处方
  2525. if advicelist.ID > 0 {
  2526. //查询最新批次库存
  2527. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2528. var batch_number_count int64
  2529. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2530. var device_number int64
  2531. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2532. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2533. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2534. device_number = prescribingNumberInt * drug.MinNumber
  2535. }
  2536. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2537. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2538. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2539. device_number = prescribingNumberInt
  2540. }
  2541. var number_count int64
  2542. if prescribingNumberUnit == drug.MaxUnit {
  2543. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2544. number_count = prescribingNumberInt * drug.MinNumber
  2545. }
  2546. if prescribingNumberUnit == drug.MinUnit {
  2547. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2548. number_count = prescribingNumberInt
  2549. }
  2550. //如果修改的数量大于之前修改的数量
  2551. if (number_count - device_number) > 0 {
  2552. //如果修改的差数量 大于库存数量
  2553. if drug.IsUse != 1 {
  2554. if drug.IsProject == 0 || drug.IsProject == 2 {
  2555. if total_count == 0 {
  2556. tx.Rollback()
  2557. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2558. return
  2559. }
  2560. if (number_count - device_number) > total_count {
  2561. tx.Rollback()
  2562. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2563. return
  2564. }
  2565. }
  2566. if adminInfo.CurrentOrgId == 10215 {
  2567. if (number_count - device_number) > batch_number_count {
  2568. tx.Rollback()
  2569. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2570. return
  2571. }
  2572. }
  2573. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2574. //查询历史出库数据总批次
  2575. // 查询该药品最后一次出库记录
  2576. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2577. var out_count int64
  2578. var in_count int64
  2579. var stock_max_number int64
  2580. var stock_min_number int64
  2581. for _, it := range outInfo {
  2582. if it.CountUnit == drug.MaxUnit {
  2583. it.Count = it.Count * drug.MinNumber
  2584. }
  2585. out_count += it.Count
  2586. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2587. stock_max_number = warehouseInfoList.StockMaxNumber
  2588. stock_min_number = warehouseInfoList.StockMinNumber
  2589. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2590. }
  2591. if out_count > 0 {
  2592. if (number_count - device_number) > in_count {
  2593. tx.Rollback()
  2594. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2595. return
  2596. }
  2597. }
  2598. // 未出库
  2599. if out_count == 0 {
  2600. var sum_in_count int64
  2601. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2602. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2603. if sum_in_count == 0 {
  2604. tx.Rollback()
  2605. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2606. return
  2607. }
  2608. //如果修改的数量大于有库存的第一个批次
  2609. if number_count > sum_in_count {
  2610. tx.Rollback()
  2611. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2612. return
  2613. }
  2614. }
  2615. }
  2616. }
  2617. }
  2618. }
  2619. }
  2620. }
  2621. }
  2622. }
  2623. }
  2624. }
  2625. }
  2626. }
  2627. }
  2628. //校验耗材库存
  2629. if goodOutConfig.IsOpen == 1 {
  2630. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2631. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2632. if len(prescriptions) > 0 {
  2633. for _, item := range prescriptions {
  2634. items := item.(map[string]interface{})
  2635. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2636. projects := items["project"].([]interface{})
  2637. if len(projects) > 0 {
  2638. for _, project := range projects {
  2639. var project_id int64
  2640. var project_type int64
  2641. var totals float64
  2642. var project_name string
  2643. var parsetotal int64
  2644. var id int64
  2645. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2646. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2647. }
  2648. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2649. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2650. }
  2651. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2652. total, _ := project.(map[string]interface{})["total"].(string)
  2653. totals, _ = strconv.ParseFloat(total, 64)
  2654. }
  2655. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2656. project_name = project.(map[string]interface{})["project_name"].(string)
  2657. }
  2658. if project_type == 3 {
  2659. //查找该耗材的出库记录
  2660. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2661. if len(goodWarehouseInfo) == 0 {
  2662. //查询耗材库存
  2663. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2664. var stock_count int64
  2665. for _, it := range list {
  2666. stock_count += it.StockCount
  2667. }
  2668. stock_counts := strconv.FormatInt(stock_count, 10)
  2669. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2670. if stock_total_count == 0 {
  2671. tx.Rollback()
  2672. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2673. return
  2674. }
  2675. if totals > stock_total_count {
  2676. tx.Rollback()
  2677. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2678. return
  2679. }
  2680. }
  2681. if len(goodWarehouseInfo) > 0 {
  2682. //查询该患者耗材的历史数据
  2683. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2684. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2685. //数量发生改变
  2686. if parsetotal != count {
  2687. //如果现在的数量大于历史数量,就要看库存是否足够
  2688. if parsetotal > count {
  2689. //查询耗材所有库存
  2690. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2691. var stock_count int64
  2692. for _, it := range list {
  2693. stock_count += it.StockCount
  2694. }
  2695. //库存不足
  2696. if stock_count == 0 {
  2697. tx.Rollback()
  2698. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2699. return
  2700. }
  2701. if (parsetotal - count) > stock_count {
  2702. tx.Rollback()
  2703. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2704. return
  2705. }
  2706. }
  2707. }
  2708. }
  2709. }
  2710. }
  2711. }
  2712. }
  2713. }
  2714. }
  2715. }
  2716. }
  2717. //不使用耗材保存处方出库
  2718. if goodOutConfig.IsOpen != 1 {
  2719. if stockConfig.IsOpen == 1 {
  2720. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2721. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2722. if len(prescriptions) > 0 {
  2723. for _, item := range prescriptions {
  2724. items := item.(map[string]interface{})
  2725. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2726. projects := items["project"].([]interface{})
  2727. if len(projects) > 0 {
  2728. for _, project := range projects {
  2729. var project_id int64
  2730. var project_type int64
  2731. var totals float64
  2732. var project_name string
  2733. var parsetotal int64
  2734. var id int64
  2735. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2736. id = int64(project.(map[string]interface{})["id"].(float64))
  2737. }
  2738. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2739. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2740. }
  2741. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2742. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2743. }
  2744. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2745. total, _ := project.(map[string]interface{})["total"].(string)
  2746. totals, _ = strconv.ParseFloat(total, 64)
  2747. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2748. }
  2749. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2750. project_name = project.(map[string]interface{})["project_name"].(string)
  2751. }
  2752. if project_type == 3 {
  2753. //查找该耗材的出库记录
  2754. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2755. //没有出库记录
  2756. if len(goodWarehouseInfo) == 0 {
  2757. //查询耗材库存
  2758. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2759. var stock_count int64
  2760. for _, it := range list {
  2761. stock_count += it.StockCount
  2762. }
  2763. stock_counts := strconv.FormatInt(stock_count, 10)
  2764. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2765. if stock_total_count == 0 {
  2766. tx.Rollback()
  2767. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2768. return
  2769. }
  2770. if totals > stock_total_count {
  2771. tx.Rollback()
  2772. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2773. return
  2774. }
  2775. //查找今日该患者已经出库的所有耗材
  2776. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2777. for _, item := range goodList {
  2778. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2779. var flush_count int64
  2780. for _, it := range goodListSix {
  2781. flush_count += it.StockCount
  2782. }
  2783. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2784. creater := adminInfo.AdminUser.Id
  2785. if errs != nil {
  2786. goodErrcode := models.XtGoodErrcode{
  2787. UserOrgId: item.OrgId,
  2788. Errcode: "手动出库更新剩余出库失败",
  2789. GoodId: item.GoodId,
  2790. Status: 1,
  2791. Ctime: time.Now().Unix(),
  2792. Mtime: 0,
  2793. Count: 0,
  2794. StockCount: 0,
  2795. Creater: creater,
  2796. BatchNumberId: 0,
  2797. WarehouseOutId: 0,
  2798. }
  2799. service.CreateGoodErrcode(goodErrcode)
  2800. }
  2801. }
  2802. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2803. }
  2804. //有出库记录
  2805. if len(goodWarehouseInfo) > 0 {
  2806. //查询该患者耗材的历史数据
  2807. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2808. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2809. //数量发生改变
  2810. if parsetotal != count {
  2811. //查找今日该患者已经出库的所有耗材
  2812. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2813. for _, item := range goodList {
  2814. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2815. var flush_count int64
  2816. for _, it := range goodListSix {
  2817. flush_count += it.StockCount
  2818. }
  2819. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2820. //减少出库数量
  2821. creater := adminInfo.AdminUser.Id
  2822. if errs != nil {
  2823. goodErrcode := models.XtGoodErrcode{
  2824. UserOrgId: item.OrgId,
  2825. Errcode: "手动出库更新剩余出库失败",
  2826. GoodId: item.GoodId,
  2827. Status: 1,
  2828. Ctime: time.Now().Unix(),
  2829. Mtime: 0,
  2830. Count: 0,
  2831. StockCount: 0,
  2832. Creater: creater,
  2833. BatchNumberId: 0,
  2834. WarehouseOutId: 0,
  2835. }
  2836. service.CreateGoodErrcode(goodErrcode)
  2837. }
  2838. //查询默认仓库
  2839. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2840. var total_count int64
  2841. for _, it := range stockList {
  2842. total_count += it.StockCount
  2843. }
  2844. //基础库插入数据
  2845. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2846. }
  2847. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2848. }
  2849. }
  2850. }
  2851. }
  2852. }
  2853. }
  2854. }
  2855. }
  2856. }
  2857. }
  2858. }
  2859. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2860. var hpInfo models.HisPrescriptionInfo
  2861. if info.ID == 0 {
  2862. var randNum int
  2863. randNum = rand.Intn(10000) + 1000
  2864. timestamp := time.Now().Unix()
  2865. tempTime := time.Unix(timestamp, 0)
  2866. timeFormat := tempTime.Format("20060102150405")
  2867. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2868. hpInfo = models.HisPrescriptionInfo{
  2869. HisPatientId: his_patient_id,
  2870. UserOrgId: adminInfo.CurrentOrgId,
  2871. RecordDate: theTime.Unix(),
  2872. PatientId: patient_id,
  2873. Status: 1,
  2874. Ctime: time.Now().Unix(),
  2875. Mtime: time.Now().Unix(),
  2876. Creator: adminInfo.AdminUser.Id,
  2877. Modifier: adminInfo.AdminUser.Id,
  2878. Diagnosis: diagnose,
  2879. SickHistory: sick_history,
  2880. Departments: department,
  2881. RegisterType: reg_type,
  2882. PrescriptionNumber: p_number,
  2883. PrescriptionStatus: 1,
  2884. Doctor: role.UserName,
  2885. DoctorId: doctor_id,
  2886. SickType: sick_type,
  2887. PType: p_type,
  2888. PatientDiagnosis: patient_diagnose,
  2889. }
  2890. service.SavePatientPrescriptionInfo(hpInfo)
  2891. //创建步骤表
  2892. finish := models.XtDialysisFinish{
  2893. IsFinish: 1,
  2894. UserOrgId: adminInfo.CurrentOrgId,
  2895. Status: 1,
  2896. Ctime: time.Now().Unix(),
  2897. Mtime: 0,
  2898. Module: 4,
  2899. RecordDate: theTime.Unix(),
  2900. Sourse: 1,
  2901. PatientId: patient_id,
  2902. }
  2903. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2904. if dialysisFinish.ID == 0 {
  2905. service.CreateDialysisFinish(finish)
  2906. }
  2907. redis := service.RedisClient()
  2908. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2909. redis.Set(key, "", time.Second)
  2910. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2911. redis.Set(keyOne, "", time.Second)
  2912. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2913. redis.Set(keySeven, "", time.Second)
  2914. defer redis.Close()
  2915. } else {
  2916. hpInfo = models.HisPrescriptionInfo{
  2917. ID: info.ID,
  2918. UserOrgId: adminInfo.CurrentOrgId,
  2919. RecordDate: info.RecordDate,
  2920. PatientId: info.PatientId,
  2921. Status: 1,
  2922. Ctime: info.Ctime,
  2923. Mtime: time.Now().Unix(),
  2924. Creator: info.Creator,
  2925. Modifier: adminInfo.AdminUser.Id,
  2926. Diagnosis: diagnose,
  2927. SickHistory: sick_history,
  2928. Departments: department,
  2929. RegisterType: reg_type,
  2930. PrescriptionNumber: info.PrescriptionNumber,
  2931. Doctor: role.UserName,
  2932. PrescriptionStatus: info.PrescriptionStatus,
  2933. DoctorId: doctor_id,
  2934. SickType: sick_type,
  2935. PType: info.PType,
  2936. HisPatientId: info.HisPatientId,
  2937. PatientDiagnosis: patient_diagnose,
  2938. }
  2939. service.SavePatientPrescriptionInfo(hpInfo)
  2940. //创建步骤表
  2941. finish := models.XtDialysisFinish{
  2942. IsFinish: 1,
  2943. UserOrgId: adminInfo.CurrentOrgId,
  2944. Status: 1,
  2945. Ctime: time.Now().Unix(),
  2946. Mtime: 0,
  2947. Module: 4,
  2948. RecordDate: info.RecordDate,
  2949. Sourse: 1,
  2950. PatientId: info.PatientId,
  2951. }
  2952. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2953. if dialysisFinish.ID == 0 {
  2954. service.CreateDialysisFinish(finish)
  2955. }
  2956. redis := service.RedisClient()
  2957. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2958. redis.Set(key, "", time.Second)
  2959. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2960. redis.Set(keyOne, "", time.Second)
  2961. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2962. redis.Set(keySeven, "", time.Second)
  2963. defer redis.Close()
  2964. }
  2965. //定义切片
  2966. var adviceList []models.HisDoctorAdviceInfo
  2967. var projectList []models.HisPrescriptionProject
  2968. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10644 || adminInfo.CurrentOrgId == 10635 || adminInfo.CurrentOrgId == 10598 || adminInfo.CurrentOrgId == 10028 || adminInfo.CurrentOrgId == 10721 || adminInfo.CurrentOrgId == 10726 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10571 || adminInfo.CurrentOrgId == 10724 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10653 {
  2969. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2970. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2971. var tempPrescription *models.HisPrescription
  2972. if len(prescriptions) > 0 {
  2973. for _, item := range prescriptions {
  2974. // 开始外部循环的事务
  2975. tx := db.Begin()
  2976. // 在函数结束时处理事务回滚
  2977. defer func() {
  2978. if r := recover(); r != nil {
  2979. tx.Rollback()
  2980. }
  2981. }()
  2982. items := item.(map[string]interface{})
  2983. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2984. utils.ErrorLog("id")
  2985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2986. return
  2987. }
  2988. id := int64(items["id"].(float64))
  2989. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2990. tempPrescription = &new_prescription
  2991. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2992. utils.ErrorLog("type")
  2993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2994. return
  2995. }
  2996. types := int64(items["type"].(float64))
  2997. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2998. utils.ErrorLog("med_type")
  2999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3000. return
  3001. }
  3002. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3003. if med_type == "0" {
  3004. med_type = "14"
  3005. }
  3006. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3007. // utils.ErrorLog("diagnoses")
  3008. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3009. // return
  3010. //}
  3011. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3012. diagnoses, _ := items["diagnoses"].(string)
  3013. //if order_status == 0 {
  3014. // order_status = 1
  3015. //}
  3016. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3017. utils.ErrorLog("pre_time")
  3018. }
  3019. preTime, _ := items["pre_time"].(string)
  3020. fmt.Println("preTime", preTime)
  3021. timeLayout := "2006-01-02"
  3022. loc, _ := time.LoadLocation("Local")
  3023. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3024. //result := strings.Split(preTime, " ")
  3025. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3026. if err != nil {
  3027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3028. return
  3029. }
  3030. pTime := theTime2.Unix()
  3031. ctime := time.Now().Unix()
  3032. if tempPrescription.ID == 0 {
  3033. prescription := &models.HisPrescription{
  3034. ID: 0,
  3035. PatientId: patient_id,
  3036. UserOrgId: adminInfo.CurrentOrgId,
  3037. RecordDate: recordDateTime,
  3038. Ctime: ctime,
  3039. Mtime: ctime,
  3040. Type: types,
  3041. Modifier: adminInfo.AdminUser.Id,
  3042. Creator: adminInfo.AdminUser.Id,
  3043. Status: 1,
  3044. Doctor: role.UserName,
  3045. HisPatientId: his_patient_id,
  3046. OrderStatus: 1,
  3047. BatchNumber: "",
  3048. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3049. PreTime: pTime,
  3050. PType: p_type,
  3051. MedType: med_type,
  3052. Diagnose: diagnoses,
  3053. }
  3054. tempPrescription = prescription
  3055. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3056. redis := service.RedisClient()
  3057. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3058. redis.Set(key, "", time.Second)
  3059. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3060. redis.Set(keyOne, "", time.Second)
  3061. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3062. redis.Set(keySeven, "", time.Second)
  3063. defer redis.Close()
  3064. } else {
  3065. tempPrescription.ID = id
  3066. tempPrescription.Type = types
  3067. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3068. tempPrescription.Mtime = time.Now().Unix()
  3069. tempPrescription.Doctor = role.UserName
  3070. //tempPrescription.OrderStatus = order_status
  3071. tempPrescription.PreTime = pTime
  3072. tempPrescription.MedType = med_type
  3073. tempPrescription.Diagnose = diagnoses
  3074. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3075. redis := service.RedisClient()
  3076. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3077. redis.Set(key, "", time.Second)
  3078. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3079. redis.Set(keyOne, "", time.Second)
  3080. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3081. redis.Set(keySeven, "", time.Second)
  3082. defer redis.Close()
  3083. }
  3084. //service.SaveHisPrescription(prescription)
  3085. //更改患者挂号状态
  3086. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3087. fmt.Println("更改失败", err2)
  3088. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3089. advices := items["advices"].([]interface{})
  3090. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3091. groupNo := int64(0)
  3092. if len(advices) > 0 {
  3093. for _, advice := range advices {
  3094. tx := db.Begin()
  3095. // 在函数结束时处理事务回滚
  3096. defer func() {
  3097. if r := recover(); r != nil {
  3098. tx.Rollback()
  3099. }
  3100. }()
  3101. var s models.HisDoctorAdviceInfo
  3102. s.PrescriptionId = tempPrescription.ID
  3103. s.AdviceType = 2
  3104. s.AdviceDoctor = doctor_id
  3105. s.StopState = 2
  3106. s.ExecutionState = 2
  3107. s.AdviceDate = theTime3.Unix()
  3108. s.Status = 1
  3109. s.UserOrgId = adminInfo.CurrentOrgId
  3110. s.RecordDate = theTime3.Unix()
  3111. s.StartTime = tempPrescription.PreTime
  3112. s.Groupno = groupNo
  3113. s.PatientId = patient_id
  3114. s.HisPatientId = his_patient_id
  3115. s.StartTime = pTime
  3116. s.IsSettle = 2
  3117. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3118. if errcode > 0 {
  3119. c.ServeFailJSONWithSGJErrorCode(errcode)
  3120. return
  3121. }
  3122. s.StartTime = pTime
  3123. var total_count int64 //处方总库存
  3124. //查询改药品信息
  3125. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3126. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3127. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3128. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3129. total_count += prescribingNumberSeven * medical.MinNumber
  3130. }
  3131. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3132. total_count += prescribingNumberSeven
  3133. }
  3134. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3135. total_count += prescribingNumberSeven
  3136. }
  3137. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3138. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3139. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3140. if s.Price != lastWarehouse.RetailPrice {
  3141. s.Price = lastWarehouse.RetailPrice
  3142. }
  3143. if s.Price == 0 {
  3144. if lastWarehouse.ID == 0 {
  3145. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3146. s.Price = lastWarehouseTwo.RetailPrice
  3147. }
  3148. }
  3149. }
  3150. //查询保存处方出库开关是否打开
  3151. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3152. if s.PatientId != 30038 {
  3153. if drugOutConfig.IsOpen == 1 {
  3154. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3155. // 查询该药品最后一次出库记录
  3156. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3157. var is_user_total int64
  3158. var no_user_total int64
  3159. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3160. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3161. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3162. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3163. }
  3164. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3165. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3166. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3167. no_user_total += prescribingNumberSevenTy
  3168. }
  3169. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3170. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3171. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3172. no_user_total += prescribingNumberSevenTy
  3173. }
  3174. if len(druginfo) > 0 {
  3175. for _, it := range druginfo {
  3176. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3177. it.Count = it.Count * drug.MinNumber
  3178. is_user_total += it.Count
  3179. }
  3180. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3181. is_user_total += it.Count
  3182. }
  3183. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3184. is_user_total += it.Count
  3185. }
  3186. }
  3187. }
  3188. //fmt.Println("药品名称----------------------", drug.DrugName)
  3189. //fmt.Println("药品名称----------------------", drug.IsUse)
  3190. //fmt.Println("is_user_total-------------------------", is_user_total)
  3191. //fmt.Println("no_user_total-------------------------", no_user_total)
  3192. if is_user_total != no_user_total {
  3193. //出库
  3194. if drug.IsUse == 2 {
  3195. creater := adminInfo.AdminUser.Id
  3196. newadviceInfo := &models.HisDoctorAdviceInfo{
  3197. ID: s.ID,
  3198. UserOrgId: s.UserOrgId,
  3199. PatientId: s.PatientId,
  3200. HisPatientId: s.HisPatientId,
  3201. AdviceType: s.AdviceType,
  3202. AdviceDate: s.AdviceDate,
  3203. StartTime: s.StartTime,
  3204. AdviceName: s.AdviceName,
  3205. AdviceDesc: s.AdviceDesc,
  3206. ReminderDate: s.ReminderDate,
  3207. SingleDose: s.SingleDose,
  3208. SingleDoseUnit: s.SingleDoseUnit,
  3209. PrescribingNumber: s.PrescribingNumber,
  3210. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3211. DeliveryWay: s.DeliveryWay,
  3212. ExecutionFrequency: s.ExecutionFrequency,
  3213. AdviceDoctor: s.AdviceDoctor,
  3214. Status: s.Status,
  3215. CreatedTime: s.CreatedTime,
  3216. UpdatedTime: s.UpdatedTime,
  3217. AdviceAffirm: s.AdviceAffirm,
  3218. Remark: s.Remark,
  3219. StopTime: s.StopTime,
  3220. StopReason: s.StopReason,
  3221. StopDoctor: s.StopDoctor,
  3222. StopState: s.StopState,
  3223. ParentId: s.ParentId,
  3224. ExecutionTime: s.ExecutionTime,
  3225. ExecutionStaff: s.ExecutionStaff,
  3226. ExecutionState: s.ExecutionState,
  3227. Checker: s.Checker,
  3228. RecordDate: s.RecordDate,
  3229. DialysisOrderId: s.DialysisOrderId,
  3230. CheckTime: s.CheckTime,
  3231. CheckState: s.CheckState,
  3232. DrugSpec: s.DrugSpec,
  3233. DrugSpecUnit: s.DrugSpecUnit,
  3234. Groupno: s.Groupno,
  3235. RemindType: s.RemindType,
  3236. FrequencyType: s.FrequencyType,
  3237. DayCount: s.DayCount,
  3238. WeekDay: s.WeekDay,
  3239. TemplateId: s.TemplateId,
  3240. Modifier: s.Modifier,
  3241. DrugId: s.DrugId,
  3242. Price: s.Price,
  3243. PrescriptionId: s.PrescriptionId,
  3244. MedListCodg: s.MedListCodg,
  3245. FeedetlSn: s.FeedetlSn,
  3246. Day: s.DayCount,
  3247. ChildDoctorAdvice: nil,
  3248. Drug: models.Drug{},
  3249. Diagnosis: s.Diagnosis,
  3250. Way: s.Way,
  3251. HospApprFlag: s.HospApprFlag,
  3252. LmtUsedFlag: s.LmtUsedFlag,
  3253. HisOrderInfo: models.HisOrderInfo{},
  3254. IsMedicine: s.IsMedicine,
  3255. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3256. Child: nil,
  3257. IsSettle: s.IsSettle,
  3258. IsMobile: s.IsMobile,
  3259. IsSelfDrug: s.IsSelfDrug,
  3260. DrugWayCount: s.DrugWayCount,
  3261. }
  3262. var history_count int64
  3263. var local_count int64
  3264. //查找已经开过的医嘱信息
  3265. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3266. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3267. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3268. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3269. local_count += prescribingNumberSevenTy * drug.MinNumber
  3270. }
  3271. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3272. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3273. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3274. local_count += prescribingNumberSevenTy
  3275. }
  3276. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3277. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3278. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3279. local_count += prescribingNumberSevenTy
  3280. }
  3281. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3282. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3283. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3284. history_count += prescribingNumberSevenTy * drug.MinNumber
  3285. }
  3286. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3287. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3288. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3289. history_count += prescribingNumberSevenTy
  3290. }
  3291. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3292. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3293. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3294. history_count += prescribingNumberSevenTy
  3295. }
  3296. //如果当前出库数量大于历史出库数量则需要出库
  3297. if local_count > history_count {
  3298. //按最小单位出库
  3299. var cha_count = local_count - history_count
  3300. newadviceInfo.PrescribingNumber = float64(cha_count)
  3301. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3302. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3303. }
  3304. //如果当前出库数量小于历史出库数量则需要退库
  3305. if local_count < history_count {
  3306. var cha_count = history_count - local_count
  3307. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3308. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3309. }
  3310. if local_count == history_count {
  3311. if is_user_total == 0 {
  3312. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3313. }
  3314. }
  3315. }
  3316. //更新字典里面的库存
  3317. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3318. var sum_count int64
  3319. for _, its := range stockInfo {
  3320. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3321. if its.MaxUnit == baseDrug.MaxUnit {
  3322. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3323. }
  3324. sum_count += its.StockMaxNumber + its.StockMinNumber
  3325. }
  3326. //更新基础库存
  3327. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3328. //剩余库存
  3329. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3330. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3331. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3332. //创建医嘱
  3333. service.CreateHisDoctorAdviceOne(&s, tx)
  3334. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3335. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3336. if len(outInfoTwo) > 0 {
  3337. for _, item := range outInfoTwo {
  3338. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3339. }
  3340. }
  3341. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3342. if len(drugAutoDetail) > 0 {
  3343. for _, item := range drugAutoDetail {
  3344. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3345. }
  3346. }
  3347. }
  3348. }
  3349. }
  3350. //记录日志
  3351. byterequest, _ := json.Marshal(s)
  3352. adviceLog := models.XtDoctorAdviceLog{
  3353. UserOrgId: s.UserOrgId,
  3354. PatientId: s.PatientId,
  3355. AdminUserId: adminInfo.AdminUser.Id,
  3356. Module: 1,
  3357. ErrLog: string(byterequest),
  3358. Status: 1,
  3359. Ctime: time.Now().Unix(),
  3360. Mtime: 0,
  3361. Source: "电脑端新建his医嘱",
  3362. RecordDate: s.AdviceDate,
  3363. }
  3364. service.CreateDoctorAdviceLog(adviceLog)
  3365. //存储切片中
  3366. adviceList = append(adviceList, s)
  3367. redis := service.RedisClient()
  3368. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3369. redis.Set(key, "", time.Second)
  3370. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3371. redis.Set(keyOne, "", time.Second)
  3372. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3373. redis.Set(keySeven, "", time.Second)
  3374. var randNum int
  3375. randNum = rand.Intn(10000) + 1000
  3376. timestamp := time.Now().Unix()
  3377. tempTime := time.Unix(timestamp, 0)
  3378. timeFormat := tempTime.Format("20060102150405")
  3379. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3380. if s.UserOrgId != 10206 {
  3381. if s.ID == 0 {
  3382. //查询改药品是否已经停用
  3383. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3384. if base.ID > 0 {
  3385. tx.Rollback()
  3386. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3387. return
  3388. }
  3389. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3390. if drugMedical.SumCount == 0 {
  3391. tx.Rollback()
  3392. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3393. return
  3394. }
  3395. }
  3396. if s.ID > 0 {
  3397. //查询改药品是否已经停用
  3398. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3399. if base.ID > 0 {
  3400. tx.Rollback()
  3401. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3402. return
  3403. }
  3404. }
  3405. }
  3406. //赤峰
  3407. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3408. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3409. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3410. if info.RetailPrice > 0 {
  3411. if s.DeliveryWay == "口服" {
  3412. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3413. s.Price = drug.RetailPrice
  3414. }
  3415. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3416. s.Price = info.RetailPrice
  3417. }
  3418. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3419. s.Price = info.RetailPrice
  3420. }
  3421. }
  3422. }
  3423. }
  3424. service.CreateHisDoctorAdviceOne(&s, tx)
  3425. tx.Commit()
  3426. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3427. redis.Set(keySix, "", time.Second)
  3428. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3429. redis.Set(keyFive, "", time.Second)
  3430. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3431. redis.Set(keyEight, "", time.Second)
  3432. defer redis.Close()
  3433. }
  3434. }
  3435. }
  3436. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3437. projects := items["project"].([]interface{})
  3438. if len(projects) > 0 {
  3439. for _, project := range projects {
  3440. tx := db.Begin()
  3441. // 在函数结束时处理事务回滚
  3442. defer func() {
  3443. if r := recover(); r != nil {
  3444. tx.Rollback()
  3445. }
  3446. }()
  3447. var p models.HisPrescriptionProject
  3448. p.PrescriptionId = tempPrescription.ID
  3449. p.PatientId = patient_id
  3450. p.RecordDate = theTime3.Unix()
  3451. p.Doctor = doctor_id
  3452. p.UserOrgId = adminInfo.CurrentOrgId
  3453. p.HisPatientId = his_patient_id
  3454. p.Status = 1
  3455. p.StartTime = pTime
  3456. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3457. if errcode > 0 {
  3458. tx.Rollback()
  3459. c.ServeFailJSONWithSGJErrorCode(errcode)
  3460. return
  3461. }
  3462. if p.ID == 0 {
  3463. p.IsOut = 2
  3464. }
  3465. if p.ID > 0 {
  3466. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3467. p.IsOut = projectDetail.IsOut
  3468. }
  3469. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3470. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3471. if p.Type == 3 {
  3472. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3473. if p.Price != lastWarehouse.PackingPrice {
  3474. p.Price = lastWarehouse.PackingPrice
  3475. }
  3476. if p.Price == 0 {
  3477. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3478. p.Price = lastWarehouseTwo.PackingPrice
  3479. }
  3480. if p.Unit == "" {
  3481. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3482. p.Unit = goodInfoOne.PackingUnit
  3483. }
  3484. }
  3485. }
  3486. if adminInfo.CurrentOrgId != 10206 {
  3487. if p.Type == 3 {
  3488. if p.ID == 0 {
  3489. //查询该耗材是否停用
  3490. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3491. //表示该耗材已经停用,不能保存
  3492. if goodInfoSeven.ID == 0 {
  3493. tx.Rollback()
  3494. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3495. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3496. return
  3497. }
  3498. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3499. if goodInfoOne.SumCount == 0 {
  3500. tx.Rollback()
  3501. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3502. return
  3503. }
  3504. }
  3505. if p.ID > 0 {
  3506. //查询该耗材是否停用
  3507. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3508. //表示该耗材已经停用,不能保存
  3509. if goodInfoSeven.ID == 0 {
  3510. tx.Rollback()
  3511. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3512. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3513. return
  3514. }
  3515. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3516. if goodInfoOne.SumCount == 0 {
  3517. tx.Rollback()
  3518. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3519. return
  3520. }
  3521. }
  3522. }
  3523. }
  3524. //查询保存耗材出库开关是否打开
  3525. if p.PatientId != 30038 {
  3526. //用机构ID区分
  3527. if adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10164 {
  3528. if goodOutConfig.IsOpen == 1 {
  3529. //耗材出库
  3530. if p.Type == 3 {
  3531. //对比当前数据和历史出库数据
  3532. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3533. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3534. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3535. //如果当前处方数量大于历史数据,则需要出库
  3536. if nowCount > historyCount {
  3537. var cha_count int64
  3538. cha_count = nowCount - historyCount
  3539. timeStr := time.Now().Format("2006-01-02")
  3540. timeArr := strings.Split(timeStr, "-")
  3541. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3542. total = total + 1
  3543. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3544. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3545. number = number + total
  3546. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3547. operation_time := time.Now().Unix()
  3548. creater := c.GetAdminUserInfo().AdminUser.Id
  3549. recordDateStr := time.Now().Format("2006-01-02")
  3550. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3551. nowtime := recordDate.Unix()
  3552. warehouseOut := models.WarehouseOut{
  3553. WarehouseOutOrderNumber: warehousing_out_order,
  3554. OperationTime: operation_time,
  3555. OrgId: adminInfo.CurrentOrgId,
  3556. Creater: creater,
  3557. Ctime: time.Now().Unix(),
  3558. Status: 1,
  3559. WarehouseOutTime: nowtime,
  3560. Type: 1,
  3561. StorehouseId: storeConfig.StorehouseOutInfo,
  3562. IsCheck: 1,
  3563. IsSys: 1,
  3564. }
  3565. //查询是否生成出库单
  3566. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3567. if out.ID == 0 {
  3568. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3569. }
  3570. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3571. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3572. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3573. dialyPrepareOne := models.DialysisBeforePrepare{
  3574. GoodTypeId: goodObj.GoodTypeId,
  3575. GoodId: p.ProjectId,
  3576. PatientId: p.PatientId,
  3577. RecordDate: p.RecordDate,
  3578. UserOrgId: adminInfo.CurrentOrgId,
  3579. Count: cha_count,
  3580. Ctime: time.Now().Unix(),
  3581. Creater: creater,
  3582. Status: 1,
  3583. StorehouseId: houseConfig.StorehouseOutInfo,
  3584. ProjectId: p.ID,
  3585. }
  3586. //出库
  3587. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3588. }
  3589. //如果当前处方数量小于历史数据,怎需要退库
  3590. if nowCount < historyCount {
  3591. var cha_count int64
  3592. cha_count = historyCount - nowCount
  3593. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3594. creater := c.GetAdminUserInfo().AdminUser.Id
  3595. newPrescriptionProject := &models.HisPrescriptionProject{
  3596. ID: p.ID,
  3597. ProjectId: p.ProjectId,
  3598. Price: p.Price,
  3599. UserOrgId: p.UserOrgId,
  3600. Status: 1,
  3601. Ctime: time.Now().Unix(),
  3602. Mtime: time.Now().Unix(),
  3603. PatientId: p.PatientId,
  3604. HisPatientId: p.HisPatientId,
  3605. RecordDate: p.RecordDate,
  3606. PrescriptionId: p.PrescriptionId,
  3607. Count: p.Count,
  3608. FeedetlSn: p.FeedetlSn,
  3609. MedListCodg: p.MedListCodg,
  3610. SingleDose: p.SingleDose,
  3611. DeliveryWay: p.DeliveryWay,
  3612. ExecutionFrequency: p.ExecutionFrequency,
  3613. Day: p.Day,
  3614. HisProject: models.HisProject{},
  3615. GoodInfo: models.GoodInfo{},
  3616. Remark: p.Remark,
  3617. Unit: p.Unit,
  3618. Type: p.Type,
  3619. Doctor: p.Doctor,
  3620. ExecutionTime: p.ExecutionTime,
  3621. ExecutionStaff: p.ExecutionStaff,
  3622. ExecutionState: p.ExecutionState,
  3623. CheckTime: p.CheckTime,
  3624. CheckState: p.CheckState,
  3625. Checker: p.Checker,
  3626. StartTime: p.StartTime,
  3627. TeamId: p.TeamId,
  3628. XtHisProjectTeam: models.XtHisProjectTeam{},
  3629. FrequencyType: p.FrequencyType,
  3630. DayCount: p.DayCount,
  3631. WeekDay: p.WeekDay,
  3632. IsCheckTeam: p.IsCheckTeam,
  3633. HisOrderInfo: models.HisOrderInfo{},
  3634. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3635. IsOut: p.IsOut,
  3636. YbSyncStatus: p.YbSyncStatus,
  3637. }
  3638. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3639. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3640. }
  3641. if nowCount == historyCount {
  3642. if historyCount == 0 {
  3643. recordDateStr := time.Now().Format("2006-01-02")
  3644. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3645. nowtime := recordDate.Unix()
  3646. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3647. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3648. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3649. creater := c.GetAdminUserInfo().AdminUser.Id
  3650. dialyPrepareOne := models.DialysisBeforePrepare{
  3651. GoodTypeId: goodObj.GoodTypeId,
  3652. GoodId: p.ProjectId,
  3653. PatientId: p.PatientId,
  3654. RecordDate: p.RecordDate,
  3655. UserOrgId: adminInfo.CurrentOrgId,
  3656. Count: nowCount,
  3657. Ctime: time.Now().Unix(),
  3658. Creater: creater,
  3659. Status: 1,
  3660. StorehouseId: houseConfig.StorehouseOutInfo,
  3661. ProjectId: p.ID,
  3662. }
  3663. //出库
  3664. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3665. }
  3666. }
  3667. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3668. //查询历史出库数据
  3669. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3670. var out_count_five int64
  3671. for _, item := range flowGood {
  3672. out_count_five += item.Count
  3673. }
  3674. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3675. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3676. if out_count_five != parseIntCount {
  3677. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3678. detail := models.AutomaticReduceDetail{
  3679. WarehouseOutId: 0,
  3680. WarehouseOutOrderNumber: "",
  3681. PatientId: p.PatientId,
  3682. Ctime: time.Now().Unix(),
  3683. Mtime: 0,
  3684. Status: 1,
  3685. RecordTime: p.RecordDate,
  3686. OrgId: p.UserOrgId,
  3687. GoodId: p.ProjectId,
  3688. GoodTypeId: 0,
  3689. Count: parseIntCount,
  3690. Type: 0,
  3691. ProjectId: lastHisProject.ID,
  3692. StorehouseId: 0,
  3693. }
  3694. service.CreateNewAutoDetail(detail, tx)
  3695. }
  3696. // //查询耗材最后一次出库记录
  3697. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3698. // //查询默认出库仓库库存
  3699. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3700. // if len(wareOut) > 0 {
  3701. //
  3702. // for _, it := range wareOut {
  3703. // //回退库存
  3704. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3705. //
  3706. // //删除出库记录
  3707. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3708. //
  3709. // }
  3710. // }
  3711. //
  3712. // timeStr := time.Now().Format("2006-01-02")
  3713. // timeArr := strings.Split(timeStr, "-")
  3714. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3715. //
  3716. // total = total + 1
  3717. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3718. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3719. // number = number + total
  3720. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3721. //
  3722. // operation_time := time.Now().Unix()
  3723. // creater := c.GetAdminUserInfo().AdminUser.Id
  3724. //
  3725. // recordDateStr := time.Now().Format("2006-01-02")
  3726. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3727. // nowtime := recordDate.Unix()
  3728. // warehouseOut := models.WarehouseOut{
  3729. // WarehouseOutOrderNumber: warehousing_out_order,
  3730. // OperationTime: operation_time,
  3731. // OrgId: adminInfo.CurrentOrgId,
  3732. // Creater: creater,
  3733. // Ctime: time.Now().Unix(),
  3734. // Status: 1,
  3735. // WarehouseOutTime: nowtime,
  3736. // Type: 1,
  3737. // StorehouseId: storeConfig.StorehouseOutInfo,
  3738. // IsCheck: 1,
  3739. // IsSys: 1,
  3740. // }
  3741. // //查询是否生成出库单
  3742. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3743. // if out.ID == 0 {
  3744. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3745. // }
  3746. //
  3747. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3748. //
  3749. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3750. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3751. //
  3752. // dialyPrepareOne := models.DialysisBeforePrepare{
  3753. // GoodTypeId: goodObj.GoodTypeId,
  3754. // GoodId: p.ProjectId,
  3755. // PatientId: p.PatientId,
  3756. // RecordDate: p.RecordDate,
  3757. // UserOrgId: adminInfo.CurrentOrgId,
  3758. // Count: parseIntCount,
  3759. // Ctime: time.Now().Unix(),
  3760. // Creater: creater,
  3761. // Status: 1,
  3762. // StorehouseId: houseConfig.StorehouseOutInfo,
  3763. // ProjectId: lastHisProject.ID,
  3764. // }
  3765. // //判断是否是零用耗材(非零用)
  3766. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3767. //
  3768. // //查询历史出库数据
  3769. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3770. // var out_count int64
  3771. // for _, item := range flowGood {
  3772. // out_count += item.Count
  3773. // }
  3774. // //如果历史数和当前数据不想等才进行退库出库
  3775. // if out_count != parseIntCount {
  3776. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3777. //
  3778. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3779. // detail := models.AutomaticReduceDetail{
  3780. // WarehouseOutId: 0,
  3781. // WarehouseOutOrderNumber: "",
  3782. // PatientId: p.PatientId,
  3783. // Ctime: time.Now().Unix(),
  3784. // Mtime: 0,
  3785. // Status: 1,
  3786. // RecordTime: p.RecordDate,
  3787. // OrgId: p.UserOrgId,
  3788. // GoodId: p.ProjectId,
  3789. // GoodTypeId: 0,
  3790. // Count: parseIntCount,
  3791. // Type: 0,
  3792. // ProjectId: lastHisProject.ID,
  3793. // StorehouseId: 0,
  3794. // }
  3795. //
  3796. // service.CreateNewAutoDetail(detail, tx)
  3797. //
  3798. // //查询剩余库存
  3799. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3800. // var sum_count int64
  3801. // for _, item := range goodList {
  3802. // sum_count += item.StockCount
  3803. // }
  3804. //
  3805. // //更新剩余库存
  3806. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3807. //
  3808. // //耗材
  3809. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3810. //
  3811. // }
  3812. // //判断是否是零用耗材(零用但是是出库耗材)
  3813. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3814. //
  3815. // //查询历史出库数据
  3816. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3817. // var out_count int64
  3818. // for _, item := range flowGood {
  3819. // out_count += item.Count
  3820. // }
  3821. // //如果历史数和当前数据不想等才进行退库出库
  3822. // if out_count != parseIntCount {
  3823. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3824. //
  3825. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3826. // detail := models.AutomaticReduceDetail{
  3827. // WarehouseOutId: 0,
  3828. // WarehouseOutOrderNumber: "",
  3829. // PatientId: p.PatientId,
  3830. // Ctime: time.Now().Unix(),
  3831. // Mtime: 0,
  3832. // Status: 1,
  3833. // RecordTime: p.RecordDate,
  3834. // OrgId: p.UserOrgId,
  3835. // GoodId: p.ProjectId,
  3836. // GoodTypeId: 0,
  3837. // Count: parseIntCount,
  3838. // Type: 0,
  3839. // ProjectId: p.ID,
  3840. // StorehouseId: 0,
  3841. // }
  3842. //
  3843. // service.CreateNewAutoDetail(detail, tx)
  3844. //
  3845. // //查询剩余库存
  3846. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3847. // var sum_count int64
  3848. // for _, item := range goodList {
  3849. // sum_count += item.StockCount
  3850. // }
  3851. //
  3852. // //更新剩余库存
  3853. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3854. //
  3855. // //耗材
  3856. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3857. // }
  3858. //
  3859. // }
  3860. //
  3861. // }
  3862. //
  3863. //}
  3864. //记录日志
  3865. byterequest, _ := json.Marshal(p)
  3866. adviceLog := models.XtDoctorAdviceLog{
  3867. UserOrgId: p.UserOrgId,
  3868. PatientId: p.PatientId,
  3869. AdminUserId: adminInfo.AdminUser.Id,
  3870. Module: 1,
  3871. ErrLog: string(byterequest),
  3872. Status: 1,
  3873. Ctime: time.Now().Unix(),
  3874. Mtime: 0,
  3875. Source: "电脑端新建his项目",
  3876. RecordDate: p.RecordDate,
  3877. }
  3878. service.CreateDoctorAdviceLog(adviceLog)
  3879. projectList = append(projectList, p)
  3880. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3881. //新增或者编辑项目,修改对应的标签数据
  3882. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3883. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3884. var label models.HisLabelPrintInfo
  3885. project, _ := service.GetProjectDetail(p.ProjectId)
  3886. if project.CostClassify == 3 { //类别为检验检查
  3887. if p.TeamId > 0 { //检验检查组套
  3888. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3889. if tempLabel.ID == 0 {
  3890. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3891. label.Number = tempPrescription.PrescriptionNumber
  3892. label.ProjectId = project.ID
  3893. label.Status = 1
  3894. label.IsPrint = 2
  3895. label.DoctorId = info.DoctorId
  3896. label.UserOrgId = p.UserOrgId
  3897. label.PatientId = patient_id
  3898. label.RecordDate = recordDateTime
  3899. label.Ctime = time.Now().Unix()
  3900. label.Mtime = time.Now().Unix()
  3901. label.ItemId = p.TeamId
  3902. label.FeedetlSn = p.FeedetlSn
  3903. label.PProjectId = p.ID
  3904. label.ProjectName = team.ProjectTeam
  3905. label.PatientName = patient.Name
  3906. service.CreateNewHisLabelRecord(&label, tx)
  3907. }
  3908. } else { //单条检验检查项目
  3909. label.Number = tempPrescription.PrescriptionNumber
  3910. label.ProjectId = project.ID
  3911. label.Status = 1
  3912. label.DoctorId = info.DoctorId
  3913. label.UserOrgId = p.UserOrgId
  3914. label.PatientId = patient_id
  3915. label.RecordDate = recordDateTime
  3916. label.IsPrint = 2
  3917. label.Ctime = time.Now().Unix()
  3918. label.Mtime = time.Now().Unix()
  3919. label.FeedetlSn = p.FeedetlSn
  3920. label.PProjectId = p.ID
  3921. label.ItemId = p.TeamId
  3922. label.ProjectName = project.ProjectName
  3923. label.PatientName = patient.Name
  3924. service.CreateNewHisLabelRecord(&label, tx)
  3925. }
  3926. }
  3927. }
  3928. }
  3929. }
  3930. }
  3931. }
  3932. if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  3933. //耗材出库
  3934. if p.Type == 3 {
  3935. //对比当前数据和历史出库数据
  3936. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3937. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3938. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3939. //如果当前处方数量大于历史数据,则需要出库
  3940. if nowCount > historyCount {
  3941. var cha_count int64
  3942. cha_count = nowCount - historyCount
  3943. timeStr := time.Now().Format("2006-01-02")
  3944. timeArr := strings.Split(timeStr, "-")
  3945. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3946. total = total + 1
  3947. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3948. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3949. number = number + total
  3950. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3951. operation_time := time.Now().Unix()
  3952. creater := c.GetAdminUserInfo().AdminUser.Id
  3953. recordDateStr := time.Now().Format("2006-01-02")
  3954. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3955. nowtime := recordDate.Unix()
  3956. warehouseOut := models.WarehouseOut{
  3957. WarehouseOutOrderNumber: warehousing_out_order,
  3958. OperationTime: operation_time,
  3959. OrgId: adminInfo.CurrentOrgId,
  3960. Creater: creater,
  3961. Ctime: time.Now().Unix(),
  3962. Status: 1,
  3963. WarehouseOutTime: nowtime,
  3964. Type: 1,
  3965. StorehouseId: storeConfig.StorehouseOutInfo,
  3966. IsCheck: 1,
  3967. IsSys: 1,
  3968. }
  3969. //查询是否生成出库单
  3970. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3971. if out.ID == 0 {
  3972. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3973. }
  3974. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3975. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3976. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3977. dialyPrepareOne := models.DialysisBeforePrepare{
  3978. GoodTypeId: goodObj.GoodTypeId,
  3979. GoodId: p.ProjectId,
  3980. PatientId: p.PatientId,
  3981. RecordDate: p.RecordDate,
  3982. UserOrgId: adminInfo.CurrentOrgId,
  3983. Count: cha_count,
  3984. Ctime: time.Now().Unix(),
  3985. Creater: creater,
  3986. Status: 1,
  3987. StorehouseId: houseConfig.StorehouseOutInfo,
  3988. ProjectId: p.ID,
  3989. }
  3990. //出库
  3991. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3992. }
  3993. //如果当前处方数量小于历史数据,怎需要退库
  3994. if nowCount < historyCount {
  3995. var cha_count int64
  3996. cha_count = historyCount - nowCount
  3997. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3998. creater := c.GetAdminUserInfo().AdminUser.Id
  3999. newPrescriptionProject := &models.HisPrescriptionProject{
  4000. ID: p.ID,
  4001. ProjectId: p.ProjectId,
  4002. Price: p.Price,
  4003. UserOrgId: p.UserOrgId,
  4004. Status: 1,
  4005. Ctime: time.Now().Unix(),
  4006. Mtime: time.Now().Unix(),
  4007. PatientId: p.PatientId,
  4008. HisPatientId: p.HisPatientId,
  4009. RecordDate: p.RecordDate,
  4010. PrescriptionId: p.PrescriptionId,
  4011. Count: p.Count,
  4012. FeedetlSn: p.FeedetlSn,
  4013. MedListCodg: p.MedListCodg,
  4014. SingleDose: p.SingleDose,
  4015. DeliveryWay: p.DeliveryWay,
  4016. ExecutionFrequency: p.ExecutionFrequency,
  4017. Day: p.Day,
  4018. HisProject: models.HisProject{},
  4019. GoodInfo: models.GoodInfo{},
  4020. Remark: p.Remark,
  4021. Unit: p.Unit,
  4022. Type: p.Type,
  4023. Doctor: p.Doctor,
  4024. ExecutionTime: p.ExecutionTime,
  4025. ExecutionStaff: p.ExecutionStaff,
  4026. ExecutionState: p.ExecutionState,
  4027. CheckTime: p.CheckTime,
  4028. CheckState: p.CheckState,
  4029. Checker: p.Checker,
  4030. StartTime: p.StartTime,
  4031. TeamId: p.TeamId,
  4032. XtHisProjectTeam: models.XtHisProjectTeam{},
  4033. FrequencyType: p.FrequencyType,
  4034. DayCount: p.DayCount,
  4035. WeekDay: p.WeekDay,
  4036. IsCheckTeam: p.IsCheckTeam,
  4037. HisOrderInfo: models.HisOrderInfo{},
  4038. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4039. IsOut: p.IsOut,
  4040. YbSyncStatus: p.YbSyncStatus,
  4041. }
  4042. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4043. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4044. }
  4045. if nowCount == historyCount {
  4046. if historyCount == 0 {
  4047. recordDateStr := time.Now().Format("2006-01-02")
  4048. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4049. nowtime := recordDate.Unix()
  4050. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4051. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4052. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4053. creater := c.GetAdminUserInfo().AdminUser.Id
  4054. dialyPrepareOne := models.DialysisBeforePrepare{
  4055. GoodTypeId: goodObj.GoodTypeId,
  4056. GoodId: p.ProjectId,
  4057. PatientId: p.PatientId,
  4058. RecordDate: p.RecordDate,
  4059. UserOrgId: adminInfo.CurrentOrgId,
  4060. Count: nowCount,
  4061. Ctime: time.Now().Unix(),
  4062. Creater: creater,
  4063. Status: 1,
  4064. StorehouseId: houseConfig.StorehouseOutInfo,
  4065. ProjectId: p.ID,
  4066. }
  4067. //出库
  4068. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4069. }
  4070. }
  4071. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4072. //查询历史出库数据
  4073. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4074. var out_count_five int64
  4075. for _, item := range flowGood {
  4076. out_count_five += item.Count
  4077. }
  4078. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4079. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4080. if out_count_five != parseIntCount {
  4081. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4082. detail := models.AutomaticReduceDetail{
  4083. WarehouseOutId: 0,
  4084. WarehouseOutOrderNumber: "",
  4085. PatientId: p.PatientId,
  4086. Ctime: time.Now().Unix(),
  4087. Mtime: 0,
  4088. Status: 1,
  4089. RecordTime: p.RecordDate,
  4090. OrgId: p.UserOrgId,
  4091. GoodId: p.ProjectId,
  4092. GoodTypeId: 0,
  4093. Count: parseIntCount,
  4094. Type: 0,
  4095. ProjectId: lastHisProject.ID,
  4096. StorehouseId: 0,
  4097. }
  4098. service.CreateNewAutoDetail(detail, tx)
  4099. }
  4100. // //查询耗材最后一次出库记录
  4101. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4102. // //查询默认出库仓库库存
  4103. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4104. // if len(wareOut) > 0 {
  4105. //
  4106. // for _, it := range wareOut {
  4107. // //回退库存
  4108. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4109. //
  4110. // //删除出库记录
  4111. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4112. //
  4113. // }
  4114. // }
  4115. //
  4116. // timeStr := time.Now().Format("2006-01-02")
  4117. // timeArr := strings.Split(timeStr, "-")
  4118. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4119. //
  4120. // total = total + 1
  4121. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4122. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4123. // number = number + total
  4124. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4125. //
  4126. // operation_time := time.Now().Unix()
  4127. // creater := c.GetAdminUserInfo().AdminUser.Id
  4128. //
  4129. // recordDateStr := time.Now().Format("2006-01-02")
  4130. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4131. // nowtime := recordDate.Unix()
  4132. // warehouseOut := models.WarehouseOut{
  4133. // WarehouseOutOrderNumber: warehousing_out_order,
  4134. // OperationTime: operation_time,
  4135. // OrgId: adminInfo.CurrentOrgId,
  4136. // Creater: creater,
  4137. // Ctime: time.Now().Unix(),
  4138. // Status: 1,
  4139. // WarehouseOutTime: nowtime,
  4140. // Type: 1,
  4141. // StorehouseId: storeConfig.StorehouseOutInfo,
  4142. // IsCheck: 1,
  4143. // IsSys: 1,
  4144. // }
  4145. // //查询是否生成出库单
  4146. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4147. // if out.ID == 0 {
  4148. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4149. // }
  4150. //
  4151. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4152. //
  4153. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4154. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4155. //
  4156. // dialyPrepareOne := models.DialysisBeforePrepare{
  4157. // GoodTypeId: goodObj.GoodTypeId,
  4158. // GoodId: p.ProjectId,
  4159. // PatientId: p.PatientId,
  4160. // RecordDate: p.RecordDate,
  4161. // UserOrgId: adminInfo.CurrentOrgId,
  4162. // Count: parseIntCount,
  4163. // Ctime: time.Now().Unix(),
  4164. // Creater: creater,
  4165. // Status: 1,
  4166. // StorehouseId: houseConfig.StorehouseOutInfo,
  4167. // ProjectId: lastHisProject.ID,
  4168. // }
  4169. // //判断是否是零用耗材(非零用)
  4170. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4171. //
  4172. // //查询历史出库数据
  4173. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4174. // var out_count int64
  4175. // for _, item := range flowGood {
  4176. // out_count += item.Count
  4177. // }
  4178. // //如果历史数和当前数据不想等才进行退库出库
  4179. // if out_count != parseIntCount {
  4180. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4181. //
  4182. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4183. // detail := models.AutomaticReduceDetail{
  4184. // WarehouseOutId: 0,
  4185. // WarehouseOutOrderNumber: "",
  4186. // PatientId: p.PatientId,
  4187. // Ctime: time.Now().Unix(),
  4188. // Mtime: 0,
  4189. // Status: 1,
  4190. // RecordTime: p.RecordDate,
  4191. // OrgId: p.UserOrgId,
  4192. // GoodId: p.ProjectId,
  4193. // GoodTypeId: 0,
  4194. // Count: parseIntCount,
  4195. // Type: 0,
  4196. // ProjectId: lastHisProject.ID,
  4197. // StorehouseId: 0,
  4198. // }
  4199. //
  4200. // service.CreateNewAutoDetail(detail, tx)
  4201. //
  4202. // //查询剩余库存
  4203. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4204. // var sum_count int64
  4205. // for _, item := range goodList {
  4206. // sum_count += item.StockCount
  4207. // }
  4208. //
  4209. // //更新剩余库存
  4210. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4211. //
  4212. // //耗材
  4213. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4214. //
  4215. // }
  4216. // //判断是否是零用耗材(零用但是是出库耗材)
  4217. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4218. //
  4219. // //查询历史出库数据
  4220. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4221. // var out_count int64
  4222. // for _, item := range flowGood {
  4223. // out_count += item.Count
  4224. // }
  4225. // //如果历史数和当前数据不想等才进行退库出库
  4226. // if out_count != parseIntCount {
  4227. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4228. //
  4229. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4230. // detail := models.AutomaticReduceDetail{
  4231. // WarehouseOutId: 0,
  4232. // WarehouseOutOrderNumber: "",
  4233. // PatientId: p.PatientId,
  4234. // Ctime: time.Now().Unix(),
  4235. // Mtime: 0,
  4236. // Status: 1,
  4237. // RecordTime: p.RecordDate,
  4238. // OrgId: p.UserOrgId,
  4239. // GoodId: p.ProjectId,
  4240. // GoodTypeId: 0,
  4241. // Count: parseIntCount,
  4242. // Type: 0,
  4243. // ProjectId: p.ID,
  4244. // StorehouseId: 0,
  4245. // }
  4246. //
  4247. // service.CreateNewAutoDetail(detail, tx)
  4248. //
  4249. // //查询剩余库存
  4250. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4251. // var sum_count int64
  4252. // for _, item := range goodList {
  4253. // sum_count += item.StockCount
  4254. // }
  4255. //
  4256. // //更新剩余库存
  4257. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4258. //
  4259. // //耗材
  4260. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4261. // }
  4262. //
  4263. // }
  4264. //
  4265. // }
  4266. //
  4267. //}
  4268. //记录日志
  4269. byterequest, _ := json.Marshal(p)
  4270. adviceLog := models.XtDoctorAdviceLog{
  4271. UserOrgId: p.UserOrgId,
  4272. PatientId: p.PatientId,
  4273. AdminUserId: adminInfo.AdminUser.Id,
  4274. Module: 1,
  4275. ErrLog: string(byterequest),
  4276. Status: 1,
  4277. Ctime: time.Now().Unix(),
  4278. Mtime: 0,
  4279. Source: "电脑端新建his项目",
  4280. RecordDate: p.RecordDate,
  4281. }
  4282. service.CreateDoctorAdviceLog(adviceLog)
  4283. projectList = append(projectList, p)
  4284. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4285. //新增或者编辑项目,修改对应的标签数据
  4286. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4287. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4288. var label models.HisLabelPrintInfo
  4289. project, _ := service.GetProjectDetail(p.ProjectId)
  4290. if project.CostClassify == 3 { //类别为检验检查
  4291. if p.TeamId > 0 { //检验检查组套
  4292. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4293. if tempLabel.ID == 0 {
  4294. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4295. label.Number = tempPrescription.PrescriptionNumber
  4296. label.ProjectId = project.ID
  4297. label.Status = 1
  4298. label.IsPrint = 2
  4299. label.DoctorId = info.DoctorId
  4300. label.UserOrgId = p.UserOrgId
  4301. label.PatientId = patient_id
  4302. label.RecordDate = recordDateTime
  4303. label.Ctime = time.Now().Unix()
  4304. label.Mtime = time.Now().Unix()
  4305. label.ItemId = p.TeamId
  4306. label.FeedetlSn = p.FeedetlSn
  4307. label.PProjectId = p.ID
  4308. label.ProjectName = team.ProjectTeam
  4309. label.PatientName = patient.Name
  4310. service.CreateNewHisLabelRecord(&label, tx)
  4311. }
  4312. } else { //单条检验检查项目
  4313. label.Number = tempPrescription.PrescriptionNumber
  4314. label.ProjectId = project.ID
  4315. label.Status = 1
  4316. label.DoctorId = info.DoctorId
  4317. label.UserOrgId = p.UserOrgId
  4318. label.PatientId = patient_id
  4319. label.RecordDate = recordDateTime
  4320. label.IsPrint = 2
  4321. label.Ctime = time.Now().Unix()
  4322. label.Mtime = time.Now().Unix()
  4323. label.FeedetlSn = p.FeedetlSn
  4324. label.PProjectId = p.ID
  4325. label.ItemId = p.TeamId
  4326. label.ProjectName = project.ProjectName
  4327. label.PatientName = patient.Name
  4328. service.CreateNewHisLabelRecord(&label, tx)
  4329. }
  4330. }
  4331. }
  4332. }
  4333. }
  4334. }
  4335. }
  4336. //插入检验数据
  4337. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4338. //新增或者编辑项目,修改对应的标签数据
  4339. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4340. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4341. var label models.HisLabelPrintInfo
  4342. project, _ := service.GetProjectDetail(p.ProjectId)
  4343. if project.CostClassify == 3 { //类别为检验检查
  4344. if p.TeamId > 0 { //检验检查组套
  4345. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4346. if tempLabel.ID == 0 {
  4347. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4348. label.Number = tempPrescription.PrescriptionNumber
  4349. label.ProjectId = project.ID
  4350. label.Status = 1
  4351. label.IsPrint = 2
  4352. label.DoctorId = info.DoctorId
  4353. label.UserOrgId = p.UserOrgId
  4354. label.PatientId = patient_id
  4355. label.RecordDate = recordDateTime
  4356. label.Ctime = time.Now().Unix()
  4357. label.Mtime = time.Now().Unix()
  4358. label.ItemId = p.TeamId
  4359. label.FeedetlSn = p.FeedetlSn
  4360. label.PProjectId = p.ID
  4361. label.ProjectName = team.ProjectTeam
  4362. label.PatientName = patient.Name
  4363. service.CreateHisLabelRecord(&label)
  4364. }
  4365. } else { //单条检验检查项目
  4366. label.Number = tempPrescription.PrescriptionNumber
  4367. label.ProjectId = project.ID
  4368. label.Status = 1
  4369. label.DoctorId = info.DoctorId
  4370. label.UserOrgId = p.UserOrgId
  4371. label.PatientId = patient_id
  4372. label.RecordDate = recordDateTime
  4373. label.IsPrint = 2
  4374. label.Ctime = time.Now().Unix()
  4375. label.Mtime = time.Now().Unix()
  4376. label.FeedetlSn = p.FeedetlSn
  4377. label.PProjectId = p.ID
  4378. label.ItemId = p.TeamId
  4379. label.ProjectName = project.ProjectName
  4380. label.PatientName = patient.Name
  4381. service.CreateHisLabelRecord(&label)
  4382. }
  4383. }
  4384. }
  4385. }
  4386. service.CreateNewHisProjectTwo(&p, tx)
  4387. var randNum int
  4388. randNum = rand.Intn(10000) + 1000
  4389. timestamp := time.Now().Unix()
  4390. tempTime := time.Unix(timestamp, 0)
  4391. timeFormat := tempTime.Format("20060102150405")
  4392. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4393. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4394. if goodBase.ID > 0 {
  4395. tx.Rollback()
  4396. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4397. return
  4398. }
  4399. service.CreateNewHisProjectTwo(&p, tx)
  4400. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4401. //查询剩余库存
  4402. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4403. var sum_count int64
  4404. for _, item := range goodList {
  4405. sum_count += item.StockCount
  4406. }
  4407. //更新剩余库存
  4408. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4409. //耗材
  4410. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4411. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4412. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4413. if len(outInfoTwo) > 0 {
  4414. for _, item := range outInfoTwo {
  4415. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4416. }
  4417. }
  4418. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4419. if len(drugAutoDetail) > 0 {
  4420. for _, item := range drugAutoDetail {
  4421. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4422. }
  4423. }
  4424. tx.Commit()
  4425. }
  4426. }
  4427. }
  4428. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4429. // addition := items["addition"].([]interface{})
  4430. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4431. // ctime := time.Now().Unix()
  4432. // mtime := ctime
  4433. // if len(addition) > 0 {
  4434. // for _, item := range addition {
  4435. // var s models.HisAdditionalCharge
  4436. // s.PrescriptionId = tempPrescription.ID
  4437. // s.Status = 1
  4438. // s.UserOrgId = adminInfo.CurrentOrgId
  4439. // s.RecordDate = recordDateTime
  4440. // s.CreatedTime = ctime
  4441. // s.UpdatedTime = mtime
  4442. // s.PatientId = patient_id
  4443. // s.HisPatientId = his_patient_id
  4444. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4445. // if errcode > 0 {
  4446. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4447. // return
  4448. // }
  4449. // service.CreateAdditionalCharge(&s)
  4450. // var randNum int
  4451. // randNum = rand.Intn(10000) + 1000
  4452. // timestamp := time.Now().Unix()
  4453. // tempTime := time.Unix(timestamp, 0)
  4454. // timeFormat := tempTime.Format("20060102150405")
  4455. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4456. // service.CreateAdditionalCharge(&s)
  4457. //
  4458. // }
  4459. // }
  4460. //}
  4461. }
  4462. }
  4463. }
  4464. tx.Commit()
  4465. if err == nil {
  4466. c.ServeSuccessJSON(map[string]interface{}{
  4467. "msg": "保存成功",
  4468. })
  4469. return
  4470. } else {
  4471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4472. return
  4473. }
  4474. } else {
  4475. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4476. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4477. var tempPrescription *models.HisPrescription
  4478. if len(prescriptions) > 0 {
  4479. for _, item := range prescriptions {
  4480. items := item.(map[string]interface{})
  4481. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4482. utils.ErrorLog("id")
  4483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4484. return
  4485. }
  4486. id := int64(items["id"].(float64))
  4487. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4488. tempPrescription = &new_prescription
  4489. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4490. utils.ErrorLog("type")
  4491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4492. return
  4493. }
  4494. types := int64(items["type"].(float64))
  4495. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4496. utils.ErrorLog("med_type")
  4497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4498. return
  4499. }
  4500. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4501. if med_type == "0" {
  4502. med_type = "14"
  4503. }
  4504. //if order_status == 0 {
  4505. // order_status = 1
  4506. //}
  4507. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4508. // utils.ErrorLog("diagnoses")
  4509. //}
  4510. diagnoses, _ := items["diagnoses"].(string)
  4511. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4512. utils.ErrorLog("pre_time")
  4513. }
  4514. preTime, _ := items["pre_time"].(string)
  4515. timeLayout := "2006-01-02"
  4516. loc, _ := time.LoadLocation("Local")
  4517. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4518. //result := strings.Split(preTime, " ")
  4519. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4520. if err != nil {
  4521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4522. return
  4523. }
  4524. pTime := theTime2.Unix()
  4525. ctime := time.Now().Unix()
  4526. if tempPrescription.ID == 0 {
  4527. prescription := &models.HisPrescription{
  4528. ID: 0,
  4529. PatientId: patient_id,
  4530. UserOrgId: adminInfo.CurrentOrgId,
  4531. RecordDate: recordDateTime,
  4532. Ctime: ctime,
  4533. Mtime: ctime,
  4534. Type: types,
  4535. Modifier: adminInfo.AdminUser.Id,
  4536. Creator: adminInfo.AdminUser.Id,
  4537. Status: 1,
  4538. Doctor: role.UserName,
  4539. HisPatientId: his_patient_id,
  4540. OrderStatus: 1,
  4541. BatchNumber: "",
  4542. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4543. PreTime: pTime,
  4544. PType: p_type,
  4545. MedType: med_type,
  4546. Diagnose: diagnoses,
  4547. }
  4548. tempPrescription = prescription
  4549. service.SaveHisPrescription(tempPrescription)
  4550. redis := service.RedisClient()
  4551. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4552. redis.Set(key, "", time.Second)
  4553. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4554. redis.Set(keyOne, "", time.Second)
  4555. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4556. redis.Set(keySeven, "", time.Second)
  4557. defer redis.Close()
  4558. } else {
  4559. tempPrescription.ID = id
  4560. tempPrescription.Type = types
  4561. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4562. tempPrescription.Mtime = time.Now().Unix()
  4563. tempPrescription.Doctor = role.UserName
  4564. //tempPrescription.OrderStatus = order_status
  4565. tempPrescription.PreTime = pTime
  4566. tempPrescription.MedType = med_type
  4567. tempPrescription.Diagnose = diagnoses
  4568. service.SaveHisPrescription(tempPrescription)
  4569. redis := service.RedisClient()
  4570. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4571. redis.Set(key, "", time.Second)
  4572. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4573. redis.Set(keyOne, "", time.Second)
  4574. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4575. redis.Set(keySeven, "", time.Second)
  4576. defer redis.Close()
  4577. }
  4578. //service.SaveHisPrescription(prescription)
  4579. //更改患者挂号状态
  4580. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4581. fmt.Println("更改失败", err2)
  4582. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4583. advices := items["advices"].([]interface{})
  4584. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4585. groupNo := int64(0)
  4586. if len(advices) > 0 {
  4587. for _, advice := range advices {
  4588. var s models.HisDoctorAdviceInfo
  4589. s.PrescriptionId = tempPrescription.ID
  4590. s.AdviceType = 2
  4591. s.AdviceDoctor = doctor_id
  4592. s.StopState = 2
  4593. s.ExecutionState = 2
  4594. s.AdviceDate = theTime3.Unix()
  4595. s.Status = 1
  4596. s.UserOrgId = adminInfo.CurrentOrgId
  4597. s.RecordDate = theTime3.Unix()
  4598. s.StartTime = tempPrescription.PreTime
  4599. s.Groupno = groupNo
  4600. s.PatientId = patient_id
  4601. s.HisPatientId = his_patient_id
  4602. s.StartTime = pTime
  4603. s.IsSettle = 2
  4604. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4605. if errcode > 0 {
  4606. c.ServeFailJSONWithSGJErrorCode(errcode)
  4607. return
  4608. }
  4609. s.StartTime = pTime
  4610. var total_count int64 //处方总库存
  4611. //查询改药品信息
  4612. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  4613. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  4614. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4615. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4616. total_count += prescribingNumberSeven * medical.MinNumber
  4617. }
  4618. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4619. total_count += prescribingNumberSeven
  4620. }
  4621. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4622. total_count += prescribingNumberSeven
  4623. }
  4624. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4625. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4626. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4627. if s.Price != lastWarehouse.RetailPrice {
  4628. s.Price = lastWarehouse.RetailPrice
  4629. }
  4630. if s.Price == 0 {
  4631. if lastWarehouse.ID == 0 {
  4632. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4633. s.Price = lastWarehouseTwo.RetailPrice
  4634. }
  4635. }
  4636. }
  4637. if adminInfo.CurrentOrgId != 10206 {
  4638. if s.ID == 0 {
  4639. //查询改药品是否已经停用
  4640. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4641. if base.ID > 0 {
  4642. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4643. return
  4644. }
  4645. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4646. if drugMedical.SumCount == 0 {
  4647. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4648. return
  4649. }
  4650. }
  4651. }
  4652. //赤峰
  4653. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4654. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4655. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4656. if info.RetailPrice > 0 {
  4657. if s.DeliveryWay == "口服" {
  4658. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4659. s.Price = drug.RetailPrice
  4660. }
  4661. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4662. s.Price = info.RetailPrice
  4663. }
  4664. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4665. s.Price = info.RetailPrice
  4666. }
  4667. }
  4668. }
  4669. }
  4670. service.CreateHisDoctorAdvice(&s)
  4671. //记录日志
  4672. byterequest, _ := json.Marshal(s)
  4673. adviceLog := models.XtDoctorAdviceLog{
  4674. UserOrgId: s.UserOrgId,
  4675. PatientId: s.PatientId,
  4676. AdminUserId: adminInfo.AdminUser.Id,
  4677. Module: 1,
  4678. ErrLog: string(byterequest),
  4679. Status: 1,
  4680. Ctime: time.Now().Unix(),
  4681. Mtime: 0,
  4682. Source: "电脑端新建his医嘱",
  4683. RecordDate: s.AdviceDate,
  4684. }
  4685. service.CreateDoctorAdviceLog(adviceLog)
  4686. //存储切片中
  4687. adviceList = append(adviceList, s)
  4688. redis := service.RedisClient()
  4689. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4690. redis.Set(key, "", time.Second)
  4691. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4692. redis.Set(keyOne, "", time.Second)
  4693. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4694. redis.Set(keySeven, "", time.Second)
  4695. var randNum int
  4696. randNum = rand.Intn(10000) + 1000
  4697. timestamp := time.Now().Unix()
  4698. tempTime := time.Unix(timestamp, 0)
  4699. timeFormat := tempTime.Format("20060102150405")
  4700. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4701. service.CreateHisDoctorAdvice(&s)
  4702. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4703. redis.Set(keySix, "", time.Second)
  4704. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4705. redis.Set(keyFive, "", time.Second)
  4706. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4707. redis.Set(keyEight, "", time.Second)
  4708. defer redis.Close()
  4709. }
  4710. }
  4711. }
  4712. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4713. projects := items["project"].([]interface{})
  4714. if len(projects) > 0 {
  4715. for _, project := range projects {
  4716. var p models.HisPrescriptionProject
  4717. p.PrescriptionId = tempPrescription.ID
  4718. p.PatientId = patient_id
  4719. p.RecordDate = theTime3.Unix()
  4720. p.Doctor = doctor_id
  4721. p.UserOrgId = adminInfo.CurrentOrgId
  4722. p.HisPatientId = his_patient_id
  4723. p.Status = 1
  4724. p.StartTime = pTime
  4725. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4726. if errcode > 0 {
  4727. c.ServeFailJSONWithSGJErrorCode(errcode)
  4728. return
  4729. }
  4730. if p.ID == 0 {
  4731. p.IsOut = 2
  4732. }
  4733. if p.ID > 0 {
  4734. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4735. p.IsOut = projectDetail.IsOut
  4736. }
  4737. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4738. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4739. if p.Type == 3 {
  4740. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4741. if p.Price != lastWarehouse.PackingPrice {
  4742. p.Price = lastWarehouse.PackingPrice
  4743. }
  4744. if p.Price == 0 {
  4745. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4746. p.Price = lastWarehouseTwo.PackingPrice
  4747. }
  4748. if p.Unit == "" {
  4749. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4750. p.Unit = goodInfoOne.PackingUnit
  4751. }
  4752. }
  4753. }
  4754. if adminInfo.CurrentOrgId != 10206 {
  4755. if p.Type == 3 {
  4756. if p.ID == 0 {
  4757. //查询该耗材是否停用
  4758. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4759. //表示该耗材已经停用,不能保存
  4760. if goodInfoSeven.ID == 0 {
  4761. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4762. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4763. return
  4764. }
  4765. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4766. if goodInfoOne.SumCount == 0 {
  4767. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4768. return
  4769. }
  4770. }
  4771. }
  4772. }
  4773. service.CreateHisProjectTwo(&p)
  4774. //记录日志
  4775. byterequest, _ := json.Marshal(p)
  4776. adviceLog := models.XtDoctorAdviceLog{
  4777. UserOrgId: p.UserOrgId,
  4778. PatientId: p.PatientId,
  4779. AdminUserId: adminInfo.AdminUser.Id,
  4780. Module: 1,
  4781. ErrLog: string(byterequest),
  4782. Status: 1,
  4783. Ctime: time.Now().Unix(),
  4784. Mtime: 0,
  4785. Source: "电脑端新建his项目",
  4786. RecordDate: p.RecordDate,
  4787. }
  4788. service.CreateDoctorAdviceLog(adviceLog)
  4789. projectList = append(projectList, p)
  4790. var randNum int
  4791. randNum = rand.Intn(10000) + 1000
  4792. timestamp := time.Now().Unix()
  4793. tempTime := time.Unix(timestamp, 0)
  4794. timeFormat := tempTime.Format("20060102150405")
  4795. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4796. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4797. //新增或者编辑项目,修改对应的标签数据
  4798. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4799. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4800. var label models.HisLabelPrintInfo
  4801. project, _ := service.GetProjectDetail(p.ProjectId)
  4802. if project.CostClassify == 3 { //类别为检验检查
  4803. if p.TeamId > 0 { //检验检查组套
  4804. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4805. if tempLabel.ID == 0 {
  4806. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4807. label.Number = tempPrescription.PrescriptionNumber
  4808. label.ProjectId = project.ID
  4809. label.Status = 1
  4810. label.IsPrint = 2
  4811. label.DoctorId = info.DoctorId
  4812. label.UserOrgId = p.UserOrgId
  4813. label.PatientId = patient_id
  4814. label.RecordDate = recordDateTime
  4815. label.Ctime = time.Now().Unix()
  4816. label.Mtime = time.Now().Unix()
  4817. label.ItemId = p.TeamId
  4818. label.FeedetlSn = p.FeedetlSn
  4819. label.PProjectId = p.ID
  4820. label.ProjectName = team.ProjectTeam
  4821. label.PatientName = patient.Name
  4822. service.CreateHisLabelRecord(&label)
  4823. }
  4824. } else { //单条检验检查项目
  4825. label.Number = tempPrescription.PrescriptionNumber
  4826. label.ProjectId = project.ID
  4827. label.Status = 1
  4828. label.DoctorId = info.DoctorId
  4829. label.UserOrgId = p.UserOrgId
  4830. label.PatientId = patient_id
  4831. label.RecordDate = recordDateTime
  4832. label.IsPrint = 2
  4833. label.Ctime = time.Now().Unix()
  4834. label.Mtime = time.Now().Unix()
  4835. label.FeedetlSn = p.FeedetlSn
  4836. label.PProjectId = p.ID
  4837. label.ItemId = p.TeamId
  4838. label.ProjectName = project.ProjectName
  4839. label.PatientName = patient.Name
  4840. service.CreateHisLabelRecord(&label)
  4841. }
  4842. }
  4843. }
  4844. }
  4845. service.SaveHisProjectTwo(&p)
  4846. }
  4847. }
  4848. }
  4849. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4850. // addition := items["addition"].([]interface{})
  4851. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4852. // ctime := time.Now().Unix()
  4853. // mtime := ctime
  4854. // if len(addition) > 0 {
  4855. // for _, item := range addition {
  4856. // var s models.HisAdditionalCharge
  4857. // s.PrescriptionId = tempPrescription.ID
  4858. // s.Status = 1
  4859. // s.UserOrgId = adminInfo.CurrentOrgId
  4860. // s.RecordDate = recordDateTime
  4861. // s.CreatedTime = ctime
  4862. // s.UpdatedTime = mtime
  4863. // s.PatientId = patient_id
  4864. // s.HisPatientId = his_patient_id
  4865. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4866. // if errcode > 0 {
  4867. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4868. // return
  4869. // }
  4870. // service.CreateAdditionalCharge(&s)
  4871. // var randNum int
  4872. // randNum = rand.Intn(10000) + 1000
  4873. // timestamp := time.Now().Unix()
  4874. // tempTime := time.Unix(timestamp, 0)
  4875. // timeFormat := tempTime.Format("20060102150405")
  4876. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4877. // service.CreateAdditionalCharge(&s)
  4878. //
  4879. // }
  4880. // }
  4881. //}
  4882. }
  4883. }
  4884. //查询今日该患者开的药品处方
  4885. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4886. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4887. //药品出库
  4888. if drugOutConfig.IsOpen == 1 {
  4889. for _, item := range hisdoctorlist {
  4890. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4891. // 查询该药品最后一次出库记录
  4892. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4893. if len(druginfo) > 0 {
  4894. //回退库存
  4895. for _, it := range druginfo {
  4896. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4897. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4898. }
  4899. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4900. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4901. }
  4902. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4903. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4904. }
  4905. }
  4906. }
  4907. //删除记录
  4908. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4909. //查询最后一次数据
  4910. if drugOutConfig.IsOpen == 1 {
  4911. //出库
  4912. if drug.IsUse == 2 {
  4913. creater := adminInfo.AdminUser.Id
  4914. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4915. }
  4916. //更新字典里面的库存
  4917. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4918. var sum_count int64
  4919. for _, its := range stockInfo {
  4920. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4921. if its.MaxUnit == baseDrug.MaxUnit {
  4922. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4923. }
  4924. sum_count += its.StockMaxNumber + its.StockMinNumber
  4925. }
  4926. //更新基础库存
  4927. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4928. //剩余库存
  4929. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4930. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4931. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4932. }
  4933. }
  4934. }
  4935. //耗材保存处方出库
  4936. if goodOutConfig.IsOpen == 1 {
  4937. //查询今日耗材出库数量
  4938. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4939. for _, item := range hisgoodlist {
  4940. //查询历史出库数据
  4941. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4942. var out_count_five int64
  4943. for _, item := range flowGood {
  4944. out_count_five += item.Count
  4945. }
  4946. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4947. if out_count_five != parseIntCount {
  4948. //查询耗材最后一次出库记录
  4949. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4950. //查询默认出库仓库库存
  4951. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4952. if len(wareOut) > 0 {
  4953. for _, it := range wareOut {
  4954. //回退库存
  4955. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4956. //删除出库记录
  4957. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4958. }
  4959. }
  4960. timeStr := time.Now().Format("2006-01-02")
  4961. timeArr := strings.Split(timeStr, "-")
  4962. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4963. total = total + 1
  4964. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4965. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4966. number = number + total
  4967. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4968. operation_time := time.Now().Unix()
  4969. creater := c.GetAdminUserInfo().AdminUser.Id
  4970. recordDateStr := time.Now().Format("2006-01-02")
  4971. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4972. nowtime := recordDate.Unix()
  4973. warehouseOut := models.WarehouseOut{
  4974. WarehouseOutOrderNumber: warehousing_out_order,
  4975. OperationTime: operation_time,
  4976. OrgId: adminInfo.CurrentOrgId,
  4977. Creater: creater,
  4978. Ctime: time.Now().Unix(),
  4979. Status: 1,
  4980. WarehouseOutTime: nowtime,
  4981. Type: 1,
  4982. StorehouseId: storeConfig.StorehouseOutInfo,
  4983. IsCheck: 1,
  4984. IsSys: 1,
  4985. }
  4986. //查询是否生成出库单
  4987. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4988. if out.ID == 0 {
  4989. service.AddSigleWarehouseOut(&warehouseOut)
  4990. }
  4991. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4992. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4993. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4994. dialyPrepareOne := models.DialysisBeforePrepare{
  4995. GoodTypeId: goodObj.GoodTypeId,
  4996. GoodId: item.ProjectId,
  4997. PatientId: item.PatientId,
  4998. RecordDate: item.RecordDate,
  4999. UserOrgId: adminInfo.CurrentOrgId,
  5000. Count: parseIntCount,
  5001. Ctime: time.Now().Unix(),
  5002. Creater: creater,
  5003. Status: 1,
  5004. StorehouseId: houseConfig.StorehouseOutInfo,
  5005. ProjectId: item.ID,
  5006. }
  5007. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5008. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5009. //查询历史出库数据
  5010. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5011. var out_count int64
  5012. for _, item := range flowGood {
  5013. out_count += item.Count
  5014. }
  5015. //如果历史数和当前数据不想等才进行退库出库
  5016. if out_count != parseIntCount {
  5017. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5018. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5019. detail := models.AutomaticReduceDetail{
  5020. WarehouseOutId: 0,
  5021. WarehouseOutOrderNumber: "",
  5022. PatientId: item.PatientId,
  5023. Ctime: time.Now().Unix(),
  5024. Mtime: 0,
  5025. Status: 1,
  5026. RecordTime: item.RecordDate,
  5027. OrgId: item.UserOrgId,
  5028. GoodId: item.ProjectId,
  5029. GoodTypeId: 0,
  5030. Count: parseIntCount,
  5031. Type: 0,
  5032. ProjectId: item.ID,
  5033. StorehouseId: 0,
  5034. }
  5035. service.CreateAutoDetail(detail)
  5036. //查询剩余库存
  5037. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5038. var sum_count int64
  5039. for _, item := range goodList {
  5040. sum_count += item.StockCount
  5041. }
  5042. //更新剩余库存
  5043. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5044. //耗材
  5045. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5046. }
  5047. }
  5048. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5049. //查询历史出库数据
  5050. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5051. var out_count int64
  5052. for _, item := range flowGood {
  5053. out_count += item.Count
  5054. }
  5055. //如果历史数和当前数据不想等才进行退库出库
  5056. if out_count != parseIntCount {
  5057. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5058. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5059. detail := models.AutomaticReduceDetail{
  5060. WarehouseOutId: 0,
  5061. WarehouseOutOrderNumber: "",
  5062. PatientId: item.PatientId,
  5063. Ctime: time.Now().Unix(),
  5064. Mtime: 0,
  5065. Status: 1,
  5066. RecordTime: item.RecordDate,
  5067. OrgId: item.UserOrgId,
  5068. GoodId: item.ProjectId,
  5069. GoodTypeId: 0,
  5070. Count: parseIntCount,
  5071. Type: 0,
  5072. ProjectId: item.ID,
  5073. StorehouseId: 0,
  5074. }
  5075. service.CreateAutoDetail(detail)
  5076. //查询剩余库存
  5077. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5078. var sum_count int64
  5079. for _, item := range goodList {
  5080. sum_count += item.StockCount
  5081. }
  5082. //更新剩余库存
  5083. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5084. //耗材
  5085. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5086. }
  5087. }
  5088. }
  5089. }
  5090. }
  5091. ////同步到自备药
  5092. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5093. if selfPrescriptionOpen.IsOpen == 1 {
  5094. timeStr := time.Now().Format("2006-01-02")
  5095. timeArr := strings.Split(timeStr, "-")
  5096. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5097. total = total + 1
  5098. operation_time := time.Now().Unix()
  5099. creater := adminInfo.AdminUser.Id
  5100. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5101. warehousing := models.XtSelfDrugWarehouse{
  5102. WarehousingOrder: warehousing_order,
  5103. OperationTime: operation_time,
  5104. OrgId: adminInfo.CurrentOrgId,
  5105. Creater: creater,
  5106. Ctime: time.Now().Unix(),
  5107. Status: 1,
  5108. WarehousingTime: recordDateTime,
  5109. Type: 0,
  5110. StorehouseId: 0,
  5111. IsCheck: 1,
  5112. PatientId: patient_id,
  5113. IsSys: 1,
  5114. }
  5115. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5116. if selfDrugWarehouse.ID == 0 {
  5117. service.AddSelfDrugWarehouse(&warehousing, tx)
  5118. }
  5119. if selfDrugWarehouse.ID > 0 {
  5120. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5121. }
  5122. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5123. fmt.Println(info)
  5124. for _, item := range hisdoctorlist {
  5125. //查询该病人的该药品是否已经入库
  5126. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5127. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5128. var in_count int64
  5129. if len(selfdruginfo) > 0 {
  5130. for _, item := range selfdruginfo {
  5131. var in_count_one int64
  5132. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5133. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5134. }
  5135. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5136. in_count_one = item.WarehousingCount
  5137. }
  5138. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5139. in_count_one = item.WarehousingCount
  5140. }
  5141. in_count += in_count_one
  5142. }
  5143. }
  5144. if selfBasedrug.IsSelfDrug == 1 {
  5145. var total_count int64
  5146. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5147. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5148. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5149. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5150. }
  5151. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5152. total_count += prescribingNumberSeven
  5153. }
  5154. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5155. total_count += prescribingNumberSeven
  5156. }
  5157. //入库
  5158. if total_count > in_count {
  5159. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5160. WarehousingOrder: warehousing_order,
  5161. WarehousingId: info.ID,
  5162. DrugId: item.DrugId,
  5163. Number: "",
  5164. ProductDate: 0,
  5165. ExpiryDate: 0,
  5166. WarehousingCount: total_count - in_count,
  5167. WarehouseingUnit: selfBasedrug.MinUnit,
  5168. Price: 0,
  5169. TotalPrice: 0,
  5170. Status: 1,
  5171. Ctime: time.Now().Unix(),
  5172. Remark: "",
  5173. OrgId: adminInfo.CurrentOrgId,
  5174. Type: 0,
  5175. Manufacturer: selfBasedrug.Manufacturer,
  5176. Dealer: selfBasedrug.Dealer,
  5177. StockMaxNumber: total_count - in_count,
  5178. RetailTotalPrice: 0,
  5179. BatchNumber: "",
  5180. MaxUnit: selfBasedrug.MinUnit,
  5181. MinUnit: selfBasedrug.MinUnit,
  5182. RetailPrice: 0,
  5183. StorehouseId: 0,
  5184. IsCheck: 1,
  5185. StockMinNumber: 0,
  5186. PatientId: patient_id,
  5187. IsSys: 1,
  5188. RecordDate: item.RecordDate,
  5189. AdviceId: item.ID,
  5190. }
  5191. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5192. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5193. Creator := adminInfo.AdminUser.Id
  5194. //查询默认仓库剩余多少库存
  5195. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5196. var sum_count int64
  5197. for _, it := range list {
  5198. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5199. if it.MaxUnit == baseDrug.MaxUnit {
  5200. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5201. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5202. }
  5203. sum_count += it.StockMaxNumber + it.StockMinNumber
  5204. }
  5205. flow := &models.XtSelfDrugFlow{
  5206. WarehousingId: info.ID,
  5207. DrugId: item.DrugId,
  5208. Number: "",
  5209. BatchNumber: "",
  5210. Count: total_count - in_count,
  5211. UserOrgId: adminInfo.CurrentOrgId,
  5212. PatientId: item.PatientId,
  5213. SystemTime: time.Now().Unix(),
  5214. ConsumableType: 1,
  5215. IsSys: 1,
  5216. WarehousingOrder: warehousing_order,
  5217. WarehouseOutId: 0,
  5218. WarehouseOutOrderNumber: "",
  5219. IsEdit: 0,
  5220. CancelStockId: 0,
  5221. CancelOrderNumber: "",
  5222. Manufacturer: selfBasedrug.Manufacturer,
  5223. Dealer: selfBasedrug.Dealer,
  5224. Creator: Creator,
  5225. UpdateCreator: Creator,
  5226. Status: 1,
  5227. Ctime: item.AdviceDate,
  5228. Mtime: 0,
  5229. Price: item.Price,
  5230. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5231. WarehouseOutDetailId: 0,
  5232. CancelOutDetailId: 0,
  5233. ExpireDate: 0,
  5234. ProductDate: 0,
  5235. MaxUnit: selfBasedrug.MinUnit,
  5236. MinUnit: selfBasedrug.MinUnit,
  5237. StorehouseId: 0,
  5238. OverCount: sum_count,
  5239. OperateTime: time.Now().Unix(),
  5240. AdviceId: item.ID,
  5241. }
  5242. service.CreateSelfDrugFlow(flow, tx)
  5243. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5244. var total_count int64 // 入库总数量
  5245. var over_count int64 //剩余库存
  5246. for _, it := range drugInfolist {
  5247. if it.MaxUnit == selfBasedrug.MaxUnit {
  5248. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5249. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5250. }
  5251. }
  5252. for _, it := range drugInfolist {
  5253. total_count += it.WarehousingCount
  5254. over_count += it.StockMaxNumber + it.StockMinNumber
  5255. }
  5256. //查询该仓库是否有默认数据
  5257. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5258. if selfDrugStock.ID == 0 {
  5259. drugStock := models.XtSelfDrugStockCount{
  5260. UserOrgId: item.UserOrgId,
  5261. PatientId: item.PatientId,
  5262. SumInCount: total_count,
  5263. SumOutCount: 0,
  5264. SumCancelCount: 0,
  5265. DrugId: item.DrugId,
  5266. Ctime: time.Now().Unix(),
  5267. Mtime: 0,
  5268. Status: 1,
  5269. FlushCount: over_count,
  5270. SumActOutCount: 0,
  5271. }
  5272. service.CreateSelfDrugStockSum(drugStock, tx)
  5273. }
  5274. if selfDrugStock.ID > 0 {
  5275. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5276. }
  5277. }
  5278. //查询这个单据的出库数量
  5279. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5280. var his_out_count int64
  5281. for _, item := range drugFlowList {
  5282. his_out_count += item.Count
  5283. }
  5284. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5285. if (total_count + his_out_count) <= in_count {
  5286. // 出库
  5287. if total_count < in_count {
  5288. var cha_count int64
  5289. cha_count = in_count - total_count
  5290. var stock_number int64 = 0
  5291. //查询库存是否充足
  5292. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5293. // 将该批次的剩余库存数量转换为拆零数量
  5294. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5295. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5296. }
  5297. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5298. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5299. }
  5300. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5301. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5302. }
  5303. if stock_number >= cha_count {
  5304. var maxNumber int64 = 0
  5305. var minNumber int64 = 0
  5306. maxNumber = cha_count / selfBasedrug.MinNumber
  5307. minNumber = cha_count % selfBasedrug.MinNumber
  5308. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5309. minNumber = maxNumber
  5310. }
  5311. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5312. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5314. return
  5315. }
  5316. }
  5317. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5318. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5319. }
  5320. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5321. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5322. }
  5323. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5324. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5325. }
  5326. if warehouse.StockMaxNumber < 0 {
  5327. warehouse.StockMaxNumber = 0
  5328. }
  5329. if warehouse.StockMinNumber < 0 {
  5330. warehouse.StockMinNumber = 0
  5331. }
  5332. warehouse.Mtime = time.Now().Unix()
  5333. if warehouse.StockMinNumber < minNumber {
  5334. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5335. if warehouse.MaxUnit != warehouse.MinUnit {
  5336. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5337. }
  5338. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5339. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5340. }
  5341. } else {
  5342. if minNumber > 0 {
  5343. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5344. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5345. }
  5346. }
  5347. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5348. if warehouse.StockMinNumber > 0 {
  5349. if warehouse.StockMinNumber-cha_count >= 0 {
  5350. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5351. }
  5352. }
  5353. }
  5354. }
  5355. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5356. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5357. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5358. }
  5359. }
  5360. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5361. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5363. return
  5364. }
  5365. }
  5366. if warehouse.StockMinNumber <= 0 {
  5367. warehouse.StockMinNumber = 0
  5368. }
  5369. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5370. //查询该药品剩余库存
  5371. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5372. var over_count int64
  5373. for _, its := range infolist {
  5374. if its.MaxUnit == selfBasedrug.MaxUnit {
  5375. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5376. }
  5377. over_count += its.StockMaxNumber + its.StockMinNumber
  5378. }
  5379. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5380. drugflow := models.XtSelfDrugFlow{
  5381. WarehouseOutId: 0,
  5382. WarehouseOutOrderNumber: warehousing_order,
  5383. WarehousingOrder: warehousing_order,
  5384. DrugId: item.DrugId,
  5385. Number: warehouse.Number,
  5386. ProductDate: warehouse.ProductDate,
  5387. ExpireDate: warehouse.ExpiryDate,
  5388. Count: cha_count,
  5389. Price: warehouse.RetailPrice,
  5390. Status: 1,
  5391. Ctime: item.AdviceDate,
  5392. Mtime: time.Now().Unix(),
  5393. UserOrgId: item.UserOrgId,
  5394. Manufacturer: warehouse.Manufacturer,
  5395. Dealer: warehouse.Dealer,
  5396. BatchNumber: warehouse.BatchNumber,
  5397. MaxUnit: selfBasedrug.MinUnit,
  5398. ConsumableType: 20,
  5399. IsEdit: 1,
  5400. Creator: 0,
  5401. IsSys: 3,
  5402. WarehouseOutDetailId: drugWareInfo.ID,
  5403. AdviceId: item.ID,
  5404. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5405. StorehouseId: 0,
  5406. AdminUserId: creater,
  5407. LastPrice: warehouse.Price,
  5408. StockCount: "",
  5409. WarehousingDetailId: 0,
  5410. OverCount: over_count,
  5411. RetailPrice: item.Price, //手动出库出库价格
  5412. WarehousingId: warehouse.ID,
  5413. SystemTime: item.AdviceDate,
  5414. PatientId: item.PatientId,
  5415. Remark: "保存处方入库数据差",
  5416. OperateTime: time.Now().Unix(),
  5417. }
  5418. if warehouse.RetailPrice == 0 {
  5419. drugflow.Price = item.Price
  5420. }
  5421. service.CreateSelfDrugFlowOne(drugflow, tx)
  5422. var out_count int64
  5423. out_count = in_count - total_count
  5424. //
  5425. //fmt.Println("in_count------------------", in_count)
  5426. //fmt.Println("total_count------------------", total_count)
  5427. //添加出库数量
  5428. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5429. //查询剩余库存
  5430. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5431. var sum_count int64
  5432. for _, its := range stockInfo {
  5433. if its.MaxUnit == selfBasedrug.MaxUnit {
  5434. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5435. }
  5436. sum_count += its.StockMaxNumber + its.StockMinNumber
  5437. }
  5438. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5439. } else {
  5440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5441. return
  5442. }
  5443. }
  5444. }
  5445. }
  5446. }
  5447. }
  5448. }
  5449. tx.Commit()
  5450. if err == nil {
  5451. c.ServeSuccessJSON(map[string]interface{}{
  5452. "msg": "保存成功",
  5453. })
  5454. return
  5455. } else {
  5456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5457. return
  5458. }
  5459. }
  5460. }
  5461. //func (c *HisApiController) EditHisPrescription() {
  5462. // record_date := c.GetString("record_date")
  5463. // patient_id, _ := c.GetInt64("patient_id")
  5464. // reg_type, _ := c.GetInt64("reg_type")
  5465. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5466. // diagnose := c.GetString("diagnose")
  5467. // sick_type, _ := c.GetInt64("sick_type")
  5468. // sick_history := c.GetString("sick_history")
  5469. // doctor_id, _ := c.GetInt64("doctor", 0)
  5470. // department, _ := c.GetInt64("department", 0)
  5471. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5472. // p_type, _ := c.GetInt64("p_type")
  5473. //
  5474. // dataBody := make(map[string]interface{}, 0)
  5475. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5476. // if err != nil {
  5477. // utils.ErrorLog(err.Error())
  5478. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5479. // return
  5480. // }
  5481. //
  5482. // timeLayout := "2006-01-02"
  5483. // loc, _ := time.LoadLocation("Local")
  5484. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5485. // if err != nil {
  5486. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5487. // return
  5488. // }
  5489. // adminInfo := c.GetAdminUserInfo()
  5490. // recordDateTime := theTime.Unix()
  5491. //
  5492. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5493. //
  5494. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5495. // var hpInfo models.HisPrescriptionInfo
  5496. // if info.ID == 0 {
  5497. // var randNum int
  5498. // randNum = rand.Intn(10000) + 1000
  5499. // timestamp := time.Now().Unix()
  5500. // tempTime := time.Unix(timestamp, 0)
  5501. // timeFormat := tempTime.Format("20060102150405")
  5502. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5503. //
  5504. // hpInfo = models.HisPrescriptionInfo{
  5505. // UserOrgId: adminInfo.CurrentOrgId,
  5506. // RecordDate: theTime.Unix(),
  5507. // PatientId: patient_id,
  5508. // Status: 1,
  5509. // Ctime: time.Now().Unix(),
  5510. // Mtime: time.Now().Unix(),
  5511. // Creator: adminInfo.AdminUser.Id,
  5512. // Modifier: adminInfo.AdminUser.Id,
  5513. // Diagnosis: diagnose,
  5514. // SickHistory: sick_history,
  5515. // Departments: department,
  5516. // RegisterType: reg_type,
  5517. // PrescriptionNumber: p_number,
  5518. // PrescriptionStatus: 1,
  5519. // Doctor: role.UserName,
  5520. // DoctorId: doctor_id,
  5521. // SickType: sick_type,
  5522. // PType: p_type,
  5523. // }
  5524. // service.SavePatientPrescriptionInfo(hpInfo)
  5525. //
  5526. // } else {
  5527. // hpInfo = models.HisPrescriptionInfo{
  5528. // ID: info.ID,
  5529. // UserOrgId: adminInfo.CurrentOrgId,
  5530. // RecordDate: info.RecordDate,
  5531. // PatientId: info.PatientId,
  5532. // Status: 1,
  5533. // Ctime: info.Ctime,
  5534. // Mtime: time.Now().Unix(),
  5535. // Creator: info.Creator,
  5536. // Modifier: adminInfo.AdminUser.Id,
  5537. // Diagnosis: diagnose,
  5538. // SickHistory: sick_history,
  5539. // Departments: department,
  5540. // RegisterType: reg_type,
  5541. // PrescriptionNumber: info.PrescriptionNumber,
  5542. // Doctor: role.UserName,
  5543. // PrescriptionStatus: info.PrescriptionStatus,
  5544. // DoctorId: doctor_id,
  5545. // SickType: sick_type,
  5546. // PType: info.PType,
  5547. // }
  5548. // service.SavePatientPrescriptionInfo(hpInfo)
  5549. // }
  5550. //
  5551. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5552. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5553. //
  5554. // if len(prescriptions) > 0 {
  5555. // for _, item := range prescriptions {
  5556. // items := item.(map[string]interface{})
  5557. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5558. // utils.ErrorLog("id")
  5559. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5560. // return
  5561. // }
  5562. // id := int64(items["id"].(float64))
  5563. //
  5564. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5565. // utils.ErrorLog("type")
  5566. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5567. // return
  5568. // }
  5569. // types := int64(items["type"].(float64))
  5570. //
  5571. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5572. // utils.ErrorLog("med_type")
  5573. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5574. // return
  5575. // }
  5576. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5577. //
  5578. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5579. //
  5580. // ctime := time.Now().Unix()
  5581. //
  5582. // prescription := &models.HisPrescription{
  5583. // ID: id,
  5584. // PatientId: patient_id,
  5585. // UserOrgId: adminInfo.CurrentOrgId,
  5586. // RecordDate: recordDateTime,
  5587. // Ctime: ctime,
  5588. // Mtime: ctime,
  5589. // Type: types,
  5590. // Modifier: adminInfo.AdminUser.Id,
  5591. // Creator: adminInfo.AdminUser.Id,
  5592. // Status: 1,
  5593. // Doctor: role.UserName,
  5594. // HisPatientId: his_patient_id,
  5595. // OrderStatus: 1,
  5596. // BatchNumber: "",
  5597. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5598. // PType: hpInfo.PType,
  5599. // MedType: med_type,
  5600. // }
  5601. //
  5602. // if historyPrescription.ID > 0 {
  5603. // prescription.PreTime = historyPrescription.PreTime
  5604. //
  5605. // }
  5606. //
  5607. // service.SaveHisPrescription(prescription)
  5608. //
  5609. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5610. // advices := items["advices"].([]interface{})
  5611. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5612. // groupNo := int64(0)
  5613. // ctime := time.Now().Unix()
  5614. // mtime := ctime
  5615. // if len(advices) > 0 {
  5616. // for _, advice := range advices {
  5617. // var s models.HisDoctorAdviceInfo
  5618. // s.PrescriptionId = prescription.ID
  5619. // s.AdviceType = 2
  5620. // s.AdviceDoctor = adminInfo.AdminUser.Id
  5621. // s.StopState = 2
  5622. // s.ExecutionState = 2
  5623. // s.AdviceDate = recordDateTime
  5624. // s.Status = 1
  5625. // s.UserOrgId = adminInfo.CurrentOrgId
  5626. // s.RecordDate = recordDateTime
  5627. // s.StartTime = prescription.PreTime
  5628. // s.Groupno = groupNo
  5629. // s.CreatedTime = ctime
  5630. // s.UpdatedTime = mtime
  5631. // s.PatientId = patient_id
  5632. // s.HisPatientId = his_patient_id
  5633. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5634. // if errcode > 0 {
  5635. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5636. // return
  5637. // }
  5638. //
  5639. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5640. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5641. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5642. // if s.Price == 0 {
  5643. // s.Price = lastWarehouse.RetailPrice
  5644. // }
  5645. // }
  5646. //
  5647. // service.CreateHisDoctorAdvice(&s)
  5648. // //记录日志
  5649. // byterequest, _ := json.Marshal(s)
  5650. // adviceLog := models.XtDoctorAdviceLog{
  5651. // UserOrgId: s.UserOrgId,
  5652. // PatientId: s.PatientId,
  5653. // AdminUserId: adminInfo.AdminUser.Id,
  5654. // Module: 1,
  5655. // ErrLog: string(byterequest),
  5656. // Status: 1,
  5657. // Ctime: time.Now().Unix(),
  5658. // Mtime: 0,
  5659. // Source: "电脑端his医嘱修改",
  5660. // RecordDate: s.AdviceDate,
  5661. // }
  5662. // service.CreateDoctorAdviceLog(adviceLog)
  5663. // redis := service.RedisClient()
  5664. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5665. // redis.Set(key, "", time.Second)
  5666. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5667. // fmt.Println("keyOne", keyOne)
  5668. // redis.Set(keyOne, "", time.Second)
  5669. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5670. // redis.Set(keySeven, "", time.Second)
  5671. // redis.Close()
  5672. //
  5673. // }
  5674. // }
  5675. // }
  5676. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5677. // projects := items["project"].([]interface{})
  5678. // if len(projects) > 0 {
  5679. // for _, project := range projects {
  5680. // var p models.HisPrescriptionProject
  5681. // p.PrescriptionId = prescription.ID
  5682. // p.Ctime = time.Now().Unix()
  5683. // p.Mtime = time.Now().Unix()
  5684. // p.PatientId = patient_id
  5685. // p.RecordDate = recordDateTime
  5686. // p.UserOrgId = adminInfo.CurrentOrgId
  5687. // p.HisPatientId = his_patient_id
  5688. // p.Status = 1
  5689. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5690. // if errcode > 0 {
  5691. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5692. // return
  5693. // }
  5694. // service.CreateHisProjectTwo(&p)
  5695. //
  5696. // //记录日志
  5697. // byterequest, _ := json.Marshal(p)
  5698. // adviceLog := models.XtDoctorAdviceLog{
  5699. // UserOrgId: p.UserOrgId,
  5700. // PatientId: p.PatientId,
  5701. // AdminUserId: adminInfo.AdminUser.Id,
  5702. // Module: 1,
  5703. // ErrLog: string(byterequest),
  5704. // Status: 1,
  5705. // Ctime: time.Now().Unix(),
  5706. // Mtime: 0,
  5707. // Source: "电脑端his项目修改",
  5708. // RecordDate: p.RecordDate,
  5709. // }
  5710. // service.CreateDoctorAdviceLog(adviceLog)
  5711. // }
  5712. // }
  5713. // }
  5714. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5715. // addition := items["addition"].([]interface{})
  5716. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5717. // ctime := time.Now().Unix()
  5718. // mtime := ctime
  5719. // if len(addition) > 0 {
  5720. // for _, item := range addition {
  5721. // var s models.HisAdditionalCharge
  5722. // s.PrescriptionId = prescription.ID
  5723. // s.Status = 1
  5724. // s.UserOrgId = adminInfo.CurrentOrgId
  5725. // s.RecordDate = recordDateTime
  5726. // s.CreatedTime = ctime
  5727. // s.UpdatedTime = mtime
  5728. // s.PatientId = patient_id
  5729. // s.HisPatientId = his_patient_id
  5730. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5731. // if errcode > 0 {
  5732. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5733. // return
  5734. // }
  5735. // service.CreateAdditionalCharge(&s)
  5736. // }
  5737. // }
  5738. // }
  5739. //
  5740. // }
  5741. // }
  5742. // }
  5743. // if err == nil {
  5744. // c.ServeSuccessJSON(map[string]interface{}{
  5745. // "msg": "保存成功",
  5746. // })
  5747. // return
  5748. //
  5749. // } else {
  5750. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5751. // return
  5752. // }
  5753. //}
  5754. func (c *HisApiController) DeletePrescription() {
  5755. prescription_id, _ := c.GetInt64("id")
  5756. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5757. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5758. ////同步到自备药
  5759. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5760. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5761. if selfPrescriptionOpen.IsOpen == 1 {
  5762. // 在函数结束时处理事务回滚
  5763. db := service.XTWriteDB()
  5764. tx := db.Begin()
  5765. defer func() {
  5766. if r := recover(); r != nil {
  5767. tx.Rollback()
  5768. } else {
  5769. tx.Commit()
  5770. }
  5771. }()
  5772. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5773. for _, item := range advicesList {
  5774. timeStr := time.Now().Format("2006-01-02")
  5775. timeArr := strings.Split(timeStr, "-")
  5776. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5777. total = total + 1
  5778. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5779. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5780. number = number + total
  5781. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5782. operation_time := time.Now().Unix()
  5783. creater := c.GetAdminUserInfo().AdminUser.Id
  5784. //创建一个出库单
  5785. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5786. WarehouseOutOrderNumber: warehousing_out_order,
  5787. OperationTime: operation_time,
  5788. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5789. Creater: creater,
  5790. Ctime: time.Now().Unix(),
  5791. Status: 1,
  5792. WarehouseOutTime: item.AdviceDate,
  5793. Type: 0,
  5794. PatientId: item.PatientId,
  5795. IsCheck: 1,
  5796. }
  5797. //查询今日是否有出库数据
  5798. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5799. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5800. if lastWarehouseOut.ID == 0 {
  5801. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5802. }
  5803. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5804. var total_count int64
  5805. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5806. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5807. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5808. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5809. }
  5810. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5811. total_count += prescribingNumberSeven
  5812. }
  5813. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5814. total_count += prescribingNumberSeven
  5815. }
  5816. //出库
  5817. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5818. WarehouseOutOrderNumber: warehousing_out_order,
  5819. WarehouseOutId: lastWarehouseOut.ID,
  5820. DrugId: item.DrugId,
  5821. Count: total_count,
  5822. Price: 0,
  5823. TotalPrice: 0,
  5824. Status: 1,
  5825. Ctime: item.AdviceDate,
  5826. Mtime: item.AdviceDate,
  5827. Remark: "",
  5828. OrgId: item.UserOrgId,
  5829. Type: 0,
  5830. Manufacturer: selfBasedrug.Manufacturer,
  5831. Dealer: selfBasedrug.Dealer,
  5832. RetailPrice: 0,
  5833. RetailTotalPrice: 0,
  5834. CountUnit: selfBasedrug.MinUnit,
  5835. ExpiryDate: 0,
  5836. ProductDate: 0,
  5837. Number: "",
  5838. BatchNumber: "",
  5839. IsSys: 1,
  5840. WarehouseInfoId: 0,
  5841. AdminUserId: 0,
  5842. StockCount: "",
  5843. IsCheck: 1,
  5844. SysRecordTime: item.AdviceDate,
  5845. PatientId: item.PatientId,
  5846. ClassType: "",
  5847. AdviceId: item.ID,
  5848. }
  5849. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5850. }
  5851. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5852. for _, it := range warehousingOutInfo {
  5853. //查询今日是否有出库数据
  5854. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5855. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5856. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5857. //出库逻辑
  5858. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5859. //查询剩余库存
  5860. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5861. var sum_count int64
  5862. for _, its := range stockInfo {
  5863. if its.MaxUnit == medical.MaxUnit {
  5864. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5865. }
  5866. sum_count += its.StockMaxNumber + its.StockMinNumber
  5867. }
  5868. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5869. }
  5870. }
  5871. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5872. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5873. //耗材保存处方出库
  5874. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5875. //已收费和已发药限制逻辑
  5876. isCharge := false
  5877. isMedicine := false
  5878. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5879. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5880. if new_prescription.IsMedicine == 1 {
  5881. isMedicine = true
  5882. }
  5883. for _, item := range new_prescriptions {
  5884. if item.OrderStatus == 4 {
  5885. isCharge = true
  5886. }
  5887. }
  5888. if p_err != nil {
  5889. if new_prescription.ID > 0 {
  5890. if new_prescription.OrderStatus == 2 {
  5891. isCharge = true
  5892. }
  5893. }
  5894. }
  5895. for _, item := range advices {
  5896. if item.IsMedicine == 1 {
  5897. isMedicine = true
  5898. }
  5899. }
  5900. if isCharge {
  5901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5902. return
  5903. }
  5904. if isMedicine {
  5905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5906. return
  5907. }
  5908. //已收费和已发药限制逻辑
  5909. if len(projects) > 0 {
  5910. for _, item := range projects {
  5911. service.DeletePrintInfo(item.ID) //删除打印信息
  5912. if goodOutConfig.IsOpen != 1 {
  5913. if stockConfig.IsOpen == 1 {
  5914. if item.Type == 3 && item.IsOut == 1 {
  5915. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5916. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5917. good.Total = good.Total + f_count
  5918. service.UpdateGoodInfo(&good)
  5919. operation_time := time.Now().Unix()
  5920. creater := c.GetAdminUserInfo().AdminUser.Id
  5921. //创建退库单
  5922. timeStr := time.Now().Format("2006-01-02")
  5923. timeArr := strings.Split(timeStr, "-")
  5924. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5925. total = total + 1
  5926. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5927. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5928. cancelStock := models.CancelStock{
  5929. OrderNumber: orderNumber,
  5930. OperaTime: operation_time,
  5931. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5932. Creater: creater,
  5933. Ctime: time.Now().Unix(),
  5934. Status: 1,
  5935. ReturnTime: item.RecordDate,
  5936. Type: 1,
  5937. StorehouseId: houseConfig.StorehouseOutInfo,
  5938. IsCheck: 1,
  5939. }
  5940. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5941. if msgerrkonde == gorm.ErrRecordNotFound {
  5942. service.AddSigleCancelStock(&cancelStock)
  5943. }
  5944. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5945. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5946. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5947. //查询该耗材是否出库
  5948. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5949. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5950. deaerler, _ := service.GetDealerById(info.Dealer)
  5951. var total_count int64
  5952. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5953. total_count += count
  5954. if info.ID > 0 {
  5955. if info.Count >= total_count {
  5956. //回退库存
  5957. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5958. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5959. var flush_count int64
  5960. for _, it := range goodList {
  5961. flush_count += it.StockCount
  5962. }
  5963. cancelStockInfo := models.CancelStockInfo{
  5964. GoodId: item.ProjectId,
  5965. CancelStockId: cancel.ID,
  5966. GoodTypeId: good.GoodTypeId,
  5967. Count: prescribingNumber,
  5968. Price: info.Price,
  5969. Total: 0,
  5970. ProductDate: info.ProductDate,
  5971. ExpiryDate: info.ExpiryDate,
  5972. Ctime: time.Now().Unix(),
  5973. Status: 1,
  5974. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5975. OrderNumber: cancel.OrderNumber,
  5976. Type: 0,
  5977. Dealer: deaerler.DealerName,
  5978. Manufacturer: manufacturer.ManufacturerName,
  5979. Number: info.Number,
  5980. RegisterAccount: "",
  5981. Remark: "",
  5982. WarehouseInfoId: info.WarehouseInfotId,
  5983. PatientId: info.PatientId,
  5984. RecordDate: info.SysRecordTime,
  5985. StorehouseId: houseConfig.StorehouseOutInfo,
  5986. IsCheck: 1,
  5987. }
  5988. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5989. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5990. flow := models.VmStockFlow{
  5991. WarehousingId: info.WarehouseInfotId,
  5992. GoodId: item.ProjectId,
  5993. Number: info.Number,
  5994. LicenseNumber: info.LicenseNumber,
  5995. Count: prescribingNumber,
  5996. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5997. PatientId: item.PatientId,
  5998. SystemTime: info.SysRecordTime,
  5999. ConsumableType: 7,
  6000. IsSys: 0,
  6001. WarehousingOrder: "",
  6002. WarehouseOutId: info.WarehouseOutId,
  6003. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6004. IsEdit: 0,
  6005. CancelStockId: cancel.ID,
  6006. CancelOrderNumber: cancel.OrderNumber,
  6007. Manufacturer: manufacturer.ID,
  6008. Dealer: 0,
  6009. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6010. UpdateCreator: 0,
  6011. Status: 1,
  6012. Ctime: time.Now().Unix(),
  6013. Mtime: 0,
  6014. Price: info.Price,
  6015. WarehousingDetailId: info.WarehouseInfotId,
  6016. WarehouseOutDetailId: info.ID,
  6017. CancelOutDetailId: cancelInfo.ID,
  6018. ProductDate: info.ProductDate,
  6019. ExpireDate: info.ExpiryDate,
  6020. StorehouseId: houseConfig.StorehouseOutInfo,
  6021. OverCount: flush_count,
  6022. OperateTime: time.Now().Unix(),
  6023. }
  6024. service.CreateStockFlowOne(flow)
  6025. //退库数量增加
  6026. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6027. //出库数量减少
  6028. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6029. }
  6030. if info.Count < total_count {
  6031. //回退库存
  6032. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6033. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6034. var flush_count int64
  6035. for _, it := range goodList {
  6036. flush_count += it.StockCount
  6037. }
  6038. cancelStockInfo := models.CancelStockInfo{
  6039. GoodId: item.ProjectId,
  6040. CancelStockId: cancel.ID,
  6041. GoodTypeId: good.GoodTypeId,
  6042. Count: info.Count,
  6043. Price: info.Price,
  6044. Total: 0,
  6045. ProductDate: info.ProductDate,
  6046. ExpiryDate: info.ExpiryDate,
  6047. Ctime: time.Now().Unix(),
  6048. Status: 1,
  6049. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6050. OrderNumber: cancel.OrderNumber,
  6051. Type: 0,
  6052. Dealer: deaerler.DealerName,
  6053. Manufacturer: manufacturer.ManufacturerName,
  6054. Number: info.Number,
  6055. RegisterAccount: "",
  6056. Remark: "",
  6057. WarehouseInfoId: info.WarehouseInfotId,
  6058. PatientId: info.PatientId,
  6059. RecordDate: info.SysRecordTime,
  6060. StorehouseId: houseConfig.StorehouseOutInfo,
  6061. IsCheck: 1,
  6062. }
  6063. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6064. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6065. flow := models.VmStockFlow{
  6066. WarehousingId: info.WarehouseInfotId,
  6067. GoodId: item.ProjectId,
  6068. Number: info.Number,
  6069. LicenseNumber: info.LicenseNumber,
  6070. Count: info.Count,
  6071. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6072. PatientId: item.PatientId,
  6073. SystemTime: info.SysRecordTime,
  6074. ConsumableType: 7,
  6075. IsSys: 0,
  6076. WarehousingOrder: "",
  6077. WarehouseOutId: info.WarehouseOutId,
  6078. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6079. IsEdit: 0,
  6080. CancelStockId: cancel.ID,
  6081. CancelOrderNumber: cancel.OrderNumber,
  6082. Manufacturer: manufacturer.ID,
  6083. Dealer: 0,
  6084. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6085. UpdateCreator: 0,
  6086. Status: 1,
  6087. Ctime: time.Now().Unix(),
  6088. Mtime: 0,
  6089. Price: info.Price,
  6090. WarehousingDetailId: info.WarehouseInfotId,
  6091. WarehouseOutDetailId: info.ID,
  6092. CancelOutDetailId: cancelInfo.ID,
  6093. ProductDate: info.ProductDate,
  6094. ExpireDate: info.ExpiryDate,
  6095. StorehouseId: houseConfig.StorehouseOutInfo,
  6096. OverCount: flush_count,
  6097. OperateTime: time.Now().Unix(),
  6098. }
  6099. service.CreateStockFlowOne(flow)
  6100. //退库数量增加
  6101. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6102. //出库数量减少
  6103. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6104. }
  6105. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6106. var flush_count int64
  6107. for _, it := range goodList {
  6108. flush_count += it.StockCount
  6109. }
  6110. //查询已出库数量
  6111. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6112. if prescribingNumber < dialysisInfo.Count {
  6113. //改变数量
  6114. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6115. }
  6116. if prescribingNumber >= dialysisInfo.Count {
  6117. //删除出库表
  6118. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6119. }
  6120. //更新库存
  6121. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6122. //更新基础库库存
  6123. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6124. }
  6125. }
  6126. }
  6127. }
  6128. //保存耗材出库
  6129. if goodOutConfig.IsOpen == 1 {
  6130. if item.Type == 3 {
  6131. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6132. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6133. good.Total = good.Total + f_count
  6134. service.UpdateGoodInfo(&good)
  6135. operation_time := time.Now().Unix()
  6136. creater := c.GetAdminUserInfo().AdminUser.Id
  6137. //创建退库单
  6138. timeStr := time.Now().Format("2006-01-02")
  6139. timeArr := strings.Split(timeStr, "-")
  6140. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6141. total = total + 1
  6142. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6143. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6144. cancelStock := models.CancelStock{
  6145. OrderNumber: orderNumber,
  6146. OperaTime: operation_time,
  6147. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6148. Creater: creater,
  6149. Ctime: time.Now().Unix(),
  6150. Status: 1,
  6151. ReturnTime: item.RecordDate,
  6152. Type: 1,
  6153. StorehouseId: houseConfig.StorehouseOutInfo,
  6154. IsCheck: 1,
  6155. }
  6156. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6157. if msgerrkonde == gorm.ErrRecordNotFound {
  6158. service.AddSigleCancelStock(&cancelStock)
  6159. }
  6160. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6161. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6162. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6163. //查询该耗材是否出库
  6164. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6165. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6166. deaerler, _ := service.GetDealerById(info.Dealer)
  6167. var total_count int64
  6168. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6169. total_count += count
  6170. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6171. var flush_count int64
  6172. for _, it := range goodList {
  6173. flush_count += it.StockCount
  6174. }
  6175. fmt.Println("历史出库数据", info.Count)
  6176. fmt.Println("出库数量", total_count)
  6177. if info.ID > 0 {
  6178. cancelStockInfo := models.CancelStockInfo{
  6179. GoodId: item.ProjectId,
  6180. CancelStockId: cancel.ID,
  6181. GoodTypeId: good.GoodTypeId,
  6182. Count: prescribingNumber,
  6183. Price: info.Price,
  6184. Total: 0,
  6185. ProductDate: info.ProductDate,
  6186. ExpiryDate: info.ExpiryDate,
  6187. Ctime: time.Now().Unix(),
  6188. Status: 1,
  6189. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6190. OrderNumber: cancel.OrderNumber,
  6191. Type: 0,
  6192. Dealer: deaerler.DealerName,
  6193. Manufacturer: manufacturer.ManufacturerName,
  6194. Number: info.Number,
  6195. RegisterAccount: "",
  6196. Remark: "",
  6197. WarehouseInfoId: info.WarehouseInfotId,
  6198. PatientId: info.PatientId,
  6199. RecordDate: info.SysRecordTime,
  6200. StorehouseId: houseConfig.StorehouseOutInfo,
  6201. IsCheck: 1,
  6202. }
  6203. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6204. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6205. //查询出库数量
  6206. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6207. //出库数据 大于 退库数量
  6208. if len(list) > 0 {
  6209. for _, it := range list {
  6210. //回退库存
  6211. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6212. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6213. var flush_count_one int64
  6214. for _, it := range goodList {
  6215. flush_count_one += it.StockCount
  6216. }
  6217. //查询该批次是否有退库数据
  6218. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6219. creater := c.GetAdminUserInfo().AdminUser.Id
  6220. flow := models.VmStockFlow{
  6221. WarehousingId: it.WarehouseInfotId,
  6222. GoodId: it.GoodId,
  6223. Number: it.Number,
  6224. LicenseNumber: it.LicenseNumber,
  6225. Count: it.Count,
  6226. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6227. PatientId: it.PatientId,
  6228. SystemTime: it.SysRecordTime,
  6229. ConsumableType: 7,
  6230. IsSys: 0,
  6231. WarehousingOrder: "",
  6232. WarehouseOutId: it.WarehouseOutId,
  6233. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6234. IsEdit: 0,
  6235. CancelStockId: cancel.ID,
  6236. CancelOrderNumber: cancel.OrderNumber,
  6237. Manufacturer: manufacturer.ID,
  6238. Dealer: 0,
  6239. Creator: creater,
  6240. UpdateCreator: 0,
  6241. Status: 1,
  6242. Ctime: time.Now().Unix(),
  6243. Mtime: 0,
  6244. Price: it.Price,
  6245. WarehousingDetailId: it.WarehouseInfotId,
  6246. WarehouseOutDetailId: it.ID,
  6247. CancelOutDetailId: cancelInfo.ID,
  6248. ProductDate: it.ProductDate,
  6249. ExpireDate: it.ExpiryDate,
  6250. StorehouseId: houseConfig.StorehouseOutInfo,
  6251. OverCount: flush_count_one,
  6252. OperateTime: time.Now().Unix(),
  6253. }
  6254. service.CreateStockFlowOne(flow)
  6255. //if flow.ID > 0 {
  6256. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6257. //}
  6258. }
  6259. }
  6260. //flow := models.VmStockFlow{
  6261. // WarehousingId: info.WarehouseInfotId,
  6262. // GoodId: item.ProjectId,
  6263. // Number: info.Number,
  6264. // LicenseNumber: info.LicenseNumber,
  6265. // Count: prescribingNumber,
  6266. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6267. // PatientId: item.PatientId,
  6268. // SystemTime: info.SysRecordTime,
  6269. // ConsumableType: 7,
  6270. // IsSys: 0,
  6271. // WarehousingOrder: "",
  6272. // WarehouseOutId: info.WarehouseOutId,
  6273. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6274. // IsEdit: 0,
  6275. // CancelStockId: cancel.ID,
  6276. // CancelOrderNumber: cancel.OrderNumber,
  6277. // Manufacturer: manufacturer.ID,
  6278. // Dealer: 0,
  6279. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6280. // UpdateCreator: 0,
  6281. // Status: 1,
  6282. // Ctime: time.Now().Unix(),
  6283. // Mtime: 0,
  6284. // Price: info.Price,
  6285. // WarehousingDetailId: info.WarehouseInfotId,
  6286. // WarehouseOutDetailId: info.ID,
  6287. // CancelOutDetailId: cancelInfo.ID,
  6288. // ProductDate: info.ProductDate,
  6289. // ExpireDate: info.ExpiryDate,
  6290. // StorehouseId: houseConfig.StorehouseOutInfo,
  6291. // OverCount: flush_count,
  6292. //}
  6293. //service.CreateStockFlowOne(flow)
  6294. //退库数量增加
  6295. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6296. //出库数量减少
  6297. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6298. //查询已出库数量
  6299. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6300. if prescribingNumber < dialysisInfo.Count {
  6301. //改变数量
  6302. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6303. }
  6304. if prescribingNumber >= dialysisInfo.Count {
  6305. //删除出库表
  6306. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6307. }
  6308. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6309. var flush_count_one int64
  6310. for _, it := range goodList {
  6311. flush_count_one += it.StockCount
  6312. }
  6313. //更新库存
  6314. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6315. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6316. //更新基础库库存
  6317. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6318. }
  6319. }
  6320. }
  6321. }
  6322. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6323. fmt.Println(err)
  6324. }
  6325. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6326. fmt.Println(err)
  6327. if len(advices) > 0 {
  6328. for _, item := range advices {
  6329. redis := service.RedisClient()
  6330. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6331. redis.Set(keyFive, "", time.Second)
  6332. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6333. redis.Set(keyOne, "", time.Second)
  6334. redis.Close()
  6335. }
  6336. }
  6337. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6338. if len(advices) > 0 {
  6339. for _, item := range advices {
  6340. creater := c.GetAdminUserInfo().AdminUser.Id
  6341. service.DrugAutoAddCancelInfo(item, creater)
  6342. }
  6343. }
  6344. } else {
  6345. if drugOutConfig.IsOpen == 1 {
  6346. if len(advices) > 0 {
  6347. for _, item := range advices {
  6348. creater := c.GetAdminUserInfo().AdminUser.Id
  6349. service.DrugAutoAddCancelInfo(item, creater)
  6350. }
  6351. }
  6352. } else {
  6353. if len(advices) > 0 {
  6354. for _, item := range advices {
  6355. creater := c.GetAdminUserInfo().AdminUser.Id
  6356. service.DrugAutoAddCancelInfo(item, creater)
  6357. }
  6358. }
  6359. }
  6360. }
  6361. c.ServeSuccessJSON(map[string]interface{}{
  6362. "msg": "删除成功",
  6363. })
  6364. return
  6365. }
  6366. func (c *HisApiController) DeleteDoctorAdvice() {
  6367. id, _ := c.GetInt64("id")
  6368. advice, _ := service.GetHisDoctorAdvicesById(id)
  6369. ////同步到自备药
  6370. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6371. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6372. if selfPrescriptionOpen.IsOpen == 1 {
  6373. db := service.XTWriteDB()
  6374. tx := db.Begin()
  6375. defer func() {
  6376. if r := recover(); r != nil {
  6377. tx.Rollback()
  6378. } else {
  6379. tx.Commit()
  6380. }
  6381. }()
  6382. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6383. var total_count int64
  6384. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6385. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6386. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6387. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6388. }
  6389. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6390. total_count += prescribingNumberSeven
  6391. }
  6392. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6393. total_count += prescribingNumberSeven
  6394. }
  6395. timeStr := time.Now().Format("2006-01-02")
  6396. timeArr := strings.Split(timeStr, "-")
  6397. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6398. total = total + 1
  6399. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6400. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6401. number = number + total
  6402. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6403. operation_time := time.Now().Unix()
  6404. creater := c.GetAdminUserInfo().AdminUser.Id
  6405. //创建一个出库单
  6406. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6407. WarehouseOutOrderNumber: warehousing_out_order,
  6408. OperationTime: operation_time,
  6409. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6410. Creater: creater,
  6411. Ctime: time.Now().Unix(),
  6412. Status: 1,
  6413. WarehouseOutTime: advice.AdviceDate,
  6414. Type: 0,
  6415. PatientId: advice.PatientId,
  6416. IsCheck: 1,
  6417. }
  6418. //查询今日是否有出库数据
  6419. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6420. if lastWarehouseOut.ID == 0 {
  6421. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6422. }
  6423. //出库
  6424. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6425. WarehouseOutId: lastWarehouseOut.ID,
  6426. WarehouseOutOrderNumber: warehousing_out_order,
  6427. DrugId: advice.DrugId,
  6428. Count: total_count,
  6429. Price: 0,
  6430. TotalPrice: 0,
  6431. Status: 1,
  6432. Ctime: advice.AdviceDate,
  6433. Mtime: advice.AdviceDate,
  6434. Remark: "",
  6435. OrgId: advice.UserOrgId,
  6436. Type: 0,
  6437. Manufacturer: selfBasedrug.Manufacturer,
  6438. Dealer: selfBasedrug.Dealer,
  6439. RetailPrice: 0,
  6440. RetailTotalPrice: 0,
  6441. CountUnit: advice.PrescribingNumberUnit,
  6442. ExpiryDate: 0,
  6443. ProductDate: 0,
  6444. Number: "",
  6445. BatchNumber: "",
  6446. IsSys: 0,
  6447. WarehouseInfoId: 0,
  6448. AdminUserId: 0,
  6449. StockCount: "",
  6450. IsCheck: 1,
  6451. SysRecordTime: advice.AdviceDate,
  6452. PatientId: advice.PatientId,
  6453. AdviceId: advice.ID,
  6454. ClassType: "",
  6455. }
  6456. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6457. for _, it := range warehousingOutInfo {
  6458. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6459. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6460. //出库逻辑
  6461. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6462. //查询剩余库存
  6463. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6464. var sum_count int64
  6465. for _, its := range stockInfo {
  6466. if its.MaxUnit == medical.MaxUnit {
  6467. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6468. }
  6469. sum_count += its.StockMaxNumber + its.StockMinNumber
  6470. }
  6471. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6472. }
  6473. }
  6474. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6475. //已收费和已发药的限制逻辑
  6476. isCharge := false
  6477. isMedicine := false
  6478. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6479. //获取今天该患者所有处方,判断是否发药或者收费
  6480. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6481. //for _, item := range new_prescriptions {
  6482. if new_prescription.IsMedicine == 1 {
  6483. isMedicine = true
  6484. }
  6485. //}
  6486. for _, item := range new_prescriptions {
  6487. if item.OrderStatus == 4 {
  6488. isCharge = true
  6489. }
  6490. }
  6491. if isMedicine {
  6492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6493. return
  6494. }
  6495. if isCharge {
  6496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6497. return
  6498. }
  6499. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6500. for _, item := range advices {
  6501. if item.IsMedicine == 1 {
  6502. isMedicine = true
  6503. }
  6504. }
  6505. if isMedicine {
  6506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6507. return
  6508. }
  6509. if new_prescription.ID > 0 {
  6510. if new_prescription.OrderStatus == 2 {
  6511. isCharge = true
  6512. }
  6513. }
  6514. if isCharge {
  6515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6516. return
  6517. }
  6518. //已收费和已发药的限制逻辑
  6519. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6520. redis := service.RedisClient()
  6521. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6522. redis.Set(keyFive, "", time.Second)
  6523. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6524. redis.Set(keyOne, "", time.Second)
  6525. defer redis.Close()
  6526. if err == nil {
  6527. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6528. //查询是否在处方中出库
  6529. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6530. if openConfig.IsOpen != 1 {
  6531. //判断该医嘱是否执行了
  6532. if advice.ExecutionState == 1 {
  6533. creater := c.GetAdminUserInfo().AdminUser.Id
  6534. service.DrugAutoAddCancelInfo(&advice, creater)
  6535. }
  6536. }
  6537. //开启保存处方扣减功能
  6538. if openConfig.IsOpen == 1 {
  6539. creater := c.GetAdminUserInfo().AdminUser.Id
  6540. service.DrugAutoAddCancelInfo(&advice, creater)
  6541. }
  6542. } else {
  6543. if drugOutConfig.IsOpen == 1 {
  6544. //查询是否在处方中出库
  6545. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6546. if openConfig.IsOpen != 1 {
  6547. //判断该医嘱是否执行了
  6548. if advice.ExecutionState == 1 {
  6549. creater := c.GetAdminUserInfo().AdminUser.Id
  6550. service.DrugAutoAddCancelInfo(&advice, creater)
  6551. }
  6552. }
  6553. //开启保存处方扣减功能
  6554. if openConfig.IsOpen == 1 {
  6555. creater := c.GetAdminUserInfo().AdminUser.Id
  6556. service.DrugAutoAddCancelInfo(&advice, creater)
  6557. }
  6558. } else {
  6559. //判断该医嘱是否执行了
  6560. if advice.ExecutionState == 1 {
  6561. creater := c.GetAdminUserInfo().AdminUser.Id
  6562. service.DrugAutoAddCancelInfo(&advice, creater)
  6563. }
  6564. }
  6565. }
  6566. c.ServeSuccessJSON(map[string]interface{}{
  6567. "msg": "删除成功",
  6568. })
  6569. return
  6570. } else {
  6571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6572. return
  6573. }
  6574. }
  6575. func (c *HisApiController) DeleteProject() {
  6576. id, _ := c.GetInt64("id")
  6577. adminInfo := c.GetAdminUserInfo()
  6578. project, _ := service.GetHisProjectByID(id)
  6579. // var consumable models.DialysisBeforePrepare
  6580. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6581. //耗材保存处方出库
  6582. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6583. isCharge := false
  6584. isMedicine := false
  6585. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6586. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6587. for _, item := range new_prescriptions {
  6588. if item.IsMedicine == 1 {
  6589. isMedicine = true
  6590. }
  6591. }
  6592. for _, item := range new_prescriptions {
  6593. if item.OrderStatus == 4 {
  6594. isCharge = true
  6595. }
  6596. }
  6597. if isMedicine {
  6598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6599. return
  6600. }
  6601. if isCharge {
  6602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6603. return
  6604. }
  6605. if new_prescription.ID > 0 {
  6606. if new_prescription.OrderStatus == 2 {
  6607. isCharge = true
  6608. }
  6609. }
  6610. if isCharge {
  6611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6612. return
  6613. }
  6614. service.DeletePrintInfo(id)
  6615. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  6616. label.Status = 0
  6617. service.CreateHisLabelRecordTwo(&label)
  6618. fmt.Println(goodOutConfig.IsOpen)
  6619. if goodOutConfig.IsOpen != 1 {
  6620. if stockConfig.IsOpen == 1 {
  6621. if project.Type == 2 {
  6622. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6623. fmt.Println(err)
  6624. }
  6625. if project.Type == 3 && project.IsOut == 1 {
  6626. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6627. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6628. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6629. operation_time := time.Now().Unix()
  6630. creater := adminInfo.AdminUser.Id
  6631. //创建退库单
  6632. timeStr := time.Now().Format("2006-01-02")
  6633. timeArr := strings.Split(timeStr, "-")
  6634. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6635. total = total + 1
  6636. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6637. cancelStock := models.CancelStock{
  6638. OrderNumber: orderNumber,
  6639. OperaTime: operation_time,
  6640. OrgId: adminInfo.CurrentOrgId,
  6641. Creater: creater,
  6642. Ctime: time.Now().Unix(),
  6643. Status: 1,
  6644. ReturnTime: project.RecordDate,
  6645. Type: 1,
  6646. StorehouseId: houseConfig.StorehouseOutInfo,
  6647. IsCheck: 1,
  6648. }
  6649. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6650. if msgerrkonde == gorm.ErrRecordNotFound {
  6651. service.AddSigleCancelStock(&cancelStock)
  6652. }
  6653. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6654. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6655. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6656. //查询是否有出库
  6657. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6658. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6659. deaerler, _ := service.GetDealerById(info.Dealer)
  6660. if info.ID > 0 {
  6661. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6662. if info.Count >= prescribingNumber {
  6663. cancelStockInfo := models.CancelStockInfo{
  6664. GoodId: project.ProjectId,
  6665. CancelStockId: cancel.ID,
  6666. GoodTypeId: good.GoodTypeId,
  6667. Count: prescribingNumber,
  6668. Price: info.Price,
  6669. Total: 0,
  6670. ProductDate: info.ProductDate,
  6671. ExpiryDate: info.ExpiryDate,
  6672. Ctime: time.Now().Unix(),
  6673. Status: 1,
  6674. OrgId: adminInfo.CurrentOrgId,
  6675. OrderNumber: cancel.OrderNumber,
  6676. Type: 0,
  6677. Dealer: deaerler.DealerName,
  6678. Manufacturer: manufacturer.ManufacturerName,
  6679. Number: info.Number,
  6680. RegisterAccount: "",
  6681. Remark: "",
  6682. WarehouseInfoId: info.WarehouseInfotId,
  6683. PatientId: info.PatientId,
  6684. RecordDate: info.SysRecordTime,
  6685. StorehouseId: houseConfig.StorehouseOutInfo,
  6686. IsCheck: 1,
  6687. }
  6688. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6689. //回退库存
  6690. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6691. //退库数量增加
  6692. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6693. //出库数量减少
  6694. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6695. }
  6696. if info.Count < prescribingNumber {
  6697. cancelStockInfo := models.CancelStockInfo{
  6698. GoodId: project.ProjectId,
  6699. CancelStockId: cancel.ID,
  6700. GoodTypeId: good.GoodTypeId,
  6701. Count: info.Count,
  6702. Price: info.Price,
  6703. Total: 0,
  6704. ProductDate: info.ProductDate,
  6705. ExpiryDate: info.ExpiryDate,
  6706. Ctime: time.Now().Unix(),
  6707. Status: 1,
  6708. OrgId: adminInfo.CurrentOrgId,
  6709. OrderNumber: cancel.OrderNumber,
  6710. Type: 0,
  6711. Dealer: deaerler.DealerName,
  6712. Manufacturer: manufacturer.ManufacturerName,
  6713. Number: info.Number,
  6714. RegisterAccount: "",
  6715. Remark: "",
  6716. WarehouseInfoId: info.WarehouseInfotId,
  6717. PatientId: info.PatientId,
  6718. RecordDate: info.SysRecordTime,
  6719. StorehouseId: houseConfig.StorehouseOutInfo,
  6720. IsCheck: 1,
  6721. }
  6722. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6723. //回退库存
  6724. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6725. //退库数量增加
  6726. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6727. //出库数量减少
  6728. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6729. }
  6730. //查询剩余库存
  6731. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6732. var over_count int64
  6733. for _, it := range goodList {
  6734. over_count += it.StockCount
  6735. }
  6736. //出库数据 大于 退库数量
  6737. if info.Count >= prescribingNumber {
  6738. flow := models.VmStockFlow{
  6739. WarehousingId: info.WarehouseInfotId,
  6740. GoodId: project.ProjectId,
  6741. Number: info.Number,
  6742. LicenseNumber: info.LicenseNumber,
  6743. Count: prescribingNumber,
  6744. UserOrgId: adminInfo.CurrentOrgId,
  6745. PatientId: project.PatientId,
  6746. SystemTime: info.SysRecordTime,
  6747. ConsumableType: 7,
  6748. IsSys: 0,
  6749. WarehousingOrder: "",
  6750. WarehouseOutId: info.WarehouseOutId,
  6751. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6752. IsEdit: 0,
  6753. CancelStockId: cancel.ID,
  6754. CancelOrderNumber: cancel.OrderNumber,
  6755. Manufacturer: manufacturer.ID,
  6756. Dealer: 0,
  6757. Creator: adminInfo.AdminUser.Id,
  6758. UpdateCreator: 0,
  6759. Status: 1,
  6760. Ctime: time.Now().Unix(),
  6761. Mtime: 0,
  6762. Price: info.Price,
  6763. WarehousingDetailId: info.WarehouseInfotId,
  6764. WarehouseOutDetailId: info.ID,
  6765. CancelOutDetailId: cancelInfo.ID,
  6766. ProductDate: info.ProductDate,
  6767. ExpireDate: info.ExpiryDate,
  6768. StorehouseId: houseConfig.StorehouseOutInfo,
  6769. OverCount: over_count,
  6770. OperateTime: time.Now().Unix(),
  6771. }
  6772. service.CreateStockFlowOne(flow)
  6773. }
  6774. //出库数据小于退库数据
  6775. if info.Count < prescribingNumber {
  6776. flow := models.VmStockFlow{
  6777. WarehousingId: info.WarehouseInfotId,
  6778. GoodId: project.ProjectId,
  6779. Number: info.Number,
  6780. LicenseNumber: info.LicenseNumber,
  6781. Count: info.Count,
  6782. UserOrgId: adminInfo.CurrentOrgId,
  6783. PatientId: project.PatientId,
  6784. SystemTime: info.SysRecordTime,
  6785. ConsumableType: 7,
  6786. IsSys: 0,
  6787. WarehousingOrder: "",
  6788. WarehouseOutId: info.WarehouseOutId,
  6789. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6790. IsEdit: 0,
  6791. CancelStockId: cancel.ID,
  6792. CancelOrderNumber: cancel.OrderNumber,
  6793. Manufacturer: manufacturer.ID,
  6794. Dealer: 0,
  6795. Creator: adminInfo.AdminUser.Id,
  6796. UpdateCreator: 0,
  6797. Status: 1,
  6798. Ctime: time.Now().Unix(),
  6799. Mtime: 0,
  6800. Price: info.Price,
  6801. WarehousingDetailId: info.WarehouseInfotId,
  6802. WarehouseOutDetailId: info.ID,
  6803. CancelOutDetailId: cancelInfo.ID,
  6804. ProductDate: info.ProductDate,
  6805. ExpireDate: info.ExpiryDate,
  6806. StorehouseId: houseConfig.StorehouseOutInfo,
  6807. OverCount: over_count,
  6808. OperateTime: time.Now().Unix(),
  6809. }
  6810. service.CreateStockFlowOne(flow)
  6811. }
  6812. //查询已出库数量
  6813. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6814. if prescribingNumber < dialysisInfo.Count {
  6815. //改变数量
  6816. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6817. }
  6818. if prescribingNumber >= dialysisInfo.Count {
  6819. //删除出库表
  6820. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6821. }
  6822. //更新剩余库存
  6823. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6824. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6825. var total_count_one int64
  6826. for _, it := range stockList {
  6827. total_count_one += it.StockCount
  6828. }
  6829. //基础库插入数据
  6830. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6831. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6832. var flush_count int64
  6833. for _, it := range goodListOne {
  6834. flush_count += it.StockCount
  6835. }
  6836. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6837. if errs != nil {
  6838. goodErrcode := models.XtGoodErrcode{
  6839. UserOrgId: project.UserOrgId,
  6840. Errcode: "手动出库更新剩余出库失败",
  6841. GoodId: project.ProjectId,
  6842. Status: 1,
  6843. Ctime: time.Now().Unix(),
  6844. Mtime: 0,
  6845. Count: 0,
  6846. StockCount: 0,
  6847. Creater: creater,
  6848. BatchNumberId: 0,
  6849. WarehouseOutId: 0,
  6850. }
  6851. service.CreateGoodErrcode(goodErrcode)
  6852. }
  6853. }
  6854. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6855. fmt.Println(err)
  6856. } else {
  6857. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6858. fmt.Println(err)
  6859. }
  6860. } else {
  6861. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6862. fmt.Println(err)
  6863. }
  6864. }
  6865. //保存处方出库
  6866. if goodOutConfig.IsOpen == 1 {
  6867. if project.Type == 3 {
  6868. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6869. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6870. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6871. operation_time := time.Now().Unix()
  6872. creater := adminInfo.AdminUser.Id
  6873. //创建退库单
  6874. timeStr := time.Now().Format("2006-01-02")
  6875. timeArr := strings.Split(timeStr, "-")
  6876. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6877. total = total + 1
  6878. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6879. cancelStock := models.CancelStock{
  6880. OrderNumber: orderNumber,
  6881. OperaTime: operation_time,
  6882. OrgId: adminInfo.CurrentOrgId,
  6883. Creater: creater,
  6884. Ctime: time.Now().Unix(),
  6885. Status: 1,
  6886. ReturnTime: project.RecordDate,
  6887. Type: 1,
  6888. StorehouseId: houseConfig.StorehouseOutInfo,
  6889. IsCheck: 1,
  6890. }
  6891. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6892. if msgerrkonde == gorm.ErrRecordNotFound {
  6893. service.AddSigleCancelStock(&cancelStock)
  6894. }
  6895. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6896. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6897. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6898. //获取出库数据
  6899. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6900. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6901. deaerler, _ := service.GetDealerById(info.Dealer)
  6902. if info.ID > 0 {
  6903. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6904. if info.Count >= prescribingNumber {
  6905. cancelStockInfo := models.CancelStockInfo{
  6906. GoodId: project.ProjectId,
  6907. CancelStockId: cancel.ID,
  6908. GoodTypeId: good.GoodTypeId,
  6909. Count: prescribingNumber,
  6910. Price: info.Price,
  6911. Total: 0,
  6912. ProductDate: info.ProductDate,
  6913. ExpiryDate: info.ExpiryDate,
  6914. Ctime: time.Now().Unix(),
  6915. Status: 1,
  6916. OrgId: adminInfo.CurrentOrgId,
  6917. OrderNumber: cancel.OrderNumber,
  6918. Type: 0,
  6919. Dealer: deaerler.DealerName,
  6920. Manufacturer: manufacturer.ManufacturerName,
  6921. Number: info.Number,
  6922. RegisterAccount: "",
  6923. Remark: "",
  6924. WarehouseInfoId: info.WarehouseInfotId,
  6925. PatientId: info.PatientId,
  6926. RecordDate: info.SysRecordTime,
  6927. StorehouseId: houseConfig.StorehouseOutInfo,
  6928. IsCheck: 1,
  6929. }
  6930. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6931. //退库数量增加
  6932. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6933. //出库数量减少
  6934. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6935. }
  6936. if info.Count < prescribingNumber {
  6937. cancelStockInfo := models.CancelStockInfo{
  6938. GoodId: project.ProjectId,
  6939. CancelStockId: cancel.ID,
  6940. GoodTypeId: good.GoodTypeId,
  6941. Count: prescribingNumber,
  6942. Price: info.Price,
  6943. Total: 0,
  6944. ProductDate: info.ProductDate,
  6945. ExpiryDate: info.ExpiryDate,
  6946. Ctime: time.Now().Unix(),
  6947. Status: 1,
  6948. OrgId: adminInfo.CurrentOrgId,
  6949. OrderNumber: cancel.OrderNumber,
  6950. Type: 0,
  6951. Dealer: deaerler.DealerName,
  6952. Manufacturer: manufacturer.ManufacturerName,
  6953. Number: info.Number,
  6954. RegisterAccount: "",
  6955. Remark: "",
  6956. WarehouseInfoId: info.WarehouseInfotId,
  6957. PatientId: info.PatientId,
  6958. RecordDate: info.SysRecordTime,
  6959. StorehouseId: houseConfig.StorehouseOutInfo,
  6960. IsCheck: 1,
  6961. }
  6962. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6963. //回退库存
  6964. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6965. }
  6966. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6967. var over_count int64
  6968. for _, it := range goodList {
  6969. over_count += it.StockCount
  6970. }
  6971. //查询出库数量
  6972. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6973. //出库数据 大于 退库数量
  6974. if len(list) > 0 {
  6975. for _, it := range list {
  6976. //回退库存
  6977. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6978. //退库数量增加
  6979. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6980. //出库数量减少
  6981. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6982. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6983. var over_count_one int64
  6984. for _, it := range goodList {
  6985. over_count_one += it.StockCount
  6986. }
  6987. //查询该批次是否有退库数据
  6988. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6989. flow := models.VmStockFlow{
  6990. WarehousingId: it.WarehouseInfotId,
  6991. GoodId: it.GoodId,
  6992. Number: it.Number,
  6993. LicenseNumber: it.LicenseNumber,
  6994. Count: it.Count,
  6995. UserOrgId: adminInfo.CurrentOrgId,
  6996. PatientId: it.PatientId,
  6997. SystemTime: it.SysRecordTime,
  6998. ConsumableType: 7,
  6999. IsSys: 0,
  7000. WarehousingOrder: "",
  7001. WarehouseOutId: it.WarehouseOutId,
  7002. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7003. IsEdit: 0,
  7004. CancelStockId: cancel.ID,
  7005. CancelOrderNumber: cancel.OrderNumber,
  7006. Manufacturer: manufacturer.ID,
  7007. Dealer: 0,
  7008. Creator: adminInfo.AdminUser.Id,
  7009. UpdateCreator: 0,
  7010. Status: 1,
  7011. Ctime: time.Now().Unix(),
  7012. Mtime: 0,
  7013. Price: it.Price,
  7014. WarehousingDetailId: it.WarehouseInfotId,
  7015. WarehouseOutDetailId: it.ID,
  7016. CancelOutDetailId: cancelInfo.ID,
  7017. ProductDate: it.ProductDate,
  7018. ExpireDate: it.ExpiryDate,
  7019. StorehouseId: houseConfig.StorehouseOutInfo,
  7020. OverCount: over_count_one,
  7021. OperateTime: time.Now().Unix(),
  7022. }
  7023. service.CreateStockFlowOne(flow)
  7024. }
  7025. }
  7026. //查询已出库数量
  7027. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7028. if prescribingNumber < dialysisInfo.Count {
  7029. //改变数量
  7030. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7031. }
  7032. if prescribingNumber >= dialysisInfo.Count {
  7033. //删除出库表
  7034. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7035. }
  7036. //更新剩余库存
  7037. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7038. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7039. var total_count_one int64
  7040. for _, it := range stockList {
  7041. total_count_one += it.StockCount
  7042. }
  7043. //基础库插入数据
  7044. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7045. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7046. var flush_count int64
  7047. for _, it := range goodListOne {
  7048. flush_count += it.StockCount
  7049. }
  7050. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7051. if errs != nil {
  7052. goodErrcode := models.XtGoodErrcode{
  7053. UserOrgId: project.UserOrgId,
  7054. Errcode: "手动出库更新剩余出库失败",
  7055. GoodId: project.ProjectId,
  7056. Status: 1,
  7057. Ctime: time.Now().Unix(),
  7058. Mtime: 0,
  7059. Count: 0,
  7060. StockCount: 0,
  7061. Creater: creater,
  7062. BatchNumberId: 0,
  7063. WarehouseOutId: 0,
  7064. }
  7065. service.CreateGoodErrcode(goodErrcode)
  7066. }
  7067. }
  7068. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7069. fmt.Println(err)
  7070. } else {
  7071. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7072. fmt.Println(err)
  7073. }
  7074. }
  7075. c.ServeSuccessJSON(map[string]interface{}{
  7076. "msg": "删除成功",
  7077. })
  7078. return
  7079. }
  7080. func (c *HisApiController) CreateHisAdditionalCharge() {
  7081. his_patient_id, _ := c.GetInt64("his_patient_id")
  7082. patient_id, _ := c.GetInt64("patient_id")
  7083. record_date := c.GetString("record_date")
  7084. timeLayout := "2006-01-02"
  7085. loc, _ := time.LoadLocation("Local")
  7086. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7087. if err != nil {
  7088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7089. return
  7090. }
  7091. adminInfo := c.GetAdminUserInfo()
  7092. recordDateTime := theTime.Unix()
  7093. dataBody := make(map[string]interface{}, 0)
  7094. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7095. if err != nil {
  7096. utils.ErrorLog(err.Error())
  7097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7098. return
  7099. }
  7100. var additions []*models.HisAdditionalCharge
  7101. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7102. additions, _ := dataBody["addition"].([]interface{})
  7103. if len(additions) > 0 {
  7104. for _, item := range additions {
  7105. items := item.(map[string]interface{})
  7106. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7107. utils.ErrorLog("item_id")
  7108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7109. return
  7110. }
  7111. item_id := int64(items["item_id"].(float64))
  7112. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7113. utils.ErrorLog("item_name")
  7114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7115. return
  7116. }
  7117. item_name := items["item_name"].(string)
  7118. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7119. utils.ErrorLog("price")
  7120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7121. return
  7122. }
  7123. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7124. ctime := time.Now().Unix()
  7125. additional := &models.HisAdditionalCharge{
  7126. PatientId: patient_id,
  7127. HisPatientId: his_patient_id,
  7128. UserOrgId: adminInfo.CurrentOrgId,
  7129. RecordDate: recordDateTime,
  7130. CreatedTime: ctime,
  7131. UpdatedTime: ctime,
  7132. Modifier: adminInfo.AdminUser.Id,
  7133. Creator: adminInfo.AdminUser.Id,
  7134. Price: price,
  7135. ItemName: item_name,
  7136. ItemId: item_id,
  7137. Status: 1,
  7138. }
  7139. additions = append(additions, additional)
  7140. }
  7141. }
  7142. }
  7143. for _, item := range additions {
  7144. service.CreateAddtionalCharge(item)
  7145. }
  7146. c.ServeSuccessJSON(map[string]interface{}{
  7147. "msg": "创建成功",
  7148. })
  7149. }
  7150. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7151. blood_fat := c.GetString("blood_fat")
  7152. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7153. blood_sugar := c.GetString("blood_sugar")
  7154. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7155. chief_conplaint := c.GetString("chief_conplaint")
  7156. dbp := c.GetString("dbp")
  7157. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7158. delivery_way, _ := c.GetInt64("delivery_way")
  7159. diagnostic := c.GetString("diagnostic")
  7160. family_history := c.GetString("family_history")
  7161. height := c.GetString("height")
  7162. history_of_present_illness := c.GetString("history_of_present_illness")
  7163. is_infect, _ := c.GetInt64("is_infect")
  7164. past_history := c.GetString("past_history")
  7165. patient_id, _ := c.GetInt64("patient_id")
  7166. his_patient_id, _ := c.GetInt64("his_patient_id")
  7167. personal_history := c.GetString("personal_history")
  7168. pulse := c.GetString("pulse")
  7169. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7170. sbp := c.GetString("sbp")
  7171. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7172. heightfloat, _ := strconv.ParseFloat(height, 64)
  7173. sicktype := c.GetString("sick_type")
  7174. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7175. symptom := c.GetString("symptom")
  7176. sick_date := c.GetString("sick_date")
  7177. temperatures := c.GetString("temperature")
  7178. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7179. record_date := c.GetString("record_date")
  7180. breathing := c.GetString("breathing")
  7181. doctor_advice := c.GetString("doctor_advice")
  7182. remark := c.GetString("remark")
  7183. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7184. sick, _ := c.GetInt64("sick")
  7185. diagnose, _ := c.GetInt64("diagnose")
  7186. //id, _ := c.GetInt64("id")
  7187. timeLayout := "2006-01-02"
  7188. loc, _ := time.LoadLocation("Local")
  7189. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7190. allergic_history := c.GetString("allergic_history")
  7191. if err != nil {
  7192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7193. return
  7194. }
  7195. recordDateTime := theTime.Unix()
  7196. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7197. if err != nil {
  7198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7199. return
  7200. }
  7201. sickTimes := sickTime.Unix()
  7202. ctime := time.Now().Unix()
  7203. primary_disease := c.GetString("primary_disease")
  7204. confirm_failure_date := c.GetString("confirm_failure_date")
  7205. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7206. drug_allergy_history := c.GetString("drug_allergy_history")
  7207. physical_examination := c.GetString("physical_examination")
  7208. special_inspection := c.GetString("special_inspection")
  7209. lab_apparatus := c.GetString("lab_apparatus")
  7210. caseHistory := models.HisPatientCaseHistory{
  7211. HisPatientId: his_patient_id,
  7212. PatientId: patient_id,
  7213. Temperature: temperature,
  7214. BloodSugar: bloodsugarfloat,
  7215. Pulse: pulsefloat,
  7216. Sbp: sbpfloat,
  7217. Dbp: dbpfloat,
  7218. Height: heightfloat,
  7219. BloodFat: bloodfatfloat,
  7220. SickType: sick_type,
  7221. Symptom: symptom,
  7222. SickDate: sickTimes,
  7223. IsInfect: is_infect,
  7224. HistoryOfPresentIllness: history_of_present_illness,
  7225. PastHistory: past_history,
  7226. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7227. ChiefConplaint: chief_conplaint,
  7228. PersonalHistory: personal_history,
  7229. FamilyHistory: family_history,
  7230. Diagnostic: diagnostic,
  7231. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7232. Status: 1,
  7233. Ctime: ctime,
  7234. Mtime: ctime,
  7235. RecordDate: recordDateTime,
  7236. DeliveryWay: delivery_way,
  7237. Breathing: breathingfloat,
  7238. DoctorAdvice: doctor_advice,
  7239. Remark: remark,
  7240. Sick: sick,
  7241. Diagnose: diagnose,
  7242. AllergicHistory: allergic_history,
  7243. PrimaryDisease: primary_disease,
  7244. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7245. DrugAllergyHistory: drug_allergy_history,
  7246. PhysicalExamination: physical_examination,
  7247. SpecialInspection: special_inspection,
  7248. LabApparatus: lab_apparatus,
  7249. }
  7250. //查询该患者是否有病历
  7251. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7252. if errcodes == gorm.ErrRecordNotFound {
  7253. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7254. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7255. if err != nil {
  7256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7257. return
  7258. }
  7259. c.ServeSuccessJSON(map[string]interface{}{
  7260. "caseHistory": caseHistory,
  7261. "historyInfo": historyInfo,
  7262. })
  7263. return
  7264. } else if errcodes == nil {
  7265. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7266. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7267. if err != nil {
  7268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7269. return
  7270. }
  7271. c.ServeSuccessJSON(map[string]interface{}{
  7272. "caseHistory": caseHistory,
  7273. "historyInfo": historyInfo,
  7274. })
  7275. }
  7276. //查询该患者是否有病历
  7277. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7278. //if errcode == gorm.ErrRecordNotFound {
  7279. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7280. // if err != nil {
  7281. // c.ServeSuccessJSON(map[string]interface{}{
  7282. // "msg": "保存成功",
  7283. // })
  7284. // }
  7285. //} else if errcode == nil {
  7286. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7287. // return
  7288. //}
  7289. }
  7290. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7291. patient_id, _ := c.GetInt64("patient_id", 0)
  7292. adminUser := c.GetAdminUserInfo()
  7293. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7294. c.ServeSuccessJSON(map[string]interface{}{
  7295. "list": caseHistorys,
  7296. })
  7297. }
  7298. func (c *HisApiController) GetHisPatientCaseHistory() {
  7299. record_date, _ := c.GetInt64("record_date", 0)
  7300. patient_id, _ := c.GetInt64("patient_id", 0)
  7301. admin := c.GetAdminUserInfo()
  7302. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7303. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7304. c.ServeSuccessJSON(map[string]interface{}{
  7305. "info": info,
  7306. "case_history": case_history,
  7307. })
  7308. }
  7309. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7310. template_name := c.GetString("template_name")
  7311. template_remark := c.GetString("template_remark")
  7312. doctor := c.GetAdminUserInfo().AdminUser.Id
  7313. diagnostic := c.GetString("diagnostic")
  7314. chief_conplaint := c.GetString("chief_conplain")
  7315. history_of_present_illness := c.GetString("history_of_present_illness")
  7316. past_history := c.GetString("past_history")
  7317. personal_history := c.GetString("personal_history")
  7318. family_history := c.GetString("family_history")
  7319. user_name := c.GetString("user_name")
  7320. doctor_advice := c.GetString("doctor_advice")
  7321. remark := c.GetString("remark")
  7322. //record_date := c.GetString("record_date")
  7323. //fmt.Println("record_date--------",record_date)
  7324. //timeLayout := "2006-01-02"
  7325. //loc, _ := time.LoadLocation("Local")
  7326. //
  7327. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7328. //if err != nil {
  7329. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7330. // return
  7331. //}
  7332. //recordDateTime := theTime.Unix()
  7333. ctime := time.Now().Unix()
  7334. template := models.HisCaseHistoryTemplate{
  7335. HistoryOfPresentIllness: history_of_present_illness,
  7336. PastHistory: past_history,
  7337. ChiefConplaint: chief_conplaint,
  7338. PersonalHistory: personal_history,
  7339. FamilyHistory: family_history,
  7340. Diagnostic: diagnostic,
  7341. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7342. Status: 1,
  7343. Ctime: ctime,
  7344. Mtime: ctime,
  7345. RecordDate: time.Now().Unix(),
  7346. TemplateName: template_name,
  7347. TemplateRemark: template_remark,
  7348. Creator: doctor,
  7349. Modifier: doctor,
  7350. UserName: user_name,
  7351. DoctorAdvice: doctor_advice,
  7352. Remark: remark,
  7353. }
  7354. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7355. if err == nil {
  7356. c.ServeSuccessJSON(map[string]interface{}{
  7357. "msg": "保存成功",
  7358. })
  7359. } else {
  7360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7361. return
  7362. }
  7363. }
  7364. func (c *HisApiController) GetCaseHistoryTemplate() {
  7365. timeLayout := "2006-01-02"
  7366. loc, _ := time.LoadLocation("Local")
  7367. keyword := c.GetString("keyword")
  7368. start_time := c.GetString("start_time")
  7369. end_time := c.GetString("end_time")
  7370. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7371. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7372. admin := c.GetAdminUserInfo()
  7373. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7374. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7375. c.ServeSuccessJSON(map[string]interface{}{
  7376. "template": template,
  7377. //"history": history,
  7378. })
  7379. }
  7380. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7381. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7382. utils.ErrorLog("drug_name")
  7383. return enums.ErrorCodeParamWrong
  7384. }
  7385. adviceName, _ := json["drug_name"].(string)
  7386. if len(adviceName) == 0 {
  7387. utils.ErrorLog("len(advice_name) == 0")
  7388. return enums.ErrorCodeParamWrong
  7389. }
  7390. advice.AdviceName = adviceName
  7391. adviceDesc, _ := json["advice_desc"].(string)
  7392. advice.AdviceDesc = adviceDesc
  7393. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7394. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7395. advice.DrugSpec = drugSpec
  7396. }
  7397. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7398. remark, _ := json["remark"].(string)
  7399. advice.Remark = remark
  7400. }
  7401. if json["id"] == nil {
  7402. advice.DrugId = 0
  7403. } else {
  7404. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7405. drug_id := int64(json["id"].(float64))
  7406. advice.DrugId = drug_id
  7407. }
  7408. }
  7409. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7410. advice_id := int64(json["advice_id"].(float64))
  7411. advice.ID = advice_id
  7412. if advice.ID > 0 {
  7413. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7414. if err == nil {
  7415. if hisAdvice.ID > 0 {
  7416. advice.ExecutionTime = hisAdvice.ExecutionTime
  7417. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7418. advice.ExecutionState = hisAdvice.ExecutionState
  7419. advice.CheckTime = hisAdvice.CheckTime
  7420. advice.Checker = hisAdvice.Checker
  7421. advice.CheckState = hisAdvice.CheckState
  7422. advice.StartTime = hisAdvice.StartTime
  7423. advice.FeedetlSn = hisAdvice.FeedetlSn
  7424. }
  7425. }
  7426. }
  7427. }
  7428. //
  7429. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7430. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7431. // advice.ExecutionTime = execution_time
  7432. //}
  7433. //
  7434. //
  7435. //
  7436. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7437. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7438. // advice.ExecutionStaff = execution_staff
  7439. //}
  7440. //
  7441. //
  7442. //
  7443. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7444. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7445. // advice.ExecutionState = execution_state
  7446. //}
  7447. //
  7448. //
  7449. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7450. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7451. // advice.CheckTime = check_time
  7452. //}
  7453. //
  7454. //
  7455. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7456. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7457. // advice.CheckState = check_state
  7458. //}
  7459. //
  7460. //
  7461. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7462. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7463. // advice.Checker = checker
  7464. //}
  7465. //
  7466. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7467. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7468. // advice.StartTime = start_time
  7469. //}
  7470. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7471. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7472. advice.IsSelfDrug = is_self_drug
  7473. }
  7474. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7475. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7476. drug_way_count, _ := json["drug_way_count"].(string)
  7477. advice.DrugWayCount = drug_way_count
  7478. }
  7479. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7480. drugSpecUnit, _ := json["min_unit"].(string)
  7481. advice.DrugSpecUnit = drugSpecUnit
  7482. }
  7483. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7484. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7485. advice.SingleDose = singleDose
  7486. }
  7487. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7488. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7489. advice.SingleDoseUnit = singleDoseUnit
  7490. }
  7491. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7492. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7493. advice.PrescribingNumber = prescribingNumber
  7494. }
  7495. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7496. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7497. advice.PrescribingNumberUnit = prescribingNumberUnit
  7498. }
  7499. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7500. deliveryWay, _ := json["delivery_way"].(string)
  7501. advice.DeliveryWay = deliveryWay
  7502. }
  7503. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7504. executionFrequency, _ := json["execution_frequency"].(string)
  7505. advice.ExecutionFrequency = executionFrequency
  7506. }
  7507. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7508. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7509. advice.Price = price
  7510. }
  7511. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7512. med_list_codg, _ := json["medical_insurance_number"].(string)
  7513. advice.MedListCodg = med_list_codg
  7514. }
  7515. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7516. day := int64(json["day"].(float64))
  7517. advice.Day = day
  7518. }
  7519. return 0
  7520. }
  7521. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7522. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7523. id := int64(json["id"].(float64))
  7524. project.ID = id
  7525. historyProject, _ := service.GetHisProjectByID(id)
  7526. project.FeedetlSn = historyProject.FeedetlSn
  7527. }
  7528. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7529. project_id := int64(json["project_id"].(float64))
  7530. project.ProjectId = project_id
  7531. }
  7532. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7533. // price := int64(json["price"].(float64))
  7534. // formatInt_price := strconv.FormatInt(price, 10)
  7535. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7536. // project.Price = float_price
  7537. // }
  7538. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7539. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7540. project.Price = price
  7541. }
  7542. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7543. total, _ := json["total"].(string)
  7544. project.Count = total
  7545. }
  7546. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7547. medical_code, _ := json["medical_code"].(string)
  7548. project.MedListCodg = medical_code
  7549. }
  7550. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7551. single_dose, _ := json["single_dose"].(string)
  7552. project.SingleDose = single_dose
  7553. }
  7554. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7555. delivery_way, _ := json["delivery_way"].(string)
  7556. project.DeliveryWay = delivery_way
  7557. }
  7558. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7559. execution_frequency, _ := json["execution_frequency"].(string)
  7560. project.ExecutionFrequency = execution_frequency
  7561. }
  7562. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7563. remark, _ := json["remark"].(string)
  7564. project.Remark = remark
  7565. }
  7566. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7567. day, _ := json["number_days"].(string)
  7568. project.Day = day
  7569. }
  7570. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7571. unit, _ := json["unit"].(string)
  7572. project.Unit = unit
  7573. }
  7574. return 0
  7575. }
  7576. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7577. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7578. id := int64(json["id"].(float64))
  7579. historyAddtions, _ := service.GetHisAdditionByID(id)
  7580. additionalCharge.ID = id
  7581. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  7582. }
  7583. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7584. item_id := int64(json["item_id"].(float64))
  7585. additionalCharge.ItemId = item_id
  7586. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7587. if config.ID > 0 {
  7588. if len(config.Code) > 0 {
  7589. additionalCharge.MedListCodg = config.Code
  7590. }
  7591. }
  7592. }
  7593. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7594. // price := int64(json["price"].(float64))
  7595. // formatInt_price := strconv.FormatInt(price, 10)
  7596. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7597. // additionalCharge.Price = float_price
  7598. // }
  7599. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7600. // price := int64(json["price"].(float64))
  7601. // formatInt_price := strconv.FormatInt(price, 10)
  7602. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7603. // additionalCharge.Price = float_price
  7604. //}
  7605. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7606. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7607. additionalCharge.Price = price
  7608. }
  7609. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7610. count, _ := json["count"].(string)
  7611. counts, _ := strconv.ParseInt(count, 10, 64)
  7612. additionalCharge.Count = counts
  7613. }
  7614. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7615. item_name, _ := json["item_name"].(string)
  7616. additionalCharge.ItemName = item_name
  7617. }
  7618. return 0
  7619. }
  7620. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7621. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7622. utils.ErrorLog("drug_name")
  7623. return enums.ErrorCodeParamWrong
  7624. }
  7625. adviceName, _ := json["drug_name"].(string)
  7626. if len(adviceName) == 0 {
  7627. utils.ErrorLog("len(advice_name) == 0")
  7628. return enums.ErrorCodeParamWrong
  7629. }
  7630. advice.AdviceName = adviceName
  7631. adviceDesc, _ := json["advice_desc"].(string)
  7632. advice.AdviceDesc = adviceDesc
  7633. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7634. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7635. advice.DrugSpec = drugSpec
  7636. }
  7637. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7638. remark, _ := json["remark"].(string)
  7639. advice.Remark = remark
  7640. }
  7641. if json["id"] == nil {
  7642. advice.DrugId = 0
  7643. } else {
  7644. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7645. drug_id := int64(json["id"].(float64))
  7646. advice.DrugId = drug_id
  7647. }
  7648. }
  7649. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7650. groupno := int64(json["groupno"].(float64))
  7651. advice.Groupno = groupno
  7652. }
  7653. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7654. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7655. advice.IsSelfDrug = is_self_drug
  7656. }
  7657. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7658. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7659. drug_way_count, _ := json["drug_way_count"].(string)
  7660. advice.DrugWayCount = drug_way_count
  7661. }
  7662. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7663. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7664. advice.HospApprFlag = hosp_appr_flag
  7665. }
  7666. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7667. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7668. advice.PrescribingNumber = prescribingNumber
  7669. }
  7670. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7671. // frequency_type := int64(json["frequency_type"].(float64))
  7672. // advice.FrequencyType = frequency_type
  7673. //}
  7674. //
  7675. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7676. // day_count := int64(json["day_count"].(float64))
  7677. // advice.DayCount = day_count
  7678. //}
  7679. //
  7680. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7681. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7682. // week_day, _ := json["week_day"].(string)
  7683. // advice.WeekDay = week_day
  7684. //}
  7685. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7686. drugSpecUnit, _ := json["min_unit"].(string)
  7687. advice.DrugSpecUnit = drugSpecUnit
  7688. }
  7689. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7690. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7691. advice.SingleDose = singleDose
  7692. }
  7693. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7694. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7695. advice.SingleDoseUnit = singleDoseUnit
  7696. }
  7697. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7698. deliveryWay, _ := json["delivery_way"].(string)
  7699. advice.DeliveryWay = deliveryWay
  7700. }
  7701. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7702. executionFrequency, _ := json["execution_frequency"].(string)
  7703. advice.ExecutionFrequency = executionFrequency
  7704. }
  7705. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7706. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7707. advice.Price = price
  7708. }
  7709. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7710. med_list_codg, _ := json["medical_insurance_number"].(string)
  7711. advice.MedListCodg = med_list_codg
  7712. }
  7713. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7714. day := int64(json["day"].(float64))
  7715. advice.Day = day
  7716. }
  7717. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7718. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7719. advice.PrescribingNumberUnit = prescribingNumberUnit
  7720. }
  7721. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7722. advice_id := int64(json["advice_id"].(float64))
  7723. advice.ID = advice_id
  7724. if advice.ID > 0 {
  7725. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7726. if err == nil {
  7727. if hisAdvice.ID > 0 {
  7728. advice.ExecutionTime = hisAdvice.ExecutionTime
  7729. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7730. advice.ExecutionState = hisAdvice.ExecutionState
  7731. advice.CheckTime = hisAdvice.CheckTime
  7732. advice.Checker = hisAdvice.Checker
  7733. advice.CheckState = hisAdvice.CheckState
  7734. advice.StartTime = hisAdvice.StartTime
  7735. advice.HospApprFlag = hisAdvice.HospApprFlag
  7736. advice.IsMedicine = hisAdvice.IsMedicine
  7737. if hisAdvice.UserOrgId == 10028 {
  7738. 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 {
  7739. advice.ExecutionTime = 0
  7740. advice.ExecutionStaff = 0
  7741. advice.ExecutionState = 2
  7742. advice.CheckTime = 0
  7743. advice.Checker = 0
  7744. advice.CheckState = 2
  7745. }
  7746. } else {
  7747. 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 {
  7748. advice.ExecutionTime = 0
  7749. advice.ExecutionStaff = 0
  7750. advice.ExecutionState = 2
  7751. advice.CheckTime = 0
  7752. advice.Checker = 0
  7753. advice.CheckState = 2
  7754. advice.UpdatedTime = time.Now().Unix()
  7755. }
  7756. }
  7757. //advice.Groupno = hisAdvice.Groupno
  7758. }
  7759. }
  7760. }
  7761. }
  7762. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7763. //
  7764. //if drugStockConfig.IsOpen == 1 {
  7765. //
  7766. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7767. // if advice.ID == 0 { //医嘱不存在
  7768. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7769. // drug.Total = drug.Total - advice.PrescribingNumber
  7770. // service.UpdateBaseDrugLib(&drug)
  7771. //
  7772. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7773. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7774. // drug.Total = drug.Total - num
  7775. // service.UpdateBaseDrugLib(&drug)
  7776. // }
  7777. //
  7778. // } else if advice.ID > 0 { //医嘱存在
  7779. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7780. // var num float64
  7781. //
  7782. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7783. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7784. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7785. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7786. // drug.Total = drug.Total + num
  7787. // service.UpdateBaseDrugLib(&drug)
  7788. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7789. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7790. // drug.Total = drug.Total - num
  7791. // service.UpdateBaseDrugLib(&drug)
  7792. // }
  7793. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7794. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7795. // if num2 > advice.PrescribingNumber {
  7796. // num = num2 - advice.PrescribingNumber
  7797. // drug.Total = drug.Total + num
  7798. // service.UpdateBaseDrugLib(&drug)
  7799. // } else if num2 < advice.PrescribingNumber {
  7800. // num = advice.PrescribingNumber - num2
  7801. // drug.Total = drug.Total - num
  7802. // service.UpdateBaseDrugLib(&drug)
  7803. // }
  7804. //
  7805. // }
  7806. //
  7807. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7808. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7809. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7810. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7811. // if num1 > num2 {
  7812. // num = num1 - num2
  7813. // drug.Total = drug.Total + num
  7814. // service.UpdateBaseDrugLib(&drug)
  7815. // } else if num1 < num2 {
  7816. // num = num2 - num1
  7817. // drug.Total = drug.Total - num
  7818. // service.UpdateBaseDrugLib(&drug)
  7819. // }
  7820. //
  7821. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7822. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7823. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7824. // if hisAdvice.PrescribingNumber > num2 {
  7825. // num = hisAdvice.PrescribingNumber - num2
  7826. // drug.Total = drug.Total + num
  7827. // service.UpdateBaseDrugLib(&drug)
  7828. // } else if num2 < advice.PrescribingNumber {
  7829. // num = num2 - hisAdvice.PrescribingNumber
  7830. // drug.Total = drug.Total - num
  7831. // service.UpdateBaseDrugLib(&drug)
  7832. // }
  7833. //
  7834. // }
  7835. // }
  7836. // }
  7837. //}
  7838. //
  7839. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7840. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7841. // advice.ExecutionTime = execution_time
  7842. //}
  7843. //
  7844. //
  7845. //
  7846. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7847. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7848. // advice.ExecutionStaff = execution_staff
  7849. //}
  7850. //
  7851. //
  7852. //
  7853. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7854. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7855. // advice.ExecutionState = execution_state
  7856. //}
  7857. //
  7858. //
  7859. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7860. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7861. // advice.CheckTime = check_time
  7862. //}
  7863. //
  7864. //
  7865. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7866. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7867. // advice.CheckState = check_state
  7868. //}
  7869. //
  7870. //
  7871. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7872. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7873. // advice.Checker = checker
  7874. //}
  7875. //
  7876. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7877. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7878. // advice.StartTime = start_time
  7879. //}
  7880. return 0
  7881. }
  7882. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7883. project.ExecutionStaff = 0
  7884. project.ExecutionState = 2
  7885. project.ExecutionTime = 0
  7886. project.Checker = 0
  7887. project.CheckState = 2
  7888. project.CheckTime = 0
  7889. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7890. id := int64(json["id"].(float64))
  7891. project.ID = id
  7892. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7893. project.ExecutionStaff = temp_project.ExecutionStaff
  7894. project.ExecutionState = temp_project.ExecutionState
  7895. project.ExecutionTime = temp_project.ExecutionTime
  7896. project.Checker = temp_project.Checker
  7897. project.CheckState = temp_project.CheckState
  7898. project.CheckTime = temp_project.CheckTime
  7899. project.TeamId = temp_project.TeamId
  7900. }
  7901. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7902. types := int64(json["type"].(float64))
  7903. project.Type = types
  7904. }
  7905. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7906. project_id := int64(json["project_id"].(float64))
  7907. project.ProjectId = project_id
  7908. }
  7909. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7910. team_id := int64(json["team_id"].(float64))
  7911. project.TeamId = team_id
  7912. }
  7913. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7914. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7915. project.Price = price
  7916. }
  7917. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7918. total, _ := json["total"].(string)
  7919. //totals, _ := strconv.ParseInt(total, 10, 64)
  7920. project.Count = total
  7921. }
  7922. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7923. medical_code, _ := json["medical_code"].(string)
  7924. project.MedListCodg = medical_code
  7925. }
  7926. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7927. single_dose, _ := json["single_dose"].(string)
  7928. project.SingleDose = single_dose
  7929. }
  7930. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7931. delivery_way, _ := json["delivery_way"].(string)
  7932. project.DeliveryWay = delivery_way
  7933. }
  7934. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7935. execution_frequency, _ := json["execution_frequency"].(string)
  7936. project.ExecutionFrequency = execution_frequency
  7937. }
  7938. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7939. remark, _ := json["remark"].(string)
  7940. project.Remark = remark
  7941. }
  7942. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7943. day, _ := json["number_days"].(string)
  7944. project.Day = day
  7945. }
  7946. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7947. unit, _ := json["unit"].(string)
  7948. project.Unit = unit
  7949. }
  7950. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7951. // frequency_type := int64(json["frequency_type"].(float64))
  7952. // project.FrequencyType = frequency_type
  7953. //}
  7954. //
  7955. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7956. // day_count := int64(json["day_count"].(float64))
  7957. // project.DayCount = day_count
  7958. //}
  7959. //
  7960. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7961. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7962. // week_day, _ := json["week_day"].(string)
  7963. // project.WeekDay = week_day
  7964. //}
  7965. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7966. //
  7967. //if project.ID == 0 {
  7968. // if stockConfig.IsOpen == 1 {
  7969. // if project.Type == 3 {
  7970. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7971. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7972. // good.Total = good.Total - f_count
  7973. // service.UpdateGoodInfo(&good)
  7974. // }
  7975. // }
  7976. //
  7977. //} else {
  7978. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7979. //
  7980. // if stockConfig.IsOpen == 1 {
  7981. // if project.Type == 3 {
  7982. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7983. // if project.Count < temp_project.Count {
  7984. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7985. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7986. //
  7987. // other_count := f_count_two - f_count_one
  7988. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7989. // good.Total = good.Total + other_count_two
  7990. // service.UpdateGoodInfo(&good)
  7991. // } else if project.Count > temp_project.Count {
  7992. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7993. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7994. //
  7995. // other_count := f_count_one - f_count_two
  7996. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7997. // good.Total = good.Total - other_count_two
  7998. // service.UpdateGoodInfo(&good)
  7999. // }
  8000. //
  8001. // }
  8002. // }
  8003. //
  8004. //}
  8005. return 0
  8006. }
  8007. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8008. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8009. utils.ErrorLog("drug_name")
  8010. return enums.ErrorCodeParamWrong
  8011. }
  8012. adviceName, _ := json["drug_name"].(string)
  8013. if len(adviceName) == 0 {
  8014. utils.ErrorLog("len(advice_name) == 0")
  8015. return enums.ErrorCodeParamWrong
  8016. }
  8017. advice.AdviceName = adviceName
  8018. adviceDesc, _ := json["advice_desc"].(string)
  8019. advice.AdviceDesc = adviceDesc
  8020. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8021. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8022. advice.DrugSpec = drugSpec
  8023. }
  8024. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8025. remark, _ := json["remark"].(string)
  8026. advice.Remark = remark
  8027. }
  8028. if json["id"] == nil {
  8029. advice.DrugId = 0
  8030. } else {
  8031. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8032. drug_id := int64(json["id"].(float64))
  8033. advice.DrugId = drug_id
  8034. }
  8035. }
  8036. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8037. groupno := int64(json["groupno"].(float64))
  8038. advice.Groupno = groupno
  8039. }
  8040. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8041. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8042. advice.IsSelfDrug = is_self_drug
  8043. }
  8044. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8045. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8046. drug_way_count, _ := json["drug_way_count"].(string)
  8047. advice.DrugWayCount = drug_way_count
  8048. }
  8049. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8050. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8051. advice.HospApprFlag = hosp_appr_flag
  8052. }
  8053. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8054. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8055. advice.PrescribingNumber = prescribingNumber
  8056. }
  8057. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8058. // frequency_type := int64(json["frequency_type"].(float64))
  8059. // advice.FrequencyType = frequency_type
  8060. //}
  8061. //
  8062. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8063. // day_count := int64(json["day_count"].(float64))
  8064. // advice.DayCount = day_count
  8065. //}
  8066. //
  8067. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8068. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8069. // week_day, _ := json["week_day"].(string)
  8070. // advice.WeekDay = week_day
  8071. //}
  8072. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8073. drugSpecUnit, _ := json["min_unit"].(string)
  8074. advice.DrugSpecUnit = drugSpecUnit
  8075. }
  8076. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8077. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8078. advice.SingleDose = singleDose
  8079. }
  8080. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8081. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8082. advice.SingleDoseUnit = singleDoseUnit
  8083. }
  8084. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8085. deliveryWay, _ := json["delivery_way"].(string)
  8086. advice.DeliveryWay = deliveryWay
  8087. }
  8088. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8089. executionFrequency, _ := json["execution_frequency"].(string)
  8090. advice.ExecutionFrequency = executionFrequency
  8091. }
  8092. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8093. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8094. advice.Price = price
  8095. }
  8096. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8097. med_list_codg, _ := json["medical_insurance_number"].(string)
  8098. advice.MedListCodg = med_list_codg
  8099. }
  8100. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8101. day := int64(json["day"].(float64))
  8102. advice.Day = day
  8103. }
  8104. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8105. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8106. advice.PrescribingNumberUnit = prescribingNumberUnit
  8107. }
  8108. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8109. advice_id := int64(json["advice_id"].(float64))
  8110. advice.ID = advice_id
  8111. if advice.ID > 0 {
  8112. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8113. if err == nil {
  8114. if hisAdvice.ID > 0 {
  8115. advice.ExecutionTime = hisAdvice.ExecutionTime
  8116. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8117. advice.ExecutionState = hisAdvice.ExecutionState
  8118. advice.CheckTime = hisAdvice.CheckTime
  8119. advice.Checker = hisAdvice.Checker
  8120. advice.DrugCode = hisAdvice.DrugCode
  8121. advice.CheckState = hisAdvice.CheckState
  8122. advice.StartTime = hisAdvice.StartTime
  8123. advice.HospApprFlag = hisAdvice.HospApprFlag
  8124. advice.IsMedicine = hisAdvice.IsMedicine
  8125. if hisAdvice.UserOrgId == 10028 {
  8126. 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 {
  8127. advice.ExecutionTime = 0
  8128. advice.ExecutionStaff = 0
  8129. advice.ExecutionState = 2
  8130. advice.CheckTime = 0
  8131. advice.Checker = 0
  8132. advice.CheckState = 2
  8133. }
  8134. } else {
  8135. 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 {
  8136. advice.ExecutionTime = 0
  8137. advice.ExecutionStaff = 0
  8138. advice.ExecutionState = 2
  8139. advice.CheckTime = 0
  8140. advice.Checker = 0
  8141. advice.CheckState = 2
  8142. //advice.UpdatedTime = time.Now().Unix()
  8143. advice.CreatedTime = hisAdvice.CreatedTime
  8144. advice.UpdatedTime = time.Now().Unix()
  8145. } else {
  8146. advice.CreatedTime = hisAdvice.CreatedTime
  8147. advice.UpdatedTime = hisAdvice.UpdatedTime
  8148. }
  8149. }
  8150. //advice.Groupno = hisAdvice.Groupno
  8151. } else {
  8152. advice.IsMedicine = 0
  8153. ctime := time.Now().Unix()
  8154. advice.CreatedTime = ctime
  8155. advice.UpdatedTime = ctime
  8156. }
  8157. }
  8158. } else {
  8159. advice.IsMedicine = 0
  8160. ctime := time.Now().Unix()
  8161. advice.CreatedTime = ctime
  8162. advice.UpdatedTime = ctime
  8163. }
  8164. }
  8165. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8166. //
  8167. //if drugStockConfig.IsOpen == 1 {
  8168. //
  8169. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8170. // if advice.ID == 0 { //医嘱不存在
  8171. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8172. // drug.Total = drug.Total - advice.PrescribingNumber
  8173. // service.UpdateBaseDrugLib(&drug)
  8174. //
  8175. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8176. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8177. // drug.Total = drug.Total - num
  8178. // service.UpdateBaseDrugLib(&drug)
  8179. // }
  8180. //
  8181. // } else if advice.ID > 0 { //医嘱存在
  8182. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8183. // var num float64
  8184. //
  8185. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8186. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8187. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8188. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8189. // drug.Total = drug.Total + num
  8190. // service.UpdateBaseDrugLib(&drug)
  8191. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8192. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8193. // drug.Total = drug.Total - num
  8194. // service.UpdateBaseDrugLib(&drug)
  8195. // }
  8196. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8197. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8198. // if num2 > advice.PrescribingNumber {
  8199. // num = num2 - advice.PrescribingNumber
  8200. // drug.Total = drug.Total + num
  8201. // service.UpdateBaseDrugLib(&drug)
  8202. // } else if num2 < advice.PrescribingNumber {
  8203. // num = advice.PrescribingNumber - num2
  8204. // drug.Total = drug.Total - num
  8205. // service.UpdateBaseDrugLib(&drug)
  8206. // }
  8207. //
  8208. // }
  8209. //
  8210. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8211. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8212. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8213. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8214. // if num1 > num2 {
  8215. // num = num1 - num2
  8216. // drug.Total = drug.Total + num
  8217. // service.UpdateBaseDrugLib(&drug)
  8218. // } else if num1 < num2 {
  8219. // num = num2 - num1
  8220. // drug.Total = drug.Total - num
  8221. // service.UpdateBaseDrugLib(&drug)
  8222. // }
  8223. //
  8224. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8225. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8226. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8227. // if hisAdvice.PrescribingNumber > num2 {
  8228. // num = hisAdvice.PrescribingNumber - num2
  8229. // drug.Total = drug.Total + num
  8230. // service.UpdateBaseDrugLib(&drug)
  8231. // } else if num2 < advice.PrescribingNumber {
  8232. // num = num2 - hisAdvice.PrescribingNumber
  8233. // drug.Total = drug.Total - num
  8234. // service.UpdateBaseDrugLib(&drug)
  8235. // }
  8236. //
  8237. // }
  8238. // }
  8239. // }
  8240. //}
  8241. //
  8242. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8243. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8244. // advice.ExecutionTime = execution_time
  8245. //}
  8246. //
  8247. //
  8248. //
  8249. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8250. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8251. // advice.ExecutionStaff = execution_staff
  8252. //}
  8253. //
  8254. //
  8255. //
  8256. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8257. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8258. // advice.ExecutionState = execution_state
  8259. //}
  8260. //
  8261. //
  8262. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8263. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8264. // advice.CheckTime = check_time
  8265. //}
  8266. //
  8267. //
  8268. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8269. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8270. // advice.CheckState = check_state
  8271. //}
  8272. //
  8273. //
  8274. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8275. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8276. // advice.Checker = checker
  8277. //}
  8278. //
  8279. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8280. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8281. // advice.StartTime = start_time
  8282. //}
  8283. return 0
  8284. }
  8285. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8286. project.ExecutionStaff = 0
  8287. project.ExecutionState = 2
  8288. project.ExecutionTime = 0
  8289. project.Checker = 0
  8290. project.CheckState = 2
  8291. project.CheckTime = 0
  8292. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8293. id := int64(json["id"].(float64))
  8294. project.ID = id
  8295. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8296. project.ExecutionStaff = temp_project.ExecutionStaff
  8297. project.ExecutionState = temp_project.ExecutionState
  8298. project.ExecutionTime = temp_project.ExecutionTime
  8299. project.Checker = temp_project.Checker
  8300. project.CheckState = temp_project.CheckState
  8301. project.CheckTime = temp_project.CheckTime
  8302. project.TeamId = temp_project.TeamId
  8303. }
  8304. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8305. types := int64(json["type"].(float64))
  8306. project.Type = types
  8307. }
  8308. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8309. project_id := int64(json["project_id"].(float64))
  8310. project.ProjectId = project_id
  8311. }
  8312. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8313. team_id := int64(json["team_id"].(float64))
  8314. project.TeamId = team_id
  8315. }
  8316. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8317. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8318. project.Price = price
  8319. }
  8320. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8321. total, _ := json["total"].(string)
  8322. //totals, _ := strconv.ParseInt(total, 10, 64)
  8323. project.Count = total
  8324. }
  8325. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8326. medical_code, _ := json["medical_code"].(string)
  8327. project.MedListCodg = medical_code
  8328. }
  8329. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8330. single_dose, _ := json["single_dose"].(string)
  8331. project.SingleDose = single_dose
  8332. }
  8333. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8334. delivery_way, _ := json["delivery_way"].(string)
  8335. project.DeliveryWay = delivery_way
  8336. }
  8337. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8338. execution_frequency, _ := json["execution_frequency"].(string)
  8339. project.ExecutionFrequency = execution_frequency
  8340. }
  8341. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8342. remark, _ := json["remark"].(string)
  8343. project.Remark = remark
  8344. }
  8345. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8346. day, _ := json["number_days"].(string)
  8347. project.Day = day
  8348. }
  8349. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8350. unit, _ := json["unit"].(string)
  8351. project.Unit = unit
  8352. }
  8353. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8354. // frequency_type := int64(json["frequency_type"].(float64))
  8355. // project.FrequencyType = frequency_type
  8356. //}
  8357. //
  8358. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8359. // day_count := int64(json["day_count"].(float64))
  8360. // project.DayCount = day_count
  8361. //}
  8362. //
  8363. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8364. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8365. // week_day, _ := json["week_day"].(string)
  8366. // project.WeekDay = week_day
  8367. //}
  8368. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8369. //
  8370. //if project.ID == 0 {
  8371. // if stockConfig.IsOpen == 1 {
  8372. // if project.Type == 3 {
  8373. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8374. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8375. // good.Total = good.Total - f_count
  8376. // service.UpdateGoodInfo(&good)
  8377. // }
  8378. // }
  8379. //
  8380. //} else {
  8381. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8382. //
  8383. // if stockConfig.IsOpen == 1 {
  8384. // if project.Type == 3 {
  8385. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8386. // if project.Count < temp_project.Count {
  8387. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8388. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8389. //
  8390. // other_count := f_count_two - f_count_one
  8391. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8392. // good.Total = good.Total + other_count_two
  8393. // service.UpdateGoodInfo(&good)
  8394. // } else if project.Count > temp_project.Count {
  8395. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8396. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8397. //
  8398. // other_count := f_count_one - f_count_two
  8399. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8400. // good.Total = good.Total - other_count_two
  8401. // service.UpdateGoodInfo(&good)
  8402. // }
  8403. //
  8404. // }
  8405. // }
  8406. //
  8407. //}
  8408. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8409. id := int64(json["id"].(float64))
  8410. if id > 0 {
  8411. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8412. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8413. fmt.Println("666666")
  8414. project.Mtime = time.Now().Unix()
  8415. project.Ctime = temp_project.Ctime
  8416. } else {
  8417. project.Mtime = temp_project.Mtime
  8418. project.Ctime = temp_project.Ctime
  8419. }
  8420. } else {
  8421. ctime := time.Now().Unix()
  8422. project.Mtime = ctime
  8423. project.Ctime = ctime
  8424. }
  8425. }
  8426. return 0
  8427. }
  8428. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8429. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8430. id := int64(json["id"].(float64))
  8431. additionalCharge.ID = id
  8432. }
  8433. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8434. item_id := int64(json["item_id"].(float64))
  8435. additionalCharge.ItemId = item_id
  8436. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8437. if config.ID > 0 {
  8438. if len(config.Code) > 0 {
  8439. additionalCharge.MedListCodg = config.Code
  8440. }
  8441. }
  8442. }
  8443. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8444. // price := int64(json["price"].(float64))
  8445. // formatInt_price := strconv.FormatInt(price, 10)
  8446. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8447. // additionalCharge.Price = float_price
  8448. // }
  8449. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8450. // price := int64(json["price"].(float64))
  8451. // formatInt_price := strconv.FormatInt(price, 10)
  8452. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8453. // additionalCharge.Price = float_price
  8454. //}
  8455. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8456. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8457. additionalCharge.Price = price
  8458. }
  8459. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8460. count, _ := json["count"].(string)
  8461. counts, _ := strconv.ParseInt(count, 10, 64)
  8462. additionalCharge.Count = counts
  8463. }
  8464. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8465. item_name, _ := json["item_name"].(string)
  8466. additionalCharge.ItemName = item_name
  8467. }
  8468. return 0
  8469. }
  8470. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8471. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8472. utils.ErrorLog("drug_name")
  8473. return enums.ErrorCodeParamWrong
  8474. }
  8475. adviceName, _ := json["drug_name"].(string)
  8476. if len(adviceName) == 0 {
  8477. utils.ErrorLog("len(advice_name) == 0")
  8478. return enums.ErrorCodeParamWrong
  8479. }
  8480. advice.AdviceName = adviceName
  8481. adviceDesc, _ := json["advice_desc"].(string)
  8482. advice.AdviceDesc = adviceDesc
  8483. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8484. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8485. advice.DrugSpec = drugSpec
  8486. }
  8487. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8488. remark, _ := json["remark"].(string)
  8489. advice.Remark = remark
  8490. }
  8491. if json["id"] == nil {
  8492. advice.DrugId = 0
  8493. } else {
  8494. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8495. drug_id := int64(json["id"].(float64))
  8496. advice.DrugId = drug_id
  8497. }
  8498. }
  8499. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8500. groupno := int64(json["groupno"].(float64))
  8501. advice.Groupno = groupno
  8502. }
  8503. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8504. drugSpecUnit, _ := json["min_unit"].(string)
  8505. advice.DrugSpecUnit = drugSpecUnit
  8506. }
  8507. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8508. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8509. advice.SingleDose = singleDose
  8510. }
  8511. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8512. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8513. advice.SingleDoseUnit = singleDoseUnit
  8514. }
  8515. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8516. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8517. advice.PrescribingNumber = prescribingNumber
  8518. }
  8519. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8520. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8521. advice.PrescribingNumberUnit = prescribingNumberUnit
  8522. }
  8523. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8524. deliveryWay, _ := json["delivery_way"].(string)
  8525. advice.DeliveryWay = deliveryWay
  8526. }
  8527. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8528. executionFrequency, _ := json["execution_frequency"].(string)
  8529. advice.ExecutionFrequency = executionFrequency
  8530. }
  8531. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8532. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8533. advice.Price = price
  8534. }
  8535. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8536. med_list_codg, _ := json["medical_insurance_number"].(string)
  8537. advice.MedListCodg = med_list_codg
  8538. }
  8539. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8540. day := int64(json["day"].(float64))
  8541. advice.Day = day
  8542. }
  8543. advice.FrequencyType = 1
  8544. return 0
  8545. }
  8546. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8547. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8548. types := int64(json["type"].(float64))
  8549. project.Type = types
  8550. }
  8551. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8552. project_id := int64(json["project_id"].(float64))
  8553. project.ProjectId = project_id
  8554. }
  8555. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8556. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8557. project.Price = price
  8558. }
  8559. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8560. total, _ := json["total"].(string)
  8561. //totals, _ := strconv.ParseInt(total, 10, 64)
  8562. project.Count = total
  8563. }
  8564. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8565. medical_code, _ := json["medical_code"].(string)
  8566. project.MedListCodg = medical_code
  8567. }
  8568. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8569. single_dose, _ := json["single_dose"].(string)
  8570. project.SingleDose = single_dose
  8571. }
  8572. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8573. delivery_way, _ := json["delivery_way"].(string)
  8574. project.DeliveryWay = delivery_way
  8575. }
  8576. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8577. execution_frequency, _ := json["execution_frequency"].(string)
  8578. project.ExecutionFrequency = execution_frequency
  8579. }
  8580. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8581. remark, _ := json["remark"].(string)
  8582. project.Remark = remark
  8583. }
  8584. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8585. day, _ := json["number_days"].(string)
  8586. project.Day = day
  8587. }
  8588. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8589. unit, _ := json["unit"].(string)
  8590. project.Unit = unit
  8591. }
  8592. project.FrequencyType = 1
  8593. return 0
  8594. }
  8595. func (c *HisApiController) GetHisOrderListTwo() {
  8596. start_time := c.GetString("start_time")
  8597. end_time := c.GetString("end_time")
  8598. timeLayout := "2006-01-02"
  8599. loc, _ := time.LoadLocation("Local")
  8600. var startTime int64
  8601. if len(start_time) > 0 {
  8602. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8603. if err != nil {
  8604. //fmt.Println(err)
  8605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8606. return
  8607. }
  8608. startTime = theTime.Unix()
  8609. }
  8610. var endTime int64
  8611. if len(end_time) > 0 {
  8612. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8613. if err != nil {
  8614. utils.ErrorLog(err.Error())
  8615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8616. return
  8617. }
  8618. endTime = theTime.Unix()
  8619. }
  8620. adminUser := c.GetAdminUserInfo()
  8621. org_id := adminUser.CurrentOrgId
  8622. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  8623. if err == nil {
  8624. c.ServeSuccessJSON(map[string]interface{}{
  8625. "order2": order,
  8626. })
  8627. } else {
  8628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8629. return
  8630. }
  8631. }
  8632. func (c *HisApiController) GetHisOrderList() {
  8633. page, _ := c.GetInt64("page", -1)
  8634. limit, _ := c.GetInt64("limit", -1)
  8635. start_time := c.GetString("start_time")
  8636. end_time := c.GetString("end_time")
  8637. types, _ := c.GetInt64("type", 0)
  8638. keywords := c.GetString("keywords")
  8639. p_type, _ := c.GetInt64("p_type", 0)
  8640. sort_type, _ := c.GetInt64("sort_type", 0)
  8641. charge_type, _ := c.GetInt64("charge_type", 0)
  8642. sch_type, _ := c.GetInt64("sch_type", 0)
  8643. zone_type, _ := c.GetInt64("zone_type", 0)
  8644. med_type, _ := c.GetInt64("med_type", 0)
  8645. timeLayout := "2006-01-02"
  8646. loc, _ := time.LoadLocation("Local")
  8647. var startTime int64
  8648. if len(start_time) > 0 {
  8649. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8650. if err != nil {
  8651. //fmt.Println(err)
  8652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8653. return
  8654. }
  8655. startTime = theTime.Unix()
  8656. }
  8657. var endTime int64
  8658. if len(end_time) > 0 {
  8659. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8660. if err != nil {
  8661. utils.ErrorLog(err.Error())
  8662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8663. return
  8664. }
  8665. endTime = theTime.Unix()
  8666. }
  8667. adminUser := c.GetAdminUserInfo()
  8668. org_id := adminUser.CurrentOrgId
  8669. 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)
  8670. for _, item := range order {
  8671. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8672. item.DoctorName = info.Doctor
  8673. item.DepartmentName = info.XtHisDepartment.Name
  8674. }
  8675. if err == nil {
  8676. c.ServeSuccessJSON(map[string]interface{}{
  8677. "order": order,
  8678. "total": total,
  8679. })
  8680. } else {
  8681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8682. return
  8683. }
  8684. }
  8685. func (c *HisApiController) GetHisOrder() {
  8686. patient_id, _ := c.GetInt64("patient_id", 0)
  8687. number := c.GetString("number")
  8688. adminInfo := c.GetAdminUserInfo()
  8689. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8690. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8691. if err == nil {
  8692. c.ServeSuccessJSON(map[string]interface{}{
  8693. "order": order,
  8694. "prescription": prescriptions,
  8695. })
  8696. } else {
  8697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8698. return
  8699. }
  8700. }
  8701. func (c *HisApiController) GetHisPrescriptionList() {
  8702. record_date := c.GetString("record_date")
  8703. keywords := c.GetString("keywords")
  8704. page, _ := c.GetInt64("page")
  8705. limit, _ := c.GetInt64("limit")
  8706. sch_type, _ := c.GetInt64("sch_type")
  8707. timeLayout := "2006-01-02"
  8708. loc, _ := time.LoadLocation("Local")
  8709. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8710. if err != nil {
  8711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8712. return
  8713. }
  8714. recordDateTime := theTime.Unix()
  8715. adminInfo := c.GetAdminUserInfo()
  8716. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8717. //adminInfo := c.GetAdminUserInfo()
  8718. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8719. //fmt.Println(prescriptionOrder)
  8720. if err == nil {
  8721. c.ServeSuccessJSON(map[string]interface{}{
  8722. "order": prescriptionOrder,
  8723. "total": total,
  8724. })
  8725. } else {
  8726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8727. return
  8728. }
  8729. }
  8730. func (c *HisApiController) GetHisPrescriptionInfo() {
  8731. id, _ := c.GetInt64("id")
  8732. adminInfo := c.GetAdminUserInfo()
  8733. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8734. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8735. if err == nil {
  8736. c.ServeSuccessJSON(map[string]interface{}{
  8737. "order": prescriptionOrder,
  8738. "prescription": prescription,
  8739. })
  8740. } else {
  8741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8742. return
  8743. }
  8744. }
  8745. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8746. adminUser := c.GetAdminUserInfo()
  8747. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8748. c.ServeSuccessJSON(map[string]interface{}{
  8749. "config": config,
  8750. })
  8751. }
  8752. type ResultTwo struct {
  8753. ErrMsg interface{} `json:"err_msg"`
  8754. InfRefmsgid string `json:"inf_refmsgid"`
  8755. Infcode int64 `json:"infcode"`
  8756. Output struct {
  8757. Baseinfo struct {
  8758. Age float64 `json:"age"`
  8759. Brdy string `json:"brdy"`
  8760. Certno string `json:"certno"`
  8761. Gend string `json:"gend"`
  8762. Naty string `json:"naty"`
  8763. PsnCertType string `json:"psn_cert_type"`
  8764. PsnName string `json:"psn_name"`
  8765. PsnNo string `json:"psn_no"`
  8766. } `json:"baseinfo"`
  8767. Idetinfo []interface{} `json:"idetinfo"`
  8768. Iinfo []struct {
  8769. Balc float64 `json:"balc"`
  8770. CvlservFlag string `json:"cvlserv_flag"`
  8771. EmpName string `json:"emp_name"`
  8772. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8773. Insutype string `json:"insutype"`
  8774. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8775. PausInsuDate interface{} `json:"paus_insu_date"`
  8776. PsnInsuDate string `json:"psn_insu_date"`
  8777. PsnInsuStas string `json:"psn_insu_stas"`
  8778. PsnType string `json:"psn_type"`
  8779. } `json:"insuinfo"`
  8780. } `json:"output"`
  8781. RefmsgTime string `json:"refmsg_time"`
  8782. RespondTime string `json:"respond_time"`
  8783. Signtype interface{} `json:"signtype"`
  8784. WarnInfo interface{} `json:"warn_info"`
  8785. }
  8786. type ResultThree struct {
  8787. Cainfo interface{} `json:"cainfo"`
  8788. ErrMsg interface{} `json:"err_msg"`
  8789. InfRefmsgid string `json:"inf_refmsgid"`
  8790. Infcode int64 `json:"infcode"`
  8791. Output struct {
  8792. Data struct {
  8793. IptOtpNo string `json:"ipt_otp_no"`
  8794. MdtrtID string `json:"mdtrt_id"`
  8795. PsnNo string `json:"psn_no"`
  8796. } `json:"data"`
  8797. } `json:"output"`
  8798. RefmsgTime string `json:"refmsg_time"`
  8799. RespondTime string `json:"respond_time"`
  8800. Signtype interface{} `json:"signtype"`
  8801. WarnMsg interface{} `json:"warn_msg"`
  8802. }
  8803. type ResultFour struct {
  8804. Cainfo string `json:"cainfo"`
  8805. ErrMsg string `json:"err_msg"`
  8806. InfRefmsgid string `json:"inf_refmsgid"`
  8807. Infcode int64 `json:"infcode"`
  8808. Output struct {
  8809. Result []struct {
  8810. BasMednFlag string `json:"bas_medn_flag"`
  8811. ChldMedcFlag string `json:"chld_medc_flag"`
  8812. ChrgitmLv string `json:"chrgitm_lv"`
  8813. Cnt float64 `json:"cnt"`
  8814. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8815. DrtReimFlag string `json:"drt_reim_flag"`
  8816. FeedetlSn string `json:"feedetl_sn"`
  8817. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8818. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8819. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8820. ListSpItemFlag string `json:"list_sp_item_flag"`
  8821. LmtUsedFlag string `json:"lmt_used_flag"`
  8822. MedChrgitmType string `json:"med_chrgitm_type"`
  8823. Memo string `json:"memo"`
  8824. OverlmtAmt float64 `json:"overlmt_amt"`
  8825. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8826. Pric float64 `json:"pric"`
  8827. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8828. SelfpayProp float64 `json:"selfpay_prop"`
  8829. } `json:"result"`
  8830. } `json:"output"`
  8831. RefmsgTime string `json:"refmsg_time"`
  8832. RespondTime string `json:"respond_time"`
  8833. Signtype string `json:"signtype"`
  8834. WarnMsg string `json:"warn_msg"`
  8835. }
  8836. type ResultFive struct {
  8837. Insutype string `json:"insutype"`
  8838. }
  8839. type ResultSix struct {
  8840. Cainfo interface{} `json:"cainfo"`
  8841. ErrMsg interface{} `json:"err_msg"`
  8842. InfRefmsgid string `json:"inf_refmsgid"`
  8843. Infcode int64 `json:"infcode"`
  8844. Output struct {
  8845. } `json:"output"`
  8846. RefmsgTime string `json:"refmsg_time"`
  8847. RespondTime string `json:"respond_time"`
  8848. Signtype interface{} `json:"signtype"`
  8849. WarnMsg interface{} `json:"warn_msg"`
  8850. }
  8851. type ResultSeven struct {
  8852. Cainfo string `json:"cainfo"`
  8853. ErrMsg string `json:"err_msg"`
  8854. InfRefmsgid string `json:"inf_refmsgid"`
  8855. Infcode int64 `json:"infcode"`
  8856. Output struct {
  8857. Setldetail []interface{} `json:"setldetail"`
  8858. Setlinfo struct {
  8859. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8860. AcctPay float64 `json:"acct_pay"`
  8861. ActPayDedc float64 `json:"act_pay_dedc"`
  8862. Age float64 `json:"age"`
  8863. Balc float64 `json:"balc"`
  8864. Brdy string `json:"brdy"`
  8865. Certno string `json:"certno"`
  8866. ClrOptins string `json:"clr_optins"`
  8867. ClrType string `json:"clr_type"`
  8868. ClrWay string `json:"clr_way"`
  8869. CvlservFlag string `json:"cvlserv_flag"`
  8870. CvlservPay float64 `json:"cvlserv_pay"`
  8871. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8872. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8873. Gend string `json:"gend"`
  8874. HifesPay float64 `json:"hifes_pay"`
  8875. HifmiPay float64 `json:"hifmi_pay"`
  8876. HifobPay float64 `json:"hifob_pay"`
  8877. HifpPay float64 `json:"hifp_pay"`
  8878. HospPartAmt float64 `json:"hosp_part_amt"`
  8879. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8880. Insutype string `json:"insutype"`
  8881. MafPay float64 `json:"maf_pay"`
  8882. MdtrtCertType string `json:"mdtrt_cert_type"`
  8883. MdtrtID string `json:"mdtrt_id"`
  8884. MedType string `json:"med_type"`
  8885. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8886. MedinsSetlID string `json:"medins_setl_id"`
  8887. Naty string `json:"naty"`
  8888. OthPay float64 `json:"oth_pay"`
  8889. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8890. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8891. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8892. PsnCashPay float64 `json:"psn_cash_pay"`
  8893. PsnCertType string `json:"psn_cert_type"`
  8894. PsnName string `json:"psn_name"`
  8895. PsnNo string `json:"psn_no"`
  8896. PsnPartAmt float64 `json:"psn_part_amt"`
  8897. PsnType string `json:"psn_type"`
  8898. SetlID string `json:"setl_id"`
  8899. SetlTime string `json:"setl_time"`
  8900. } `json:"setlinfo"`
  8901. } `json:"output"`
  8902. RefmsgTime string `json:"refmsg_time"`
  8903. RespondTime string `json:"respond_time"`
  8904. Signtype interface{} `json:"signtype"`
  8905. WarnMsg interface{} `json:"warn_msg"`
  8906. }
  8907. type ResultEight struct {
  8908. Cainfo string `json:"cainfo"`
  8909. ErrMsg string `json:"err_msg"`
  8910. InfRefmsgid string `json:"inf_refmsgid"`
  8911. Infcode int64 `json:"infcode"`
  8912. Output struct {
  8913. Stmtinfo struct {
  8914. SetlOptins string `json:"setl_optins"`
  8915. StmtRslt string `json:"stmt_rslt"`
  8916. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8917. } `json:"stmtinfo"`
  8918. } `json:"output"`
  8919. RefmsgTime string `json:"refmsg_time"`
  8920. RespondTime string `json:"respond_time"`
  8921. Signtype interface{} `json:"signtype"`
  8922. WarnMsg interface{} `json:"warn_msg"`
  8923. }
  8924. type ResultNine struct {
  8925. Cainfo string `json:"cainfo"`
  8926. ErrMsg string `json:"err_msg"`
  8927. InfRefmsgid string `json:"inf_refmsgid"`
  8928. Infcode int64 `json:"infcode"`
  8929. Output struct {
  8930. FileQuryNo string `json:"file_qury_no"`
  8931. } `json:"output"`
  8932. RefmsgTime string `json:"refmsg_time"`
  8933. RespondTime string `json:"respond_time"`
  8934. Signtype interface{} `json:"signtype"`
  8935. WarnMsg interface{} `json:"warn_msg"`
  8936. }
  8937. type ResultTen struct {
  8938. Cainfo string `json:"cainfo"`
  8939. ErrMsg string `json:"err_msg"`
  8940. InfRefmsgid string `json:"inf_refmsgid"`
  8941. Infcode int64 `json:"infcode"`
  8942. Output struct {
  8943. DldEndtime string `json:"dld_endtime"`
  8944. FileQuryNo string `json:"file_qury_no"`
  8945. Filename string `json:"filename"`
  8946. } `json:"output"`
  8947. RefmsgTime string `json:"refmsg_time"`
  8948. RespondTime string `json:"respond_time"`
  8949. Signtype interface{} `json:"signtype"`
  8950. WarnMsg interface{} `json:"warn_msg"`
  8951. }
  8952. type ResultEleven struct {
  8953. Cainfo string `json:"cainfo"`
  8954. ErrMsg string `json:"err_msg"`
  8955. InfRefmsgid string `json:"inf_refmsgid"`
  8956. Infcode int64 `json:"infcode"`
  8957. Output struct {
  8958. Setlinfo struct {
  8959. FixmedinsName string `json:"fixmedins_name"`
  8960. FixmedinsCode string `json:"fixmedins_code"`
  8961. PsnNo string `json:"psn_no"`
  8962. PsnName string `json:"psn_name"`
  8963. HifobPay float64 `json:"hifob_pay"`
  8964. Gend string `json:"gend"`
  8965. Brdy string `json:"brdy"`
  8966. PsnCertType string `json:"psn_cert_type"`
  8967. PsnType string `json:"psn_type"`
  8968. EmpName string `json:"emp_name"`
  8969. Certno string `json:"certno"`
  8970. Insutype string `json:"insutype"`
  8971. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8972. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8973. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8974. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8975. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8976. ActPayDedc float64 `json:"act_pay_dedc"`
  8977. HifpPay float64 `json:"hifp_pay"`
  8978. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8979. CvlservPay float64 `json:"cvlserv_pay"`
  8980. HifesPay float64 `json:"hifes_pay"`
  8981. HifmiPay float64 `json:"hifmi_pay"`
  8982. MafPay float64 `json:"maf_pay"`
  8983. OthPay float64 `json:"oth_pay"`
  8984. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8985. PsnPay float64 `json:"psn_pay"`
  8986. AcctPay float64 `json:"acct_pay"`
  8987. CashPayamt float64 `json:"cash_payamt"`
  8988. Balc float64 `json:"balc"`
  8989. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8990. MedinsSetlId string `json:"medins_setl_id"`
  8991. RefdSetlFlag string `json:"refd_setl_flag"`
  8992. SetlTime string `json:"setl_time"`
  8993. MedType string `json:"med_type"`
  8994. } `json:"setlinfo"`
  8995. } `json:"output"`
  8996. RefmsgTime string `json:"refmsg_time"`
  8997. RespondTime string `json:"respond_time"`
  8998. Signtype interface{} `json:"signtype"`
  8999. WarnMsg interface{} `json:"warn_msg"`
  9000. }
  9001. type Custom struct {
  9002. DetItemFeeSumamt string
  9003. Cut string
  9004. FeedetlSn string
  9005. Price string
  9006. MedListCodg string
  9007. Type int64
  9008. AdviceId int64
  9009. ProjectId int64
  9010. ItemId int64
  9011. CostType int64
  9012. }
  9013. // 获取个人信息----挂号-----上传就诊信息
  9014. func (c *HisApiController) GetRegisterInfo() {
  9015. id, _ := c.GetInt64("id")
  9016. record_time := c.GetString("record_time")
  9017. settlementValue, _ := c.GetInt64("settlement_value")
  9018. medical_insurance_card := c.GetString("medical_insurance_card")
  9019. name := c.GetString("name")
  9020. id_card_type, _ := c.GetInt64("id_card_type")
  9021. certificates, _ := c.GetInt64("certificates")
  9022. medical_care, _ := c.GetInt64("medical_care")
  9023. birthday := c.GetString("birthday")
  9024. age, _ := c.GetInt64("age")
  9025. id_card := c.GetString("id_card")
  9026. register_type, _ := c.GetInt64("register")
  9027. doctor, _ := c.GetInt64("doctor")
  9028. department, _ := c.GetInt64("department")
  9029. gender, _ := c.GetInt64("sex")
  9030. phone := c.GetString("phone")
  9031. registration_fee, _ := c.GetFloat("registration_fee")
  9032. medical_expenses, _ := c.GetFloat("medical_expenses")
  9033. social_type, _ := c.GetInt64("social_type")
  9034. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9035. diagnosis_ids := c.GetString("diagnosis")
  9036. sick_type, _ := c.GetInt64("sick_type")
  9037. reg_type := c.GetString("p_type")
  9038. timeLayout := "2006-01-02"
  9039. loc, _ := time.LoadLocation("Local")
  9040. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9041. birthUnix := birthdays.Unix()
  9042. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9043. if err != nil {
  9044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9045. return
  9046. }
  9047. recordDateTime := theTime.Unix()
  9048. adminInfo := c.GetAdminUserInfo()
  9049. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9050. if tempPatient.ID == 0 {
  9051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9052. return
  9053. }
  9054. var patient service.Patients
  9055. if id == 0 {
  9056. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9057. } else {
  9058. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9059. }
  9060. if patient.ID == 0 {
  9061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9062. return
  9063. }
  9064. if len(patient.IdCardNo) == 0 {
  9065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9066. return
  9067. }
  9068. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9069. if len(his) >= 1 {
  9070. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9071. if len(his) >= 1 && order.ID == 0 {
  9072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9073. return
  9074. }
  9075. }
  9076. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9077. fmt.Println(timeStr)
  9078. timeArr := strings.Split(timeStr, " ")
  9079. fmt.Println(timeArr)
  9080. timeArrTwo := strings.Split(timeArr[0], "-")
  9081. timeArrThree := strings.Split(timeArr[1], ":")
  9082. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9083. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9084. if len(lists) == 0 {
  9085. var hisPatient models.XtHisPatient
  9086. hisPatient = models.XtHisPatient{
  9087. Name: name,
  9088. Age: age,
  9089. Gender: gender,
  9090. Birthday: birthUnix,
  9091. Phone: phone,
  9092. MedicalTreatmentType: medical_care,
  9093. IdType: certificates,
  9094. IdCardNo: id_card,
  9095. BalanceAccountsType: settlementValue,
  9096. SocialType: social_type,
  9097. MedicalInsuranceNumber: medical_insurance_card,
  9098. RegisterType: register_type,
  9099. RegisterCost: registration_fee,
  9100. TreatmentCost: medical_expenses,
  9101. AdminUserId: adminInfo.AdminUser.Id,
  9102. UserOrgId: adminInfo.CurrentOrgId,
  9103. Status: 1,
  9104. RecordDate: recordDateTime,
  9105. IsReturn: 1,
  9106. PatientId: patient.ID,
  9107. Ctime: time.Now().Unix(),
  9108. Mtime: time.Now().Unix(),
  9109. Number: str,
  9110. IdCardType: id_card_type,
  9111. Departments: department,
  9112. Doctor: doctor,
  9113. PType: reg_type,
  9114. Diagnosis: diagnosis_ids,
  9115. SickType: sick_type,
  9116. }
  9117. service.CreateHisPatient(&hisPatient)
  9118. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9119. c.ServeSuccessJSON(map[string]interface{}{
  9120. "his_info": hisPatient,
  9121. })
  9122. } else {
  9123. //chrgBchno := rand.Intn(1000000) + 10000
  9124. var hisPatient models.XtHisPatient
  9125. hisPatient = models.XtHisPatient{
  9126. Name: name,
  9127. Age: age,
  9128. Gender: gender,
  9129. Birthday: birthUnix,
  9130. Phone: phone,
  9131. MedicalTreatmentType: medical_care,
  9132. IdType: certificates,
  9133. IdCardNo: id_card,
  9134. BalanceAccountsType: settlementValue,
  9135. SocialType: social_type,
  9136. MedicalInsuranceNumber: medical_insurance_card,
  9137. RegisterType: register_type,
  9138. RegisterCost: registration_fee,
  9139. TreatmentCost: medical_expenses,
  9140. AdminUserId: adminInfo.AdminUser.Id,
  9141. UserOrgId: adminInfo.CurrentOrgId,
  9142. Status: 1,
  9143. RecordDate: recordDateTime,
  9144. IsReturn: 1,
  9145. PatientId: patient.ID,
  9146. Ctime: time.Now().Unix(),
  9147. Mtime: time.Now().Unix(),
  9148. Number: str,
  9149. IdCardType: id_card_type,
  9150. Departments: department,
  9151. Doctor: doctor,
  9152. PType: reg_type,
  9153. Diagnosis: diagnosis_ids,
  9154. SickType: sick_type,
  9155. }
  9156. service.CreateHisPatient(&hisPatient)
  9157. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9158. c.ServeSuccessJSON(map[string]interface{}{
  9159. "his_info": hisPatient,
  9160. })
  9161. }
  9162. }
  9163. // 上传明细----结算
  9164. func (c *HisApiController) GetUploadInfo() {
  9165. id, _ := c.GetInt64("id")
  9166. record_time := c.GetString("record_time")
  9167. his_patient_id, _ := c.GetInt64("his_patient_id")
  9168. oth_desc := c.GetString("oth_desc")
  9169. pay_way, _ := c.GetInt64("pay_way")
  9170. pay_ways := c.GetString("pay_ways")
  9171. pay_price, _ := c.GetFloat("pay_price")
  9172. pay_card_no := c.GetString("pay_card_no")
  9173. discount_price, _ := c.GetFloat("discount_price")
  9174. preferential_price, _ := c.GetFloat("preferential_price")
  9175. reality_price, _ := c.GetFloat("reality_price")
  9176. found_price, _ := c.GetFloat("found_price")
  9177. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9178. private_price, _ := c.GetFloat("private_price")
  9179. timeLayout := "2006-01-02"
  9180. loc, _ := time.LoadLocation("Local")
  9181. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9182. fapiao_code := c.GetString("fapiao_code")
  9183. fapiao_number := c.GetString("fapiao_number")
  9184. diagnosis_id := c.GetString("diagnosis")
  9185. sick_type, _ := c.GetInt64("sick_type")
  9186. reg_type, _ := c.GetInt64("p_type")
  9187. order_id, _ := c.GetInt64("order_id")
  9188. cash_pay := c.GetString("cash_pay")
  9189. wechat_pay := c.GetString("wechat_pay")
  9190. ali_pay := c.GetString("ali_pay")
  9191. jifen_pay := c.GetString("jifen_pay")
  9192. card_desc := c.GetString("card_desc")
  9193. band_card_pay := c.GetString("band_card_pay")
  9194. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9195. tmp_decimal := c.GetString("tmp_decimal")
  9196. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9197. var decimal float64 //本次使用的押金
  9198. var errmsg error
  9199. tx := service.XTWriteDB().Begin() //开了事务
  9200. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9201. defer func() {
  9202. if errmsg != nil {
  9203. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9204. tx.Rollback()
  9205. } else {
  9206. tx.Commit()
  9207. }
  9208. }()
  9209. fmt.Println("dec_way", dec_way)
  9210. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9211. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9212. return
  9213. }
  9214. if len(tmp_decimal) > 0 {
  9215. if tmp_decimal[0] == 45 {
  9216. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9217. return
  9218. }
  9219. }
  9220. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9221. fmt.Println(errs)
  9222. decimal = tt
  9223. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9224. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9225. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9226. if err != nil {
  9227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9228. return
  9229. }
  9230. recordDateTime := theTime.Unix()
  9231. adminUser := c.GetAdminUserInfo()
  9232. var prescriptions []*models.HisPrescription
  9233. var prescriptionsOne []*models.HisPrescription
  9234. var start_time int64
  9235. var end_time int64
  9236. ids_str := c.GetString("ids")
  9237. ids_arr := strings.Split(ids_str, ",")
  9238. if tempOrder.ID == 0 {
  9239. if settle_accounts_type == 1 { //日结
  9240. fmt.Println(reg_type)
  9241. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9242. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9243. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9244. } else {
  9245. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9246. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9247. }
  9248. } else { //月结
  9249. start_time_str := c.GetString("start_time")
  9250. end_time_str := c.GetString("end_time")
  9251. timeLayout := "2006-01-02"
  9252. loc, _ := time.LoadLocation("Local")
  9253. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9254. if err != nil {
  9255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9256. return
  9257. }
  9258. recordStartTime := theStartTime.Unix()
  9259. start_time = recordStartTime
  9260. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9261. if err != nil {
  9262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9263. return
  9264. }
  9265. recordEndTime := theEndTime.Unix()
  9266. end_time = recordEndTime
  9267. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9268. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9269. }
  9270. var goods []*models.DialysisBeforePrepareGoods
  9271. var newGoods []*models.NewDialysisBeforePrepareGoods
  9272. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9273. var infos []*models.HisDoctorAdviceInfo
  9274. var infoList []*models.HisDoctorAdviceInfo
  9275. var hisAdvice []*models.HisDoctorAdviceInfo
  9276. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9277. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9278. //判断库存不足
  9279. //结算出库开关
  9280. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9281. if settConfig.IsOpen == 1 {
  9282. //判断库存的地方
  9283. for _, info := range prescriptions {
  9284. if info.Type == 1 {
  9285. infos = append(infos, info.HisDoctorAdviceInfo...)
  9286. }
  9287. if info.Type == 2 {
  9288. for _, sumItem := range info.HisPrescriptionProject {
  9289. if sumItem.Type == 3 {
  9290. var good models.DialysisBeforePrepareGoods
  9291. var newGood models.NewDialysisBeforePrepareGoods
  9292. good.GoodId = sumItem.GoodInfo.ID
  9293. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9294. count, _ := strconv.Atoi(sumItem.Count)
  9295. good.Count = int64(count)
  9296. good.StorehouseId = houseConfig.StorehouseOutInfo
  9297. good.ProjectId = sumItem.ID
  9298. goods = append(goods, &good)
  9299. newGood.GoodId = sumItem.GoodInfo.ID
  9300. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9301. count2, _ := strconv.Atoi(sumItem.Count)
  9302. newGood.Count = int64(count2)
  9303. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9304. newGood.ProjectId = sumItem.ID
  9305. newGoods = append(newGoods, &newGood)
  9306. }
  9307. }
  9308. }
  9309. }
  9310. for _, info := range prescriptionsOne {
  9311. if info.Type == 1 {
  9312. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9313. }
  9314. if info.Type == 2 {
  9315. for _, sumItem := range info.HisPrescriptionProject {
  9316. if sumItem.Type == 3 {
  9317. var newGood models.NewDialysisBeforePrepareGoods
  9318. newGood.GoodId = sumItem.GoodInfo.ID
  9319. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9320. count2, _ := strconv.Atoi(sumItem.Count)
  9321. newGood.Count = int64(count2)
  9322. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9323. newGood.ProjectId = sumItem.ID
  9324. newGoodOne = append(newGoodOne, &newGood)
  9325. }
  9326. }
  9327. }
  9328. }
  9329. //判断
  9330. for _, itemOne := range infos {
  9331. for _, itemTwo := range hisAdvice {
  9332. if itemOne.DrugId == itemTwo.DrugId {
  9333. itemTwo.Child = append(itemTwo.Child, itemOne)
  9334. }
  9335. }
  9336. }
  9337. for _, itemTwo := range hisAdvice {
  9338. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9339. var sum_out_count int64
  9340. for _, itemThree := range itemTwo.Child {
  9341. var prescribing_number int64
  9342. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9343. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9344. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9345. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9346. }
  9347. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9348. prescribing_number = parseIntPrescribingNumber
  9349. }
  9350. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9351. prescribing_number = parseIntPrescribingNumber
  9352. }
  9353. sum_out_count += prescribing_number
  9354. }
  9355. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9356. if sum_out_count > drugStockOut.FlushCount {
  9357. c.ServeSuccessJSON(map[string]interface{}{
  9358. "msg": "2",
  9359. "drug": medical,
  9360. })
  9361. return
  9362. }
  9363. }
  9364. for _, itemOne := range newGoods {
  9365. for _, item := range newGoodOne {
  9366. if itemOne.GoodId == item.GoodId {
  9367. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9368. }
  9369. }
  9370. }
  9371. for _, item := range newGoodOne {
  9372. var sum_out_count_one int64
  9373. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9374. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9375. sum_out_count_one += itemOne.Count
  9376. }
  9377. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9378. fmt.Println("sum_out_count_one", sum_out_count_one)
  9379. fmt.Println("list.FlushCount", list.FlushCount)
  9380. if sum_out_count_one > list.FlushCount {
  9381. c.ServeSuccessJSON(map[string]interface{}{
  9382. "msg": "3",
  9383. "good": good,
  9384. })
  9385. return
  9386. }
  9387. }
  9388. }
  9389. timestamp := time.Now().Unix()
  9390. tempTime := time.Unix(timestamp, 0)
  9391. timeFormat := tempTime.Format("20060102150405")
  9392. chrgBchno := rand.Intn(100000) + 10000
  9393. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9394. strconv.FormatInt(his.PatientId, 10)
  9395. var ids []int64
  9396. for _, item := range prescriptions {
  9397. ids = append(ids, item.ID)
  9398. }
  9399. var total float64
  9400. for _, item := range prescriptions {
  9401. fmt.Println(item)
  9402. if item.Type == 1 { //药品
  9403. for _, subItem := range item.HisDoctorAdviceInfo {
  9404. total = total + (subItem.Price * subItem.PrescribingNumber)
  9405. }
  9406. }
  9407. if item.Type == 2 { //项目
  9408. for _, subItem := range item.HisPrescriptionProject {
  9409. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9410. total = total + (subItem.Price * cnt)
  9411. }
  9412. }
  9413. for _, subItem := range item.HisAdditionalCharge {
  9414. total = total + (subItem.Price * float64(subItem.Count))
  9415. }
  9416. }
  9417. if reg_type == 1111 || reg_type == 1112 {
  9418. reg_type = 11
  9419. }
  9420. tm := time.Unix(time.Now().Unix(), 0)
  9421. allTotal := fmt.Sprintf("%.4f", total)
  9422. totals, _ := strconv.ParseFloat(allTotal, 64)
  9423. order := &models.HisOrder{
  9424. UserOrgId: adminUser.CurrentOrgId,
  9425. HisPatientId: his.ID,
  9426. PatientId: id,
  9427. SettleAccountsDate: recordDateTime,
  9428. Ctime: time.Now().Unix(),
  9429. Mtime: time.Now().Unix(),
  9430. Status: 1,
  9431. OrderStatus: 2,
  9432. MdtrtId: his.Number,
  9433. Number: chrg_bchno,
  9434. MedfeeSumamt: totals,
  9435. PayWay: pay_way,
  9436. PayWays: pay_ways,
  9437. PayPrice: pay_price,
  9438. MedType: strconv.Itoa(int(reg_type)),
  9439. PayCardNo: pay_card_no,
  9440. DiscountPrice: discount_price,
  9441. PreferentialPrice: preferential_price,
  9442. RealityPrice: reality_price,
  9443. FoundPrice: found_price,
  9444. MedicalInsurancePrice: medical_insurance_price,
  9445. PrivatePrice: private_price,
  9446. SettleEndTime: end_time,
  9447. SettleStartTime: start_time,
  9448. PsnPartAmt: totals,
  9449. PsnCashPay: totals,
  9450. SettleType: settle_accounts_type,
  9451. FaPiaoCode: fapiao_code,
  9452. FaPiaoNumber: fapiao_number,
  9453. Diagnosis: diagnosis_id,
  9454. PType: 2,
  9455. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9456. Decimal: decimal,
  9457. OthDesc: oth_desc,
  9458. CashPay: cash_pay,
  9459. WechatPay: wechat_pay,
  9460. AliPay: ali_pay,
  9461. JifenPay: jifen_pay,
  9462. BandCardPay: band_card_pay,
  9463. Creator: adminUser.AdminUser.Id,
  9464. CardDesc: card_desc,
  9465. }
  9466. err = service.CreateOrderTX(order, tx)
  9467. if err != nil {
  9468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9469. return
  9470. }
  9471. var customs []*Custom
  9472. for _, item := range prescriptions {
  9473. if item.Type == 1 { //药品a
  9474. for _, subItem := range item.HisDoctorAdviceInfo {
  9475. cus := &Custom{
  9476. AdviceId: subItem.ID,
  9477. ProjectId: 0,
  9478. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9479. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9480. FeedetlSn: subItem.FeedetlSn,
  9481. Price: fmt.Sprintf("%.4f", subItem.Price),
  9482. MedListCodg: subItem.MedListCodg,
  9483. Type: 1,
  9484. CostType: 9,
  9485. }
  9486. customs = append(customs, cus)
  9487. }
  9488. }
  9489. if item.Type == 2 { //项目
  9490. for _, subItem := range item.HisPrescriptionProject {
  9491. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9492. cus := &Custom{
  9493. AdviceId: 0,
  9494. ProjectId: subItem.ID,
  9495. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9496. Cut: fmt.Sprintf("%.4f", cnt),
  9497. FeedetlSn: subItem.FeedetlSn,
  9498. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9499. MedListCodg: subItem.MedListCodg,
  9500. Type: 2,
  9501. CostType: subItem.HisProject.CostClassify,
  9502. }
  9503. customs = append(customs, cus)
  9504. }
  9505. }
  9506. for _, item := range item.HisAdditionalCharge {
  9507. cus := &Custom{
  9508. ItemId: item.ID,
  9509. AdviceId: 0,
  9510. ProjectId: 0,
  9511. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9512. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9513. FeedetlSn: item.FeedetlSn,
  9514. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9515. MedListCodg: item.XtHisAddtionConfig.Code,
  9516. Type: 3,
  9517. CostType: 5,
  9518. }
  9519. customs = append(customs, cus)
  9520. }
  9521. }
  9522. for _, item := range customs {
  9523. var advice_id int64 = 0
  9524. var project_id int64 = 0
  9525. var item_id int64 = 0
  9526. var types int64 = 0
  9527. var med_chrgitm_type string
  9528. if item.Type == 1 {
  9529. advice_id = item.AdviceId
  9530. project_id = 0
  9531. item_id = 0
  9532. med_chrgitm_type = "09"
  9533. } else if item.Type == 2 {
  9534. med_chrgitm_type = "05"
  9535. if item.CostType == 3 {
  9536. med_chrgitm_type = "04"
  9537. }
  9538. if item.CostType == 8 {
  9539. med_chrgitm_type = "03"
  9540. }
  9541. advice_id = 0
  9542. item_id = 0
  9543. project_id = item.ProjectId
  9544. } else if item.Type == 3 {
  9545. advice_id = 0
  9546. item_id = item.ItemId
  9547. project_id = 0
  9548. med_chrgitm_type = "08"
  9549. }
  9550. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9551. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9552. pric, _ := strconv.ParseFloat(item.Price, 32)
  9553. info := &models.HisOrderInfo{
  9554. OrderNumber: order.Number,
  9555. UploadDate: time.Now().Unix(),
  9556. AdviceId: advice_id,
  9557. DetItemFeeSumamt: detItemFeeSumamt,
  9558. MedChrgitmType: med_chrgitm_type,
  9559. Cnt: cut,
  9560. Pric: pric,
  9561. PatientId: id,
  9562. Status: 1,
  9563. Mtime: time.Now().Unix(),
  9564. Ctime: time.Now().Unix(),
  9565. UserOrgId: adminUser.CurrentOrgId,
  9566. HisPatientId: his.ID,
  9567. OrderId: order.ID,
  9568. ProjectId: project_id,
  9569. Type: types,
  9570. ItemId: item_id,
  9571. }
  9572. service.CreateOrderInfoTX(info, tx)
  9573. }
  9574. his.Diagnosis = diagnosis_id
  9575. his.SickType = sick_type
  9576. his.RegisterType = reg_type
  9577. his.MedicalTreatmentType = reg_type
  9578. service.UpdataHisPateintTX(&his, tx)
  9579. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  9580. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  9581. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  9582. //判断是否使用了押金
  9583. if dec_way == "true" {
  9584. tmpstring := strconv.FormatInt(order.ID, 10)
  9585. //扣押金
  9586. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  9587. order.Decimal = decimal
  9588. service.UpDateOrderTwo(order, tx)
  9589. if errmsg != nil {
  9590. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  9591. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9592. return
  9593. }
  9594. }
  9595. if err == nil {
  9596. for _, info := range prescriptions {
  9597. if info.Type == 1 {
  9598. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  9599. }
  9600. if info.Type == 2 {
  9601. for _, sumItem := range info.HisPrescriptionProject {
  9602. if sumItem.Type == 3 {
  9603. var good models.DialysisBeforePrepareGoods
  9604. var newGood models.NewDialysisBeforePrepareGoods
  9605. var oldGood models.OldDialysisBeforePrepareGoods
  9606. good.GoodId = sumItem.GoodInfo.ID
  9607. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9608. count, _ := strconv.Atoi(sumItem.Count)
  9609. good.Count = int64(count)
  9610. good.StorehouseId = houseConfig.StorehouseOutInfo
  9611. good.ProjectId = sumItem.ID
  9612. good.PatientId = sumItem.PatientId
  9613. goods = append(goods, &good)
  9614. newGood.GoodId = sumItem.GoodInfo.ID
  9615. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9616. count2, _ := strconv.Atoi(sumItem.Count)
  9617. newGood.Count = int64(count2)
  9618. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9619. newGood.ProjectId = sumItem.ID
  9620. newGood.PatientId = sumItem.HisPatientId
  9621. newGoods = append(newGoods, &newGood)
  9622. oldGood.GoodId = sumItem.GoodInfo.ID
  9623. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9624. count3, _ := strconv.Atoi(sumItem.Count)
  9625. oldGood.Count = int64(count3)
  9626. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9627. oldGood.ProjectId = sumItem.ID
  9628. oldGood.RecordDate = sumItem.RecordDate
  9629. oldGood.PatientId = sumItem.HisPatientId
  9630. oldGoods = append(oldGoods, &oldGood)
  9631. }
  9632. }
  9633. }
  9634. }
  9635. if settConfig.IsOpen == 1 {
  9636. for _, item := range infoList {
  9637. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9638. if medical.IsUse == 2 {
  9639. //药品出库
  9640. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9641. //查询默认仓库
  9642. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9643. //查询默认仓库剩余多少库存
  9644. var sum_count int64
  9645. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9646. for _, its := range stockInfo {
  9647. if its.MaxUnit == medical.MaxUnit {
  9648. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9649. }
  9650. sum_count += its.StockMaxNumber + its.StockMinNumber
  9651. }
  9652. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9653. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9654. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9655. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9656. }
  9657. }
  9658. orgId := c.GetAdminUserInfo().CurrentOrgId
  9659. if len(oldGoods) > 0 {
  9660. timeStr := time.Now().Format("2006-01-02")
  9661. timeArr := strings.Split(timeStr, "-")
  9662. total, _ := service.FindAllWarehouseOut(orgId)
  9663. total = total + 1
  9664. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9665. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9666. number = number + total
  9667. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9668. operation_time := time.Now().Unix()
  9669. creater := c.GetAdminUserInfo().AdminUser.Id
  9670. //查询默认出库仓库库存
  9671. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9672. recordDateStr := time.Now().Format("2006-01-02")
  9673. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9674. nowtime := recordDate.Unix()
  9675. warehouseOut := models.WarehouseOut{
  9676. WarehouseOutOrderNumber: warehousing_out_order,
  9677. OperationTime: operation_time,
  9678. OrgId: orgId,
  9679. Creater: creater,
  9680. Ctime: time.Now().Unix(),
  9681. Status: 1,
  9682. WarehouseOutTime: nowtime,
  9683. Type: 1,
  9684. StorehouseId: storeConfig.StorehouseOutInfo,
  9685. IsCheck: 1,
  9686. OrderId: order.ID,
  9687. IsSys: 5,
  9688. }
  9689. //查询是否生成出库单
  9690. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9691. if out.ID == 0 {
  9692. service.AddSigleWarehouseOut(&warehouseOut)
  9693. }
  9694. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9695. for _, item := range oldGoods {
  9696. dialyPrepareOne := models.DialysisBeforePrepare{
  9697. GoodTypeId: item.GoodTypeId,
  9698. GoodId: item.GoodId,
  9699. PatientId: his.PatientId,
  9700. RecordDate: item.RecordDate,
  9701. UserOrgId: adminUser.CurrentOrgId,
  9702. Count: item.Count,
  9703. Ctime: time.Now().Unix(),
  9704. Creater: adminUser.AdminUser.Id,
  9705. CommdityCode: item.CommdityCode,
  9706. Status: 1,
  9707. StorehouseId: houseConfig.StorehouseOutInfo,
  9708. }
  9709. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9710. //非零用
  9711. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9712. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9713. //查询剩余库存
  9714. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9715. var sum_count int64
  9716. for _, item := range goodList {
  9717. sum_count += item.StockCount
  9718. }
  9719. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9720. //耗材
  9721. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9722. }
  9723. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9724. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9725. //查询剩余库存
  9726. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9727. var sum_count int64
  9728. for _, item := range goodList {
  9729. sum_count += item.StockCount
  9730. }
  9731. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9732. //耗材
  9733. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9734. }
  9735. }
  9736. }
  9737. }
  9738. c.ServeSuccessJSON(map[string]interface{}{
  9739. "msg": "结算成功",
  9740. })
  9741. }
  9742. }
  9743. }
  9744. // 退款
  9745. func (c *HisApiController) Refund() {
  9746. order_id, _ := c.GetInt64("order_id")
  9747. order, _ := service.GetHisOrderByID(order_id)
  9748. adminUser := c.GetAdminUserInfo()
  9749. orgid := c.GetAdminUserInfo().CurrentOrgId
  9750. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9751. if err != nil {
  9752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9753. return
  9754. }
  9755. tmp := strconv.FormatInt(order.ID, 10)
  9756. //当押金不为零时产生退费记录
  9757. if order.Decimal != 0 {
  9758. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9759. if err != nil {
  9760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9761. return
  9762. }
  9763. }
  9764. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9765. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9766. var goods []*models.DialysisBeforePrepareGoods
  9767. var newGoods []*models.NewDialysisBeforePrepareGoods
  9768. var infos []*models.HisDoctorAdviceInfo
  9769. for _, info := range orders {
  9770. if info.AdviceId > 0 && info.ProjectId == 0 {
  9771. infos = append(infos, &info.HisDoctorAdviceInfo)
  9772. }
  9773. if info.ProjectId > 0 && info.AdviceId == 0 {
  9774. if info.HisPrescriptionProject.Type == 3 {
  9775. var good models.DialysisBeforePrepareGoods
  9776. var newGood models.NewDialysisBeforePrepareGoods
  9777. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9778. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9779. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9780. good.Count = int64(count)
  9781. good.StorehouseId = houseConfig.StorehouseOutInfo
  9782. good.ProjectId = info.HisPrescriptionProject.ID
  9783. good.PatientId = info.PatientId
  9784. good.OrderId = order_id
  9785. goods = append(goods, &good)
  9786. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9787. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9788. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9789. newGood.Count = int64(count2)
  9790. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9791. newGood.ProjectId = info.HisPrescriptionProject.ID
  9792. newGood.RecordDate = order.SettleAccountsDate
  9793. newGood.UserOrgId = order.UserOrgId
  9794. newGood.PatientId = info.PatientId
  9795. newGood.OrderId = order_id
  9796. newGoods = append(newGoods, &newGood)
  9797. }
  9798. }
  9799. }
  9800. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9801. if settConfig.IsOpen == 1 {
  9802. for _, item := range infos {
  9803. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9804. }
  9805. for _, item := range newGoods {
  9806. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9807. }
  9808. }
  9809. c.ServeSuccessJSON(map[string]interface{}{
  9810. "msg": "退费成功",
  9811. })
  9812. }
  9813. func (c *HisApiController) RefundNumber() {
  9814. his_patient_id, _ := c.GetInt64("id")
  9815. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9816. info.Status = 0
  9817. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9818. if count > 0 {
  9819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9820. return
  9821. }
  9822. err := service.SaveHisPatient(info)
  9823. if err == nil {
  9824. c.ServeSuccessJSON(map[string]interface{}{
  9825. "msg": "退号成功",
  9826. })
  9827. } else {
  9828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9829. return
  9830. }
  9831. }
  9832. func (this *HisApiController) AdditionalCharge() {
  9833. dataBody := make(map[string]interface{}, 0)
  9834. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9835. fmt.Println(err)
  9836. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9837. patient_id := int64(dataBody["patient_id"].(float64))
  9838. medicineData, _ := dataBody["medicineData"].([]interface{})
  9839. adminUserInfo := this.GetAdminUserInfo()
  9840. orgId := adminUserInfo.CurrentOrgId
  9841. admin_user_id := adminUserInfo.AdminUser.Id
  9842. timeStr := time.Now().Format("2006-01-02")
  9843. timeLayout := "2006-01-02 15:04:05"
  9844. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9845. timenow := timeStringToTime.Unix()
  9846. var additionalCharges []*models.HisAdditionalCharge
  9847. for _, item := range medicineData {
  9848. var randNum int
  9849. randNum = rand.Intn(10000) + 1000
  9850. timestamp := time.Now().Unix()
  9851. tempTime := time.Unix(timestamp, 0)
  9852. timeFormat := tempTime.Format("20060102150405")
  9853. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9854. items := item.(map[string]interface{})
  9855. money := items["price"].(string)
  9856. item_id_str := items["item_id"].(string)
  9857. name := items["name"].(string)
  9858. id_str := items["id"].(string)
  9859. moneys, _ := strconv.ParseInt(money, 10, 64)
  9860. monStr := strconv.FormatInt(moneys, 10)
  9861. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9862. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9863. id, _ := strconv.ParseInt(id_str, 10, 64)
  9864. additionalCharge := &models.HisAdditionalCharge{
  9865. ID: id,
  9866. HisPatientId: his_patient_id,
  9867. UserOrgId: orgId,
  9868. PatientId: patient_id,
  9869. RecordDate: timenow,
  9870. Price: monneyStr,
  9871. Status: 1,
  9872. ItemName: name,
  9873. ItemId: item_id,
  9874. AdminUserId: admin_user_id,
  9875. CreatedTime: time.Now().Unix(),
  9876. OrderStatus: 0,
  9877. PrescriptionNumber: "",
  9878. BatchNumber: "",
  9879. FeedetlSn: p_number,
  9880. }
  9881. service.CreateAdditionalCharge(additionalCharge)
  9882. additionalCharges = append(additionalCharges, additionalCharge)
  9883. }
  9884. this.ServeSuccessJSON(map[string]interface{}{
  9885. "msg": "添加成功",
  9886. "additional_charges": additionalCharges,
  9887. })
  9888. }
  9889. func (this *HisApiController) DeleteAddition() {
  9890. id, _ := this.GetInt64("id")
  9891. //TODO 需要判断是否已经结算
  9892. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9893. if err == nil {
  9894. this.ServeSuccessJSON(map[string]interface{}{
  9895. "msg": "删除成功",
  9896. })
  9897. return
  9898. } else {
  9899. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9900. return
  9901. }
  9902. }
  9903. func (this *HisApiController) GetAdminUsers() {
  9904. adminUser := this.GetAdminUserInfo()
  9905. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9906. this.ServeSuccessJSON(map[string]interface{}{
  9907. "doctors": doctors,
  9908. })
  9909. }
  9910. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9911. change_type, _ := this.GetInt64("type", 0)
  9912. record_date := this.GetString("record_time")
  9913. patient_id, _ := this.GetInt64("patient_id", 0)
  9914. p_type, _ := this.GetInt64("p_type", 0)
  9915. timeLayout := "2006-01-02"
  9916. loc, _ := time.LoadLocation("Local")
  9917. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9918. record_time := theAdviceRecordTime.Unix()
  9919. adminUserInfo := this.GetAdminUserInfo()
  9920. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9921. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9922. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9923. if config.ID > 0 && config.IsOpen == 1 {
  9924. for _, subitems := range prescriptions {
  9925. for _, item := range subitems.VMHisPrescription {
  9926. for _, subItem := range item.HisDoctorAdviceInfo {
  9927. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9928. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9929. if info.RetailPrice > 0 {
  9930. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9931. subItem.Drug.RetailPrice = drug.RetailPrice
  9932. }
  9933. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9934. subItem.Drug.MinPrice = info.RetailPrice
  9935. subItem.Drug.RetailPrice = info.RetailPrice
  9936. }
  9937. }
  9938. }
  9939. }
  9940. }
  9941. }
  9942. if config.ID > 0 && config.IsOpen == 1 {
  9943. for _, subitems := range prescriptions {
  9944. for _, item := range subitems.VMHisPrescription {
  9945. for _, subItem := range item.HisPrescriptionProject {
  9946. if subItem.Type == 3 {
  9947. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9948. if info.Price > 0 {
  9949. subItem.GoodInfo.PackingPrice = info.Price
  9950. }
  9951. }
  9952. }
  9953. }
  9954. }
  9955. }
  9956. }
  9957. if err == nil {
  9958. if len(prescriptions) == 0 {
  9959. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9960. return
  9961. } else {
  9962. this.ServeSuccessJSON(map[string]interface{}{
  9963. "prescriptions": prescriptions,
  9964. })
  9965. return
  9966. }
  9967. } else {
  9968. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9969. return
  9970. }
  9971. }
  9972. func (this *HisApiController) GetCallHisPrescription() {
  9973. patient_id, _ := this.GetInt64("patient_id", 0)
  9974. timeLayout := "2006-01-02"
  9975. loc, _ := time.LoadLocation("Local")
  9976. start_time := this.GetString("start_time")
  9977. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9978. end_time := this.GetString("end_time")
  9979. p_type, _ := this.GetInt64("p_type")
  9980. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9981. adminUserInfo := this.GetAdminUserInfo()
  9982. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9983. //if
  9984. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9985. //
  9986. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9987. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9988. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9989. if config.ID > 0 && config.IsOpen == 1 {
  9990. for _, subitems := range prescriptions {
  9991. for _, item := range subitems.VMHisPrescription {
  9992. for _, subItem := range item.HisDoctorAdviceInfo {
  9993. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9994. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9995. if info.RetailPrice > 0 {
  9996. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9997. subItem.Drug.RetailPrice = drug.RetailPrice
  9998. }
  9999. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10000. subItem.Drug.MinPrice = info.RetailPrice
  10001. subItem.Drug.RetailPrice = info.RetailPrice
  10002. }
  10003. }
  10004. }
  10005. }
  10006. }
  10007. }
  10008. if config.ID > 0 && config.IsOpen == 1 {
  10009. for _, subitems := range prescriptions {
  10010. for _, item := range subitems.VMHisPrescription {
  10011. for _, subItem := range item.HisPrescriptionProject {
  10012. if subItem.Type == 3 {
  10013. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10014. if info.Price > 0 {
  10015. subItem.GoodInfo.PackingPrice = info.Price
  10016. }
  10017. }
  10018. }
  10019. }
  10020. }
  10021. }
  10022. }
  10023. if err == nil {
  10024. this.ServeSuccessJSON(map[string]interface{}{
  10025. "prescriptions": prescriptions,
  10026. })
  10027. return
  10028. } else {
  10029. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10030. return
  10031. }
  10032. }
  10033. func (this *HisApiController) GetHisDayPrescription() {
  10034. timeLayout := "2006-01-02"
  10035. loc, _ := time.LoadLocation("Local")
  10036. start_time := this.GetString("start_time")
  10037. patient_id, _ := this.GetInt64("patient_id", 0)
  10038. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10039. end_time := this.GetString("end_time")
  10040. p_type, _ := this.GetInt64("p_type")
  10041. order_status, _ := this.GetInt64("type")
  10042. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10043. adminUserInfo := this.GetAdminUserInfo()
  10044. var dayHisPrescription []*models.HisPrescription
  10045. var err error
  10046. if order_status == 1 || order_status == 0 {
  10047. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10048. } else if order_status == 2 {
  10049. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10050. }
  10051. var settle_total float64
  10052. for _, item := range dayHisPrescription {
  10053. if len(item.HisPrescriptionProject) > 0 {
  10054. for _, subItem := range item.HisPrescriptionProject {
  10055. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10056. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10057. settle_total = settle_total + total
  10058. }
  10059. }
  10060. if len(item.HisDoctorAdviceInfo) > 0 {
  10061. for _, subItem := range item.HisDoctorAdviceInfo {
  10062. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10063. settle_total = settle_total + total
  10064. }
  10065. }
  10066. }
  10067. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10068. if err == nil {
  10069. this.ServeSuccessJSON(map[string]interface{}{
  10070. "day_prescription": dayHisPrescription,
  10071. "settle_total": settle_total,
  10072. })
  10073. return
  10074. } else {
  10075. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10076. return
  10077. }
  10078. }
  10079. func (c *HisApiController) GetHisChargePatientList() {
  10080. record_date := c.GetString("record_date")
  10081. order_status, _ := c.GetInt64("type")
  10082. sch_type, _ := c.GetInt64("sch_type")
  10083. timeLayout := "2006-01-02"
  10084. loc, _ := time.LoadLocation("Local")
  10085. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10086. if err != nil {
  10087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10088. return
  10089. }
  10090. recordDateTime := theTime.Unix()
  10091. adminInfo := c.GetAdminUserInfo()
  10092. var tempPatients []*service.NewTempPatients
  10093. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10094. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10095. if order_status != 2 {
  10096. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10097. } else {
  10098. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10099. }
  10100. } else {
  10101. if order_status != 2 {
  10102. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10103. } else {
  10104. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10105. }
  10106. }
  10107. var patients []*service.NewTempPatients
  10108. var patients_two []*service.NewTempPatients
  10109. for _, item := range tempPatients {
  10110. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10111. //过滤掉没挂号的和没开处方的
  10112. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10113. patients = append(patients, item)
  10114. }
  10115. //过滤掉没挂号的
  10116. if len(item.HisPatient) > 0 {
  10117. patients_two = append(patients_two, item)
  10118. }
  10119. } else {
  10120. if len(item.HisPrescription) > 0 {
  10121. patients = append(patients, item)
  10122. }
  10123. }
  10124. }
  10125. c.ServeSuccessJSON(map[string]interface{}{
  10126. "list": patients,
  10127. "list_two": patients_two,
  10128. })
  10129. }
  10130. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10131. record_date := c.GetString("record_date")
  10132. timeLayout := "2006-01-02"
  10133. loc, _ := time.LoadLocation("Local")
  10134. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10135. if err != nil {
  10136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10137. return
  10138. }
  10139. recordDateTime := theTime.Unix()
  10140. adminUser := c.GetAdminUserInfo()
  10141. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10142. var patients []*service.Patients
  10143. for _, item := range tempPatients {
  10144. if item.HisPatient.ID == 0 {
  10145. patients = append(patients, item)
  10146. }
  10147. }
  10148. c.ServeSuccessJSON(map[string]interface{}{
  10149. "list": patients,
  10150. //"list_two": patients_two,
  10151. })
  10152. }
  10153. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10154. newArr = make([]*service.Patients, 0)
  10155. for i := 0; i < len(patient); i++ {
  10156. repeat := false
  10157. for j := i + 1; j < len(patient); j++ {
  10158. if patient[i].ID == patient[j].ID {
  10159. repeat = true
  10160. break
  10161. }
  10162. }
  10163. if !repeat {
  10164. newArr = append(newArr, patient[i])
  10165. }
  10166. }
  10167. return
  10168. }
  10169. func (c *HisApiController) GetHisChargePatientInfo() {
  10170. patient_id, _ := c.GetInt64("patient_id")
  10171. his_patient_id, _ := c.GetInt64("his_patient_id")
  10172. record_date := c.GetString("record_date")
  10173. //start_time := c.GetString("start_time")
  10174. //end_time := c.GetString("end_time")
  10175. order_status, _ := c.GetInt64("type", 0)
  10176. p_type, _ := c.GetInt64("p_type", 0)
  10177. order_id, _ := c.GetInt64("order_id", 0)
  10178. timeLayout := "2006-01-02"
  10179. loc, _ := time.LoadLocation("Local")
  10180. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10181. if err != nil {
  10182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10183. return
  10184. }
  10185. recordDateTime := theTime.Unix()
  10186. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10187. //if err != nil {
  10188. //
  10189. //}
  10190. //startRecordDateTime := startTime.Unix()
  10191. //
  10192. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10193. //if err != nil {
  10194. //
  10195. //}
  10196. //endRecordDateTime := endTime.Unix()
  10197. admin := c.GetAdminUserInfo()
  10198. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10199. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10200. var prescriptions []*models.HisPrescription
  10201. //var unChargeMonthPrescriptions []*models.HisPrescription
  10202. order, _ := service.GetHisOrderByID(order_id)
  10203. if order_status == 1 || order_status == 0 {
  10204. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10205. } else if order_status == 2 {
  10206. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10207. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10208. }
  10209. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10210. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10211. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10212. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10213. //获取所有科室信息
  10214. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10215. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10216. c.ServeSuccessJSON(map[string]interface{}{
  10217. "his_info": his_patient_info,
  10218. "xt_info": xt_patient_info,
  10219. "prescription": prescriptions,
  10220. "case_history": case_history,
  10221. "info": patientPrescriptionInfo,
  10222. "last_info": lastPatientPrescriptionInfo,
  10223. "order": order,
  10224. "doctors": doctors,
  10225. "department": department,
  10226. "sch": sch,
  10227. })
  10228. return
  10229. }
  10230. func (c *HisApiController) GetAllOrderDetail() {
  10231. order_id, _ := c.GetInt64("id", 0)
  10232. order, _ := service.GetHisOrderByID(order_id)
  10233. if order.ID == 0 {
  10234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10235. return
  10236. }
  10237. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10238. org_id := c.GetAdminUserInfo().CurrentOrgId
  10239. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10240. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10241. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10242. c.ServeSuccessJSON(map[string]interface{}{
  10243. "order": order,
  10244. "order_info": order_info,
  10245. "patient": patient,
  10246. "admin_info": adminInfo,
  10247. "hospital_record": record,
  10248. })
  10249. return
  10250. }
  10251. func (c *HisApiController) GetAllOrderDetailCollect() {
  10252. order_id, _ := c.GetInt64("id", 0)
  10253. order, _ := service.GetHisOrderByID(order_id)
  10254. if order.ID == 0 {
  10255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10256. return
  10257. }
  10258. org_id := c.GetAdminUserInfo().CurrentOrgId
  10259. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10260. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10261. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10262. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10263. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10264. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10265. var bedCostTotal float64 = 0 //床位总费
  10266. //var bedCostSelfTotal float64 = 0 //床位自费
  10267. var operationCostTotal float64 = 0 //手术费
  10268. //var operationCostSelfTotal float64 = 0 //手术费
  10269. var otherCostTotal float64 = 0 //其他费用
  10270. //var otherCostSelfTotal float64 = 0 //其他费用
  10271. var materialCostTotal float64 = 0 //材料费
  10272. //var materialCostSelfTotal float64 = 0 //材料费
  10273. var westernMedicineCostTotal float64 = 0 //西药费
  10274. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10275. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10276. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10277. var checkCostTotal float64 = 0 //检查费
  10278. //var checkCostSelfTotal float64 = 0 //检查费
  10279. var laboratoryCostTotal float64 = 0 //化验费
  10280. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10281. var treatCostTotal float64 = 0 //治疗费用
  10282. //var treatCostSelfTotal float64 = 0 //治疗费用
  10283. var zhenChaCostTotal float64 = 0 //其他费用
  10284. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10285. decimal.DivisionPrecision = 2
  10286. var BalanceAccountsType int64
  10287. if his.ID > 0 {
  10288. BalanceAccountsType = his.BalanceAccountsType
  10289. } else {
  10290. BalanceAccountsType = record.BalanceAccountsType
  10291. }
  10292. if BalanceAccountsType != 2 {
  10293. for _, item := range order_info {
  10294. if org_id == 10215 {
  10295. if item.MedChrgitmType == "01" { //床位费
  10296. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10297. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10298. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10299. }
  10300. if item.MedChrgitmType == "02" { //诊察费
  10301. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10302. //zhenChaCostSelfTotal = zhenChaCostTotal
  10303. }
  10304. if item.MedChrgitmType == "03" { //检查费
  10305. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10306. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10307. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10308. }
  10309. //if item.MedChrgitmType == "02" { //检查费
  10310. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10311. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10312. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10313. //}
  10314. if item.MedChrgitmType == "04" { //化验费
  10315. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10316. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10317. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10318. }
  10319. if item.MedChrgitmType == "05" { //治疗费
  10320. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10321. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10322. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10323. }
  10324. if item.MedChrgitmType == "06" { //手术费
  10325. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10326. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10327. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10328. }
  10329. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10330. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10331. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10332. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10333. }
  10334. if item.MedChrgitmType == "09" { //西药费
  10335. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10336. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10337. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10338. }
  10339. if item.MedChrgitmType == "11" { //中成费
  10340. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10341. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10342. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10343. }
  10344. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10345. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10346. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10347. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10348. }
  10349. } else if org_id == 10188 || org_id == 10217 {
  10350. if item.MedChrgitmType == "01" { //床位费
  10351. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10352. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10353. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10354. }
  10355. if item.MedChrgitmType == "02" { //诊察费
  10356. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10357. //zhenChaCostSelfTotal = zhenChaCostTotal
  10358. }
  10359. if item.MedChrgitmType == "03" { //检查费
  10360. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10361. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10362. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10363. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10364. }
  10365. //if item.MedChrgitmType == "02" { //检查费
  10366. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10367. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10368. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10369. //}
  10370. if item.MedChrgitmType == "04" { //化验费
  10371. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10372. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10373. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10374. }
  10375. if item.MedChrgitmType == "05" { //治疗费
  10376. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10377. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10378. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10379. }
  10380. if item.MedChrgitmType == "06" { //手术费
  10381. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10382. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10383. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10384. }
  10385. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10386. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10387. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10388. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10389. }
  10390. if item.MedChrgitmType == "09" { //西药费
  10391. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10392. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10393. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10394. }
  10395. if item.MedChrgitmType == "11" { //中成费
  10396. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10397. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10398. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10399. }
  10400. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10401. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10402. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10403. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10404. }
  10405. } else {
  10406. if item.MedChrgitmType == "01" { //床位费
  10407. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10408. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10409. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10410. }
  10411. //if item.MedChrgitmType == "02" { //诊察费
  10412. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10413. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10414. //}
  10415. if item.MedChrgitmType == "03" { //检查费
  10416. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10417. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10418. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10419. }
  10420. //if item.MedChrgitmType == "02" { //检查费
  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 == "04" { //化验费
  10426. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10427. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10428. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10429. }
  10430. if item.MedChrgitmType == "05" { //治疗费
  10431. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10432. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10433. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10434. }
  10435. if item.MedChrgitmType == "06" { //手术费
  10436. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10437. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10438. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10439. }
  10440. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10441. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10442. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10443. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10444. }
  10445. if item.MedChrgitmType == "09" { //西药费
  10446. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10447. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10448. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10449. }
  10450. if item.MedChrgitmType == "11" { //中成费
  10451. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10452. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10453. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10454. }
  10455. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10456. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10457. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10458. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10459. }
  10460. }
  10461. }
  10462. c.ServeSuccessJSON(map[string]interface{}{
  10463. "order": order,
  10464. "order_info": order_info,
  10465. "patient": patient,
  10466. "admin_info": adminInfo,
  10467. "his_hospital": record,
  10468. "bedCostTotal": bedCostTotal,
  10469. "operationCostTotal": operationCostTotal,
  10470. "otherCostTotal": otherCostTotal,
  10471. "materialCostTotal": materialCostTotal,
  10472. "westernMedicineCostTotal": westernMedicineCostTotal,
  10473. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10474. "checkCostTotal": checkCostTotal,
  10475. "zhenChaCostTotal": zhenChaCostTotal,
  10476. "laboratoryCostTotal": laboratoryCostTotal,
  10477. "treatCostTotal": treatCostTotal,
  10478. })
  10479. } else {
  10480. for _, item := range order_info {
  10481. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10482. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10483. item.MedChrgitmType = "09"
  10484. }
  10485. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10486. if item.HisPrescriptionProject.Type == 2 {
  10487. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10488. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10489. case 0:
  10490. item.MedChrgitmType = "0"
  10491. break
  10492. case 1:
  10493. item.MedChrgitmType = "14"
  10494. break
  10495. case 2:
  10496. item.MedChrgitmType = "05"
  10497. break
  10498. case 3:
  10499. item.MedChrgitmType = "03"
  10500. break
  10501. case 4:
  10502. item.MedChrgitmType = "03"
  10503. break
  10504. case 5:
  10505. item.MedChrgitmType = "08"
  10506. break
  10507. case 6:
  10508. item.MedChrgitmType = "14"
  10509. break
  10510. case 7:
  10511. item.MedChrgitmType = "14"
  10512. break
  10513. case 8:
  10514. item.MedChrgitmType = "03"
  10515. break
  10516. case 9:
  10517. item.MedChrgitmType = "14"
  10518. break
  10519. case 10:
  10520. item.MedChrgitmType = "14"
  10521. break
  10522. case 11:
  10523. item.MedChrgitmType = "06"
  10524. break
  10525. case 12:
  10526. item.MedChrgitmType = "12"
  10527. break
  10528. case 13:
  10529. item.MedChrgitmType = "01"
  10530. break
  10531. case 14:
  10532. item.MedChrgitmType = "04"
  10533. break
  10534. case 15:
  10535. item.MedChrgitmType = "14"
  10536. break
  10537. }
  10538. } else {
  10539. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10540. case 1:
  10541. item.MedChrgitmType = "14"
  10542. break
  10543. case 2:
  10544. item.MedChrgitmType = "05"
  10545. break
  10546. case 3:
  10547. item.MedChrgitmType = "04"
  10548. break
  10549. case 4:
  10550. item.MedChrgitmType = "14"
  10551. break
  10552. case 5:
  10553. item.MedChrgitmType = "08"
  10554. break
  10555. case 6:
  10556. item.MedChrgitmType = "14"
  10557. break
  10558. case 7:
  10559. item.MedChrgitmType = "14"
  10560. break
  10561. case 8:
  10562. item.MedChrgitmType = "03"
  10563. break
  10564. case 9:
  10565. item.MedChrgitmType = "14"
  10566. break
  10567. }
  10568. }
  10569. } else if item.HisPrescriptionProject.Type == 3 {
  10570. item.MedChrgitmType = "08"
  10571. }
  10572. }
  10573. }
  10574. for _, item := range order_info {
  10575. if org_id == 10215 {
  10576. if item.MedChrgitmType == "01" { //床位费
  10577. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10578. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10579. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10580. }
  10581. if item.MedChrgitmType == "02" { //诊察费
  10582. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10583. //zhenChaCostSelfTotal = zhenChaCostTotal
  10584. }
  10585. if item.MedChrgitmType == "03" { //检查费
  10586. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10587. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10588. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10589. }
  10590. //if item.MedChrgitmType == "02" { //检查费
  10591. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10592. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10593. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10594. //}
  10595. if item.MedChrgitmType == "04" { //化验费
  10596. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10597. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10598. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10599. }
  10600. if item.MedChrgitmType == "05" { //治疗费
  10601. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10602. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10603. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10604. }
  10605. if item.MedChrgitmType == "06" { //手术费
  10606. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10607. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10608. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10609. }
  10610. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10611. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10612. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10613. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10614. }
  10615. if item.MedChrgitmType == "09" { //西药费
  10616. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10617. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10618. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10619. }
  10620. if item.MedChrgitmType == "11" { //中成费
  10621. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10622. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10623. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10624. }
  10625. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10626. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10627. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10628. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10629. }
  10630. } else {
  10631. if item.MedChrgitmType == "01" { //床位费
  10632. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10633. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10634. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10635. }
  10636. //if item.MedChrgitmType == "02" { //诊察费
  10637. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10638. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10639. //}
  10640. if item.MedChrgitmType == "03" { //检查费
  10641. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10642. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10643. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10644. }
  10645. //if item.MedChrgitmType == "02" { //检查费
  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 == "04" { //化验费
  10651. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10652. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10653. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10654. }
  10655. if item.MedChrgitmType == "05" { //治疗费
  10656. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10657. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10658. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10659. }
  10660. if item.MedChrgitmType == "06" { //手术费
  10661. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10662. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10663. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10664. }
  10665. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10666. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10667. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10668. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10669. }
  10670. if item.MedChrgitmType == "09" { //西药费
  10671. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10672. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10673. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10674. }
  10675. if item.MedChrgitmType == "11" { //中成费
  10676. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10677. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10678. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10679. }
  10680. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10681. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10682. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10683. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10684. }
  10685. }
  10686. }
  10687. c.ServeSuccessJSON(map[string]interface{}{
  10688. "order": order,
  10689. "order_info": order_info,
  10690. "patient": patient,
  10691. "admin_info": adminInfo,
  10692. "his_hospital": record,
  10693. "bedCostTotal": bedCostTotal,
  10694. "operationCostTotal": operationCostTotal,
  10695. "otherCostTotal": otherCostTotal,
  10696. "materialCostTotal": materialCostTotal,
  10697. "westernMedicineCostTotal": westernMedicineCostTotal,
  10698. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10699. "checkCostTotal": checkCostTotal,
  10700. "zhenChaCostTotal": zhenChaCostTotal,
  10701. "laboratoryCostTotal": laboratoryCostTotal,
  10702. "treatCostTotal": treatCostTotal,
  10703. })
  10704. }
  10705. }
  10706. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10707. page, _ := c.GetInt64("page")
  10708. limit, _ := c.GetInt64("limit")
  10709. keywords := c.GetString("keywords")
  10710. start_time := c.GetString("start_time")
  10711. end_time := c.GetString("end_time")
  10712. //clr_type := c.GetString("clr_type")
  10713. insutype := c.GetString("insutype")
  10714. timeLayout := "2006-01-02"
  10715. loc, _ := time.LoadLocation("Local")
  10716. var theStartTIme int64
  10717. if len(start_time) > 0 {
  10718. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10719. theStartTIme = theTime.Unix()
  10720. }
  10721. var theEndtTIme int64
  10722. if len(end_time) > 0 {
  10723. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10724. theEndtTIme = theTime.Unix()
  10725. }
  10726. if page <= 0 {
  10727. page = 1
  10728. }
  10729. if limit <= 0 {
  10730. limit = 10
  10731. }
  10732. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10733. c.ServeSuccessJSON(map[string]interface{}{
  10734. "total": total,
  10735. "list": list,
  10736. })
  10737. return
  10738. }
  10739. func (c *HisApiController) GetPutOnRecordList() {
  10740. page, _ := c.GetInt64("page")
  10741. limit, _ := c.GetInt64("limit")
  10742. keywords := c.GetString("keywords")
  10743. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10744. if page <= 0 {
  10745. page = 1
  10746. }
  10747. if limit <= 0 {
  10748. limit = 10
  10749. }
  10750. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10751. c.ServeSuccessJSON(map[string]interface{}{
  10752. "total": total,
  10753. "list": list,
  10754. })
  10755. return
  10756. }
  10757. func (c *HisApiController) GetCompareData() {
  10758. start_time := c.GetString("start_time")
  10759. end_time := c.GetString("end_time")
  10760. insutype := c.GetString("insutype")
  10761. clr_type := c.GetString("clr_type")
  10762. timeLayout := "2006-01-02"
  10763. loc, _ := time.LoadLocation("Local")
  10764. var theStartTIme int64
  10765. if len(start_time) > 0 {
  10766. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10767. if err != nil {
  10768. theStartTIme = 0
  10769. }
  10770. theStartTIme = theTime.Unix()
  10771. }
  10772. var theEndtTIme int64
  10773. if len(end_time) > 0 {
  10774. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10775. if err != nil {
  10776. theEndtTIme = 0
  10777. }
  10778. theEndtTIme = theTime.Unix()
  10779. }
  10780. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10781. fmt.Println(err)
  10782. if err == nil {
  10783. c.ServeSuccessJSON(map[string]interface{}{
  10784. "list": formData,
  10785. })
  10786. } else {
  10787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10788. return
  10789. }
  10790. }
  10791. func (c *HisApiController) GetFaPiaoData() {
  10792. order_id, _ := c.GetInt64("order_id")
  10793. patient_id, _ := c.GetInt64("patient_id")
  10794. //number := c.GetString("number")
  10795. adminUser := c.GetAdminUserInfo()
  10796. order, _ := service.GetHisOrderByID(order_id)
  10797. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10798. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10799. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10800. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10801. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10802. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10803. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10804. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10805. var bedCostTotal float64 = 0 //床位总费
  10806. var bedCostSelfTotal float64 = 0 //床位自费
  10807. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10808. var operationCostTotal float64 = 0 //手术费
  10809. var operationCostSelfTotal float64 = 0 //手术费
  10810. var operationCostPartSelfTotal float64 = 0 //手术费
  10811. var otherCostTotal float64 = 0 //其他费用
  10812. var otherCostSelfTotal float64 = 0 //其他费用
  10813. var otherCostPartSelfTotal float64 = 0 //其他费用
  10814. var materialCostTotal float64 = 0 //材料费
  10815. var materialCostSelfTotal float64 = 0 //材料费
  10816. var materialCostPartSelfTotal float64 = 0 //材料费
  10817. var westernMedicineCostTotal float64 = 0 //西药费
  10818. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10819. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10820. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10821. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10822. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10823. var checkCostTotal float64 = 0 //检查费
  10824. var checkCostSelfTotal float64 = 0 //检查费
  10825. var checkCostPartSelfTotal float64 = 0 //检查费
  10826. var hiliCostTotal float64 = 0 //护理费
  10827. var hiliCostSelfTotal float64 = 0 //护理费
  10828. var hiliCostPartSelfTotal float64 = 0 //护理费
  10829. var laboratoryCostTotal float64 = 0 //化验费
  10830. var laboratoryCostSelfTotal float64 = 0 //化验费
  10831. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10832. var treatCostTotal float64 = 0 //治疗费用
  10833. var treatCostSelfTotal float64 = 0 //治疗费用
  10834. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10835. var zhenChaCostTotal float64 = 0 //其他费用
  10836. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10837. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10838. decimal.DivisionPrecision = 2
  10839. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10840. var balanceAccountsType int64
  10841. if his.ID > 0 {
  10842. balanceAccountsType = his.BalanceAccountsType
  10843. } else {
  10844. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10845. }
  10846. if balanceAccountsType == 2 {
  10847. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10848. for _, item := range orderInfos_two {
  10849. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10850. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10851. item.MedChrgitmType = "09"
  10852. }
  10853. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10854. if item.HisPrescriptionProject.Type == 2 {
  10855. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10856. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10857. case 0:
  10858. item.MedChrgitmType = "0"
  10859. break
  10860. case 1:
  10861. item.MedChrgitmType = "14"
  10862. break
  10863. case 2:
  10864. item.MedChrgitmType = "05"
  10865. break
  10866. case 3:
  10867. item.MedChrgitmType = "03"
  10868. break
  10869. case 4:
  10870. item.MedChrgitmType = "03"
  10871. break
  10872. case 5:
  10873. item.MedChrgitmType = "08"
  10874. break
  10875. case 6:
  10876. item.MedChrgitmType = "14"
  10877. break
  10878. case 7:
  10879. item.MedChrgitmType = "14"
  10880. break
  10881. case 8:
  10882. item.MedChrgitmType = "03"
  10883. break
  10884. case 9:
  10885. item.MedChrgitmType = "14"
  10886. break
  10887. case 10:
  10888. item.MedChrgitmType = "14"
  10889. break
  10890. case 11:
  10891. item.MedChrgitmType = "06"
  10892. break
  10893. case 12:
  10894. item.MedChrgitmType = "12"
  10895. break
  10896. case 13:
  10897. item.MedChrgitmType = "01"
  10898. break
  10899. case 14:
  10900. item.MedChrgitmType = "04"
  10901. break
  10902. case 15:
  10903. item.MedChrgitmType = "02"
  10904. break
  10905. }
  10906. } else {
  10907. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10908. case 1:
  10909. item.MedChrgitmType = "14"
  10910. break
  10911. case 2:
  10912. item.MedChrgitmType = "05"
  10913. break
  10914. case 3:
  10915. item.MedChrgitmType = "04"
  10916. break
  10917. case 4:
  10918. item.MedChrgitmType = "03"
  10919. break
  10920. case 5:
  10921. item.MedChrgitmType = "08"
  10922. break
  10923. case 6:
  10924. item.MedChrgitmType = "14"
  10925. break
  10926. case 7:
  10927. item.MedChrgitmType = "14"
  10928. break
  10929. case 8:
  10930. item.MedChrgitmType = "03"
  10931. break
  10932. case 9:
  10933. item.MedChrgitmType = "14"
  10934. break
  10935. }
  10936. }
  10937. } else if item.HisPrescriptionProject.Type == 3 {
  10938. item.MedChrgitmType = "08"
  10939. }
  10940. }
  10941. }
  10942. for _, item := range orderInfos_two {
  10943. fmt.Println(item.MedChrgitmType)
  10944. if item.MedChrgitmType == "07" { //床位费
  10945. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10946. hiliCostSelfTotal = hiliCostTotal
  10947. }
  10948. if item.MedChrgitmType == "01" { //床位费
  10949. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10950. bedCostSelfTotal = bedCostTotal
  10951. }
  10952. if item.MedChrgitmType == "02" { //诊察费
  10953. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10954. zhenChaCostSelfTotal = zhenChaCostTotal
  10955. }
  10956. if item.MedChrgitmType == "03" { //检查费
  10957. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10958. checkCostSelfTotal = checkCostTotal
  10959. }
  10960. if item.MedChrgitmType == "04" { //化验费
  10961. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10962. laboratoryCostSelfTotal = laboratoryCostTotal
  10963. }
  10964. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10965. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10966. treatCostSelfTotal = treatCostTotal
  10967. }
  10968. if item.MedChrgitmType == "06" { //手术费
  10969. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10970. operationCostSelfTotal = treatCostTotal
  10971. }
  10972. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10973. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10974. materialCostSelfTotal = materialCostTotal
  10975. }
  10976. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10977. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10978. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10979. }
  10980. if item.MedChrgitmType == "11" { //中成费
  10981. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10982. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10983. }
  10984. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10985. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10986. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10987. otherCostSelfTotal = otherCostTotal
  10988. }
  10989. } else {
  10990. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10991. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10992. otherCostSelfTotal = otherCostTotal
  10993. }
  10994. }
  10995. }
  10996. } else {
  10997. for _, item := range orderInfos {
  10998. if item.MedChrgitmType == "01" { //床位费
  10999. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11000. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11001. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11002. }
  11003. if item.MedChrgitmType == "02" { //诊察费
  11004. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11005. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11006. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11007. }
  11008. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11009. if item.MedChrgitmType == "03" { //检查费
  11010. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11011. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11012. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11013. }
  11014. } else {
  11015. if item.MedChrgitmType == "03" { //检查费
  11016. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11017. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11018. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11019. }
  11020. }
  11021. if item.MedChrgitmType == "04" { //化验费
  11022. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11023. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11024. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11025. }
  11026. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11027. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11028. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11029. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11030. }
  11031. if item.MedChrgitmType == "06" { //手术费
  11032. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11033. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11034. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11035. }
  11036. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11037. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11038. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11039. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11040. }
  11041. if item.MedChrgitmType == "07" { //护理
  11042. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11043. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11044. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11045. }
  11046. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11047. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11048. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11049. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11050. }
  11051. if item.MedChrgitmType == "11" { //中成费
  11052. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11053. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11054. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11055. }
  11056. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11057. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11058. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11059. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11060. }
  11061. }
  11062. }
  11063. timeLayout := "2006-01-02"
  11064. loc, _ := time.LoadLocation("Local")
  11065. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11066. if err != nil {
  11067. }
  11068. startRecordDateTime := startTime.Unix()
  11069. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11070. if err != nil {
  11071. }
  11072. endRecordDateTime := endTime.Unix()
  11073. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11074. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11075. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11076. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11077. c.ServeSuccessJSON(map[string]interface{}{
  11078. "charge_admin_name": charge_admin.UserName,
  11079. "order_number": order.Number, //业务流水号
  11080. "id_card_no": his.IdCardNo, //社会保障号
  11081. "patient": patient,
  11082. "department_name": department.Name, //科室
  11083. "number": his.Number, //门诊号
  11084. "date": order.SettleAccountsDate, //结算日期
  11085. "name": order.PsnName, //姓名
  11086. "gender": patient.Gender, //性别
  11087. "psn_cash_money": order.PsnCashPay, //个人支付
  11088. "pay_way": "门诊", //结算方式
  11089. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11090. "admin_user_name": admin.UserName, //收款员
  11091. "order": order,
  11092. "order_info": orderInfos_two,
  11093. "his": his,
  11094. "bedCostTotal": bedCostTotal,
  11095. "bedCostSelfTotal": bedCostSelfTotal,
  11096. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11097. "operationCostTotal": operationCostTotal,
  11098. "operationCostSelfTotal": operationCostSelfTotal,
  11099. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11100. "otherCostTotal": otherCostTotal,
  11101. "otherCostSelfTotal": otherCostSelfTotal,
  11102. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11103. "materialCostTotal": materialCostTotal,
  11104. "materialCostSelfTotal": materialCostSelfTotal,
  11105. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11106. "westernMedicineCostTotal": westernMedicineCostTotal,
  11107. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11108. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11109. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11110. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11111. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11112. "checkCostTotal": checkCostTotal,
  11113. "checkCostSelfTotal": checkCostSelfTotal,
  11114. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11115. "laboratoryCostTotal": laboratoryCostTotal,
  11116. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11117. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11118. "treatCostTotal": treatCostTotal,
  11119. "treatCostSelfTotal": treatCostSelfTotal,
  11120. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11121. "zhenChaCostTotal": zhenChaCostTotal,
  11122. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11123. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11124. "his_hospital_record": his_hospital_record,
  11125. "pre_pay_money": pre_pay_money,
  11126. "refund_sum": sum,
  11127. "doctor_info": doctor_info,
  11128. "hiliCostTotal": hiliCostTotal,
  11129. "hiliCostSelfTotal": hiliCostSelfTotal,
  11130. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11131. })
  11132. }
  11133. //func (c *HisApiController) GetFaPiaoDatas() {
  11134. // order_ids := c.GetString("order_ids")
  11135. // patient_id, _ := c.GetInt64("patient_id")
  11136. // adminUser := c.GetAdminUserInfo()
  11137. //
  11138. // orders := strings.Split(order_ids, ",")
  11139. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11140. //
  11141. // for _, item := range orders {
  11142. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11143. // order, _ := service.GetHisOrderByID(order_id)
  11144. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11145. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11146. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11147. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11148. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11149. //
  11150. // }
  11151. //
  11152. // var bedCostTotal float64 = 0 //床位总费
  11153. // var bedCostSelfTotal float64 = 0 //床位自费
  11154. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11155. //
  11156. // var operationCostTotal float64 = 0 //手术费
  11157. // var operationCostSelfTotal float64 = 0 //手术费
  11158. // var operationCostPartSelfTotal float64 = 0 //手术费
  11159. //
  11160. // var otherCostTotal float64 = 0 //其他费用
  11161. // var otherCostSelfTotal float64 = 0 //其他费用
  11162. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11163. //
  11164. // var materialCostTotal float64 = 0 //材料费
  11165. // var materialCostSelfTotal float64 = 0 //材料费
  11166. // var materialCostPartSelfTotal float64 = 0 //材料费
  11167. //
  11168. // var westernMedicineCostTotal float64 = 0 //西药费
  11169. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11170. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11171. //
  11172. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11173. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11174. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11175. //
  11176. // var checkCostTotal float64 = 0 //检查费
  11177. // var checkCostSelfTotal float64 = 0 //检查费
  11178. // var checkCostPartSelfTotal float64 = 0 //检查费
  11179. //
  11180. // var laboratoryCostTotal float64 = 0 //化验费
  11181. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11182. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11183. //
  11184. // var treatCostTotal float64 = 0 //治疗费用
  11185. // var treatCostSelfTotal float64 = 0 //治疗费用
  11186. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11187. //
  11188. // var zhenChaCostTotal float64 = 0 //其他费用
  11189. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11190. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11191. //
  11192. // decimal.DivisionPrecision = 2
  11193. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11194. //
  11195. // var balanceAccountsType int64
  11196. // if his.ID > 0 {
  11197. // balanceAccountsType = his.BalanceAccountsType
  11198. // } else {
  11199. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11200. // }
  11201. // if balanceAccountsType == 2 {
  11202. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11203. // for _, item := range orderInfos_two {
  11204. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11205. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11206. // item.MedChrgitmType = "09"
  11207. // }
  11208. //
  11209. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11210. // if item.HisPrescriptionProject.Type == 2 {
  11211. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11212. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11213. // case 0:
  11214. // item.MedChrgitmType = "0"
  11215. // break
  11216. // case 1:
  11217. // item.MedChrgitmType = "14"
  11218. // break
  11219. // case 2:
  11220. // item.MedChrgitmType = "05"
  11221. //
  11222. // break
  11223. // case 3:
  11224. // item.MedChrgitmType = "03"
  11225. //
  11226. // break
  11227. // case 4:
  11228. // item.MedChrgitmType = "03"
  11229. //
  11230. // break
  11231. // case 5:
  11232. // item.MedChrgitmType = "08"
  11233. //
  11234. // break
  11235. // case 6:
  11236. // item.MedChrgitmType = "14"
  11237. //
  11238. // break
  11239. // case 7:
  11240. // item.MedChrgitmType = "14"
  11241. //
  11242. // break
  11243. // case 8:
  11244. // item.MedChrgitmType = "03"
  11245. // break
  11246. // case 9:
  11247. // item.MedChrgitmType = "14"
  11248. // break
  11249. // case 10:
  11250. // item.MedChrgitmType = "14"
  11251. // break
  11252. // case 11:
  11253. // item.MedChrgitmType = "06"
  11254. // break
  11255. // case 12:
  11256. // item.MedChrgitmType = "12"
  11257. // break
  11258. // case 13:
  11259. // item.MedChrgitmType = "01"
  11260. // break
  11261. // case 14:
  11262. // item.MedChrgitmType = "04"
  11263. // break
  11264. // case 15:
  11265. // item.MedChrgitmType = "02"
  11266. // break
  11267. //
  11268. // }
  11269. //
  11270. // } else {
  11271. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11272. //
  11273. // case 1:
  11274. // item.MedChrgitmType = "14"
  11275. // break
  11276. // case 2:
  11277. // item.MedChrgitmType = "05"
  11278. //
  11279. // break
  11280. // case 3:
  11281. // item.MedChrgitmType = "03"
  11282. //
  11283. // break
  11284. // case 4:
  11285. // item.MedChrgitmType = "03"
  11286. //
  11287. // break
  11288. // case 5:
  11289. // item.MedChrgitmType = "08"
  11290. //
  11291. // break
  11292. // case 6:
  11293. // item.MedChrgitmType = "14"
  11294. //
  11295. // break
  11296. // case 7:
  11297. // item.MedChrgitmType = "14"
  11298. //
  11299. // break
  11300. // case 8:
  11301. // item.MedChrgitmType = "03"
  11302. // break
  11303. // case 9:
  11304. // item.MedChrgitmType = "14"
  11305. // break
  11306. //
  11307. // }
  11308. //
  11309. // }
  11310. //
  11311. // } else if item.HisPrescriptionProject.Type == 3 {
  11312. // item.MedChrgitmType = "08"
  11313. // }
  11314. // }
  11315. // }
  11316. //
  11317. // for _, item := range orderInfos_two {
  11318. // fmt.Println(item.MedChrgitmType)
  11319. // if item.MedChrgitmType == "01" { //床位费
  11320. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11321. // bedCostSelfTotal = bedCostTotal
  11322. // }
  11323. //
  11324. // if item.MedChrgitmType == "02" { //诊察费
  11325. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11326. // zhenChaCostSelfTotal = zhenChaCostTotal
  11327. // }
  11328. //
  11329. // if item.MedChrgitmType == "03" { //检查费
  11330. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11331. // checkCostSelfTotal = checkCostTotal
  11332. // }
  11333. //
  11334. // if item.MedChrgitmType == "04" { //化验费
  11335. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11336. // laboratoryCostSelfTotal = laboratoryCostTotal
  11337. // }
  11338. //
  11339. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11340. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11341. // treatCostSelfTotal = treatCostTotal
  11342. // }
  11343. //
  11344. // if item.MedChrgitmType == "06" { //手术费
  11345. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11346. // operationCostSelfTotal = treatCostTotal
  11347. // }
  11348. //
  11349. // if item.MedChrgitmType == "08" { //材料费
  11350. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11351. // materialCostSelfTotal = materialCostTotal
  11352. // }
  11353. //
  11354. // if item.MedChrgitmType == "09" { //西药费
  11355. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11356. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11357. // }
  11358. //
  11359. // if item.MedChrgitmType == "11" { //中成费
  11360. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11361. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11362. // }
  11363. //
  11364. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11365. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11366. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11367. // otherCostSelfTotal = otherCostTotal
  11368. // }
  11369. // } else {
  11370. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11371. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11372. // otherCostSelfTotal = otherCostTotal
  11373. // }
  11374. //
  11375. // }
  11376. //
  11377. // }
  11378. //
  11379. // } else {
  11380. // for _, item := range orderInfos {
  11381. // if item.MedChrgitmType == "01" { //床位费
  11382. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11383. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11384. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11385. // }
  11386. //
  11387. // if item.MedChrgitmType == "02" { //诊察费
  11388. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11389. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11390. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11391. // }
  11392. //
  11393. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11394. // if item.MedChrgitmType == "03" { //检查费
  11395. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11396. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11397. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11398. //
  11399. // }
  11400. // } else {
  11401. // if item.MedChrgitmType == "03" { //检查费
  11402. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11403. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11404. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11405. // }
  11406. //
  11407. // }
  11408. //
  11409. // if item.MedChrgitmType == "04" { //化验费
  11410. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11411. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11412. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11413. //
  11414. // }
  11415. //
  11416. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11417. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11418. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11419. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11420. //
  11421. // }
  11422. //
  11423. // if item.MedChrgitmType == "06" { //手术费
  11424. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11425. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11426. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11427. // }
  11428. //
  11429. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11430. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11431. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11432. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11433. // }
  11434. //
  11435. // if item.MedChrgitmType == "09" { //西药费
  11436. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11437. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11438. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11439. // }
  11440. //
  11441. // if item.MedChrgitmType == "11" { //中成费
  11442. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11443. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11444. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11445. // }
  11446. //
  11447. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11448. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11449. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11450. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11451. // }
  11452. //
  11453. // }
  11454. // }
  11455. // timeLayout := "2006-01-02"
  11456. // loc, _ := time.LoadLocation("Local")
  11457. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11458. // if err != nil {
  11459. // }
  11460. // startRecordDateTime := startTime.Unix()
  11461. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11462. // if err != nil {
  11463. // }
  11464. // endRecordDateTime := endTime.Unix()
  11465. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11466. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11467. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11468. //
  11469. // c.ServeSuccessJSON(map[string]interface{}{
  11470. // "order_number": order.Number, //业务流水号
  11471. // "id_card_no": his.IdCardNo, //社会保障号
  11472. // "department_name": department.Name, //科室
  11473. // "number": his.Number, //门诊号
  11474. // "date": order.SettleAccountsDate, //结算日期
  11475. // "name": order.PsnName, //姓名
  11476. // "gender": patient.Gender, //性别
  11477. // "psn_cash_money": order.PsnCashPay, //个人支付
  11478. // "pay_way": "门诊", //结算方式
  11479. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11480. // "admin_user_name": admin.UserName, //收款员
  11481. // "order": order,
  11482. // "order_info": orderInfos_two,
  11483. // "his": his,
  11484. // "bedCostTotal": bedCostTotal,
  11485. // "bedCostSelfTotal": bedCostSelfTotal,
  11486. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11487. // "operationCostTotal": operationCostTotal,
  11488. // "operationCostSelfTotal": operationCostSelfTotal,
  11489. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11490. // "otherCostTotal": otherCostTotal,
  11491. // "otherCostSelfTotal": otherCostSelfTotal,
  11492. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11493. // "materialCostTotal": materialCostTotal,
  11494. // "materialCostSelfTotal": materialCostSelfTotal,
  11495. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11496. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11497. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11498. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11499. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11500. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11501. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11502. // "checkCostTotal": checkCostTotal,
  11503. // "checkCostSelfTotal": checkCostSelfTotal,
  11504. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11505. // "laboratoryCostTotal": laboratoryCostTotal,
  11506. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11507. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11508. // "treatCostTotal": treatCostTotal,
  11509. // "treatCostSelfTotal": treatCostSelfTotal,
  11510. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11511. // "zhenChaCostTotal": zhenChaCostTotal,
  11512. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11513. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11514. // "his_hospital_record": his_hospital_record,
  11515. // "pre_pay_money": pre_pay_money,
  11516. // "refund_sum": sum,
  11517. // })
  11518. //
  11519. //}
  11520. func (this *HisApiController) GetIncomeStatisticsData() {
  11521. start_time := this.GetString("start_time")
  11522. end_time := this.GetString("end_time")
  11523. key_words := this.GetString("key_words")
  11524. limit, _ := this.GetInt64("limit")
  11525. page, _ := this.GetInt64("page")
  11526. if page <= 0 {
  11527. page = 1
  11528. }
  11529. if limit <= 0 {
  11530. limit = 10
  11531. }
  11532. statistics_type, _ := this.GetInt64("statistics_type")
  11533. admin := this.GetAdminUserInfo()
  11534. timeLayout := "2006-01-02"
  11535. loc, _ := time.LoadLocation("Local")
  11536. var theStartTIme int64
  11537. if len(start_time) > 0 {
  11538. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11539. if err != nil {
  11540. theStartTIme = 0
  11541. }
  11542. theStartTIme = theTime.Unix()
  11543. }
  11544. var theEndtTIme int64
  11545. if len(end_time) > 0 {
  11546. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11547. if err != nil {
  11548. theEndtTIme = 0
  11549. }
  11550. theEndtTIme = theTime.Unix()
  11551. }
  11552. if statistics_type == 1 {
  11553. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11554. this.ServeSuccessJSON(map[string]interface{}{
  11555. "list": list,
  11556. "total": total,
  11557. })
  11558. } else {
  11559. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11560. this.ServeSuccessJSON(map[string]interface{}{
  11561. "list": list,
  11562. "total": total,
  11563. })
  11564. }
  11565. }
  11566. func (c *HisApiController) PostProjectInformation() {
  11567. adminUser := c.GetAdminUserInfo()
  11568. orgId := adminUser.CurrentOrgId
  11569. dataBody := make(map[string]interface{}, 0)
  11570. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11571. if err != nil {
  11572. utils.ErrorLog(err.Error())
  11573. return
  11574. }
  11575. utils.ErrorLog("%v", dataBody)
  11576. var projectList []*models.HisProject
  11577. var total_goods []interface{}
  11578. tempProjects := dataBody["projects"].([]interface{})
  11579. total_goods = tempProjects
  11580. for index, projectMap := range tempProjects {
  11581. projectM := projectMap.(map[string]interface{})
  11582. var project models.HisProject
  11583. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  11584. utils.ErrorLog("project_name")
  11585. return
  11586. }
  11587. project_name, _ := projectM["project_name"].(string)
  11588. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  11589. err_log := models.ExportErrLog{
  11590. LogType: 6,
  11591. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11592. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  11593. Status: 1,
  11594. CreateTime: time.Now().Unix(),
  11595. UpdateTime: time.Now().Unix(),
  11596. ExportTime: time.Now().Unix(),
  11597. }
  11598. service.CreateExportErrLog(&err_log)
  11599. continue
  11600. }
  11601. project.ProjectName = project_name
  11602. prices := projectM["price"].(string)
  11603. price, _ := strconv.ParseFloat(prices, 64)
  11604. if price <= 0 { //名字为空则生成一条导入错误日志
  11605. err_log := models.ExportErrLog{
  11606. LogType: 6,
  11607. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11608. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  11609. Status: 1,
  11610. CreateTime: time.Now().Unix(),
  11611. UpdateTime: time.Now().Unix(),
  11612. ExportTime: time.Now().Unix(),
  11613. }
  11614. service.CreateExportErrLog(&err_log)
  11615. continue
  11616. }
  11617. project.Price = price
  11618. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  11619. utils.ErrorLog("unit_id")
  11620. return
  11621. }
  11622. unit := projectM["unit"].(string)
  11623. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  11624. err_log := models.ExportErrLog{
  11625. LogType: 6,
  11626. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11627. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11628. Status: 1,
  11629. CreateTime: time.Now().Unix(),
  11630. UpdateTime: time.Now().Unix(),
  11631. ExportTime: time.Now().Unix(),
  11632. }
  11633. service.CreateExportErrLog(&err_log)
  11634. continue
  11635. }
  11636. project.Unit = unit
  11637. cost_classify := projectM["cost_classify"].(string)
  11638. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11639. err_log := models.ExportErrLog{
  11640. LogType: 6,
  11641. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11642. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11643. Status: 1,
  11644. CreateTime: time.Now().Unix(),
  11645. UpdateTime: time.Now().Unix(),
  11646. ExportTime: time.Now().Unix(),
  11647. }
  11648. service.CreateExportErrLog(&err_log)
  11649. continue
  11650. }
  11651. var costClassify = "费用类别"
  11652. var cost_classify_id int64
  11653. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11654. if len(cost_classify) != 0 {
  11655. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11656. if errcode == gorm.ErrRecordNotFound {
  11657. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11658. dataconfig := models.DictDataconfig{
  11659. ParentId: costClassifyConfig.ID,
  11660. Module: "system",
  11661. OrgId: orgId,
  11662. Name: cost_classify,
  11663. FieldName: "",
  11664. Value: costConfig.Value + 1,
  11665. CreatedTime: "",
  11666. UpdatedTime: "",
  11667. CreateUserId: adminUser.AdminUser.Id,
  11668. Status: 1,
  11669. Remark: "",
  11670. DeleteIdSystem: 0,
  11671. Title: "",
  11672. Content: "",
  11673. Order: 0,
  11674. Code: "",
  11675. }
  11676. service.CreatedDicConfig(&dataconfig)
  11677. }
  11678. }
  11679. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11680. for _, it := range costClassList {
  11681. if cost_classify == it.Name {
  11682. cost_classify_id = int64(it.Value)
  11683. }
  11684. }
  11685. project.CostClassify = cost_classify_id
  11686. executive_section := projectM["executive_section"].(string)
  11687. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11688. err_log := models.ExportErrLog{
  11689. LogType: 6,
  11690. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11691. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11692. Status: 1,
  11693. CreateTime: time.Now().Unix(),
  11694. UpdateTime: time.Now().Unix(),
  11695. ExportTime: time.Now().Unix(),
  11696. }
  11697. service.CreateExportErrLog(&err_log)
  11698. continue
  11699. }
  11700. if len(executive_section) != 0 {
  11701. //查找科室是否有内容
  11702. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11703. if errcodedepart == gorm.ErrRecordNotFound {
  11704. department := models.XtHisDepartment{
  11705. Name: executive_section,
  11706. Status: 1,
  11707. UserOrgId: adminUser.CurrentOrgId,
  11708. CreatedTime: time.Now().Unix(),
  11709. }
  11710. service.CreateDePartment(&department)
  11711. }
  11712. }
  11713. var executive_section_id int64
  11714. departMentList, _ := service.GetAllDepartMent(orgId)
  11715. for _, it := range departMentList {
  11716. if executive_section == it.Name {
  11717. executive_section_id = it.ID
  11718. }
  11719. }
  11720. project.ExecutiveSection = executive_section_id
  11721. medical_coverage := projectM["medical_coverage"].(string)
  11722. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11723. err_log := models.ExportErrLog{
  11724. LogType: 6,
  11725. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11726. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11727. Status: 1,
  11728. CreateTime: time.Now().Unix(),
  11729. UpdateTime: time.Now().Unix(),
  11730. ExportTime: time.Now().Unix(),
  11731. }
  11732. service.CreateExportErrLog(&err_log)
  11733. continue
  11734. }
  11735. var medicalCoverage = "医保等级"
  11736. var medical_coverage_id int64
  11737. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11738. if len(medical_coverage) != 0 {
  11739. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11740. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11741. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11742. dataconfig := models.DictDataconfig{
  11743. ParentId: medicalCoverageConfig.ID,
  11744. Module: "system",
  11745. OrgId: orgId,
  11746. Name: medical_coverage,
  11747. FieldName: "",
  11748. Value: medicalCoverageConfig.Value + 1,
  11749. CreatedTime: "",
  11750. UpdatedTime: "",
  11751. CreateUserId: adminUser.AdminUser.Id,
  11752. Status: 1,
  11753. Remark: "",
  11754. DeleteIdSystem: 0,
  11755. Title: "",
  11756. Content: "",
  11757. Order: 0,
  11758. Code: "",
  11759. }
  11760. service.CreatedDicConfig(&dataconfig)
  11761. }
  11762. }
  11763. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11764. for _, it := range medicalCoverageList {
  11765. if medical_coverage == it.Name {
  11766. medical_coverage_id = int64(it.Value)
  11767. }
  11768. }
  11769. project.MedicalCoverage = medical_coverage_id
  11770. pinyin := projectM["pinyin"].(string)
  11771. project.Pinyin = pinyin
  11772. wubi := projectM["wubi"].(string)
  11773. project.Wubi = wubi
  11774. statistical_classification := projectM["statistical_classification"].(string)
  11775. var statisticalClassification = "统计分类"
  11776. var statistical_classification_id int64
  11777. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11778. if len(statistical_classification) != 0 {
  11779. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11780. if classificationerrcodes == gorm.ErrRecordNotFound {
  11781. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11782. dataconfig := models.DictDataconfig{
  11783. ParentId: classiFication.ID,
  11784. Module: "system",
  11785. OrgId: orgId,
  11786. Name: statistical_classification,
  11787. FieldName: "",
  11788. Value: classiFicationConfig.Value + 1,
  11789. CreatedTime: "",
  11790. UpdatedTime: "",
  11791. CreateUserId: adminUser.AdminUser.Id,
  11792. Status: 1,
  11793. Remark: "",
  11794. DeleteIdSystem: 0,
  11795. Title: "",
  11796. Content: "",
  11797. Order: 0,
  11798. Code: "",
  11799. }
  11800. service.CreatedDicConfig(&dataconfig)
  11801. }
  11802. }
  11803. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11804. for _, it := range classiFicationList {
  11805. if statistical_classification == it.Name {
  11806. statistical_classification_id = int64(it.Value)
  11807. }
  11808. }
  11809. project.StatisticalClassification = statistical_classification_id
  11810. disease_directory := int64(projectM["disease_directory"].(float64))
  11811. project.DiseaseDirectory = disease_directory
  11812. is_record := int64(projectM["is_record"].(float64))
  11813. project.IsRecord = is_record
  11814. medical_code := projectM["medical_code"].(string)
  11815. project.MedicalCode = medical_code
  11816. tube_color := projectM["tube_color"].(string)
  11817. var tubeColor = "试管颜色"
  11818. var tube_color_id int64
  11819. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11820. if len(tube_color) != 0 {
  11821. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11822. if errcodetube == gorm.ErrRecordNotFound {
  11823. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11824. dataconfig := models.DictDataconfig{
  11825. ParentId: tubeColorConfig.ID,
  11826. Module: "system",
  11827. OrgId: orgId,
  11828. Name: tube_color,
  11829. FieldName: "",
  11830. Value: tubeConfig.Value + 1,
  11831. CreatedTime: "",
  11832. UpdatedTime: "",
  11833. CreateUserId: adminUser.AdminUser.Id,
  11834. Status: 1,
  11835. Remark: "",
  11836. DeleteIdSystem: 0,
  11837. Title: "",
  11838. Content: "",
  11839. Order: 0,
  11840. Code: "",
  11841. }
  11842. service.CreatedDicConfig(&dataconfig)
  11843. }
  11844. }
  11845. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11846. for _, it := range tubeColorList {
  11847. if tube_color == it.Name {
  11848. tube_color_id = int64(it.Value)
  11849. }
  11850. }
  11851. project.TubeColor = tube_color_id
  11852. single_dose := projectM["single_dose"].(string)
  11853. project.SingleDose = single_dose
  11854. execution_frequency := projectM["execution_frequency"].(string)
  11855. project.ExecutionFrequency = execution_frequency
  11856. delivery_way := projectM["delivery_way"].(string)
  11857. project.DeliveryWay = delivery_way
  11858. number_days := projectM["number_days"].(string)
  11859. project.NumberDays = number_days
  11860. total := projectM["total"].(string)
  11861. project.Total = total
  11862. medical_status := int64(projectM["medical_status"].(float64))
  11863. project.MedicalStatus = medical_status
  11864. category := int64(projectM["category"].(float64))
  11865. project.Category = category
  11866. specail_project := int64(projectM["specail_project"].(float64))
  11867. project.SpecailProject = specail_project
  11868. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11869. project.SocialSecurityDirectoryCode = social_security_directory_code
  11870. remark := projectM["remark"].(string)
  11871. project.Remark = remark
  11872. record_date := projectM["record_date"].(string)
  11873. timeLayout := "2006-01-02"
  11874. loc, _ := time.LoadLocation("Local")
  11875. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11876. project.RecordDate = theTime.Unix()
  11877. projectList = append(projectList, &project)
  11878. }
  11879. export_time := time.Now().Unix()
  11880. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11881. if len(projectList) > 0 {
  11882. for _, item := range projectList {
  11883. hans := item.ProjectName // 要转换的汉字字符串
  11884. // 创建一个拼音转换器
  11885. p := pinyin.NewArgs()
  11886. // 将汉字转为拼音
  11887. pinyinSlice := pinyin.Pinyin(hans, p)
  11888. // 输出拼音
  11889. fmt.Println("Pinyin:", pinyinSlice)
  11890. // 获取首字母
  11891. firstLetter := ""
  11892. for _, py := range pinyinSlice {
  11893. if len(py) > 0 {
  11894. firstLetter += string(py[0][0])
  11895. }
  11896. }
  11897. item.FirstLetter = firstLetter
  11898. project := models.HisProject{
  11899. ProjectName: item.ProjectName,
  11900. Price: item.Price,
  11901. Unit: item.Unit,
  11902. CostClassify: item.CostClassify,
  11903. ExecutiveSection: item.ExecutiveSection,
  11904. MedicalCoverage: item.MedicalCoverage,
  11905. UserOrgId: orgId,
  11906. Status: 1,
  11907. CreatedTime: time.Now().Unix(),
  11908. Pinyin: item.Pinyin,
  11909. Wubi: item.Wubi,
  11910. StatisticalClassification: item.StatisticalClassification,
  11911. DiseaseDirectory: item.DiseaseDirectory,
  11912. IsRecord: item.IsRecord,
  11913. MedicalCode: item.MedicalCode,
  11914. TubeColor: item.TubeColor,
  11915. SingleDose: item.SingleDose,
  11916. DeliveryWay: item.DeliveryWay,
  11917. NumberDays: item.NumberDays,
  11918. Total: item.Total,
  11919. Category: item.Category,
  11920. MedicalStatus: item.MedicalStatus,
  11921. SpecailProject: item.SpecailProject,
  11922. RecordDate: item.RecordDate,
  11923. Remark: item.Remark,
  11924. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11925. ExecutionFrequency: item.ExecutionFrequency,
  11926. FirstLetter: item.FirstLetter,
  11927. }
  11928. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11929. if errcodeproject == gorm.ErrRecordNotFound {
  11930. service.CreateProjectInfomation(&project)
  11931. } else if errcodeproject == nil {
  11932. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11933. }
  11934. log := models.ExportLog{
  11935. LogType: 6,
  11936. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11937. TotalNum: int64(len(total_goods)),
  11938. FailNum: int64(len(errLogs)),
  11939. SuccessNum: int64(len(projectList)),
  11940. CreateTime: time.Now().Unix(),
  11941. UpdateTime: time.Now().Unix(),
  11942. ExportTime: export_time,
  11943. Status: 1,
  11944. }
  11945. service.CreateExportLog(&log)
  11946. c.ServeSuccessJSON(map[string]interface{}{
  11947. "msg": "导入成功",
  11948. "total_num": len(total_goods),
  11949. "success_num": len(projectList),
  11950. "fail_num": int64(len(errLogs)),
  11951. })
  11952. }
  11953. } else {
  11954. log := models.ExportLog{
  11955. LogType: 6,
  11956. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11957. TotalNum: int64(len(total_goods)),
  11958. FailNum: int64(len(errLogs)),
  11959. SuccessNum: int64(len(projectList)),
  11960. CreateTime: time.Now().Unix(),
  11961. UpdateTime: time.Now().Unix(),
  11962. ExportTime: export_time,
  11963. Status: 1,
  11964. }
  11965. service.CreateExportLog(&log)
  11966. c.ServeSuccessJSON(map[string]interface{}{
  11967. "msg": "导入成功",
  11968. "total_num": len(total_goods),
  11969. "success_num": len(projectList),
  11970. "fail_num": int64(len(errLogs)),
  11971. })
  11972. }
  11973. }
  11974. //func (this *HisApiController) EditProjectInformation(){
  11975. //
  11976. // id, _ := this.GetInt64("id")
  11977. // project_team := this.GetString("project_team")
  11978. // price := this.GetString("price")
  11979. // price_float, _ := strconv.ParseFloat(price, 64)
  11980. // pinyin := this.GetString("pinyin")
  11981. // wubi := this.GetString("wubi")
  11982. // tube_color, _ := this.GetInt64("tube_color")
  11983. // team_type, _ := this.GetInt64("team_type")
  11984. // remark := this.GetString("remark")
  11985. // ids := this.GetString("ids")
  11986. // item_id := this.GetString("item_id")
  11987. // projectTeam := models.XtHisProjectTeam{
  11988. // ProjectTeam: project_team,
  11989. // Price: price_float,
  11990. // Pinyin: pinyin,
  11991. // Wubi: wubi,
  11992. // TubeColor: tube_color,
  11993. // TeamType: team_type,
  11994. // Remark: remark,
  11995. // ProjectId: ids,
  11996. // ItemId: item_id,
  11997. // }
  11998. //
  11999. //
  12000. // dataBody := make(map[string]interface{}, 0)
  12001. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12002. // if err != nil {
  12003. // utils.ErrorLog(err.Error())
  12004. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12005. // return
  12006. // }
  12007. //
  12008. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12009. //
  12010. //
  12011. // if err != nil {
  12012. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12013. // return
  12014. // }
  12015. //
  12016. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12017. // infos, _ := dataBody["info"].([]interface{})
  12018. // if len(infos) > 0 {
  12019. // var ids []string
  12020. //
  12021. // for _, item := range infos {
  12022. // items := item.(map[string]interface{})
  12023. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12024. // utils.ErrorLog("id")
  12025. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12026. // return
  12027. // }
  12028. // id := int64(items["id"].(float64))
  12029. //
  12030. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12031. // utils.ErrorLog("type")
  12032. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12033. // return
  12034. // }
  12035. // types := int64(items["type"].(float64))
  12036. //
  12037. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12038. // utils.ErrorLog("number")
  12039. // }
  12040. //
  12041. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12042. //
  12043. // projectList := models.XtHisProjectList{
  12044. // Number: number,
  12045. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12046. // ProjectId: id,
  12047. // Status: 1,
  12048. // CreatedTime: time.Now().Unix(),
  12049. // UpdatedTime: time.Now().Unix(),
  12050. // TeamId: projectTeam.ID,
  12051. // Type: types,
  12052. // }
  12053. // list := projectList
  12054. //
  12055. // service.CreateProjectList(&list)
  12056. //
  12057. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12058. //
  12059. // }
  12060. // ids_str := strings.Join(ids, ",")
  12061. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12062. // service.SaveProjectTeam(&projectTeam)
  12063. // this.ServeSuccessJSON(map[string]interface{}{
  12064. // "projectTeam": projectTeam,
  12065. // })
  12066. // }
  12067. // }
  12068. //}
  12069. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12070. name := c.GetString("name")
  12071. mode_id, _ := c.GetInt64("mode", 0)
  12072. types, _ := c.GetInt64("type", 0)
  12073. patient_id, _ := c.GetInt64("patient_id", 0)
  12074. types = 1
  12075. adminInfo := c.GetAdminUserInfo()
  12076. template := &models.HisPrescriptionTemplate{
  12077. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12078. PatientId: patient_id,
  12079. Type: types,
  12080. Status: 1,
  12081. Ctime: time.Now().Unix(),
  12082. Mtime: time.Now().Unix(),
  12083. Name: name,
  12084. Mode: mode_id,
  12085. }
  12086. dataBody := make(map[string]interface{}, 0)
  12087. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12088. if err != nil {
  12089. utils.ErrorLog(err.Error())
  12090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12091. return
  12092. }
  12093. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12094. //如果已经存在记录则删除处方
  12095. if template_one.ID > 0 {
  12096. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12097. var ids []int64
  12098. var org_id int64
  12099. for _, item := range ps {
  12100. org_id = c.GetAdminUserInfo().CurrentOrgId
  12101. ids = append(ids, item.ID)
  12102. }
  12103. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12104. if err2 == nil {
  12105. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12106. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12107. if len(prescriptions) > 0 {
  12108. for _, item := range prescriptions {
  12109. items := item.(map[string]interface{})
  12110. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12111. utils.ErrorLog("type")
  12112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12113. return
  12114. }
  12115. types := int64(items["type"].(float64))
  12116. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12117. utils.ErrorLog("med_type")
  12118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12119. return
  12120. }
  12121. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12122. ctime := time.Now().Unix()
  12123. prescription := &models.HisPrescriptionInfoTemplate{
  12124. PatientId: patient_id,
  12125. UserOrgId: adminInfo.CurrentOrgId,
  12126. Ctime: ctime,
  12127. Mtime: ctime,
  12128. Type: types,
  12129. Modifier: adminInfo.AdminUser.Id,
  12130. Creator: adminInfo.AdminUser.Id,
  12131. Status: 1,
  12132. PTemplateId: template_one.ID,
  12133. MedType: med_type,
  12134. }
  12135. service.CreateHisPrescriptionInfoTemplate(prescription)
  12136. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12137. advices := items["advices"].([]interface{})
  12138. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12139. ctime := time.Now().Unix()
  12140. mtime := ctime
  12141. if len(advices) > 0 {
  12142. for _, advice := range advices {
  12143. var s models.HisPrescriptionAdviceTemplate
  12144. s.PrescriptionId = prescription.ID
  12145. s.AdviceType = 2
  12146. s.StopState = 2
  12147. s.ExecutionState = 2
  12148. s.Status = 1
  12149. s.UserOrgId = adminInfo.CurrentOrgId
  12150. s.CreatedTime = ctime
  12151. s.UpdatedTime = mtime
  12152. s.PatientId = patient_id
  12153. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12154. if errcode > 0 {
  12155. c.ServeFailJSONWithSGJErrorCode(errcode)
  12156. return
  12157. }
  12158. service.CreateHisPrescriptionAdviceTemplate(&s)
  12159. }
  12160. }
  12161. }
  12162. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12163. projects := items["project"].([]interface{})
  12164. if len(projects) > 0 {
  12165. for _, project := range projects {
  12166. var p models.HisPrescriptionProjectTemplate
  12167. p.PrescriptionId = prescription.ID
  12168. p.Ctime = time.Now().Unix()
  12169. p.Mtime = time.Now().Unix()
  12170. p.PatientId = patient_id
  12171. p.UserOrgId = adminInfo.CurrentOrgId
  12172. p.Status = 1
  12173. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12174. if errcode > 0 {
  12175. c.ServeFailJSONWithSGJErrorCode(errcode)
  12176. return
  12177. }
  12178. service.CreateHisPrescriptionProjectTemplate(&p)
  12179. }
  12180. }
  12181. }
  12182. }
  12183. c.ServeSuccessJSON(map[string]interface{}{
  12184. "msg": "创建成功",
  12185. })
  12186. }
  12187. }
  12188. } else {
  12189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12190. return
  12191. }
  12192. } else {
  12193. err3 := service.CreateHisPrescriptionTemplate(template)
  12194. if err3 == nil {
  12195. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12196. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12197. if len(prescriptions) > 0 {
  12198. for _, item := range prescriptions {
  12199. items := item.(map[string]interface{})
  12200. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12201. utils.ErrorLog("type")
  12202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12203. return
  12204. }
  12205. types := int64(items["type"].(float64))
  12206. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12207. utils.ErrorLog("med_type")
  12208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12209. return
  12210. }
  12211. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12212. ctime := time.Now().Unix()
  12213. prescription := &models.HisPrescriptionInfoTemplate{
  12214. PatientId: patient_id,
  12215. UserOrgId: adminInfo.CurrentOrgId,
  12216. Ctime: ctime,
  12217. Mtime: ctime,
  12218. Type: types,
  12219. Modifier: adminInfo.AdminUser.Id,
  12220. Creator: adminInfo.AdminUser.Id,
  12221. Status: 1,
  12222. PTemplateId: template.ID,
  12223. MedType: med_type,
  12224. }
  12225. service.CreateHisPrescriptionInfoTemplate(prescription)
  12226. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12227. advices := items["advices"].([]interface{})
  12228. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12229. ctime := time.Now().Unix()
  12230. mtime := ctime
  12231. if len(advices) > 0 {
  12232. for _, advice := range advices {
  12233. var s models.HisPrescriptionAdviceTemplate
  12234. s.PrescriptionId = prescription.ID
  12235. s.AdviceType = 2
  12236. s.StopState = 2
  12237. s.ExecutionState = 2
  12238. s.Status = 1
  12239. s.UserOrgId = adminInfo.CurrentOrgId
  12240. s.CreatedTime = ctime
  12241. s.UpdatedTime = mtime
  12242. s.PatientId = patient_id
  12243. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12244. if errcode > 0 {
  12245. c.ServeFailJSONWithSGJErrorCode(errcode)
  12246. return
  12247. }
  12248. service.CreateHisPrescriptionAdviceTemplate(&s)
  12249. }
  12250. }
  12251. }
  12252. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12253. projects := items["project"].([]interface{})
  12254. if len(projects) > 0 {
  12255. for _, project := range projects {
  12256. var p models.HisPrescriptionProjectTemplate
  12257. p.PrescriptionId = prescription.ID
  12258. p.Ctime = time.Now().Unix()
  12259. p.Mtime = time.Now().Unix()
  12260. p.PatientId = patient_id
  12261. p.UserOrgId = adminInfo.CurrentOrgId
  12262. p.Status = 1
  12263. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12264. if errcode > 0 {
  12265. c.ServeFailJSONWithSGJErrorCode(errcode)
  12266. return
  12267. }
  12268. service.CreateHisPrescriptionProjectTemplate(&p)
  12269. }
  12270. }
  12271. }
  12272. }
  12273. c.ServeSuccessJSON(map[string]interface{}{
  12274. "msg": "创建成功",
  12275. })
  12276. }
  12277. }
  12278. } else {
  12279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12280. return
  12281. }
  12282. }
  12283. }
  12284. func (c *HisApiController) PreSettle() {
  12285. id, _ := c.GetInt64("id")
  12286. record_time := c.GetString("record_time")
  12287. his_patient_id, _ := c.GetInt64("his_patient_id")
  12288. timeLayout := "2006-01-02"
  12289. loc, _ := time.LoadLocation("Local")
  12290. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12291. diagnosis_id := c.GetString("diagnosis")
  12292. sick_type, _ := c.GetInt64("sick_type")
  12293. reg_type, _ := c.GetInt64("p_type")
  12294. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12295. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12296. if err != nil {
  12297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12298. return
  12299. }
  12300. recordDateTime := theTime.Unix()
  12301. adminUser := c.GetAdminUserInfo()
  12302. var prescriptions []*models.HisPrescription
  12303. var start_time int64
  12304. var end_time int64
  12305. ids_str := c.GetString("ids")
  12306. ids_arr := strings.Split(ids_str, ",")
  12307. fmt.Println(reg_type)
  12308. if settle_accounts_type == 1 { //日结
  12309. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12310. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12311. } else {
  12312. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12313. }
  12314. fmt.Println(prescriptions)
  12315. } else { //月结
  12316. start_time_str := c.GetString("start_time")
  12317. end_time_str := c.GetString("end_time")
  12318. timeLayout := "2006-01-02"
  12319. loc, _ := time.LoadLocation("Local")
  12320. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12321. if err != nil {
  12322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12323. return
  12324. }
  12325. recordStartTime := theStartTime.Unix()
  12326. start_time = recordStartTime
  12327. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12328. if err != nil {
  12329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12330. return
  12331. }
  12332. recordEndTime := theEndTime.Unix()
  12333. end_time = recordEndTime
  12334. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12335. }
  12336. if reg_type == 1111 || reg_type == 1112 {
  12337. reg_type = 11
  12338. }
  12339. timestamp := time.Now().Unix()
  12340. tempTime := time.Unix(timestamp, 0)
  12341. timeFormat := tempTime.Format("20060102150405")
  12342. chrgBchno := rand.Intn(100000) + 10000
  12343. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12344. strconv.FormatInt(his.PatientId, 10)
  12345. var ids []int64
  12346. for _, item := range prescriptions {
  12347. ids = append(ids, item.ID)
  12348. }
  12349. fmt.Println(ids)
  12350. var total float64
  12351. for _, item := range prescriptions {
  12352. fmt.Println(item)
  12353. if item.Type == 1 { //药品
  12354. for _, subItem := range item.HisDoctorAdviceInfo {
  12355. total = total + (subItem.Price * subItem.PrescribingNumber)
  12356. }
  12357. }
  12358. if item.Type == 2 { //项目
  12359. for _, subItem := range item.HisPrescriptionProject {
  12360. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12361. total = total + (subItem.Price * cnt)
  12362. }
  12363. }
  12364. for _, subItem := range item.HisAdditionalCharge {
  12365. total = total + (subItem.Price * float64(subItem.Count))
  12366. }
  12367. }
  12368. allTotal := fmt.Sprintf("%.2f", total)
  12369. totals, _ := strconv.ParseFloat(allTotal, 64)
  12370. order := &models.HisOrder{
  12371. UserOrgId: adminUser.CurrentOrgId,
  12372. HisPatientId: his.ID,
  12373. PatientId: id,
  12374. SettleAccountsDate: recordDateTime,
  12375. Ctime: time.Now().Unix(),
  12376. Mtime: time.Now().Unix(),
  12377. Status: 1,
  12378. OrderStatus: 1,
  12379. MdtrtId: his.Number,
  12380. Number: chrg_bchno,
  12381. MedfeeSumamt: totals,
  12382. SettleEndTime: end_time,
  12383. SettleStartTime: start_time,
  12384. SettleType: settle_accounts_type,
  12385. PsnPartAmt: totals,
  12386. PsnCashPay: totals,
  12387. PType: 2,
  12388. IsPre: 1,
  12389. MedType: strconv.Itoa(int(reg_type)),
  12390. Diagnosis: diagnosis_id,
  12391. }
  12392. err = service.CreateOrder(order)
  12393. if err != nil {
  12394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12395. return
  12396. }
  12397. var customs []*Custom
  12398. for _, item := range prescriptions {
  12399. fmt.Println(item.Type)
  12400. if item.Type == 1 { //药品
  12401. for _, subItem := range item.HisDoctorAdviceInfo {
  12402. cus := &Custom{
  12403. AdviceId: subItem.ID,
  12404. ProjectId: 0,
  12405. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12406. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12407. FeedetlSn: subItem.FeedetlSn,
  12408. Price: fmt.Sprintf("%.2f", subItem.Price),
  12409. MedListCodg: subItem.MedListCodg,
  12410. Type: 1,
  12411. }
  12412. customs = append(customs, cus)
  12413. }
  12414. }
  12415. if item.Type == 2 { //项目
  12416. for _, subItem := range item.HisPrescriptionProject {
  12417. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12418. cus := &Custom{
  12419. AdviceId: 0,
  12420. ProjectId: subItem.ID,
  12421. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12422. Cut: fmt.Sprintf("%.2f", cnt),
  12423. FeedetlSn: subItem.FeedetlSn,
  12424. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12425. MedListCodg: subItem.MedListCodg,
  12426. Type: 2,
  12427. }
  12428. customs = append(customs, cus)
  12429. }
  12430. }
  12431. for _, item := range item.HisAdditionalCharge {
  12432. cus := &Custom{
  12433. ItemId: item.ID,
  12434. AdviceId: 0,
  12435. ProjectId: 0,
  12436. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12437. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12438. FeedetlSn: item.FeedetlSn,
  12439. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12440. MedListCodg: item.XtHisAddtionConfig.Code,
  12441. Type: 3,
  12442. }
  12443. customs = append(customs, cus)
  12444. }
  12445. }
  12446. fmt.Println(customs)
  12447. for _, item := range customs {
  12448. var advice_id int64 = 0
  12449. var project_id int64 = 0
  12450. var item_id int64 = 0
  12451. var types int64 = 0
  12452. if item.Type == 1 {
  12453. advice_id = item.AdviceId
  12454. project_id = 0
  12455. item_id = 0
  12456. } else if item.Type == 2 {
  12457. advice_id = 0
  12458. item_id = 0
  12459. project_id = item.ProjectId
  12460. } else if item.Type == 3 {
  12461. advice_id = 0
  12462. item_id = item.ItemId
  12463. project_id = 0
  12464. }
  12465. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12466. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12467. pric, _ := strconv.ParseFloat(item.Price, 32)
  12468. info := &models.HisOrderInfo{
  12469. OrderNumber: order.Number,
  12470. UploadDate: time.Now().Unix(),
  12471. AdviceId: advice_id,
  12472. DetItemFeeSumamt: detItemFeeSumamt,
  12473. Cnt: cut,
  12474. Pric: pric,
  12475. PatientId: id,
  12476. Status: 1,
  12477. Mtime: time.Now().Unix(),
  12478. Ctime: time.Now().Unix(),
  12479. UserOrgId: adminUser.CurrentOrgId,
  12480. HisPatientId: his.ID,
  12481. OrderId: order.ID,
  12482. ProjectId: project_id,
  12483. Type: types,
  12484. ItemId: item_id,
  12485. }
  12486. service.CreateOrderInfo(info)
  12487. }
  12488. his.SickType = sick_type
  12489. service.UpdataHisPateint(&his)
  12490. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12491. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12492. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12493. if err == nil {
  12494. c.ServeSuccessJSON(map[string]interface{}{
  12495. "msg": "结算成功",
  12496. })
  12497. }
  12498. }
  12499. type CustomOrderInfo struct {
  12500. Name string
  12501. Spec string
  12502. Unit string
  12503. Count float64
  12504. Price float64
  12505. Total float64
  12506. }
  12507. func (c *HisApiController) GetPrivateExpensesInfo() {
  12508. order_id, _ := c.GetInt64("id", 0)
  12509. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12510. order, _ := service.GetHisOrderByID(order_id)
  12511. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12512. if order.ID == 0 {
  12513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12514. return
  12515. }
  12516. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12517. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12518. org_id := c.GetAdminUserInfo().CurrentOrgId
  12519. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12520. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12521. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12522. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12523. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12524. //var orderInfos_four []*models.HisOrderInfoTwo
  12525. //for _, item := range orderInfos_three {
  12526. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  12527. // item.HisPrescriptionProject.IsCheckTeam = 1
  12528. // orderInfos_four = append(orderInfos_four, item)
  12529. //
  12530. // }
  12531. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  12532. // item.HisPrescriptionProject.IsCheckTeam = 2
  12533. // orderInfos_two = append(orderInfos_two, item)
  12534. // }
  12535. //}
  12536. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  12537. //var cus_slice []CustomOrderInfo
  12538. //for _, item := range new_order_info {
  12539. // var cus CustomOrderInfo
  12540. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  12541. // cus.Unit = ""
  12542. // cus.Spec = ""
  12543. // var total float64
  12544. // for _, subItem := range orderInfos_four {
  12545. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  12546. // total = total + subItem.DetItemFeeSumamt
  12547. // fmt.Println(subItem.DetItemFeeSumamt)
  12548. // }
  12549. // }
  12550. // cus.Count = 1
  12551. // cus.Total = total
  12552. // cus_slice = append(cus_slice, cus)
  12553. //}
  12554. orderInfos = append(orderInfos, orderInfos_two...)
  12555. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  12556. //orderInfos = append(orderInfos, orderInfos_three...)
  12557. //}/**/
  12558. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  12559. c.ServeSuccessJSON(map[string]interface{}{
  12560. "order": order,
  12561. "order_info": orderInfos,
  12562. "patient": patient,
  12563. "admin_info": adminInfo,
  12564. "his": his,
  12565. "current_admin": role,
  12566. "org_config": miConfig,
  12567. //"new_order_info": cus_slice,
  12568. })
  12569. }
  12570. func (this *HisApiController) ChangeMedType() {
  12571. med_type := this.GetString("med_type")
  12572. old_med_type := this.GetString("old_med_type")
  12573. ids := this.GetString("ids")
  12574. settle_type, _ := this.GetInt64("settle_type")
  12575. start_time := this.GetString("start_time")
  12576. end_time := this.GetString("end_time")
  12577. ids_arr := strings.Split(ids, ",")
  12578. if settle_type == 1 { //日结
  12579. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  12580. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  12581. prescription.MedType = med_type
  12582. err := service.SaveHisPrescriptionTwo(&prescription)
  12583. if err == nil {
  12584. this.ServeSuccessJSON(map[string]interface{}{
  12585. "msg": "修改成功",
  12586. })
  12587. } else {
  12588. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12589. return
  12590. }
  12591. } else if settle_type == 2 {
  12592. timeLayout := "2006-01-02"
  12593. loc, _ := time.LoadLocation("Local")
  12594. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12595. if err != nil {
  12596. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12597. return
  12598. }
  12599. recordStartTime := theStartTime.Unix()
  12600. start_time_timestamp := recordStartTime
  12601. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  12602. if err != nil {
  12603. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12604. return
  12605. }
  12606. recordEndTime := theEndTime.Unix()
  12607. end_time_timestamp := recordEndTime
  12608. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  12609. if updateErr == nil {
  12610. this.ServeSuccessJSON(map[string]interface{}{
  12611. "msg": "修改成功",
  12612. })
  12613. } else {
  12614. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12615. return
  12616. }
  12617. }
  12618. }
  12619. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  12620. patient_id, _ := c.GetInt64("patient_id")
  12621. his_patient_id, _ := c.GetInt64("his_patient_id")
  12622. record_date := c.GetString("record_date")
  12623. start_time := c.GetString("start_time")
  12624. end_time := c.GetString("end_time")
  12625. order_status, _ := c.GetInt64("type", 0)
  12626. p_type, _ := c.GetInt64("p_type", 0)
  12627. order_id, _ := c.GetInt64("order_id", 0)
  12628. timeLayout := "2006-01-02"
  12629. loc, _ := time.LoadLocation("Local")
  12630. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12631. if err != nil {
  12632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12633. return
  12634. }
  12635. recordDateTime := theTime.Unix()
  12636. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12637. if err != nil {
  12638. }
  12639. startRecordDateTime := startTime.Unix()
  12640. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12641. if err != nil {
  12642. }
  12643. endRecordDateTime := endTime.Unix()
  12644. admin := c.GetAdminUserInfo()
  12645. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12646. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12647. order, _ := service.GetHisOrderByID(order_id)
  12648. var monthPrescriptions []*models.HisPrescription
  12649. if order_status == 1 || order_status == 0 {
  12650. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12651. } else if order_status == 2 {
  12652. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12653. }
  12654. var settle_total float64
  12655. for _, item := range monthPrescriptions {
  12656. if len(item.HisPrescriptionProject) > 0 {
  12657. for _, subItem := range item.HisPrescriptionProject {
  12658. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12659. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12660. settle_total = settle_total + total
  12661. }
  12662. }
  12663. if len(item.HisDoctorAdviceInfo) > 0 {
  12664. for _, subItem := range item.HisDoctorAdviceInfo {
  12665. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12666. settle_total = settle_total + total
  12667. }
  12668. }
  12669. }
  12670. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12671. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12672. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12673. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12674. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12675. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12676. //获取所有科室信息
  12677. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12678. var dia string
  12679. for _, item := range month_p_info {
  12680. if len(dia) == 0 {
  12681. dia = item.Diagnosis
  12682. } else {
  12683. dia = dia + "," + item.Diagnosis
  12684. }
  12685. }
  12686. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12687. dia_arr = removeEmptyStrings(dia_arr)
  12688. c.ServeSuccessJSON(map[string]interface{}{
  12689. "his_info": his_patient_info,
  12690. "xt_info": xt_patient_info,
  12691. "case_history": case_history,
  12692. "info": patientPrescriptionInfo,
  12693. "last_info": lastPatientPrescriptionInfo,
  12694. "month_prescriptions": monthPrescriptions,
  12695. "order": order,
  12696. "doctors": doctors,
  12697. "department": department,
  12698. "settle_total": settle_total,
  12699. "dia_arr": dia_arr,
  12700. })
  12701. return
  12702. }
  12703. func removeEmptyStrings(input []string) []string {
  12704. var output []string
  12705. for _, s := range input {
  12706. if s != "" {
  12707. output = append(output, s)
  12708. }
  12709. }
  12710. return output
  12711. }
  12712. func removeDuplicates(input []string) []string {
  12713. seen := make(map[string]bool)
  12714. output := []string{}
  12715. for _, s := range input {
  12716. if _, exists := seen[s]; !exists {
  12717. seen[s] = true
  12718. output = append(output, s)
  12719. }
  12720. }
  12721. return output
  12722. }
  12723. func (c *HisApiController) GetHisMonthPatientInfo() {
  12724. patient_id, _ := c.GetInt64("patient_id")
  12725. his_patient_id, _ := c.GetInt64("his_patient_id")
  12726. record_date := c.GetString("record_date")
  12727. number := c.GetString("number")
  12728. start_time := c.GetString("start_time")
  12729. end_time := c.GetString("end_time")
  12730. p_type, _ := c.GetInt64("p_type")
  12731. timeLayout := "2006-01-02"
  12732. loc, _ := time.LoadLocation("Local")
  12733. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12734. if err != nil {
  12735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12736. return
  12737. }
  12738. recordDateTime := theTime.Unix()
  12739. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12740. if err != nil {
  12741. }
  12742. startRecordDateTime := startTime.Unix()
  12743. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12744. if err != nil {
  12745. }
  12746. endRecordDateTime := endTime.Unix()
  12747. admin := c.GetAdminUserInfo()
  12748. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12749. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12750. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12751. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12752. var settle_total float64
  12753. for _, item := range monthPrescriptions {
  12754. if len(item.HisPrescriptionProject) > 0 {
  12755. for _, subItem := range item.HisPrescriptionProject {
  12756. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12757. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12758. settle_total = settle_total + total
  12759. }
  12760. }
  12761. if len(item.HisDoctorAdviceInfo) > 0 {
  12762. for _, subItem := range item.HisDoctorAdviceInfo {
  12763. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12764. settle_total = settle_total + total
  12765. }
  12766. }
  12767. }
  12768. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12769. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12770. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12771. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12772. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12773. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12774. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12775. //获取所有科室信息
  12776. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12777. c.ServeSuccessJSON(map[string]interface{}{
  12778. "his_info": his_patient_info,
  12779. "xt_info": xt_patient_info,
  12780. "case_history": case_history,
  12781. "info": patientPrescriptionInfo,
  12782. "month_prescriptions": monthPrescriptions,
  12783. "order": order,
  12784. "doctors": doctors,
  12785. "department": department,
  12786. "count": count,
  12787. "drugStockConfig": drugStockConfig,
  12788. "last_info": lastPatientPrescriptionInfo,
  12789. "settle_total": settle_total,
  12790. })
  12791. return
  12792. }
  12793. func (c *HisApiController) GetAllOrder() {
  12794. org_id := c.GetAdminUserInfo().CurrentOrgId
  12795. orders, _ := service.GetNewHisOrderList(org_id)
  12796. c.ServeSuccessJSON(map[string]interface{}{
  12797. "order": orders,
  12798. })
  12799. return
  12800. }
  12801. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12802. newArr = make([]*models.HisOrderInfoTwo, 0)
  12803. for i := 0; i < len(arr); i++ {
  12804. repeat := false
  12805. for j := i + 1; j < len(arr); j++ {
  12806. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12807. repeat = true
  12808. break
  12809. }
  12810. }
  12811. if !repeat {
  12812. newArr = append(newArr, arr[i])
  12813. }
  12814. }
  12815. return
  12816. }
  12817. // 修改处方退库操作 参数传修改之前的处方数据
  12818. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12819. if advice.ExecutionState == 1 {
  12820. //查询该病人该药品是否有库存记录
  12821. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12822. if errcode == gorm.ErrRecordNotFound {
  12823. } else {
  12824. //退库
  12825. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12826. if advice.PrescribingNumberUnit == drug.MinUnit {
  12827. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12828. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12829. //退库
  12830. warehouseInfo := models.DrugWarehouseInfo{
  12831. StockMinNumber: prescribingNumber,
  12832. }
  12833. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12834. operation_time := time.Now().Unix()
  12835. creater := advice.AdviceDoctor
  12836. ctime := time.Now().Unix()
  12837. timeStr := time.Now().Format("2006-01-02")
  12838. timeArr := strings.Split(timeStr, "-")
  12839. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12840. total = total + 1
  12841. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12842. cancelStock := models.DrugCancelStock{
  12843. OrderNumber: orderNumber,
  12844. OperaTime: operation_time,
  12845. OrgId: advice.UserOrgId,
  12846. Creater: creater,
  12847. Ctime: ctime,
  12848. Status: 1,
  12849. ReturnTime: advice.AdviceDate,
  12850. Dealer: info.Dealer,
  12851. Manufacturer: info.Manufacturer,
  12852. Type: 1,
  12853. }
  12854. service.AddSigleDrugCancelStock(&cancelStock)
  12855. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12856. dealer, _ := service.GetDealerById(info.Dealer)
  12857. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12858. cancelStockInfo := models.DrugCancelStockInfo{
  12859. OrderNumber: cancelInfo.OrderNumber,
  12860. CancelStockId: cancelInfo.ID,
  12861. DrugId: info.DrugId,
  12862. Count: info.Count,
  12863. Status: 1,
  12864. Ctime: ctime,
  12865. OrgId: advice.UserOrgId,
  12866. Type: 1,
  12867. Manufacturer: manufactureName.ManufacturerName,
  12868. Dealer: dealer.DealerName,
  12869. Total: 0,
  12870. RetailPrice: info.RetailPrice,
  12871. RetailTotalPrice: info.RetailTotalPrice,
  12872. Price: info.Price,
  12873. RegisterAccount: "",
  12874. Remark: info.Remark,
  12875. BatchNumber: info.BatchNumber,
  12876. MaxUnit: info.CountUnit,
  12877. ProductDate: info.ProductDate,
  12878. ExpiryDate: info.ExpiryDate,
  12879. BatchNumberId: info.WarehouseInfoId,
  12880. }
  12881. flow := models.DrugFlow{
  12882. WarehousingId: 0,
  12883. DrugId: info.DrugId,
  12884. Number: "",
  12885. BatchNumber: info.BatchNumber,
  12886. Count: info.Count,
  12887. UserOrgId: advice.UserOrgId,
  12888. PatientId: 0,
  12889. SystemTime: ctime,
  12890. ConsumableType: 4,
  12891. IsSys: 0,
  12892. WarehousingOrder: "",
  12893. WarehouseOutId: 0,
  12894. WarehouseOutOrderNumber: "",
  12895. IsEdit: 0,
  12896. CancelStockId: cancelStock.ID,
  12897. CancelOrderNumber: cancelStock.OrderNumber,
  12898. Manufacturer: info.Manufacturer,
  12899. Dealer: info.Dealer,
  12900. Creator: advice.UserOrgId,
  12901. UpdateCreator: 0,
  12902. Status: 1,
  12903. Ctime: time.Now().Unix(),
  12904. Mtime: 0,
  12905. Price: info.Price,
  12906. WarehousingDetailId: 0,
  12907. WarehouseOutDetailId: 0,
  12908. CancelOutDetailId: 0,
  12909. ExpireDate: info.ExpiryDate,
  12910. ProductDate: info.ProductDate,
  12911. MaxUnit: info.CountUnit,
  12912. MinUnit: "",
  12913. }
  12914. service.CreatedCancelStock(cancelStockInfo)
  12915. service.CreateDrugFlowOne(flow)
  12916. } else {
  12917. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12918. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12919. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12920. warehouseInfo := models.DrugWarehouseInfo{
  12921. StockMinNumber: prescribingNumber,
  12922. }
  12923. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12924. }
  12925. operation_time := time.Now().Unix()
  12926. creater := advice.AdviceDoctor
  12927. ctime := time.Now().Unix()
  12928. timeStr := time.Now().Format("2006-01-02")
  12929. timeArr := strings.Split(timeStr, "-")
  12930. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12931. total = total + 1
  12932. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12933. cancelStock := models.DrugCancelStock{
  12934. OrderNumber: orderNumber,
  12935. OperaTime: operation_time,
  12936. OrgId: advice.UserOrgId,
  12937. Creater: creater,
  12938. Ctime: ctime,
  12939. Status: 1,
  12940. ReturnTime: advice.AdviceDate,
  12941. Dealer: info.Dealer,
  12942. Manufacturer: info.Manufacturer,
  12943. Type: 1,
  12944. }
  12945. service.AddSigleDrugCancelStock(&cancelStock)
  12946. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12947. dealer, _ := service.GetDealerById(info.Dealer)
  12948. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12949. cancelStockInfo := models.DrugCancelStockInfo{
  12950. OrderNumber: cancelInfo.OrderNumber,
  12951. CancelStockId: cancelInfo.ID,
  12952. DrugId: info.DrugId,
  12953. Count: info.Count,
  12954. Status: 1,
  12955. Ctime: ctime,
  12956. OrgId: advice.UserOrgId,
  12957. Type: 1,
  12958. Manufacturer: manufactureName.ManufacturerName,
  12959. Dealer: dealer.DealerName,
  12960. Total: 0,
  12961. RetailPrice: info.RetailPrice,
  12962. RetailTotalPrice: info.RetailTotalPrice,
  12963. Price: info.Price,
  12964. RegisterAccount: "",
  12965. Remark: info.Remark,
  12966. BatchNumber: info.BatchNumber,
  12967. MaxUnit: info.CountUnit,
  12968. ProductDate: info.ProductDate,
  12969. ExpiryDate: info.ExpiryDate,
  12970. BatchNumberId: info.WarehouseInfoId,
  12971. }
  12972. flow := models.DrugFlow{
  12973. WarehousingId: 0,
  12974. DrugId: info.DrugId,
  12975. Number: "",
  12976. BatchNumber: info.BatchNumber,
  12977. Count: info.Count,
  12978. UserOrgId: advice.UserOrgId,
  12979. PatientId: 0,
  12980. SystemTime: ctime,
  12981. ConsumableType: 4,
  12982. IsSys: 0,
  12983. WarehousingOrder: "",
  12984. WarehouseOutId: 0,
  12985. WarehouseOutOrderNumber: "",
  12986. IsEdit: 0,
  12987. CancelStockId: cancelStock.ID,
  12988. CancelOrderNumber: cancelStock.OrderNumber,
  12989. Manufacturer: info.Manufacturer,
  12990. Dealer: info.Dealer,
  12991. Creator: advice.AdviceDoctor,
  12992. UpdateCreator: 0,
  12993. Status: 1,
  12994. Ctime: time.Now().Unix(),
  12995. Mtime: 0,
  12996. Price: info.Price,
  12997. WarehousingDetailId: 0,
  12998. WarehouseOutDetailId: 0,
  12999. CancelOutDetailId: 0,
  13000. ExpireDate: info.ExpiryDate,
  13001. ProductDate: info.ProductDate,
  13002. MaxUnit: info.CountUnit,
  13003. MinUnit: "",
  13004. }
  13005. service.CreatedCancelStock(cancelStockInfo)
  13006. service.CreateDrugFlowOne(flow)
  13007. }
  13008. }
  13009. }
  13010. return err
  13011. }
  13012. func (this *HisApiController) DeleteNCDS() {
  13013. id, _ := this.GetInt64("id", 0)
  13014. if id > 0 {
  13015. service.DeletePsnNCDSRecordById(id)
  13016. this.ServeSuccessJSON(map[string]interface{}{
  13017. "msg": "删除成功",
  13018. })
  13019. } else {
  13020. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13021. return
  13022. }
  13023. }
  13024. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13025. id, _ := c.GetInt64("id")
  13026. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13027. c.ServeSuccessJSON(map[string]interface{}{
  13028. "advice": advice,
  13029. })
  13030. return
  13031. }
  13032. func (c *HisApiController) GetHisMonthChargePatientList() {
  13033. record_date := c.GetString("record_date")
  13034. start_time := c.GetString("start_time")
  13035. end_time := c.GetString("end_time")
  13036. timeLayout := "2006-01-02"
  13037. loc, _ := time.LoadLocation("Local")
  13038. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13039. if err != nil {
  13040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13041. return
  13042. }
  13043. if err != nil {
  13044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13045. return
  13046. }
  13047. recordDateTime := theTime.Unix()
  13048. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13049. if err != nil {
  13050. }
  13051. startRecordDateTime := startTime.Unix()
  13052. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13053. if err != nil {
  13054. }
  13055. endRecordDateTime := endTime.Unix()
  13056. adminInfo := c.GetAdminUserInfo()
  13057. var tempMonthChargePatients []*service.MonthChargePatients
  13058. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13059. for _, item := range tempPatients {
  13060. //过滤没有处方的
  13061. if len(item.HisPrescription) == 0 {
  13062. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13063. }
  13064. }
  13065. c.ServeSuccessJSON(map[string]interface{}{
  13066. "list": tempMonthChargePatients,
  13067. })
  13068. }
  13069. // PrescriptionDifference 医嘱数量差值结构体
  13070. type PrescriptionDrugDifference struct {
  13071. DrugID int64 //基础库药品id
  13072. ID int64 //医嘱id
  13073. Difference float64 //差值
  13074. Unit string //单位
  13075. }
  13076. type PrescriptionGoodDifference struct {
  13077. GoodID int64 //基础库项目耗材id
  13078. ID int64 //医嘱id
  13079. Difference int64 //差值
  13080. Unit string //单位
  13081. Type int64 //类型
  13082. }
  13083. type EditCustomData struct {
  13084. adviceList []*models.HisDoctorAdviceInfo
  13085. projectList []*models.HisPrescriptionProject
  13086. }
  13087. type SrcCustomData struct {
  13088. adviceList []*models.HisDoctorAdviceInfo
  13089. projectList []*models.HisPrescriptionProject
  13090. }
  13091. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13092. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13093. differences := make([]*PrescriptionDrugDifference, 0)
  13094. // 创建一个 map 来存储第一个切片中的药品信息
  13095. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13096. for _, advice := range firstPrescription {
  13097. firstMap[advice.DrugId] = advice
  13098. }
  13099. // 遍历第二个切片中的药品信息,并比较数量差值
  13100. for _, advice := range secondPrescription {
  13101. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13102. diff := &PrescriptionDrugDifference{
  13103. DrugID: advice.DrugId,
  13104. ID: firstAdvice.ID,
  13105. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13106. Unit: firstAdvice.PrescribingNumberUnit,
  13107. }
  13108. differences = append(differences, diff)
  13109. }
  13110. }
  13111. return differences
  13112. }
  13113. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13114. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13115. differences := make([]*PrescriptionGoodDifference, 0)
  13116. // 创建一个 map 来存储第一个切片中的耗材信息
  13117. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13118. for _, good := range firstPrescription {
  13119. firstMap[good.ProjectId] = good
  13120. }
  13121. // 遍历第二个切片中的耗材信息,并比较数量差值
  13122. for _, good := range secondPrescription {
  13123. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13124. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13125. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13126. diff := &PrescriptionGoodDifference{
  13127. GoodID: good.ProjectId,
  13128. ID: firstGood.ID,
  13129. Difference: count - firstCount,
  13130. Unit: firstGood.Unit,
  13131. Type: firstGood.Type,
  13132. }
  13133. differences = append(differences, diff)
  13134. }
  13135. }
  13136. return differences
  13137. }
  13138. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13139. var adviceList []*models.HisDoctorAdviceInfo
  13140. var projectList []*models.HisPrescriptionProject
  13141. var advice_ids []int64
  13142. var project_ids []int64
  13143. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13144. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13145. //var tempPrescription *models.HisPrescriptionProjectscription
  13146. if len(prescriptions) > 0 {
  13147. for _, item := range prescriptions {
  13148. items := item.(map[string]interface{})
  13149. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13150. advices := items["advices"].([]interface{})
  13151. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13152. groupNo := int64(0)
  13153. ctime := time.Now().Unix()
  13154. mtime := ctime
  13155. if len(advices) > 0 {
  13156. for _, advice := range advices {
  13157. var s models.HisDoctorAdviceInfo
  13158. s.AdviceType = 2
  13159. s.StopState = 2
  13160. s.ExecutionState = 2
  13161. s.Status = 1
  13162. s.Groupno = groupNo
  13163. s.CreatedTime = ctime
  13164. s.UpdatedTime = mtime
  13165. s.IsSettle = 2
  13166. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13167. //存储切片中
  13168. if s.ID > 0 {
  13169. advice_ids = append(advice_ids, s.ID)
  13170. adviceList = append(adviceList, &s)
  13171. }
  13172. }
  13173. }
  13174. }
  13175. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13176. projects := items["project"].([]interface{})
  13177. if len(projects) > 0 {
  13178. for _, project := range projects {
  13179. var p models.HisPrescriptionProject
  13180. p.Ctime = time.Now().Unix()
  13181. p.Mtime = time.Now().Unix()
  13182. p.Status = 1
  13183. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13184. if p.ID > 0 {
  13185. project_ids = append(project_ids, p.ID)
  13186. projectList = append(projectList, &p)
  13187. }
  13188. }
  13189. }
  13190. }
  13191. }
  13192. }
  13193. }
  13194. editCustomData.projectList = projectList
  13195. editCustomData.adviceList = adviceList
  13196. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13197. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13198. srcCustomData.adviceList = list
  13199. srcCustomData.projectList = list2
  13200. return
  13201. }
  13202. func (c *HisApiController) GetAllGoodInforList() {
  13203. orgId := c.GetAdminUserInfo().CurrentOrgId
  13204. goodList, _ := service.GetAllGoodList(orgId)
  13205. c.ServeSuccessJSON(map[string]interface{}{
  13206. "goodList": goodList,
  13207. })
  13208. return
  13209. }
  13210. func (this *HisApiController) SaveGoodList() {
  13211. project_name := this.GetString("project_name")
  13212. sort, _ := this.GetInt64("sort")
  13213. orgId := this.GetAdminUserInfo().CurrentOrgId
  13214. dataBody := make(map[string]interface{}, 0)
  13215. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13216. if err != nil {
  13217. utils.ErrorLog(err.Error())
  13218. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13219. return
  13220. }
  13221. goodTeam := models.XtGoodTeam{
  13222. ProjectName: project_name,
  13223. Sort: sort,
  13224. UserOrgId: orgId,
  13225. Status: 1,
  13226. Ctime: time.Now().Unix(),
  13227. Mtime: time.Now().Unix(),
  13228. }
  13229. service.CreateGoodTeam(goodTeam)
  13230. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13231. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13232. infos, _ := dataBody["info"].([]interface{})
  13233. if len(infos) > 0 {
  13234. for _, item := range infos {
  13235. items := item.(map[string]interface{})
  13236. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13237. utils.ErrorLog("good_id")
  13238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13239. return
  13240. }
  13241. good_id := int64(items["good_id"].(float64))
  13242. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13243. utils.ErrorLog("number")
  13244. }
  13245. number := int64(items["number"].(float64))
  13246. xtGoodTeamList := models.XtGoodTeamList{
  13247. GoodId: good_id,
  13248. Count: number,
  13249. TeamId: lastGoodTeam.ID,
  13250. UserOrgId: orgId,
  13251. Status: 1,
  13252. Ctime: time.Now().Unix(),
  13253. Mtime: time.Now().Unix(),
  13254. }
  13255. service.CreateGoodList(xtGoodTeamList)
  13256. }
  13257. this.ServeSuccessJSON(map[string]interface{}{
  13258. "lastGoodTeam": lastGoodTeam,
  13259. })
  13260. }
  13261. }
  13262. return
  13263. }
  13264. func (this *HisApiController) GetGoodList() {
  13265. orgId := this.GetAdminUserInfo().CurrentOrgId
  13266. limit, _ := this.GetInt64("limit")
  13267. page, _ := this.GetInt64("page")
  13268. keyword := this.GetString("keyword")
  13269. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13270. this.ServeSuccessJSON(map[string]interface{}{
  13271. "list": list,
  13272. "total": total,
  13273. })
  13274. }
  13275. func (this *HisApiController) GetGoodNameDetail() {
  13276. id, _ := this.GetInt64("id")
  13277. orgId := this.GetAdminUserInfo().CurrentOrgId
  13278. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13279. goodList, _ := service.GetAllGoodList(orgId)
  13280. this.ServeSuccessJSON(map[string]interface{}{
  13281. "goodNameDetail": goodNameDetail,
  13282. "goodList": goodList,
  13283. })
  13284. }
  13285. func (this *HisApiController) UpdateGoodList() {
  13286. project_name := this.GetString("project_name")
  13287. sort, _ := this.GetInt64("sort")
  13288. id, _ := this.GetInt64("id")
  13289. orgId := this.GetAdminUserInfo().CurrentOrgId
  13290. dataBody := make(map[string]interface{}, 0)
  13291. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13292. if err != nil {
  13293. utils.ErrorLog(err.Error())
  13294. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13295. return
  13296. }
  13297. goodTeam := models.XtGoodTeam{
  13298. ProjectName: project_name,
  13299. Sort: sort,
  13300. UserOrgId: orgId,
  13301. Status: 1,
  13302. Ctime: time.Now().Unix(),
  13303. Mtime: time.Now().Unix(),
  13304. ID: id,
  13305. }
  13306. service.SaveGoodTeam(goodTeam)
  13307. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13308. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13309. infos, _ := dataBody["info"].([]interface{})
  13310. if len(infos) > 0 {
  13311. for _, item := range infos {
  13312. items := item.(map[string]interface{})
  13313. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13314. utils.ErrorLog("good_id")
  13315. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13316. return
  13317. }
  13318. good_id := int64(items["good_id"].(float64))
  13319. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13320. utils.ErrorLog("id")
  13321. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13322. return
  13323. }
  13324. id := int64(items["id"].(float64))
  13325. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13326. utils.ErrorLog("number")
  13327. }
  13328. number := int64(items["number"].(float64))
  13329. xtGoodTeamList := models.XtGoodTeamList{
  13330. ID: id,
  13331. GoodId: good_id,
  13332. Count: number,
  13333. TeamId: lastGoodTeam.ID,
  13334. UserOrgId: orgId,
  13335. Status: 1,
  13336. Ctime: time.Now().Unix(),
  13337. Mtime: time.Now().Unix(),
  13338. }
  13339. service.SaveGoodList(xtGoodTeamList)
  13340. }
  13341. this.ServeSuccessJSON(map[string]interface{}{
  13342. "lastGoodTeam": lastGoodTeam,
  13343. })
  13344. }
  13345. }
  13346. return
  13347. }
  13348. func (this *HisApiController) DeleteGoodTeam() {
  13349. id, _ := this.GetInt64("id")
  13350. team, _ := service.DeleteGoodTeam(id)
  13351. this.ServeSuccessJSON(map[string]interface{}{
  13352. "team": team,
  13353. })
  13354. }
  13355. func (this *HisApiController) DeleteGood() {
  13356. id, _ := this.GetInt64("id")
  13357. good, _ := service.DeleteGood(id)
  13358. this.ServeSuccessJSON(map[string]interface{}{
  13359. "good": good,
  13360. })
  13361. }